"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_TRANSACTION);
    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 = [
        { label: DeviceLabels_1.DeviceLabels.NEW_ORDINARY, action: "both" },
        { label: DeviceLabels_1.DeviceLabels.TRANSACTION_FEE, action: "both" },
        { label: DeviceLabels_1.DeviceLabels.REGISTER, action: "both" },
        { label: DeviceLabels_1.DeviceLabels.STAKE_KEY, action: "both" },
        { label: DeviceLabels_1.DeviceLabels.CONFIRM, action: "both" },
        { label: DeviceLabels_1.DeviceLabels.DELEGATE_STAKE, action: "both" },
        { label: DeviceLabels_1.DeviceLabels.STAKE_KEY, action: "both" },
        { label: DeviceLabels_1.DeviceLabels.CONFIRM, action: "both" },
        { label: DeviceLabels_1.DeviceLabels.CONFIRM, action: "both" },
    ];
    const LNSSpecificSteps = [
        { label: DeviceLabels_1.DeviceLabels.NEW_ORDINARY, action: "right" },
        { label: DeviceLabels_1.DeviceLabels.TRANSACTION_FEE, action: "both" },
        { label: DeviceLabels_1.DeviceLabels.REGISTER, action: "both" },
        { label: DeviceLabels_1.DeviceLabels.STAKE_KEY, action: "both" },
        { label: DeviceLabels_1.DeviceLabels.CONFIRM, action: "right" },
        { label: DeviceLabels_1.DeviceLabels.DELEGATE_STAKE, action: "both" },
        { label: DeviceLabels_1.DeviceLabels.STAKE_KEY, action: "both" },
        { label: DeviceLabels_1.DeviceLabels.CONFIRM, action: "right" },
        { label: DeviceLabels_1.DeviceLabels.CONFIRM, action: "right" },
    ];
    const stepsToExecute = process.env.SPECULOS_DEVICE === Device_1.Device.LNS ? LNSSpecificSteps : commonSteps;
    for (const step of stepsToExecute) {
        await (0, speculos_1.waitFor)(step.label);
        if (step.action === "both") {
            await (0, speculos_1.pressBoth)();
        }
        else if (step.action === "right") {
            await (0, speculos_1.pressRightButton)();
        }
    }
}
exports.delegateCardano = delegateCardano;
//# sourceMappingURL=cardano.js.map