@ledgerhq/coin-algorand
Version:
Ledger Algorand Coin integration
89 lines • 2.9 kB
JavaScript
import { findTokenById } from "@ledgerhq/cryptoassets/index";
import { getAccountCurrency } from "@ledgerhq/coin-framework/account";
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies";
import { extractTokenId } from "./tokens";
export const displayTokenValue = (token) => `${token.name} (#${extractTokenId(token.id)})`;
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: displayTokenValue(account.token),
});
}
if (amount) {
fields.push({
label: account.type === "TokenAccount" ? "Asset amt" : "Amount",
type: "amount",
value: formatCurrencyUnit(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 = findTokenById(assetId);
fields.push({
type: "text",
label: "Asset ID",
value: token ? displayTokenValue(token) : `#${extractTokenId(assetId)}`,
});
}
fields.push({
type: "text",
label: "Asset amt",
value: "0",
});
break;
default:
break;
}
return fields;
}
export default getDeviceTransactionConfig;
//# sourceMappingURL=deviceTransactionConfig.js.map