@ledgerhq/live-common 21.5.1 → 21.7.1-patch.1

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 (170) hide show
  1. package/lib/env.js +1 -1
  2. package/lib/env.js.map +1 -1
  3. package/lib/exchange/swap/getExchangeRates.d.ts.map +1 -1
  4. package/lib/exchange/swap/getExchangeRates.js +9 -8
  5. package/lib/exchange/swap/getExchangeRates.js.map +1 -1
  6. package/lib/exchange/swap/hooks/index.d.ts +11 -0
  7. package/lib/exchange/swap/hooks/index.d.ts.map +1 -0
  8. package/lib/exchange/swap/hooks/index.js +23 -0
  9. package/lib/exchange/swap/hooks/index.js.map +1 -0
  10. package/lib/exchange/swap/hooks/useFromState.d.ts +15 -0
  11. package/lib/exchange/swap/hooks/useFromState.d.ts.map +1 -0
  12. package/lib/exchange/swap/hooks/useFromState.js +67 -0
  13. package/lib/exchange/swap/hooks/useFromState.js.map +1 -0
  14. package/lib/exchange/swap/hooks/useFromState.test.d.ts +2 -0
  15. package/lib/exchange/swap/hooks/useFromState.test.d.ts.map +1 -0
  16. package/lib/exchange/swap/hooks/useFromState.test.js +141 -0
  17. package/lib/exchange/swap/hooks/useFromState.test.js.map +1 -0
  18. package/lib/exchange/swap/hooks/usePickDefaultAccount.d.ts +5 -0
  19. package/lib/exchange/swap/hooks/usePickDefaultAccount.d.ts.map +1 -0
  20. package/lib/exchange/swap/hooks/usePickDefaultAccount.js +37 -0
  21. package/lib/exchange/swap/hooks/usePickDefaultAccount.js.map +1 -0
  22. package/lib/exchange/swap/hooks/usePickDefaultAccount.test.d.ts +2 -0
  23. package/lib/exchange/swap/hooks/usePickDefaultAccount.test.d.ts.map +1 -0
  24. package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js +185 -0
  25. package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js.map +1 -0
  26. package/lib/exchange/swap/hooks/usePickDefaultCurrency.d.ts +3 -0
  27. package/lib/exchange/swap/hooks/usePickDefaultCurrency.d.ts.map +1 -0
  28. package/lib/exchange/swap/hooks/usePickDefaultCurrency.js +17 -0
  29. package/lib/exchange/swap/hooks/usePickDefaultCurrency.js.map +1 -0
  30. package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.d.ts +2 -0
  31. package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.d.ts.map +1 -0
  32. package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.js +73 -0
  33. package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.js.map +1 -0
  34. package/lib/exchange/swap/hooks/usePollKYCStatus.d.ts +12 -0
  35. package/lib/exchange/swap/hooks/usePollKYCStatus.d.ts.map +1 -0
  36. package/lib/exchange/swap/hooks/usePollKYCStatus.js +105 -0
  37. package/lib/exchange/swap/hooks/usePollKYCStatus.js.map +1 -0
  38. package/lib/exchange/swap/hooks/usePollKYCStatus.test.d.ts +2 -0
  39. package/lib/exchange/swap/hooks/usePollKYCStatus.test.d.ts.map +1 -0
  40. package/lib/exchange/swap/hooks/usePollKYCStatus.test.js +78 -0
  41. package/lib/exchange/swap/hooks/usePollKYCStatus.test.js.map +1 -0
  42. package/lib/exchange/swap/hooks/useProviderRates.d.ts +20 -0
  43. package/lib/exchange/swap/hooks/useProviderRates.d.ts.map +1 -0
  44. package/lib/exchange/swap/hooks/useProviderRates.js +174 -0
  45. package/lib/exchange/swap/hooks/useProviderRates.js.map +1 -0
  46. package/lib/exchange/swap/hooks/useProviderRates.test.d.ts +2 -0
  47. package/lib/exchange/swap/hooks/useProviderRates.test.d.ts.map +1 -0
  48. package/lib/exchange/swap/hooks/useProviderRates.test.js +261 -0
  49. package/lib/exchange/swap/hooks/useProviderRates.test.js.map +1 -0
  50. package/lib/exchange/swap/hooks/useReverseAccounts.d.ts +15 -0
  51. package/lib/exchange/swap/hooks/useReverseAccounts.d.ts.map +1 -0
  52. package/lib/exchange/swap/hooks/useReverseAccounts.js +35 -0
  53. package/lib/exchange/swap/hooks/useReverseAccounts.js.map +1 -0
  54. package/lib/exchange/swap/hooks/useReverseAccounts.test.d.ts +2 -0
  55. package/lib/exchange/swap/hooks/useReverseAccounts.test.d.ts.map +1 -0
  56. package/lib/exchange/swap/hooks/useReverseAccounts.test.js +79 -0
  57. package/lib/exchange/swap/hooks/useReverseAccounts.test.js.map +1 -0
  58. package/lib/exchange/swap/hooks/useSelectableCurrencies.d.ts +5 -0
  59. package/lib/exchange/swap/hooks/useSelectableCurrencies.d.ts.map +1 -0
  60. package/lib/exchange/swap/hooks/useSelectableCurrencies.js +43 -0
  61. package/lib/exchange/swap/hooks/useSelectableCurrencies.js.map +1 -0
  62. package/lib/exchange/swap/hooks/useSelectableCurrencies.test.d.ts +2 -0
  63. package/lib/exchange/swap/hooks/useSelectableCurrencies.test.d.ts.map +1 -0
  64. package/lib/exchange/swap/hooks/useSelectableCurrencies.test.js +32 -0
  65. package/lib/exchange/swap/hooks/useSelectableCurrencies.test.js.map +1 -0
  66. package/lib/exchange/swap/hooks/useSwapProviders.d.ts +14 -0
  67. package/lib/exchange/swap/hooks/useSwapProviders.d.ts.map +1 -0
  68. package/lib/exchange/swap/hooks/useSwapProviders.js +104 -0
  69. package/lib/exchange/swap/hooks/useSwapProviders.js.map +1 -0
  70. package/lib/exchange/swap/hooks/useSwapProviders.test.d.ts +2 -0
  71. package/lib/exchange/swap/hooks/useSwapProviders.test.d.ts.map +1 -0
  72. package/lib/exchange/swap/hooks/useSwapProviders.test.js +174 -0
  73. package/lib/exchange/swap/hooks/useSwapProviders.test.js.map +1 -0
  74. package/lib/exchange/swap/hooks/useSwapTransaction.d.ts +53 -0
  75. package/lib/exchange/swap/hooks/useSwapTransaction.d.ts.map +1 -0
  76. package/lib/exchange/swap/hooks/useSwapTransaction.js +109 -0
  77. package/lib/exchange/swap/hooks/useSwapTransaction.js.map +1 -0
  78. package/lib/exchange/swap/hooks/useSwapTransaction.test.d.ts +2 -0
  79. package/lib/exchange/swap/hooks/useSwapTransaction.test.d.ts.map +1 -0
  80. package/lib/exchange/swap/hooks/useSwapTransaction.test.js +50 -0
  81. package/lib/exchange/swap/hooks/useSwapTransaction.test.js.map +1 -0
  82. package/lib/exchange/swap/hooks/useToState.d.ts +12 -0
  83. package/lib/exchange/swap/hooks/useToState.d.ts.map +1 -0
  84. package/lib/exchange/swap/hooks/useToState.js +73 -0
  85. package/lib/exchange/swap/hooks/useToState.js.map +1 -0
  86. package/lib/exchange/swap/hooks/useToState.test.d.ts +2 -0
  87. package/lib/exchange/swap/hooks/useToState.test.d.ts.map +1 -0
  88. package/lib/exchange/swap/hooks/useToState.test.js +107 -0
  89. package/lib/exchange/swap/hooks/useToState.test.js.map +1 -0
  90. package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts +15 -0
  91. package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts.map +1 -0
  92. package/lib/exchange/swap/hooks/useUpdateMaxAmount.js +106 -0
  93. package/lib/exchange/swap/hooks/useUpdateMaxAmount.js.map +1 -0
  94. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.d.ts +2 -0
  95. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.d.ts.map +1 -0
  96. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js +217 -0
  97. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js.map +1 -0
  98. package/lib/exchange/swap/mock.d.ts +6 -2
  99. package/lib/exchange/swap/mock.d.ts.map +1 -1
  100. package/lib/exchange/swap/mock.js +21 -6
  101. package/lib/exchange/swap/mock.js.map +1 -1
  102. package/lib/exchange/swap/types.d.ts +1 -1
  103. package/lib/exchange/swap/types.d.ts.map +1 -1
  104. package/lib/exchange/swap/utils/index.d.ts +16 -0
  105. package/lib/exchange/swap/utils/index.d.ts.map +1 -0
  106. package/lib/exchange/swap/utils/index.js +49 -0
  107. package/lib/exchange/swap/utils/index.js.map +1 -0
  108. package/lib/exchange/swap/utils/index.test.d.ts +2 -0
  109. package/lib/exchange/swap/utils/index.test.d.ts.map +1 -0
  110. package/lib/exchange/swap/utils/index.test.js +238 -0
  111. package/lib/exchange/swap/utils/index.test.js.map +1 -0
  112. package/lib/families/crypto_org/datasets/croeseid.d.ts.map +1 -1
  113. package/lib/families/crypto_org/datasets/croeseid.js +2 -6
  114. package/lib/families/crypto_org/datasets/croeseid.js.map +1 -1
  115. package/lib/families/elrond/api/apiCalls.d.ts +0 -4
  116. package/lib/families/elrond/api/apiCalls.d.ts.map +1 -1
  117. package/lib/families/elrond/api/apiCalls.js +3 -37
  118. package/lib/families/elrond/api/apiCalls.js.map +1 -1
  119. package/lib/families/elrond/api/sdk.js +2 -2
  120. package/lib/families/elrond/api/sdk.js.map +1 -1
  121. package/lib/families/elrond/js-transaction.d.ts +2 -0
  122. package/lib/families/elrond/js-transaction.d.ts.map +1 -1
  123. package/lib/families/elrond/types.d.ts +2 -0
  124. package/lib/families/elrond/types.d.ts.map +1 -1
  125. package/lib/families/elrond/types.js.map +1 -1
  126. package/lib/families/tezos/bridge/js.d.ts.map +1 -1
  127. package/lib/families/tezos/bridge/js.js +11 -1
  128. package/lib/families/tezos/bridge/js.js.map +1 -1
  129. package/lib/mock/account.d.ts +2 -1
  130. package/lib/mock/account.d.ts.map +1 -1
  131. package/lib/mock/account.js +4 -2
  132. package/lib/mock/account.js.map +1 -1
  133. package/package.json +15 -15
  134. package/src/__tests__/__snapshots__/all.libcore.ts.snap +10 -10
  135. package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +30 -15
  136. package/src/env.ts +1 -1
  137. package/src/exchange/swap/getExchangeRates.ts +8 -5
  138. package/src/exchange/swap/hooks/index.ts +10 -0
  139. package/src/exchange/swap/hooks/useFromState.test.ts +134 -0
  140. package/src/exchange/swap/hooks/useFromState.ts +84 -0
  141. package/src/exchange/swap/hooks/usePickDefaultAccount.test.ts +167 -0
  142. package/src/exchange/swap/hooks/usePickDefaultAccount.ts +47 -0
  143. package/src/exchange/swap/hooks/usePickDefaultCurrency.test.ts +107 -0
  144. package/src/exchange/swap/hooks/usePickDefaultCurrency.ts +20 -0
  145. package/src/exchange/swap/hooks/usePollKYCStatus.test.ts +89 -0
  146. package/src/exchange/swap/hooks/usePollKYCStatus.ts +43 -0
  147. package/src/exchange/swap/hooks/useProviderRates.test.ts +200 -0
  148. package/src/exchange/swap/hooks/useProviderRates.ts +130 -0
  149. package/src/exchange/swap/hooks/useReverseAccounts.test.ts +83 -0
  150. package/src/exchange/swap/hooks/useReverseAccounts.ts +56 -0
  151. package/src/exchange/swap/hooks/useSelectableCurrencies.test.ts +39 -0
  152. package/src/exchange/swap/hooks/useSelectableCurrencies.ts +26 -0
  153. package/src/exchange/swap/hooks/useSwapProviders.test.ts +113 -0
  154. package/src/exchange/swap/hooks/useSwapProviders.ts +57 -0
  155. package/src/exchange/swap/hooks/useSwapTransaction.test.ts +54 -0
  156. package/src/exchange/swap/hooks/useSwapTransaction.ts +170 -0
  157. package/src/exchange/swap/hooks/useToState.test.ts +53 -0
  158. package/src/exchange/swap/hooks/useToState.ts +86 -0
  159. package/src/exchange/swap/hooks/useUpdateMaxAmount.test.ts +132 -0
  160. package/src/exchange/swap/hooks/useUpdateMaxAmount.ts +67 -0
  161. package/src/exchange/swap/mock.ts +22 -3
  162. package/src/exchange/swap/types.ts +2 -1
  163. package/src/exchange/swap/utils/index.test.ts +224 -0
  164. package/src/exchange/swap/utils/index.ts +67 -0
  165. package/src/families/crypto_org/datasets/croeseid.ts +7 -9
  166. package/src/families/elrond/api/apiCalls.ts +3 -31
  167. package/src/families/elrond/api/sdk.ts +2 -2
  168. package/src/families/elrond/types.ts +2 -0
  169. package/src/families/tezos/bridge/js.ts +13 -0
  170. package/src/mock/account.ts +2 -2
@@ -0,0 +1,224 @@
1
+ import BigNumber from "bignumber.js";
2
+
3
+ import { pickExchangeRate, getAccountTuplesForCurrency } from "./index";
4
+ import { getMockExchangeRate } from "../mock";
5
+ import { genAccount } from "../../../mock/account";
6
+ import type {
7
+ Account,
8
+ CryptoCurrency,
9
+ SubAccount,
10
+ TokenCurrency,
11
+ } from "../../../types";
12
+ import { getCryptoCurrencyById } from "../../../currencies";
13
+ import { getTokenById } from "@ledgerhq/cryptoassets/lib/tokens";
14
+
15
+ describe("swap/utils/pickExchangeRate", () => {
16
+ test("calls the callback function with null when no exchange rates are passed", () => {
17
+ const setExchangeRate = jest.fn();
18
+ pickExchangeRate([], undefined, setExchangeRate);
19
+
20
+ expect(setExchangeRate).toHaveBeenCalledTimes(1);
21
+ expect(setExchangeRate).toHaveBeenCalledWith(null);
22
+ });
23
+
24
+ test("calls the callback function with null when no exchange rates are passed but there is an exchange rate", () => {
25
+ const setExchangeRate = jest.fn();
26
+ const exchangeRate = getMockExchangeRate({ provider: "wyre" });
27
+ pickExchangeRate([], exchangeRate, setExchangeRate);
28
+
29
+ expect(setExchangeRate).toHaveBeenCalledTimes(1);
30
+ expect(setExchangeRate).toHaveBeenCalledWith(null);
31
+ });
32
+
33
+ test("calls the callback function with the first exchange rate when the exchange passed isn't included in the list", () => {
34
+ const setExchangeRate = jest.fn();
35
+ const firstExchangeRate = getMockExchangeRate({
36
+ provider: "changelly",
37
+ tradeMethod: "fixed",
38
+ });
39
+ const exchangeRates = [
40
+ firstExchangeRate,
41
+ getMockExchangeRate({ provider: "changelly", tradeMethod: "float" }),
42
+ ];
43
+ const exchangeRate = getMockExchangeRate({ provider: "wyre" });
44
+
45
+ pickExchangeRate(exchangeRates, exchangeRate, setExchangeRate);
46
+
47
+ expect(setExchangeRate).toHaveBeenCalledTimes(1);
48
+ expect(setExchangeRate).toHaveBeenCalledWith(firstExchangeRate);
49
+ });
50
+
51
+ test("calls the callback function with the passed exchange rate when the exchange passed is included in the list", () => {
52
+ const setExchangeRate = jest.fn();
53
+ const exchangeRate = getMockExchangeRate({
54
+ provider: "changelly",
55
+ tradeMethod: "fixed",
56
+ });
57
+ const exchangeRates = [
58
+ getMockExchangeRate({ provider: "changelly", tradeMethod: "float" }),
59
+ exchangeRate,
60
+ ];
61
+
62
+ pickExchangeRate(exchangeRates, exchangeRate, setExchangeRate);
63
+
64
+ expect(setExchangeRate).toHaveBeenCalledTimes(1);
65
+ expect(setExchangeRate).toHaveBeenCalledWith(exchangeRate);
66
+ });
67
+ });
68
+
69
+ /* TODO: Refacto these two function and move them to mock/account.ts if needed */
70
+ function* accountGenerator(currency: CryptoCurrency): Generator<Account> {
71
+ let id = 0;
72
+ while (true) {
73
+ id += 1;
74
+ yield genAccount(`mocked-account-${id}`, { currency, operationsSize: 0 });
75
+ }
76
+ }
77
+ const getAccountCreator = (currencyId: string) => {
78
+ const generator = accountGenerator(getCryptoCurrencyById(currencyId));
79
+ return () => generator.next().value;
80
+ };
81
+
82
+ describe("swap/utils/getAccountTuplesForCurrency", () => {
83
+ const getEthAccount = getAccountCreator("ethereum");
84
+ const getBtcAccount = getAccountCreator("bitcoin");
85
+ const getPolkadotAccount = getAccountCreator("polkadot");
86
+ const getCosmosAccount = getAccountCreator("cosmos");
87
+
88
+ describe("CryptoCurrency", () => {
89
+ test("returns all accounts associated to the CryptoCurrency", () => {
90
+ const ethCurrency = getCryptoCurrencyById("ethereum");
91
+ const ethAccounts = [getEthAccount(), getEthAccount()];
92
+ const allAccounts: Account[] = [
93
+ getCosmosAccount(),
94
+ ...ethAccounts,
95
+ getBtcAccount(),
96
+ getPolkadotAccount(),
97
+ ];
98
+
99
+ const results = getAccountTuplesForCurrency(
100
+ ethCurrency,
101
+ allAccounts,
102
+ false
103
+ );
104
+
105
+ expect(results).toHaveLength(2);
106
+ results.forEach((result, index) => {
107
+ expect(result.account).toEqual(ethAccounts[index]);
108
+ expect(result.subAccount).toBeNull();
109
+ });
110
+ });
111
+
112
+ test("returns only associated accounts if they have a balance greater than 0 when the flag is passed", () => {
113
+ const ethCurrency = getCryptoCurrencyById("ethereum");
114
+ const richEthAccounts = [
115
+ { ...getEthAccount(), balance: new BigNumber(10) },
116
+ { ...getEthAccount(), balance: new BigNumber(10) },
117
+ ];
118
+ const poorEthAccounts = { ...getEthAccount(), balance: new BigNumber(0) };
119
+
120
+ const allAccounts: Account[] = [
121
+ getCosmosAccount(),
122
+ ...richEthAccounts,
123
+ poorEthAccounts,
124
+ getBtcAccount(),
125
+ getPolkadotAccount(),
126
+ ];
127
+
128
+ const results = getAccountTuplesForCurrency(
129
+ ethCurrency,
130
+ allAccounts,
131
+ true
132
+ );
133
+
134
+ expect(results).toHaveLength(richEthAccounts.length);
135
+ results.forEach((result, index) => {
136
+ expect(result.account).toEqual(richEthAccounts[index]);
137
+ expect(result.subAccount).toBeNull();
138
+ });
139
+ });
140
+
141
+ test("returns an empty array if the CryptoCurrency passed has no associated account", () => {
142
+ const ethCurrency = getCryptoCurrencyById("ethereum");
143
+ const allAccounts: Account[] = [
144
+ getCosmosAccount(),
145
+ getBtcAccount(),
146
+ getPolkadotAccount(),
147
+ ];
148
+
149
+ const results = getAccountTuplesForCurrency(
150
+ ethCurrency,
151
+ allAccounts,
152
+ false
153
+ );
154
+
155
+ expect(results).toHaveLength(0);
156
+ });
157
+ });
158
+
159
+ describe("TokenCurrency", () => {
160
+ const aaveToken = Object.freeze(getTokenById("ethereum/erc20/aave"));
161
+
162
+ test("returns correct parent accounts including a new subAccount when a TokenCurrency is provided", () => {
163
+ const ethAccounts = [
164
+ { ...getEthAccount(), subAccounts: [] },
165
+ { ...getEthAccount(), subAccounts: [] },
166
+ ];
167
+ const allAccounts: Account[] = [
168
+ getCosmosAccount(),
169
+ ...ethAccounts,
170
+ getBtcAccount(),
171
+ getPolkadotAccount(),
172
+ ];
173
+
174
+ const results = getAccountTuplesForCurrency(
175
+ aaveToken,
176
+ allAccounts,
177
+ false
178
+ );
179
+
180
+ expect(results).toHaveLength(ethAccounts.length);
181
+ results.forEach((result, index) => {
182
+ expect(result.account).toEqual(ethAccounts[index]);
183
+ expect(
184
+ (result.subAccount as SubAccount & { token: TokenCurrency }).token
185
+ ).toEqual(aaveToken);
186
+ });
187
+ });
188
+
189
+ test("returns correct parent accounts including already existing subAccounts when a TokenCurrency is provided", () => {
190
+ const ethAccounts = [{ ...getEthAccount(), subAccounts: [aaveToken] }];
191
+ const allAccounts: Account[] = [
192
+ getCosmosAccount(),
193
+ ...ethAccounts,
194
+ getBtcAccount(),
195
+ getPolkadotAccount(),
196
+ ];
197
+
198
+ const results = getAccountTuplesForCurrency(
199
+ aaveToken,
200
+ allAccounts,
201
+ false
202
+ );
203
+
204
+ expect(results).toHaveLength(ethAccounts.length);
205
+ results.forEach((result, index) => {
206
+ expect(result.account).toEqual(ethAccounts[index]);
207
+ expect(
208
+ (result.subAccount as SubAccount & { token: TokenCurrency }).token
209
+ ).toEqual(aaveToken);
210
+ });
211
+ });
212
+
213
+ test("returns an empty array when a TokenCurrency is provided but the accounts list is empty", () => {
214
+ const allAccounts: Account[] = [];
215
+
216
+ const results = getAccountTuplesForCurrency(
217
+ aaveToken,
218
+ allAccounts,
219
+ false
220
+ );
221
+ expect(results).toHaveLength(0);
222
+ });
223
+ });
224
+ });
@@ -0,0 +1,67 @@
1
+ import { CryptoCurrency, TokenCurrency } from "@ledgerhq/cryptoassets";
2
+ import { makeEmptyTokenAccount } from "../../../account";
3
+ import { Account, SubAccount } from "../../../types";
4
+ import type { ExchangeRate } from "../types";
5
+
6
+ export const KYC_STATUS = {
7
+ pending: "pending",
8
+ rejected: "closed",
9
+ approved: "approved",
10
+ };
11
+
12
+ export type KYCStatus = keyof typeof KYC_STATUS;
13
+
14
+ export const pickExchangeRate = (
15
+ exchangeRates: ExchangeRate[],
16
+ exchangeRate: ExchangeRate | null | undefined,
17
+ setExchangeRate: (rate?: ExchangeRate | null) => void
18
+ ): void => {
19
+ const hasRates = exchangeRates?.length > 0;
20
+ // If the user picked an exchange rate before, try to select the new one that matches.
21
+ // Otherwise pick the first one.
22
+ const rate =
23
+ hasRates &&
24
+ ((exchangeRate &&
25
+ exchangeRates.find(
26
+ ({ tradeMethod, provider }) =>
27
+ tradeMethod === exchangeRate.tradeMethod &&
28
+ provider === exchangeRate.provider
29
+ )) ||
30
+ exchangeRates[0]);
31
+ setExchangeRate(rate || null);
32
+ };
33
+
34
+ export type AccountTuple = {
35
+ account: Account | null | undefined;
36
+ subAccount: SubAccount | null | undefined;
37
+ };
38
+
39
+ export function getAccountTuplesForCurrency(
40
+ currency: CryptoCurrency | TokenCurrency,
41
+ allAccounts: Account[],
42
+ hideEmpty?: boolean
43
+ ): AccountTuple[] {
44
+ if (currency.type === "TokenCurrency") {
45
+ return allAccounts
46
+ .filter((account) => account.currency.id === currency.parentCurrency.id)
47
+ .map((account) => ({
48
+ account,
49
+ subAccount:
50
+ (account.subAccounts &&
51
+ account.subAccounts.find(
52
+ (subAcc: SubAccount) =>
53
+ subAcc.type === "TokenAccount" &&
54
+ subAcc.token.id === currency.id
55
+ )) ||
56
+ makeEmptyTokenAccount(account, currency),
57
+ }))
58
+ .filter((a) => (hideEmpty ? a.subAccount?.balance.gt(0) : true));
59
+ }
60
+ return allAccounts
61
+ .filter((account) => account.currency.id === currency.id)
62
+ .map((account) => ({
63
+ account,
64
+ subAccount: null,
65
+ }))
66
+ .filter((a) => (hideEmpty ? a.account?.balance.gt(0) : true));
67
+ }
@@ -1,24 +1,22 @@
1
+ // @flow
1
2
  import type { CurrenciesData } from "../../../types";
2
3
  import type { Transaction } from "../types";
3
4
 
4
5
  const dataset: CurrenciesData<Transaction> = {
5
6
  scanAccounts: [
6
7
  {
7
- // FIXME use better dataset
8
- // use a seed that we "froze" (aka we'll never use it again, but it contains many txs scenario)
9
- // then run:
10
- // ledger-live generateTestScanAccounts -c crypto_org_croeseid
11
- name: "crypto_org_croeseid seed gre (temporary)",
8
+ name: "crypto_org_croeseid seed 1",
12
9
  apdus: `
13
10
  => 5504000019047463726f2c0000808a010080000000800000000000000000
14
- <= 02ac96e7f6648484ef48f5cfcd540249c89e4dbfff0553dcf664612c79cfd194297463726f31363734706e6d6b6a6b6c663335703679336e7364357765703378367764656e363438326e79329000
11
+ <= 02bf9e382bf60d6ffaa982534b3e88014ee472bf091b7ff17167fe8978074349417463726f316b357538747a68386e73666d367571776c633438787a3467356a336d6d387878397a793579399000
15
12
  => 5504000019047463726f2c0000808a010080000000800000000000000000
16
- <= 02ac96e7f6648484ef48f5cfcd540249c89e4dbfff0553dcf664612c79cfd194297463726f31363734706e6d6b6a6b6c663335703679336e7364357765703378367764656e363438326e79329000
13
+ <= 02bf9e382bf60d6ffaa982534b3e88014ee472bf091b7ff17167fe8978074349417463726f316b357538747a68386e73666d367571776c633438787a3467356a336d6d387878397a793579399000
17
14
  => 5504000019047463726f2c0000808a010080010000800000000000000000
18
- <= 02c5546649f7c6f921eb36bd5fef4350cf3a8ff6d33308a4cdf59183cf079c08847463726f31757635307463396d30767534773067333376377937656a687434723636676a66656b347574769000
15
+ <= 03972a47c0cfce99f4428d078f6fa359a9e972a587d0952274f4d28023cbba3bae7463726f316568713371787873796a77766175367639716e327477763036757437386734763467336a6d709000
16
+ => 5504000019047463726f2c0000808a010080020000800000000000000000
17
+ <= 03635321f8045b86d903daedd02a07bc5cb188f1d498563d5f2cdb9392a0cb59c37463726f316b716677736875736734763767666163356a36716d6370346767786337346677676b343868399000
19
18
  `,
20
19
  },
21
20
  ],
22
21
  };
23
-
24
22
  export default dataset;
@@ -121,44 +121,16 @@ export default class ElrondApi {
121
121
  from = from + TRANSACTIONS_SIZE;
122
122
  }
123
123
 
124
- if (!allTransactions.length) {
125
- return allTransactions; //Account does not have any transactions
126
- }
127
-
128
- return Promise.all(
129
- allTransactions.map(async (transaction) => {
130
- const { blockHeight, blockHash } = await this.getConfirmedTransaction(
131
- transaction.txHash
132
- );
133
- return { ...transaction, blockHash, blockHeight };
134
- })
135
- );
124
+ return allTransactions;
136
125
  }
137
126
 
138
127
  async getBlockchainBlockHeight() {
139
128
  const {
140
- data: [{ nonce: blockHeight }],
129
+ data: [{ round: blockHeight }],
141
130
  } = await network({
142
131
  method: "GET",
143
- url: `${this.API_URL}/blocks?shard=${METACHAIN_SHARD}&fields=nonce`,
132
+ url: `${this.API_URL}/blocks?shard=${METACHAIN_SHARD}&fields=round`,
144
133
  });
145
134
  return blockHeight;
146
135
  }
147
-
148
- async getConfirmedTransaction(txHash: string) {
149
- const {
150
- data: {
151
- data: {
152
- transaction: { hyperblockNonce, blockHash },
153
- },
154
- },
155
- } = await network({
156
- method: "GET",
157
- url: `${this.API_URL}/transaction/${txHash}`,
158
- });
159
- return {
160
- blockHeight: hyperblockNonce,
161
- blockHash,
162
- };
163
- }
164
136
  }
@@ -71,8 +71,8 @@ function transactionToOperation(
71
71
  value: getOperationValue(transaction, addr),
72
72
  type,
73
73
  hash: transaction.txHash ?? "",
74
- blockHash: transaction.blockHash,
75
- blockHeight: transaction.blockHeight,
74
+ blockHash: transaction.miniBlockHash,
75
+ blockHeight: transaction.round,
76
76
  date: new Date(transaction.timestamp ? transaction.timestamp * 1000 : 0),
77
77
  extra: {},
78
78
  senders: [transaction.sender ?? ""],
@@ -36,6 +36,8 @@ export type Transaction = TransactionCommon & {
36
36
  nonce?: number;
37
37
  status?: string;
38
38
  fee?: BigNumber;
39
+ round?: number;
40
+ miniBlockHash?: string;
39
41
  };
40
42
 
41
43
  /**
@@ -104,6 +104,8 @@ const getTransactionStatus = async (
104
104
  if (t.mode === "send") {
105
105
  if (!errors.amount && t.amount.eq(0)) {
106
106
  errors.amount = new AmountRequired();
107
+ } else if (!errors.amount && t.amount.lt(0)) {
108
+ errors.amount = new NotEnoughBalance();
107
109
  } else if (t.amount.gt(0) && estimatedFees.times(10).gt(t.amount)) {
108
110
  warnings.feeTooHigh = new FeeTooHigh();
109
111
  }
@@ -199,6 +201,17 @@ const prepareTransaction = async (
199
201
  transaction.storageLimit = new BigNumber(out.storageLimit);
200
202
 
201
203
  if (transaction.useAllAmount) {
204
+ // Temporary fix, see https://gitlab.com/tezos/tezos/-/issues/1754
205
+ // we need to increase the gasLimit and fee returned by the estimation
206
+ const gasBuffer = 500;
207
+ const MINIMAL_FEE_PER_GAS_MUTEZ = 0.1;
208
+ const increasedFee = (gasBuffer: number, opSize: number) => {
209
+ return gasBuffer * MINIMAL_FEE_PER_GAS_MUTEZ + opSize;
210
+ };
211
+ transaction.fees = transaction.fees.plus(
212
+ increasedFee(gasBuffer, Number(out.opSize))
213
+ );
214
+ transaction.gasLimit = transaction.gasLimit.plus(gasBuffer);
202
215
  const s = await getTransactionStatus(account, transaction);
203
216
  transaction.amount = account.balance.minus(s.estimatedFees);
204
217
  }
@@ -293,7 +293,7 @@ type GenAccountOptions = {
293
293
  swapHistorySize?: number;
294
294
  };
295
295
 
296
- function genTokenAccount(
296
+ export function genTokenAccount(
297
297
  index: number,
298
298
  account: Account,
299
299
  token: TokenCurrency
@@ -340,7 +340,7 @@ export function genAccount(
340
340
  ): Account {
341
341
  const rng = new Prando(id);
342
342
  const currency = opts.currency || rng.nextArrayItem(currencies);
343
- const operationsSize = opts.operationsSize || rng.nextInt(1, 200);
343
+ const operationsSize = opts.operationsSize ?? rng.nextInt(1, 200);
344
344
  const swapHistorySize = opts.swapHistorySize || 0;
345
345
  const address = genAddress(currency, rng);
346
346
  const derivationPath = runDerivationScheme(