UNPKG

@ledgerhq/coin-algorand

Version:
93 lines 3.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.displayTokenValue = void 0; const index_1 = require("@ledgerhq/cryptoassets/index"); const account_1 = require("@ledgerhq/coin-framework/account"); const currencies_1 = require("@ledgerhq/coin-framework/currencies"); const tokens_1 = require("./tokens"); const displayTokenValue = (token) => `${token.name} (#${(0, tokens_1.extractTokenId)(token.id)})`; exports.displayTokenValue = displayTokenValue; const getSendFields = (transaction, status, account, addRecipient) => { const { estimatedFees, amount } = status; const fields = []; fields.push({ type: "text", label: "Type", value: account.type === "TokenAccount" ? "Asset xfer" : "Payment", }); if (estimatedFees && !estimatedFees.isZero()) { fields.push({ type: "fees", label: "Fee", }); } if (addRecipient) { fields.push({ type: "address", label: "Recipient", address: transaction.recipient, }); } if (account.type === "TokenAccount") { fields.push({ type: "text", label: "Asset ID", value: (0, exports.displayTokenValue)(account.token), }); } if (amount) { fields.push({ label: account.type === "TokenAccount" ? "Asset amt" : "Amount", type: "amount", value: (0, currencies_1.formatCurrencyUnit)((0, account_1.getAccountCurrency)(account).units[0], amount, { showCode: true, disableRounding: true, }), }); } return fields; }; function getDeviceTransactionConfig({ account, transaction, status, }) { const { mode, assetId } = transaction; const { estimatedFees } = status; let fields = []; switch (mode) { case "send": fields = getSendFields(transaction, status, account, false); break; case "claimReward": fields = getSendFields(transaction, status, account, true); break; case "optIn": fields.push({ type: "text", label: "Type", value: "Asset xfer", }); if (estimatedFees && !estimatedFees.isZero()) { fields.push({ type: "fees", label: "Fee", }); } if (assetId) { const token = (0, index_1.findTokenById)(assetId); fields.push({ type: "text", label: "Asset ID", value: token ? (0, exports.displayTokenValue)(token) : `#${(0, tokens_1.extractTokenId)(assetId)}`, }); } fields.push({ type: "text", label: "Asset amt", value: "0", }); break; default: break; } return fields; } exports.default = getDeviceTransactionConfig; //# sourceMappingURL=deviceTransactionConfig.js.map