@ledgerhq/coin-hedera 1.13.0-nightly.2 → 1.13.0-nightly.3
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/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +1 -1
- package/CHANGELOG.md +14 -0
- package/jest.config.js +1 -1
- package/jest.integ.config.js +8 -0
- package/lib/api/index.d.ts +4 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +119 -0
- package/lib/api/index.js.map +1 -0
- package/lib/bridge/broadcast.d.ts +1 -1
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +6 -9
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -1
- package/lib/bridge/buildOptimisticOperation.js +14 -11
- package/lib/bridge/buildOptimisticOperation.js.map +1 -1
- package/lib/bridge/createTransaction.d.ts +1 -1
- package/lib/bridge/createTransaction.d.ts.map +1 -1
- package/lib/bridge/createTransaction.js +2 -0
- package/lib/bridge/createTransaction.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +2 -2
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +11 -10
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +6 -5
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts +1 -1
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +53 -14
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +24 -11
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/bridge/utils.d.ts +3 -13
- package/lib/bridge/utils.d.ts.map +1 -1
- package/lib/bridge/utils.js +10 -119
- package/lib/bridge/utils.js.map +1 -1
- package/lib/config.d.ts +8 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +9 -0
- package/lib/config.js.map +1 -0
- package/lib/constants.d.ts +11 -8
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +17 -13
- package/lib/constants.js.map +1 -1
- package/lib/deviceTransactionConfig.d.ts +1 -1
- package/lib/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/deviceTransactionConfig.js +3 -3
- package/lib/deviceTransactionConfig.js.map +1 -1
- package/lib/logic/broadcast.d.ts +3 -0
- package/lib/logic/broadcast.d.ts.map +1 -0
- package/lib/logic/broadcast.js +11 -0
- package/lib/logic/broadcast.js.map +1 -0
- package/lib/logic/combine.d.ts +2 -0
- package/lib/logic/combine.d.ts.map +1 -0
- package/lib/logic/combine.js +19 -0
- package/lib/logic/combine.js.map +1 -0
- package/lib/logic/craftTransaction.d.ts +8 -0
- package/lib/logic/craftTransaction.d.ts.map +1 -0
- package/lib/logic/craftTransaction.js +107 -0
- package/lib/logic/craftTransaction.js.map +1 -0
- package/lib/logic/estimateFees.d.ts +5 -0
- package/lib/logic/estimateFees.d.ts.map +1 -0
- package/lib/logic/estimateFees.js +25 -0
- package/lib/logic/estimateFees.js.map +1 -0
- package/lib/logic/getAssetFromToken.d.ts +4 -0
- package/lib/logic/getAssetFromToken.d.ts.map +1 -0
- package/lib/logic/getAssetFromToken.js +14 -0
- package/lib/logic/getAssetFromToken.js.map +1 -0
- package/lib/logic/getBalance.d.ts +4 -0
- package/lib/logic/getBalance.d.ts.map +1 -0
- package/lib/logic/getBalance.js +36 -0
- package/lib/logic/getBalance.js.map +1 -0
- package/lib/logic/getTokenFromAsset.d.ts +4 -0
- package/lib/logic/getTokenFromAsset.d.ts.map +1 -0
- package/lib/logic/getTokenFromAsset.js +13 -0
- package/lib/logic/getTokenFromAsset.js.map +1 -0
- package/lib/logic/index.d.ts +10 -0
- package/lib/logic/index.d.ts.map +1 -0
- package/lib/logic/index.js +22 -0
- package/lib/logic/index.js.map +1 -0
- package/lib/logic/lastBlock.d.ts +12 -0
- package/lib/logic/lastBlock.d.ts.map +1 -0
- package/lib/logic/lastBlock.js +25 -0
- package/lib/logic/lastBlock.js.map +1 -0
- package/lib/logic/listOperations.d.ts +19 -0
- package/lib/logic/listOperations.d.ts.map +1 -0
- package/lib/logic/listOperations.js +179 -0
- package/lib/logic/listOperations.js.map +1 -0
- package/lib/logic/utils.d.ts +55 -0
- package/lib/logic/utils.d.ts.map +1 -0
- package/lib/logic/utils.js +197 -0
- package/lib/logic/utils.js.map +1 -0
- package/lib/network/api.d.ts +24 -0
- package/lib/network/api.d.ts.map +1 -0
- package/lib/network/api.js +119 -0
- package/lib/network/api.js.map +1 -0
- package/lib/network/rpc.d.ts +12 -0
- package/lib/network/rpc.d.ts.map +1 -0
- package/lib/network/rpc.js +22 -0
- package/lib/network/rpc.js.map +1 -0
- package/lib/{api → network}/utils.d.ts +1 -5
- package/lib/network/utils.d.ts.map +1 -0
- package/lib/network/utils.js +52 -0
- package/lib/network/utils.js.map +1 -0
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib/test/bridgeDatasetTest.js +5 -1
- package/lib/test/bridgeDatasetTest.js.map +1 -1
- package/lib/test/fixtures/account.fixture.d.ts +17 -0
- package/lib/test/fixtures/account.fixture.d.ts.map +1 -1
- package/lib/test/fixtures/account.fixture.js +18 -1
- package/lib/test/fixtures/account.fixture.js.map +1 -1
- package/lib/test/fixtures/currency.fixture.d.ts.map +1 -1
- package/lib/test/fixtures/currency.fixture.js +1 -1
- package/lib/test/fixtures/currency.fixture.js.map +1 -1
- package/lib/test/fixtures/mirror.fixture.d.ts +1 -1
- package/lib/test/fixtures/mirror.fixture.d.ts.map +1 -1
- package/lib/test/fixtures/network.fixture.d.ts +3 -0
- package/lib/test/fixtures/network.fixture.d.ts.map +1 -0
- package/lib/test/fixtures/network.fixture.js +9 -0
- package/lib/test/fixtures/network.fixture.js.map +1 -0
- package/lib/test/fixtures/transaction.fixture.d.ts.map +1 -1
- package/lib/test/fixtures/transaction.fixture.js +3 -0
- package/lib/test/fixtures/transaction.fixture.js.map +1 -1
- package/lib/transaction.d.ts +1 -1
- package/lib/transaction.d.ts.map +1 -1
- package/lib/transaction.js +35 -6
- package/lib/transaction.js.map +1 -1
- package/lib/types/alpaca.d.ts +3 -0
- package/lib/types/alpaca.d.ts.map +1 -0
- package/lib/{api/types.js → types/alpaca.js} +1 -1
- package/lib/types/alpaca.js.map +1 -0
- package/lib/types/bridge.d.ts +28 -9
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +2 -0
- package/lib/types/index.js.map +1 -1
- package/lib/{api/types.d.ts → types/mirror.d.ts} +21 -2
- package/lib/types/mirror.d.ts.map +1 -0
- package/lib/types/mirror.js +3 -0
- package/lib/types/mirror.js.map +1 -0
- package/lib-es/api/index.d.ts +4 -0
- package/lib-es/api/index.d.ts.map +1 -0
- package/lib-es/api/index.js +112 -0
- package/lib-es/api/index.js.map +1 -0
- package/lib-es/bridge/broadcast.d.ts +1 -1
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +4 -7
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -1
- package/lib-es/bridge/buildOptimisticOperation.js +12 -9
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -1
- package/lib-es/bridge/createTransaction.d.ts +1 -1
- package/lib-es/bridge/createTransaction.d.ts.map +1 -1
- package/lib-es/bridge/createTransaction.js +2 -0
- package/lib-es/bridge/createTransaction.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +2 -2
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +7 -6
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +4 -3
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/signOperation.d.ts +1 -1
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +53 -14
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +24 -11
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/bridge/utils.d.ts +3 -13
- package/lib-es/bridge/utils.d.ts.map +1 -1
- package/lib-es/bridge/utils.js +7 -113
- package/lib-es/bridge/utils.js.map +1 -1
- package/lib-es/config.d.ts +8 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +4 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/constants.d.ts +11 -8
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +13 -9
- package/lib-es/constants.js.map +1 -1
- package/lib-es/deviceTransactionConfig.d.ts +1 -1
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -1
- package/lib-es/deviceTransactionConfig.js +1 -1
- package/lib-es/deviceTransactionConfig.js.map +1 -1
- package/lib-es/logic/broadcast.d.ts +3 -0
- package/lib-es/logic/broadcast.d.ts.map +1 -0
- package/lib-es/logic/broadcast.js +7 -0
- package/lib-es/logic/broadcast.js.map +1 -0
- package/lib-es/logic/combine.d.ts +2 -0
- package/lib-es/logic/combine.d.ts.map +1 -0
- package/lib-es/logic/combine.js +12 -0
- package/lib-es/logic/combine.js.map +1 -0
- package/lib-es/logic/craftTransaction.d.ts +8 -0
- package/lib-es/logic/craftTransaction.d.ts.map +1 -0
- package/lib-es/logic/craftTransaction.js +100 -0
- package/lib-es/logic/craftTransaction.js.map +1 -0
- package/lib-es/logic/estimateFees.d.ts +5 -0
- package/lib-es/logic/estimateFees.d.ts.map +1 -0
- package/lib-es/logic/estimateFees.js +18 -0
- package/lib-es/logic/estimateFees.js.map +1 -0
- package/lib-es/logic/getAssetFromToken.d.ts +4 -0
- package/lib-es/logic/getAssetFromToken.d.ts.map +1 -0
- package/lib-es/logic/getAssetFromToken.js +10 -0
- package/lib-es/logic/getAssetFromToken.js.map +1 -0
- package/lib-es/logic/getBalance.d.ts +4 -0
- package/lib-es/logic/getBalance.d.ts.map +1 -0
- package/lib-es/logic/getBalance.js +32 -0
- package/lib-es/logic/getBalance.js.map +1 -0
- package/lib-es/logic/getTokenFromAsset.d.ts +4 -0
- package/lib-es/logic/getTokenFromAsset.d.ts.map +1 -0
- package/lib-es/logic/getTokenFromAsset.js +9 -0
- package/lib-es/logic/getTokenFromAsset.js.map +1 -0
- package/lib-es/logic/index.d.ts +10 -0
- package/lib-es/logic/index.d.ts.map +1 -0
- package/lib-es/logic/index.js +10 -0
- package/lib-es/logic/index.js.map +1 -0
- package/lib-es/logic/lastBlock.d.ts +12 -0
- package/lib-es/logic/lastBlock.d.ts.map +1 -0
- package/lib-es/logic/lastBlock.js +21 -0
- package/lib-es/logic/lastBlock.js.map +1 -0
- package/lib-es/logic/listOperations.d.ts +19 -0
- package/lib-es/logic/listOperations.d.ts.map +1 -0
- package/lib-es/logic/listOperations.js +172 -0
- package/lib-es/logic/listOperations.js.map +1 -0
- package/lib-es/logic/utils.d.ts +55 -0
- package/lib-es/logic/utils.d.ts.map +1 -0
- package/lib-es/logic/utils.js +174 -0
- package/lib-es/logic/utils.js.map +1 -0
- package/lib-es/network/api.d.ts +24 -0
- package/lib-es/network/api.d.ts.map +1 -0
- package/lib-es/network/api.js +113 -0
- package/lib-es/network/api.js.map +1 -0
- package/lib-es/network/rpc.d.ts +12 -0
- package/lib-es/network/rpc.d.ts.map +1 -0
- package/lib-es/network/rpc.js +19 -0
- package/lib-es/network/rpc.js.map +1 -0
- package/lib-es/{api → network}/utils.d.ts +1 -5
- package/lib-es/network/utils.d.ts.map +1 -0
- package/lib-es/network/utils.js +45 -0
- package/lib-es/network/utils.js.map +1 -0
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib-es/test/bridgeDatasetTest.js +5 -1
- package/lib-es/test/bridgeDatasetTest.js.map +1 -1
- package/lib-es/test/fixtures/account.fixture.d.ts +17 -0
- package/lib-es/test/fixtures/account.fixture.d.ts.map +1 -1
- package/lib-es/test/fixtures/account.fixture.js +17 -0
- package/lib-es/test/fixtures/account.fixture.js.map +1 -1
- package/lib-es/test/fixtures/currency.fixture.d.ts.map +1 -1
- package/lib-es/test/fixtures/currency.fixture.js +1 -1
- package/lib-es/test/fixtures/currency.fixture.js.map +1 -1
- package/lib-es/test/fixtures/mirror.fixture.d.ts +1 -1
- package/lib-es/test/fixtures/mirror.fixture.d.ts.map +1 -1
- package/lib-es/test/fixtures/network.fixture.d.ts +3 -0
- package/lib-es/test/fixtures/network.fixture.d.ts.map +1 -0
- package/lib-es/test/fixtures/network.fixture.js +5 -0
- package/lib-es/test/fixtures/network.fixture.js.map +1 -0
- package/lib-es/test/fixtures/transaction.fixture.d.ts.map +1 -1
- package/lib-es/test/fixtures/transaction.fixture.js +3 -0
- package/lib-es/test/fixtures/transaction.fixture.js.map +1 -1
- package/lib-es/transaction.d.ts +1 -1
- package/lib-es/transaction.d.ts.map +1 -1
- package/lib-es/transaction.js +35 -6
- package/lib-es/transaction.js.map +1 -1
- package/lib-es/types/alpaca.d.ts +3 -0
- package/lib-es/types/alpaca.d.ts.map +1 -0
- package/lib-es/types/alpaca.js +2 -0
- package/lib-es/types/alpaca.js.map +1 -0
- package/lib-es/types/bridge.d.ts +28 -9
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/lib-es/types/index.d.ts +2 -0
- package/lib-es/types/index.d.ts.map +1 -1
- package/lib-es/types/index.js +2 -0
- package/lib-es/types/index.js.map +1 -1
- package/lib-es/{api/types.d.ts → types/mirror.d.ts} +21 -2
- package/lib-es/types/mirror.d.ts.map +1 -0
- package/lib-es/types/mirror.js +2 -0
- package/lib-es/types/mirror.js.map +1 -0
- package/package.json +4 -3
- package/src/api/index.integ.test.ts +401 -0
- package/src/api/index.test.ts +30 -0
- package/src/api/index.ts +149 -0
- package/src/bridge/broadcast.ts +5 -10
- package/src/bridge/buildOptimisticOperation.integration.test.ts +8 -8
- package/src/bridge/buildOptimisticOperation.ts +13 -10
- package/src/bridge/createTransaction.ts +3 -1
- package/src/bridge/estimateMaxSpendable.ts +6 -3
- package/src/bridge/getTransactionStatus.test.ts +11 -10
- package/src/bridge/getTransactionStatus.ts +12 -11
- package/src/bridge/js-estimateMaxSpendable.integration.test.ts +6 -3
- package/src/bridge/prepareTransaction.test.ts +9 -17
- package/src/bridge/prepareTransaction.ts +5 -4
- package/src/bridge/serialization.test.ts +6 -6
- package/src/bridge/signOperation.ts +69 -16
- package/src/bridge/synchronisation.ts +22 -14
- package/src/bridge/utils.integration.test.ts +19 -248
- package/src/bridge/utils.ts +14 -160
- package/src/config.ts +7 -0
- package/src/constants.ts +15 -9
- package/src/deviceTransactionConfig.ts +2 -2
- package/src/logic/broadcast.test.ts +58 -0
- package/src/logic/broadcast.ts +8 -0
- package/src/logic/combine.test.ts +119 -0
- package/src/logic/combine.ts +14 -0
- package/src/logic/craftTransaction.test.ts +215 -0
- package/src/logic/craftTransaction.ts +175 -0
- package/src/logic/estimateFees.test.ts +99 -0
- package/src/logic/estimateFees.ts +28 -0
- package/src/logic/getAssetFromToken.test.ts +27 -0
- package/src/logic/getAssetFromToken.ts +12 -0
- package/src/logic/getBalance.test.ts +200 -0
- package/src/logic/getBalance.ts +39 -0
- package/src/logic/getTokenFromAsset.test.ts +22 -0
- package/src/logic/getTokenFromAsset.ts +17 -0
- package/src/logic/index.ts +9 -0
- package/src/logic/lastBlock.test.ts +23 -0
- package/src/logic/lastBlock.ts +23 -0
- package/src/logic/listOperations.test.ts +388 -0
- package/src/logic/listOperations.ts +247 -0
- package/src/logic/utils.test.ts +432 -0
- package/src/logic/utils.ts +255 -0
- package/src/{api/mirror.test.ts → network/api.test.ts} +81 -35
- package/src/network/api.ts +159 -0
- package/src/network/rpc.test.ts +68 -0
- package/src/network/rpc.ts +25 -0
- package/src/network/utils.test.ts +175 -0
- package/src/network/utils.ts +58 -0
- package/src/test/bridgeDatasetTest.ts +6 -2
- package/src/test/fixtures/account.fixture.ts +18 -0
- package/src/test/fixtures/currency.fixture.ts +1 -1
- package/src/test/fixtures/mirror.fixture.ts +1 -1
- package/src/test/fixtures/network.fixture.ts +6 -0
- package/src/test/fixtures/transaction.fixture.ts +5 -2
- package/src/transaction.ts +40 -9
- package/src/types/alpaca.ts +3 -0
- package/src/types/bridge.ts +36 -10
- package/src/types/index.ts +2 -0
- package/src/{api/types.ts → types/mirror.ts} +23 -1
- package/lib/api/mirror.d.ts +0 -6
- package/lib/api/mirror.d.ts.map +0 -1
- package/lib/api/mirror.js +0 -84
- package/lib/api/mirror.js.map +0 -1
- package/lib/api/network.d.ts +0 -11
- package/lib/api/network.d.ts.map +0 -1
- package/lib/api/network.js +0 -80
- package/lib/api/network.js.map +0 -1
- package/lib/api/types.d.ts.map +0 -1
- package/lib/api/types.js.map +0 -1
- package/lib/api/utils.d.ts.map +0 -1
- package/lib/api/utils.js +0 -132
- package/lib/api/utils.js.map +0 -1
- package/lib/logic.d.ts +0 -11
- package/lib/logic.d.ts.map +0 -1
- package/lib/logic.js +0 -37
- package/lib/logic.js.map +0 -1
- package/lib-es/api/mirror.d.ts +0 -6
- package/lib-es/api/mirror.d.ts.map +0 -1
- package/lib-es/api/mirror.js +0 -74
- package/lib-es/api/mirror.js.map +0 -1
- package/lib-es/api/network.d.ts +0 -11
- package/lib-es/api/network.d.ts.map +0 -1
- package/lib-es/api/network.js +0 -71
- package/lib-es/api/network.js.map +0 -1
- package/lib-es/api/types.d.ts.map +0 -1
- package/lib-es/api/types.js +0 -2
- package/lib-es/api/types.js.map +0 -1
- package/lib-es/api/utils.d.ts.map +0 -1
- package/lib-es/api/utils.js +0 -124
- package/lib-es/api/utils.js.map +0 -1
- package/lib-es/logic.d.ts +0 -11
- package/lib-es/logic.d.ts.map +0 -1
- package/lib-es/logic.js +0 -29
- package/lib-es/logic.js.map +0 -1
- package/src/api/mirror.ts +0 -91
- package/src/api/network.test.ts +0 -49
- package/src/api/network.ts +0 -125
- package/src/api/utils.ts +0 -150
- package/src/logic.test.ts +0 -152
- package/src/logic.ts +0 -66
|
@@ -2,10 +2,10 @@ import invariant from "invariant";
|
|
|
2
2
|
import type { Account, Operation, OperationType, TokenAccount } from "@ledgerhq/types-live";
|
|
3
3
|
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
4
4
|
import { findSubAccountById, isTokenAccount } from "@ledgerhq/coin-framework/account/helpers";
|
|
5
|
-
import type { HederaOperationExtra, Transaction } from "../types";
|
|
6
|
-
import { getEstimatedFees, safeParseAccountId } from "./utils";
|
|
7
|
-
import { isTokenAssociateTransaction } from "../logic";
|
|
8
5
|
import { HEDERA_OPERATION_TYPES } from "../constants";
|
|
6
|
+
import { estimateFees } from "../logic/estimateFees";
|
|
7
|
+
import { isTokenAssociateTransaction, safeParseAccountId } from "../logic/utils";
|
|
8
|
+
import type { HederaOperationExtra, Transaction } from "../types";
|
|
9
9
|
|
|
10
10
|
const buildOptimisticTokenAssociateOperation = async ({
|
|
11
11
|
account,
|
|
@@ -16,15 +16,14 @@ const buildOptimisticTokenAssociateOperation = async ({
|
|
|
16
16
|
}): Promise<Operation> => {
|
|
17
17
|
invariant(isTokenAssociateTransaction(transaction), "invalid transaction properties");
|
|
18
18
|
|
|
19
|
-
const estimatedFee = await
|
|
20
|
-
const value = transaction.amount;
|
|
19
|
+
const estimatedFee = await estimateFees(account.currency, HEDERA_OPERATION_TYPES.TokenAssociate);
|
|
21
20
|
const type: OperationType = "ASSOCIATE_TOKEN";
|
|
22
21
|
|
|
23
22
|
const operation: Operation = {
|
|
24
23
|
id: encodeOperationId(account.id, "", type),
|
|
25
24
|
hash: "",
|
|
26
25
|
type,
|
|
27
|
-
value,
|
|
26
|
+
value: estimatedFee,
|
|
28
27
|
fee: estimatedFee,
|
|
29
28
|
blockHash: null,
|
|
30
29
|
blockHeight: null,
|
|
@@ -52,7 +51,7 @@ const buildOptimisticCoinOperation = async ({
|
|
|
52
51
|
const estimatedFee =
|
|
53
52
|
transactionType === "FEES"
|
|
54
53
|
? transaction.amount
|
|
55
|
-
: await
|
|
54
|
+
: await estimateFees(account.currency, HEDERA_OPERATION_TYPES.CryptoTransfer);
|
|
56
55
|
const value = transaction.amount;
|
|
57
56
|
const type: OperationType = transactionType ?? "OUT";
|
|
58
57
|
const [_, recipientAddress] = safeParseAccountId(transaction.recipient);
|
|
@@ -70,7 +69,9 @@ const buildOptimisticCoinOperation = async ({
|
|
|
70
69
|
recipients: [recipientWithoutChecksum],
|
|
71
70
|
accountId: account.id,
|
|
72
71
|
date: new Date(),
|
|
73
|
-
extra: {
|
|
72
|
+
extra: {
|
|
73
|
+
...(!!transaction.memo && { memo: transaction.memo }),
|
|
74
|
+
},
|
|
74
75
|
};
|
|
75
76
|
|
|
76
77
|
return operation;
|
|
@@ -85,7 +86,7 @@ const buildOptimisticTokenOperation = async ({
|
|
|
85
86
|
tokenAccount: TokenAccount;
|
|
86
87
|
transaction: Transaction;
|
|
87
88
|
}): Promise<Operation> => {
|
|
88
|
-
const estimatedFee = await
|
|
89
|
+
const estimatedFee = await estimateFees(account.currency, HEDERA_OPERATION_TYPES.TokenTransfer);
|
|
89
90
|
const value = transaction.amount;
|
|
90
91
|
const type: OperationType = "OUT";
|
|
91
92
|
const [_, recipientAddress] = safeParseAccountId(transaction.recipient);
|
|
@@ -116,7 +117,9 @@ const buildOptimisticTokenOperation = async ({
|
|
|
116
117
|
recipients: [recipientWithoutChecksum],
|
|
117
118
|
accountId: tokenAccount.id,
|
|
118
119
|
date: new Date(),
|
|
119
|
-
extra: {
|
|
120
|
+
extra: {
|
|
121
|
+
...(!!transaction.memo && { memo: transaction.memo }),
|
|
122
|
+
},
|
|
120
123
|
},
|
|
121
124
|
],
|
|
122
125
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import { AccountBridge } from "@ledgerhq/types-live";
|
|
3
|
-
import {
|
|
3
|
+
import { HEDERA_TRANSACTION_MODES } from "../constants";
|
|
4
|
+
import type { Transaction } from "../types";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Creates an empty transaction.
|
|
@@ -8,6 +9,7 @@ import { Transaction } from "../types";
|
|
|
8
9
|
* @returns {Transaction}
|
|
9
10
|
*/
|
|
10
11
|
export const createTransaction: AccountBridge<Transaction>["createTransaction"] = () => ({
|
|
12
|
+
mode: HEDERA_TRANSACTION_MODES.Send,
|
|
11
13
|
family: "hedera",
|
|
12
14
|
amount: new BigNumber(0),
|
|
13
15
|
recipient: "",
|
|
@@ -2,9 +2,9 @@ import BigNumber from "bignumber.js";
|
|
|
2
2
|
import type { AccountBridge } from "@ledgerhq/types-live";
|
|
3
3
|
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
|
|
4
4
|
import { isTokenAccount } from "@ledgerhq/coin-framework/account/helpers";
|
|
5
|
-
import type { Transaction } from "../types";
|
|
6
|
-
import { getEstimatedFees } from "./utils";
|
|
7
5
|
import { HEDERA_OPERATION_TYPES } from "../constants";
|
|
6
|
+
import { estimateFees } from "../logic/estimateFees";
|
|
7
|
+
import type { Transaction } from "../types";
|
|
8
8
|
|
|
9
9
|
export const estimateMaxSpendable: AccountBridge<Transaction>["estimateMaxSpendable"] = async ({
|
|
10
10
|
account,
|
|
@@ -18,7 +18,10 @@ export const estimateMaxSpendable: AccountBridge<Transaction>["estimateMaxSpenda
|
|
|
18
18
|
return Promise.resolve(balance);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const estimatedFees = await
|
|
21
|
+
const estimatedFees = await estimateFees(
|
|
22
|
+
mainAccount.currency,
|
|
23
|
+
HEDERA_OPERATION_TYPES.CryptoTransfer,
|
|
24
|
+
);
|
|
22
25
|
let maxSpendable = balance.minus(estimatedFees);
|
|
23
26
|
|
|
24
27
|
// set max spendable to 0 if negative
|
|
@@ -5,18 +5,19 @@ import {
|
|
|
5
5
|
AmountRequired,
|
|
6
6
|
NotEnoughBalance,
|
|
7
7
|
} from "@ledgerhq/errors";
|
|
8
|
+
import { HEDERA_TRANSACTION_MODES } from "../constants";
|
|
8
9
|
import {
|
|
9
10
|
HederaRecipientInvalidChecksum,
|
|
10
11
|
HederaInsufficientFundsForAssociation,
|
|
11
12
|
HederaRecipientTokenAssociationRequired,
|
|
12
13
|
HederaRecipientTokenAssociationUnverified,
|
|
13
14
|
} from "../errors";
|
|
15
|
+
import { getTransactionStatus } from "./getTransactionStatus";
|
|
16
|
+
import * as estimateFees from "../logic/estimateFees";
|
|
17
|
+
import * as logicUtils from "../logic/utils";
|
|
14
18
|
import { getMockedAccount, getMockedTokenAccount } from "../test/fixtures/account.fixture";
|
|
15
19
|
import { getMockedTokenCurrency } from "../test/fixtures/currency.fixture";
|
|
16
20
|
import { getMockedTransaction } from "../test/fixtures/transaction.fixture";
|
|
17
|
-
import { getTransactionStatus } from "./getTransactionStatus";
|
|
18
|
-
import * as utils from "./utils";
|
|
19
|
-
import { HEDERA_TRANSACTION_KINDS } from "../constants";
|
|
20
21
|
|
|
21
22
|
describe("getTransactionStatus", () => {
|
|
22
23
|
const mockedEstimatedFee = new BigNumber(1);
|
|
@@ -27,8 +28,8 @@ describe("getTransactionStatus", () => {
|
|
|
27
28
|
beforeEach(() => {
|
|
28
29
|
jest.clearAllMocks();
|
|
29
30
|
|
|
30
|
-
jest.spyOn(
|
|
31
|
-
jest.spyOn(
|
|
31
|
+
jest.spyOn(logicUtils, "getCurrencyToUSDRate").mockResolvedValueOnce(mockedUsdRate);
|
|
32
|
+
jest.spyOn(estimateFees, "estimateFees").mockResolvedValueOnce(mockedEstimatedFee);
|
|
32
33
|
});
|
|
33
34
|
|
|
34
35
|
test("coin transfer with valid recipient and sufficient balance completes successfully", async () => {
|
|
@@ -47,7 +48,7 @@ describe("getTransactionStatus", () => {
|
|
|
47
48
|
});
|
|
48
49
|
|
|
49
50
|
test("token transfer with valid recipient and sufficient balance completes successfully", async () => {
|
|
50
|
-
jest.spyOn(
|
|
51
|
+
jest.spyOn(logicUtils, "checkAccountTokenAssociationStatus").mockResolvedValueOnce(true);
|
|
51
52
|
|
|
52
53
|
const tokenCurrency = getMockedTokenCurrency();
|
|
53
54
|
const tokenAccount = getMockedTokenAccount(tokenCurrency, { balance: new BigNumber(500) });
|
|
@@ -69,8 +70,8 @@ describe("getTransactionStatus", () => {
|
|
|
69
70
|
const mockedTokenCurrency = getMockedTokenCurrency();
|
|
70
71
|
const mockedAccount = getMockedAccount();
|
|
71
72
|
const mockedTransaction = getMockedTransaction({
|
|
73
|
+
mode: HEDERA_TRANSACTION_MODES.TokenAssociate,
|
|
72
74
|
properties: {
|
|
73
|
-
name: HEDERA_TRANSACTION_KINDS.TokenAssociate.name,
|
|
74
75
|
token: mockedTokenCurrency,
|
|
75
76
|
},
|
|
76
77
|
});
|
|
@@ -139,8 +140,8 @@ describe("getTransactionStatus", () => {
|
|
|
139
140
|
const mockedTokenCurrency = getMockedTokenCurrency();
|
|
140
141
|
const mockedAccount = getMockedAccount({ balance: new BigNumber(0) });
|
|
141
142
|
const mockedTransaction = getMockedTransaction({
|
|
143
|
+
mode: HEDERA_TRANSACTION_MODES.TokenAssociate,
|
|
142
144
|
properties: {
|
|
143
|
-
name: HEDERA_TRANSACTION_KINDS.TokenAssociate.name,
|
|
144
145
|
token: mockedTokenCurrency,
|
|
145
146
|
},
|
|
146
147
|
});
|
|
@@ -153,7 +154,7 @@ describe("getTransactionStatus", () => {
|
|
|
153
154
|
});
|
|
154
155
|
|
|
155
156
|
test("adds warning during token transfer if recipient has no token associated", async () => {
|
|
156
|
-
jest.spyOn(
|
|
157
|
+
jest.spyOn(logicUtils, "checkAccountTokenAssociationStatus").mockResolvedValueOnce(false);
|
|
157
158
|
|
|
158
159
|
const mockedTokenCurrency = getMockedTokenCurrency();
|
|
159
160
|
const mockedTokenAccount = getMockedTokenAccount(mockedTokenCurrency);
|
|
@@ -172,7 +173,7 @@ describe("getTransactionStatus", () => {
|
|
|
172
173
|
|
|
173
174
|
test("adds warning if token association status can't be verified", async () => {
|
|
174
175
|
jest
|
|
175
|
-
.spyOn(
|
|
176
|
+
.spyOn(logicUtils, "checkAccountTokenAssociationStatus")
|
|
176
177
|
.mockRejectedValueOnce(new HederaRecipientTokenAssociationUnverified());
|
|
177
178
|
|
|
178
179
|
const mockedTokenCurrency = getMockedTokenCurrency();
|
|
@@ -8,21 +8,22 @@ import {
|
|
|
8
8
|
import type { Account, AccountBridge, TokenAccount } from "@ledgerhq/types-live";
|
|
9
9
|
import { findSubAccountById, isTokenAccount } from "@ledgerhq/coin-framework/account";
|
|
10
10
|
import { getEnv } from "@ledgerhq/live-env";
|
|
11
|
+
import { HEDERA_OPERATION_TYPES } from "../constants";
|
|
11
12
|
import {
|
|
12
13
|
HederaInsufficientFundsForAssociation,
|
|
13
14
|
HederaRecipientTokenAssociationRequired,
|
|
14
15
|
HederaRecipientTokenAssociationUnverified,
|
|
15
16
|
} from "../errors";
|
|
16
|
-
import {
|
|
17
|
-
import type { TokenAssociateProperties, Transaction, TransactionStatus } from "../types";
|
|
17
|
+
import { estimateFees } from "../logic/estimateFees";
|
|
18
18
|
import {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
isTokenAssociateTransaction,
|
|
20
|
+
isTokenAssociationRequired,
|
|
21
21
|
getCurrencyToUSDRate,
|
|
22
|
-
|
|
22
|
+
checkAccountTokenAssociationStatus,
|
|
23
23
|
safeParseAccountId,
|
|
24
|
-
} from "
|
|
25
|
-
import {
|
|
24
|
+
} from "../logic/utils";
|
|
25
|
+
import type { Transaction, TransactionStatus, TransactionTokenAssociate } from "../types";
|
|
26
|
+
import { calculateAmount } from "./utils";
|
|
26
27
|
|
|
27
28
|
type Errors = Record<string, Error>;
|
|
28
29
|
type Warnings = Record<string, Error>;
|
|
@@ -49,14 +50,14 @@ function validateRecipient(account: Account, recipient: string): Error | null {
|
|
|
49
50
|
|
|
50
51
|
async function handleTokenAssociateTransaction(
|
|
51
52
|
account: Account,
|
|
52
|
-
transaction:
|
|
53
|
+
transaction: TransactionTokenAssociate,
|
|
53
54
|
): Promise<TransactionStatus> {
|
|
54
55
|
const errors: Errors = {};
|
|
55
56
|
const warnings: Warnings = {};
|
|
56
57
|
|
|
57
58
|
const [usdRate, estimatedFees] = await Promise.all([
|
|
58
59
|
getCurrencyToUSDRate(account.currency),
|
|
59
|
-
|
|
60
|
+
estimateFees(account.currency, HEDERA_OPERATION_TYPES.TokenAssociate),
|
|
60
61
|
]);
|
|
61
62
|
|
|
62
63
|
const amount = BigNumber(0);
|
|
@@ -93,7 +94,7 @@ async function handleTokenTransaction(
|
|
|
93
94
|
const warnings: Warnings = {};
|
|
94
95
|
const [calculatedAmount, estimatedFees] = await Promise.all([
|
|
95
96
|
calculateAmount({ transaction, account }),
|
|
96
|
-
|
|
97
|
+
estimateFees(account.currency, HEDERA_OPERATION_TYPES.TokenTransfer),
|
|
97
98
|
]);
|
|
98
99
|
|
|
99
100
|
const recipientError = validateRecipient(account, transaction.recipient);
|
|
@@ -146,7 +147,7 @@ async function handleCoinTransaction(
|
|
|
146
147
|
const warnings: Warnings = {};
|
|
147
148
|
const [calculatedAmount, estimatedFees] = await Promise.all([
|
|
148
149
|
calculateAmount({ transaction, account }),
|
|
149
|
-
|
|
150
|
+
estimateFees(account.currency, HEDERA_OPERATION_TYPES.CryptoTransfer),
|
|
150
151
|
]);
|
|
151
152
|
|
|
152
153
|
const recipientError = validateRecipient(account, transaction.recipient);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import { createBridges } from ".";
|
|
3
|
-
import {
|
|
3
|
+
import { HEDERA_OPERATION_TYPES } from "../constants";
|
|
4
|
+
import { estimateFees } from "../logic/estimateFees";
|
|
4
5
|
import { getMockedAccount, getMockedTokenAccount } from "../test/fixtures/account.fixture";
|
|
5
6
|
import { getMockedTokenCurrency } from "../test/fixtures/currency.fixture";
|
|
6
|
-
import { HEDERA_OPERATION_TYPES } from "../constants";
|
|
7
7
|
|
|
8
8
|
describe("js-estimateMaxSpendable", () => {
|
|
9
9
|
let bridge: ReturnType<typeof createBridges>;
|
|
@@ -14,7 +14,10 @@ describe("js-estimateMaxSpendable", () => {
|
|
|
14
14
|
bridge = createBridges(signer);
|
|
15
15
|
|
|
16
16
|
const mockedAccount = getMockedAccount();
|
|
17
|
-
const crypto = await
|
|
17
|
+
const crypto = await estimateFees(
|
|
18
|
+
mockedAccount.currency,
|
|
19
|
+
HEDERA_OPERATION_TYPES.CryptoTransfer,
|
|
20
|
+
);
|
|
18
21
|
|
|
19
22
|
estimatedFees = { crypto };
|
|
20
23
|
});
|
|
@@ -1,28 +1,20 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
|
-
import
|
|
3
|
-
import * as utils from "./utils";
|
|
2
|
+
import { estimateFees } from "../logic/estimateFees";
|
|
4
3
|
import { prepareTransaction } from "./prepareTransaction";
|
|
5
|
-
import {
|
|
4
|
+
import { getMockedAccount } from "../test/fixtures/account.fixture";
|
|
5
|
+
import { getMockedTransaction } from "../test/fixtures/transaction.fixture";
|
|
6
|
+
import * as utils from "./utils";
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
const mockAccount = {
|
|
9
|
-
id: "hedera:0:testAccount",
|
|
10
|
-
freshAddress: "0.0.123",
|
|
11
|
-
spendableBalance: new BigNumber(1000000),
|
|
12
|
-
currency: { id: "hedera" },
|
|
13
|
-
} as Account;
|
|
8
|
+
jest.mock("../logic/estimateFees");
|
|
14
9
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
recipient: "",
|
|
19
|
-
useAllAmount: false,
|
|
20
|
-
} as Transaction;
|
|
10
|
+
describe("prepareTransaction", () => {
|
|
11
|
+
const mockAccount = getMockedAccount();
|
|
12
|
+
const mockTx = getMockedTransaction();
|
|
21
13
|
|
|
22
14
|
beforeEach(() => {
|
|
23
15
|
jest.clearAllMocks();
|
|
24
16
|
|
|
25
|
-
jest.
|
|
17
|
+
(estimateFees as jest.Mock).mockResolvedValue(Promise.resolve(new BigNumber(10)));
|
|
26
18
|
jest
|
|
27
19
|
.spyOn(utils, "calculateAmount")
|
|
28
20
|
.mockResolvedValue(
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { findSubAccountById, isTokenAccount } from "@ledgerhq/coin-framework/account/helpers";
|
|
2
2
|
import type { AccountBridge } from "@ledgerhq/types-live";
|
|
3
|
-
import type { Transaction } from "../types";
|
|
4
|
-
import { calculateAmount, getEstimatedFees } from "./utils";
|
|
5
3
|
import { HEDERA_OPERATION_TYPES } from "../constants";
|
|
6
|
-
import {
|
|
4
|
+
import { estimateFees } from "../logic/estimateFees";
|
|
5
|
+
import { isTokenAssociateTransaction } from "../logic/utils";
|
|
6
|
+
import type { Transaction } from "../types";
|
|
7
|
+
import { calculateAmount } from "./utils";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Gather any more neccessary information for a transaction,
|
|
@@ -33,7 +34,7 @@ export const prepareTransaction: AccountBridge<Transaction>["prepareTransaction"
|
|
|
33
34
|
// i.e. if `useAllAmount` has been toggled to true, this is where it will update the transaction to reflect that action
|
|
34
35
|
const [{ amount }, estimatedFees] = await Promise.all([
|
|
35
36
|
calculateAmount({ account, transaction }),
|
|
36
|
-
|
|
37
|
+
estimateFees(account.currency, operationType),
|
|
37
38
|
]);
|
|
38
39
|
|
|
39
40
|
// `maxFee` must be explicitly set to avoid the @hashgraph/sdk default fallback
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getMockedAccount,
|
|
3
|
-
getMockedAccountRaw,
|
|
4
|
-
mockHederaResources,
|
|
5
|
-
mockHederaResourcesRaw,
|
|
6
|
-
} from "../test/fixtures/account.fixture";
|
|
7
1
|
import {
|
|
8
2
|
assignFromAccountRaw,
|
|
9
3
|
assignToAccountRaw,
|
|
10
4
|
fromHederaResourcesRaw,
|
|
11
5
|
toHederaResourcesRaw,
|
|
12
6
|
} from "./serialization";
|
|
7
|
+
import {
|
|
8
|
+
getMockedAccount,
|
|
9
|
+
getMockedAccountRaw,
|
|
10
|
+
mockHederaResources,
|
|
11
|
+
mockHederaResourcesRaw,
|
|
12
|
+
} from "../test/fixtures/account.fixture";
|
|
13
13
|
|
|
14
14
|
const mockedAccount = getMockedAccount();
|
|
15
15
|
const mockedAccountRaw = getMockedAccountRaw();
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { Observable } from "rxjs";
|
|
2
|
-
import { PublicKey } from "@hashgraph/sdk";
|
|
3
2
|
import { Account, AccountBridge } from "@ledgerhq/types-live";
|
|
4
|
-
import {
|
|
5
|
-
import { buildUnsignedTransaction } from "../api/network";
|
|
3
|
+
import { AssetInfo, FeeEstimation } from "@ledgerhq/coin-framework/api/types";
|
|
6
4
|
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
7
|
-
import {
|
|
5
|
+
import { findSubAccountById, isTokenAccount } from "@ledgerhq/coin-framework/account/helpers";
|
|
6
|
+
import { buildOptimisticOperation } from "./buildOptimisticOperation";
|
|
7
|
+
import { HEDERA_TRANSACTION_MODES } from "../constants";
|
|
8
|
+
import { combine } from "../logic/combine";
|
|
9
|
+
import { craftTransaction } from "../logic/craftTransaction";
|
|
10
|
+
import {
|
|
11
|
+
serializeSignature,
|
|
12
|
+
serializeTransaction,
|
|
13
|
+
getHederaTransactionBodyBytes,
|
|
14
|
+
isTokenAssociateTransaction,
|
|
15
|
+
} from "../logic/utils";
|
|
16
|
+
import type { Transaction, HederaSigner } from "../types";
|
|
8
17
|
|
|
9
18
|
export const buildSignOperation =
|
|
10
19
|
(
|
|
@@ -18,18 +27,63 @@ export const buildSignOperation =
|
|
|
18
27
|
type: "device-signature-requested",
|
|
19
28
|
});
|
|
20
29
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
let type: Transaction["mode"];
|
|
31
|
+
let asset: AssetInfo;
|
|
32
|
+
const accountAddress = account.freshAddress;
|
|
33
|
+
const accountPublicKey = account.seedIdentifier;
|
|
34
|
+
const subAccount = findSubAccountById(account, transaction.subAccountId || "");
|
|
35
|
+
const isTokenTransaction = isTokenAccount(subAccount);
|
|
36
|
+
|
|
37
|
+
if (isTokenAssociateTransaction(transaction)) {
|
|
38
|
+
type = HEDERA_TRANSACTION_MODES.TokenAssociate;
|
|
39
|
+
asset = {
|
|
40
|
+
type: transaction.properties.token.tokenType,
|
|
41
|
+
assetReference: transaction.properties.token.contractAddress,
|
|
42
|
+
};
|
|
43
|
+
} else if (isTokenTransaction) {
|
|
44
|
+
type = HEDERA_TRANSACTION_MODES.Send;
|
|
45
|
+
asset = {
|
|
46
|
+
type: subAccount.token.tokenType,
|
|
47
|
+
assetReference: subAccount.token.contractAddress,
|
|
48
|
+
assetOwner: accountAddress,
|
|
49
|
+
};
|
|
50
|
+
} else {
|
|
51
|
+
type = HEDERA_TRANSACTION_MODES.Send;
|
|
52
|
+
asset = {
|
|
53
|
+
type: "native",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const customFees: FeeEstimation | undefined = transaction.maxFee
|
|
58
|
+
? { value: BigInt(transaction.maxFee.toString()) }
|
|
59
|
+
: undefined;
|
|
60
|
+
|
|
61
|
+
const signedTx = await signerContext(deviceId, async signer => {
|
|
62
|
+
const { tx } = await craftTransaction(
|
|
63
|
+
{
|
|
64
|
+
intentType: "transaction",
|
|
65
|
+
type,
|
|
66
|
+
asset,
|
|
67
|
+
amount: BigInt(transaction.amount.toString()),
|
|
68
|
+
sender: accountAddress,
|
|
69
|
+
recipient: transaction.recipient,
|
|
70
|
+
memo: {
|
|
71
|
+
kind: "text",
|
|
72
|
+
type: "string",
|
|
73
|
+
value: transaction.memo ?? "",
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
customFees,
|
|
77
|
+
);
|
|
25
78
|
|
|
26
|
-
|
|
79
|
+
const txBodyBytes = getHederaTransactionBodyBytes(tx);
|
|
80
|
+
const signatureBytes = await signer.signTransaction(txBodyBytes);
|
|
27
81
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
82
|
+
return combine(
|
|
83
|
+
serializeTransaction(tx),
|
|
84
|
+
serializeSignature(signatureBytes),
|
|
85
|
+
accountPublicKey,
|
|
86
|
+
);
|
|
33
87
|
});
|
|
34
88
|
|
|
35
89
|
o.next({
|
|
@@ -45,8 +99,7 @@ export const buildSignOperation =
|
|
|
45
99
|
type: "signed",
|
|
46
100
|
signedOperation: {
|
|
47
101
|
operation,
|
|
48
|
-
|
|
49
|
-
signature: Buffer.from(res).toString("base64"),
|
|
102
|
+
signature: signedTx,
|
|
50
103
|
},
|
|
51
104
|
});
|
|
52
105
|
|
|
@@ -8,7 +8,9 @@ import type {
|
|
|
8
8
|
} from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
9
9
|
import { mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
10
10
|
import { encodeAccountId } from "@ledgerhq/coin-framework/account";
|
|
11
|
-
import {
|
|
11
|
+
import { listOperations } from "../logic/listOperations";
|
|
12
|
+
import { apiClient } from "../network/api";
|
|
13
|
+
import type { HederaAccount } from "../types";
|
|
12
14
|
import {
|
|
13
15
|
getSubAccounts,
|
|
14
16
|
prepareOperations,
|
|
@@ -16,8 +18,6 @@ import {
|
|
|
16
18
|
mergeSubAccounts,
|
|
17
19
|
getSyncHash,
|
|
18
20
|
} from "./utils";
|
|
19
|
-
import type { HederaAccount } from "../types";
|
|
20
|
-
import { getOperationsForAccount } from "../api/utils";
|
|
21
21
|
|
|
22
22
|
export const getAccountShape: GetAccountShape<HederaAccount> = async (
|
|
23
23
|
info,
|
|
@@ -39,8 +39,8 @@ export const getAccountShape: GetAccountShape<HederaAccount> = async (
|
|
|
39
39
|
// tokens are fetched with separate requests to get "created_timestamp" for each token
|
|
40
40
|
// based on this, ASSOCIATE_TOKEN operations can be connected with tokens
|
|
41
41
|
const [mirrorAccount, mirrorTokens] = await Promise.all([
|
|
42
|
-
getAccount(address),
|
|
43
|
-
getAccountTokens(address),
|
|
42
|
+
apiClient.getAccount(address),
|
|
43
|
+
apiClient.getAccountTokens(address),
|
|
44
44
|
]);
|
|
45
45
|
|
|
46
46
|
const accountBalance = new BigNumber(mirrorAccount.balance.balance);
|
|
@@ -53,15 +53,24 @@ export const getAccountShape: GetAccountShape<HederaAccount> = async (
|
|
|
53
53
|
const pendingOperations = initialAccount?.pendingOperations ?? [];
|
|
54
54
|
|
|
55
55
|
// grab latest operation's consensus timestamp for incremental sync
|
|
56
|
+
const latestOperation = oldOperations[0];
|
|
56
57
|
const latestOperationTimestamp =
|
|
57
|
-
!shouldSyncFromScratch &&
|
|
58
|
-
? new BigNumber(Math.floor(
|
|
58
|
+
!shouldSyncFromScratch && latestOperation
|
|
59
|
+
? new BigNumber(Math.floor(latestOperation.date.getTime() / 1000))
|
|
59
60
|
: null;
|
|
60
|
-
const latestAccountOperations = await
|
|
61
|
-
|
|
61
|
+
const latestAccountOperations = await listOperations({
|
|
62
|
+
currency,
|
|
62
63
|
address,
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
mirrorTokens,
|
|
65
|
+
pagination: {
|
|
66
|
+
minHeight: 0,
|
|
67
|
+
...(latestOperationTimestamp && { lastPagingToken: latestOperationTimestamp.toString() }),
|
|
68
|
+
},
|
|
69
|
+
fetchAllPages: true,
|
|
70
|
+
skipFeesForTokenOperations: false,
|
|
71
|
+
useEncodedHash: true,
|
|
72
|
+
useSyntheticBlocks: false,
|
|
73
|
+
});
|
|
65
74
|
|
|
66
75
|
const newSubAccounts = await getSubAccounts(
|
|
67
76
|
liveAccountId,
|
|
@@ -72,7 +81,6 @@ export const getAccountShape: GetAccountShape<HederaAccount> = async (
|
|
|
72
81
|
const newOperations = prepareOperations(
|
|
73
82
|
latestAccountOperations.coinOperations,
|
|
74
83
|
latestAccountOperations.tokenOperations,
|
|
75
|
-
mirrorTokens,
|
|
76
84
|
);
|
|
77
85
|
const enrichedNewOperations = applyPendingExtras(newOperations, pendingOperations);
|
|
78
86
|
const operations = shouldSyncFromScratch
|
|
@@ -100,7 +108,7 @@ export const getAccountShape: GetAccountShape<HederaAccount> = async (
|
|
|
100
108
|
};
|
|
101
109
|
|
|
102
110
|
export const buildIterateResult: IterateResultBuilder = async ({ result: rootResult }) => {
|
|
103
|
-
const mirrorAccounts = await getAccountsForPublicKey(rootResult.publicKey);
|
|
111
|
+
const mirrorAccounts = await apiClient.getAccountsForPublicKey(rootResult.publicKey);
|
|
104
112
|
const addresses = mirrorAccounts.map(a => a.account);
|
|
105
113
|
|
|
106
114
|
return async ({ currency, derivationMode, index }) => {
|
|
@@ -117,7 +125,7 @@ export const buildIterateResult: IterateResultBuilder = async ({ result: rootRes
|
|
|
117
125
|
address: addresses[index],
|
|
118
126
|
publicKey: addresses[index],
|
|
119
127
|
path: freshAddressPath,
|
|
120
|
-
}
|
|
128
|
+
} satisfies Result)
|
|
121
129
|
: null;
|
|
122
130
|
};
|
|
123
131
|
};
|