@ledgerhq/coin-icon 0.4.1-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 +41 -0
- package/CHANGELOG.md +495 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +11 -0
- package/lib/__test__/api/index.unit.test.d.ts +2 -0
- package/lib/__test__/api/index.unit.test.d.ts.map +1 -0
- package/lib/__test__/api/index.unit.test.js +173 -0
- package/lib/__test__/api/index.unit.test.js.map +1 -0
- package/lib/__test__/unit/buildTransaction.test.d.ts +2 -0
- package/lib/__test__/unit/buildTransaction.test.d.ts.map +1 -0
- package/lib/__test__/unit/buildTransaction.test.js +76 -0
- package/lib/__test__/unit/buildTransaction.test.js.map +1 -0
- package/lib/__test__/unit/getFeesForTransaction.unit.test.d.ts +2 -0
- package/lib/__test__/unit/getFeesForTransaction.unit.test.d.ts.map +1 -0
- package/lib/__test__/unit/getFeesForTransaction.unit.test.js +101 -0
- package/lib/__test__/unit/getFeesForTransaction.unit.test.js.map +1 -0
- package/lib/__test__/unit/getTransactionStatus.unit.test.d.ts +2 -0
- package/lib/__test__/unit/getTransactionStatus.unit.test.d.ts.map +1 -0
- package/lib/__test__/unit/getTransactionStatus.unit.test.js +178 -0
- package/lib/__test__/unit/getTransactionStatus.unit.test.js.map +1 -0
- package/lib/__test__/unit/logic.unit.test.d.ts +2 -0
- package/lib/__test__/unit/logic.unit.test.d.ts.map +1 -0
- package/lib/__test__/unit/logic.unit.test.js +112 -0
- package/lib/__test__/unit/logic.unit.test.js.map +1 -0
- package/lib/__test__/unit/serializations.unit.test.d.ts +2 -0
- package/lib/__test__/unit/serializations.unit.test.d.ts.map +1 -0
- package/lib/__test__/unit/serializations.unit.test.js +73 -0
- package/lib/__test__/unit/serializations.unit.test.js.map +1 -0
- package/lib/__test__/unit/transaction.unit.test.d.ts +2 -0
- package/lib/__test__/unit/transaction.unit.test.d.ts.map +1 -0
- package/lib/__test__/unit/transaction.unit.test.js +130 -0
- package/lib/__test__/unit/transaction.unit.test.js.map +1 -0
- package/lib/account.d.ts +7 -0
- package/lib/account.d.ts.map +1 -0
- package/lib/account.js +26 -0
- package/lib/account.js.map +1 -0
- package/lib/api/api-type.d.ts +62 -0
- package/lib/api/api-type.d.ts.map +1 -0
- package/lib/api/api-type.js +3 -0
- package/lib/api/api-type.js.map +1 -0
- package/lib/api/index.d.ts +13 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +134 -0
- package/lib/api/index.js.map +1 -0
- package/lib/api/node.d.ts +31 -0
- package/lib/api/node.d.ts.map +1 -0
- package/lib/api/node.js +112 -0
- package/lib/api/node.js.map +1 -0
- package/lib/bridge/index.d.ts +13 -0
- package/lib/bridge/index.d.ts.map +1 -0
- package/lib/bridge/index.js +71 -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 +105 -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 +25 -0
- package/lib/broadcast.js.map +1 -0
- package/lib/buildTransaction.d.ts +12 -0
- package/lib/buildTransaction.d.ts.map +1 -0
- package/lib/buildTransaction.js +55 -0
- package/lib/buildTransaction.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 +15 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +17 -0
- package/lib/config.js.map +1 -0
- package/lib/constants.d.ts +14 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +17 -0
- package/lib/constants.js.map +1 -0
- package/lib/createTransaction.d.ts +8 -0
- package/lib/createTransaction.d.ts.map +1 -0
- package/lib/createTransaction.js +19 -0
- package/lib/createTransaction.js.map +1 -0
- package/lib/deviceTransactionConfig.d.ts +15 -0
- package/lib/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/deviceTransactionConfig.js +24 -0
- package/lib/deviceTransactionConfig.js.map +1 -0
- package/lib/errors.d.ts +10 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +8 -0
- package/lib/errors.js.map +1 -0
- package/lib/estimateMaxSpendable.d.ts +14 -0
- package/lib/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/estimateMaxSpendable.js +38 -0
- package/lib/estimateMaxSpendable.js.map +1 -0
- package/lib/getFeesForTransaction.d.ts +14 -0
- package/lib/getFeesForTransaction.d.ts.map +1 -0
- package/lib/getFeesForTransaction.js +44 -0
- package/lib/getFeesForTransaction.js.map +1 -0
- package/lib/getTransactionStatus.d.ts +4 -0
- package/lib/getTransactionStatus.d.ts.map +1 -0
- package/lib/getTransactionStatus.js +114 -0
- package/lib/getTransactionStatus.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 +23 -0
- package/lib/hw-getAddress.js.map +1 -0
- package/lib/initAccount.d.ts +3 -0
- package/lib/initAccount.d.ts.map +1 -0
- package/lib/initAccount.js +13 -0
- package/lib/initAccount.js.map +1 -0
- package/lib/logic.d.ts +55 -0
- package/lib/logic.d.ts.map +1 -0
- package/lib/logic.js +124 -0
- package/lib/logic.js.map +1 -0
- package/lib/prepareTransaction.d.ts +9 -0
- package/lib/prepareTransaction.d.ts.map +1 -0
- package/lib/prepareTransaction.js +33 -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 +36 -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 +96 -0
- package/lib/signOperation.js.map +1 -0
- package/lib/signer.d.ts +14 -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 +100 -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 +44 -0
- package/lib/speculos-deviceActions.js.map +1 -0
- package/lib/synchronization.d.ts +3 -0
- package/lib/synchronization.d.ts.map +1 -0
- package/lib/synchronization.js +76 -0
- package/lib/synchronization.js.map +1 -0
- package/lib/transaction.d.ts +15 -0
- package/lib/transaction.d.ts.map +1 -0
- package/lib/transaction.js +39 -0
- package/lib/transaction.js.map +1 -0
- package/lib/types/bridge.fixture.d.ts +5 -0
- package/lib/types/bridge.fixture.d.ts.map +1 -0
- package/lib/types/bridge.fixture.js +77 -0
- package/lib/types/bridge.fixture.js.map +1 -0
- package/lib/types/index.d.ts +46 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +3 -0
- package/lib/types/index.js.map +1 -0
- package/lib-es/__test__/api/index.unit.test.d.ts +2 -0
- package/lib-es/__test__/api/index.unit.test.d.ts.map +1 -0
- package/lib-es/__test__/api/index.unit.test.js +145 -0
- package/lib-es/__test__/api/index.unit.test.js.map +1 -0
- package/lib-es/__test__/unit/buildTransaction.test.d.ts +2 -0
- package/lib-es/__test__/unit/buildTransaction.test.d.ts.map +1 -0
- package/lib-es/__test__/unit/buildTransaction.test.js +71 -0
- package/lib-es/__test__/unit/buildTransaction.test.js.map +1 -0
- package/lib-es/__test__/unit/getFeesForTransaction.unit.test.d.ts +2 -0
- package/lib-es/__test__/unit/getFeesForTransaction.unit.test.d.ts.map +1 -0
- package/lib-es/__test__/unit/getFeesForTransaction.unit.test.js +73 -0
- package/lib-es/__test__/unit/getFeesForTransaction.unit.test.js.map +1 -0
- package/lib-es/__test__/unit/getTransactionStatus.unit.test.d.ts +2 -0
- package/lib-es/__test__/unit/getTransactionStatus.unit.test.d.ts.map +1 -0
- package/lib-es/__test__/unit/getTransactionStatus.unit.test.js +153 -0
- package/lib-es/__test__/unit/getTransactionStatus.unit.test.js.map +1 -0
- package/lib-es/__test__/unit/logic.unit.test.d.ts +2 -0
- package/lib-es/__test__/unit/logic.unit.test.d.ts.map +1 -0
- package/lib-es/__test__/unit/logic.unit.test.js +107 -0
- package/lib-es/__test__/unit/logic.unit.test.js.map +1 -0
- package/lib-es/__test__/unit/serializations.unit.test.d.ts +2 -0
- package/lib-es/__test__/unit/serializations.unit.test.d.ts.map +1 -0
- package/lib-es/__test__/unit/serializations.unit.test.js +71 -0
- package/lib-es/__test__/unit/serializations.unit.test.js.map +1 -0
- package/lib-es/__test__/unit/transaction.unit.test.d.ts +2 -0
- package/lib-es/__test__/unit/transaction.unit.test.d.ts.map +1 -0
- package/lib-es/__test__/unit/transaction.unit.test.js +128 -0
- package/lib-es/__test__/unit/transaction.unit.test.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 +24 -0
- package/lib-es/account.js.map +1 -0
- package/lib-es/api/api-type.d.ts +62 -0
- package/lib-es/api/api-type.d.ts.map +1 -0
- package/lib-es/api/api-type.js +2 -0
- package/lib-es/api/api-type.js.map +1 -0
- package/lib-es/api/index.d.ts +13 -0
- package/lib-es/api/index.d.ts.map +1 -0
- package/lib-es/api/index.js +123 -0
- package/lib-es/api/index.js.map +1 -0
- package/lib-es/api/node.d.ts +31 -0
- package/lib-es/api/node.d.ts.map +1 -0
- package/lib-es/api/node.js +99 -0
- package/lib-es/api/node.js.map +1 -0
- package/lib-es/bridge/index.d.ts +13 -0
- package/lib-es/bridge/index.d.ts.map +1 -0
- package/lib-es/bridge/index.js +62 -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 +99 -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 +21 -0
- package/lib-es/broadcast.js.map +1 -0
- package/lib-es/buildTransaction.d.ts +12 -0
- package/lib-es/buildTransaction.d.ts.map +1 -0
- package/lib-es/buildTransaction.js +48 -0
- package/lib-es/buildTransaction.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 +15 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +12 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/constants.d.ts +14 -0
- package/lib-es/constants.d.ts.map +1 -0
- package/lib-es/constants.js +14 -0
- package/lib-es/constants.js.map +1 -0
- package/lib-es/createTransaction.d.ts +8 -0
- package/lib-es/createTransaction.d.ts.map +1 -0
- package/lib-es/createTransaction.js +15 -0
- package/lib-es/createTransaction.js.map +1 -0
- package/lib-es/deviceTransactionConfig.d.ts +15 -0
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/deviceTransactionConfig.js +22 -0
- package/lib-es/deviceTransactionConfig.js.map +1 -0
- package/lib-es/errors.d.ts +10 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +5 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/estimateMaxSpendable.d.ts +14 -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/getFeesForTransaction.d.ts +14 -0
- package/lib-es/getFeesForTransaction.d.ts.map +1 -0
- package/lib-es/getFeesForTransaction.js +42 -0
- package/lib-es/getFeesForTransaction.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 +109 -0
- package/lib-es/getTransactionStatus.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 +21 -0
- package/lib-es/hw-getAddress.js.map +1 -0
- package/lib-es/initAccount.d.ts +3 -0
- package/lib-es/initAccount.d.ts.map +1 -0
- package/lib-es/initAccount.js +9 -0
- package/lib-es/initAccount.js.map +1 -0
- package/lib-es/logic.d.ts +55 -0
- package/lib-es/logic.d.ts.map +1 -0
- package/lib-es/logic.js +109 -0
- package/lib-es/logic.js.map +1 -0
- package/lib-es/prepareTransaction.d.ts +9 -0
- package/lib-es/prepareTransaction.d.ts.map +1 -0
- package/lib-es/prepareTransaction.js +26 -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 +29 -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 +89 -0
- package/lib-es/signOperation.js.map +1 -0
- package/lib-es/signer.d.ts +14 -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 +95 -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 +41 -0
- package/lib-es/speculos-deviceActions.js.map +1 -0
- package/lib-es/synchronization.d.ts +3 -0
- package/lib-es/synchronization.d.ts.map +1 -0
- package/lib-es/synchronization.js +69 -0
- package/lib-es/synchronization.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 +33 -0
- package/lib-es/transaction.js.map +1 -0
- package/lib-es/types/bridge.fixture.d.ts +5 -0
- package/lib-es/types/bridge.fixture.d.ts.map +1 -0
- package/lib-es/types/bridge.fixture.js +68 -0
- package/lib-es/types/bridge.fixture.js.map +1 -0
- package/lib-es/types/index.d.ts +46 -0
- package/lib-es/types/index.d.ts.map +1 -0
- package/lib-es/types/index.js +2 -0
- package/lib-es/types/index.js.map +1 -0
- package/package.json +85 -0
- package/src/__test__/api/index.unit.test.ts +151 -0
- package/src/__test__/unit/buildTransaction.test.ts +76 -0
- package/src/__test__/unit/getFeesForTransaction.unit.test.ts +76 -0
- package/src/__test__/unit/getTransactionStatus.unit.test.ts +172 -0
- package/src/__test__/unit/logic.unit.test.ts +145 -0
- package/src/__test__/unit/serializations.unit.test.ts +92 -0
- package/src/__test__/unit/transaction.unit.test.ts +144 -0
- package/src/account.ts +30 -0
- package/src/api/api-type.ts +65 -0
- package/src/api/index.ts +156 -0
- package/src/api/node.ts +115 -0
- package/src/bridge/index.ts +76 -0
- package/src/bridge.integration.test.ts +107 -0
- package/src/broadcast.ts +18 -0
- package/src/buildTransaction.ts +53 -0
- package/src/cli-transaction.ts +49 -0
- package/src/config.ts +29 -0
- package/src/constants.ts +14 -0
- package/src/createTransaction.ts +16 -0
- package/src/deviceTransactionConfig.ts +44 -0
- package/src/errors.ts +5 -0
- package/src/estimateMaxSpendable.ts +34 -0
- package/src/getFeesForTransaction.ts +46 -0
- package/src/getTransactionStatus.ts +139 -0
- package/src/hw-getAddress.ts +19 -0
- package/src/initAccount.ts +11 -0
- package/src/logic.ts +132 -0
- package/src/prepareTransaction.ts +24 -0
- package/src/serialization.ts +34 -0
- package/src/signOperation.ts +140 -0
- package/src/signer.ts +14 -0
- package/src/specs.ts +124 -0
- package/src/speculos-deviceActions.ts +46 -0
- package/src/synchronization.ts +70 -0
- package/src/transaction.ts +60 -0
- package/src/types/bridge.fixture.ts +75 -0
- package/src/types/index.ts +61 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { encodeAccountId } from "@ledgerhq/coin-framework/account/accountId";
|
|
2
|
+
import { mergeOps, AccountShapeInfo } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
3
|
+
import type { GetAccountShape } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
4
|
+
|
|
5
|
+
import { getAccount, getCurrentBlockHeight, getOperations } from "./api";
|
|
6
|
+
import BigNumber from "bignumber.js";
|
|
7
|
+
import { getDelegation } from "./api/node";
|
|
8
|
+
import { IconResources } from "./types";
|
|
9
|
+
import { convertICXtoLoop } from "./logic";
|
|
10
|
+
|
|
11
|
+
export const getAccountShape: GetAccountShape = async (info: AccountShapeInfo) => {
|
|
12
|
+
const { address, initialAccount, currency, derivationMode } = info;
|
|
13
|
+
const accountId = encodeAccountId({
|
|
14
|
+
type: "js",
|
|
15
|
+
version: "2",
|
|
16
|
+
currencyId: currency.id,
|
|
17
|
+
xpubOrAddress: address,
|
|
18
|
+
derivationMode,
|
|
19
|
+
});
|
|
20
|
+
try {
|
|
21
|
+
const oldOperations = initialAccount?.operations || [];
|
|
22
|
+
const blockHeight = await getCurrentBlockHeight(currency);
|
|
23
|
+
const iconAccount = await getAccount(info.address, currency);
|
|
24
|
+
|
|
25
|
+
// Merge new operations with the previously synced ones
|
|
26
|
+
const newOperations = await getOperations(
|
|
27
|
+
accountId,
|
|
28
|
+
address,
|
|
29
|
+
0, // skip === 0 is the lastest transaction
|
|
30
|
+
currency,
|
|
31
|
+
iconAccount?.contract_updated_block - oldOperations.length,
|
|
32
|
+
);
|
|
33
|
+
const operations = mergeOps(oldOperations, newOperations);
|
|
34
|
+
const delegationData = await getDelegation(address, currency);
|
|
35
|
+
const iconResources: IconResources = {
|
|
36
|
+
nonce: 0,
|
|
37
|
+
totalDelegated: delegationData.totalDelegated,
|
|
38
|
+
votingPower: delegationData.votingPower,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const balance = convertICXtoLoop(iconAccount?.balance || 0);
|
|
42
|
+
const spendableBalance = balance
|
|
43
|
+
.minus(iconResources.totalDelegated)
|
|
44
|
+
.minus(iconResources.votingPower);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
id: accountId,
|
|
48
|
+
balance,
|
|
49
|
+
spendableBalance,
|
|
50
|
+
operationsCount: operations.length,
|
|
51
|
+
blockHeight,
|
|
52
|
+
iconResources,
|
|
53
|
+
operations,
|
|
54
|
+
};
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return {
|
|
57
|
+
id: accountId,
|
|
58
|
+
balance: new BigNumber(0),
|
|
59
|
+
spendableBalance: new BigNumber(0),
|
|
60
|
+
operationsCount: 0,
|
|
61
|
+
iconResources: {
|
|
62
|
+
nonce: 0,
|
|
63
|
+
totalDelegated: new BigNumber(0),
|
|
64
|
+
votingPower: new BigNumber(0),
|
|
65
|
+
},
|
|
66
|
+
blockHeight: 0,
|
|
67
|
+
operations: [],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
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 type { Account } from "@ledgerhq/types-live";
|
|
11
|
+
import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index";
|
|
12
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
|
|
13
|
+
|
|
14
|
+
export const formatTransaction = (
|
|
15
|
+
{ mode, amount, recipient, useAllAmount }: Transaction,
|
|
16
|
+
account: Account,
|
|
17
|
+
): string =>
|
|
18
|
+
`
|
|
19
|
+
${mode.toUpperCase()} ${
|
|
20
|
+
useAllAmount
|
|
21
|
+
? "MAX"
|
|
22
|
+
: amount.isZero()
|
|
23
|
+
? ""
|
|
24
|
+
: " " +
|
|
25
|
+
formatCurrencyUnit(getAccountCurrency(account).units[0], amount, {
|
|
26
|
+
showCode: true,
|
|
27
|
+
disableRounding: true,
|
|
28
|
+
})
|
|
29
|
+
}${recipient ? `\nTO ${recipient}` : ""}`;
|
|
30
|
+
|
|
31
|
+
export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
|
|
32
|
+
const common = fromTransactionCommonRaw(tr);
|
|
33
|
+
return {
|
|
34
|
+
...common,
|
|
35
|
+
family: tr.family,
|
|
36
|
+
mode: tr.mode,
|
|
37
|
+
fees: tr.fees ? new BigNumber(tr.fees) : null,
|
|
38
|
+
stepLimit: tr.stepLimit ? new BigNumber(tr.stepLimit) : undefined,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const toTransactionRaw = (t: Transaction): TransactionRaw => {
|
|
43
|
+
const common = toTransactionCommonRaw(t);
|
|
44
|
+
return {
|
|
45
|
+
...common,
|
|
46
|
+
family: t.family,
|
|
47
|
+
mode: t.mode,
|
|
48
|
+
fees: t.fees?.toString() || null,
|
|
49
|
+
stepLimit: t.stepLimit?.toString() || undefined,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default {
|
|
54
|
+
formatTransaction,
|
|
55
|
+
fromTransactionRaw,
|
|
56
|
+
toTransactionRaw,
|
|
57
|
+
fromTransactionStatusRaw,
|
|
58
|
+
toTransactionStatusRaw,
|
|
59
|
+
formatTransactionStatus,
|
|
60
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { faker } from "@faker-js/faker";
|
|
3
|
+
import { listCryptoCurrencies } from "@ledgerhq/cryptoassets/currencies";
|
|
4
|
+
import { getAbandonSeedAddress } from "@ledgerhq/cryptoassets/abandonseed";
|
|
5
|
+
import { emptyHistoryCache } from "@ledgerhq/coin-framework/account/index";
|
|
6
|
+
import { IconAccount, IconOperation, IconResources, Transaction } from "./index";
|
|
7
|
+
|
|
8
|
+
export function createFixtureAccount(account?: Partial<IconAccount>): IconAccount {
|
|
9
|
+
const currency = listCryptoCurrencies(true).find(c => c.id === "icon")!;
|
|
10
|
+
|
|
11
|
+
const iconResources: IconResources = account?.iconResources || {
|
|
12
|
+
nonce: 0,
|
|
13
|
+
votingPower: BigNumber(0),
|
|
14
|
+
totalDelegated: BigNumber(0),
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const freshAddress = {
|
|
18
|
+
address: "hx1234567890abcdef",
|
|
19
|
+
derivationPath: "derivation_path",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const id = faker.string.uuid();
|
|
23
|
+
const seedIdentifier = faker.string.uuid();
|
|
24
|
+
const index = faker.number.int();
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
type: "Account",
|
|
28
|
+
id,
|
|
29
|
+
seedIdentifier,
|
|
30
|
+
derivationMode: "",
|
|
31
|
+
index,
|
|
32
|
+
freshAddress: freshAddress.address,
|
|
33
|
+
freshAddressPath: freshAddress.derivationPath,
|
|
34
|
+
used: true,
|
|
35
|
+
balance: account?.balance || new BigNumber(0),
|
|
36
|
+
spendableBalance: account?.spendableBalance || new BigNumber(0),
|
|
37
|
+
creationDate: faker.date.past(),
|
|
38
|
+
blockHeight: faker.number.int({ min: 100_000, max: 200_000 }),
|
|
39
|
+
currency,
|
|
40
|
+
operationsCount: account?.operationsCount || 0,
|
|
41
|
+
operations: account?.operations || [],
|
|
42
|
+
pendingOperations: account?.pendingOperations || [],
|
|
43
|
+
lastSyncDate: new Date(),
|
|
44
|
+
balanceHistoryCache: emptyHistoryCache,
|
|
45
|
+
swapHistory: [],
|
|
46
|
+
iconResources,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function createFixtureTransaction(tx?: Partial<Transaction>): Transaction {
|
|
51
|
+
return {
|
|
52
|
+
amount: tx?.amount || new BigNumber(0),
|
|
53
|
+
recipient: tx?.recipient || getAbandonSeedAddress("icon"),
|
|
54
|
+
mode: tx?.mode || "send",
|
|
55
|
+
family: "icon",
|
|
56
|
+
fees: tx?.fees || undefined,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function createFixtureOperation(operation?: Partial<IconOperation>): IconOperation {
|
|
61
|
+
return {
|
|
62
|
+
id: operation?.id || faker.string.uuid(),
|
|
63
|
+
hash: operation?.hash || faker.string.uuid(),
|
|
64
|
+
type: operation?.type || "OUT",
|
|
65
|
+
value: operation?.value || new BigNumber(faker.string.numeric()),
|
|
66
|
+
fee: operation?.fee || new BigNumber(0),
|
|
67
|
+
senders: operation?.senders || [],
|
|
68
|
+
recipients: operation?.recipients || [],
|
|
69
|
+
blockHeight: operation?.blockHeight || undefined,
|
|
70
|
+
blockHash: operation?.blockHash || undefined,
|
|
71
|
+
accountId: operation?.accountId || faker.string.uuid(),
|
|
72
|
+
date: operation?.date || faker.date.past(),
|
|
73
|
+
extra: {},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { BigNumber } from "bignumber.js";
|
|
2
|
+
import {
|
|
3
|
+
Account,
|
|
4
|
+
AccountRaw,
|
|
5
|
+
TransactionCommon,
|
|
6
|
+
TransactionCommonRaw,
|
|
7
|
+
TransactionStatusCommon,
|
|
8
|
+
TransactionStatusCommonRaw,
|
|
9
|
+
Operation,
|
|
10
|
+
} from "@ledgerhq/types-live";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Icon account resources
|
|
14
|
+
*/
|
|
15
|
+
export type IconResources = {
|
|
16
|
+
nonce: number;
|
|
17
|
+
votingPower: string | BigNumber;
|
|
18
|
+
totalDelegated: string | BigNumber;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Icon account resources from raw JSON
|
|
23
|
+
*/
|
|
24
|
+
export type IconResourcesRaw = {
|
|
25
|
+
nonce: number;
|
|
26
|
+
votingPower: string | BigNumber;
|
|
27
|
+
totalDelegated: string | BigNumber;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Icon transaction
|
|
32
|
+
*/
|
|
33
|
+
export type Transaction = TransactionCommon & {
|
|
34
|
+
mode: string;
|
|
35
|
+
family: "icon";
|
|
36
|
+
fees?: BigNumber | null | undefined;
|
|
37
|
+
stepLimit?: BigNumber;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Icon transaction from a raw JSON
|
|
42
|
+
*/
|
|
43
|
+
export type TransactionRaw = TransactionCommonRaw & {
|
|
44
|
+
family: "icon";
|
|
45
|
+
mode: string;
|
|
46
|
+
fees?: string | null | undefined;
|
|
47
|
+
stepLimit?: string;
|
|
48
|
+
// also the transaction fields as raw JSON data
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type IconOperation = Operation;
|
|
52
|
+
|
|
53
|
+
export type IconAccount = Account & { iconResources: IconResources };
|
|
54
|
+
|
|
55
|
+
export type IconAccountRaw = AccountRaw & {
|
|
56
|
+
iconResources: IconResourcesRaw;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type TransactionStatus = TransactionStatusCommon;
|
|
60
|
+
|
|
61
|
+
export type TransactionStatusRaw = TransactionStatusCommonRaw;
|
package/tsconfig.json
ADDED