@ledgerhq/coin-cardano 0.1.0-next.0
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 +20 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +35 -0
- package/CHANGELOG.md +19 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/lib/account.d.ts +7 -0
- package/lib/account.d.ts.map +1 -0
- package/lib/account.js +41 -0
- package/lib/account.js.map +1 -0
- package/lib/address.unit.test.d.ts +2 -0
- package/lib/address.unit.test.d.ts.map +1 -0
- package/lib/address.unit.test.js +21 -0
- package/lib/address.unit.test.js.map +1 -0
- package/lib/api/api-types.d.ts +106 -0
- package/lib/api/api-types.d.ts.map +1 -0
- package/lib/api/api-types.js +9 -0
- package/lib/api/api-types.js.map +1 -0
- package/lib/api/getDelegationInfo.d.ts +4 -0
- package/lib/api/getDelegationInfo.d.ts.map +1 -0
- package/lib/api/getDelegationInfo.js +48 -0
- package/lib/api/getDelegationInfo.js.map +1 -0
- package/lib/api/getNetworkInfo.d.ts +5 -0
- package/lib/api/getNetworkInfo.d.ts.map +1 -0
- package/lib/api/getNetworkInfo.js +46 -0
- package/lib/api/getNetworkInfo.js.map +1 -0
- package/lib/api/getPools.d.ts +5 -0
- package/lib/api/getPools.d.ts.map +1 -0
- package/lib/api/getPools.js +45 -0
- package/lib/api/getPools.js.map +1 -0
- package/lib/api/getTransactions.d.ts +10 -0
- package/lib/api/getTransactions.d.ts.map +1 -0
- package/lib/api/getTransactions.js +139 -0
- package/lib/api/getTransactions.js.map +1 -0
- package/lib/api/submitTransaction.d.ts +7 -0
- package/lib/api/submitTransaction.d.ts.map +1 -0
- package/lib/api/submitTransaction.js +34 -0
- package/lib/api/submitTransaction.js.map +1 -0
- package/lib/bridge/index.d.ts +11 -0
- package/lib/bridge/index.d.ts.map +1 -0
- package/lib/bridge/index.js +70 -0
- package/lib/bridge/index.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 +113 -0
- package/lib/bridge.integration.test.js.map +1 -0
- package/lib/broadcast.d.ts +8 -0
- package/lib/broadcast.d.ts.map +1 -0
- package/lib/broadcast.js +28 -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 +125 -0
- package/lib/buildOptimisticOperation.js.map +1 -0
- package/lib/buildSubAccounts.d.ts +26 -0
- package/lib/buildSubAccounts.d.ts.map +1 -0
- package/lib/buildSubAccounts.js +124 -0
- package/lib/buildSubAccounts.js.map +1 -0
- package/lib/buildTransaction.d.ts +11 -0
- package/lib/buildTransaction.d.ts.map +1 -0
- package/lib/buildTransaction.js +342 -0
- package/lib/buildTransaction.js.map +1 -0
- package/lib/cli-transaction.d.ts +18 -0
- package/lib/cli-transaction.d.ts.map +1 -0
- package/lib/cli-transaction.js +66 -0
- package/lib/cli-transaction.js.map +1 -0
- package/lib/constants.d.ts +8 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +12 -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 +23 -0
- package/lib/createTransaction.js.map +1 -0
- package/lib/datasets/rawAccount.1.d.ts +3 -0
- package/lib/datasets/rawAccount.1.d.ts.map +1 -0
- package/lib/datasets/rawAccount.1.js +20 -0
- package/lib/datasets/rawAccount.1.js.map +1 -0
- package/lib/datasets/scanAccounts.d.ts +5 -0
- package/lib/datasets/scanAccounts.d.ts.map +1 -0
- package/lib/datasets/scanAccounts.js +27 -0
- package/lib/datasets/scanAccounts.js.map +1 -0
- package/lib/deviceTransactionConfig.d.ts +11 -0
- package/lib/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/deviceTransactionConfig.js +106 -0
- package/lib/deviceTransactionConfig.js.map +1 -0
- package/lib/errors.d.ts +22 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +18 -0
- package/lib/errors.js.map +1 -0
- package/lib/estimateMaxSpendable.d.ts +9 -0
- package/lib/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/estimateMaxSpendable.js +53 -0
- package/lib/estimateMaxSpendable.js.map +1 -0
- package/lib/getTransactionStatus.d.ts +4 -0
- package/lib/getTransactionStatus.d.ts.map +1 -0
- package/lib/getTransactionStatus.js +214 -0
- package/lib/getTransactionStatus.js.map +1 -0
- package/lib/getTransactionStatus.unit.test.d.ts +2 -0
- package/lib/getTransactionStatus.unit.test.d.ts.map +1 -0
- package/lib/getTransactionStatus.unit.test.js +54 -0
- package/lib/getTransactionStatus.unit.test.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 +37 -0
- package/lib/hw-getAddress.js.map +1 -0
- package/lib/logic.d.ts +88 -0
- package/lib/logic.d.ts.map +1 -0
- package/lib/logic.js +264 -0
- package/lib/logic.js.map +1 -0
- package/lib/logic.unit.test.d.ts +2 -0
- package/lib/logic.unit.test.d.ts.map +1 -0
- package/lib/logic.unit.test.js +40 -0
- package/lib/logic.unit.test.js.map +1 -0
- package/lib/networks.d.ts +3 -0
- package/lib/networks.d.ts.map +1 -0
- package/lib/networks.js +36 -0
- package/lib/networks.js.map +1 -0
- package/lib/postSyncPatch.d.ts +6 -0
- package/lib/postSyncPatch.d.ts.map +1 -0
- package/lib/postSyncPatch.js +35 -0
- package/lib/postSyncPatch.js.map +1 -0
- package/lib/prepareTransaction.d.ts +10 -0
- package/lib/prepareTransaction.d.ts.map +1 -0
- package/lib/prepareTransaction.js +44 -0
- package/lib/prepareTransaction.js.map +1 -0
- package/lib/serialization.d.ts +7 -0
- package/lib/serialization.d.ts.map +1 -0
- package/lib/serialization.js +146 -0
- package/lib/serialization.js.map +1 -0
- package/lib/signOperation.d.ts +9 -0
- package/lib/signOperation.d.ts.map +1 -0
- package/lib/signOperation.js +71 -0
- package/lib/signOperation.js.map +1 -0
- package/lib/signer.d.ts +92 -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 +218 -0
- package/lib/specs.js.map +1 -0
- package/lib/speculos-deviceActions.d.ts +4 -0
- package/lib/speculos-deviceActions.d.ts.map +1 -0
- package/lib/speculos-deviceActions.js +128 -0
- package/lib/speculos-deviceActions.js.map +1 -0
- package/lib/synchronisation.d.ts +6 -0
- package/lib/synchronisation.d.ts.map +1 -0
- package/lib/synchronisation.js +237 -0
- package/lib/synchronisation.js.map +1 -0
- package/lib/synchronisation.unit.test.d.ts +2 -0
- package/lib/synchronisation.unit.test.d.ts.map +1 -0
- package/lib/synchronisation.unit.test.js +129 -0
- package/lib/synchronisation.unit.test.js.map +1 -0
- package/lib/transaction.d.ts +15 -0
- package/lib/transaction.d.ts.map +1 -0
- package/lib/transaction.js +43 -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 +18 -0
- package/lib/types.js.map +1 -0
- package/lib/typhonSerializer.d.ts +17 -0
- package/lib/typhonSerializer.d.ts.map +1 -0
- package/lib/typhonSerializer.js +213 -0
- package/lib/typhonSerializer.js.map +1 -0
- package/lib/utils.d.ts +2 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +8 -0
- package/lib/utils.js.map +1 -0
- package/lib-es/account.d.ts +7 -0
- package/lib-es/account.d.ts.map +1 -0
- package/lib-es/account.js +34 -0
- package/lib-es/account.js.map +1 -0
- package/lib-es/address.unit.test.d.ts +2 -0
- package/lib-es/address.unit.test.d.ts.map +1 -0
- package/lib-es/address.unit.test.js +19 -0
- package/lib-es/address.unit.test.js.map +1 -0
- package/lib-es/api/api-types.d.ts +106 -0
- package/lib-es/api/api-types.d.ts.map +1 -0
- package/lib-es/api/api-types.js +6 -0
- package/lib-es/api/api-types.js.map +1 -0
- package/lib-es/api/getDelegationInfo.d.ts +4 -0
- package/lib-es/api/getDelegationInfo.d.ts.map +1 -0
- package/lib-es/api/getDelegationInfo.js +41 -0
- package/lib-es/api/getDelegationInfo.js.map +1 -0
- package/lib-es/api/getNetworkInfo.d.ts +5 -0
- package/lib-es/api/getNetworkInfo.d.ts.map +1 -0
- package/lib-es/api/getNetworkInfo.js +39 -0
- package/lib-es/api/getNetworkInfo.js.map +1 -0
- package/lib-es/api/getPools.d.ts +5 -0
- package/lib-es/api/getPools.d.ts.map +1 -0
- package/lib-es/api/getPools.js +37 -0
- package/lib-es/api/getPools.js.map +1 -0
- package/lib-es/api/getTransactions.d.ts +10 -0
- package/lib-es/api/getTransactions.d.ts.map +1 -0
- package/lib-es/api/getTransactions.js +132 -0
- package/lib-es/api/getTransactions.js.map +1 -0
- package/lib-es/api/submitTransaction.d.ts +7 -0
- package/lib-es/api/submitTransaction.d.ts.map +1 -0
- package/lib-es/api/submitTransaction.js +27 -0
- package/lib-es/api/submitTransaction.js.map +1 -0
- package/lib-es/bridge/index.d.ts +11 -0
- package/lib-es/bridge/index.d.ts.map +1 -0
- package/lib-es/bridge/index.js +61 -0
- package/lib-es/bridge/index.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 +107 -0
- package/lib-es/bridge.integration.test.js.map +1 -0
- package/lib-es/broadcast.d.ts +8 -0
- package/lib-es/broadcast.d.ts.map +1 -0
- package/lib-es/broadcast.js +24 -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 +118 -0
- package/lib-es/buildOptimisticOperation.js.map +1 -0
- package/lib-es/buildSubAccounts.d.ts +26 -0
- package/lib-es/buildSubAccounts.d.ts.map +1 -0
- package/lib-es/buildSubAccounts.js +114 -0
- package/lib-es/buildSubAccounts.js.map +1 -0
- package/lib-es/buildTransaction.d.ts +11 -0
- package/lib-es/buildTransaction.d.ts.map +1 -0
- package/lib-es/buildTransaction.js +335 -0
- package/lib-es/buildTransaction.js.map +1 -0
- package/lib-es/cli-transaction.d.ts +18 -0
- package/lib-es/cli-transaction.d.ts.map +1 -0
- package/lib-es/cli-transaction.js +60 -0
- package/lib-es/cli-transaction.js.map +1 -0
- package/lib-es/constants.d.ts +8 -0
- package/lib-es/constants.d.ts.map +1 -0
- package/lib-es/constants.js +9 -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 +16 -0
- package/lib-es/createTransaction.js.map +1 -0
- package/lib-es/datasets/rawAccount.1.d.ts +3 -0
- package/lib-es/datasets/rawAccount.1.d.ts.map +1 -0
- package/lib-es/datasets/rawAccount.1.js +17 -0
- package/lib-es/datasets/rawAccount.1.js.map +1 -0
- package/lib-es/datasets/scanAccounts.d.ts +5 -0
- package/lib-es/datasets/scanAccounts.d.ts.map +1 -0
- package/lib-es/datasets/scanAccounts.js +24 -0
- package/lib-es/datasets/scanAccounts.js.map +1 -0
- package/lib-es/deviceTransactionConfig.d.ts +11 -0
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/deviceTransactionConfig.js +101 -0
- package/lib-es/deviceTransactionConfig.js.map +1 -0
- package/lib-es/errors.d.ts +22 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +15 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/estimateMaxSpendable.d.ts +9 -0
- package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/estimateMaxSpendable.js +49 -0
- package/lib-es/estimateMaxSpendable.js.map +1 -0
- package/lib-es/getTransactionStatus.d.ts +4 -0
- package/lib-es/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/getTransactionStatus.js +210 -0
- package/lib-es/getTransactionStatus.js.map +1 -0
- package/lib-es/getTransactionStatus.unit.test.d.ts +2 -0
- package/lib-es/getTransactionStatus.unit.test.d.ts.map +1 -0
- package/lib-es/getTransactionStatus.unit.test.js +49 -0
- package/lib-es/getTransactionStatus.unit.test.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 +35 -0
- package/lib-es/hw-getAddress.js.map +1 -0
- package/lib-es/logic.d.ts +88 -0
- package/lib-es/logic.d.ts.map +1 -0
- package/lib-es/logic.js +236 -0
- package/lib-es/logic.js.map +1 -0
- package/lib-es/logic.unit.test.d.ts +2 -0
- package/lib-es/logic.unit.test.d.ts.map +1 -0
- package/lib-es/logic.unit.test.js +35 -0
- package/lib-es/logic.unit.test.js.map +1 -0
- package/lib-es/networks.d.ts +3 -0
- package/lib-es/networks.d.ts.map +1 -0
- package/lib-es/networks.js +32 -0
- package/lib-es/networks.js.map +1 -0
- package/lib-es/postSyncPatch.d.ts +6 -0
- package/lib-es/postSyncPatch.d.ts.map +1 -0
- package/lib-es/postSyncPatch.js +31 -0
- package/lib-es/postSyncPatch.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 +40 -0
- package/lib-es/prepareTransaction.js.map +1 -0
- package/lib-es/serialization.d.ts +7 -0
- package/lib-es/serialization.d.ts.map +1 -0
- package/lib-es/serialization.js +139 -0
- package/lib-es/serialization.js.map +1 -0
- package/lib-es/signOperation.d.ts +9 -0
- package/lib-es/signOperation.d.ts.map +1 -0
- package/lib-es/signOperation.js +64 -0
- package/lib-es/signOperation.js.map +1 -0
- package/lib-es/signer.d.ts +92 -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 +213 -0
- package/lib-es/specs.js.map +1 -0
- package/lib-es/speculos-deviceActions.d.ts +4 -0
- package/lib-es/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/speculos-deviceActions.js +125 -0
- package/lib-es/speculos-deviceActions.js.map +1 -0
- package/lib-es/synchronisation.d.ts +6 -0
- package/lib-es/synchronisation.d.ts.map +1 -0
- package/lib-es/synchronisation.js +230 -0
- package/lib-es/synchronisation.js.map +1 -0
- package/lib-es/synchronisation.unit.test.d.ts +2 -0
- package/lib-es/synchronisation.unit.test.d.ts.map +1 -0
- package/lib-es/synchronisation.unit.test.js +124 -0
- package/lib-es/synchronisation.unit.test.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 +37 -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 +15 -0
- package/lib-es/types.js.map +1 -0
- package/lib-es/typhonSerializer.d.ts +17 -0
- package/lib-es/typhonSerializer.d.ts.map +1 -0
- package/lib-es/typhonSerializer.js +207 -0
- package/lib-es/typhonSerializer.js.map +1 -0
- package/lib-es/utils.d.ts +2 -0
- package/lib-es/utils.d.ts.map +1 -0
- package/lib-es/utils.js +5 -0
- package/lib-es/utils.js.map +1 -0
- package/package.json +91 -0
- package/src/account.ts +39 -0
- package/src/address.unit.test.ts +32 -0
- package/src/api/api-types.ts +115 -0
- package/src/api/getDelegationInfo.ts +39 -0
- package/src/api/getNetworkInfo.ts +34 -0
- package/src/api/getPools.ts +35 -0
- package/src/api/getTransactions.ts +218 -0
- package/src/api/submitTransaction.ts +24 -0
- package/src/bridge/index.ts +69 -0
- package/src/bridge.integration.test.ts +113 -0
- package/src/broadcast.ts +21 -0
- package/src/buildOptimisticOperation.ts +181 -0
- package/src/buildSubAccounts.ts +170 -0
- package/src/buildTransaction.ts +435 -0
- package/src/cli-transaction.ts +82 -0
- package/src/constants.ts +10 -0
- package/src/createTransaction.ts +18 -0
- package/src/datasets/rawAccount.1.ts +19 -0
- package/src/datasets/scanAccounts.ts +23 -0
- package/src/deviceTransactionConfig.ts +128 -0
- package/src/errors.ts +18 -0
- package/src/estimateMaxSpendable.ts +61 -0
- package/src/getTransactionStatus.ts +251 -0
- package/src/getTransactionStatus.unit.test.ts +45 -0
- package/src/hw-getAddress.ts +37 -0
- package/src/logic.ts +330 -0
- package/src/logic.unit.test.ts +39 -0
- package/src/networks.ts +33 -0
- package/src/postSyncPatch.ts +42 -0
- package/src/prepareTransaction.ts +41 -0
- package/src/serialization.ts +219 -0
- package/src/signOperation.ts +82 -0
- package/src/signer.ts +98 -0
- package/src/specs.ts +253 -0
- package/src/speculos-deviceActions.ts +132 -0
- package/src/synchronisation.ts +347 -0
- package/src/synchronisation.unit.test.ts +137 -0
- package/src/transaction.ts +66 -0
- package/src/types.ts +227 -0
- package/src/typhonSerializer.ts +259 -0
- package/src/utils.ts +4 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import uniqBy from "lodash/uniqBy";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
import {
|
|
4
|
+
AccountShapeInfo,
|
|
5
|
+
GetAccountShape,
|
|
6
|
+
mergeOps,
|
|
7
|
+
} from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
8
|
+
import { utils as TyphonUtils } from "@stricahq/typhonjs";
|
|
9
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
10
|
+
import { listTokensForCryptoCurrency } from "@ledgerhq/cryptoassets";
|
|
11
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
12
|
+
import { encodeAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
13
|
+
import { calculateMinUtxoAmount } from "@stricahq/typhonjs/dist/utils/utils";
|
|
14
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
|
|
15
|
+
import { inferSubOperations } from "@ledgerhq/coin-framework/serialization/index";
|
|
16
|
+
import type { Operation, OperationType, TokenAccount } from "@ledgerhq/types-live";
|
|
17
|
+
import { getDelegationInfo } from "./api/getDelegationInfo";
|
|
18
|
+
import { APITransaction, HashType } from "./api/api-types";
|
|
19
|
+
import { getTransactions } from "./api/getTransactions";
|
|
20
|
+
import { getNetworkInfo } from "./api/getNetworkInfo";
|
|
21
|
+
import { buildSubAccounts } from "./buildSubAccounts";
|
|
22
|
+
import { getNetworkParameters } from "./networks";
|
|
23
|
+
import { CardanoSigner } from "./signer";
|
|
24
|
+
import {
|
|
25
|
+
CardanoAccount,
|
|
26
|
+
CardanoOperation,
|
|
27
|
+
CardanoOperationExtra,
|
|
28
|
+
CardanoOutput,
|
|
29
|
+
PaymentCredential,
|
|
30
|
+
ProtocolParams,
|
|
31
|
+
StakeCredential,
|
|
32
|
+
} from "./types";
|
|
33
|
+
import {
|
|
34
|
+
getAccountChange,
|
|
35
|
+
getAccountStakeCredential,
|
|
36
|
+
getBaseAddress,
|
|
37
|
+
getBipPathString,
|
|
38
|
+
getMemoFromTx,
|
|
39
|
+
getOperationType,
|
|
40
|
+
isHexString,
|
|
41
|
+
mergeTokens,
|
|
42
|
+
} from "./logic";
|
|
43
|
+
|
|
44
|
+
export const makeGetAccountShape =
|
|
45
|
+
(signerContext: SignerContext<CardanoSigner>): GetAccountShape<CardanoAccount> =>
|
|
46
|
+
async (info, { blacklistedTokenIds }) => {
|
|
47
|
+
const {
|
|
48
|
+
currency,
|
|
49
|
+
index: accountIndex,
|
|
50
|
+
derivationPath,
|
|
51
|
+
derivationMode,
|
|
52
|
+
initialAccount,
|
|
53
|
+
deviceId,
|
|
54
|
+
} = info;
|
|
55
|
+
// In case we get a full derivation path
|
|
56
|
+
const rootPath = derivationPath.split("/", 2).join("/");
|
|
57
|
+
const accountPath = `${rootPath}/${accountIndex}'`;
|
|
58
|
+
|
|
59
|
+
const paramXpub = initialAccount?.xpub;
|
|
60
|
+
let xpub;
|
|
61
|
+
if (!paramXpub) {
|
|
62
|
+
if (deviceId === undefined || deviceId === null) {
|
|
63
|
+
// deviceId not provided
|
|
64
|
+
throw new Error("deviceId required to generate the xpub");
|
|
65
|
+
}
|
|
66
|
+
const extendedPubKeyRes = await signerContext(deviceId, signer =>
|
|
67
|
+
signer.getPublicKey(accountPath),
|
|
68
|
+
);
|
|
69
|
+
xpub = `${extendedPubKeyRes.publicKeyHex}${extendedPubKeyRes.chainCodeHex}`;
|
|
70
|
+
} else {
|
|
71
|
+
xpub = paramXpub;
|
|
72
|
+
}
|
|
73
|
+
const accountId = encodeAccountId({
|
|
74
|
+
type: "js",
|
|
75
|
+
version: "2",
|
|
76
|
+
currencyId: currency.id,
|
|
77
|
+
xpubOrAddress: xpub,
|
|
78
|
+
derivationMode,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// when new tokens are added / blacklist changes, we need to sync again because we need to go through all operations again
|
|
82
|
+
const syncHash =
|
|
83
|
+
JSON.stringify(blacklistedTokenIds || []) +
|
|
84
|
+
"_" +
|
|
85
|
+
listTokensForCryptoCurrency(currency, {
|
|
86
|
+
withDelisted: true,
|
|
87
|
+
}).length;
|
|
88
|
+
const outdatedSyncHash = initialAccount?.syncHash !== syncHash;
|
|
89
|
+
|
|
90
|
+
const requiredConfirmations = 90;
|
|
91
|
+
|
|
92
|
+
const oldOperations = initialAccount?.operations || [];
|
|
93
|
+
const lastBlockHeight = oldOperations.length ? (oldOperations[0].blockHeight || 0) + 1 : 0;
|
|
94
|
+
|
|
95
|
+
const syncFromBlockHeight = outdatedSyncHash
|
|
96
|
+
? 0
|
|
97
|
+
: lastBlockHeight > requiredConfirmations
|
|
98
|
+
? lastBlockHeight - requiredConfirmations
|
|
99
|
+
: 0;
|
|
100
|
+
|
|
101
|
+
const {
|
|
102
|
+
transactions: newTransactions,
|
|
103
|
+
blockHeight,
|
|
104
|
+
externalCredentials,
|
|
105
|
+
internalCredentials,
|
|
106
|
+
} = await getTransactions(xpub, accountIndex, initialAccount, syncFromBlockHeight, currency);
|
|
107
|
+
|
|
108
|
+
const accountCredentialsMap = [...externalCredentials, ...internalCredentials].reduce(
|
|
109
|
+
(finalMap, cred) => {
|
|
110
|
+
finalMap[cred.key] = cred;
|
|
111
|
+
return finalMap;
|
|
112
|
+
},
|
|
113
|
+
{} as Record<string, PaymentCredential>,
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const stableOperationsByIds: Record<string, Operation> = {};
|
|
117
|
+
(initialAccount?.operations || []).forEach(o => {
|
|
118
|
+
if ((o.blockHeight as number) < syncFromBlockHeight) {
|
|
119
|
+
stableOperationsByIds[o.hash] = o;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const stableUtxos = (initialAccount?.cardanoResources?.utxos || []).filter(
|
|
124
|
+
u => stableOperationsByIds[u.hash],
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const utxos = prepareUtxos(newTransactions, stableUtxos, accountCredentialsMap);
|
|
128
|
+
const utxosSum = utxos.reduce((total, u) => total.plus(u.amount), new BigNumber(0));
|
|
129
|
+
const tokenBalance = mergeTokens(utxos.map(u => u.tokens).flat());
|
|
130
|
+
const subAccounts = buildSubAccounts({
|
|
131
|
+
initialAccount,
|
|
132
|
+
parentAccountId: accountId,
|
|
133
|
+
parentCurrency: currency,
|
|
134
|
+
newTransactions,
|
|
135
|
+
tokens: tokenBalance,
|
|
136
|
+
accountCredentialsMap,
|
|
137
|
+
}).filter(a => !blacklistedTokenIds?.includes(a.token.id));
|
|
138
|
+
|
|
139
|
+
const stakeCredential = getAccountStakeCredential(xpub, accountIndex);
|
|
140
|
+
const networkParams = getNetworkParameters(currency.id);
|
|
141
|
+
const freshAddresses = externalCredentials
|
|
142
|
+
.filter(c => !c.isUsed)
|
|
143
|
+
.map(c => ({
|
|
144
|
+
derivationPath: getBipPathString(c.path),
|
|
145
|
+
address: getBaseAddress({
|
|
146
|
+
networkId: networkParams.networkId,
|
|
147
|
+
paymentCred: c,
|
|
148
|
+
stakeCred: stakeCredential,
|
|
149
|
+
}).getBech32(),
|
|
150
|
+
}));
|
|
151
|
+
const cardanoNetworkInfo = await getNetworkInfo(initialAccount, currency);
|
|
152
|
+
const delegationInfo = await getDelegationInfo(currency, stakeCredential.key);
|
|
153
|
+
|
|
154
|
+
const totalBalance = delegationInfo?.rewards ? utxosSum.plus(delegationInfo.rewards) : utxosSum;
|
|
155
|
+
|
|
156
|
+
const minAdaBalanceForTokens = tokenBalance.length
|
|
157
|
+
? calculateMinUtxoAmount(
|
|
158
|
+
tokenBalance,
|
|
159
|
+
new BigNumber(cardanoNetworkInfo.protocolParams.lovelacePerUtxoWord),
|
|
160
|
+
false,
|
|
161
|
+
)
|
|
162
|
+
: new BigNumber(0);
|
|
163
|
+
|
|
164
|
+
const newOperations = newTransactions.map(t =>
|
|
165
|
+
mapTxToAccountOperation(
|
|
166
|
+
t,
|
|
167
|
+
accountId,
|
|
168
|
+
accountCredentialsMap,
|
|
169
|
+
stakeCredential,
|
|
170
|
+
subAccounts,
|
|
171
|
+
info,
|
|
172
|
+
cardanoNetworkInfo.protocolParams,
|
|
173
|
+
),
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const operations = mergeOps(Object.values(stableOperationsByIds), newOperations);
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
id: accountId,
|
|
180
|
+
xpub,
|
|
181
|
+
balance: totalBalance,
|
|
182
|
+
spendableBalance: utxosSum.minus(minAdaBalanceForTokens),
|
|
183
|
+
operations: operations,
|
|
184
|
+
syncHash,
|
|
185
|
+
subAccounts,
|
|
186
|
+
freshAddress: freshAddresses[0].address,
|
|
187
|
+
freshAddressPath: freshAddresses[0].derivationPath,
|
|
188
|
+
blockHeight,
|
|
189
|
+
cardanoResources: {
|
|
190
|
+
utxos,
|
|
191
|
+
externalCredentials,
|
|
192
|
+
internalCredentials,
|
|
193
|
+
delegation: delegationInfo,
|
|
194
|
+
protocolParams: cardanoNetworkInfo.protocolParams,
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
function mapTxToAccountOperation(
|
|
200
|
+
tx: APITransaction,
|
|
201
|
+
accountId: string,
|
|
202
|
+
accountCredentialsMap: Record<string, PaymentCredential>,
|
|
203
|
+
stakeCredential: StakeCredential,
|
|
204
|
+
subAccounts: Array<TokenAccount>,
|
|
205
|
+
accountShapeInfo: AccountShapeInfo,
|
|
206
|
+
protocolParams: ProtocolParams,
|
|
207
|
+
): CardanoOperation {
|
|
208
|
+
const accountChange = getAccountChange(tx, accountCredentialsMap);
|
|
209
|
+
|
|
210
|
+
const subOperations = inferSubOperations(tx.hash, subAccounts);
|
|
211
|
+
const memo = getMemoFromTx(tx);
|
|
212
|
+
const extra: CardanoOperationExtra = {};
|
|
213
|
+
if (memo) {
|
|
214
|
+
extra.memo = memo;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
let operationValue = accountChange.ada;
|
|
218
|
+
|
|
219
|
+
if (tx.certificate.stakeRegistrations.length) {
|
|
220
|
+
const walletRegistration = tx.certificate.stakeRegistrations.find(
|
|
221
|
+
c =>
|
|
222
|
+
c.stakeCredential.type === HashType.ADDRESS &&
|
|
223
|
+
c.stakeCredential.key === stakeCredential.key,
|
|
224
|
+
);
|
|
225
|
+
if (walletRegistration) {
|
|
226
|
+
extra.deposit = formatCurrencyUnit(
|
|
227
|
+
accountShapeInfo.currency.units[0],
|
|
228
|
+
new BigNumber(protocolParams.stakeKeyDeposit),
|
|
229
|
+
{
|
|
230
|
+
showCode: true,
|
|
231
|
+
disableRounding: true,
|
|
232
|
+
},
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (tx.certificate.stakeDeRegistrations.length) {
|
|
238
|
+
const walletDeRegistration = tx.certificate.stakeDeRegistrations.find(
|
|
239
|
+
c =>
|
|
240
|
+
c.stakeCredential.type === HashType.ADDRESS &&
|
|
241
|
+
c.stakeCredential.key === stakeCredential.key,
|
|
242
|
+
);
|
|
243
|
+
if (walletDeRegistration) {
|
|
244
|
+
operationValue = operationValue.minus(protocolParams.stakeKeyDeposit);
|
|
245
|
+
extra.refund = formatCurrencyUnit(
|
|
246
|
+
accountShapeInfo.currency.units[0],
|
|
247
|
+
new BigNumber(protocolParams.stakeKeyDeposit),
|
|
248
|
+
{
|
|
249
|
+
showCode: true,
|
|
250
|
+
disableRounding: true,
|
|
251
|
+
},
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (tx.withdrawals && tx.withdrawals.length) {
|
|
257
|
+
const walletWithdraw = tx.withdrawals.find(
|
|
258
|
+
w =>
|
|
259
|
+
w.stakeCredential.type === HashType.ADDRESS &&
|
|
260
|
+
w.stakeCredential.key === stakeCredential.key,
|
|
261
|
+
);
|
|
262
|
+
if (walletWithdraw) {
|
|
263
|
+
operationValue = operationValue.minus(walletWithdraw.amount);
|
|
264
|
+
extra.rewards = formatCurrencyUnit(
|
|
265
|
+
accountShapeInfo.currency.units[0],
|
|
266
|
+
new BigNumber(walletWithdraw.amount),
|
|
267
|
+
{
|
|
268
|
+
showCode: true,
|
|
269
|
+
disableRounding: true,
|
|
270
|
+
},
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const mainOperationType: OperationType = tx.certificate.stakeDelegations.length
|
|
276
|
+
? "DELEGATE"
|
|
277
|
+
: tx.certificate.stakeDeRegistrations.length
|
|
278
|
+
? "UNDELEGATE"
|
|
279
|
+
: getOperationType({
|
|
280
|
+
valueChange: operationValue,
|
|
281
|
+
fees: new BigNumber(tx.fees),
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
return {
|
|
285
|
+
accountId,
|
|
286
|
+
id: encodeOperationId(accountId, tx.hash, mainOperationType),
|
|
287
|
+
hash: tx.hash,
|
|
288
|
+
type: mainOperationType,
|
|
289
|
+
fee: new BigNumber(tx.fees),
|
|
290
|
+
value: operationValue.absoluteValue(),
|
|
291
|
+
senders: tx.inputs.map(i =>
|
|
292
|
+
isHexString(i.address) ? TyphonUtils.getAddressFromHex(i.address).getBech32() : i.address,
|
|
293
|
+
),
|
|
294
|
+
recipients: tx.outputs.map(o =>
|
|
295
|
+
isHexString(o.address) ? TyphonUtils.getAddressFromHex(o.address).getBech32() : o.address,
|
|
296
|
+
),
|
|
297
|
+
subOperations,
|
|
298
|
+
blockHeight: tx.blockHeight,
|
|
299
|
+
date: new Date(tx.timestamp),
|
|
300
|
+
extra: extra,
|
|
301
|
+
blockHash: undefined,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function prepareUtxos(
|
|
306
|
+
newTransactions: Array<APITransaction>,
|
|
307
|
+
stableUtxos: Array<CardanoOutput>,
|
|
308
|
+
accountCredentialsMap: Record<string, PaymentCredential>,
|
|
309
|
+
): Array<CardanoOutput> {
|
|
310
|
+
const newUtxos: Array<CardanoOutput> = [];
|
|
311
|
+
// spentUtxoKey = txId#index
|
|
312
|
+
const spentUtxoKeys: Set<string> = new Set();
|
|
313
|
+
|
|
314
|
+
newTransactions.forEach(t => {
|
|
315
|
+
t.inputs.forEach(i => {
|
|
316
|
+
const cred = accountCredentialsMap[i.paymentKey];
|
|
317
|
+
if (cred) spentUtxoKeys.add(`${i.txId}#${i.index}`);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
t.outputs.forEach((o, outputIndex) => {
|
|
321
|
+
const cred = accountCredentialsMap[o.paymentKey];
|
|
322
|
+
if (cred) {
|
|
323
|
+
newUtxos.push({
|
|
324
|
+
hash: t.hash,
|
|
325
|
+
index: outputIndex,
|
|
326
|
+
address: o.address,
|
|
327
|
+
amount: new BigNumber(o.value),
|
|
328
|
+
tokens: o.tokens.map(token => ({
|
|
329
|
+
assetName: token.assetName,
|
|
330
|
+
policyId: token.policyId,
|
|
331
|
+
amount: new BigNumber(token.value),
|
|
332
|
+
})),
|
|
333
|
+
paymentCredential: {
|
|
334
|
+
key: o.paymentKey,
|
|
335
|
+
path: cred.path,
|
|
336
|
+
},
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
const utxos = uniqBy([...stableUtxos, ...newUtxos], u => `${u.hash}#${u.index}`).filter(
|
|
343
|
+
u => !spentUtxoKeys.has(`${u.hash}#${u.index}`),
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
return utxos;
|
|
347
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import type { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
3
|
+
import { AccountShapeInfo, GetAccountShape } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
4
|
+
import { BipPath, CardanoAccount, CardanoDelegation, PaymentCredential } from "./types";
|
|
5
|
+
import { getDelegationInfo } from "./api/getDelegationInfo";
|
|
6
|
+
import { makeGetAccountShape } from "./synchronisation";
|
|
7
|
+
import { getTransactions } from "./api/getTransactions";
|
|
8
|
+
import { buildSubAccounts } from "./buildSubAccounts";
|
|
9
|
+
import { getNetworkInfo } from "./api/getNetworkInfo";
|
|
10
|
+
import { APINetworkInfo } from "./api/api-types";
|
|
11
|
+
import { CardanoSigner } from "./signer";
|
|
12
|
+
|
|
13
|
+
jest.mock("./buildSubAccounts");
|
|
14
|
+
jest.mock("./api/getTransactions");
|
|
15
|
+
jest.mock("./api/getNetworkInfo");
|
|
16
|
+
jest.mock("./api/getDelegationInfo");
|
|
17
|
+
|
|
18
|
+
describe("makeGetAccountShape", () => {
|
|
19
|
+
let signerContext: SignerContext<CardanoSigner>;
|
|
20
|
+
let shape: GetAccountShape<CardanoAccount>;
|
|
21
|
+
let accountShapeInfo: AccountShapeInfo<CardanoAccount>;
|
|
22
|
+
let getTransactionsMock: jest.MaybeMockedDeep<typeof getTransactions>;
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
const pubKeyMock = {
|
|
26
|
+
chainCodeHex: "chainCodeHex",
|
|
27
|
+
publicKeyHex: "publicKeyHex",
|
|
28
|
+
};
|
|
29
|
+
const fakeSigner: CardanoSigner = {
|
|
30
|
+
getAddress: jest.fn(),
|
|
31
|
+
sign: jest.fn(),
|
|
32
|
+
getPublicKey: jest.fn().mockResolvedValue(pubKeyMock),
|
|
33
|
+
};
|
|
34
|
+
signerContext = <T>(_: string, fn: (signer: CardanoSigner) => Promise<T>) => fn(fakeSigner);
|
|
35
|
+
shape = makeGetAccountShape(signerContext);
|
|
36
|
+
accountShapeInfo = {
|
|
37
|
+
currency: { id: "cardano" } as any,
|
|
38
|
+
address: "add",
|
|
39
|
+
index: 0,
|
|
40
|
+
initialAccount: {
|
|
41
|
+
cardanoResources: {
|
|
42
|
+
utxos: [
|
|
43
|
+
{
|
|
44
|
+
hash: "hash",
|
|
45
|
+
index: 0,
|
|
46
|
+
address: "addr",
|
|
47
|
+
amount: new BigNumber(1),
|
|
48
|
+
tokens: [],
|
|
49
|
+
paymentCredential: {
|
|
50
|
+
key: "key",
|
|
51
|
+
path: {
|
|
52
|
+
purpose: 1852,
|
|
53
|
+
coin: 1815,
|
|
54
|
+
account: 0,
|
|
55
|
+
chain: 0,
|
|
56
|
+
index: 0,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
} as unknown as CardanoAccount,
|
|
63
|
+
derivationPath: "",
|
|
64
|
+
derivationMode: "cardano",
|
|
65
|
+
deviceId: "id",
|
|
66
|
+
};
|
|
67
|
+
const buildSubAccountsMock = jest.mocked(buildSubAccounts);
|
|
68
|
+
buildSubAccountsMock.mockReturnValue([]);
|
|
69
|
+
getTransactionsMock = jest.mocked(getTransactions);
|
|
70
|
+
const getNetworkInfoMock = jest.mocked(getNetworkInfo);
|
|
71
|
+
getNetworkInfoMock.mockReturnValue(
|
|
72
|
+
Promise.resolve({ protocolParams: { lovelacePerUtxoWord: "1" } } as APINetworkInfo),
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
afterEach(() => {
|
|
77
|
+
jest.resetAllMocks();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe("balance", () => {
|
|
81
|
+
it("should return 0 balance when there is no utxos", async () => {
|
|
82
|
+
getTransactionsMock.mockReturnValue(
|
|
83
|
+
Promise.resolve({
|
|
84
|
+
transactions: [],
|
|
85
|
+
externalCredentials: [
|
|
86
|
+
{ path: { index: 0 } as BipPath, networkId: "id", isUsed: false, key: "" },
|
|
87
|
+
],
|
|
88
|
+
internalCredentials: [],
|
|
89
|
+
blockHeight: 0,
|
|
90
|
+
}),
|
|
91
|
+
);
|
|
92
|
+
const result = await shape(accountShapeInfo, { paginationConfig: {} });
|
|
93
|
+
expect(result.balance).toEqual(new BigNumber(0));
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("should return the sum of utxos with delegation reward value", async () => {
|
|
97
|
+
getTransactionsMock.mockReturnValue(
|
|
98
|
+
Promise.resolve({
|
|
99
|
+
transactions: [],
|
|
100
|
+
externalCredentials: [
|
|
101
|
+
{ path: { index: 0 } as BipPath, networkId: "id", isUsed: false, key: "" },
|
|
102
|
+
],
|
|
103
|
+
internalCredentials: [
|
|
104
|
+
{
|
|
105
|
+
isUsed: true,
|
|
106
|
+
key: "cred",
|
|
107
|
+
} as PaymentCredential,
|
|
108
|
+
],
|
|
109
|
+
blockHeight: 0,
|
|
110
|
+
}),
|
|
111
|
+
);
|
|
112
|
+
const getDelegationInfoMock = jest.mocked(getDelegationInfo);
|
|
113
|
+
getDelegationInfoMock.mockReturnValue(
|
|
114
|
+
Promise.resolve({ rewards: new BigNumber(42) } as CardanoDelegation),
|
|
115
|
+
);
|
|
116
|
+
const result = await shape(accountShapeInfo, { paginationConfig: {} });
|
|
117
|
+
expect(result.balance).toEqual(new BigNumber(42));
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe("spendableBalance", () => {
|
|
122
|
+
it("should return 0 spendable balance when there is no utxos", async () => {
|
|
123
|
+
const getTransactionsMock = jest.mocked(getTransactions);
|
|
124
|
+
getTransactionsMock.mockReturnValue(
|
|
125
|
+
Promise.resolve({
|
|
126
|
+
transactions: [],
|
|
127
|
+
externalCredentials: [{ path: "p", networkId: "id" }],
|
|
128
|
+
internalCredentials: [],
|
|
129
|
+
} as any),
|
|
130
|
+
);
|
|
131
|
+
const result = await shape(accountShapeInfo, { paginationConfig: {} });
|
|
132
|
+
expect(result.spendableBalance).toEqual(new BigNumber(0));
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// it("should return the sum of utxos minus ada minimum for tokens", async () => {});
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Transaction, TransactionRaw } from "./types";
|
|
2
|
+
import { BigNumber } from "bignumber.js";
|
|
3
|
+
import { formatTransactionStatus } from "@ledgerhq/coin-framework/formatters";
|
|
4
|
+
import {
|
|
5
|
+
fromTransactionCommonRaw,
|
|
6
|
+
fromTransactionStatusRawCommon as fromTransactionStatusRaw,
|
|
7
|
+
toTransactionCommonRaw,
|
|
8
|
+
toTransactionStatusRawCommon as toTransactionStatusRaw,
|
|
9
|
+
} from "@ledgerhq/coin-framework/serialization";
|
|
10
|
+
import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index";
|
|
11
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
|
|
12
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
13
|
+
|
|
14
|
+
export const formatTransaction = (
|
|
15
|
+
{ mode, amount, recipient, useAllAmount, subAccountId }: Transaction,
|
|
16
|
+
mainAccount: Account,
|
|
17
|
+
): string => {
|
|
18
|
+
const account =
|
|
19
|
+
(subAccountId && (mainAccount.subAccounts || []).find(a => a.id === subAccountId)) ||
|
|
20
|
+
mainAccount;
|
|
21
|
+
return `
|
|
22
|
+
${mode.toUpperCase()} ${
|
|
23
|
+
useAllAmount
|
|
24
|
+
? "MAX"
|
|
25
|
+
: amount.isZero()
|
|
26
|
+
? ""
|
|
27
|
+
: " " +
|
|
28
|
+
formatCurrencyUnit(getAccountCurrency(account).units[0], amount, {
|
|
29
|
+
showCode: true,
|
|
30
|
+
disableRounding: true,
|
|
31
|
+
})
|
|
32
|
+
}${recipient ? `\nTO ${recipient}` : ""}`;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
|
|
36
|
+
const common = fromTransactionCommonRaw(tr);
|
|
37
|
+
return {
|
|
38
|
+
...common,
|
|
39
|
+
family: tr.family,
|
|
40
|
+
mode: tr.mode,
|
|
41
|
+
fees: tr.fees ? new BigNumber(tr.fees) : undefined,
|
|
42
|
+
memo: tr.memo,
|
|
43
|
+
poolId: tr.poolId,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const toTransactionRaw = (t: Transaction): TransactionRaw => {
|
|
48
|
+
const common = toTransactionCommonRaw(t);
|
|
49
|
+
return {
|
|
50
|
+
...common,
|
|
51
|
+
family: t.family,
|
|
52
|
+
mode: t.mode,
|
|
53
|
+
fees: t.fees?.toString() || undefined,
|
|
54
|
+
memo: t.memo,
|
|
55
|
+
poolId: t.poolId,
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default {
|
|
60
|
+
formatTransaction,
|
|
61
|
+
fromTransactionRaw,
|
|
62
|
+
toTransactionRaw,
|
|
63
|
+
fromTransactionStatusRaw,
|
|
64
|
+
toTransactionStatusRaw,
|
|
65
|
+
formatTransactionStatus,
|
|
66
|
+
};
|