@ledgerhq/live-common 24.0.0-next.0 → 24.0.0-next.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 (110) hide show
  1. package/lib/env.d.ts +16 -6
  2. package/lib/env.d.ts.map +1 -1
  3. package/lib/env.js +11 -1
  4. package/lib/env.js.map +1 -1
  5. package/lib/env.react.d.ts +1 -1
  6. package/lib/env.react.d.ts.map +1 -1
  7. package/lib/errors.d.ts +0 -3
  8. package/lib/errors.d.ts.map +1 -1
  9. package/lib/errors.js +2 -3
  10. package/lib/errors.js.map +1 -1
  11. package/lib/exchange/index.d.ts +5 -0
  12. package/lib/exchange/index.d.ts.map +1 -1
  13. package/lib/exchange/index.js.map +1 -1
  14. package/lib/exchange/swap/checkQuote.d.ts +4 -0
  15. package/lib/exchange/swap/checkQuote.d.ts.map +1 -0
  16. package/lib/exchange/swap/checkQuote.js +80 -0
  17. package/lib/exchange/swap/checkQuote.js.map +1 -0
  18. package/lib/exchange/swap/checkQuote.test.d.ts +2 -0
  19. package/lib/exchange/swap/checkQuote.test.d.ts.map +1 -0
  20. package/lib/exchange/swap/checkQuote.test.js +103 -0
  21. package/lib/exchange/swap/checkQuote.test.js.map +1 -0
  22. package/lib/exchange/swap/completeExchange.d.ts.map +1 -1
  23. package/lib/exchange/swap/completeExchange.js +9 -9
  24. package/lib/exchange/swap/completeExchange.js.map +1 -1
  25. package/lib/exchange/swap/getExchangeRates.d.ts.map +1 -1
  26. package/lib/exchange/swap/getExchangeRates.js +3 -1
  27. package/lib/exchange/swap/getExchangeRates.js.map +1 -1
  28. package/lib/exchange/swap/getProviders.d.ts.map +1 -1
  29. package/lib/exchange/swap/getProviders.js +10 -4
  30. package/lib/exchange/swap/getProviders.js.map +1 -1
  31. package/lib/exchange/swap/getStatus.d.ts +1 -3
  32. package/lib/exchange/swap/getStatus.d.ts.map +1 -1
  33. package/lib/exchange/swap/getStatus.js +2 -30
  34. package/lib/exchange/swap/getStatus.js.map +1 -1
  35. package/lib/exchange/swap/hooks/useProviderRates.d.ts +3 -4
  36. package/lib/exchange/swap/hooks/useProviderRates.d.ts.map +1 -1
  37. package/lib/exchange/swap/hooks/useProviderRates.js +35 -5
  38. package/lib/exchange/swap/hooks/useProviderRates.js.map +1 -1
  39. package/lib/exchange/swap/hooks/useProviderRates.test.js +106 -1
  40. package/lib/exchange/swap/hooks/useProviderRates.test.js.map +1 -1
  41. package/lib/exchange/swap/hooks/useSwapTransaction.d.ts +5 -4
  42. package/lib/exchange/swap/hooks/useSwapTransaction.d.ts.map +1 -1
  43. package/lib/exchange/swap/hooks/useSwapTransaction.js +6 -6
  44. package/lib/exchange/swap/hooks/useSwapTransaction.js.map +1 -1
  45. package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts +4 -3
  46. package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts.map +1 -1
  47. package/lib/exchange/swap/hooks/useUpdateMaxAmount.js +8 -5
  48. package/lib/exchange/swap/hooks/useUpdateMaxAmount.js.map +1 -1
  49. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js +35 -4
  50. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js.map +1 -1
  51. package/lib/exchange/swap/index.d.ts +10 -8
  52. package/lib/exchange/swap/index.d.ts.map +1 -1
  53. package/lib/exchange/swap/index.js +43 -18
  54. package/lib/exchange/swap/index.js.map +1 -1
  55. package/lib/exchange/swap/index.test.d.ts +2 -0
  56. package/lib/exchange/swap/index.test.d.ts.map +1 -0
  57. package/lib/exchange/swap/index.test.js +30 -0
  58. package/lib/exchange/swap/index.test.js.map +1 -0
  59. package/lib/exchange/swap/initSwap.d.ts +1 -1
  60. package/lib/exchange/swap/initSwap.d.ts.map +1 -1
  61. package/lib/exchange/swap/initSwap.js +30 -25
  62. package/lib/exchange/swap/initSwap.js.map +1 -1
  63. package/lib/exchange/swap/mock.d.ts +5 -2
  64. package/lib/exchange/swap/mock.d.ts.map +1 -1
  65. package/lib/exchange/swap/mock.js +127 -6
  66. package/lib/exchange/swap/mock.js.map +1 -1
  67. package/lib/exchange/swap/postSwapState.d.ts +4 -0
  68. package/lib/exchange/swap/postSwapState.d.ts.map +1 -0
  69. package/lib/exchange/swap/postSwapState.js +121 -0
  70. package/lib/exchange/swap/postSwapState.js.map +1 -0
  71. package/lib/exchange/swap/types.d.ts +30 -2
  72. package/lib/exchange/swap/types.d.ts.map +1 -1
  73. package/lib/exchange/swap/updateAccountSwapStatus.d.ts.map +1 -1
  74. package/lib/exchange/swap/updateAccountSwapStatus.js +2 -2
  75. package/lib/exchange/swap/updateAccountSwapStatus.js.map +1 -1
  76. package/lib/exchange/swap/utils/index.d.ts +19 -2
  77. package/lib/exchange/swap/utils/index.d.ts.map +1 -1
  78. package/lib/exchange/swap/utils/index.js +96 -20
  79. package/lib/exchange/swap/utils/index.js.map +1 -1
  80. package/lib/exchange/swap/utils/index.test.js +95 -48
  81. package/lib/exchange/swap/utils/index.test.js.map +1 -1
  82. package/lib/hw/actions/initSwap.d.ts +4 -3
  83. package/lib/hw/actions/initSwap.d.ts.map +1 -1
  84. package/lib/hw/actions/initSwap.js +7 -5
  85. package/lib/hw/actions/initSwap.js.map +1 -1
  86. package/package.json +4 -1
  87. package/src/env.ts +12 -2
  88. package/src/errors.ts +0 -1
  89. package/src/exchange/index.ts +7 -0
  90. package/src/exchange/swap/checkQuote.test.ts +53 -0
  91. package/src/exchange/swap/checkQuote.ts +34 -0
  92. package/src/exchange/swap/completeExchange.ts +9 -11
  93. package/src/exchange/swap/getExchangeRates.ts +5 -3
  94. package/src/exchange/swap/getProviders.ts +12 -4
  95. package/src/exchange/swap/getStatus.ts +2 -12
  96. package/src/exchange/swap/hooks/useProviderRates.test.ts +103 -1
  97. package/src/exchange/swap/hooks/useProviderRates.ts +57 -9
  98. package/src/exchange/swap/hooks/useSwapTransaction.ts +14 -13
  99. package/src/exchange/swap/hooks/useUpdateMaxAmount.test.ts +31 -4
  100. package/src/exchange/swap/hooks/useUpdateMaxAmount.ts +13 -7
  101. package/src/exchange/swap/index.test.ts +36 -0
  102. package/src/exchange/swap/index.ts +51 -30
  103. package/src/exchange/swap/initSwap.ts +54 -40
  104. package/src/exchange/swap/mock.ts +128 -13
  105. package/src/exchange/swap/postSwapState.ts +61 -0
  106. package/src/exchange/swap/types.ts +68 -5
  107. package/src/exchange/swap/updateAccountSwapStatus.ts +4 -4
  108. package/src/exchange/swap/utils/index.test.ts +127 -63
  109. package/src/exchange/swap/utils/index.ts +128 -23
  110. package/src/hw/actions/initSwap.ts +20 -9
@@ -1,11 +1,11 @@
1
+ import type { Account, SubAccount } from "../../types";
2
+ import { isSwapOperationPending } from "./";
1
3
  import { getMultipleStatus } from "./getStatus";
2
- import type { SubAccount, Account } from "../../types";
3
4
  import type {
4
- UpdateAccountSwapStatus,
5
5
  SwapOperation,
6
6
  SwapStatusRequest,
7
+ UpdateAccountSwapStatus,
7
8
  } from "./types";
8
- import { operationStatusList } from "./";
9
9
 
10
10
  const maybeGetUpdatedSwapHistory = async (
11
11
  swapHistory: SwapOperation[] | null | undefined
@@ -16,7 +16,7 @@ const maybeGetUpdatedSwapHistory = async (
16
16
 
17
17
  if (swapHistory) {
18
18
  for (const { provider, swapId, status } of swapHistory) {
19
- if (operationStatusList.pending.includes(status)) {
19
+ if (isSwapOperationPending(status)) {
20
20
  pendingSwapIds.push({
21
21
  provider,
22
22
  swapId,
@@ -1,11 +1,6 @@
1
+ import { getTokenById } from "@ledgerhq/cryptoassets/lib/tokens";
1
2
  import BigNumber from "bignumber.js";
2
-
3
- import {
4
- pickExchangeRate,
5
- getAccountTuplesForCurrency,
6
- getAvailableAccountsById,
7
- } from "./index";
8
- import { getMockExchangeRate } from "../mock";
3
+ import { getCryptoCurrencyById } from "../../../currencies";
9
4
  import { genAccount } from "../../../mock/account";
10
5
  import type {
11
6
  Account,
@@ -13,62 +8,14 @@ import type {
13
8
  SubAccount,
14
9
  TokenCurrency,
15
10
  } from "../../../types";
16
- import { getCryptoCurrencyById } from "../../../currencies";
17
- import { getTokenById } from "@ledgerhq/cryptoassets/lib/tokens";
18
-
19
- describe("swap/utils/pickExchangeRate", () => {
20
- test("calls the callback function with null when no exchange rates are passed", () => {
21
- const setExchangeRate = jest.fn();
22
- pickExchangeRate([], undefined, setExchangeRate);
23
-
24
- expect(setExchangeRate).toHaveBeenCalledTimes(1);
25
- expect(setExchangeRate).toHaveBeenCalledWith(null);
26
- });
27
-
28
- test("calls the callback function with null when no exchange rates are passed but there is an exchange rate", () => {
29
- const setExchangeRate = jest.fn();
30
- const exchangeRate = getMockExchangeRate({ provider: "wyre" });
31
- pickExchangeRate([], exchangeRate, setExchangeRate);
32
-
33
- expect(setExchangeRate).toHaveBeenCalledTimes(1);
34
- expect(setExchangeRate).toHaveBeenCalledWith(null);
35
- });
36
-
37
- test("calls the callback function with the first exchange rate when the exchange passed isn't included in the list", () => {
38
- const setExchangeRate = jest.fn();
39
- const firstExchangeRate = getMockExchangeRate({
40
- provider: "changelly",
41
- tradeMethod: "fixed",
42
- });
43
- const exchangeRates = [
44
- firstExchangeRate,
45
- getMockExchangeRate({ provider: "changelly", tradeMethod: "float" }),
46
- ];
47
- const exchangeRate = getMockExchangeRate({ provider: "wyre" });
48
-
49
- pickExchangeRate(exchangeRates, exchangeRate, setExchangeRate);
50
-
51
- expect(setExchangeRate).toHaveBeenCalledTimes(1);
52
- expect(setExchangeRate).toHaveBeenCalledWith(firstExchangeRate);
53
- });
54
-
55
- test("calls the callback function with the passed exchange rate when the exchange passed is included in the list", () => {
56
- const setExchangeRate = jest.fn();
57
- const exchangeRate = getMockExchangeRate({
58
- provider: "changelly",
59
- tradeMethod: "fixed",
60
- });
61
- const exchangeRates = [
62
- getMockExchangeRate({ provider: "changelly", tradeMethod: "float" }),
63
- exchangeRate,
64
- ];
65
-
66
- pickExchangeRate(exchangeRates, exchangeRate, setExchangeRate);
67
-
68
- expect(setExchangeRate).toHaveBeenCalledTimes(1);
69
- expect(setExchangeRate).toHaveBeenCalledWith(exchangeRate);
70
- });
71
- });
11
+ import {
12
+ getAccountTuplesForCurrency,
13
+ getAvailableAccountsById,
14
+ getProviderName,
15
+ KYCStatus,
16
+ shouldShowKYCBanner,
17
+ shouldShowLoginBanner,
18
+ } from "./index";
72
19
 
73
20
  /* TODO: Refacto these two function and move them to mock/account.ts if needed */
74
21
  function* accountGenerator(currency: CryptoCurrency): Generator<Account> {
@@ -265,3 +212,120 @@ describe("swap/utils/getAvailableAccountsById", () => {
265
212
  );
266
213
  });
267
214
  });
215
+
216
+ describe("swap/utils/shouldShowLoginBanner", () => {
217
+ test("should not display Login banner if no provider is specified", () => {
218
+ const result = shouldShowLoginBanner({
219
+ provider: undefined,
220
+ token: "token",
221
+ });
222
+
223
+ expect(result).toBe(false);
224
+ });
225
+
226
+ ["changelly", "wyre"].forEach((provider) => {
227
+ test(`should not display Login banner for ${provider}`, () => {
228
+ const result = shouldShowLoginBanner({
229
+ provider,
230
+ token: "token",
231
+ });
232
+
233
+ expect(result).toBe(false);
234
+ });
235
+ });
236
+
237
+ ["ftx", "ftxus"].forEach((provider) => {
238
+ describe(`${provider.toUpperCase()}`, () => {
239
+ test("should display Login banner if no token is provided", () => {
240
+ const result = shouldShowLoginBanner({
241
+ provider: provider,
242
+ token: undefined,
243
+ });
244
+
245
+ expect(result).toBe(true);
246
+ });
247
+
248
+ test("should display Login banner if token is expired", () => {
249
+ /**
250
+ * TODO: add test by mocking `isJwtExpired`
251
+ */
252
+ });
253
+
254
+ test("should not display Login banner if token is not expired", () => {
255
+ /**
256
+ * TODO: add test by mocking `isJwtExpired`
257
+ */
258
+ });
259
+ });
260
+ });
261
+ });
262
+
263
+ describe("swap/utils/shouldShowKYCBanner", () => {
264
+ test("should not display KYC banner if no provider is specified", () => {
265
+ const result = shouldShowKYCBanner({
266
+ provider: undefined,
267
+ kycStatus: "rejected",
268
+ });
269
+
270
+ expect(result).toBe(false);
271
+ });
272
+
273
+ test("should not display KYC banner if provider does not require KYC", () => {
274
+ const result = shouldShowKYCBanner({
275
+ provider: "changelly",
276
+ kycStatus: "rejected",
277
+ });
278
+
279
+ expect(result).toBe(false);
280
+ });
281
+
282
+ ["ftx", "ftxus", "wyre"].forEach((provider) => {
283
+ describe(`${provider.toUpperCase()}`, () => {
284
+ ["pending", "upgradeRequired", "rejected"].forEach((status) => {
285
+ test(`should display KYC banner if kycStatus is ${status}`, () => {
286
+ const result = shouldShowKYCBanner({
287
+ provider,
288
+ kycStatus: status as KYCStatus,
289
+ });
290
+
291
+ expect(result).toBe(true);
292
+ });
293
+ });
294
+
295
+ test("should not display KYC banner if kycStatus is approved", () => {
296
+ const result = shouldShowKYCBanner({
297
+ provider,
298
+ kycStatus: "approved",
299
+ });
300
+
301
+ expect(result).toBe(false);
302
+ });
303
+ });
304
+ });
305
+ });
306
+
307
+ describe("swap/utils/getProviderName", () => {
308
+ test("should return uppercase provider name for ftx", () => {
309
+ const expectedResult = "FTX";
310
+
311
+ const result = getProviderName("ftx");
312
+
313
+ expect(result).toBe(expectedResult);
314
+ });
315
+
316
+ test("should return uppercase provider name for ftxus", () => {
317
+ const expectedResult = "FTXUS";
318
+
319
+ const result = getProviderName("ftxus");
320
+
321
+ expect(result).toBe(expectedResult);
322
+ });
323
+
324
+ test("should return capitalized provider name for other provider", () => {
325
+ const expectedResult = "Changelly";
326
+
327
+ const result = getProviderName("changelly");
328
+
329
+ expect(result).toBe(expectedResult);
330
+ });
331
+ });
@@ -1,37 +1,21 @@
1
1
  import { CryptoCurrency, TokenCurrency } from "@ledgerhq/cryptoassets";
2
- import { makeEmptyTokenAccount } from "../../../account";
2
+ import jwtDecode from "jwt-decode";
3
+ import { getProviderConfig } from "../";
4
+ import { getAccountCurrency, makeEmptyTokenAccount } from "../../../account";
5
+ import { getEnv } from "../../../env";
3
6
  import { Account, SubAccount, TokenAccount } from "../../../types";
4
- import type { ExchangeRate } from "../types";
5
- import { getAccountCurrency } from "../../../account";
7
+ import type { CheckQuoteStatus } from "../types";
6
8
 
9
+ // Note: looks like we can't use an enum because this is used in LLD js code
7
10
  export const KYC_STATUS = {
8
11
  pending: "pending",
9
12
  rejected: "closed",
10
13
  approved: "approved",
14
+ upgradeRequired: "upgradeRequired",
11
15
  };
12
16
 
13
17
  export type KYCStatus = keyof typeof KYC_STATUS;
14
18
 
15
- export const pickExchangeRate = (
16
- exchangeRates: ExchangeRate[],
17
- exchangeRate: ExchangeRate | null | undefined,
18
- setExchangeRate: (rate?: ExchangeRate | null) => void
19
- ): void => {
20
- const hasRates = exchangeRates?.length > 0;
21
- // If the user picked an exchange rate before, try to select the new one that matches.
22
- // Otherwise pick the first one.
23
- const rate =
24
- hasRates &&
25
- ((exchangeRate &&
26
- exchangeRates.find(
27
- ({ tradeMethod, provider }) =>
28
- tradeMethod === exchangeRate.tradeMethod &&
29
- provider === exchangeRate.provider
30
- )) ||
31
- exchangeRates[0]);
32
- setExchangeRate(rate || null);
33
- };
34
-
35
19
  export type AccountTuple = {
36
20
  account: Account | null | undefined;
37
21
  subAccount: SubAccount | null | undefined;
@@ -76,3 +60,124 @@ export const getAvailableAccountsById = (
76
60
  accounts
77
61
  .filter((acc) => getAccountCurrency(acc)?.id === id && !acc.disabled)
78
62
  .sort((a, b) => b.balance.minus(a.balance).toNumber());
63
+
64
+ // Note: used in UI (LLD / LLM)
65
+ export const isJwtExpired = (jwtToken: string): boolean => {
66
+ /**
67
+ * Note:
68
+ * The JWT token should have at least an exp property (the expiration date of the token)
69
+ */
70
+ const { exp } = jwtDecode<{ exp: number }>(jwtToken);
71
+
72
+ const currentTime = new Date().getTime() / 1000;
73
+
74
+ return currentTime > exp;
75
+ };
76
+
77
+ // Note: used in UI (LLD / LLM)
78
+ export const getKYCStatusFromCheckQuoteStatus = (
79
+ checkQuoteStatus: CheckQuoteStatus
80
+ ): KYCStatus | null => {
81
+ switch (checkQuoteStatus.codeName) {
82
+ case "KYC_PENDING":
83
+ return KYC_STATUS.pending as KYCStatus;
84
+
85
+ case "KYC_FAILED":
86
+ return KYC_STATUS.rejected as KYCStatus;
87
+
88
+ case "KYC_UNDEFINED":
89
+ case "KYC_UPGRADE_REQUIRED":
90
+ return KYC_STATUS.upgradeRequired as KYCStatus;
91
+
92
+ case "RATE_VALID":
93
+ return KYC_STATUS.approved as KYCStatus;
94
+
95
+ // FIXME: should handle all other non KYC related error cases somewhere
96
+ default:
97
+ return null;
98
+ }
99
+ };
100
+
101
+ // Note: used in UI (LLD / LLM)
102
+ export type WidgetTypes = "login" | "kyc" | "mfa";
103
+ export type FTXProviders = "ftx" | "ftxus";
104
+ export const getFTXURL = ({
105
+ type,
106
+ provider,
107
+ }: {
108
+ type: WidgetTypes;
109
+ provider: FTXProviders;
110
+ }): string => {
111
+ const baseUrl =
112
+ getEnv("MOCK_SWAP_WIDGET_BASE_URL") ||
113
+ (() => {
114
+ switch (provider) {
115
+ case "ftx":
116
+ return "https://ftx.com";
117
+
118
+ case "ftxus":
119
+ return "https://ftx.us";
120
+
121
+ default:
122
+ break;
123
+ }
124
+ })();
125
+
126
+ if (!baseUrl) {
127
+ throw new Error(`Could not find domain for ${provider}`);
128
+ }
129
+
130
+ return `${baseUrl}/${type}?hideFrame=true&ledgerLive=true`;
131
+ };
132
+
133
+ // Note: used in UI (LLD / LLM)
134
+ export const shouldShowLoginBanner = ({
135
+ provider,
136
+ token,
137
+ }: {
138
+ provider?: string;
139
+ token?: string;
140
+ }): boolean => {
141
+ if (!provider) {
142
+ return false;
143
+ }
144
+
145
+ const providerConfig = getProviderConfig(provider);
146
+
147
+ if (!providerConfig.needsBearerToken) {
148
+ return false;
149
+ }
150
+
151
+ return !token || isJwtExpired(token);
152
+ };
153
+
154
+ // Note: used in UI (LLD / LLM)
155
+ export const shouldShowKYCBanner = ({
156
+ provider,
157
+ kycStatus,
158
+ }: {
159
+ provider?: string;
160
+ kycStatus: KYCStatus;
161
+ }): boolean => {
162
+ if (!provider) {
163
+ return false;
164
+ }
165
+
166
+ const providerConfig = getProviderConfig(provider);
167
+
168
+ if (!providerConfig.needsKYC) {
169
+ return false;
170
+ }
171
+
172
+ return kycStatus !== KYC_STATUS.approved;
173
+ };
174
+
175
+ export const getProviderName = (provider: string): string => {
176
+ switch (provider) {
177
+ case "ftx":
178
+ case "ftxus":
179
+ return provider.toUpperCase();
180
+ default:
181
+ return provider.charAt(0).toUpperCase() + provider.slice(1);
182
+ }
183
+ };
@@ -1,24 +1,26 @@
1
- import { Observable, of, concat } from "rxjs";
2
- import { scan, tap, catchError } from "rxjs/operators";
1
+ import { log } from "@ledgerhq/logs";
3
2
  import { useEffect, useState } from "react";
3
+ import { concat, Observable, of } from "rxjs";
4
+ import { catchError, scan, tap } from "rxjs/operators";
4
5
  import { getMainAccount } from "../../account";
5
- import type { ConnectAppEvent, Input as ConnectAppInput } from "../connectApp";
6
- import type { InitSwapInput, SwapTransaction } from "../../exchange/swap/types";
7
- import type { Action, Device } from "./types";
8
- import type { AppState } from "./app";
9
- import { log } from "@ledgerhq/logs";
10
- import { createAction as createAppAction } from "./app";
11
6
  import type {
12
7
  Exchange,
13
8
  ExchangeRate,
9
+ InitSwapInput,
14
10
  InitSwapResult,
15
11
  SwapRequestEvent,
12
+ SwapTransaction,
16
13
  } from "../../exchange/swap/types";
14
+ import type { ConnectAppEvent, Input as ConnectAppInput } from "../connectApp";
15
+ import type { AppState } from "./app";
16
+ import { createAction as createAppAction } from "./app";
17
+ import type { Action, Device } from "./types";
17
18
 
18
19
  type State = {
19
20
  initSwapResult: InitSwapResult | null | undefined;
20
21
  initSwapRequested: boolean;
21
22
  initSwapError: Error | null | undefined;
23
+ swapId?: string;
22
24
  error?: Error;
23
25
  isLoading: boolean;
24
26
  freezeReduxDevice: boolean;
@@ -40,6 +42,7 @@ type Result =
40
42
  }
41
43
  | {
42
44
  initSwapError: Error;
45
+ swapId?: string;
43
46
  };
44
47
 
45
48
  type InitSwapAction = Action<InitSwapRequest, InitSwapState, Result>;
@@ -47,6 +50,7 @@ type InitSwapAction = Action<InitSwapRequest, InitSwapState, Result>;
47
50
  const mapResult = ({
48
51
  initSwapResult,
49
52
  initSwapError,
53
+ swapId,
50
54
  }: InitSwapState): Result | null | undefined =>
51
55
  initSwapResult
52
56
  ? {
@@ -55,12 +59,14 @@ const mapResult = ({
55
59
  : initSwapError
56
60
  ? {
57
61
  initSwapError,
62
+ swapId,
58
63
  }
59
64
  : null;
60
65
 
61
66
  const initialState: State = {
62
67
  initSwapResult: null,
63
68
  initSwapError: null,
69
+ swapId: undefined,
64
70
  initSwapRequested: false,
65
71
  isLoading: true,
66
72
  freezeReduxDevice: false,
@@ -72,7 +78,12 @@ const reducer = (state: State, e: SwapRequestEvent) => {
72
78
  return { ...state, freezeReduxDevice: true };
73
79
 
74
80
  case "init-swap-error":
75
- return { ...state, initSwapError: e.error, isLoading: false };
81
+ return {
82
+ ...state,
83
+ initSwapError: e.error,
84
+ swapId: e.swapId,
85
+ isLoading: false,
86
+ };
76
87
 
77
88
  case "init-swap-requested":
78
89
  return {