@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.
- package/lib/env.js +1 -1
- package/lib/env.js.map +1 -1
- package/lib/exchange/swap/getExchangeRates.d.ts.map +1 -1
- package/lib/exchange/swap/getExchangeRates.js +9 -8
- package/lib/exchange/swap/getExchangeRates.js.map +1 -1
- package/lib/exchange/swap/hooks/index.d.ts +11 -0
- package/lib/exchange/swap/hooks/index.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/index.js +23 -0
- package/lib/exchange/swap/hooks/index.js.map +1 -0
- package/lib/exchange/swap/hooks/useFromState.d.ts +15 -0
- package/lib/exchange/swap/hooks/useFromState.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useFromState.js +67 -0
- package/lib/exchange/swap/hooks/useFromState.js.map +1 -0
- package/lib/exchange/swap/hooks/useFromState.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useFromState.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useFromState.test.js +141 -0
- package/lib/exchange/swap/hooks/useFromState.test.js.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.d.ts +5 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.js +37 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.js.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js +185 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.d.ts +3 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.js +17 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.js.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.js +73 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.js.map +1 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.d.ts +12 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.js +105 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.js.map +1 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.test.js +78 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useProviderRates.d.ts +20 -0
- package/lib/exchange/swap/hooks/useProviderRates.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useProviderRates.js +174 -0
- package/lib/exchange/swap/hooks/useProviderRates.js.map +1 -0
- package/lib/exchange/swap/hooks/useProviderRates.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useProviderRates.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useProviderRates.test.js +261 -0
- package/lib/exchange/swap/hooks/useProviderRates.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.d.ts +15 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.js +35 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.js.map +1 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.test.js +79 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.d.ts +5 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.js +43 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.js.map +1 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.test.js +32 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useSwapProviders.d.ts +14 -0
- package/lib/exchange/swap/hooks/useSwapProviders.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useSwapProviders.js +104 -0
- package/lib/exchange/swap/hooks/useSwapProviders.js.map +1 -0
- package/lib/exchange/swap/hooks/useSwapProviders.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useSwapProviders.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useSwapProviders.test.js +174 -0
- package/lib/exchange/swap/hooks/useSwapProviders.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.d.ts +53 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.js +109 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.js.map +1 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.test.js +50 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useToState.d.ts +12 -0
- package/lib/exchange/swap/hooks/useToState.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useToState.js +73 -0
- package/lib/exchange/swap/hooks/useToState.js.map +1 -0
- package/lib/exchange/swap/hooks/useToState.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useToState.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useToState.test.js +107 -0
- package/lib/exchange/swap/hooks/useToState.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts +15 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.js +106 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.js.map +1 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js +217 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js.map +1 -0
- package/lib/exchange/swap/mock.d.ts +6 -2
- package/lib/exchange/swap/mock.d.ts.map +1 -1
- package/lib/exchange/swap/mock.js +21 -6
- package/lib/exchange/swap/mock.js.map +1 -1
- package/lib/exchange/swap/types.d.ts +1 -1
- package/lib/exchange/swap/types.d.ts.map +1 -1
- package/lib/exchange/swap/utils/index.d.ts +16 -0
- package/lib/exchange/swap/utils/index.d.ts.map +1 -0
- package/lib/exchange/swap/utils/index.js +49 -0
- package/lib/exchange/swap/utils/index.js.map +1 -0
- package/lib/exchange/swap/utils/index.test.d.ts +2 -0
- package/lib/exchange/swap/utils/index.test.d.ts.map +1 -0
- package/lib/exchange/swap/utils/index.test.js +238 -0
- package/lib/exchange/swap/utils/index.test.js.map +1 -0
- package/lib/families/crypto_org/datasets/croeseid.d.ts.map +1 -1
- package/lib/families/crypto_org/datasets/croeseid.js +2 -6
- package/lib/families/crypto_org/datasets/croeseid.js.map +1 -1
- package/lib/families/elrond/api/apiCalls.d.ts +0 -4
- package/lib/families/elrond/api/apiCalls.d.ts.map +1 -1
- package/lib/families/elrond/api/apiCalls.js +3 -37
- package/lib/families/elrond/api/apiCalls.js.map +1 -1
- package/lib/families/elrond/api/sdk.js +2 -2
- package/lib/families/elrond/api/sdk.js.map +1 -1
- package/lib/families/elrond/js-transaction.d.ts +2 -0
- package/lib/families/elrond/js-transaction.d.ts.map +1 -1
- package/lib/families/elrond/types.d.ts +2 -0
- package/lib/families/elrond/types.d.ts.map +1 -1
- package/lib/families/elrond/types.js.map +1 -1
- package/lib/families/tezos/bridge/js.d.ts.map +1 -1
- package/lib/families/tezos/bridge/js.js +11 -1
- package/lib/families/tezos/bridge/js.js.map +1 -1
- package/lib/mock/account.d.ts +2 -1
- package/lib/mock/account.d.ts.map +1 -1
- package/lib/mock/account.js +4 -2
- package/lib/mock/account.js.map +1 -1
- package/package.json +15 -15
- package/src/__tests__/__snapshots__/all.libcore.ts.snap +10 -10
- package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +30 -15
- package/src/env.ts +1 -1
- package/src/exchange/swap/getExchangeRates.ts +8 -5
- package/src/exchange/swap/hooks/index.ts +10 -0
- package/src/exchange/swap/hooks/useFromState.test.ts +134 -0
- package/src/exchange/swap/hooks/useFromState.ts +84 -0
- package/src/exchange/swap/hooks/usePickDefaultAccount.test.ts +167 -0
- package/src/exchange/swap/hooks/usePickDefaultAccount.ts +47 -0
- package/src/exchange/swap/hooks/usePickDefaultCurrency.test.ts +107 -0
- package/src/exchange/swap/hooks/usePickDefaultCurrency.ts +20 -0
- package/src/exchange/swap/hooks/usePollKYCStatus.test.ts +89 -0
- package/src/exchange/swap/hooks/usePollKYCStatus.ts +43 -0
- package/src/exchange/swap/hooks/useProviderRates.test.ts +200 -0
- package/src/exchange/swap/hooks/useProviderRates.ts +130 -0
- package/src/exchange/swap/hooks/useReverseAccounts.test.ts +83 -0
- package/src/exchange/swap/hooks/useReverseAccounts.ts +56 -0
- package/src/exchange/swap/hooks/useSelectableCurrencies.test.ts +39 -0
- package/src/exchange/swap/hooks/useSelectableCurrencies.ts +26 -0
- package/src/exchange/swap/hooks/useSwapProviders.test.ts +113 -0
- package/src/exchange/swap/hooks/useSwapProviders.ts +57 -0
- package/src/exchange/swap/hooks/useSwapTransaction.test.ts +54 -0
- package/src/exchange/swap/hooks/useSwapTransaction.ts +170 -0
- package/src/exchange/swap/hooks/useToState.test.ts +53 -0
- package/src/exchange/swap/hooks/useToState.ts +86 -0
- package/src/exchange/swap/hooks/useUpdateMaxAmount.test.ts +132 -0
- package/src/exchange/swap/hooks/useUpdateMaxAmount.ts +67 -0
- package/src/exchange/swap/mock.ts +22 -3
- package/src/exchange/swap/types.ts +2 -1
- package/src/exchange/swap/utils/index.test.ts +224 -0
- package/src/exchange/swap/utils/index.ts +67 -0
- package/src/families/crypto_org/datasets/croeseid.ts +7 -9
- package/src/families/elrond/api/apiCalls.ts +3 -31
- package/src/families/elrond/api/sdk.ts +2 -2
- package/src/families/elrond/types.ts +2 -0
- package/src/families/tezos/bridge/js.ts +13 -0
- 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
|
-
|
|
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
|
-
<=
|
|
11
|
+
<= 02bf9e382bf60d6ffaa982534b3e88014ee472bf091b7ff17167fe8978074349417463726f316b357538747a68386e73666d367571776c633438787a3467356a336d6d387878397a793579399000
|
|
15
12
|
=> 5504000019047463726f2c0000808a010080000000800000000000000000
|
|
16
|
-
<=
|
|
13
|
+
<= 02bf9e382bf60d6ffaa982534b3e88014ee472bf091b7ff17167fe8978074349417463726f316b357538747a68386e73666d367571776c633438787a3467356a336d6d387878397a793579399000
|
|
17
14
|
=> 5504000019047463726f2c0000808a010080010000800000000000000000
|
|
18
|
-
<=
|
|
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
|
-
|
|
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: [{
|
|
129
|
+
data: [{ round: blockHeight }],
|
|
141
130
|
} = await network({
|
|
142
131
|
method: "GET",
|
|
143
|
-
url: `${this.API_URL}/blocks?shard=${METACHAIN_SHARD}&fields=
|
|
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.
|
|
75
|
-
blockHeight: transaction.
|
|
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 ?? ""],
|
|
@@ -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
|
}
|
package/src/mock/account.ts
CHANGED
|
@@ -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
|
|
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(
|