@ledgerhq/live-common 34.45.0-nightly.1 → 34.45.0-nightly.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/__tests__/test-helpers/bridge.d.ts.map +1 -1
- package/lib/__tests__/test-helpers/bridge.js +3 -1
- package/lib/__tests__/test-helpers/bridge.js.map +1 -1
- package/lib/braze/anonymousUsers.d.ts +1 -0
- package/lib/braze/anonymousUsers.d.ts.map +1 -1
- package/lib/braze/anonymousUsers.js +7 -5
- package/lib/braze/anonymousUsers.js.map +1 -1
- package/lib/bridge/generic-alpaca/accountBridge.d.ts +1 -1
- package/lib/bridge/generic-alpaca/accountBridge.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/accountBridge.js.map +1 -1
- package/lib/bridge/generic-alpaca/alpaca/index.d.ts +1 -1
- package/lib/bridge/generic-alpaca/alpaca/index.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/alpaca/index.js +4 -2
- package/lib/bridge/generic-alpaca/alpaca/index.js.map +1 -1
- package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts +4 -4
- package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.js +10 -10
- package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.js.map +1 -1
- package/lib/bridge/generic-alpaca/broadcast.d.ts +1 -1
- package/lib/bridge/generic-alpaca/broadcast.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/broadcast.js.map +1 -1
- package/lib/bridge/generic-alpaca/buildSubAccounts.d.ts +17 -0
- package/lib/bridge/generic-alpaca/buildSubAccounts.d.ts.map +1 -0
- package/lib/bridge/generic-alpaca/buildSubAccounts.js +75 -0
- package/lib/bridge/generic-alpaca/buildSubAccounts.js.map +1 -0
- package/lib/bridge/generic-alpaca/createTransaction.d.ts +17 -9
- package/lib/bridge/generic-alpaca/createTransaction.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/createTransaction.js +36 -10
- package/lib/bridge/generic-alpaca/createTransaction.js.map +1 -1
- package/lib/bridge/generic-alpaca/currencyBridge.d.ts +1 -1
- package/lib/bridge/generic-alpaca/currencyBridge.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/currencyBridge.js.map +1 -1
- package/lib/bridge/generic-alpaca/estimateMaxSpendable.d.ts +1 -1
- package/lib/bridge/generic-alpaca/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/estimateMaxSpendable.js +9 -0
- package/lib/bridge/generic-alpaca/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/generic-alpaca/getAccountShape.d.ts +1 -1
- package/lib/bridge/generic-alpaca/getAccountShape.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/getAccountShape.js +66 -37
- package/lib/bridge/generic-alpaca/getAccountShape.js.map +1 -1
- package/lib/bridge/generic-alpaca/getTransactionStatus.d.ts +1 -1
- package/lib/bridge/generic-alpaca/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/getTransactionStatus.js +27 -15
- package/lib/bridge/generic-alpaca/getTransactionStatus.js.map +1 -1
- package/lib/bridge/generic-alpaca/prepareTransaction.d.ts +5 -1
- package/lib/bridge/generic-alpaca/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/prepareTransaction.js +28 -5
- package/lib/bridge/generic-alpaca/prepareTransaction.js.map +1 -1
- package/lib/bridge/generic-alpaca/signOperation.d.ts +1 -1
- package/lib/bridge/generic-alpaca/signOperation.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/signOperation.js +64 -13
- package/lib/bridge/generic-alpaca/signOperation.js.map +1 -1
- package/lib/bridge/generic-alpaca/signer/index.d.ts +1 -1
- package/lib/bridge/generic-alpaca/signer/index.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/signer/index.js +38 -5
- package/lib/bridge/generic-alpaca/signer/index.js.map +1 -1
- package/lib/bridge/generic-alpaca/signer/signTransaction.d.ts +2 -0
- package/lib/bridge/generic-alpaca/signer/signTransaction.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/signer/signTransaction.js +8 -1
- package/lib/bridge/generic-alpaca/signer/signTransaction.js.map +1 -1
- package/lib/bridge/generic-alpaca/signer/types.d.ts +3 -0
- package/lib/bridge/generic-alpaca/signer/types.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/tests/estimateMaxSpendable.test.js +70 -46
- package/lib/bridge/generic-alpaca/tests/estimateMaxSpendable.test.js.map +1 -1
- package/lib/bridge/generic-alpaca/tests/prepareTransaction.test.js +1 -1
- package/lib/bridge/generic-alpaca/tests/prepareTransaction.test.js.map +1 -1
- package/lib/bridge/generic-alpaca/tests/signOperation.test.js +25 -22
- package/lib/bridge/generic-alpaca/tests/signOperation.test.js.map +1 -1
- package/lib/bridge/generic-alpaca/tests/utils.test.d.ts.map +1 -0
- package/lib/bridge/generic-alpaca/{utils.test.js → tests/utils.test.js} +1 -1
- package/lib/bridge/generic-alpaca/tests/utils.test.js.map +1 -0
- package/lib/bridge/generic-alpaca/utils.d.ts +36 -1
- package/lib/bridge/generic-alpaca/utils.d.ts.map +1 -1
- package/lib/bridge/generic-alpaca/utils.js +130 -14
- package/lib/bridge/generic-alpaca/utils.js.map +1 -1
- package/lib/bridge/impl.d.ts.map +1 -1
- package/lib/bridge/impl.js +5 -4
- package/lib/bridge/impl.js.map +1 -1
- package/lib/e2e/enum/Account.js +4 -4
- package/lib/e2e/enum/Account.js.map +1 -1
- package/lib/e2e/enum/AppInfos.d.ts +1 -1
- package/lib/e2e/enum/AppInfos.d.ts.map +1 -1
- package/lib/e2e/enum/AppInfos.js +1 -1
- package/lib/e2e/enum/AppInfos.js.map +1 -1
- package/lib/e2e/enum/Currency.d.ts.map +1 -1
- package/lib/e2e/enum/Currency.js +3 -3
- package/lib/e2e/enum/Currency.js.map +1 -1
- package/lib/e2e/speculos.js +2 -2
- package/lib/e2e/speculos.js.map +1 -1
- package/lib/families/stellar/bridge/logic.d.ts +1 -1
- package/lib/families/stellar/bridge/logic.d.ts.map +1 -1
- package/lib/families/stellar/bridge/logic.js +1 -1
- package/lib/families/stellar/bridge/logic.js.map +1 -1
- package/lib/families/stellar/bridge/mock.js +2 -2
- package/lib/families/stellar/bridge/mock.js.map +1 -1
- package/lib/families/stellar/setup.d.ts +3 -6
- package/lib/families/stellar/setup.d.ts.map +1 -1
- package/lib/families/stellar/setup.js +3 -12
- package/lib/families/stellar/setup.js.map +1 -1
- package/lib/families/xrp/bridge/mock.js +2 -2
- package/lib/families/xrp/bridge/mock.js.map +1 -1
- package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib/featureFlags/defaultFeatures.js +4 -2
- package/lib/featureFlags/defaultFeatures.js.map +1 -1
- package/lib/generated/bridge/js.d.ts +0 -1
- package/lib/generated/bridge/js.d.ts.map +1 -1
- package/lib/generated/bridge/js.js +12 -14
- package/lib/generated/bridge/js.js.map +1 -1
- package/lib/generated/transaction.d.ts +1 -1
- package/lib/modularDrawer/__test__/useModularDrawerVisibility.test.js +229 -14
- package/lib/modularDrawer/__test__/useModularDrawerVisibility.test.js.map +1 -1
- package/lib/modularDrawer/enums.d.ts +0 -1
- package/lib/modularDrawer/enums.d.ts.map +1 -1
- package/lib/modularDrawer/enums.js +0 -1
- package/lib/modularDrawer/enums.js.map +1 -1
- package/lib/modularDrawer/useModularDrawerVisibility.d.ts +7 -1
- package/lib/modularDrawer/useModularDrawerVisibility.d.ts.map +1 -1
- package/lib/modularDrawer/useModularDrawerVisibility.js +18 -2
- package/lib/modularDrawer/useModularDrawerVisibility.js.map +1 -1
- package/lib-es/__tests__/test-helpers/bridge.d.ts.map +1 -1
- package/lib-es/__tests__/test-helpers/bridge.js +3 -1
- package/lib-es/__tests__/test-helpers/bridge.js.map +1 -1
- package/lib-es/braze/anonymousUsers.d.ts +1 -0
- package/lib-es/braze/anonymousUsers.d.ts.map +1 -1
- package/lib-es/braze/anonymousUsers.js +5 -4
- package/lib-es/braze/anonymousUsers.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/accountBridge.d.ts +1 -1
- package/lib-es/bridge/generic-alpaca/accountBridge.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/accountBridge.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/alpaca/index.d.ts +1 -1
- package/lib-es/bridge/generic-alpaca/alpaca/index.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/alpaca/index.js +4 -2
- package/lib-es/bridge/generic-alpaca/alpaca/index.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts +4 -4
- package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.js +10 -10
- package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/broadcast.d.ts +1 -1
- package/lib-es/bridge/generic-alpaca/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/broadcast.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/buildSubAccounts.d.ts +17 -0
- package/lib-es/bridge/generic-alpaca/buildSubAccounts.d.ts.map +1 -0
- package/lib-es/bridge/generic-alpaca/buildSubAccounts.js +65 -0
- package/lib-es/bridge/generic-alpaca/buildSubAccounts.js.map +1 -0
- package/lib-es/bridge/generic-alpaca/createTransaction.d.ts +17 -9
- package/lib-es/bridge/generic-alpaca/createTransaction.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/createTransaction.js +35 -9
- package/lib-es/bridge/generic-alpaca/createTransaction.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/currencyBridge.d.ts +1 -1
- package/lib-es/bridge/generic-alpaca/currencyBridge.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/currencyBridge.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/estimateMaxSpendable.d.ts +1 -1
- package/lib-es/bridge/generic-alpaca/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/estimateMaxSpendable.js +9 -0
- package/lib-es/bridge/generic-alpaca/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/getAccountShape.d.ts +1 -1
- package/lib-es/bridge/generic-alpaca/getAccountShape.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/getAccountShape.js +66 -37
- package/lib-es/bridge/generic-alpaca/getAccountShape.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/getTransactionStatus.d.ts +1 -1
- package/lib-es/bridge/generic-alpaca/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/getTransactionStatus.js +27 -15
- package/lib-es/bridge/generic-alpaca/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/prepareTransaction.d.ts +5 -1
- package/lib-es/bridge/generic-alpaca/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/prepareTransaction.js +26 -4
- package/lib-es/bridge/generic-alpaca/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/signOperation.d.ts +1 -1
- package/lib-es/bridge/generic-alpaca/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/signOperation.js +61 -13
- package/lib-es/bridge/generic-alpaca/signOperation.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/signer/index.d.ts +1 -1
- package/lib-es/bridge/generic-alpaca/signer/index.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/signer/index.js +39 -6
- package/lib-es/bridge/generic-alpaca/signer/index.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/signer/signTransaction.d.ts +2 -0
- package/lib-es/bridge/generic-alpaca/signer/signTransaction.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/signer/signTransaction.js +6 -0
- package/lib-es/bridge/generic-alpaca/signer/signTransaction.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/signer/types.d.ts +3 -0
- package/lib-es/bridge/generic-alpaca/signer/types.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/tests/estimateMaxSpendable.test.js +70 -46
- package/lib-es/bridge/generic-alpaca/tests/estimateMaxSpendable.test.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/tests/prepareTransaction.test.js +1 -1
- package/lib-es/bridge/generic-alpaca/tests/prepareTransaction.test.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/tests/signOperation.test.js +25 -22
- package/lib-es/bridge/generic-alpaca/tests/signOperation.test.js.map +1 -1
- package/lib-es/bridge/generic-alpaca/tests/utils.test.d.ts.map +1 -0
- package/lib-es/bridge/generic-alpaca/{utils.test.js → tests/utils.test.js} +1 -1
- package/lib-es/bridge/generic-alpaca/tests/utils.test.js.map +1 -0
- package/lib-es/bridge/generic-alpaca/utils.d.ts +36 -1
- package/lib-es/bridge/generic-alpaca/utils.d.ts.map +1 -1
- package/lib-es/bridge/generic-alpaca/utils.js +130 -14
- package/lib-es/bridge/generic-alpaca/utils.js.map +1 -1
- package/lib-es/bridge/impl.d.ts.map +1 -1
- package/lib-es/bridge/impl.js +5 -4
- package/lib-es/bridge/impl.js.map +1 -1
- package/lib-es/e2e/enum/Account.js +4 -4
- package/lib-es/e2e/enum/Account.js.map +1 -1
- package/lib-es/e2e/enum/AppInfos.d.ts +1 -1
- package/lib-es/e2e/enum/AppInfos.d.ts.map +1 -1
- package/lib-es/e2e/enum/AppInfos.js +1 -1
- package/lib-es/e2e/enum/AppInfos.js.map +1 -1
- package/lib-es/e2e/enum/Currency.d.ts.map +1 -1
- package/lib-es/e2e/enum/Currency.js +3 -3
- package/lib-es/e2e/enum/Currency.js.map +1 -1
- package/lib-es/e2e/speculos.js +2 -2
- package/lib-es/e2e/speculos.js.map +1 -1
- package/lib-es/families/stellar/bridge/logic.d.ts +1 -1
- package/lib-es/families/stellar/bridge/logic.d.ts.map +1 -1
- package/lib-es/families/stellar/bridge/logic.js +1 -1
- package/lib-es/families/stellar/bridge/logic.js.map +1 -1
- package/lib-es/families/stellar/bridge/mock.js +2 -2
- package/lib-es/families/stellar/bridge/mock.js.map +1 -1
- package/lib-es/families/stellar/setup.d.ts +3 -6
- package/lib-es/families/stellar/setup.d.ts.map +1 -1
- package/lib-es/families/stellar/setup.js +2 -10
- package/lib-es/families/stellar/setup.js.map +1 -1
- package/lib-es/families/xrp/bridge/mock.js +2 -2
- package/lib-es/families/xrp/bridge/mock.js.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.js +4 -2
- package/lib-es/featureFlags/defaultFeatures.js.map +1 -1
- package/lib-es/generated/bridge/js.d.ts +0 -1
- package/lib-es/generated/bridge/js.d.ts.map +1 -1
- package/lib-es/generated/bridge/js.js +0 -2
- package/lib-es/generated/bridge/js.js.map +1 -1
- package/lib-es/generated/transaction.d.ts +1 -1
- package/lib-es/modularDrawer/__test__/useModularDrawerVisibility.test.js +229 -14
- package/lib-es/modularDrawer/__test__/useModularDrawerVisibility.test.js.map +1 -1
- package/lib-es/modularDrawer/enums.d.ts +0 -1
- package/lib-es/modularDrawer/enums.d.ts.map +1 -1
- package/lib-es/modularDrawer/enums.js +0 -1
- package/lib-es/modularDrawer/enums.js.map +1 -1
- package/lib-es/modularDrawer/useModularDrawerVisibility.d.ts +7 -1
- package/lib-es/modularDrawer/useModularDrawerVisibility.d.ts.map +1 -1
- package/lib-es/modularDrawer/useModularDrawerVisibility.js +18 -2
- package/lib-es/modularDrawer/useModularDrawerVisibility.js.map +1 -1
- package/package.json +43 -42
- package/src/__tests__/test-helpers/bridge.ts +3 -1
- package/src/braze/anonymousUsers.ts +7 -4
- package/src/bridge/generic-alpaca/accountBridge.ts +1 -4
- package/src/bridge/generic-alpaca/alpaca/index.ts +7 -2
- package/src/bridge/generic-alpaca/alpaca/network/network-alpaca.ts +17 -22
- package/src/bridge/generic-alpaca/broadcast.ts +1 -4
- package/src/bridge/generic-alpaca/buildSubAccounts.ts +110 -0
- package/src/bridge/generic-alpaca/createTransaction.ts +48 -18
- package/src/bridge/generic-alpaca/currencyBridge.ts +1 -1
- package/src/bridge/generic-alpaca/estimateMaxSpendable.ts +13 -4
- package/src/bridge/generic-alpaca/getAccountShape.ts +84 -46
- package/src/bridge/generic-alpaca/getTransactionStatus.ts +46 -22
- package/src/bridge/generic-alpaca/prepareTransaction.ts +41 -7
- package/src/bridge/generic-alpaca/signOperation.ts +85 -18
- package/src/bridge/generic-alpaca/signer/index.ts +43 -7
- package/src/bridge/generic-alpaca/signer/signTransaction.ts +11 -0
- package/src/bridge/generic-alpaca/signer/types.ts +1 -0
- package/src/bridge/generic-alpaca/tests/estimateMaxSpendable.test.ts +72 -47
- package/src/bridge/generic-alpaca/tests/prepareTransaction.test.ts +1 -1
- package/src/bridge/generic-alpaca/tests/signOperation.test.ts +28 -26
- package/src/bridge/generic-alpaca/{utils.test.ts → tests/utils.test.ts} +1 -1
- package/src/bridge/generic-alpaca/utils.ts +158 -18
- package/src/bridge/impl.ts +5 -4
- package/src/e2e/enum/Account.ts +4 -4
- package/src/e2e/enum/AppInfos.ts +1 -1
- package/src/e2e/enum/Currency.ts +3 -13
- package/src/e2e/speculos.ts +2 -2
- package/src/families/stellar/__snapshots__/bridge.integration.test.ts.snap +569 -2068
- package/src/families/stellar/bridge/logic.ts +1 -1
- package/src/families/stellar/bridge/mock.ts +2 -2
- package/src/families/stellar/setup.ts +2 -22
- package/src/families/xrp/bridge/mock.ts +2 -2
- package/src/featureFlags/defaultFeatures.ts +4 -2
- package/src/generated/bridge/js.ts +0 -2
- package/src/modularDrawer/__test__/useModularDrawerVisibility.test.ts +345 -14
- package/src/modularDrawer/enums.ts +0 -1
- package/src/modularDrawer/useModularDrawerVisibility.ts +26 -2
- package/lib/bridge/generic-alpaca/utils.test.d.ts.map +0 -1
- package/lib/bridge/generic-alpaca/utils.test.js.map +0 -1
- package/lib/families/canton/bridge.integration.test.d.ts +0 -2
- package/lib/families/canton/bridge.integration.test.d.ts.map +0 -1
- package/lib/families/canton/bridge.integration.test.js +0 -7
- package/lib/families/canton/bridge.integration.test.js.map +0 -1
- package/lib-es/bridge/generic-alpaca/utils.test.d.ts.map +0 -1
- package/lib-es/bridge/generic-alpaca/utils.test.js.map +0 -1
- package/lib-es/families/canton/bridge.integration.test.d.ts +0 -2
- package/lib-es/families/canton/bridge.integration.test.d.ts.map +0 -1
- package/lib-es/families/canton/bridge.integration.test.js +0 -5
- package/lib-es/families/canton/bridge.integration.test.js.map +0 -1
- package/src/families/canton/bridge.integration.test.ts +0 -6
- /package/lib/bridge/generic-alpaca/{utils.test.d.ts → tests/utils.test.d.ts} +0 -0
- /package/lib-es/bridge/generic-alpaca/{utils.test.d.ts → tests/utils.test.d.ts} +0 -0
@@ -1,5 +1,4 @@
|
|
1
|
-
import {
|
2
|
-
Account,
|
1
|
+
import type {
|
3
2
|
Balance,
|
4
3
|
Block,
|
5
4
|
BlockInfo,
|
@@ -7,10 +6,9 @@ import {
|
|
7
6
|
FeeEstimation,
|
8
7
|
Pagination,
|
9
8
|
TransactionIntent,
|
10
|
-
Transaction,
|
11
9
|
TransactionValidation,
|
12
|
-
AccountInfo,
|
13
10
|
Api,
|
11
|
+
AssetInfo,
|
14
12
|
Cursor,
|
15
13
|
Page,
|
16
14
|
Stake,
|
@@ -18,7 +16,7 @@ import {
|
|
18
16
|
} from "@ledgerhq/coin-framework/api/index";
|
19
17
|
import network from "@ledgerhq/live-network";
|
20
18
|
|
21
|
-
function adaptOp(backendOp:
|
19
|
+
function adaptOp<T extends AssetInfo>(backendOp: Operation<T>): Operation<T> {
|
22
20
|
const { date } = backendOp.tx;
|
23
21
|
const newDate = new Date(date);
|
24
22
|
|
@@ -31,7 +29,7 @@ function adaptOp(backendOp: any): Operation<any> {
|
|
31
29
|
|
32
30
|
const ALPACA_URL = "http://0.0.0.0:3000";
|
33
31
|
|
34
|
-
const buildBroadcast =
|
32
|
+
const buildBroadcast = networkFamily =>
|
35
33
|
async function broadcast(signedOperation: string): Promise<string> {
|
36
34
|
const { data } = await network<
|
37
35
|
{
|
@@ -50,7 +48,7 @@ const buildBroadcast = (networkFamily: string) =>
|
|
50
48
|
return data.transactionIdentifier;
|
51
49
|
};
|
52
50
|
|
53
|
-
const buildCombine =
|
51
|
+
const buildCombine = networkFamily =>
|
54
52
|
async function combine(tx: string, signature: string, pubKey?: string): Promise<string> {
|
55
53
|
const { data } = await network<
|
56
54
|
{
|
@@ -69,7 +67,7 @@ const buildCombine = (networkFamily: string) =>
|
|
69
67
|
return data.signedTransaction;
|
70
68
|
};
|
71
69
|
|
72
|
-
const buildEstimateFees =
|
70
|
+
const buildEstimateFees = networkFamily =>
|
73
71
|
async function estimateFees(intent: TransactionIntent<any>): Promise<FeeEstimation> {
|
74
72
|
const { data } = await network<{ fee: string }, unknown>({
|
75
73
|
method: "POST",
|
@@ -86,11 +84,8 @@ const buildEstimateFees = (networkFamily: string) =>
|
|
86
84
|
};
|
87
85
|
};
|
88
86
|
|
89
|
-
const buildValidateIntent =
|
90
|
-
async function validateIntent(
|
91
|
-
account: Account,
|
92
|
-
transaction: Transaction,
|
93
|
-
): Promise<TransactionValidation> {
|
87
|
+
const buildValidateIntent = networkFamily =>
|
88
|
+
async function validateIntent(transaction: TransactionIntent): Promise<TransactionValidation> {
|
94
89
|
const { data } = await network<
|
95
90
|
{
|
96
91
|
errors: Record<string, Error>;
|
@@ -105,7 +100,6 @@ const buildValidateIntent = (networkFamily: string) =>
|
|
105
100
|
url: `${ALPACA_URL}/${networkFamily}/transaction/validate`,
|
106
101
|
data: {
|
107
102
|
transaction,
|
108
|
-
account,
|
109
103
|
},
|
110
104
|
});
|
111
105
|
return data;
|
@@ -122,13 +116,14 @@ const buildGetBalance = (networkFamily: string) =>
|
|
122
116
|
{
|
123
117
|
value: BigInt(data.value),
|
124
118
|
asset: data.asset,
|
119
|
+
locked: BigInt(data?.locked ?? "0"),
|
125
120
|
},
|
126
121
|
];
|
127
122
|
};
|
128
123
|
|
129
|
-
const
|
130
|
-
async function
|
131
|
-
const { data } = await network<
|
124
|
+
const buildGetSequence = (networkFamily: string) =>
|
125
|
+
async function getSequence(address: string): Promise<number> {
|
126
|
+
const { data } = await network<number, unknown>({
|
132
127
|
method: "GET",
|
133
128
|
url: `${ALPACA_URL}/${networkFamily}/account/${address}/info`,
|
134
129
|
});
|
@@ -136,10 +131,10 @@ const buildGetAccountInfo = (networkFamily: string) =>
|
|
136
131
|
return data;
|
137
132
|
};
|
138
133
|
|
139
|
-
const buildListOperations =
|
134
|
+
const buildListOperations = networkFamily =>
|
140
135
|
async function listOperations(
|
141
136
|
address: string,
|
142
|
-
pagination: Pagination,
|
137
|
+
pagination: Pagination = { minHeight: 0 },
|
143
138
|
): Promise<[Operation<any>[], string]> {
|
144
139
|
const { data } = await network<{ operations: Operation<any>[] }, unknown>({
|
145
140
|
method: "GET",
|
@@ -151,7 +146,7 @@ const buildListOperations = (networkFamily: string) =>
|
|
151
146
|
return [data.operations.map(op => adaptOp(op)), ""];
|
152
147
|
};
|
153
148
|
|
154
|
-
const buildLastBlock =
|
149
|
+
const buildLastBlock = networkFamily =>
|
155
150
|
async function lastBlock(): Promise<BlockInfo> {
|
156
151
|
const { data } = await network<any, unknown>({
|
157
152
|
method: "GET",
|
@@ -164,7 +159,7 @@ const buildLastBlock = (networkFamily: string) =>
|
|
164
159
|
};
|
165
160
|
};
|
166
161
|
|
167
|
-
const buildCraftTransaction =
|
162
|
+
const buildCraftTransaction = networkFamily =>
|
168
163
|
async function craftTransaction(intent: TransactionIntent<any>): Promise<string> {
|
169
164
|
const { data } = await network<any, unknown>({
|
170
165
|
method: "POST",
|
@@ -186,7 +181,7 @@ export const getNetworkAlpacaApi = (networkFamily: string) =>
|
|
186
181
|
validateIntent: buildValidateIntent(networkFamily),
|
187
182
|
estimateFees: buildEstimateFees(networkFamily),
|
188
183
|
getBalance: buildGetBalance(networkFamily),
|
189
|
-
|
184
|
+
getSequence: buildGetSequence(networkFamily),
|
190
185
|
listOperations: buildListOperations(networkFamily),
|
191
186
|
lastBlock: buildLastBlock(networkFamily),
|
192
187
|
craftTransaction: buildCraftTransaction(networkFamily),
|
@@ -2,10 +2,7 @@ import { AccountBridge, TransactionCommon } from "@ledgerhq/types-live";
|
|
2
2
|
import { patchOperationWithHash } from "../../operation";
|
3
3
|
import { getAlpacaApi } from "./alpaca";
|
4
4
|
|
5
|
-
export const genericBroadcast: (
|
6
|
-
network: string,
|
7
|
-
kind: "local" | "remote",
|
8
|
-
) => AccountBridge<TransactionCommon>["broadcast"] =
|
5
|
+
export const genericBroadcast: (network, kind) => AccountBridge<TransactionCommon>["broadcast"] =
|
9
6
|
(network, kind) =>
|
10
7
|
async ({ signedOperation: { signature, operation } }) => {
|
11
8
|
const hash = await getAlpacaApi(network, kind).broadcast(signature);
|
@@ -0,0 +1,110 @@
|
|
1
|
+
import BigNumber from "bignumber.js";
|
2
|
+
import { emptyHistoryCache } from "@ledgerhq/coin-framework/account/index";
|
3
|
+
import type { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
4
|
+
import type { Operation, SyncConfig, TokenAccount } from "@ledgerhq/types-live";
|
5
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
6
|
+
import { listTokensForCryptoCurrency } from "@ledgerhq/cryptoassets";
|
7
|
+
import { AssetInfo, Balance } from "@ledgerhq/coin-framework/api/types";
|
8
|
+
import { findTokenById } from "@ledgerhq/cryptoassets/tokens";
|
9
|
+
|
10
|
+
export interface OperationCommon extends Operation {
|
11
|
+
extra: Record<string, any>;
|
12
|
+
}
|
13
|
+
|
14
|
+
export const getAssetIdFromTokenId = (tokenId: string): string => tokenId.split("/")[2];
|
15
|
+
|
16
|
+
export const getAssetIdFromAsset = (asset: AssetInfo) =>
|
17
|
+
asset.type !== "native" && "assetReference" in asset && "assetOwner" in asset
|
18
|
+
? `${asset.assetReference}:${asset.assetOwner}`
|
19
|
+
: "";
|
20
|
+
|
21
|
+
function buildTokenAccount({
|
22
|
+
parentAccountId,
|
23
|
+
assetBalance,
|
24
|
+
token,
|
25
|
+
operations,
|
26
|
+
}: {
|
27
|
+
parentAccountId: string;
|
28
|
+
assetBalance: Balance;
|
29
|
+
token: TokenCurrency;
|
30
|
+
operations: OperationCommon[];
|
31
|
+
}): TokenAccount {
|
32
|
+
const assetId = getAssetIdFromTokenId(token.id);
|
33
|
+
const id = `${parentAccountId}+${assetId}`;
|
34
|
+
const balance = new BigNumber(assetBalance.value.toString() || "0");
|
35
|
+
|
36
|
+
// TODO: recheck this logic
|
37
|
+
const spendableBalance = new BigNumber(assetBalance.value.toString()).minus(
|
38
|
+
new BigNumber(assetBalance.locked?.toString() || "0"),
|
39
|
+
);
|
40
|
+
|
41
|
+
const tokenOperations = operations.map(op => ({
|
42
|
+
...op,
|
43
|
+
id: encodeOperationId(id, op.hash, op.extra?.ledgerOpType),
|
44
|
+
accountId: id,
|
45
|
+
type: op.extra?.ledgerOpType,
|
46
|
+
value: op.extra?.assetAmount ? new BigNumber(op.extra?.assetAmount) : op.value,
|
47
|
+
}));
|
48
|
+
|
49
|
+
return {
|
50
|
+
type: "TokenAccount",
|
51
|
+
id,
|
52
|
+
parentId: parentAccountId,
|
53
|
+
token,
|
54
|
+
operationsCount: operations.length,
|
55
|
+
operations: tokenOperations,
|
56
|
+
pendingOperations: [],
|
57
|
+
balance,
|
58
|
+
spendableBalance: spendableBalance,
|
59
|
+
swapHistory: [],
|
60
|
+
creationDate: operations.length > 0 ? operations[operations.length - 1].date : new Date(),
|
61
|
+
balanceHistoryCache: emptyHistoryCache, // calculated in the jsHelpers
|
62
|
+
};
|
63
|
+
}
|
64
|
+
|
65
|
+
export function buildSubAccounts({
|
66
|
+
currency,
|
67
|
+
accountId,
|
68
|
+
assetsBalance,
|
69
|
+
syncConfig,
|
70
|
+
operations,
|
71
|
+
}: {
|
72
|
+
currency: CryptoCurrency;
|
73
|
+
accountId: string;
|
74
|
+
assetsBalance: Balance[];
|
75
|
+
syncConfig: SyncConfig;
|
76
|
+
operations: OperationCommon[];
|
77
|
+
}): TokenAccount[] | undefined {
|
78
|
+
const { blacklistedTokenIds = [] } = syncConfig;
|
79
|
+
const allTokens = listTokensForCryptoCurrency(currency);
|
80
|
+
|
81
|
+
if (allTokens.length === 0 || assetsBalance.length === 0) {
|
82
|
+
return undefined;
|
83
|
+
}
|
84
|
+
const tokenAccounts: TokenAccount[] = [];
|
85
|
+
assetsBalance
|
86
|
+
.filter(b => b.asset.type !== "native") // NOTE: this could be removed, keeping here while fixing things up
|
87
|
+
.map(balance => {
|
88
|
+
const token = findToken(currency, balance);
|
89
|
+
// NOTE: for future tokens, will need to check over currencyName/standard(erc20,trc10,trc20, etc)/id
|
90
|
+
if (token && !blacklistedTokenIds.includes(token.id)) {
|
91
|
+
tokenAccounts.push(
|
92
|
+
buildTokenAccount({
|
93
|
+
parentAccountId: accountId,
|
94
|
+
assetBalance: balance,
|
95
|
+
token,
|
96
|
+
operations: operations.filter(
|
97
|
+
op =>
|
98
|
+
op.extra.assetReference === balance.asset?.["assetReference"] &&
|
99
|
+
op.extra.assetOwner === balance.asset?.["assetOwner"], // NOTE: we could narrow type
|
100
|
+
),
|
101
|
+
}),
|
102
|
+
);
|
103
|
+
}
|
104
|
+
});
|
105
|
+
return tokenAccounts;
|
106
|
+
}
|
107
|
+
|
108
|
+
export function findToken(currency: CryptoCurrency, balance: Balance): TokenCurrency | undefined {
|
109
|
+
return findTokenById(`${currency.family}/asset/${getAssetIdFromAsset(balance.asset)}`);
|
110
|
+
}
|
@@ -1,27 +1,57 @@
|
|
1
|
-
import { Account, TransactionCommon } from "@ledgerhq/types-live";
|
1
|
+
import { Account, TokenAccount, TransactionCommon } from "@ledgerhq/types-live";
|
2
2
|
import BigNumber from "bignumber.js";
|
3
3
|
import type { Unit } from "@ledgerhq/types-cryptoassets";
|
4
4
|
|
5
|
+
export enum NetworkCongestionLevel {
|
6
|
+
LOW = "LOW",
|
7
|
+
MEDIUM = "MEDIUM",
|
8
|
+
HIGH = "HIGH",
|
9
|
+
}
|
10
|
+
|
5
11
|
export type NetworkInfo = {
|
6
|
-
|
7
|
-
serverFee: BigNumber;
|
8
|
-
baseReserve: BigNumber;
|
12
|
+
fees: BigNumber;
|
9
13
|
};
|
10
14
|
|
11
|
-
export function createTransaction(account: Account): TransactionCommon & {
|
15
|
+
export function createTransaction(account: Account | TokenAccount): TransactionCommon & {
|
12
16
|
family: string;
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
fees?: BigNumber | null;
|
18
|
+
tag?: number | null | undefined;
|
19
|
+
feeCustomUnit?: Unit | null | undefined;
|
20
|
+
memoType?: string | null;
|
21
|
+
memoValue?: string | null;
|
22
|
+
mode?: "send" | "changeTrust";
|
23
|
+
assetReference?: string;
|
24
|
+
assetOwner?: string;
|
25
|
+
networkInfo?: NetworkInfo | null;
|
17
26
|
} {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
const currency =
|
28
|
+
account.type === "TokenAccount" ? account.token.parentCurrency : account.currency;
|
29
|
+
switch (currency.family) {
|
30
|
+
case "xrp":
|
31
|
+
case "ripple":
|
32
|
+
return {
|
33
|
+
family: currency.family,
|
34
|
+
amount: BigNumber(0),
|
35
|
+
recipient: "",
|
36
|
+
fees: null,
|
37
|
+
tag: undefined,
|
38
|
+
feeCustomUnit: null, // NOTE: XRP does not use custom units for fees anymore
|
39
|
+
};
|
40
|
+
case "stellar":
|
41
|
+
return {
|
42
|
+
family: currency.family,
|
43
|
+
amount: new BigNumber(0),
|
44
|
+
fees: null,
|
45
|
+
recipient: "",
|
46
|
+
memoValue: null,
|
47
|
+
memoType: null,
|
48
|
+
useAllAmount: false,
|
49
|
+
mode: "send",
|
50
|
+
assetReference: "",
|
51
|
+
assetOwner: "",
|
52
|
+
networkInfo: null,
|
53
|
+
};
|
54
|
+
default:
|
55
|
+
throw new Error(`Unsupported currency family: ${currency.family}`);
|
56
|
+
}
|
27
57
|
}
|
@@ -3,7 +3,7 @@ import { CurrencyBridge } from "@ledgerhq/types-live";
|
|
3
3
|
import { genericGetAccountShape } from "./getAccountShape";
|
4
4
|
import { getSigner } from "./signer";
|
5
5
|
|
6
|
-
export function getAlpacaCurrencyBridge(network: string, kind:
|
6
|
+
export function getAlpacaCurrencyBridge(network: string, kind: string): CurrencyBridge {
|
7
7
|
return {
|
8
8
|
preload: () => Promise.resolve({}),
|
9
9
|
hydrate: () => {
|
@@ -6,21 +6,30 @@ import { transactionToIntent } from "./utils";
|
|
6
6
|
import BigNumber from "bignumber.js";
|
7
7
|
|
8
8
|
export function genericEstimateMaxSpendable(
|
9
|
-
network
|
10
|
-
kind
|
9
|
+
network,
|
10
|
+
kind,
|
11
11
|
): AccountBridge<any>["estimateMaxSpendable"] {
|
12
12
|
return async ({ account, parentAccount, transaction }) => {
|
13
|
+
if (account.type === "TokenAccount") {
|
14
|
+
return account.spendableBalance;
|
15
|
+
}
|
13
16
|
const mainAccount = getMainAccount(account, parentAccount);
|
14
|
-
|
15
17
|
const draftTransaction = {
|
16
18
|
...createTransaction(account as any),
|
17
19
|
...transaction,
|
18
20
|
amount: mainAccount.spendableBalance,
|
21
|
+
useAllAmount: true,
|
22
|
+
fees: transaction?.fees ? BigInt(transaction.fees.toString()) : 0n,
|
19
23
|
};
|
20
24
|
const fees = await getAlpacaApi(network, kind).estimateFees(
|
21
25
|
transactionToIntent(mainAccount, draftTransaction),
|
22
26
|
);
|
23
|
-
|
27
|
+
const { amount } = await getAlpacaApi(network, kind).validateIntent(
|
28
|
+
transactionToIntent(account, { ...draftTransaction }),
|
29
|
+
);
|
30
|
+
if (network === "stellar") {
|
31
|
+
return amount > 0 ? new BigNumber(amount.toString()) : new BigNumber(0);
|
32
|
+
}
|
24
33
|
const bnFee = BigNumber(fees.value.toString());
|
25
34
|
return BigNumber.max(0, account.spendableBalance.minus(bnFee));
|
26
35
|
};
|
@@ -3,59 +3,97 @@ import { GetAccountShape, mergeOps } from "@ledgerhq/coin-framework/bridge/jsHel
|
|
3
3
|
import BigNumber from "bignumber.js";
|
4
4
|
import { getAlpacaApi } from "./alpaca";
|
5
5
|
import { adaptCoreOperationToLiveOperation, extractBalance } from "./utils";
|
6
|
+
import { inferSubOperations } from "@ledgerhq/coin-framework/serialization";
|
7
|
+
import { findToken } from "./buildSubAccounts";
|
8
|
+
import { buildSubAccounts, OperationCommon } from "./buildSubAccounts";
|
6
9
|
|
7
|
-
export function genericGetAccountShape(network: string, kind:
|
8
|
-
return async info => {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
derivationMode,
|
17
|
-
});
|
18
|
-
|
19
|
-
const blockInfo = await getAlpacaApi(network, kind).lastBlock();
|
20
|
-
|
21
|
-
const balances = await getAlpacaApi(network, kind).getBalance(address);
|
22
|
-
const nativeBalance = extractBalance(balances, "native");
|
23
|
-
const balance = BigNumber(nativeBalance.value.toString());
|
24
|
-
|
25
|
-
let spendableBalance: BigNumber;
|
26
|
-
if (nativeBalance.locked) {
|
27
|
-
spendableBalance = BigNumber.max(
|
28
|
-
balance.minus(BigNumber(nativeBalance.locked.toString())),
|
29
|
-
BigNumber(0),
|
30
|
-
);
|
31
|
-
} else {
|
32
|
-
spendableBalance = initialAccount?.spendableBalance || balance;
|
10
|
+
export function genericGetAccountShape(network: string, kind: string): GetAccountShape {
|
11
|
+
return async (info, syncConfig) => {
|
12
|
+
const { address, initialAccount, currency, derivationMode } = info;
|
13
|
+
const alpacaApi = getAlpacaApi(network, kind);
|
14
|
+
|
15
|
+
if (alpacaApi.getChainSpecificRules) {
|
16
|
+
const chainSpecificValidation = alpacaApi.getChainSpecificRules();
|
17
|
+
if (chainSpecificValidation.getAccountShape) {
|
18
|
+
chainSpecificValidation.getAccountShape(address);
|
33
19
|
}
|
34
|
-
|
20
|
+
}
|
21
|
+
|
22
|
+
const accountId = encodeAccountId({
|
23
|
+
type: "js",
|
24
|
+
version: "2",
|
25
|
+
currencyId: currency.id,
|
26
|
+
xpubOrAddress: address,
|
27
|
+
derivationMode,
|
28
|
+
});
|
29
|
+
|
30
|
+
const blockInfo = await alpacaApi.lastBlock();
|
31
|
+
const balanceRes = await alpacaApi.getBalance(address);
|
32
|
+
const nativeAsset = extractBalance(balanceRes, "native");
|
33
|
+
|
34
|
+
const assetsBalance = balanceRes
|
35
|
+
.filter(b => b.asset.type !== "native")
|
36
|
+
.filter(b => findToken(currency, b));
|
37
|
+
|
38
|
+
const nativeBalance = BigInt(nativeAsset?.value ?? "0");
|
39
|
+
|
40
|
+
const spendableBalance = BigInt(nativeBalance - BigInt(nativeAsset?.locked ?? "0"));
|
35
41
|
|
36
|
-
|
42
|
+
const oldOps = (initialAccount?.operations || []) as OperationCommon[];
|
43
|
+
const lastPagingToken = oldOps[0]?.extra?.pagingToken || "";
|
37
44
|
|
38
|
-
|
39
|
-
|
40
|
-
|
45
|
+
const blockHeight = oldOps.length ? (oldOps[0].blockHeight ?? 0) + 1 : 0;
|
46
|
+
const paginationParams: any = { minHeight: blockHeight };
|
47
|
+
if (lastPagingToken) {
|
48
|
+
paginationParams.lastPagingToken = lastPagingToken;
|
49
|
+
}
|
50
|
+
|
51
|
+
const [newCoreOps] = await alpacaApi.listOperations(address, paginationParams);
|
52
|
+
const newOps = newCoreOps.map(op =>
|
53
|
+
adaptCoreOperationToLiveOperation(accountId, op),
|
54
|
+
) as OperationCommon[];
|
55
|
+
const mergedOps = mergeOps(oldOps, newOps) as OperationCommon[];
|
56
|
+
|
57
|
+
const assetOperations: OperationCommon[] = [];
|
58
|
+
mergedOps.forEach(operation => {
|
59
|
+
if (
|
60
|
+
operation?.extra?.assetReference &&
|
61
|
+
operation?.extra?.assetOwner &&
|
62
|
+
!["OPT_IN", "OPT_OUT"].includes(operation.type)
|
63
|
+
) {
|
64
|
+
assetOperations.push(operation);
|
65
|
+
}
|
66
|
+
});
|
41
67
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
68
|
+
const subAccounts =
|
69
|
+
buildSubAccounts({
|
70
|
+
currency,
|
71
|
+
accountId,
|
72
|
+
assetsBalance,
|
73
|
+
syncConfig,
|
74
|
+
operations: assetOperations,
|
75
|
+
}) || [];
|
76
|
+
|
77
|
+
const operationsWithSubs = mergedOps.map(op => {
|
78
|
+
const subOperations = inferSubOperations(op.hash, subAccounts);
|
46
79
|
|
47
80
|
return {
|
48
|
-
|
49
|
-
|
50
|
-
blockHeight: operations.length === 0 ? 0 : blockInfo.height || initialAccount?.blockHeight,
|
51
|
-
balance,
|
52
|
-
spendableBalance,
|
53
|
-
operations,
|
54
|
-
operationsCount: operations.length,
|
81
|
+
...op,
|
82
|
+
subOperations,
|
55
83
|
};
|
56
|
-
}
|
57
|
-
|
58
|
-
|
59
|
-
|
84
|
+
});
|
85
|
+
|
86
|
+
const res = {
|
87
|
+
id: accountId,
|
88
|
+
xpub: address,
|
89
|
+
blockHeight:
|
90
|
+
operationsWithSubs.length === 0 ? 0 : blockInfo.height || initialAccount?.blockHeight,
|
91
|
+
balance: new BigNumber(nativeBalance.toString()),
|
92
|
+
spendableBalance: new BigNumber(spendableBalance.toString()),
|
93
|
+
operations: operationsWithSubs,
|
94
|
+
subAccounts,
|
95
|
+
operationsCount: operationsWithSubs.length,
|
96
|
+
};
|
97
|
+
return res;
|
60
98
|
};
|
61
99
|
}
|
@@ -1,38 +1,62 @@
|
|
1
1
|
import { AccountBridge, TransactionCommon } from "@ledgerhq/types-live";
|
2
|
+
import { AccountAwaitingSendPendingOperations } from "@ledgerhq/errors";
|
2
3
|
import BigNumber from "bignumber.js";
|
3
4
|
import { getAlpacaApi } from "./alpaca";
|
5
|
+
import { transactionToIntent } from "./utils";
|
4
6
|
|
5
7
|
// => alpaca validateIntent
|
6
8
|
export function genericGetTransactionStatus(
|
7
|
-
network
|
8
|
-
kind
|
9
|
+
network,
|
10
|
+
kind,
|
9
11
|
): AccountBridge<any>["getTransactionStatus"] {
|
10
|
-
return async (
|
11
|
-
|
12
|
+
return async (
|
13
|
+
account,
|
14
|
+
transaction: TransactionCommon & {
|
15
|
+
fees: BigNumber | null | undefined;
|
16
|
+
assetReference?: string;
|
17
|
+
assetOwner?: string;
|
18
|
+
mode?: string;
|
19
|
+
subAccountId?: string;
|
20
|
+
memoType?: string;
|
21
|
+
memoValue?: string;
|
22
|
+
},
|
23
|
+
) => {
|
12
24
|
const alpacaApi = getAlpacaApi(network, kind);
|
13
|
-
const
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
)
|
25
|
+
const draftTransaction = {
|
26
|
+
mode: transaction?.mode,
|
27
|
+
recipient: transaction.recipient,
|
28
|
+
amount: transaction.amount ?? new BigNumber(0),
|
29
|
+
fees: transaction.fees ? BigInt(transaction.fees.toString()) : 0n,
|
30
|
+
useAllAmount: !!transaction.useAllAmount,
|
31
|
+
assetReference: transaction.assetReference || "",
|
32
|
+
assetOwner: transaction.assetOwner || "",
|
33
|
+
subAccountId: transaction.subAccountId || "",
|
34
|
+
memoType: transaction.memoType || "",
|
35
|
+
memoValue: transaction.memoValue || "",
|
36
|
+
};
|
37
|
+
|
38
|
+
if (alpacaApi.getChainSpecificRules) {
|
39
|
+
const chainSpecificValidation = alpacaApi.getChainSpecificRules();
|
40
|
+
if (chainSpecificValidation.getTransactionStatus.throwIfPendingOperation) {
|
41
|
+
if (account.pendingOperations.length > 0) {
|
42
|
+
throw new AccountAwaitingSendPendingOperations();
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
27
46
|
|
28
|
-
const estimatedFees
|
47
|
+
const { errors, warnings, estimatedFees, amount, totalSpent } = await alpacaApi.validateIntent(
|
48
|
+
transactionToIntent(account, draftTransaction),
|
49
|
+
);
|
29
50
|
|
30
51
|
return Promise.resolve({
|
31
52
|
errors,
|
32
53
|
warnings,
|
33
|
-
estimatedFees
|
34
|
-
|
35
|
-
|
54
|
+
estimatedFees:
|
55
|
+
!transaction.fees || transaction.fees.isZero()
|
56
|
+
? new BigNumber(estimatedFees.toString())
|
57
|
+
: transaction.fees,
|
58
|
+
amount: transaction.amount.eq(0) ? new BigNumber(amount.toString()) : transaction.amount,
|
59
|
+
totalSpent: new BigNumber(totalSpent.toString()),
|
36
60
|
});
|
37
61
|
};
|
38
62
|
}
|
@@ -2,6 +2,7 @@ import { Account, AccountBridge, TransactionCommon } from "@ledgerhq/types-live"
|
|
2
2
|
import { getAlpacaApi } from "./alpaca";
|
3
3
|
import { transactionToIntent } from "./utils";
|
4
4
|
import BigNumber from "bignumber.js";
|
5
|
+
import { NetworkInfo } from "./createTransaction";
|
5
6
|
|
6
7
|
function bnEq(a: BigNumber | null | undefined, b: BigNumber | null | undefined): boolean {
|
7
8
|
return !a && !b ? true : !a || !b ? false : a.eq(b);
|
@@ -9,18 +10,51 @@ function bnEq(a: BigNumber | null | undefined, b: BigNumber | null | undefined):
|
|
9
10
|
|
10
11
|
export function genericPrepareTransaction(
|
11
12
|
network: string,
|
12
|
-
kind
|
13
|
+
kind,
|
13
14
|
): AccountBridge<TransactionCommon, Account, any, any>["prepareTransaction"] {
|
14
|
-
return async (
|
15
|
+
return async (
|
16
|
+
account,
|
17
|
+
transaction: TransactionCommon & {
|
18
|
+
fees: BigNumber | null | undefined;
|
19
|
+
assetReference?: string;
|
20
|
+
assetOwner?: string;
|
21
|
+
subAccountId?: string;
|
22
|
+
networkInfo?: NetworkInfo | null;
|
23
|
+
},
|
24
|
+
) => {
|
25
|
+
const [assetReference, assetOwner] = getAssetInfos(transaction);
|
15
26
|
const fees = await getAlpacaApi(network, kind).estimateFees(
|
16
|
-
transactionToIntent(account,
|
27
|
+
transactionToIntent(account, {
|
28
|
+
...transaction,
|
29
|
+
fees: transaction.fees ? BigInt(transaction.fees.toString()) : 0n,
|
30
|
+
}),
|
17
31
|
);
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
32
|
+
// NOTE: this is problematic, we should maybe have a method / object that lists what field warrant an update per chain
|
33
|
+
// for reference, stellar checked this:
|
34
|
+
// transaction.networkInfo !== networkInfo ||
|
35
|
+
// transaction.baseReserve !== baseReserve
|
36
|
+
if (!bnEq(transaction.fees, new BigNumber(fees.value.toString()))) {
|
37
|
+
return {
|
38
|
+
...transaction,
|
39
|
+
fees: new BigNumber(fees.value.toString()),
|
40
|
+
assetReference,
|
41
|
+
assetOwner,
|
42
|
+
networkInfo: {
|
43
|
+
fees: new BigNumber(fees.value.toString()),
|
44
|
+
},
|
45
|
+
};
|
22
46
|
}
|
23
47
|
|
24
48
|
return transaction;
|
25
49
|
};
|
26
50
|
}
|
51
|
+
|
52
|
+
export function getAssetInfos(
|
53
|
+
tr: TransactionCommon & { assetReference?: string; assetOwner?: string },
|
54
|
+
): string[] {
|
55
|
+
if (tr.subAccountId) {
|
56
|
+
const assetString = tr.subAccountId.split("+")[1];
|
57
|
+
return assetString.split(":");
|
58
|
+
}
|
59
|
+
return [tr.assetReference || "", tr.assetOwner || ""];
|
60
|
+
}
|