UNPKG

@ledgerhq/live-common

Version:
81 lines 3.79 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.delegateCardano = exports.sendCardano = void 0; const expect_1 = __importDefault(require("expect")); const speculos_1 = require("../speculos"); const DeviceLabels_1 = require("../enum/DeviceLabels"); const Device_1 = require("../enum/Device"); async function sendCardano(tx) { const isNanoS = process.env.SPECULOS_DEVICE === Device_1.Device.LNS; await (0, speculos_1.waitFor)(DeviceLabels_1.DeviceLabels.NEW_ORDINARY); await (isNanoS ? (0, speculos_1.pressRightButton)() : (0, speculos_1.pressBoth)()); if (isNanoS) { await (0, speculos_1.waitFor)(DeviceLabels_1.DeviceLabels.SEND_TO_ADDRESS); await (0, speculos_1.pressBoth)(); } else { await (0, speculos_1.pressUntilTextFound)(DeviceLabels_1.DeviceLabels.SEND_TO_ADDRESS_2); await (0, speculos_1.pressBoth)(); } const events = await (0, speculos_1.pressUntilTextFound)(DeviceLabels_1.DeviceLabels.SEND); if (!isNanoS) { const isAmountCorrect = (0, speculos_1.containsSubstringInEvent)(tx.amount, events); (0, expect_1.default)(isAmountCorrect).toBeTruthy(); } await (0, speculos_1.pressBoth)(); await (0, speculos_1.waitFor)(DeviceLabels_1.DeviceLabels.TRANSACTION_FEE); await (0, speculos_1.pressBoth)(); await (0, speculos_1.waitFor)(DeviceLabels_1.DeviceLabels.CONFIRM); if (isNanoS) { await (0, speculos_1.pressRightButton)(); } else { await (0, speculos_1.pressBoth)(); const isAddressCorrect = (0, speculos_1.containsSubstringInEvent)(tx.accountToCredit.address, events); (0, expect_1.default)(isAddressCorrect).toBeTruthy(); } } exports.sendCardano = sendCardano; async function delegateCardano() { const commonSteps = [ [DeviceLabels_1.DeviceLabels.NEW_ORDINARY, "both"], [DeviceLabels_1.DeviceLabels.TRANSACTION_FEE, "both"], [DeviceLabels_1.DeviceLabels.REGISTER, "both"], [DeviceLabels_1.DeviceLabels.STAKE_KEY, "both"], [DeviceLabels_1.DeviceLabels.DEPOSIT, "both"], [DeviceLabels_1.DeviceLabels.CONFIRM, "both"], [DeviceLabels_1.DeviceLabels.DELEGATE_STAKE, "both"], [DeviceLabels_1.DeviceLabels.STAKE_KEY, "both"], [DeviceLabels_1.DeviceLabels.CONFIRM, "both"], [DeviceLabels_1.DeviceLabels.CONFIRM, "both"], ]; const LNSSpecificSteps = [ [DeviceLabels_1.DeviceLabels.NEW_ORDINARY, "right"], [DeviceLabels_1.DeviceLabels.TRANSACTION_FEE, "both"], [DeviceLabels_1.DeviceLabels.REGISTER, "both"], [DeviceLabels_1.DeviceLabels.STAKE_KEY, "both"], [DeviceLabels_1.DeviceLabels.DEPOSIT, "both"], [DeviceLabels_1.DeviceLabels.CONFIRM, "right"], [DeviceLabels_1.DeviceLabels.DELEGATE_STAKE, "both"], [DeviceLabels_1.DeviceLabels.STAKE_KEY, "both"], [DeviceLabels_1.DeviceLabels.CONFIRM, "right"], [DeviceLabels_1.DeviceLabels.CONFIRM, "right"], ]; const steps = process.env.SPECULOS_DEVICE === Device_1.Device.LNS ? LNSSpecificSteps : commonSteps; for (const [label, action] of steps) { try { await (0, speculos_1.waitFor)(label); action === "both" ? await (0, speculos_1.pressBoth)() : await (0, speculos_1.pressRightButton)(); } catch (error) { const message = error instanceof Error ? error.message : String(error); console.error(`Error while waiting for "${label}":`, message); break; } } } exports.delegateCardano = delegateCardano; //# sourceMappingURL=cardano.js.map