UNPKG

@ledgerhq/coin-ton

Version:
111 lines 4.77 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("@ledgerhq/coin-framework/currencies/index"); const index_2 = require("@ledgerhq/coin-framework/lib/account/index"); const core_1 = require("@ton/core"); const bignumber_js_1 = __importDefault(require("bignumber.js")); const constants_1 = require("../../constants"); const deviceTransactionConfig_1 = __importDefault(require("../../deviceTransactionConfig")); const common_fixtures_1 = require("../fixtures/common.fixtures"); const status = { errors: {}, warnings: {}, estimatedFees: new bignumber_js_1.default(0), amount: new bignumber_js_1.default(0), totalSpent: new bignumber_js_1.default(0), }; describe("deviceTransactionConfig", () => { describe("TON transaction", () => { it("should return the fields for a transaction when there is a valid comment", async () => { const transaction = { ...common_fixtures_1.transaction, comment: { isEncrypted: false, text: "validComment" }, }; const res = await (0, deviceTransactionConfig_1.default)({ account: common_fixtures_1.account, parentAccount: undefined, transaction, status, }); expect(res).toEqual([ { type: "address", label: "To", address: transaction.recipient, }, { type: "amount", label: "Amount", }, { type: "fees", label: "Fee" }, { type: "text", label: "Comment", value: "validComment" }, ]); }); it("should return the fields for a transaction when useAllAmount is true and there is a valid comment", async () => { const transaction = { ...common_fixtures_1.transaction, useAllAmount: true, comment: { isEncrypted: false, text: "validComment" }, }; const res = await (0, deviceTransactionConfig_1.default)({ account: common_fixtures_1.account, parentAccount: undefined, transaction, status, }); expect(res).toEqual([ { type: "address", label: "To", address: transaction.recipient, }, { type: "text", label: "Amount", value: "ALL YOUR TONs", }, { type: "fees", label: "Fee" }, { type: "text", label: "Comment", value: "validComment" }, ]); }); }); describe("Jetton transaction", () => { it("should return the fields for a jetton transaction", async () => { if (common_fixtures_1.account.subAccounts?.[0]) { const res = await (0, deviceTransactionConfig_1.default)({ account: common_fixtures_1.account.subAccounts[0], parentAccount: common_fixtures_1.account, transaction: common_fixtures_1.jettonTransaction, status, }); expect(res).toEqual([ { type: "address", label: "To", address: common_fixtures_1.jettonTransaction.recipient, }, { type: "text", label: "Jetton amount", value: (0, index_1.formatCurrencyUnit)((0, index_2.getAccountCurrency)(common_fixtures_1.account.subAccounts[0]).units[0], common_fixtures_1.jettonTransaction.amount, { showCode: true, disableRounding: true, }), }, { type: "text", label: "Amount", value: (0, index_1.formatCurrencyUnit)((0, index_2.getAccountCurrency)(common_fixtures_1.account).units[0], (0, bignumber_js_1.default)((0, core_1.toNano)(constants_1.TOKEN_TRANSFER_MAX_FEE).toString()), { showCode: true, disableRounding: true, }), }, ]); } }); }); }); //# sourceMappingURL=deviceTransactionConfig.unit.test.js.map