@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
41 lines • 1.77 kB
JavaScript
import expect from "expect";
import { pressBoth, pressUntilTextFound, waitFor, containsSubstringInEvent, getSpeculosModel, } from "../speculos";
import { DeviceLabels } from "../enum/DeviceLabels";
import { Device } from "../enum/Device";
import invariant from "invariant";
export async function sendBTCBasedCoin(tx) {
const events = await pressUntilTextFound(DeviceLabels.ACCEPT);
const isAmountCorrect = containsSubstringInEvent(tx.amount, events);
expect(isAmountCorrect).toBeTruthy();
const isAddressCorrect = containsSubstringInEvent(tx.accountToCredit.address, events);
expect(isAddressCorrect).toBeTruthy();
await pressBoth();
await waitFor(DeviceLabels.CONFIRM);
await pressUntilTextFound(DeviceLabels.ACCEPT);
await pressBoth();
}
export async function sendBTC(tx) {
const speculosDevice = getSpeculosModel();
try {
const events = speculosDevice === Device.LNS
? await pressUntilTextFound(DeviceLabels.CONTINUE)
: await pressUntilTextFound(DeviceLabels.SIGN_TRANSACTION);
const isAmountCorrect = containsSubstringInEvent(tx.amount, events);
expect(isAmountCorrect).toBeTruthy();
const isAddressCorrect = containsSubstringInEvent(tx.accountToCredit.address, events);
expect(isAddressCorrect).toBeTruthy();
await pressBoth();
if (speculosDevice === Device.LNS) {
await pressUntilTextFound(DeviceLabels.SIGN);
await pressBoth();
await waitFor(DeviceLabels.BITCOIN_IS_READY);
}
else {
await waitFor(DeviceLabels.TRANSACTION_SIGNED);
}
}
catch (e) {
invariant(false, `Error while sending BTC transaction: ${e}`);
}
}
//# sourceMappingURL=bitcoin.js.map