UNPKG

@ledgerhq/live-common

Version:
49 lines 2.56 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendBTC = exports.sendBTCBasedCoin = 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"); const invariant_1 = __importDefault(require("invariant")); async function sendBTCBasedCoin(tx) { const events = await (0, speculos_1.pressUntilTextFound)(DeviceLabels_1.DeviceLabels.ACCEPT); const isAmountCorrect = (0, speculos_1.containsSubstringInEvent)(tx.amount, events); (0, expect_1.default)(isAmountCorrect).toBeTruthy(); const isAddressCorrect = (0, speculos_1.containsSubstringInEvent)(tx.accountToCredit.address, events); (0, expect_1.default)(isAddressCorrect).toBeTruthy(); await (0, speculos_1.pressBoth)(); await (0, speculos_1.waitFor)(DeviceLabels_1.DeviceLabels.CONFIRM); await (0, speculos_1.pressUntilTextFound)(DeviceLabels_1.DeviceLabels.ACCEPT); await (0, speculos_1.pressBoth)(); } exports.sendBTCBasedCoin = sendBTCBasedCoin; async function sendBTC(tx) { const speculosDevice = (0, speculos_1.getSpeculosModel)(); try { const events = speculosDevice === Device_1.Device.LNS ? await (0, speculos_1.pressUntilTextFound)(DeviceLabels_1.DeviceLabels.CONTINUE) : await (0, speculos_1.pressUntilTextFound)(DeviceLabels_1.DeviceLabels.SIGN_TRANSACTION); const isAmountCorrect = (0, speculos_1.containsSubstringInEvent)(tx.amount, events); (0, expect_1.default)(isAmountCorrect).toBeTruthy(); const isAddressCorrect = (0, speculos_1.containsSubstringInEvent)(tx.accountToCredit.address, events); (0, expect_1.default)(isAddressCorrect).toBeTruthy(); await (0, speculos_1.pressBoth)(); if (speculosDevice === Device_1.Device.LNS) { await (0, speculos_1.pressUntilTextFound)(DeviceLabels_1.DeviceLabels.SIGN); await (0, speculos_1.pressBoth)(); await (0, speculos_1.waitFor)(DeviceLabels_1.DeviceLabels.BITCOIN_IS_READY); } else { await (0, speculos_1.waitFor)(DeviceLabels_1.DeviceLabels.TRANSACTION_SIGNED); } } catch (e) { (0, invariant_1.default)(false, `Error while sending BTC transaction: ${e}`); } } exports.sendBTC = sendBTC; //# sourceMappingURL=bitcoin.js.map