UNPKG

@ledgerhq/coin-filecoin

Version:
159 lines 6.07 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateDeviceActionFlow = void 0; const specs_1 = require("@ledgerhq/coin-framework/bot/specs"); const utils_1 = require("../bridge/utils"); const network_1 = require("../network"); const address_1 = require("iso-filecoin/address"); const common_logic_1 = require("../common-logic"); const invariant_1 = __importDefault(require("invariant")); const generateDeviceActionFlow = (scenario) => { const data = { steps: [] }; data.steps = data.steps.concat([ { title: "Please", button: specs_1.SpeculosButton.RIGHT, }, ]); if (scenario === utils_1.BotScenario.F4_RECIPIENT) { data.steps.push({ title: "To", button: specs_1.SpeculosButton.RIGHT, expectedValue: ({ transaction }) => { const addr = (0, address_1.fromString)(transaction.recipient); if ((0, network_1.isFilEthAddress)(addr)) { return (0, address_1.toEthAddress)(addr) + transaction.recipient; } return "unexpected flow... address should be eth type"; }, }); } else if (scenario === utils_1.BotScenario.ETH_RECIPIENT) { data.steps.push({ title: "To", button: specs_1.SpeculosButton.RIGHT, expectedValue: ({ transaction }) => { const addr = (0, address_1.fromEthAddress)(transaction.recipient, "mainnet"); return transaction.recipient + addr.toString(); }, }); } else if (scenario === utils_1.BotScenario.TOKEN_TRANSFER) { data.steps.push({ title: "To", button: specs_1.SpeculosButton.RIGHT, expectedValue: ({ transaction }) => { return (0, utils_1.expectedToFieldForTokenTransfer)(transaction.recipient); }, }); } else { data.steps.push({ title: "To", button: specs_1.SpeculosButton.RIGHT, expectedValue: ({ transaction }) => transaction.recipient, }); } data.steps = data.steps.concat([ { title: "From", button: specs_1.SpeculosButton.RIGHT, expectedValue: ({ account }) => account.freshAddress, }, { title: "Nonce", button: specs_1.SpeculosButton.RIGHT, expectedValue: ({ transaction }) => transaction.nonce.toString(), }, ]); if (scenario === utils_1.BotScenario.TOKEN_TRANSFER) { data.steps.push({ title: "Value", button: specs_1.SpeculosButton.RIGHT, expectedValue: ({ account, transaction }) => { const subAccount = (0, common_logic_1.getSubAccount)(account, transaction); (0, invariant_1.default)(subAccount, "subAccount is required for token transfer"); return (0, specs_1.formatDeviceAmount)(subAccount.token, transaction.amount, { hideCode: false, showAllDigits: true, }); }, }); } else { data.steps.push({ title: "Value", button: specs_1.SpeculosButton.RIGHT, expectedValue: ({ account, status }) => (0, specs_1.formatDeviceAmount)(account.currency, status.amount, { hideCode: true, showAllDigits: true, }), }); } if (scenario === utils_1.BotScenario.TOKEN_TRANSFER) { data.steps.push({ title: "Gas Limit", button: specs_1.SpeculosButton.RIGHT, expectedValue: ({ transaction, account }) => (0, specs_1.formatDeviceAmount)(account.currency, transaction.gasLimit, { hideCode: false, showAllDigits: true, }), }); } else { data.steps = data.steps.concat([ { title: "Gas Limit", button: specs_1.SpeculosButton.RIGHT, expectedValue: ({ transaction }) => transaction.gasLimit.toFixed(), }, { title: "Gas Premium", button: specs_1.SpeculosButton.RIGHT, expectedValue: ({ account, transaction }) => (0, specs_1.formatDeviceAmount)(account.currency, transaction.gasPremium, { hideCode: true, showAllDigits: true, }), }, { title: "Gas Fee Cap", button: specs_1.SpeculosButton.RIGHT, expectedValue: ({ account, transaction }) => (0, specs_1.formatDeviceAmount)(account.currency, transaction.gasFeeCap, { hideCode: true, showAllDigits: true, }), }, ]); } if (scenario === utils_1.BotScenario.ETH_RECIPIENT || scenario === utils_1.BotScenario.F4_RECIPIENT) { data.steps.push({ title: "Method", button: specs_1.SpeculosButton.RIGHT, expectedValue: () => utils_1.Methods.InvokeEVM.toString(), }); } else if (scenario === utils_1.BotScenario.TOKEN_TRANSFER) { data.steps.push({ title: "Method", button: specs_1.SpeculosButton.RIGHT, expectedValue: () => (0, utils_1.methodToString)(utils_1.Methods.ERC20Transfer), }); } else { data.steps.push({ title: "Method", button: specs_1.SpeculosButton.RIGHT, expectedValue: () => "Transfer", }); } data.steps.push({ title: "APPROVE", button: specs_1.SpeculosButton.BOTH, }); return (0, specs_1.deviceActionFlow)(data); }; exports.generateDeviceActionFlow = generateDeviceActionFlow; //# sourceMappingURL=speculos-deviceActions.js.map