@ledgerhq/live-common 34.37.0-nightly.2 → 34.37.0-nightly.4
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/e2e/index.d.ts +2 -0
- package/lib/e2e/index.d.ts.map +1 -1
- package/lib/exchange/swap/completeExchange.d.ts.map +1 -1
- package/lib/exchange/swap/completeExchange.js +0 -7
- package/lib/exchange/swap/completeExchange.js.map +1 -1
- package/lib/families/evm/config.js +2 -2
- package/lib/families/evm/config.js.map +1 -1
- package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib/featureFlags/defaultFeatures.js +6 -0
- package/lib/featureFlags/defaultFeatures.js.map +1 -1
- package/lib/featureFlags/useFeature.d.ts +1 -1
- package/lib/featureFlags/useFeature.d.ts.map +1 -1
- package/lib/hooks/useShowProviderLoadingTransition.d.ts +9 -0
- package/lib/hooks/useShowProviderLoadingTransition.d.ts.map +1 -0
- package/lib/hooks/useShowProviderLoadingTransition.js +46 -0
- package/lib/hooks/useShowProviderLoadingTransition.js.map +1 -0
- package/lib/hooks/useShowProviderLoadingTransition.test.d.ts +5 -0
- package/lib/hooks/useShowProviderLoadingTransition.test.d.ts.map +1 -0
- package/lib/hooks/useShowProviderLoadingTransition.test.js +83 -0
- package/lib/hooks/useShowProviderLoadingTransition.test.js.map +1 -0
- package/lib/wallet-api/Exchange/server.d.ts +2 -0
- package/lib/wallet-api/Exchange/server.d.ts.map +1 -1
- package/lib/wallet-api/Exchange/server.js +6 -0
- package/lib/wallet-api/Exchange/server.js.map +1 -1
- package/lib-es/e2e/index.d.ts +2 -0
- package/lib-es/e2e/index.d.ts.map +1 -1
- package/lib-es/exchange/swap/completeExchange.d.ts.map +1 -1
- package/lib-es/exchange/swap/completeExchange.js +0 -7
- package/lib-es/exchange/swap/completeExchange.js.map +1 -1
- package/lib-es/families/evm/config.js +2 -2
- package/lib-es/families/evm/config.js.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib-es/featureFlags/defaultFeatures.js +6 -0
- package/lib-es/featureFlags/defaultFeatures.js.map +1 -1
- package/lib-es/featureFlags/useFeature.d.ts +1 -1
- package/lib-es/featureFlags/useFeature.d.ts.map +1 -1
- package/lib-es/hooks/useShowProviderLoadingTransition.d.ts +9 -0
- package/lib-es/hooks/useShowProviderLoadingTransition.d.ts.map +1 -0
- package/lib-es/hooks/useShowProviderLoadingTransition.js +41 -0
- package/lib-es/hooks/useShowProviderLoadingTransition.js.map +1 -0
- package/lib-es/hooks/useShowProviderLoadingTransition.test.d.ts +5 -0
- package/lib-es/hooks/useShowProviderLoadingTransition.test.d.ts.map +1 -0
- package/lib-es/hooks/useShowProviderLoadingTransition.test.js +81 -0
- package/lib-es/hooks/useShowProviderLoadingTransition.test.js.map +1 -0
- package/lib-es/wallet-api/Exchange/server.d.ts +2 -0
- package/lib-es/wallet-api/Exchange/server.d.ts.map +1 -1
- package/lib-es/wallet-api/Exchange/server.js +6 -0
- package/lib-es/wallet-api/Exchange/server.js.map +1 -1
- package/package.json +62 -62
- package/src/exchange/swap/completeExchange.ts +0 -15
- package/src/families/evm/config.ts +2 -2
- package/src/featureFlags/defaultFeatures.ts +7 -0
- package/src/hooks/useShowProviderLoadingTransition.test.ts +112 -0
- package/src/hooks/useShowProviderLoadingTransition.ts +57 -0
- package/src/wallet-api/Exchange/server.ts +8 -0
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ledgerhq/live-common",
|
3
3
|
"description": "Common ground for the Ledger Live apps",
|
4
|
-
"version": "34.37.0-nightly.
|
4
|
+
"version": "34.37.0-nightly.4",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
7
7
|
"url": "https://github.com/LedgerHQ/ledger-live.git"
|
@@ -162,72 +162,72 @@
|
|
162
162
|
"xstate": "^5.19.2",
|
163
163
|
"yargs": "^17.0.0",
|
164
164
|
"zod": "^3.22.4",
|
165
|
-
"@ledgerhq/coin-algorand": "^0.9.9-nightly.
|
166
|
-
"@ledgerhq/coin-aptos": "^2.2.0-nightly.
|
167
|
-
"@ledgerhq/coin-bitcoin": "^0.15.9-nightly.
|
168
|
-
"@ledgerhq/coin-cardano": "^0.8.9-nightly.
|
169
|
-
"@ledgerhq/coin-casper": "^1.7.4-nightly.
|
170
|
-
"@ledgerhq/coin-celo": "^1.1.7-nightly.
|
171
|
-
"@ledgerhq/coin-cosmos": "^0.15.1-nightly.
|
172
|
-
"@ledgerhq/coin-evm": "^2.22.3-nightly.
|
173
|
-
"@ledgerhq/coin-filecoin": "^1.9.9-nightly.
|
174
|
-
"@ledgerhq/coin-framework": "^5.3.0-nightly.
|
175
|
-
"@ledgerhq/coin-hedera": "^1.7.1-nightly.
|
176
|
-
"@ledgerhq/coin-icon": "^0.10.9-nightly.
|
177
|
-
"@ledgerhq/coin-internet_computer": "^1.7.9-nightly.
|
178
|
-
"@ledgerhq/coin-mina": "^1.1.8-nightly.
|
179
|
-
"@ledgerhq/coin-multiversx": "^0.4.9-nightly.
|
180
|
-
"@ledgerhq/coin-near": "^0.11.9-nightly.
|
181
|
-
"@ledgerhq/coin-polkadot": "^6.1.3-nightly.
|
182
|
-
"@ledgerhq/coin-solana": "^0.
|
183
|
-
"@ledgerhq/coin-stacks": "^0.8.9-nightly.
|
184
|
-
"@ledgerhq/coin-stellar": "^5.1.2-nightly.
|
185
|
-
"@ledgerhq/coin-sui": "^0.4.2-nightly.
|
186
|
-
"@ledgerhq/coin-tezos": "^5.2.2-nightly.
|
187
|
-
"@ledgerhq/coin-ton": "^0.12.1-nightly.
|
188
|
-
"@ledgerhq/coin-tron": "^4.2.0-nightly.
|
189
|
-
"@ledgerhq/coin-vechain": "^2.7.9-nightly.
|
190
|
-
"@ledgerhq/coin-xrp": "^6.1.4-nightly.
|
165
|
+
"@ledgerhq/coin-algorand": "^0.9.9-nightly.3",
|
166
|
+
"@ledgerhq/coin-aptos": "^2.2.0-nightly.3",
|
167
|
+
"@ledgerhq/coin-bitcoin": "^0.15.9-nightly.3",
|
168
|
+
"@ledgerhq/coin-cardano": "^0.8.9-nightly.3",
|
169
|
+
"@ledgerhq/coin-casper": "^1.7.4-nightly.3",
|
170
|
+
"@ledgerhq/coin-celo": "^1.1.7-nightly.3",
|
171
|
+
"@ledgerhq/coin-cosmos": "^0.15.1-nightly.3",
|
172
|
+
"@ledgerhq/coin-evm": "^2.22.3-nightly.3",
|
173
|
+
"@ledgerhq/coin-filecoin": "^1.9.9-nightly.3",
|
174
|
+
"@ledgerhq/coin-framework": "^5.3.0-nightly.3",
|
175
|
+
"@ledgerhq/coin-hedera": "^1.7.1-nightly.3",
|
176
|
+
"@ledgerhq/coin-icon": "^0.10.9-nightly.3",
|
177
|
+
"@ledgerhq/coin-internet_computer": "^1.7.9-nightly.3",
|
178
|
+
"@ledgerhq/coin-mina": "^1.1.8-nightly.3",
|
179
|
+
"@ledgerhq/coin-multiversx": "^0.4.9-nightly.3",
|
180
|
+
"@ledgerhq/coin-near": "^0.11.9-nightly.3",
|
181
|
+
"@ledgerhq/coin-polkadot": "^6.1.3-nightly.3",
|
182
|
+
"@ledgerhq/coin-solana": "^0.26.0-nightly.3",
|
183
|
+
"@ledgerhq/coin-stacks": "^0.8.9-nightly.3",
|
184
|
+
"@ledgerhq/coin-stellar": "^5.1.2-nightly.3",
|
185
|
+
"@ledgerhq/coin-sui": "^0.4.2-nightly.3",
|
186
|
+
"@ledgerhq/coin-tezos": "^5.2.2-nightly.3",
|
187
|
+
"@ledgerhq/coin-ton": "^0.12.1-nightly.3",
|
188
|
+
"@ledgerhq/coin-tron": "^4.2.0-nightly.4",
|
189
|
+
"@ledgerhq/coin-vechain": "^2.7.9-nightly.3",
|
190
|
+
"@ledgerhq/coin-xrp": "^6.1.4-nightly.3",
|
191
191
|
"@ledgerhq/crypto-icons-ui": "^1.15.0-nightly.0",
|
192
|
-
"@ledgerhq/cryptoassets": "^13.
|
193
|
-
"@ledgerhq/device-core": "^0.4.27-nightly.
|
194
|
-
"@ledgerhq/devices": "8.4.
|
195
|
-
"@ledgerhq/errors": "^6.
|
196
|
-
"@ledgerhq/hw-app-algorand": "^6.31.
|
197
|
-
"@ledgerhq/hw-app-aptos": "^6.34.
|
198
|
-
"@ledgerhq/hw-app-btc": "^10.9.
|
199
|
-
"@ledgerhq/hw-app-celo": "^6.33.5-nightly.
|
200
|
-
"@ledgerhq/hw-app-cosmos": "^6.32.
|
201
|
-
"@ledgerhq/hw-app-eth": "^6.45.7-nightly.
|
202
|
-
"@ledgerhq/hw-app-exchange": "^0.10.
|
203
|
-
"@ledgerhq/hw-app-hedera": "^1.2.
|
204
|
-
"@ledgerhq/hw-app-icon": "^1.3.
|
205
|
-
"@ledgerhq/hw-app-multiversx": "^6.24.
|
206
|
-
"@ledgerhq/hw-app-near": "^6.31.
|
207
|
-
"@ledgerhq/hw-app-polkadot": "^6.34.
|
208
|
-
"@ledgerhq/hw-app-str": "^7.2.
|
192
|
+
"@ledgerhq/cryptoassets": "^13.19.0-nightly.1",
|
193
|
+
"@ledgerhq/device-core": "^0.4.27-nightly.3",
|
194
|
+
"@ledgerhq/devices": "8.4.7-nightly.0",
|
195
|
+
"@ledgerhq/errors": "^6.22.0-nightly.0",
|
196
|
+
"@ledgerhq/hw-app-algorand": "^6.31.3-nightly.0",
|
197
|
+
"@ledgerhq/hw-app-aptos": "^6.34.3-nightly.0",
|
198
|
+
"@ledgerhq/hw-app-btc": "^10.9.3-nightly.0",
|
199
|
+
"@ledgerhq/hw-app-celo": "^6.33.5-nightly.3",
|
200
|
+
"@ledgerhq/hw-app-cosmos": "^6.32.3-nightly.0",
|
201
|
+
"@ledgerhq/hw-app-eth": "^6.45.7-nightly.3",
|
202
|
+
"@ledgerhq/hw-app-exchange": "^0.10.3-nightly.0",
|
203
|
+
"@ledgerhq/hw-app-hedera": "^1.2.3-nightly.0",
|
204
|
+
"@ledgerhq/hw-app-icon": "^1.3.3-nightly.0",
|
205
|
+
"@ledgerhq/hw-app-multiversx": "^6.24.3-nightly.0",
|
206
|
+
"@ledgerhq/hw-app-near": "^6.31.3-nightly.0",
|
207
|
+
"@ledgerhq/hw-app-polkadot": "^6.34.3-nightly.0",
|
208
|
+
"@ledgerhq/hw-app-str": "^7.2.3-nightly.0",
|
209
209
|
"@ledgerhq/hw-app-sui": "^1.1.0",
|
210
|
-
"@ledgerhq/hw-app-tezos": "^6.31.
|
211
|
-
"@ledgerhq/hw-app-trx": "^6.31.
|
212
|
-
"@ledgerhq/hw-app-vet": "^0.5.
|
213
|
-
"@ledgerhq/hw-app-xrp": "^6.31.
|
214
|
-
"@ledgerhq/hw-transport": "^6.31.
|
215
|
-
"@ledgerhq/hw-transport-mocker": "^6.29.
|
216
|
-
"@ledgerhq/ledger-cal-service": "^0.
|
210
|
+
"@ledgerhq/hw-app-tezos": "^6.31.3-nightly.0",
|
211
|
+
"@ledgerhq/hw-app-trx": "^6.31.3-nightly.0",
|
212
|
+
"@ledgerhq/hw-app-vet": "^0.5.6-nightly.1",
|
213
|
+
"@ledgerhq/hw-app-xrp": "^6.31.3-nightly.0",
|
214
|
+
"@ledgerhq/hw-transport": "^6.31.7-nightly.0",
|
215
|
+
"@ledgerhq/hw-transport-mocker": "^6.29.7-nightly.0",
|
216
|
+
"@ledgerhq/ledger-cal-service": "^1.0.0-nightly.2",
|
217
217
|
"@ledgerhq/live-config": "^3.1.0",
|
218
|
-
"@ledgerhq/live-countervalues": "^0.5.9-nightly.
|
219
|
-
"@ledgerhq/live-dmk-shared": "^0.9.0",
|
220
|
-
"@ledgerhq/live-countervalues-react": "^0.2.38-nightly.
|
218
|
+
"@ledgerhq/live-countervalues": "^0.5.9-nightly.3",
|
219
|
+
"@ledgerhq/live-dmk-shared": "^0.9.1-nightly.0",
|
220
|
+
"@ledgerhq/live-countervalues-react": "^0.2.38-nightly.3",
|
221
221
|
"@ledgerhq/live-env": "^2.9.1-nightly.0",
|
222
222
|
"@ledgerhq/live-hooks": "0.1.0",
|
223
|
-
"@ledgerhq/live-network": "^2.0.
|
224
|
-
"@ledgerhq/live-nft": "^0.8.9-nightly.
|
223
|
+
"@ledgerhq/live-network": "^2.0.10-nightly.0",
|
224
|
+
"@ledgerhq/live-nft": "^0.8.9-nightly.3",
|
225
225
|
"@ledgerhq/live-promise": "^0.1.1",
|
226
|
-
"@ledgerhq/live-signer-evm": "^0.5.2-nightly.
|
227
|
-
"@ledgerhq/live-signer-solana": "^0.
|
228
|
-
"@ledgerhq/live-wallet": "^0.10.12-nightly.
|
226
|
+
"@ledgerhq/live-signer-evm": "^0.5.2-nightly.3",
|
227
|
+
"@ledgerhq/live-signer-solana": "^0.3.0-nightly.3",
|
228
|
+
"@ledgerhq/live-wallet": "^0.10.12-nightly.3",
|
229
229
|
"@ledgerhq/logs": "^6.13.0",
|
230
|
-
"@ledgerhq/speculos-transport": "^0.2.
|
230
|
+
"@ledgerhq/speculos-transport": "^0.2.3-nightly.0",
|
231
231
|
"@ledgerhq/wallet-api-acre-module": "^0.5.0",
|
232
232
|
"@ledgerhq/wallet-api-exchange-module": "^0.13.0"
|
233
233
|
},
|
@@ -277,10 +277,10 @@
|
|
277
277
|
"undici": "6.19.2",
|
278
278
|
"uuid": "^8.3.2",
|
279
279
|
"ws": "7",
|
280
|
-
"@ledgerhq/device-react": "^0.2.33-nightly.
|
280
|
+
"@ledgerhq/device-react": "^0.2.33-nightly.3",
|
281
281
|
"@ledgerhq/types-cryptoassets": "^7.23.0",
|
282
282
|
"@ledgerhq/types-devices": "^6.25.3",
|
283
|
-
"@ledgerhq/types-live": "^6.73.0-nightly.
|
283
|
+
"@ledgerhq/types-live": "^6.73.0-nightly.2"
|
284
284
|
},
|
285
285
|
"scripts": {
|
286
286
|
"build": "zx ./scripts/build-ts.mjs",
|
@@ -25,8 +25,6 @@ import { CompleteExchangeStep, convertTransportError } from "../error";
|
|
25
25
|
import type { CompleteExchangeInputSwap, CompleteExchangeRequestEvent } from "../platform/types";
|
26
26
|
import { convertToAppExchangePartnerKey, getSwapProvider } from "../providers";
|
27
27
|
import { CEXProviderConfig } from "../providers/swap";
|
28
|
-
import { isAddressSanctioned } from "../../sanction";
|
29
|
-
import { RecipientAddressSanctionedError } from "../../sanction/errors";
|
30
28
|
|
31
29
|
const COMPLETE_EXCHANGE_LOG = "SWAP-CompleteExchange";
|
32
30
|
|
@@ -66,19 +64,6 @@ const completeExchange = (
|
|
66
64
|
const payoutCurrency = getAccountCurrency(toAccount);
|
67
65
|
const refundCurrency = getAccountCurrency(fromAccount);
|
68
66
|
const mainRefundCurrency = getAccountCurrency(refundAccount);
|
69
|
-
|
70
|
-
const isPayoutSanctioned = await isAddressSanctioned(
|
71
|
-
payoutAccount.currency,
|
72
|
-
payoutAccount.freshAddress,
|
73
|
-
);
|
74
|
-
const isRefundSanctioned = await isAddressSanctioned(
|
75
|
-
refundAccount.currency,
|
76
|
-
refundAccount.freshAddress,
|
77
|
-
);
|
78
|
-
|
79
|
-
if (isPayoutSanctioned || isRefundSanctioned) {
|
80
|
-
throw new RecipientAddressSanctionedError();
|
81
|
-
}
|
82
67
|
if (mainPayoutCurrency.type !== "CryptoCurrency")
|
83
68
|
throw new Error("This should be a cryptocurrency");
|
84
69
|
if (mainRefundCurrency.type !== "CryptoCurrency")
|
@@ -104,7 +104,7 @@ const evmConfig: CurrencyLiveConfigDefinition = {
|
|
104
104
|
type: "ledger",
|
105
105
|
explorerId: "eth",
|
106
106
|
},
|
107
|
-
showNfts:
|
107
|
+
showNfts: false,
|
108
108
|
},
|
109
109
|
},
|
110
110
|
config_currency_sonic: {
|
@@ -266,7 +266,7 @@ const evmConfig: CurrencyLiveConfigDefinition = {
|
|
266
266
|
type: "ledger",
|
267
267
|
explorerId: "matic",
|
268
268
|
},
|
269
|
-
showNfts:
|
269
|
+
showNfts: false,
|
270
270
|
},
|
271
271
|
},
|
272
272
|
config_currency_reosc: {
|
@@ -0,0 +1,112 @@
|
|
1
|
+
/**
|
2
|
+
* @jest-environment jsdom
|
3
|
+
*/
|
4
|
+
|
5
|
+
import { renderHook } from "@testing-library/react";
|
6
|
+
import { LiveAppManifest } from "../platform/types";
|
7
|
+
import { INTERNAL_APP_IDS } from "../wallet-api/constants";
|
8
|
+
import { useFeature } from "../featureFlags";
|
9
|
+
import { useInternalAppIds } from "./useInternalAppIds";
|
10
|
+
|
11
|
+
import { useShowProviderLoadingTransition } from "./useShowProviderLoadingTransition";
|
12
|
+
|
13
|
+
jest.mock("../featureFlags", () => ({
|
14
|
+
useFeature: jest.fn(),
|
15
|
+
}));
|
16
|
+
jest.mock("../wallet-api/constants", () => ({
|
17
|
+
INTERNAL_APP_IDS: ["internal-app-id-1", "internal-app-id-2"],
|
18
|
+
}));
|
19
|
+
jest.mock("./useInternalAppIds", () => ({
|
20
|
+
useInternalAppIds: jest.fn(),
|
21
|
+
}));
|
22
|
+
|
23
|
+
describe("useShowProviderLoadingTransition", () => {
|
24
|
+
const mockUseFeature = useFeature as jest.Mock;
|
25
|
+
const mockUseInternalAppIds = useInternalAppIds as jest.Mock;
|
26
|
+
|
27
|
+
beforeEach(() => {
|
28
|
+
jest.clearAllMocks();
|
29
|
+
});
|
30
|
+
|
31
|
+
it("should return false when feature is disabled", () => {
|
32
|
+
mockUseFeature.mockReturnValue({ enabled: false, params: {} });
|
33
|
+
const { result } = renderHook(() =>
|
34
|
+
useShowProviderLoadingTransition({
|
35
|
+
manifest: { id: "test-app-id" } as LiveAppManifest,
|
36
|
+
isLoading: true,
|
37
|
+
}),
|
38
|
+
);
|
39
|
+
expect(result.current).toBe(false);
|
40
|
+
});
|
41
|
+
|
42
|
+
it("should return false for internal apps", () => {
|
43
|
+
mockUseFeature.mockReturnValue({ enabled: true, params: {} });
|
44
|
+
mockUseInternalAppIds.mockReturnValue(INTERNAL_APP_IDS);
|
45
|
+
const { result } = renderHook(() =>
|
46
|
+
useShowProviderLoadingTransition({
|
47
|
+
manifest: { id: "internal-app-id-1" } as LiveAppManifest,
|
48
|
+
isLoading: true,
|
49
|
+
}),
|
50
|
+
);
|
51
|
+
expect(result.current).toBe(false);
|
52
|
+
});
|
53
|
+
|
54
|
+
it("should return true when loading and feature is enabled", () => {
|
55
|
+
mockUseFeature.mockReturnValue({ enabled: true, params: {} });
|
56
|
+
mockUseInternalAppIds.mockReturnValue([]);
|
57
|
+
const { result } = renderHook(() =>
|
58
|
+
useShowProviderLoadingTransition({
|
59
|
+
manifest: { id: "test-app-id" } as LiveAppManifest,
|
60
|
+
isLoading: true,
|
61
|
+
}),
|
62
|
+
);
|
63
|
+
expect(result.current).toBe(true);
|
64
|
+
});
|
65
|
+
|
66
|
+
it("should handle extended loading state", () => {
|
67
|
+
jest.useFakeTimers();
|
68
|
+
mockUseFeature.mockReturnValue({ enabled: true, params: { durationMs: 1000 } });
|
69
|
+
mockUseInternalAppIds.mockReturnValue([]);
|
70
|
+
|
71
|
+
const { result, rerender } = renderHook(
|
72
|
+
({ isLoading }) =>
|
73
|
+
useShowProviderLoadingTransition({
|
74
|
+
manifest: { id: "test-app-id" } as LiveAppManifest,
|
75
|
+
isLoading,
|
76
|
+
}),
|
77
|
+
{
|
78
|
+
initialProps: { isLoading: true },
|
79
|
+
},
|
80
|
+
);
|
81
|
+
|
82
|
+
expect(result.current).toBe(true);
|
83
|
+
|
84
|
+
// Simulate the timeout
|
85
|
+
jest.advanceTimersByTime(1000);
|
86
|
+
|
87
|
+
rerender({ isLoading: false });
|
88
|
+
|
89
|
+
expect(result.current).toBe(false);
|
90
|
+
|
91
|
+
jest.useRealTimers();
|
92
|
+
});
|
93
|
+
it("should clear timeout on unmount", () => {
|
94
|
+
jest.useFakeTimers();
|
95
|
+
mockUseFeature.mockReturnValue({ enabled: true, params: { durationMs: 1000 } });
|
96
|
+
mockUseInternalAppIds.mockReturnValue([]);
|
97
|
+
|
98
|
+
const { unmount } = renderHook(() =>
|
99
|
+
useShowProviderLoadingTransition({
|
100
|
+
manifest: { id: "test-app-id" } as LiveAppManifest,
|
101
|
+
isLoading: true,
|
102
|
+
}),
|
103
|
+
);
|
104
|
+
|
105
|
+
unmount();
|
106
|
+
|
107
|
+
// Advance timers to ensure no memory leaks
|
108
|
+
jest.advanceTimersByTime(1000);
|
109
|
+
|
110
|
+
jest.useRealTimers();
|
111
|
+
});
|
112
|
+
});
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
2
|
+
|
3
|
+
import { useFeature } from "../featureFlags/index";
|
4
|
+
import { INTERNAL_APP_IDS } from "../wallet-api/constants";
|
5
|
+
import { useInternalAppIds } from "./useInternalAppIds";
|
6
|
+
import { LiveAppManifest } from "../platform/types";
|
7
|
+
|
8
|
+
export function useShowProviderLoadingTransition({
|
9
|
+
isLoading,
|
10
|
+
manifest,
|
11
|
+
}: {
|
12
|
+
manifest: LiveAppManifest;
|
13
|
+
isLoading: boolean;
|
14
|
+
}) {
|
15
|
+
const isEnabled = useProviderInterstitalEnabled({ manifest });
|
16
|
+
const [extendedInitialLoading, setExtendedInitialLoading] = useState(false);
|
17
|
+
|
18
|
+
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
19
|
+
const buySellLoaderFF = useFeature("buySellLoader");
|
20
|
+
const durationMs = buySellLoaderFF?.params?.durationMs ?? 0;
|
21
|
+
const internalAppIds = useInternalAppIds() || INTERNAL_APP_IDS;
|
22
|
+
const isAppInternal = internalAppIds.includes(manifest.id);
|
23
|
+
|
24
|
+
useEffect(() => {
|
25
|
+
if (isEnabled && isLoading && !extendedInitialLoading) {
|
26
|
+
setExtendedInitialLoading(true);
|
27
|
+
|
28
|
+
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
29
|
+
|
30
|
+
timeoutRef.current = setTimeout(() => {
|
31
|
+
setExtendedInitialLoading(false);
|
32
|
+
}, durationMs);
|
33
|
+
}
|
34
|
+
}, [durationMs, extendedInitialLoading, isAppInternal, isEnabled, isLoading]);
|
35
|
+
|
36
|
+
useEffect(() => {
|
37
|
+
return () => {
|
38
|
+
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
39
|
+
};
|
40
|
+
}, []);
|
41
|
+
|
42
|
+
return isEnabled && (isLoading || extendedInitialLoading);
|
43
|
+
}
|
44
|
+
|
45
|
+
export function useProviderInterstitalEnabled({ manifest }: { manifest?: LiveAppManifest }) {
|
46
|
+
const buySellLoaderFF = useFeature("buySellLoader");
|
47
|
+
const internalAppIds = useInternalAppIds() || INTERNAL_APP_IDS;
|
48
|
+
|
49
|
+
if (!manifest) {
|
50
|
+
return false;
|
51
|
+
}
|
52
|
+
|
53
|
+
const isAppInternal = internalAppIds.includes(manifest.id);
|
54
|
+
const isEnabled = buySellLoaderFF?.enabled && !isAppInternal;
|
55
|
+
|
56
|
+
return isEnabled;
|
57
|
+
}
|
@@ -65,6 +65,8 @@ export type CompleteExchangeUiRequest = {
|
|
65
65
|
swapId?: string;
|
66
66
|
amountExpectedTo?: number;
|
67
67
|
magnitudeAwareRate?: BigNumber;
|
68
|
+
refundAddress?: string;
|
69
|
+
payoutAddress?: string;
|
68
70
|
};
|
69
71
|
|
70
72
|
type ExchangeStartParamsUiRequest =
|
@@ -286,11 +288,15 @@ export const handlers = ({
|
|
286
288
|
|
287
289
|
let amountExpectedTo;
|
288
290
|
let magnitudeAwareRate;
|
291
|
+
let refundAddress;
|
292
|
+
let payoutAddress;
|
289
293
|
if (params.exchangeType === "SWAP") {
|
290
294
|
// Get amountExpectedTo and magnitudeAwareRate from binary payload
|
291
295
|
const decodePayload = await decodeSwapPayload(params.hexBinaryPayload);
|
292
296
|
amountExpectedTo = new BigNumber(decodePayload.amountToWallet.toString());
|
293
297
|
magnitudeAwareRate = tx.amount && amountExpectedTo.dividedBy(tx.amount);
|
298
|
+
refundAddress = decodePayload.refundAddress;
|
299
|
+
payoutAddress = decodePayload.payoutAddress;
|
294
300
|
}
|
295
301
|
|
296
302
|
return new Promise((resolve, reject) =>
|
@@ -306,6 +312,8 @@ export const handlers = ({
|
|
306
312
|
swapId: params.exchangeType === "SWAP" ? params.swapId : undefined,
|
307
313
|
amountExpectedTo,
|
308
314
|
magnitudeAwareRate,
|
315
|
+
refundAddress,
|
316
|
+
payoutAddress,
|
309
317
|
},
|
310
318
|
onSuccess: (transactionHash: string) => {
|
311
319
|
tracking.completeExchangeSuccess({
|