@ledgerhq/live-common 34.46.0-nightly.4 → 34.46.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 (210) hide show
  1. package/lib/bridge/crypto-assets/index.d.ts +1 -1
  2. package/lib/bridge/crypto-assets/index.d.ts.map +1 -1
  3. package/lib/bridge/crypto-assets/index.js +1 -1
  4. package/lib/bridge/crypto-assets/index.js.map +1 -1
  5. package/lib/bridge/impl.d.ts +1 -1
  6. package/lib/bridge/impl.d.ts.map +1 -1
  7. package/lib/domain/getTokensWithFunds.test.js +1 -1
  8. package/lib/domain/getTokensWithFunds.test.js.map +1 -1
  9. package/lib/e2e/enum/DeviceLabels.d.ts +2 -3
  10. package/lib/e2e/enum/DeviceLabels.d.ts.map +1 -1
  11. package/lib/e2e/enum/DeviceLabels.js +1 -2
  12. package/lib/e2e/enum/DeviceLabels.js.map +1 -1
  13. package/lib/e2e/families/solana.d.ts.map +1 -1
  14. package/lib/e2e/families/solana.js +4 -4
  15. package/lib/e2e/families/solana.js.map +1 -1
  16. package/lib/e2e/index.d.ts +0 -3
  17. package/lib/e2e/index.d.ts.map +1 -1
  18. package/lib/e2e/speculos.js +1 -1
  19. package/lib/e2e/speculos.js.map +1 -1
  20. package/lib/env.react.d.ts +1 -1
  21. package/lib/env.react.d.ts.map +1 -1
  22. package/lib/exchange/swap/api/v5/actions.js +1 -1
  23. package/lib/exchange/swap/api/v5/actions.js.map +1 -1
  24. package/lib/exchange/swap/types.d.ts +1 -1
  25. package/lib/exchange/swap/types.d.ts.map +1 -1
  26. package/lib/families/evm/setup.d.ts.map +1 -1
  27. package/lib/families/evm/setup.js +1 -11
  28. package/lib/families/evm/setup.js.map +1 -1
  29. package/lib/families/hedera/setup.d.ts +5 -5
  30. package/lib/families/hedera/setup.d.ts.map +1 -1
  31. package/lib/families/hedera/setup.js.map +1 -1
  32. package/lib/families/solana/setup.d.ts.map +1 -1
  33. package/lib/families/solana/setup.js +1 -2
  34. package/lib/families/solana/setup.js.map +1 -1
  35. package/lib/generated/bridge/js.d.ts +1 -1
  36. package/lib/market/utils/countervalueFormatter.d.ts.map +1 -1
  37. package/lib/market/utils/countervalueFormatter.js.map +1 -1
  38. package/lib/market/utils/types.d.ts +0 -2
  39. package/lib/market/utils/types.d.ts.map +1 -1
  40. package/lib/modularDrawer/__mocks__/currencies.mock.d.ts.map +1 -1
  41. package/lib/modularDrawer/__mocks__/currencies.mock.js +7 -7
  42. package/lib/modularDrawer/__mocks__/currencies.mock.js.map +1 -1
  43. package/lib/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.js +1 -1
  44. package/lib/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.js.map +1 -1
  45. package/lib/modularDrawer/utils/__tests__/currencyUtils.test.js +1 -1
  46. package/lib/modularDrawer/utils/__tests__/currencyUtils.test.js.map +1 -1
  47. package/lib/modularDrawer/utils/__tests__/haveOneCommonProvider.test.js +1 -1
  48. package/lib/modularDrawer/utils/__tests__/haveOneCommonProvider.test.js.map +1 -1
  49. package/lib/utils/__tests__/getAccountTuplesForCurrency.test.js +1 -1
  50. package/lib/utils/__tests__/getAccountTuplesForCurrency.test.js.map +1 -1
  51. package/lib-es/bridge/crypto-assets/index.d.ts +1 -1
  52. package/lib-es/bridge/crypto-assets/index.d.ts.map +1 -1
  53. package/lib-es/bridge/crypto-assets/index.js +1 -1
  54. package/lib-es/bridge/crypto-assets/index.js.map +1 -1
  55. package/lib-es/bridge/impl.d.ts +1 -1
  56. package/lib-es/bridge/impl.d.ts.map +1 -1
  57. package/lib-es/domain/getTokensWithFunds.test.js +1 -1
  58. package/lib-es/domain/getTokensWithFunds.test.js.map +1 -1
  59. package/lib-es/e2e/enum/DeviceLabels.d.ts +2 -3
  60. package/lib-es/e2e/enum/DeviceLabels.d.ts.map +1 -1
  61. package/lib-es/e2e/enum/DeviceLabels.js +1 -2
  62. package/lib-es/e2e/enum/DeviceLabels.js.map +1 -1
  63. package/lib-es/e2e/families/solana.d.ts.map +1 -1
  64. package/lib-es/e2e/families/solana.js +4 -4
  65. package/lib-es/e2e/families/solana.js.map +1 -1
  66. package/lib-es/e2e/index.d.ts +0 -3
  67. package/lib-es/e2e/index.d.ts.map +1 -1
  68. package/lib-es/e2e/speculos.js +1 -1
  69. package/lib-es/e2e/speculos.js.map +1 -1
  70. package/lib-es/env.react.d.ts +1 -1
  71. package/lib-es/env.react.d.ts.map +1 -1
  72. package/lib-es/exchange/swap/api/v5/actions.js +1 -1
  73. package/lib-es/exchange/swap/api/v5/actions.js.map +1 -1
  74. package/lib-es/exchange/swap/types.d.ts +1 -1
  75. package/lib-es/exchange/swap/types.d.ts.map +1 -1
  76. package/lib-es/families/evm/setup.d.ts.map +1 -1
  77. package/lib-es/families/evm/setup.js +1 -11
  78. package/lib-es/families/evm/setup.js.map +1 -1
  79. package/lib-es/families/hedera/setup.d.ts +5 -5
  80. package/lib-es/families/hedera/setup.d.ts.map +1 -1
  81. package/lib-es/families/hedera/setup.js.map +1 -1
  82. package/lib-es/families/solana/setup.d.ts.map +1 -1
  83. package/lib-es/families/solana/setup.js +1 -2
  84. package/lib-es/families/solana/setup.js.map +1 -1
  85. package/lib-es/generated/bridge/js.d.ts +1 -1
  86. package/lib-es/market/utils/countervalueFormatter.d.ts.map +1 -1
  87. package/lib-es/market/utils/countervalueFormatter.js.map +1 -1
  88. package/lib-es/market/utils/types.d.ts +0 -2
  89. package/lib-es/market/utils/types.d.ts.map +1 -1
  90. package/lib-es/modularDrawer/__mocks__/currencies.mock.d.ts.map +1 -1
  91. package/lib-es/modularDrawer/__mocks__/currencies.mock.js +1 -1
  92. package/lib-es/modularDrawer/__mocks__/currencies.mock.js.map +1 -1
  93. package/lib-es/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.js +1 -1
  94. package/lib-es/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.js.map +1 -1
  95. package/lib-es/modularDrawer/utils/__tests__/currencyUtils.test.js +1 -1
  96. package/lib-es/modularDrawer/utils/__tests__/currencyUtils.test.js.map +1 -1
  97. package/lib-es/modularDrawer/utils/__tests__/haveOneCommonProvider.test.js +1 -1
  98. package/lib-es/modularDrawer/utils/__tests__/haveOneCommonProvider.test.js.map +1 -1
  99. package/lib-es/utils/__tests__/getAccountTuplesForCurrency.test.js +1 -1
  100. package/lib-es/utils/__tests__/getAccountTuplesForCurrency.test.js.map +1 -1
  101. package/package.json +72 -73
  102. package/src/DataModel.test.ts +1 -1
  103. package/src/__tests__/accounts/groupPerDay.ts +1 -1
  104. package/src/__tests__/test-helpers/setup.ts +1 -1
  105. package/src/account/serialization.test.ts +1 -1
  106. package/src/bridge/crypto-assets/index.test.ts +1 -1
  107. package/src/bridge/crypto-assets/index.ts +2 -3
  108. package/src/bridge/impl.ts +1 -1
  109. package/src/currencies/sortByMarketcap.test.ts +1 -1
  110. package/src/domain/getTokensWithFunds.test.ts +1 -1
  111. package/src/e2e/enum/DeviceLabels.ts +1 -2
  112. package/src/e2e/families/solana.ts +4 -7
  113. package/src/e2e/speculos.ts +1 -1
  114. package/src/exchange/swap/api/v5/actions.ts +1 -1
  115. package/src/exchange/swap/types.ts +1 -1
  116. package/src/families/bitcoin/__snapshots__/bridge.integration.test.ts.snap +0 -7
  117. package/src/families/bitcoin/satstack.test.ts +1 -1
  118. package/src/families/evm/setup.ts +1 -12
  119. package/src/families/hedera/__snapshots__/bridge.integration.test.ts.snap +1135 -464
  120. package/src/families/hedera/setup.ts +3 -7
  121. package/src/families/solana/setup.ts +0 -2
  122. package/src/families/tron/data.mock.ts +1 -1
  123. package/src/market/utils/countervalueFormatter.ts +1 -0
  124. package/src/market/utils/types.ts +0 -4
  125. package/src/modularDrawer/__mocks__/currencies.mock.ts +1 -1
  126. package/src/modularDrawer/__mocks__/useGroupedCurrenciesByProvider.mock.ts +1 -1
  127. package/src/modularDrawer/utils/__tests__/currencyUtils.test.ts +1 -1
  128. package/src/modularDrawer/utils/__tests__/haveOneCommonProvider.test.ts +2 -2
  129. package/src/utils/__tests__/getAccountTuplesForCurrency.test.ts +1 -1
  130. package/lib/families/hedera/constants.d.ts +0 -2
  131. package/lib/families/hedera/constants.d.ts.map +0 -1
  132. package/lib/families/hedera/constants.js +0 -19
  133. package/lib/families/hedera/constants.js.map +0 -1
  134. package/lib/modularDrawer/utils/__tests__/counterValueFormatter.test.d.ts +0 -2
  135. package/lib/modularDrawer/utils/__tests__/counterValueFormatter.test.d.ts.map +0 -1
  136. package/lib/modularDrawer/utils/__tests__/counterValueFormatter.test.js +0 -496
  137. package/lib/modularDrawer/utils/__tests__/counterValueFormatter.test.js.map +0 -1
  138. package/lib/modularDrawer/utils/calculateProviderTotal.d.ts +0 -9
  139. package/lib/modularDrawer/utils/calculateProviderTotal.d.ts.map +0 -1
  140. package/lib/modularDrawer/utils/calculateProviderTotal.js +0 -23
  141. package/lib/modularDrawer/utils/calculateProviderTotal.js.map +0 -1
  142. package/lib/modularDrawer/utils/counterValueFormatter.d.ts +0 -14
  143. package/lib/modularDrawer/utils/counterValueFormatter.d.ts.map +0 -1
  144. package/lib/modularDrawer/utils/counterValueFormatter.js +0 -107
  145. package/lib/modularDrawer/utils/counterValueFormatter.js.map +0 -1
  146. package/lib/modularDrawer/utils/getBalanceAndFiatValueByAssets.d.ts +0 -11
  147. package/lib/modularDrawer/utils/getBalanceAndFiatValueByAssets.d.ts.map +0 -1
  148. package/lib/modularDrawer/utils/getBalanceAndFiatValueByAssets.js +0 -45
  149. package/lib/modularDrawer/utils/getBalanceAndFiatValueByAssets.js.map +0 -1
  150. package/lib/modularDrawer/utils/getProviderCurrency.d.ts +0 -3
  151. package/lib/modularDrawer/utils/getProviderCurrency.d.ts.map +0 -1
  152. package/lib/modularDrawer/utils/getProviderCurrency.js +0 -14
  153. package/lib/modularDrawer/utils/getProviderCurrency.js.map +0 -1
  154. package/lib/modularDrawer/utils/groupAccountsByAsset.d.ts +0 -11
  155. package/lib/modularDrawer/utils/groupAccountsByAsset.d.ts.map +0 -1
  156. package/lib/modularDrawer/utils/groupAccountsByAsset.js +0 -32
  157. package/lib/modularDrawer/utils/groupAccountsByAsset.js.map +0 -1
  158. package/lib/modularDrawer/utils/parseToBigNumber.d.ts +0 -9
  159. package/lib/modularDrawer/utils/parseToBigNumber.d.ts.map +0 -1
  160. package/lib/modularDrawer/utils/parseToBigNumber.js +0 -24
  161. package/lib/modularDrawer/utils/parseToBigNumber.js.map +0 -1
  162. package/lib/modularDrawer/utils/type.d.ts +0 -21
  163. package/lib/modularDrawer/utils/type.d.ts.map +0 -1
  164. package/lib/modularDrawer/utils/type.js +0 -3
  165. package/lib/modularDrawer/utils/type.js.map +0 -1
  166. package/lib-es/families/hedera/constants.d.ts +0 -2
  167. package/lib-es/families/hedera/constants.d.ts.map +0 -1
  168. package/lib-es/families/hedera/constants.js +0 -3
  169. package/lib-es/families/hedera/constants.js.map +0 -1
  170. package/lib-es/modularDrawer/utils/__tests__/counterValueFormatter.test.d.ts +0 -2
  171. package/lib-es/modularDrawer/utils/__tests__/counterValueFormatter.test.d.ts.map +0 -1
  172. package/lib-es/modularDrawer/utils/__tests__/counterValueFormatter.test.js +0 -494
  173. package/lib-es/modularDrawer/utils/__tests__/counterValueFormatter.test.js.map +0 -1
  174. package/lib-es/modularDrawer/utils/calculateProviderTotal.d.ts +0 -9
  175. package/lib-es/modularDrawer/utils/calculateProviderTotal.d.ts.map +0 -1
  176. package/lib-es/modularDrawer/utils/calculateProviderTotal.js +0 -16
  177. package/lib-es/modularDrawer/utils/calculateProviderTotal.js.map +0 -1
  178. package/lib-es/modularDrawer/utils/counterValueFormatter.d.ts +0 -14
  179. package/lib-es/modularDrawer/utils/counterValueFormatter.d.ts.map +0 -1
  180. package/lib-es/modularDrawer/utils/counterValueFormatter.js +0 -103
  181. package/lib-es/modularDrawer/utils/counterValueFormatter.js.map +0 -1
  182. package/lib-es/modularDrawer/utils/getBalanceAndFiatValueByAssets.d.ts +0 -11
  183. package/lib-es/modularDrawer/utils/getBalanceAndFiatValueByAssets.d.ts.map +0 -1
  184. package/lib-es/modularDrawer/utils/getBalanceAndFiatValueByAssets.js +0 -41
  185. package/lib-es/modularDrawer/utils/getBalanceAndFiatValueByAssets.js.map +0 -1
  186. package/lib-es/modularDrawer/utils/getProviderCurrency.d.ts +0 -3
  187. package/lib-es/modularDrawer/utils/getProviderCurrency.d.ts.map +0 -1
  188. package/lib-es/modularDrawer/utils/getProviderCurrency.js +0 -10
  189. package/lib-es/modularDrawer/utils/getProviderCurrency.js.map +0 -1
  190. package/lib-es/modularDrawer/utils/groupAccountsByAsset.d.ts +0 -11
  191. package/lib-es/modularDrawer/utils/groupAccountsByAsset.d.ts.map +0 -1
  192. package/lib-es/modularDrawer/utils/groupAccountsByAsset.js +0 -25
  193. package/lib-es/modularDrawer/utils/groupAccountsByAsset.js.map +0 -1
  194. package/lib-es/modularDrawer/utils/parseToBigNumber.d.ts +0 -9
  195. package/lib-es/modularDrawer/utils/parseToBigNumber.d.ts.map +0 -1
  196. package/lib-es/modularDrawer/utils/parseToBigNumber.js +0 -17
  197. package/lib-es/modularDrawer/utils/parseToBigNumber.js.map +0 -1
  198. package/lib-es/modularDrawer/utils/type.d.ts +0 -21
  199. package/lib-es/modularDrawer/utils/type.d.ts.map +0 -1
  200. package/lib-es/modularDrawer/utils/type.js +0 -2
  201. package/lib-es/modularDrawer/utils/type.js.map +0 -1
  202. package/src/families/hedera/constants.ts +0 -2
  203. package/src/modularDrawer/utils/__tests__/counterValueFormatter.test.ts +0 -549
  204. package/src/modularDrawer/utils/calculateProviderTotal.ts +0 -23
  205. package/src/modularDrawer/utils/counterValueFormatter.ts +0 -165
  206. package/src/modularDrawer/utils/getBalanceAndFiatValueByAssets.ts +0 -76
  207. package/src/modularDrawer/utils/getProviderCurrency.ts +0 -13
  208. package/src/modularDrawer/utils/groupAccountsByAsset.ts +0 -51
  209. package/src/modularDrawer/utils/parseToBigNumber.ts +0 -17
  210. package/src/modularDrawer/utils/type.ts +0 -22
@@ -1,165 +0,0 @@
1
- import { rangeDataTable } from "../../market/utils/rangeDataTable";
2
- import { TFunction } from "i18next";
3
-
4
- export const RANGES = Object.keys(rangeDataTable).filter(key => key !== "1h");
5
-
6
- const indexes: [string, number][] = [
7
- ["d", 1],
8
- ["K", 1000],
9
- ["M", 1000000],
10
- ["B", 1000000000],
11
- ["T", 1000000000000],
12
- ["Q", 1000000000000000],
13
- ["Qn", 1000000000000000000],
14
- ];
15
-
16
- const formatters: Record<string, { [key: string]: Intl.NumberFormat }> = {};
17
-
18
- const getSanitizedValue = (currency: string | undefined, locale: string): string => {
19
- if (currency) {
20
- return `${formatters[locale][currency]
21
- ?.format(0)
22
- .replace(/[0-9,.]+/, "***")
23
- .trim()}`;
24
- }
25
- return "***";
26
- };
27
-
28
- const shouldReturnDash = (
29
- value: number,
30
- allowZeroValue: boolean,
31
- discreetMode: boolean,
32
- ): boolean => {
33
- return !discreetMode && (isNaN(value) || (!value && !allowZeroValue));
34
- };
35
-
36
- const ensureFormatterExists = (
37
- locale: string,
38
- currency: string | undefined,
39
- decimalPlaces: number,
40
- ): void => {
41
- if (!formatters[locale]) formatters[locale] = {};
42
-
43
- if (currency && !formatters[locale]?.[currency]) {
44
- createCurrencyFormatter(locale, currency, decimalPlaces);
45
- } else if (!currency && !formatters[locale]?.[`decimal_${decimalPlaces}`]) {
46
- createDecimalFormatter(locale, decimalPlaces);
47
- }
48
- };
49
-
50
- const createCurrencyFormatter = (locale: string, currency: string, decimalPlaces: number): void => {
51
- try {
52
- formatters[locale][currency] = new Intl.NumberFormat(locale, {
53
- style: "currency",
54
- currency,
55
- });
56
- } catch {
57
- formatters[locale][currency] = new Intl.NumberFormat(locale, {
58
- style: "decimal",
59
- minimumFractionDigits: decimalPlaces,
60
- maximumFractionDigits: 8,
61
- });
62
- }
63
- };
64
-
65
- const createDecimalFormatter = (locale: string, decimalPlaces: number): void => {
66
- formatters[locale][`decimal_${decimalPlaces}`] = new Intl.NumberFormat(locale, {
67
- style: "decimal",
68
- minimumFractionDigits: decimalPlaces,
69
- maximumFractionDigits: decimalPlaces,
70
- });
71
- };
72
-
73
- const getFormatter = (
74
- currency: string | undefined,
75
- locale: string,
76
- shorten: boolean | undefined,
77
- decimalPlaces: number,
78
- ): Intl.NumberFormat | undefined => {
79
- if (currency) {
80
- return formatters[locale][currency];
81
- }
82
-
83
- if (shorten) {
84
- return new Intl.NumberFormat(locale, {
85
- notation: "compact",
86
- maximumFractionDigits: 3,
87
- minimumFractionDigits: Math.min(decimalPlaces, 3),
88
- });
89
- }
90
-
91
- return formatters[locale][`decimal_${decimalPlaces}`];
92
- };
93
-
94
- const formatShortenedValue = (
95
- value: number,
96
- formatter: Intl.NumberFormat,
97
- t: TFunction,
98
- ): string => {
99
- const sign = value > 0 ? "" : "-";
100
- const v = Math.abs(value);
101
- const index = Math.floor(Math.log10(v) / 3) || 0;
102
- const [i, n] = indexes[index] || ["", 1];
103
- const roundedValue = Math.round((v / n) * 1000) / 1000;
104
- const number = formatter.format(roundedValue);
105
- const I = t(`numberCompactNotation.${i}`);
106
- const formattedNumber = number.replace(/([0-9,. ]+)/, `${sign}$1 ${I}`);
107
- return formattedNumber.trim();
108
- };
109
-
110
- const formatRegularValue = (
111
- value: number,
112
- formatter: Intl.NumberFormat,
113
- ticker: string,
114
- currency: string | undefined,
115
- locale: string,
116
- discreetMode: boolean,
117
- ): string => {
118
- if (discreetMode) {
119
- return getSanitizedValue(currency, locale);
120
- }
121
-
122
- const formattedValue = formatter.format(value);
123
- const upperCaseTicker = ticker?.trim()?.toLocaleUpperCase();
124
- return `${formattedValue} ${upperCaseTicker}`.trim();
125
- };
126
-
127
- export const counterValueFormatter = ({
128
- currency,
129
- value,
130
- shorten,
131
- locale,
132
- t,
133
- allowZeroValue = false,
134
- ticker = "",
135
- discreetMode = false,
136
- decimalPlaces = 2,
137
- }: {
138
- currency?: string;
139
- value: number;
140
- shorten?: boolean;
141
- locale: string;
142
- t?: TFunction;
143
- allowZeroValue?: boolean;
144
- ticker?: string;
145
- discreetMode?: boolean;
146
- decimalPlaces?: number;
147
- }): string => {
148
- if (shouldReturnDash(value, allowZeroValue, discreetMode)) {
149
- return "-";
150
- }
151
-
152
- ensureFormatterExists(locale, currency, decimalPlaces);
153
-
154
- const formatter = getFormatter(currency, locale, shorten, decimalPlaces);
155
-
156
- if (!formatter) {
157
- return String(value);
158
- }
159
-
160
- if (shorten && t) {
161
- return formatShortenedValue(value, formatter, t);
162
- }
163
-
164
- return formatRegularValue(value, formatter, ticker, currency, locale, discreetMode);
165
- };
@@ -1,76 +0,0 @@
1
- import { formatCurrencyUnit } from "@ledgerhq/coin-framework/lib-es/currencies/formatCurrencyUnit";
2
- import type { CounterValuesState } from "@ledgerhq/live-countervalues/types";
3
- import type { CryptoOrTokenCurrency, Currency } from "@ledgerhq/types-cryptoassets";
4
- import { groupAccountsByAsset, type GroupedAccount } from "./groupAccountsByAsset";
5
- import { AssetType } from "./type";
6
- import { AccountLike } from "@ledgerhq/types-live";
7
- import { counterValueFormatter } from "./counterValueFormatter";
8
-
9
- interface ExtendedAssetType extends AssetType {
10
- balance?: string;
11
- fiatValue?: string;
12
- }
13
-
14
- export const getBalanceAndFiatValueByAssets = (
15
- accounts: AccountLike[],
16
- assets: CryptoOrTokenCurrency[],
17
- counterValuesState: CounterValuesState,
18
- targetCurrency: Currency,
19
- isDiscreetMode: boolean = false,
20
- userLocale: string,
21
- ): ExtendedAssetType[] => {
22
- const groupedAccountsByAsset = groupAccountsByAsset(
23
- accounts,
24
- counterValuesState,
25
- targetCurrency,
26
- isDiscreetMode,
27
- );
28
-
29
- return assets.map(asset => {
30
- const assetGroup = groupedAccountsByAsset[asset.id];
31
-
32
- if (assetGroup) {
33
- return formatAssetDetails(assetGroup, asset, targetCurrency, isDiscreetMode, userLocale);
34
- }
35
-
36
- return {
37
- id: asset.id,
38
- name: asset.name,
39
- ticker: asset.ticker,
40
- };
41
- });
42
- };
43
-
44
- const formatAssetDetails = (
45
- assetGroup: GroupedAccount,
46
- asset: CryptoOrTokenCurrency,
47
- targetCurrency: Currency,
48
- isDiscreetMode: boolean,
49
- userLocale: string,
50
- ): ExtendedAssetType => {
51
- const assetDetails =
52
- assetGroup.accounts[0].type === "Account"
53
- ? assetGroup.accounts[0].currency
54
- : assetGroup.accounts[0].token;
55
-
56
- const formattedBalance = formatCurrencyUnit(assetDetails.units[0], assetGroup.totalBalance, {
57
- showCode: true,
58
- discreet: isDiscreetMode,
59
- });
60
-
61
- const formattedFiatValue = counterValueFormatter({
62
- currency: targetCurrency.ticker,
63
- value: assetGroup.totalFiatValue.toNumber(),
64
- locale: userLocale,
65
- allowZeroValue: true,
66
- discreetMode: isDiscreetMode,
67
- });
68
-
69
- return {
70
- id: asset.id,
71
- name: asset.name,
72
- ticker: asset.ticker,
73
- balance: formattedBalance,
74
- fiatValue: formattedFiatValue,
75
- };
76
- };
@@ -1,13 +0,0 @@
1
- import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets";
2
- import { getTokenOrCryptoCurrencyById } from "../../deposit/helper";
3
-
4
- export const getProviderCurrency = (
5
- mainCurrency: CryptoOrTokenCurrency,
6
- currencies: CryptoOrTokenCurrency[],
7
- ) => {
8
- try {
9
- return getTokenOrCryptoCurrencyById(mainCurrency.id);
10
- } catch {
11
- return getTokenOrCryptoCurrencyById(currencies[0].id);
12
- }
13
- };
@@ -1,51 +0,0 @@
1
- import { getBalanceAndFiatValue } from "./getBalanceAndFiatValue";
2
- import type { CounterValuesState } from "@ledgerhq/live-countervalues/types";
3
- import { Currency } from "@ledgerhq/types-cryptoassets";
4
- import { AccountLike } from "@ledgerhq/types-live";
5
- import BigNumber from "bignumber.js";
6
- import { parseToBigNumber } from "./parseToBigNumber";
7
-
8
- export type GroupedAccount = {
9
- totalBalance: BigNumber;
10
- totalFiatValue: BigNumber;
11
- accounts: AccountLike[];
12
- };
13
-
14
- export const groupAccountsByAsset = (
15
- accounts: AccountLike[],
16
- counterValuesState: CounterValuesState,
17
- targetCurrency: Currency,
18
- isDiscreetMode: boolean,
19
- ): Record<string, GroupedAccount> => {
20
- const initialGroupedAccounts: Record<string, GroupedAccount> = {};
21
-
22
- return accounts.reduce((groupedAccounts, account) => {
23
- const assetId = account.type === "Account" ? account.currency.id : account.token.id;
24
-
25
- if (!groupedAccounts[assetId]) {
26
- groupedAccounts[assetId] = {
27
- totalBalance: new BigNumber(0),
28
- totalFiatValue: new BigNumber(0),
29
- accounts: [],
30
- };
31
- }
32
-
33
- const { fiatValue } = getBalanceAndFiatValue(
34
- account,
35
- counterValuesState,
36
- targetCurrency,
37
- isDiscreetMode,
38
- false,
39
- );
40
- const balance = account.balance;
41
-
42
- const parsedFiatValue = parseToBigNumber(fiatValue ?? "0");
43
-
44
- groupedAccounts[assetId].totalBalance = groupedAccounts[assetId].totalBalance.plus(balance);
45
- groupedAccounts[assetId].totalFiatValue =
46
- groupedAccounts[assetId].totalFiatValue.plus(parsedFiatValue);
47
- groupedAccounts[assetId].accounts.push(account);
48
-
49
- return groupedAccounts;
50
- }, initialGroupedAccounts);
51
- };
@@ -1,17 +0,0 @@
1
- import BigNumber from "bignumber.js";
2
-
3
- /**
4
- *
5
- * @param value - The value to parse into a BigNumber. It can be a string, number, or an existing BigNumber instance.
6
- * @template T - The type of the value, which can be string, number, or BigNumber.
7
- * @returns A BigNumber instance representing the parsed value.
8
- */
9
- export const parseToBigNumber = <T extends string | number | BigNumber>(value: T): BigNumber => {
10
- if (value instanceof BigNumber) {
11
- return value;
12
- }
13
- if (typeof value === "string") {
14
- return new BigNumber(value.replace(/,/g, ""));
15
- }
16
- return new BigNumber(value);
17
- };
@@ -1,22 +0,0 @@
1
- export type AssetType = {
2
- name: string;
3
- ticker: string;
4
- id: string;
5
- leftElement?: React.ReactNode;
6
- rightElement?: React.ReactNode;
7
- };
8
-
9
- export type ProviderBalanceAsset = {
10
- id: string;
11
- name: string;
12
- ticker: string;
13
- balance: string;
14
- fiatValue: string;
15
- sortValue: number;
16
- };
17
-
18
- export type ProviderBalanceResultsMap = Map<string, ProviderBalanceAsset>;
19
-
20
- export type AssetWithBalance = AssetType & {
21
- sortValue?: number;
22
- };