@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
73 lines • 2.75 kB
JavaScript
import expect from "expect";
import { pressBoth, pressUntilTextFound, containsSubstringInEvent, waitFor, pressRightButton, } from "../speculos";
import { DeviceLabels } from "../enum/DeviceLabels";
import { Device } from "../enum/Device";
export async function sendCardano(tx) {
const isNanoS = process.env.SPECULOS_DEVICE === Device.LNS;
await waitFor(DeviceLabels.NEW_ORDINARY);
await (isNanoS ? pressRightButton() : pressBoth());
if (isNanoS) {
await waitFor(DeviceLabels.SEND_TO_ADDRESS);
await pressBoth();
}
else {
await pressUntilTextFound(DeviceLabels.SEND_TO_ADDRESS_2);
await pressBoth();
}
const events = await pressUntilTextFound(DeviceLabels.SEND);
if (!isNanoS) {
const isAmountCorrect = containsSubstringInEvent(tx.amount, events);
expect(isAmountCorrect).toBeTruthy();
}
await pressBoth();
await waitFor(DeviceLabels.TRANSACTION_FEE);
await pressBoth();
await waitFor(DeviceLabels.CONFIRM);
if (isNanoS) {
await pressRightButton();
}
else {
await pressBoth();
const isAddressCorrect = containsSubstringInEvent(tx.accountToCredit.address, events);
expect(isAddressCorrect).toBeTruthy();
}
}
export async function delegateCardano() {
const commonSteps = [
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
];
const LNSSpecificSteps = [
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
];
const steps = process.env.SPECULOS_DEVICE === Device.LNS ? LNSSpecificSteps : commonSteps;
for (const [label, action] of steps) {
try {
await waitFor(label);
action === "both" ? await pressBoth() : await pressRightButton();
}
catch (error) {
const message = error instanceof Error ? error.message : String(error);
console.error(`Error while waiting for "${label}":`, message);
break;
}
}
}
//# sourceMappingURL=cardano.js.map