@ledgerhq/coin-multiversx
Version:
Ledger MultiversX Coin integration
250 lines • 9.53 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.acceptEsdtTransferTransaction = exports.acceptWithdrawTransaction = exports.acceptUndelegateTransaction = exports.acceptDelegateTransaction = exports.acceptMoveBalanceTransaction = void 0;
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const currencies_1 = require("@ledgerhq/coin-framework/currencies");
const specs_1 = require("@ledgerhq/coin-framework/bot/specs");
const account_1 = require("@ledgerhq/coin-framework/account");
exports.acceptMoveBalanceTransaction = (0, specs_1.deviceActionFlow)({
steps: [
{
title: "Receiver",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ transaction }) => transaction.recipient,
},
{
title: "Amount",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ account, status }) => {
return (0, specs_1.formatDeviceAmount)(account.currency, status.amount, {
postfixCode: true,
});
},
},
{
title: "Fee",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ account, transaction }) => (0, currencies_1.formatCurrencyUnit)(account.currency.units[0], transaction.fees || new bignumber_js_1.default(50000), {
showCode: true,
disableRounding: true,
joinFragmentsSeparator: " ",
}).replace(/\s+/g, " "),
},
{
title: "Data",
button: specs_1.SpeculosButton.RIGHT,
},
{
title: "Sign",
button: specs_1.SpeculosButton.BOTH,
final: true,
},
{
title: "Network",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: () => "Mainnet",
},
],
});
exports.acceptDelegateTransaction = (0, specs_1.deviceActionFlow)({
steps: [
{
title: "Receiver",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ transaction }) => transaction.recipient,
},
{
title: "Amount",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ account, transaction }) => (0, currencies_1.formatCurrencyUnit)(account.currency.units[0], transaction.amount, {
showCode: true,
disableRounding: true,
joinFragmentsSeparator: " ",
}).replace(/\s+/g, " "),
},
{
title: "Fee",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ account, transaction }) => (0, currencies_1.formatCurrencyUnit)(account.currency.units[0], transaction.fees || new bignumber_js_1.default(50000), {
showCode: true,
disableRounding: true,
joinFragmentsSeparator: " ",
}).replace(/\s+/g, " "),
},
{
title: "Data",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: () => "[Size: 8] delegate",
},
{
title: "Sign",
button: specs_1.SpeculosButton.BOTH,
final: true,
},
{
title: "Network",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: () => "Mainnet",
},
],
});
exports.acceptUndelegateTransaction = (0, specs_1.deviceActionFlow)({
steps: [
{
title: "Receiver",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ transaction }) => transaction.recipient,
},
{
title: "Amount",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ account }) => (0, currencies_1.formatCurrencyUnit)(account.currency.units[0], new bignumber_js_1.default(0), {
showCode: true,
disableRounding: true,
joinFragmentsSeparator: " ",
}).replace(/\s+/g, " "),
},
{
title: "Fee",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ account, transaction }) => (0, currencies_1.formatCurrencyUnit)(account.currency.units[0], transaction.fees || new bignumber_js_1.default(50000), {
showCode: true,
disableRounding: true,
joinFragmentsSeparator: " ",
}).replace(/\s+/g, " "),
},
{
title: "Data",
button: specs_1.SpeculosButton.RIGHT,
},
{
title: "Sign",
button: specs_1.SpeculosButton.BOTH,
final: true,
},
{
title: "Network",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: () => "Mainnet",
},
],
});
exports.acceptWithdrawTransaction = (0, specs_1.deviceActionFlow)({
steps: [
{
title: "Receiver",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ transaction }) => transaction.recipient,
},
{
title: "Amount",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ account }) => (0, currencies_1.formatCurrencyUnit)(account.currency.units[0], new bignumber_js_1.default(0), {
showCode: true,
disableRounding: true,
joinFragmentsSeparator: " ",
}).replace(/\s+/g, " "),
},
{
title: "Fee",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ account, transaction }) => (0, currencies_1.formatCurrencyUnit)(account.currency.units[0], transaction.fees || new bignumber_js_1.default(50000), {
showCode: true,
disableRounding: true,
joinFragmentsSeparator: " ",
}).replace(/\s+/g, " "),
},
{
title: "Data",
button: specs_1.SpeculosButton.RIGHT,
},
{
title: "Sign",
button: specs_1.SpeculosButton.BOTH,
final: true,
},
{
title: "Network",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: () => "Mainnet",
},
],
});
exports.acceptEsdtTransferTransaction = (0, specs_1.deviceActionFlow)({
steps: [
{
title: "Token",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: async ({ account, transaction }) => {
const { subAccounts } = account;
const { subAccountId } = transaction;
const tokenAccount = !subAccountId
? null
: subAccounts && subAccounts.find(ta => ta.id === subAccountId);
if (!tokenAccount) {
throw new Error();
}
const { token } = await (0, account_1.decodeTokenAccountId)(tokenAccount.id);
return token?.name ?? "";
},
},
{
title: "Value",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: async ({ account, transaction }) => {
const { subAccounts } = account;
const { subAccountId } = transaction;
const tokenAccount = !subAccountId
? null
: subAccounts && subAccounts.find(ta => ta.id === subAccountId);
if (!tokenAccount) {
throw new Error();
}
const { token } = await (0, account_1.decodeTokenAccountId)(tokenAccount.id);
if (!token) {
throw new Error();
}
return (0, currencies_1.formatCurrencyUnit)(token.units[0], transaction.amount, {
showCode: true,
disableRounding: true,
joinFragmentsSeparator: " ",
}).replace(/\s+/g, " ");
},
},
{
title: "Receiver",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ transaction }) => transaction.recipient,
},
{
title: "Fee",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: ({ account, transaction }) => (0, currencies_1.formatCurrencyUnit)(account.currency.units[0], transaction.fees || new bignumber_js_1.default(50000), {
showCode: true,
disableRounding: true,
joinFragmentsSeparator: " ",
}).replace(/\s+/g, " "),
},
{
title: "Confirm transfer",
button: specs_1.SpeculosButton.BOTH,
final: true,
},
{
title: "Network",
button: specs_1.SpeculosButton.RIGHT,
expectedValue: () => "Mainnet",
},
],
});
exports.default = {
acceptMoveBalanceTransaction: exports.acceptMoveBalanceTransaction,
acceptEsdtTransferTransaction: exports.acceptEsdtTransferTransaction,
acceptDelegateTransaction: exports.acceptDelegateTransaction,
acceptUndelegateTransaction: exports.acceptUndelegateTransaction,
acceptWithdrawTransaction: exports.acceptWithdrawTransaction,
};
//# sourceMappingURL=speculos-deviceActions.js.map