@ledgerhq/coin-near
Version:
68 lines • 2.42 kB
JavaScript
import * as nearAPI from "near-api-js";
import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index";
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
import { deviceActionFlow, SpeculosButton } from "@ledgerhq/coin-framework/bot/specs";
const confirmWording = {
send: "transfer",
stake: "deposit_and_stake",
unstake: "unstake",
withdraw: "withdraw",
};
export const acceptTransaction = deviceActionFlow({
steps: [
{
title: "Confirm",
button: SpeculosButton.RIGHT,
expectedValue: ({ transaction }) => confirmWording[transaction.mode],
},
{
title: "Deposit",
button: SpeculosButton.RIGHT,
expectedValue: ({ transaction, account }) => {
if (transaction.mode === "stake") {
return formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, {
disableRounding: true,
});
}
return "0";
},
},
{
title: "Amount",
button: SpeculosButton.RIGHT,
expectedValue: ({ transaction, account }) => formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, {
disableRounding: true,
}),
},
{
title: "To",
button: SpeculosButton.RIGHT,
expectedValue: ({ transaction }) => transaction.recipient,
},
{
title: "From",
button: SpeculosButton.RIGHT,
expectedValue: ({ account }) => account.freshAddress,
},
{
title: "Args",
button: SpeculosButton.RIGHT,
expectedValue: ({ transaction, account }) => {
if (transaction.mode === "stake") {
return "{}";
}
return JSON.stringify({
amount: nearAPI.utils.format.parseNearAmount(formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, {
disableRounding: true,
})),
});
},
},
{
title: "Approve",
button: SpeculosButton.BOTH,
final: true,
},
],
});
//# sourceMappingURL=speculos-deviceActions.js.map