@ledgerhq/live-common 21.7.0 → 21.7.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/src/env.ts CHANGED
@@ -366,6 +366,11 @@ const envDefinitions = {
366
366
  parser: stringParser,
367
367
  desc: "switch the app into a MOCK mode for test purpose, the value will be used as a seed for the rng. Avoid falsy values.",
368
368
  },
369
+ MOCK_SWAP_KYC: {
370
+ def: "",
371
+ parser: stringParser,
372
+ desc: "mock the server response for the exchange KYC check, options are 'open', 'pending', 'closed' or 'approved'.",
373
+ },
369
374
  OPERATION_ADDRESSES_LIMIT: {
370
375
  def: 100,
371
376
  parser: intParser,
@@ -2,11 +2,15 @@ import network from "../../network";
2
2
  import { getSwapAPIBaseURL } from "./";
3
3
  import type { GetKYCStatus } from "./types";
4
4
  import { SwapCheckKYCStatusFailed } from "../../errors";
5
+ import { getEnv } from "../../env";
6
+ import { mockGetKYCStatus } from "./mock";
5
7
  export const getKYCStatus: GetKYCStatus = async (
6
8
  provider: string,
7
9
  id: string
8
10
  ) => {
9
- //if (getEnv("MOCK")) return mockGetKYCStatus(id); // TODO implement
11
+ const mockedStatus = getEnv("MOCK_SWAP_KYC");
12
+ if (mockedStatus) return mockGetKYCStatus(id, mockedStatus);
13
+
10
14
  const res = await network({
11
15
  method: "GET",
12
16
  url: `${getSwapAPIBaseURL()}/provider/${provider}/user/${id}`,
@@ -4,7 +4,9 @@ import type {
4
4
  ExchangeRate,
5
5
  GetMultipleStatus,
6
6
  GetProviders,
7
+ KYCStatus,
7
8
  SwapRequestEvent,
9
+ ValidKYCStatus,
8
10
  } from "./types";
9
11
  import { getAccountUnit } from "../../account";
10
12
  import type { Transaction, TokenCurrency, CryptoCurrency } from "../../types";
@@ -176,3 +178,12 @@ export const mockGetStatus: GetMultipleStatus = async (statusList) => {
176
178
  await new Promise((r) => setTimeout(r, 800));
177
179
  return statusList.map((s) => ({ ...s, status: "finished" }));
178
180
  };
181
+
182
+ export const mockGetKYCStatus = async (
183
+ id: string,
184
+ status: ValidKYCStatus
185
+ ): Promise<KYCStatus> => {
186
+ //Fake delay to show the pending state in the UI
187
+ await new Promise((r) => setTimeout(r, 2000));
188
+ return { id, status };
189
+ };
@@ -283,7 +283,7 @@ const bitcoinTestnet: AppSpec<Transaction> = {
283
283
  targetAccountSize: 8,
284
284
  minimalAmount: parseCurrencyUnit(
285
285
  getCryptoCurrencyById("bitcoin_testnet").units[0],
286
- "0.001"
286
+ "0.0001"
287
287
  ),
288
288
  }),
289
289
  };
@@ -5,101 +5,106 @@ import {
5
5
  NotEnoughBalance,
6
6
  InvalidAddress,
7
7
  } from "@ledgerhq/errors";
8
- import type { DatasetTest } from "../../types";
8
+ import type { DatasetTest, CurrenciesData } from "../../types";
9
9
  import type { Transaction } from "./types";
10
10
  const TEST_ADDRESS =
11
11
  "erd1vgfp3g7azqjx4wsmtt7067m0l62v3psmqzr24j6xvywj2tlz0gesvyzsq2";
12
- const dataset: DatasetTest<Transaction> = {
13
- implementations: ["js"],
14
- currencies: {
15
- elrond: {
16
- scanAccounts: [
12
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
13
+ const elrond: CurrenciesData<Transaction> = {
14
+ scanAccounts: [
15
+ {
16
+ name: "elrond seed 1",
17
+ apdus: `
18
+ => ed030000080000000000000000
19
+ <= 3e6572643176676670336737617a716a783477736d7474373036376d306c3632763370736d717a7232346a36787679776a32746c7a3067657376797a7371329000
20
+ => ed030000080000000080000000
21
+ <= 3e6572643176676670336737617a716a783477736d7474373036376d306c3632763370736d717a7232346a36787679776a32746c7a3067657376797a7371329000
22
+ => ed030000080000000080000001
23
+ <= 3e65726431706d33676a65326c6d643576796c6463767579366a7078676465347261706a70756a76756a6b65653661376a77327a6d6834747172653739367a9000
24
+ `,
25
+ },
26
+ ],
27
+ accounts: [
28
+ {
29
+ raw: {
30
+ id: `js:2:elrond:${TEST_ADDRESS}:`,
31
+ seedIdentifier: `${TEST_ADDRESS}`,
32
+ name: "Elrond 1",
33
+ derivationMode: "",
34
+ index: 0,
35
+ freshAddress: `${TEST_ADDRESS}`,
36
+ freshAddressPath: "44'/508'/0'/0/0'",
37
+ freshAddresses: [],
38
+ blockHeight: 0,
39
+ operations: [],
40
+ pendingOperations: [],
41
+ currencyId: "elrond",
42
+ unitMagnitude: 10,
43
+ lastSyncDate: "",
44
+ balance: "299569965",
45
+ },
46
+ transactions: [
17
47
  {
18
- name: "elrond seed 1",
19
- apdus: `
20
- => ed030000080000000000000000
21
- <= 3e6572643176676670336737617a716a783477736d7474373036376d306c3632763370736d717a7232346a36787679776a32746c7a3067657376797a7371329000
22
- => ed030000080000000080000000
23
- <= 3e6572643176676670336737617a716a783477736d7474373036376d306c3632763370736d717a7232346a36787679776a32746c7a3067657376797a7371329000
24
- => ed030000080000000080000001
25
- <= 3e65726431706d33676a65326c6d643576796c6463767579366a7078676465347261706a70756a76756a6b65653661376a77327a6d6834747172653739367a9000
26
- `,
48
+ name: "recipient and sender must not be the same",
49
+ transaction: fromTransactionRaw({
50
+ family: "elrond",
51
+ recipient: `${TEST_ADDRESS}`,
52
+ amount: "100000000",
53
+ mode: "send",
54
+ fees: null,
55
+ }),
56
+ expectedStatus: {
57
+ amount: new BigNumber("100000000"),
58
+ errors: {
59
+ recipient: new InvalidAddressBecauseDestinationIsAlsoSource(),
60
+ },
61
+ warnings: {},
62
+ },
27
63
  },
28
- ],
29
- accounts: [
30
64
  {
31
- raw: {
32
- id: `js:2:elrond:${TEST_ADDRESS}:`,
33
- seedIdentifier: `${TEST_ADDRESS}`,
34
- name: "Elrond 1",
35
- derivationMode: "",
36
- index: 0,
37
- freshAddress: `${TEST_ADDRESS}`,
38
- freshAddressPath: "44'/508'/0'/0/0'",
39
- freshAddresses: [],
40
- blockHeight: 0,
41
- operations: [],
42
- pendingOperations: [],
43
- currencyId: "elrond",
44
- unitMagnitude: 10,
45
- lastSyncDate: "",
46
- balance: "299569965",
47
- },
48
- transactions: [
49
- {
50
- name: "recipient and sender must not be the same",
51
- transaction: fromTransactionRaw({
52
- family: "elrond",
53
- recipient: `${TEST_ADDRESS}`,
54
- amount: "100000000",
55
- mode: "send",
56
- fees: null,
57
- }),
58
- expectedStatus: {
59
- amount: new BigNumber("100000000"),
60
- errors: {
61
- recipient: new InvalidAddressBecauseDestinationIsAlsoSource(),
62
- },
63
- warnings: {},
64
- },
65
- },
66
- {
67
- name: "Not a valid address",
68
- transaction: fromTransactionRaw({
69
- family: "elrond",
70
- recipient: "elrondinv",
71
- amount: "100000000",
72
- mode: "send",
73
- fees: null,
74
- }),
75
- expectedStatus: {
76
- errors: {
77
- recipient: new InvalidAddress(),
78
- },
79
- warnings: {},
80
- },
65
+ name: "Not a valid address",
66
+ transaction: fromTransactionRaw({
67
+ family: "elrond",
68
+ recipient: "elrondinv",
69
+ amount: "100000000",
70
+ mode: "send",
71
+ fees: null,
72
+ }),
73
+ expectedStatus: {
74
+ errors: {
75
+ recipient: new InvalidAddress(),
81
76
  },
82
- {
83
- name: "Not enough balance",
84
- transaction: fromTransactionRaw({
85
- family: "elrond",
86
- recipient:
87
- "erd1frj909pfums4m8aza596595l9pl56crwdj077vs2aqcw6ynl28wsfkw9rd",
88
- amount: "1000000000000000000000000",
89
- mode: "send",
90
- fees: null,
91
- }),
92
- expectedStatus: {
93
- errors: {
94
- amount: new NotEnoughBalance(),
95
- },
96
- warnings: {},
97
- },
77
+ warnings: {},
78
+ },
79
+ },
80
+ {
81
+ name: "Not enough balance",
82
+ transaction: fromTransactionRaw({
83
+ family: "elrond",
84
+ recipient:
85
+ "erd1frj909pfums4m8aza596595l9pl56crwdj077vs2aqcw6ynl28wsfkw9rd",
86
+ amount: "1000000000000000000000000",
87
+ mode: "send",
88
+ fees: null,
89
+ }),
90
+ expectedStatus: {
91
+ errors: {
92
+ amount: new NotEnoughBalance(),
98
93
  },
99
- ],
94
+ warnings: {},
95
+ },
100
96
  },
101
97
  ],
102
98
  },
99
+ ],
100
+ };
101
+
102
+ const dataset: DatasetTest<Transaction> = {
103
+ implementations: ["js"],
104
+ currencies: {
105
+ // FIXME: temporarily disabled until a solution is found for an inconstency between two sync
106
+ // elrond,
103
107
  },
104
108
  };
109
+
105
110
  export default dataset;
@@ -8,7 +8,7 @@ import {
8
8
  } from "@ledgerhq/errors";
9
9
  import { fromTransactionRaw } from "./transaction";
10
10
  import type { Transaction } from "./types";
11
- // import ethereumScanAccounts1 from "./datasets/ethereum.scanAccounts.1";
11
+ import ethereumScanAccounts1 from "./datasets/ethereum.scanAccounts.1";
12
12
  import ethereum_classic from "./datasets/ethereum_classic";
13
13
  import { syncAccount } from "../../__tests__/test-helpers/bridge";
14
14
  export const ethereum1: AccountRaw = {
@@ -39,8 +39,7 @@ const dataset: DatasetTest<Transaction> = {
39
39
  implementations: ["mock", "js"],
40
40
  currencies: {
41
41
  ethereum: {
42
- scanAccounts: [], // FIXME https://ledgerhq.atlassian.net/browse/LL-6445
43
- // scanAccounts: [ethereumScanAccounts1],
42
+ scanAccounts: [ethereumScanAccounts1],
44
43
  accounts: [
45
44
  {
46
45
  implementations: ["js"],