@ledgerhq/live-common 34.50.0-nightly.6 → 34.51.0-nightly.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.
Files changed (179) hide show
  1. package/lib/bridge/generic-alpaca/prepareTransaction.d.ts.map +1 -1
  2. package/lib/bridge/generic-alpaca/prepareTransaction.js +3 -6
  3. package/lib/bridge/generic-alpaca/prepareTransaction.js.map +1 -1
  4. package/lib/bridge/generic-alpaca/tests/prepareTransaction.test.js +60 -0
  5. package/lib/bridge/generic-alpaca/tests/prepareTransaction.test.js.map +1 -1
  6. package/lib/bridge/generic-alpaca/types.d.ts +0 -1
  7. package/lib/bridge/generic-alpaca/types.d.ts.map +1 -1
  8. package/lib/exchange/swap/postSwapState.d.ts.map +1 -1
  9. package/lib/exchange/swap/postSwapState.js +19 -23
  10. package/lib/exchange/swap/postSwapState.js.map +1 -1
  11. package/lib/exchange/swap/setBroadcastTransaction.d.ts +4 -4
  12. package/lib/exchange/swap/setBroadcastTransaction.js +7 -7
  13. package/lib/exchange/swap/setBroadcastTransaction.js.map +1 -1
  14. package/lib/exchange/swap/types.d.ts +3 -3
  15. package/lib/exchange/swap/types.d.ts.map +1 -1
  16. package/lib/families/tezos/config.js +2 -2
  17. package/lib/modularDrawer/hooks/modules/useRightMarketTrendModule.js +5 -2
  18. package/lib/modularDrawer/hooks/modules/useRightMarketTrendModule.js.map +1 -1
  19. package/lib/modularDrawer/hooks/useRightBalanceAsset.d.ts +5 -8
  20. package/lib/modularDrawer/hooks/useRightBalanceAsset.d.ts.map +1 -1
  21. package/lib/modularDrawer/hooks/useRightBalanceAsset.js +15 -24
  22. package/lib/modularDrawer/hooks/useRightBalanceAsset.js.map +1 -1
  23. package/lib/modularDrawer/hooks/useRightBalanceNetwork.d.ts +6 -25
  24. package/lib/modularDrawer/hooks/useRightBalanceNetwork.d.ts.map +1 -1
  25. package/lib/modularDrawer/hooks/useRightBalanceNetwork.js +4 -3
  26. package/lib/modularDrawer/hooks/useRightBalanceNetwork.js.map +1 -1
  27. package/lib/modularDrawer/modules/createNetworkConfiguration.d.ts.map +1 -1
  28. package/lib/modularDrawer/modules/createNetworkConfiguration.js +8 -4
  29. package/lib/modularDrawer/modules/createNetworkConfiguration.js.map +1 -1
  30. package/lib/modularDrawer/utils/__tests__/calculateProviderTotal.test.d.ts +2 -0
  31. package/lib/modularDrawer/utils/__tests__/calculateProviderTotal.test.d.ts.map +1 -0
  32. package/lib/modularDrawer/utils/__tests__/calculateProviderTotal.test.js +212 -0
  33. package/lib/modularDrawer/utils/__tests__/calculateProviderTotal.test.js.map +1 -0
  34. package/lib/modularDrawer/utils/__tests__/groupAccountsByAsset.test.d.ts +2 -0
  35. package/lib/modularDrawer/utils/__tests__/groupAccountsByAsset.test.d.ts.map +1 -0
  36. package/lib/modularDrawer/utils/__tests__/groupAccountsByAsset.test.js +202 -0
  37. package/lib/modularDrawer/utils/__tests__/groupAccountsByAsset.test.js.map +1 -0
  38. package/lib/modularDrawer/utils/calculateProviderTotal.d.ts +1 -0
  39. package/lib/modularDrawer/utils/calculateProviderTotal.d.ts.map +1 -1
  40. package/lib/modularDrawer/utils/calculateProviderTotal.js +10 -2
  41. package/lib/modularDrawer/utils/calculateProviderTotal.js.map +1 -1
  42. package/lib/modularDrawer/utils/getBalanceAndFiatValueByAssets.d.ts +6 -4
  43. package/lib/modularDrawer/utils/getBalanceAndFiatValueByAssets.d.ts.map +1 -1
  44. package/lib/modularDrawer/utils/getBalanceAndFiatValueByAssets.js +9 -22
  45. package/lib/modularDrawer/utils/getBalanceAndFiatValueByAssets.js.map +1 -1
  46. package/lib/modularDrawer/utils/groupAccountsByAsset.d.ts +4 -3
  47. package/lib/modularDrawer/utils/groupAccountsByAsset.d.ts.map +1 -1
  48. package/lib/modularDrawer/utils/groupAccountsByAsset.js +27 -11
  49. package/lib/modularDrawer/utils/groupAccountsByAsset.js.map +1 -1
  50. package/lib/modularDrawer/utils/index.d.ts +0 -1
  51. package/lib/modularDrawer/utils/index.d.ts.map +1 -1
  52. package/lib/modularDrawer/utils/index.js +1 -3
  53. package/lib/modularDrawer/utils/index.js.map +1 -1
  54. package/lib/modularDrawer/utils/sortByBalance.d.ts +1 -3
  55. package/lib/modularDrawer/utils/sortByBalance.d.ts.map +1 -1
  56. package/lib/modularDrawer/utils/sortByBalance.js +6 -18
  57. package/lib/modularDrawer/utils/sortByBalance.js.map +1 -1
  58. package/lib/modularDrawer/utils/type.d.ts +9 -8
  59. package/lib/modularDrawer/utils/type.d.ts.map +1 -1
  60. package/lib/wallet-api/Exchange/server.js +6 -6
  61. package/lib/wallet-api/Exchange/server.js.map +1 -1
  62. package/lib-es/bridge/generic-alpaca/prepareTransaction.d.ts.map +1 -1
  63. package/lib-es/bridge/generic-alpaca/prepareTransaction.js +3 -6
  64. package/lib-es/bridge/generic-alpaca/prepareTransaction.js.map +1 -1
  65. package/lib-es/bridge/generic-alpaca/tests/prepareTransaction.test.js +60 -0
  66. package/lib-es/bridge/generic-alpaca/tests/prepareTransaction.test.js.map +1 -1
  67. package/lib-es/bridge/generic-alpaca/types.d.ts +0 -1
  68. package/lib-es/bridge/generic-alpaca/types.d.ts.map +1 -1
  69. package/lib-es/exchange/swap/postSwapState.d.ts.map +1 -1
  70. package/lib-es/exchange/swap/postSwapState.js +19 -23
  71. package/lib-es/exchange/swap/postSwapState.js.map +1 -1
  72. package/lib-es/exchange/swap/setBroadcastTransaction.d.ts +4 -4
  73. package/lib-es/exchange/swap/setBroadcastTransaction.js +7 -7
  74. package/lib-es/exchange/swap/setBroadcastTransaction.js.map +1 -1
  75. package/lib-es/exchange/swap/types.d.ts +3 -3
  76. package/lib-es/exchange/swap/types.d.ts.map +1 -1
  77. package/lib-es/families/tezos/config.js +2 -2
  78. package/lib-es/modularDrawer/hooks/modules/useRightMarketTrendModule.js +1 -1
  79. package/lib-es/modularDrawer/hooks/modules/useRightMarketTrendModule.js.map +1 -1
  80. package/lib-es/modularDrawer/hooks/useRightBalanceAsset.d.ts +5 -8
  81. package/lib-es/modularDrawer/hooks/useRightBalanceAsset.d.ts.map +1 -1
  82. package/lib-es/modularDrawer/hooks/useRightBalanceAsset.js +15 -24
  83. package/lib-es/modularDrawer/hooks/useRightBalanceAsset.js.map +1 -1
  84. package/lib-es/modularDrawer/hooks/useRightBalanceNetwork.d.ts +6 -25
  85. package/lib-es/modularDrawer/hooks/useRightBalanceNetwork.d.ts.map +1 -1
  86. package/lib-es/modularDrawer/hooks/useRightBalanceNetwork.js +4 -3
  87. package/lib-es/modularDrawer/hooks/useRightBalanceNetwork.js.map +1 -1
  88. package/lib-es/modularDrawer/modules/createNetworkConfiguration.d.ts.map +1 -1
  89. package/lib-es/modularDrawer/modules/createNetworkConfiguration.js +8 -4
  90. package/lib-es/modularDrawer/modules/createNetworkConfiguration.js.map +1 -1
  91. package/lib-es/modularDrawer/utils/__tests__/calculateProviderTotal.test.d.ts +2 -0
  92. package/lib-es/modularDrawer/utils/__tests__/calculateProviderTotal.test.d.ts.map +1 -0
  93. package/lib-es/modularDrawer/utils/__tests__/calculateProviderTotal.test.js +207 -0
  94. package/lib-es/modularDrawer/utils/__tests__/calculateProviderTotal.test.js.map +1 -0
  95. package/lib-es/modularDrawer/utils/__tests__/groupAccountsByAsset.test.d.ts +2 -0
  96. package/lib-es/modularDrawer/utils/__tests__/groupAccountsByAsset.test.d.ts.map +1 -0
  97. package/lib-es/modularDrawer/utils/__tests__/groupAccountsByAsset.test.js +197 -0
  98. package/lib-es/modularDrawer/utils/__tests__/groupAccountsByAsset.test.js.map +1 -0
  99. package/lib-es/modularDrawer/utils/calculateProviderTotal.d.ts +1 -0
  100. package/lib-es/modularDrawer/utils/calculateProviderTotal.d.ts.map +1 -1
  101. package/lib-es/modularDrawer/utils/calculateProviderTotal.js +10 -2
  102. package/lib-es/modularDrawer/utils/calculateProviderTotal.js.map +1 -1
  103. package/lib-es/modularDrawer/utils/getBalanceAndFiatValueByAssets.d.ts +6 -4
  104. package/lib-es/modularDrawer/utils/getBalanceAndFiatValueByAssets.d.ts.map +1 -1
  105. package/lib-es/modularDrawer/utils/getBalanceAndFiatValueByAssets.js +9 -22
  106. package/lib-es/modularDrawer/utils/getBalanceAndFiatValueByAssets.js.map +1 -1
  107. package/lib-es/modularDrawer/utils/groupAccountsByAsset.d.ts +4 -3
  108. package/lib-es/modularDrawer/utils/groupAccountsByAsset.d.ts.map +1 -1
  109. package/lib-es/modularDrawer/utils/groupAccountsByAsset.js +27 -11
  110. package/lib-es/modularDrawer/utils/groupAccountsByAsset.js.map +1 -1
  111. package/lib-es/modularDrawer/utils/index.d.ts +0 -1
  112. package/lib-es/modularDrawer/utils/index.d.ts.map +1 -1
  113. package/lib-es/modularDrawer/utils/index.js +0 -1
  114. package/lib-es/modularDrawer/utils/index.js.map +1 -1
  115. package/lib-es/modularDrawer/utils/sortByBalance.d.ts +1 -3
  116. package/lib-es/modularDrawer/utils/sortByBalance.d.ts.map +1 -1
  117. package/lib-es/modularDrawer/utils/sortByBalance.js +5 -15
  118. package/lib-es/modularDrawer/utils/sortByBalance.js.map +1 -1
  119. package/lib-es/modularDrawer/utils/type.d.ts +9 -8
  120. package/lib-es/modularDrawer/utils/type.d.ts.map +1 -1
  121. package/lib-es/wallet-api/Exchange/server.js +6 -6
  122. package/lib-es/wallet-api/Exchange/server.js.map +1 -1
  123. package/package.json +70 -70
  124. package/src/bridge/generic-alpaca/prepareTransaction.ts +3 -7
  125. package/src/bridge/generic-alpaca/tests/prepareTransaction.test.ts +78 -0
  126. package/src/bridge/generic-alpaca/types.ts +1 -1
  127. package/src/exchange/swap/postSwapState.ts +28 -32
  128. package/src/exchange/swap/setBroadcastTransaction.ts +12 -12
  129. package/src/exchange/swap/types.ts +3 -3
  130. package/src/families/tezos/config.ts +2 -2
  131. package/src/modularDrawer/hooks/modules/useRightMarketTrendModule.tsx +1 -1
  132. package/src/modularDrawer/hooks/useRightBalanceAsset.tsx +22 -38
  133. package/src/modularDrawer/hooks/useRightBalanceNetwork.tsx +5 -7
  134. package/src/modularDrawer/modules/createNetworkConfiguration.ts +10 -5
  135. package/src/modularDrawer/utils/__tests__/calculateProviderTotal.test.ts +237 -0
  136. package/src/modularDrawer/utils/__tests__/groupAccountsByAsset.test.ts +228 -0
  137. package/src/modularDrawer/utils/calculateProviderTotal.ts +13 -2
  138. package/src/modularDrawer/utils/getBalanceAndFiatValueByAssets.ts +13 -37
  139. package/src/modularDrawer/utils/groupAccountsByAsset.ts +38 -19
  140. package/src/modularDrawer/utils/index.ts +0 -2
  141. package/src/modularDrawer/utils/sortByBalance.tsx +5 -18
  142. package/src/modularDrawer/utils/type.ts +13 -4
  143. package/src/wallet-api/Exchange/server.ts +6 -6
  144. package/lib/modularDrawer/utils/__tests__/counterValueFormatter.test.d.ts +0 -2
  145. package/lib/modularDrawer/utils/__tests__/counterValueFormatter.test.d.ts.map +0 -1
  146. package/lib/modularDrawer/utils/__tests__/counterValueFormatter.test.js +0 -496
  147. package/lib/modularDrawer/utils/__tests__/counterValueFormatter.test.js.map +0 -1
  148. package/lib/modularDrawer/utils/counterValueFormatter.d.ts +0 -14
  149. package/lib/modularDrawer/utils/counterValueFormatter.d.ts.map +0 -1
  150. package/lib/modularDrawer/utils/counterValueFormatter.js +0 -107
  151. package/lib/modularDrawer/utils/counterValueFormatter.js.map +0 -1
  152. package/lib/modularDrawer/utils/getBalanceAndFiatValue.d.ts +0 -20
  153. package/lib/modularDrawer/utils/getBalanceAndFiatValue.d.ts.map +0 -1
  154. package/lib/modularDrawer/utils/getBalanceAndFiatValue.js +0 -39
  155. package/lib/modularDrawer/utils/getBalanceAndFiatValue.js.map +0 -1
  156. package/lib/modularDrawer/utils/parseToBigNumber.d.ts +0 -9
  157. package/lib/modularDrawer/utils/parseToBigNumber.d.ts.map +0 -1
  158. package/lib/modularDrawer/utils/parseToBigNumber.js +0 -24
  159. package/lib/modularDrawer/utils/parseToBigNumber.js.map +0 -1
  160. package/lib-es/modularDrawer/utils/__tests__/counterValueFormatter.test.d.ts +0 -2
  161. package/lib-es/modularDrawer/utils/__tests__/counterValueFormatter.test.d.ts.map +0 -1
  162. package/lib-es/modularDrawer/utils/__tests__/counterValueFormatter.test.js +0 -494
  163. package/lib-es/modularDrawer/utils/__tests__/counterValueFormatter.test.js.map +0 -1
  164. package/lib-es/modularDrawer/utils/counterValueFormatter.d.ts +0 -14
  165. package/lib-es/modularDrawer/utils/counterValueFormatter.d.ts.map +0 -1
  166. package/lib-es/modularDrawer/utils/counterValueFormatter.js +0 -103
  167. package/lib-es/modularDrawer/utils/counterValueFormatter.js.map +0 -1
  168. package/lib-es/modularDrawer/utils/getBalanceAndFiatValue.d.ts +0 -20
  169. package/lib-es/modularDrawer/utils/getBalanceAndFiatValue.d.ts.map +0 -1
  170. package/lib-es/modularDrawer/utils/getBalanceAndFiatValue.js +0 -32
  171. package/lib-es/modularDrawer/utils/getBalanceAndFiatValue.js.map +0 -1
  172. package/lib-es/modularDrawer/utils/parseToBigNumber.d.ts +0 -9
  173. package/lib-es/modularDrawer/utils/parseToBigNumber.d.ts.map +0 -1
  174. package/lib-es/modularDrawer/utils/parseToBigNumber.js +0 -17
  175. package/lib-es/modularDrawer/utils/parseToBigNumber.js.map +0 -1
  176. package/src/modularDrawer/utils/__tests__/counterValueFormatter.test.ts +0 -549
  177. package/src/modularDrawer/utils/counterValueFormatter.ts +0 -165
  178. package/src/modularDrawer/utils/getBalanceAndFiatValue.ts +0 -53
  179. package/src/modularDrawer/utils/parseToBigNumber.ts +0 -17
@@ -7,14 +7,14 @@ import { getSwapAPIBaseURL, getSwapUserIP } from ".";
7
7
 
8
8
  function createSwapIntentHashes({
9
9
  provider,
10
- fromAccountId,
11
- toAccountId,
12
- amount,
10
+ fromAccountAddress,
11
+ toAccountAddress,
12
+ fromAmount,
13
13
  }: {
14
14
  provider: string;
15
- fromAccountId?: string;
16
- toAccountId?: string;
17
- amount?: string;
15
+ fromAccountAddress?: string;
16
+ toAccountAddress?: string;
17
+ fromAmount?: string;
18
18
  }) {
19
19
  // for example '2025-08-01' used to add a one day unique nonce to the swap intent hash
20
20
  const currentday = new Date().toISOString().split("T")[0];
@@ -24,9 +24,9 @@ function createSwapIntentHashes({
24
24
  .update(
25
25
  JSON.stringify({
26
26
  provider,
27
- fromAccountId,
28
- toAccountId,
29
- amount,
27
+ fromAccountAddress,
28
+ toAccountAddress,
29
+ fromAmount,
30
30
  currentday,
31
31
  }),
32
32
  )
@@ -36,9 +36,9 @@ function createSwapIntentHashes({
36
36
  .createHash("sha256")
37
37
  .update(
38
38
  JSON.stringify({
39
- fromAccountId,
40
- toAccountId,
41
- amount,
39
+ fromAccountAddress,
40
+ toAccountAddress,
41
+ fromAmount,
42
42
  currentday,
43
43
  }),
44
44
  )
@@ -52,9 +52,9 @@ export const postSwapAccepted: PostSwapAccepted = async ({
52
52
  swapId = "",
53
53
  transactionId,
54
54
  swapAppVersion,
55
- fromAccountId,
56
- toAccountId,
57
- amount,
55
+ fromAccountAddress,
56
+ toAccountAddress,
57
+ fromAmount,
58
58
  ...rest
59
59
  }) => {
60
60
  if (isIntegrationTestEnv())
@@ -70,9 +70,9 @@ export const postSwapAccepted: PostSwapAccepted = async ({
70
70
 
71
71
  const { swapIntentWithProvider, swapIntentWithoutProvider } = createSwapIntentHashes({
72
72
  provider,
73
- fromAccountId,
74
- toAccountId,
75
- amount,
73
+ fromAccountAddress,
74
+ toAccountAddress,
75
+ fromAmount,
76
76
  });
77
77
 
78
78
  try {
@@ -99,9 +99,9 @@ export const postSwapCancelled: PostSwapCancelled = async ({
99
99
  provider,
100
100
  swapId = "",
101
101
  swapAppVersion,
102
- fromAccountId,
103
- toAccountId,
104
- amount,
102
+ fromAccountAddress,
103
+ toAccountAddress,
104
+ fromAmount,
105
105
  seedIdFrom,
106
106
  seedIdTo,
107
107
  refundAddress,
@@ -120,19 +120,14 @@ export const postSwapCancelled: PostSwapCancelled = async ({
120
120
 
121
121
  const { swapIntentWithProvider, swapIntentWithoutProvider } = createSwapIntentHashes({
122
122
  provider,
123
- fromAccountId,
124
- toAccountId,
125
- amount,
123
+ fromAccountAddress,
124
+ toAccountAddress,
125
+ fromAmount,
126
126
  });
127
127
 
128
128
  // Check if the refundAddress and payoutAddress match the account addresses, just to eliminate this supposition
129
129
  const payloadAddressMatchAccountAddress =
130
- fromAccountId &&
131
- toAccountId &&
132
- refundAddress &&
133
- payoutAddress &&
134
- fromAccountId.includes(refundAddress) &&
135
- toAccountId.includes(payoutAddress);
130
+ fromAccountAddress === refundAddress && toAccountAddress === payoutAddress;
136
131
 
137
132
  try {
138
133
  const ipHeader = getSwapUserIP();
@@ -151,8 +146,9 @@ export const postSwapCancelled: PostSwapCancelled = async ({
151
146
  swapIntentWithProvider,
152
147
  swapIntentWithoutProvider,
153
148
  payloadAddressMatchAccountAddress,
154
- fromAccountId: shouldIncludeAddresses ? fromAccountId : undefined,
155
- toAccountId: shouldIncludeAddresses ? toAccountId : undefined,
149
+ fromAmount,
150
+ fromAccountAddress: shouldIncludeAddresses ? fromAccountAddress : undefined,
151
+ toAccountAddress: shouldIncludeAddresses ? toAccountAddress : undefined,
156
152
  payloadRefundAddress: shouldIncludeAddresses ? refundAddress : undefined,
157
153
  payloadPayoutAddress: shouldIncludeAddresses ? payoutAddress : undefined,
158
154
  maybeSeedMatch: seedIdFrom === seedIdTo, // Only true if both accounts are from the same seed and from the same chain type
@@ -12,9 +12,9 @@ export const setBroadcastTransaction = ({
12
12
  hardwareWalletType,
13
13
  swapType,
14
14
  swapAppVersion,
15
- fromAccountId,
16
- toAccountId,
17
- amount,
15
+ fromAccountAddress,
16
+ toAccountAddress,
17
+ fromAmount,
18
18
  }: {
19
19
  result: { operation: Operation | string; swapId: string };
20
20
  provider: string;
@@ -23,9 +23,9 @@ export const setBroadcastTransaction = ({
23
23
  hardwareWalletType?: DeviceModelId;
24
24
  swapType?: TradeMethod;
25
25
  swapAppVersion?: string;
26
- fromAccountId?: string;
27
- toAccountId?: string;
28
- amount?: string;
26
+ fromAccountAddress?: string;
27
+ toAccountAddress?: string;
28
+ fromAmount?: string;
29
29
  }) => {
30
30
  const { operation, swapId } = result;
31
31
 
@@ -45,9 +45,9 @@ export const setBroadcastTransaction = ({
45
45
  hardwareWalletType,
46
46
  swapType: swapType,
47
47
  swapAppVersion,
48
- fromAccountId,
49
- toAccountId,
50
- amount,
48
+ fromAccountAddress,
49
+ toAccountAddress,
50
+ fromAmount,
51
51
  });
52
52
  } else {
53
53
  postSwapAccepted({
@@ -59,9 +59,9 @@ export const setBroadcastTransaction = ({
59
59
  hardwareWalletType,
60
60
  swapType,
61
61
  swapAppVersion,
62
- fromAccountId,
63
- toAccountId,
64
- amount,
62
+ fromAccountAddress,
63
+ toAccountAddress,
64
+ fromAmount,
65
65
  });
66
66
  }
67
67
  };
@@ -200,9 +200,9 @@ type SwapStateRequest = {
200
200
  hardwareWalletType: DeviceModelId;
201
201
  swapType: TradeMethod;
202
202
  swapAppVersion?: string;
203
- fromAccountId?: string;
204
- toAccountId?: string;
205
- amount?: string;
203
+ fromAccountAddress?: string;
204
+ toAccountAddress?: string;
205
+ fromAmount?: string;
206
206
  seedIdFrom?: string;
207
207
  seedIdTo?: string;
208
208
  refundAddress?: string;
@@ -22,8 +22,8 @@ export const tezosConfig: Record<string, ConfigInfo> = {
22
22
  minGasLimit: 600,
23
23
  minRevealGasLimit: 300,
24
24
  minStorageLimit: 0,
25
- minFees: 500,
26
- minEstimatedFees: 500,
25
+ minFees: 300,
26
+ minEstimatedFees: 300,
27
27
  },
28
28
  },
29
29
  },
@@ -1,7 +1,7 @@
1
1
  import React, { useMemo } from "react";
2
2
  import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
3
3
  import { useMarketByCurrencies } from "../../../dada-client/hooks/useMarketByCurrencies";
4
- import { counterValueFormatter } from "../../utils/counterValueFormatter";
4
+ import counterValueFormatter from "../../../market/utils/countervalueFormatter";
5
5
  import { UseBalanceDeps } from "../../utils/type";
6
6
 
7
7
  const createMarketPriceItem = ({
@@ -1,16 +1,14 @@
1
- import { useMemo, type ReactNode } from "react";
2
- import type { CryptoOrTokenCurrency, Currency } from "@ledgerhq/types-cryptoassets";
3
- import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/formatCurrencyUnit";
1
+ import { useMemo } from "react";
2
+ import type { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
4
3
  import BigNumber from "bignumber.js";
5
- import { counterValueFormatter } from "../utils/counterValueFormatter";
6
4
  import { compareByBalanceThenFiat } from "../utils/sortByBalance";
7
- import { UseBalanceDeps } from "../utils/type";
5
+ import { UseBalanceDeps, CreateBalanceItem } from "../utils/type";
8
6
  import { calculateProviderTotals } from "../utils/calculateProviderTotal";
9
7
  import { groupAccountsByAsset } from "../utils/groupAccountsByAsset";
10
8
 
11
9
  export type AssetDeps = {
12
10
  useBalanceDeps: UseBalanceDeps;
13
- balanceItem: (asset: { fiatValue?: string; balance?: string }) => ReactNode;
11
+ balanceItem: CreateBalanceItem;
14
12
  assetsMap: Map<
15
13
  string,
16
14
  { mainCurrency: CryptoOrTokenCurrency; currencies: CryptoOrTokenCurrency[] }
@@ -22,50 +20,36 @@ export function createUseRightBalanceAsset({ useBalanceDeps, balanceItem, assets
22
20
  providerCurrency: CryptoOrTokenCurrency,
23
21
  totalBalance: BigNumber,
24
22
  totalFiatValue: BigNumber,
25
- counterValueCurrency: Currency,
26
- locale: string,
27
- discreet: boolean,
28
23
  ) => {
29
- const unit = providerCurrency.units?.[0];
30
- const balance = unit
31
- ? formatCurrencyUnit(unit, totalBalance, { showCode: true, discreet })
32
- : `${totalBalance.toFixed()} ${providerCurrency.ticker ?? providerCurrency.symbol}`;
33
- const fiatValue = counterValueFormatter({
34
- currency: counterValueCurrency.ticker,
35
- value: totalFiatValue.toNumber(),
36
- locale,
37
- allowZeroValue: true,
38
- });
39
- return { balance, fiatValue };
24
+ return {
25
+ currency: providerCurrency,
26
+ balance: totalBalance,
27
+ fiatValue: totalFiatValue.toNumber(),
28
+ };
40
29
  };
41
30
 
42
31
  return function useRightBalanceAsset(assets: CryptoOrTokenCurrency[]) {
43
- const { flattenedAccounts, discreet, state, counterValueCurrency, locale } = useBalanceDeps();
32
+ const { flattenedAccounts, state, counterValueCurrency } = useBalanceDeps();
44
33
 
45
34
  const grouped = useMemo(
46
- () => groupAccountsByAsset(flattenedAccounts, state, counterValueCurrency, discreet),
47
- [flattenedAccounts, state, counterValueCurrency, discreet],
35
+ () => groupAccountsByAsset(flattenedAccounts, state, counterValueCurrency),
36
+ [flattenedAccounts, state, counterValueCurrency],
48
37
  );
49
38
 
50
39
  return useMemo(() => {
51
40
  const balanceMap = new Map();
52
41
 
53
42
  for (const [, { currencies, mainCurrency }] of assetsMap) {
54
- const { totalBalance, totalFiatValue } = calculateProviderTotals(currencies, grouped);
55
-
56
- const { balance, fiatValue } = formatProviderResult(
57
- mainCurrency,
58
- totalBalance,
59
- totalFiatValue,
60
- counterValueCurrency,
61
- locale,
62
- discreet,
43
+ const { totalBalance, totalFiatValue, referenceCurrency } = calculateProviderTotals(
44
+ currencies,
45
+ grouped,
63
46
  );
64
47
 
65
- balanceMap.set(mainCurrency.id, {
66
- balance: balance,
67
- fiatValue: fiatValue,
68
- });
48
+ // Use referenceCurrency from actual accounts if available, fallback to mainCurrency
49
+ const currencyToUse = referenceCurrency || mainCurrency;
50
+ const balanceData = formatProviderResult(currencyToUse, totalBalance, totalFiatValue);
51
+
52
+ balanceMap.set(mainCurrency.id, balanceData);
69
53
  }
70
54
 
71
55
  const assetsWithBalanceData = assets.map(asset => {
@@ -78,8 +62,8 @@ export function createUseRightBalanceAsset({ useBalanceDeps, balanceItem, assets
78
62
  });
79
63
 
80
64
  return assetsWithBalanceData.sort((a, b) =>
81
- compareByBalanceThenFiat(a.balanceData, b.balanceData, discreet),
65
+ compareByBalanceThenFiat(a.balanceData, b.balanceData),
82
66
  );
83
- }, [assets, grouped, counterValueCurrency, locale, discreet]);
67
+ }, [assets, grouped]);
84
68
  };
85
69
  }
@@ -1,10 +1,9 @@
1
- import { type ReactNode } from "react";
2
1
  import type { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
3
- import { UseBalanceDeps } from "../utils/type";
2
+ import { UseBalanceDeps, CreateBalanceItem } from "../utils/type";
4
3
  import { getBalanceAndFiatValueByAssets } from "../utils/getBalanceAndFiatValueByAssets";
5
4
 
6
5
  export type NetworkDeps = {
7
- balanceItem: (asset: { fiatValue?: string; balance?: string }) => ReactNode;
6
+ balanceItem: CreateBalanceItem;
8
7
  useBalanceDeps: UseBalanceDeps;
9
8
  };
10
9
 
@@ -14,23 +13,22 @@ type Params = {
14
13
 
15
14
  export function createUseRightBalanceNetwork({ useBalanceDeps, balanceItem }: NetworkDeps) {
16
15
  return function useRightBalanceNetwork({ networks }: Params) {
17
- const { flattenedAccounts, discreet, state, counterValueCurrency, locale } = useBalanceDeps();
16
+ const { flattenedAccounts, state, counterValueCurrency } = useBalanceDeps();
18
17
 
19
18
  const networkBalanceData = getBalanceAndFiatValueByAssets(
20
19
  flattenedAccounts,
21
20
  networks,
22
21
  state,
23
22
  counterValueCurrency,
24
- discreet,
25
- locale,
26
23
  );
27
24
 
28
25
  const balanceMap = new Map(networkBalanceData.map(b => [b.id, b]));
29
26
 
30
27
  return networks.map(network => {
31
28
  const balanceData = balanceMap.get(network.id) || {};
29
+ const details = network.type === "TokenCurrency" ? network.parentCurrency : network;
32
30
  return {
33
- ...network,
31
+ ...details,
34
32
  rightElement: balanceItem(balanceData),
35
33
  balanceData: balanceData,
36
34
  };
@@ -83,14 +83,19 @@ export const createNetworkConfigurationHook =
83
83
 
84
84
  const result = composedHook(assets);
85
85
 
86
- if (leftElement === "numberOfAccounts" || leftElement === "numberOfAccountsAndApy") {
86
+ if (
87
+ leftElement === "numberOfAccounts" ||
88
+ leftElement === "numberOfAccountsAndApy" ||
89
+ leftElement === undefined // default
90
+ ) {
87
91
  result.sort((a, b) => (b?.count || 0) - (a?.count || 0));
88
92
  }
89
93
 
90
- if (rightElement === "balance") {
91
- const { discreet } = NetworkConfigurationDeps.useBalanceDeps();
92
-
93
- result.sort((a, b) => compareByBalanceThenFiat(a?.balanceData, b?.balanceData, discreet));
94
+ if (
95
+ rightElement === "balance" ||
96
+ rightElement === undefined // default
97
+ ) {
98
+ result.sort((a, b) => compareByBalanceThenFiat(a?.balanceData, b?.balanceData));
94
99
  }
95
100
 
96
101
  return result;
@@ -0,0 +1,237 @@
1
+ import { calculateProviderTotals } from "../calculateProviderTotal";
2
+ import { createFixtureCryptoCurrency } from "../../../mock/fixtures/cryptoCurrencies";
3
+ import { genAccount } from "../../../mock/account";
4
+ import BigNumber from "bignumber.js";
5
+ import type { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
6
+
7
+ describe("calculateProviderTotals", () => {
8
+ const mockBTCCurrency = createFixtureCryptoCurrency("bitcoin");
9
+ const mockETHCurrency = createFixtureCryptoCurrency("ethereum");
10
+
11
+ const mockBTCAccount = genAccount("btc-account", { currency: mockBTCCurrency });
12
+ const mockUSDCAccount = genAccount("usdc-account", { currency: mockETHCurrency });
13
+ const mockBscUSDCAccount = genAccount("bsc-usdc-account", { currency: mockETHCurrency });
14
+
15
+ const mockUSDCToken: CryptoOrTokenCurrency = {
16
+ type: "TokenCurrency",
17
+ id: "ethereum/erc20/usdc",
18
+ contractAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
19
+ parentCurrency: mockETHCurrency,
20
+ tokenType: "erc20",
21
+ name: "USD Coin",
22
+ ticker: "USDC",
23
+ units: [{ name: "USD Coin", code: "USDC", magnitude: 6 }],
24
+ };
25
+
26
+ const mockBscUSDCToken: CryptoOrTokenCurrency = {
27
+ type: "TokenCurrency",
28
+ id: "bsc/bep20/usdc",
29
+ contractAddress: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
30
+ parentCurrency: mockETHCurrency, // Using ETH as parent for simplicity
31
+ tokenType: "bep20",
32
+ name: "USD Coin (BSC)",
33
+ ticker: "USDC",
34
+ units: [{ name: "USD Coin", code: "USDC", magnitude: 18 }],
35
+ };
36
+
37
+ it("should return totals with hasAccounts false when no accounts exist", () => {
38
+ const currencies = [mockBTCCurrency, mockUSDCToken];
39
+ const groupedAccounts = {};
40
+
41
+ const result = calculateProviderTotals(currencies, groupedAccounts);
42
+
43
+ expect(result).toEqual({
44
+ totalBalance: new BigNumber(0),
45
+ totalFiatValue: new BigNumber(0),
46
+ hasAccounts: false,
47
+ referenceCurrency: null,
48
+ });
49
+ });
50
+
51
+ it("should sum totals across multiple currencies", () => {
52
+ const currencies = [mockBTCCurrency, mockUSDCToken];
53
+ const groupedAccounts = {
54
+ [mockBTCCurrency.id]: {
55
+ totalBalance: new BigNumber(100000000), // 1 BTC
56
+ totalFiatValue: new BigNumber(50000), // $50,000
57
+ accounts: [mockBTCAccount], // Non-empty accounts array
58
+ referenceCurrency: mockBTCCurrency,
59
+ },
60
+ [mockUSDCToken.id]: {
61
+ totalBalance: new BigNumber(1000000), // 1 USDC
62
+ totalFiatValue: new BigNumber(1), // $1
63
+ accounts: [mockUSDCAccount], // Non-empty accounts array
64
+ referenceCurrency: mockUSDCToken,
65
+ },
66
+ };
67
+
68
+ const result = calculateProviderTotals(currencies, groupedAccounts);
69
+
70
+ // BTC (magnitude 8) sets reference, USDC (magnitude 6) gets normalized
71
+ // USDC: 1000000 * 10^(8-6) = 1000000 * 100 = 100000000
72
+ // Total: 100000000 (BTC) + 100000000 (normalized USDC) = 200000000
73
+ expect(result).toEqual({
74
+ totalBalance: new BigNumber(200000000), // Combined balance after magnitude normalization
75
+ totalFiatValue: new BigNumber(50001), // Combined fiat value
76
+ hasAccounts: true,
77
+ referenceCurrency: mockBTCCurrency, // First currency with accounts
78
+ });
79
+ });
80
+
81
+ it("should return referenceCurrency from first asset group with accounts", () => {
82
+ const currencies = [mockUSDCToken, mockBscUSDCToken];
83
+ const groupedAccounts = {
84
+ [mockUSDCToken.id]: {
85
+ totalBalance: new BigNumber(1000000),
86
+ totalFiatValue: new BigNumber(1),
87
+ accounts: [mockUSDCAccount], // Non-empty accounts array
88
+ referenceCurrency: mockUSDCToken, // ETH USDC with 6 decimals
89
+ },
90
+ [mockBscUSDCToken.id]: {
91
+ totalBalance: new BigNumber("1000000000000000000"),
92
+ totalFiatValue: new BigNumber(1),
93
+ accounts: [mockBscUSDCAccount], // Non-empty accounts array
94
+ referenceCurrency: mockBscUSDCToken, // BSC USDC with 18 decimals
95
+ },
96
+ };
97
+
98
+ const result = calculateProviderTotals(currencies, groupedAccounts);
99
+
100
+ expect(result.referenceCurrency).toEqual(mockUSDCToken); // First currency
101
+ expect(result.hasAccounts).toBe(true);
102
+ });
103
+
104
+ it("should skip currencies with no accounts", () => {
105
+ const currencies = [mockBTCCurrency, mockUSDCToken];
106
+ const groupedAccounts = {
107
+ [mockUSDCToken.id]: {
108
+ totalBalance: new BigNumber(1000000),
109
+ totalFiatValue: new BigNumber(1),
110
+ accounts: [mockUSDCAccount], // Non-empty accounts array
111
+ referenceCurrency: mockUSDCToken,
112
+ },
113
+ // BTC has no entry in groupedAccounts
114
+ };
115
+
116
+ const result = calculateProviderTotals(currencies, groupedAccounts);
117
+
118
+ expect(result).toEqual({
119
+ totalBalance: new BigNumber(1000000), // Only USDC balance
120
+ totalFiatValue: new BigNumber(1), // Only USDC fiat value
121
+ hasAccounts: true,
122
+ referenceCurrency: mockUSDCToken,
123
+ });
124
+ });
125
+
126
+ it("should skip currencies with empty accounts array", () => {
127
+ const currencies = [mockBTCCurrency, mockUSDCToken];
128
+ const groupedAccounts = {
129
+ [mockBTCCurrency.id]: {
130
+ totalBalance: new BigNumber(100000000),
131
+ totalFiatValue: new BigNumber(50000),
132
+ accounts: [], // Empty accounts array should be skipped
133
+ referenceCurrency: mockBTCCurrency,
134
+ },
135
+ [mockUSDCToken.id]: {
136
+ totalBalance: new BigNumber(1000000),
137
+ totalFiatValue: new BigNumber(1),
138
+ accounts: [mockUSDCAccount], // Non-empty accounts array
139
+ referenceCurrency: mockUSDCToken,
140
+ },
141
+ };
142
+
143
+ const result = calculateProviderTotals(currencies, groupedAccounts);
144
+
145
+ expect(result).toEqual({
146
+ totalBalance: new BigNumber(1000000), // Only USDC (non-empty accounts)
147
+ totalFiatValue: new BigNumber(1),
148
+ hasAccounts: true,
149
+ referenceCurrency: mockUSDCToken,
150
+ });
151
+ });
152
+
153
+ it("should normalize balances based on magnitude differences", () => {
154
+ // Test the specific code: magnitude normalization between currencies
155
+ const currencies = [mockUSDCToken, mockBscUSDCToken];
156
+ const groupedAccounts = {
157
+ [mockUSDCToken.id]: {
158
+ totalBalance: new BigNumber(1000000), // 1 USDC with 6 decimals
159
+ totalFiatValue: new BigNumber(1),
160
+ accounts: [mockUSDCAccount],
161
+ referenceCurrency: mockUSDCToken, // 6 decimals
162
+ },
163
+ [mockBscUSDCToken.id]: {
164
+ totalBalance: new BigNumber("1000000000000000000"), // 1 USDC with 18 decimals
165
+ totalFiatValue: new BigNumber(1),
166
+ accounts: [mockBscUSDCAccount],
167
+ referenceCurrency: mockBscUSDCToken, // 18 decimals
168
+ },
169
+ };
170
+
171
+ const result = calculateProviderTotals(currencies, groupedAccounts);
172
+
173
+ // First currency (USDC) sets reference magnitude of 6
174
+ // Second currency (BSC USDC) has magnitude 18, so diff = 6 - 18 = -12
175
+ // BSC balance of 1000000000000000000 shifted by -12 = 1000000
176
+ // Total should be 1000000 + 1000000 = 2000000
177
+ expect(result.totalBalance).toEqual(new BigNumber(2000000));
178
+ expect(result.totalFiatValue).toEqual(new BigNumber(2));
179
+ expect(result.hasAccounts).toBe(true);
180
+ expect(result.referenceCurrency).toEqual(mockUSDCToken);
181
+ });
182
+
183
+ it("should handle magnitude normalization when referenceCurrency is set", () => {
184
+ const currencies = [mockBscUSDCToken];
185
+ const groupedAccounts = {
186
+ [mockBscUSDCToken.id]: {
187
+ totalBalance: new BigNumber("2000000000000000000"),
188
+ totalFiatValue: new BigNumber(2),
189
+ accounts: [mockBscUSDCAccount],
190
+ referenceCurrency: mockBscUSDCToken,
191
+ },
192
+ };
193
+
194
+ const result = calculateProviderTotals(currencies, groupedAccounts);
195
+
196
+ expect(result.totalBalance).toEqual(new BigNumber("2000000000000000000"));
197
+ expect(result.referenceCurrency).toEqual(mockBscUSDCToken);
198
+ });
199
+
200
+ it("should handle zero magnitude difference correctly", () => {
201
+ const sameMagnitudeCurrency: CryptoOrTokenCurrency = {
202
+ type: "TokenCurrency",
203
+ id: "ethereum/erc20/usdc2",
204
+ contractAddress: "0x1234567890123456789012345678901234567890",
205
+ parentCurrency: mockETHCurrency,
206
+ tokenType: "erc20",
207
+ name: "USD Coin 2",
208
+ ticker: "USDC2",
209
+ units: [{ name: "USD Coin 2", code: "USDC2", magnitude: 6 }],
210
+ };
211
+
212
+ const mockSameMagnitudeAccount = genAccount("usdc2-account", { currency: mockETHCurrency });
213
+
214
+ const currencies = [mockUSDCToken, sameMagnitudeCurrency];
215
+ const groupedAccounts = {
216
+ [mockUSDCToken.id]: {
217
+ totalBalance: new BigNumber(1000000), // 1 USDC
218
+ totalFiatValue: new BigNumber(1),
219
+ accounts: [mockUSDCAccount],
220
+ referenceCurrency: mockUSDCToken, // 6 decimals
221
+ },
222
+ [sameMagnitudeCurrency.id]: {
223
+ totalBalance: new BigNumber(2000000), // 2 USDC2
224
+ totalFiatValue: new BigNumber(2),
225
+ accounts: [mockSameMagnitudeAccount],
226
+ referenceCurrency: sameMagnitudeCurrency, // 6 decimals
227
+ },
228
+ };
229
+
230
+ const result = calculateProviderTotals(currencies, groupedAccounts);
231
+
232
+ // Both have magnitude 6, so diff = 6 - 6 = 0
233
+ // No shifting needed, simple addition: 1000000 + 2000000 = 3000000
234
+ expect(result.totalBalance).toEqual(new BigNumber(3000000));
235
+ expect(result.totalFiatValue).toEqual(new BigNumber(3));
236
+ });
237
+ });