@ledgerhq/coin-multiversx 0.2.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +23 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +31 -0
- package/CHANGELOG.md +400 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/lib/api/apiCalls.d.ts +22 -0
- package/lib/api/apiCalls.d.ts.map +1 -0
- package/lib/api/apiCalls.js +153 -0
- package/lib/api/apiCalls.js.map +1 -0
- package/lib/api/dtos/multiversx-account.d.ts +9 -0
- package/lib/api/dtos/multiversx-account.d.ts.map +1 -0
- package/lib/api/dtos/multiversx-account.js +17 -0
- package/lib/api/dtos/multiversx-account.js.map +1 -0
- package/lib/api/index.d.ts +2 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +16 -0
- package/lib/api/index.js.map +1 -0
- package/lib/api/sdk.d.ts +29 -0
- package/lib/api/sdk.d.ts.map +1 -0
- package/lib/api/sdk.js +281 -0
- package/lib/api/sdk.js.map +1 -0
- package/lib/bridge/js.d.ts +11 -0
- package/lib/bridge/js.d.ts.map +1 -0
- package/lib/bridge/js.js +62 -0
- package/lib/bridge/js.js.map +1 -0
- package/lib/bridge.integration.test.d.ts +4 -0
- package/lib/bridge.integration.test.d.ts.map +1 -0
- package/lib/bridge.integration.test.js +142 -0
- package/lib/bridge.integration.test.js.map +1 -0
- package/lib/broadcast.d.ts +9 -0
- package/lib/broadcast.d.ts.map +1 -0
- package/lib/broadcast.js +16 -0
- package/lib/broadcast.js.map +1 -0
- package/lib/buildOptimisticOperation.d.ts +4 -0
- package/lib/buildOptimisticOperation.d.ts.map +1 -0
- package/lib/buildOptimisticOperation.js +100 -0
- package/lib/buildOptimisticOperation.js.map +1 -0
- package/lib/buildOptimisticOperation.test.d.ts +2 -0
- package/lib/buildOptimisticOperation.test.d.ts.map +1 -0
- package/lib/buildOptimisticOperation.test.js +78 -0
- package/lib/buildOptimisticOperation.test.js.map +1 -0
- package/lib/buildSubAccounts.d.ts +11 -0
- package/lib/buildSubAccounts.d.ts.map +1 -0
- package/lib/buildSubAccounts.js +117 -0
- package/lib/buildSubAccounts.js.map +1 -0
- package/lib/buildTransaction.d.ts +19 -0
- package/lib/buildTransaction.d.ts.map +1 -0
- package/lib/buildTransaction.js +49 -0
- package/lib/buildTransaction.js.map +1 -0
- package/lib/buildTransaction.unit.test.d.ts +2 -0
- package/lib/buildTransaction.unit.test.d.ts.map +1 -0
- package/lib/buildTransaction.unit.test.js +47 -0
- package/lib/buildTransaction.unit.test.js.map +1 -0
- package/lib/cli-transaction.d.ts +16 -0
- package/lib/cli-transaction.d.ts.map +1 -0
- package/lib/cli-transaction.js +35 -0
- package/lib/cli-transaction.js.map +1 -0
- package/lib/config.d.ts +14 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +16 -0
- package/lib/config.js.map +1 -0
- package/lib/constants.d.ts +21 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +27 -0
- package/lib/constants.js.map +1 -0
- package/lib/createTransaction.d.ts +9 -0
- package/lib/createTransaction.d.ts.map +1 -0
- package/lib/createTransaction.js +26 -0
- package/lib/createTransaction.js.map +1 -0
- package/lib/datasets/multiversx1.d.ts +3 -0
- package/lib/datasets/multiversx1.d.ts.map +1 -0
- package/lib/datasets/multiversx1.js +21 -0
- package/lib/datasets/multiversx1.js.map +1 -0
- package/lib/deviceTransactionConfig.d.ts +10 -0
- package/lib/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/deviceTransactionConfig.js +60 -0
- package/lib/deviceTransactionConfig.js.map +1 -0
- package/lib/encode.d.ts +11 -0
- package/lib/encode.d.ts.map +1 -0
- package/lib/encode.js +39 -0
- package/lib/encode.js.map +1 -0
- package/lib/errors.d.ts +16 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +10 -0
- package/lib/errors.js.map +1 -0
- package/lib/estimateMaxSpendable.d.ts +10 -0
- package/lib/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/estimateMaxSpendable.js +35 -0
- package/lib/estimateMaxSpendable.js.map +1 -0
- package/lib/formatters.d.ts +11 -0
- package/lib/formatters.d.ts.map +1 -0
- package/lib/formatters.js +65 -0
- package/lib/formatters.js.map +1 -0
- package/lib/getTransactionStatus.d.ts +5 -0
- package/lib/getTransactionStatus.d.ts.map +1 -0
- package/lib/getTransactionStatus.js +107 -0
- package/lib/getTransactionStatus.js.map +1 -0
- package/lib/helpers/denominate.d.ts +9 -0
- package/lib/helpers/denominate.d.ts.map +1 -0
- package/lib/helpers/denominate.js +75 -0
- package/lib/helpers/denominate.js.map +1 -0
- package/lib/helpers/handleTransactionStatus.d.ts +7 -0
- package/lib/helpers/handleTransactionStatus.d.ts.map +1 -0
- package/lib/helpers/handleTransactionStatus.js +18 -0
- package/lib/helpers/handleTransactionStatus.js.map +1 -0
- package/lib/helpers/hasMinimumDelegableBalance.d.ts +3 -0
- package/lib/helpers/hasMinimumDelegableBalance.d.ts.map +1 -0
- package/lib/helpers/hasMinimumDelegableBalance.js +7 -0
- package/lib/helpers/hasMinimumDelegableBalance.js.map +1 -0
- package/lib/helpers/randomizeProviders.d.ts +7 -0
- package/lib/helpers/randomizeProviders.d.ts.map +1 -0
- package/lib/helpers/randomizeProviders.js +12 -0
- package/lib/helpers/randomizeProviders.js.map +1 -0
- package/lib/hw-getAddress.d.ts +6 -0
- package/lib/hw-getAddress.d.ts.map +1 -0
- package/lib/hw-getAddress.js +14 -0
- package/lib/hw-getAddress.js.map +1 -0
- package/lib/logic.d.ts +15 -0
- package/lib/logic.d.ts.map +1 -0
- package/lib/logic.js +77 -0
- package/lib/logic.js.map +1 -0
- package/lib/preload.d.ts +11 -0
- package/lib/preload.d.ts.map +1 -0
- package/lib/preload.js +94 -0
- package/lib/preload.js.map +1 -0
- package/lib/prepareTransaction.d.ts +10 -0
- package/lib/prepareTransaction.d.ts.map +1 -0
- package/lib/prepareTransaction.js +72 -0
- package/lib/prepareTransaction.js.map +1 -0
- package/lib/reconciliation.d.ts +3 -0
- package/lib/reconciliation.d.ts.map +1 -0
- package/lib/reconciliation.js +56 -0
- package/lib/reconciliation.js.map +1 -0
- package/lib/serialization.d.ts +9 -0
- package/lib/serialization.d.ts.map +1 -0
- package/lib/serialization.js +65 -0
- package/lib/serialization.js.map +1 -0
- package/lib/signOperation.d.ts +10 -0
- package/lib/signOperation.d.ts.map +1 -0
- package/lib/signOperation.js +65 -0
- package/lib/signOperation.js.map +1 -0
- package/lib/signer.d.ts +16 -0
- package/lib/signer.d.ts.map +1 -0
- package/lib/signer.js +3 -0
- package/lib/signer.js.map +1 -0
- package/lib/specs.d.ts +7 -0
- package/lib/specs.d.ts.map +1 -0
- package/lib/specs.js +286 -0
- package/lib/specs.js.map +1 -0
- package/lib/speculos-deviceActions.d.ts +16 -0
- package/lib/speculos-deviceActions.d.ts.map +1 -0
- package/lib/speculos-deviceActions.js +250 -0
- package/lib/speculos-deviceActions.js.map +1 -0
- package/lib/synchronisation.d.ts +5 -0
- package/lib/synchronisation.d.ts.map +1 -0
- package/lib/synchronisation.js +69 -0
- package/lib/synchronisation.js.map +1 -0
- package/lib/transaction.d.ts +15 -0
- package/lib/transaction.d.ts.map +1 -0
- package/lib/transaction.js +62 -0
- package/lib/transaction.js.map +1 -0
- package/lib/types.d.ts +188 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +17 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/binary.utils.d.ts +5 -0
- package/lib/utils/binary.utils.d.ts.map +1 -0
- package/lib/utils/binary.utils.js +16 -0
- package/lib/utils/binary.utils.js.map +1 -0
- package/lib-es/api/apiCalls.d.ts +22 -0
- package/lib-es/api/apiCalls.d.ts.map +1 -0
- package/lib-es/api/apiCalls.js +147 -0
- package/lib-es/api/apiCalls.js.map +1 -0
- package/lib-es/api/dtos/multiversx-account.d.ts +9 -0
- package/lib-es/api/dtos/multiversx-account.d.ts.map +1 -0
- package/lib-es/api/dtos/multiversx-account.js +13 -0
- package/lib-es/api/dtos/multiversx-account.js.map +1 -0
- package/lib-es/api/index.d.ts +2 -0
- package/lib-es/api/index.d.ts.map +1 -0
- package/lib-es/api/index.js +2 -0
- package/lib-es/api/index.js.map +1 -0
- package/lib-es/api/sdk.d.ts +29 -0
- package/lib-es/api/sdk.d.ts.map +1 -0
- package/lib-es/api/sdk.js +264 -0
- package/lib-es/api/sdk.js.map +1 -0
- package/lib-es/bridge/js.d.ts +11 -0
- package/lib-es/bridge/js.d.ts.map +1 -0
- package/lib-es/bridge/js.js +53 -0
- package/lib-es/bridge/js.js.map +1 -0
- package/lib-es/bridge.integration.test.d.ts +4 -0
- package/lib-es/bridge.integration.test.d.ts.map +1 -0
- package/lib-es/bridge.integration.test.js +139 -0
- package/lib-es/bridge.integration.test.js.map +1 -0
- package/lib-es/broadcast.d.ts +9 -0
- package/lib-es/broadcast.d.ts.map +1 -0
- package/lib-es/broadcast.js +12 -0
- package/lib-es/broadcast.js.map +1 -0
- package/lib-es/buildOptimisticOperation.d.ts +4 -0
- package/lib-es/buildOptimisticOperation.d.ts.map +1 -0
- package/lib-es/buildOptimisticOperation.js +93 -0
- package/lib-es/buildOptimisticOperation.js.map +1 -0
- package/lib-es/buildOptimisticOperation.test.d.ts +2 -0
- package/lib-es/buildOptimisticOperation.test.d.ts.map +1 -0
- package/lib-es/buildOptimisticOperation.test.js +73 -0
- package/lib-es/buildOptimisticOperation.test.js.map +1 -0
- package/lib-es/buildSubAccounts.d.ts +11 -0
- package/lib-es/buildSubAccounts.d.ts.map +1 -0
- package/lib-es/buildSubAccounts.js +112 -0
- package/lib-es/buildSubAccounts.js.map +1 -0
- package/lib-es/buildTransaction.d.ts +19 -0
- package/lib-es/buildTransaction.d.ts.map +1 -0
- package/lib-es/buildTransaction.js +44 -0
- package/lib-es/buildTransaction.js.map +1 -0
- package/lib-es/buildTransaction.unit.test.d.ts +2 -0
- package/lib-es/buildTransaction.unit.test.d.ts.map +1 -0
- package/lib-es/buildTransaction.unit.test.js +42 -0
- package/lib-es/buildTransaction.unit.test.js.map +1 -0
- package/lib-es/cli-transaction.d.ts +16 -0
- package/lib-es/cli-transaction.d.ts.map +1 -0
- package/lib-es/cli-transaction.js +29 -0
- package/lib-es/cli-transaction.js.map +1 -0
- package/lib-es/config.d.ts +14 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +11 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/constants.d.ts +21 -0
- package/lib-es/constants.d.ts.map +1 -0
- package/lib-es/constants.js +21 -0
- package/lib-es/constants.js.map +1 -0
- package/lib-es/createTransaction.d.ts +9 -0
- package/lib-es/createTransaction.d.ts.map +1 -0
- package/lib-es/createTransaction.js +19 -0
- package/lib-es/createTransaction.js.map +1 -0
- package/lib-es/datasets/multiversx1.d.ts +3 -0
- package/lib-es/datasets/multiversx1.d.ts.map +1 -0
- package/lib-es/datasets/multiversx1.js +18 -0
- package/lib-es/datasets/multiversx1.js.map +1 -0
- package/lib-es/deviceTransactionConfig.d.ts +10 -0
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/deviceTransactionConfig.js +55 -0
- package/lib-es/deviceTransactionConfig.js.map +1 -0
- package/lib-es/encode.d.ts +11 -0
- package/lib-es/encode.d.ts.map +1 -0
- package/lib-es/encode.js +35 -0
- package/lib-es/encode.js.map +1 -0
- package/lib-es/errors.d.ts +16 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +7 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/estimateMaxSpendable.d.ts +10 -0
- package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/estimateMaxSpendable.js +31 -0
- package/lib-es/estimateMaxSpendable.js.map +1 -0
- package/lib-es/formatters.d.ts +11 -0
- package/lib-es/formatters.d.ts.map +1 -0
- package/lib-es/formatters.js +60 -0
- package/lib-es/formatters.js.map +1 -0
- package/lib-es/getTransactionStatus.d.ts +5 -0
- package/lib-es/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/getTransactionStatus.js +100 -0
- package/lib-es/getTransactionStatus.js.map +1 -0
- package/lib-es/helpers/denominate.d.ts +9 -0
- package/lib-es/helpers/denominate.d.ts.map +1 -0
- package/lib-es/helpers/denominate.js +71 -0
- package/lib-es/helpers/denominate.js.map +1 -0
- package/lib-es/helpers/handleTransactionStatus.d.ts +7 -0
- package/lib-es/helpers/handleTransactionStatus.d.ts.map +1 -0
- package/lib-es/helpers/handleTransactionStatus.js +14 -0
- package/lib-es/helpers/handleTransactionStatus.js.map +1 -0
- package/lib-es/helpers/hasMinimumDelegableBalance.d.ts +3 -0
- package/lib-es/helpers/hasMinimumDelegableBalance.d.ts.map +1 -0
- package/lib-es/helpers/hasMinimumDelegableBalance.js +3 -0
- package/lib-es/helpers/hasMinimumDelegableBalance.js.map +1 -0
- package/lib-es/helpers/randomizeProviders.d.ts +7 -0
- package/lib-es/helpers/randomizeProviders.d.ts.map +1 -0
- package/lib-es/helpers/randomizeProviders.js +8 -0
- package/lib-es/helpers/randomizeProviders.js.map +1 -0
- package/lib-es/hw-getAddress.d.ts +6 -0
- package/lib-es/hw-getAddress.d.ts.map +1 -0
- package/lib-es/hw-getAddress.js +12 -0
- package/lib-es/hw-getAddress.js.map +1 -0
- package/lib-es/logic.d.ts +15 -0
- package/lib-es/logic.d.ts.map +1 -0
- package/lib-es/logic.js +65 -0
- package/lib-es/logic.js.map +1 -0
- package/lib-es/preload.d.ts +11 -0
- package/lib-es/preload.d.ts.map +1 -0
- package/lib-es/preload.js +85 -0
- package/lib-es/preload.js.map +1 -0
- package/lib-es/prepareTransaction.d.ts +10 -0
- package/lib-es/prepareTransaction.d.ts.map +1 -0
- package/lib-es/prepareTransaction.js +68 -0
- package/lib-es/prepareTransaction.js.map +1 -0
- package/lib-es/reconciliation.d.ts +3 -0
- package/lib-es/reconciliation.d.ts.map +1 -0
- package/lib-es/reconciliation.js +52 -0
- package/lib-es/reconciliation.js.map +1 -0
- package/lib-es/serialization.d.ts +9 -0
- package/lib-es/serialization.d.ts.map +1 -0
- package/lib-es/serialization.js +53 -0
- package/lib-es/serialization.js.map +1 -0
- package/lib-es/signOperation.d.ts +10 -0
- package/lib-es/signOperation.d.ts.map +1 -0
- package/lib-es/signOperation.js +61 -0
- package/lib-es/signOperation.js.map +1 -0
- package/lib-es/signer.d.ts +16 -0
- package/lib-es/signer.d.ts.map +1 -0
- package/lib-es/signer.js +2 -0
- package/lib-es/signer.js.map +1 -0
- package/lib-es/specs.d.ts +7 -0
- package/lib-es/specs.d.ts.map +1 -0
- package/lib-es/specs.js +281 -0
- package/lib-es/specs.js.map +1 -0
- package/lib-es/speculos-deviceActions.d.ts +16 -0
- package/lib-es/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/speculos-deviceActions.js +244 -0
- package/lib-es/speculos-deviceActions.js.map +1 -0
- package/lib-es/synchronisation.d.ts +5 -0
- package/lib-es/synchronisation.d.ts.map +1 -0
- package/lib-es/synchronisation.js +62 -0
- package/lib-es/synchronisation.js.map +1 -0
- package/lib-es/transaction.d.ts +15 -0
- package/lib-es/transaction.d.ts.map +1 -0
- package/lib-es/transaction.js +56 -0
- package/lib-es/transaction.js.map +1 -0
- package/lib-es/types.d.ts +188 -0
- package/lib-es/types.d.ts.map +1 -0
- package/lib-es/types.js +12 -0
- package/lib-es/types.js.map +1 -0
- package/lib-es/utils/binary.utils.d.ts +5 -0
- package/lib-es/utils/binary.utils.d.ts.map +1 -0
- package/lib-es/utils/binary.utils.js +12 -0
- package/lib-es/utils/binary.utils.js.map +1 -0
- package/package.json +86 -0
- package/src/__snapshots__/bridge.integration.test.ts.snap +181 -0
- package/src/api/apiCalls.ts +243 -0
- package/src/api/dtos/multiversx-account.ts +20 -0
- package/src/api/index.ts +13 -0
- package/src/api/sdk.ts +368 -0
- package/src/bridge/js.ts +77 -0
- package/src/bridge.integration.test.ts +147 -0
- package/src/broadcast.ts +16 -0
- package/src/buildOptimisticOperation.test.ts +88 -0
- package/src/buildOptimisticOperation.ts +120 -0
- package/src/buildSubAccounts.ts +153 -0
- package/src/buildTransaction.ts +67 -0
- package/src/buildTransaction.unit.test.ts +49 -0
- package/src/cli-transaction.ts +41 -0
- package/src/config.ts +26 -0
- package/src/constants.ts +24 -0
- package/src/createTransaction.ts +21 -0
- package/src/datasets/multiversx1.ts +19 -0
- package/src/deviceTransactionConfig.ts +74 -0
- package/src/encode.ts +46 -0
- package/src/errors.ts +19 -0
- package/src/estimateMaxSpendable.ts +43 -0
- package/src/formatters.ts +76 -0
- package/src/getTransactionStatus.ts +151 -0
- package/src/helpers/denominate.ts +95 -0
- package/src/helpers/handleTransactionStatus.ts +26 -0
- package/src/helpers/hasMinimumDelegableBalance.ts +6 -0
- package/src/helpers/randomizeProviders.ts +20 -0
- package/src/hw-getAddress.ts +19 -0
- package/src/logic.ts +83 -0
- package/src/preload.ts +95 -0
- package/src/prepareTransaction.ts +78 -0
- package/src/reconciliation.ts +64 -0
- package/src/serialization.ts +72 -0
- package/src/signOperation.ts +99 -0
- package/src/signer.ts +21 -0
- package/src/specs.ts +387 -0
- package/src/speculos-deviceActions.ts +269 -0
- package/src/synchronisation.ts +74 -0
- package/src/transaction.ts +76 -0
- package/src/types.ts +235 -0
- package/src/utils/binary.utils.ts +13 -0
- package/tsconfig.json +13 -0
package/src/specs.ts
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MultiversXAccount,
|
|
3
|
+
MultiversXOperation,
|
|
4
|
+
MultiversXOperationRaw,
|
|
5
|
+
Transaction,
|
|
6
|
+
} from "./types";
|
|
7
|
+
import invariant from "invariant";
|
|
8
|
+
import { parseCurrencyUnit } from "@ledgerhq/coin-framework/currencies";
|
|
9
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
|
|
10
|
+
import { botTest, pickSiblings, genericTestDestination } from "@ledgerhq/coin-framework/bot/specs";
|
|
11
|
+
import type { AppSpec, TransactionTestInput } from "@ledgerhq/coin-framework/bot/types";
|
|
12
|
+
import { toOperationRaw } from "@ledgerhq/coin-framework/serialization";
|
|
13
|
+
import { DeviceModelId } from "@ledgerhq/devices";
|
|
14
|
+
import expect from "expect";
|
|
15
|
+
import {
|
|
16
|
+
acceptDelegateTransaction,
|
|
17
|
+
acceptEsdtTransferTransaction,
|
|
18
|
+
acceptMoveBalanceTransaction,
|
|
19
|
+
acceptUndelegateTransaction,
|
|
20
|
+
acceptWithdrawTransaction,
|
|
21
|
+
} from "./speculos-deviceActions";
|
|
22
|
+
import BigNumber from "bignumber.js";
|
|
23
|
+
import { MIN_DELEGATION_AMOUNT } from "./constants";
|
|
24
|
+
import { SubAccount } from "@ledgerhq/types-live";
|
|
25
|
+
import sample from "lodash/sample";
|
|
26
|
+
|
|
27
|
+
const currency = getCryptoCurrencyById("elrond");
|
|
28
|
+
const minimalAmount = parseCurrencyUnit(currency.units[0], "0.001");
|
|
29
|
+
const maxAccounts = 6;
|
|
30
|
+
|
|
31
|
+
const MULTIVERSX_MIN_ACTIVATION_SAFE = new BigNumber(10000);
|
|
32
|
+
const UNCAPPED_PROVIDER = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqlhllllsr0pd0j";
|
|
33
|
+
|
|
34
|
+
function expectCorrectBalanceChange(input: TransactionTestInput<Transaction>) {
|
|
35
|
+
const { account, operation, accountBeforeTransaction } = input;
|
|
36
|
+
|
|
37
|
+
botTest("EGLD balance change is correct", () =>
|
|
38
|
+
expect(account.balance.toFixed()).toStrictEqual(
|
|
39
|
+
accountBeforeTransaction.balance.minus(operation.value).toFixed(),
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function expectCorrectEsdtBalanceChange(input: TransactionTestInput<Transaction>) {
|
|
45
|
+
const { account, operation, accountBeforeTransaction, transaction } = input;
|
|
46
|
+
|
|
47
|
+
const { subAccountId } = transaction;
|
|
48
|
+
const subAccounts = account.subAccounts ?? [];
|
|
49
|
+
const subAccountsBefore = accountBeforeTransaction.subAccounts ?? [];
|
|
50
|
+
|
|
51
|
+
const tokenAccount = subAccounts.find(ta => ta.id === subAccountId);
|
|
52
|
+
const tokenAccountBefore = subAccountsBefore.find(ta => ta.id === subAccountId);
|
|
53
|
+
|
|
54
|
+
const subOperation = operation.subOperations?.find(sa => sa.id === operation.id);
|
|
55
|
+
|
|
56
|
+
if (tokenAccount && tokenAccountBefore && subOperation) {
|
|
57
|
+
botTest("ESDT balance change is correct", () =>
|
|
58
|
+
expect(tokenAccount.balance.toFixed()).toStrictEqual(
|
|
59
|
+
tokenAccountBefore.balance.minus(subOperation.value).toFixed(),
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function expectCorrectOptimisticOperation(input: TransactionTestInput<Transaction>) {
|
|
66
|
+
const { operation, optimisticOperation, transaction } = input;
|
|
67
|
+
|
|
68
|
+
const opExpected: Partial<MultiversXOperationRaw> = toOperationRaw({
|
|
69
|
+
...optimisticOperation,
|
|
70
|
+
}) as MultiversXOperationRaw;
|
|
71
|
+
delete opExpected.value;
|
|
72
|
+
delete opExpected.fee;
|
|
73
|
+
delete opExpected.date;
|
|
74
|
+
delete opExpected.blockHash;
|
|
75
|
+
delete opExpected.blockHeight;
|
|
76
|
+
|
|
77
|
+
if (operation.type !== "OUT") {
|
|
78
|
+
delete opExpected.senders;
|
|
79
|
+
delete opExpected.recipients;
|
|
80
|
+
delete opExpected.contract;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
botTest("optimistic operation matches id", () =>
|
|
84
|
+
expect(operation.id).toStrictEqual(optimisticOperation.id),
|
|
85
|
+
);
|
|
86
|
+
botTest("optimistic operation matches hash", () =>
|
|
87
|
+
expect(operation.hash).toStrictEqual(optimisticOperation.hash),
|
|
88
|
+
);
|
|
89
|
+
botTest("optimistic operation matches accountId", () =>
|
|
90
|
+
expect(operation.accountId).toStrictEqual(optimisticOperation.accountId),
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
// On ESDT transactions the fee can decrease when the transaction is executed
|
|
94
|
+
if (!transaction.subAccountId) {
|
|
95
|
+
botTest("optimistic operation matches fee", () =>
|
|
96
|
+
expect(operation.fee.toFixed()).toStrictEqual(optimisticOperation.fee.toFixed()),
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
botTest("optimistic operation matches type", () =>
|
|
101
|
+
expect(operation.type).toStrictEqual(optimisticOperation.type),
|
|
102
|
+
);
|
|
103
|
+
if (operation.type === "OUT") {
|
|
104
|
+
botTest("optimistic operation matches contract", () =>
|
|
105
|
+
expect(operation.contract).toStrictEqual(optimisticOperation.contract),
|
|
106
|
+
);
|
|
107
|
+
botTest("optimistic operation matches senders", () =>
|
|
108
|
+
expect(operation.senders).toStrictEqual(optimisticOperation.senders),
|
|
109
|
+
);
|
|
110
|
+
botTest("optimistic operation matches recipients", () =>
|
|
111
|
+
expect(operation.recipients).toStrictEqual(optimisticOperation.recipients),
|
|
112
|
+
);
|
|
113
|
+
if (!transaction.subAccountId) {
|
|
114
|
+
botTest("optimistic operation matches value", () =>
|
|
115
|
+
expect(operation.value.toFixed()).toStrictEqual(optimisticOperation.value.toFixed()),
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
botTest("optimistic operation matches transactionSequenceNumber", () =>
|
|
121
|
+
expect(operation.transactionSequenceNumber).toStrictEqual(
|
|
122
|
+
optimisticOperation.transactionSequenceNumber,
|
|
123
|
+
),
|
|
124
|
+
);
|
|
125
|
+
botTest("raw optimistic operation matches", () =>
|
|
126
|
+
expect(toOperationRaw(operation)).toMatchObject(opExpected),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function expectCorrectSpendableBalanceChange(input: TransactionTestInput<Transaction>) {
|
|
131
|
+
const { account, accountBeforeTransaction } = input;
|
|
132
|
+
const operation = input.operation as MultiversXOperation;
|
|
133
|
+
let value = operation.value;
|
|
134
|
+
if (operation.extra.amount) {
|
|
135
|
+
if (operation.type === "DELEGATE") {
|
|
136
|
+
value = value.plus(operation.extra.amount);
|
|
137
|
+
} else if (operation.type === "WITHDRAW_UNBONDED") {
|
|
138
|
+
value = value.minus(operation.extra.amount);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
botTest("EGLD spendable balance change is correct", () =>
|
|
143
|
+
expect(account.spendableBalance.toFixed()).toStrictEqual(
|
|
144
|
+
accountBeforeTransaction.spendableBalance.minus(value).toFixed(),
|
|
145
|
+
),
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function expectCorrectBalanceFeeChange(input: TransactionTestInput<Transaction>) {
|
|
150
|
+
const { account, operation, accountBeforeTransaction } = input;
|
|
151
|
+
botTest("Only change on balance is fees", () =>
|
|
152
|
+
expect(account.balance.toFixed()).toStrictEqual(
|
|
153
|
+
accountBeforeTransaction.balance.minus(operation.fee).toFixed(),
|
|
154
|
+
),
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const multiversx: AppSpec<Transaction> = {
|
|
159
|
+
name: "MultiversX",
|
|
160
|
+
currency: getCryptoCurrencyById("elrond"),
|
|
161
|
+
appQuery: {
|
|
162
|
+
model: DeviceModelId.nanoS,
|
|
163
|
+
appName: "MultiversX",
|
|
164
|
+
},
|
|
165
|
+
genericDeviceAction: acceptMoveBalanceTransaction,
|
|
166
|
+
genericDeviceActionForSubAccountTransfers: acceptEsdtTransferTransaction,
|
|
167
|
+
testTimeout: 2 * 60 * 1000,
|
|
168
|
+
minViableAmount: minimalAmount,
|
|
169
|
+
transactionCheck: ({ maxSpendable }) => {
|
|
170
|
+
invariant(maxSpendable.gt(minimalAmount), "balance is too low");
|
|
171
|
+
},
|
|
172
|
+
test: input => {
|
|
173
|
+
expectCorrectOptimisticOperation(input);
|
|
174
|
+
},
|
|
175
|
+
mutations: [
|
|
176
|
+
{
|
|
177
|
+
name: "send 50%~",
|
|
178
|
+
feature: "send",
|
|
179
|
+
maxRun: 1,
|
|
180
|
+
deviceAction: acceptMoveBalanceTransaction,
|
|
181
|
+
transaction: ({ account, siblings, bridge }) => {
|
|
182
|
+
invariant(account.spendableBalance.gt(0), "balance is 0");
|
|
183
|
+
const sibling = pickSiblings(siblings, maxAccounts);
|
|
184
|
+
let amount = account.spendableBalance.div(1.9 + 0.2 * Math.random()).integerValue();
|
|
185
|
+
|
|
186
|
+
if (!sibling.used && amount.lt(MULTIVERSX_MIN_ACTIVATION_SAFE)) {
|
|
187
|
+
invariant(
|
|
188
|
+
account.spendableBalance.gt(MULTIVERSX_MIN_ACTIVATION_SAFE),
|
|
189
|
+
"send is too low to activate account",
|
|
190
|
+
);
|
|
191
|
+
amount = MULTIVERSX_MIN_ACTIVATION_SAFE;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
transaction: bridge.createTransaction(account),
|
|
196
|
+
updates: [
|
|
197
|
+
{
|
|
198
|
+
recipient: sibling.freshAddress,
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
amount,
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
};
|
|
205
|
+
},
|
|
206
|
+
testDestination: genericTestDestination,
|
|
207
|
+
test: input => {
|
|
208
|
+
expectCorrectBalanceChange(input);
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
name: "send max",
|
|
213
|
+
feature: "sendMax",
|
|
214
|
+
maxRun: 1,
|
|
215
|
+
deviceAction: acceptMoveBalanceTransaction,
|
|
216
|
+
transaction: ({ account, siblings, bridge }) => {
|
|
217
|
+
invariant(account.spendableBalance.gt(0), "balance is 0");
|
|
218
|
+
const sibling = pickSiblings(siblings, maxAccounts);
|
|
219
|
+
|
|
220
|
+
if (!sibling.used) {
|
|
221
|
+
invariant(
|
|
222
|
+
account.spendableBalance.gt(MULTIVERSX_MIN_ACTIVATION_SAFE),
|
|
223
|
+
"send is too low to activate account",
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
transaction: bridge.createTransaction(account),
|
|
229
|
+
updates: [
|
|
230
|
+
{
|
|
231
|
+
recipient: sibling.freshAddress,
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
useAllAmount: true,
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
};
|
|
238
|
+
},
|
|
239
|
+
testDestination: genericTestDestination,
|
|
240
|
+
test: input => {
|
|
241
|
+
expectCorrectBalanceChange(input);
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
name: "move some ESDT",
|
|
246
|
+
feature: "tokens",
|
|
247
|
+
maxRun: 1,
|
|
248
|
+
deviceAction: acceptEsdtTransferTransaction,
|
|
249
|
+
transaction: ({ account, siblings, bridge }) => {
|
|
250
|
+
const esdtAccount: SubAccount | undefined = sample(
|
|
251
|
+
(account.subAccounts || []).filter(a => a.balance.gt(0)),
|
|
252
|
+
);
|
|
253
|
+
invariant(esdtAccount, "no esdt account");
|
|
254
|
+
|
|
255
|
+
invariant(esdtAccount?.balance.gt(0), "esdt balance is 0");
|
|
256
|
+
|
|
257
|
+
const sibling = pickSiblings(siblings, 2);
|
|
258
|
+
const recipient = sibling.freshAddress;
|
|
259
|
+
|
|
260
|
+
const amount = esdtAccount?.balance.times(Math.random()).integerValue();
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
transaction: bridge.createTransaction(account),
|
|
264
|
+
updates: [
|
|
265
|
+
{
|
|
266
|
+
subAccountId: esdtAccount?.id,
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
recipient,
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
amount,
|
|
273
|
+
},
|
|
274
|
+
],
|
|
275
|
+
};
|
|
276
|
+
},
|
|
277
|
+
test: input => {
|
|
278
|
+
expectCorrectEsdtBalanceChange(input);
|
|
279
|
+
expectCorrectBalanceFeeChange(input);
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
name: "delegate 1 EGLD",
|
|
284
|
+
feature: "staking",
|
|
285
|
+
maxRun: 1,
|
|
286
|
+
deviceAction: acceptDelegateTransaction,
|
|
287
|
+
transaction: ({ account, bridge }) => {
|
|
288
|
+
invariant(
|
|
289
|
+
account.spendableBalance.gt(MIN_DELEGATION_AMOUNT),
|
|
290
|
+
`spendable balance is less than minimum delegation amount`,
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
const amount = MIN_DELEGATION_AMOUNT;
|
|
294
|
+
|
|
295
|
+
return {
|
|
296
|
+
transaction: bridge.createTransaction(account),
|
|
297
|
+
updates: [
|
|
298
|
+
{
|
|
299
|
+
recipient: UNCAPPED_PROVIDER,
|
|
300
|
+
mode: "delegate",
|
|
301
|
+
amount,
|
|
302
|
+
},
|
|
303
|
+
],
|
|
304
|
+
};
|
|
305
|
+
},
|
|
306
|
+
test: input => {
|
|
307
|
+
expectCorrectSpendableBalanceChange(input);
|
|
308
|
+
expectCorrectBalanceFeeChange(input);
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
name: "unDelegate 1 EGLD",
|
|
313
|
+
feature: "staking",
|
|
314
|
+
maxRun: 1,
|
|
315
|
+
deviceAction: acceptUndelegateTransaction,
|
|
316
|
+
transaction: ({ account, bridge }) => {
|
|
317
|
+
const delegations = (account as MultiversXAccount)?.multiversxResources?.delegations;
|
|
318
|
+
invariant(delegations?.length, "account doesn't have any delegations");
|
|
319
|
+
invariant(
|
|
320
|
+
delegations.some(d => new BigNumber(d.userActiveStake).gt(0)),
|
|
321
|
+
"no active stake for account",
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
const amount = MIN_DELEGATION_AMOUNT;
|
|
325
|
+
|
|
326
|
+
return {
|
|
327
|
+
transaction: bridge.createTransaction(account),
|
|
328
|
+
updates: [
|
|
329
|
+
{
|
|
330
|
+
recipient: UNCAPPED_PROVIDER,
|
|
331
|
+
mode: "unDelegate",
|
|
332
|
+
amount,
|
|
333
|
+
},
|
|
334
|
+
],
|
|
335
|
+
};
|
|
336
|
+
},
|
|
337
|
+
test: input => {
|
|
338
|
+
expectCorrectSpendableBalanceChange(input);
|
|
339
|
+
expectCorrectBalanceFeeChange(input);
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
name: "withdraw all EGLD",
|
|
344
|
+
feature: "staking",
|
|
345
|
+
maxRun: 1,
|
|
346
|
+
deviceAction: acceptWithdrawTransaction,
|
|
347
|
+
transaction: ({ account, bridge }) => {
|
|
348
|
+
const delegations = (account as MultiversXAccount)?.multiversxResources?.delegations;
|
|
349
|
+
invariant(delegations?.length, "account doesn't have any delegations");
|
|
350
|
+
invariant(
|
|
351
|
+
// among all delegations
|
|
352
|
+
delegations.some(d =>
|
|
353
|
+
// among all undelegating amounts
|
|
354
|
+
d.userUndelegatedList?.some(
|
|
355
|
+
u =>
|
|
356
|
+
new BigNumber(u.amount).gt(0) && // the undelegation has a positive amount
|
|
357
|
+
new BigNumber(u.seconds).eq(0), // the undelegation period has ended
|
|
358
|
+
),
|
|
359
|
+
),
|
|
360
|
+
"no withdrawable stake for account",
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
return {
|
|
364
|
+
transaction: bridge.createTransaction(account),
|
|
365
|
+
updates: [
|
|
366
|
+
{
|
|
367
|
+
recipient: UNCAPPED_PROVIDER,
|
|
368
|
+
mode: "withdraw",
|
|
369
|
+
amount: new BigNumber(0),
|
|
370
|
+
},
|
|
371
|
+
],
|
|
372
|
+
};
|
|
373
|
+
},
|
|
374
|
+
test: input => {
|
|
375
|
+
expectCorrectSpendableBalanceChange(input);
|
|
376
|
+
expectCorrectBalanceFeeChange(input);
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
// TODO
|
|
380
|
+
// "reDelegateRewards"
|
|
381
|
+
// "claimRewards"
|
|
382
|
+
],
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
export default {
|
|
386
|
+
multiversx,
|
|
387
|
+
};
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import type { DeviceAction } from "@ledgerhq/coin-framework/bot/types";
|
|
3
|
+
import type { Transaction } from "./types";
|
|
4
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies";
|
|
5
|
+
import {
|
|
6
|
+
deviceActionFlow,
|
|
7
|
+
formatDeviceAmount,
|
|
8
|
+
SpeculosButton,
|
|
9
|
+
} from "@ledgerhq/coin-framework/bot/specs";
|
|
10
|
+
import { decodeTokenAccountId } from "@ledgerhq/coin-framework/account";
|
|
11
|
+
|
|
12
|
+
export const acceptMoveBalanceTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
13
|
+
steps: [
|
|
14
|
+
{
|
|
15
|
+
title: "Receiver",
|
|
16
|
+
button: SpeculosButton.RIGHT,
|
|
17
|
+
expectedValue: ({ transaction }) => transaction.recipient,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
title: "Amount",
|
|
21
|
+
button: SpeculosButton.RIGHT,
|
|
22
|
+
expectedValue: ({ account, status }) => {
|
|
23
|
+
return formatDeviceAmount(account.currency, status.amount, {
|
|
24
|
+
postfixCode: true,
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
title: "Fee",
|
|
30
|
+
button: SpeculosButton.RIGHT,
|
|
31
|
+
expectedValue: ({ account, transaction }) =>
|
|
32
|
+
formatCurrencyUnit(account.currency.units[0], transaction.fees || new BigNumber(50000), {
|
|
33
|
+
showCode: true,
|
|
34
|
+
disableRounding: true,
|
|
35
|
+
joinFragmentsSeparator: " ",
|
|
36
|
+
}).replace(/\s+/g, " "),
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
title: "Data",
|
|
40
|
+
button: SpeculosButton.RIGHT,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
title: "Sign",
|
|
44
|
+
button: SpeculosButton.BOTH,
|
|
45
|
+
final: true,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
title: "Network",
|
|
49
|
+
button: SpeculosButton.RIGHT,
|
|
50
|
+
expectedValue: () => "Mainnet",
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export const acceptDelegateTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
56
|
+
steps: [
|
|
57
|
+
{
|
|
58
|
+
title: "Receiver",
|
|
59
|
+
button: SpeculosButton.RIGHT,
|
|
60
|
+
expectedValue: ({ transaction }) => transaction.recipient,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
title: "Amount",
|
|
64
|
+
button: SpeculosButton.RIGHT,
|
|
65
|
+
expectedValue: ({ account, transaction }) =>
|
|
66
|
+
formatCurrencyUnit(account.currency.units[0], transaction.amount, {
|
|
67
|
+
showCode: true,
|
|
68
|
+
disableRounding: true,
|
|
69
|
+
joinFragmentsSeparator: " ",
|
|
70
|
+
}).replace(/\s+/g, " "),
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
title: "Fee",
|
|
74
|
+
button: SpeculosButton.RIGHT,
|
|
75
|
+
expectedValue: ({ account, transaction }) =>
|
|
76
|
+
formatCurrencyUnit(account.currency.units[0], transaction.fees || new BigNumber(50000), {
|
|
77
|
+
showCode: true,
|
|
78
|
+
disableRounding: true,
|
|
79
|
+
joinFragmentsSeparator: " ",
|
|
80
|
+
}).replace(/\s+/g, " "),
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
title: "Data",
|
|
84
|
+
button: SpeculosButton.RIGHT,
|
|
85
|
+
expectedValue: () => "[Size: 8] delegate",
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
title: "Sign",
|
|
89
|
+
button: SpeculosButton.BOTH,
|
|
90
|
+
final: true,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
title: "Network",
|
|
94
|
+
button: SpeculosButton.RIGHT,
|
|
95
|
+
expectedValue: () => "Mainnet",
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
export const acceptUndelegateTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
101
|
+
steps: [
|
|
102
|
+
{
|
|
103
|
+
title: "Receiver",
|
|
104
|
+
button: SpeculosButton.RIGHT,
|
|
105
|
+
expectedValue: ({ transaction }) => transaction.recipient,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
title: "Amount",
|
|
109
|
+
button: SpeculosButton.RIGHT,
|
|
110
|
+
expectedValue: ({ account }) =>
|
|
111
|
+
formatCurrencyUnit(account.currency.units[0], new BigNumber(0), {
|
|
112
|
+
showCode: true,
|
|
113
|
+
disableRounding: true,
|
|
114
|
+
joinFragmentsSeparator: " ",
|
|
115
|
+
}).replace(/\s+/g, " "),
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
title: "Fee",
|
|
119
|
+
button: SpeculosButton.RIGHT,
|
|
120
|
+
expectedValue: ({ account, transaction }) =>
|
|
121
|
+
formatCurrencyUnit(account.currency.units[0], transaction.fees || new BigNumber(50000), {
|
|
122
|
+
showCode: true,
|
|
123
|
+
disableRounding: true,
|
|
124
|
+
joinFragmentsSeparator: " ",
|
|
125
|
+
}).replace(/\s+/g, " "),
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
title: "Data",
|
|
129
|
+
button: SpeculosButton.RIGHT,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
title: "Sign",
|
|
133
|
+
button: SpeculosButton.BOTH,
|
|
134
|
+
final: true,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
title: "Network",
|
|
138
|
+
button: SpeculosButton.RIGHT,
|
|
139
|
+
expectedValue: () => "Mainnet",
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
export const acceptWithdrawTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
145
|
+
steps: [
|
|
146
|
+
{
|
|
147
|
+
title: "Receiver",
|
|
148
|
+
button: SpeculosButton.RIGHT,
|
|
149
|
+
expectedValue: ({ transaction }) => transaction.recipient,
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
title: "Amount",
|
|
153
|
+
button: SpeculosButton.RIGHT,
|
|
154
|
+
expectedValue: ({ account }) =>
|
|
155
|
+
formatCurrencyUnit(account.currency.units[0], new BigNumber(0), {
|
|
156
|
+
showCode: true,
|
|
157
|
+
disableRounding: true,
|
|
158
|
+
joinFragmentsSeparator: " ",
|
|
159
|
+
}).replace(/\s+/g, " "),
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
title: "Fee",
|
|
163
|
+
button: SpeculosButton.RIGHT,
|
|
164
|
+
expectedValue: ({ account, transaction }) =>
|
|
165
|
+
formatCurrencyUnit(account.currency.units[0], transaction.fees || new BigNumber(50000), {
|
|
166
|
+
showCode: true,
|
|
167
|
+
disableRounding: true,
|
|
168
|
+
joinFragmentsSeparator: " ",
|
|
169
|
+
}).replace(/\s+/g, " "),
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
title: "Data",
|
|
173
|
+
button: SpeculosButton.RIGHT,
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
title: "Sign",
|
|
177
|
+
button: SpeculosButton.BOTH,
|
|
178
|
+
final: true,
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
title: "Network",
|
|
182
|
+
button: SpeculosButton.RIGHT,
|
|
183
|
+
expectedValue: () => "Mainnet",
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
export const acceptEsdtTransferTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
189
|
+
steps: [
|
|
190
|
+
{
|
|
191
|
+
title: "Token",
|
|
192
|
+
button: SpeculosButton.RIGHT,
|
|
193
|
+
expectedValue: ({ account, transaction }) => {
|
|
194
|
+
const { subAccounts } = account;
|
|
195
|
+
const { subAccountId } = transaction;
|
|
196
|
+
const tokenAccount = !subAccountId
|
|
197
|
+
? null
|
|
198
|
+
: subAccounts && subAccounts.find(ta => ta.id === subAccountId);
|
|
199
|
+
|
|
200
|
+
if (!tokenAccount) {
|
|
201
|
+
throw new Error();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const { token } = decodeTokenAccountId(tokenAccount.id);
|
|
205
|
+
|
|
206
|
+
return token?.name ?? "";
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
title: "Value",
|
|
211
|
+
button: SpeculosButton.RIGHT,
|
|
212
|
+
expectedValue: ({ account, transaction }) => {
|
|
213
|
+
const { subAccounts } = account;
|
|
214
|
+
const { subAccountId } = transaction;
|
|
215
|
+
const tokenAccount = !subAccountId
|
|
216
|
+
? null
|
|
217
|
+
: subAccounts && subAccounts.find(ta => ta.id === subAccountId);
|
|
218
|
+
|
|
219
|
+
if (!tokenAccount) {
|
|
220
|
+
throw new Error();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const { token } = decodeTokenAccountId(tokenAccount.id);
|
|
224
|
+
if (!token) {
|
|
225
|
+
throw new Error();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return formatCurrencyUnit(token.units[0], transaction.amount, {
|
|
229
|
+
showCode: true,
|
|
230
|
+
disableRounding: true,
|
|
231
|
+
joinFragmentsSeparator: " ",
|
|
232
|
+
}).replace(/\s+/g, " ");
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
title: "Receiver",
|
|
237
|
+
button: SpeculosButton.RIGHT,
|
|
238
|
+
expectedValue: ({ transaction }) => transaction.recipient,
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
title: "Fee",
|
|
242
|
+
button: SpeculosButton.RIGHT,
|
|
243
|
+
expectedValue: ({ account, transaction }) =>
|
|
244
|
+
formatCurrencyUnit(account.currency.units[0], transaction.fees || new BigNumber(50000), {
|
|
245
|
+
showCode: true,
|
|
246
|
+
disableRounding: true,
|
|
247
|
+
joinFragmentsSeparator: " ",
|
|
248
|
+
}).replace(/\s+/g, " "),
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
title: "Confirm transfer",
|
|
252
|
+
button: SpeculosButton.BOTH,
|
|
253
|
+
final: true,
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
title: "Network",
|
|
257
|
+
button: SpeculosButton.RIGHT,
|
|
258
|
+
expectedValue: () => "Mainnet",
|
|
259
|
+
},
|
|
260
|
+
],
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
export default {
|
|
264
|
+
acceptMoveBalanceTransaction,
|
|
265
|
+
acceptEsdtTransferTransaction,
|
|
266
|
+
acceptDelegateTransaction,
|
|
267
|
+
acceptUndelegateTransaction,
|
|
268
|
+
acceptWithdrawTransaction,
|
|
269
|
+
};
|