@ledgerhq/live-common 34.40.0-nightly.0 → 34.40.0-nightly.2
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/enum/Provider.d.ts +3 -0
- package/lib/e2e/enum/Provider.d.ts.map +1 -1
- package/lib/e2e/enum/Provider.js +3 -0
- package/lib/e2e/enum/Provider.js.map +1 -1
- package/lib/e2e/index.d.ts +1 -0
- package/lib/e2e/index.d.ts.map +1 -1
- package/lib/env.react.d.ts +1 -1
- package/lib/env.react.d.ts.map +1 -1
- package/lib/exchange/error.d.ts +1 -0
- package/lib/exchange/error.d.ts.map +1 -1
- package/lib/exchange/error.js +11 -1
- package/lib/exchange/error.js.map +1 -1
- package/lib/exchange/swap/api/v5/actions.d.ts +3 -0
- package/lib/exchange/swap/api/v5/actions.d.ts.map +1 -0
- package/lib/exchange/swap/api/v5/actions.js +36 -0
- package/lib/exchange/swap/api/v5/actions.js.map +1 -0
- package/lib/exchange/swap/getCompleteSwapHistory.js +1 -1
- package/lib/exchange/swap/getCompleteSwapHistory.js.map +1 -1
- package/lib/exchange/swap/postSwapState.js +3 -3
- package/lib/exchange/swap/postSwapState.js.map +1 -1
- package/lib/exchange/swap/setBroadcastTransaction.d.ts +1 -1
- package/lib/exchange/swap/setBroadcastTransaction.d.ts.map +1 -1
- package/lib/exchange/swap/setBroadcastTransaction.js +1 -1
- package/lib/exchange/swap/setBroadcastTransaction.js.map +1 -1
- package/lib/exchange/swap/transactionStrategies.d.ts +25 -0
- package/lib/exchange/swap/transactionStrategies.d.ts.map +1 -0
- package/lib/exchange/swap/transactionStrategies.js +152 -0
- package/lib/exchange/swap/transactionStrategies.js.map +1 -0
- package/lib/exchange/swap/types.d.ts +58 -0
- package/lib/exchange/swap/types.d.ts.map +1 -1
- package/lib/hooks/useAppVersionBlockCheck.d.ts.map +1 -1
- package/lib/hooks/useAppVersionBlockCheck.js +10 -12
- package/lib/hooks/useAppVersionBlockCheck.js.map +1 -1
- package/lib/hooks/useAppVersionBlockCheck.test.js +50 -0
- package/lib/hooks/useAppVersionBlockCheck.test.js.map +1 -1
- package/lib/wallet-api/Exchange/server.d.ts +29 -10
- package/lib/wallet-api/Exchange/server.d.ts.map +1 -1
- package/lib/wallet-api/Exchange/server.js +202 -7
- package/lib/wallet-api/Exchange/server.js.map +1 -1
- package/lib/wallet-api/Exchange/server.test.js +3 -1
- package/lib/wallet-api/Exchange/server.test.js.map +1 -1
- package/lib-es/e2e/enum/Provider.d.ts +3 -0
- package/lib-es/e2e/enum/Provider.d.ts.map +1 -1
- package/lib-es/e2e/enum/Provider.js +3 -0
- package/lib-es/e2e/enum/Provider.js.map +1 -1
- package/lib-es/e2e/index.d.ts +1 -0
- package/lib-es/e2e/index.d.ts.map +1 -1
- package/lib-es/env.react.d.ts +1 -1
- package/lib-es/env.react.d.ts.map +1 -1
- package/lib-es/exchange/error.d.ts +1 -0
- package/lib-es/exchange/error.d.ts.map +1 -1
- package/lib-es/exchange/error.js +9 -0
- package/lib-es/exchange/error.js.map +1 -1
- package/lib-es/exchange/swap/api/v5/actions.d.ts +3 -0
- package/lib-es/exchange/swap/api/v5/actions.d.ts.map +1 -0
- package/lib-es/exchange/swap/api/v5/actions.js +29 -0
- package/lib-es/exchange/swap/api/v5/actions.js.map +1 -0
- package/lib-es/exchange/swap/getCompleteSwapHistory.js +1 -1
- package/lib-es/exchange/swap/getCompleteSwapHistory.js.map +1 -1
- package/lib-es/exchange/swap/postSwapState.js +1 -1
- package/lib-es/exchange/swap/postSwapState.js.map +1 -1
- package/lib-es/exchange/swap/setBroadcastTransaction.d.ts +1 -1
- package/lib-es/exchange/swap/setBroadcastTransaction.d.ts.map +1 -1
- package/lib-es/exchange/swap/setBroadcastTransaction.js +1 -1
- package/lib-es/exchange/swap/setBroadcastTransaction.js.map +1 -1
- package/lib-es/exchange/swap/transactionStrategies.d.ts +25 -0
- package/lib-es/exchange/swap/transactionStrategies.d.ts.map +1 -0
- package/lib-es/exchange/swap/transactionStrategies.js +140 -0
- package/lib-es/exchange/swap/transactionStrategies.js.map +1 -0
- package/lib-es/exchange/swap/types.d.ts +58 -0
- package/lib-es/exchange/swap/types.d.ts.map +1 -1
- package/lib-es/hooks/useAppVersionBlockCheck.d.ts.map +1 -1
- package/lib-es/hooks/useAppVersionBlockCheck.js +10 -12
- package/lib-es/hooks/useAppVersionBlockCheck.js.map +1 -1
- package/lib-es/hooks/useAppVersionBlockCheck.test.js +50 -0
- package/lib-es/hooks/useAppVersionBlockCheck.test.js.map +1 -1
- package/lib-es/wallet-api/Exchange/server.d.ts +29 -10
- package/lib-es/wallet-api/Exchange/server.d.ts.map +1 -1
- package/lib-es/wallet-api/Exchange/server.js +204 -9
- package/lib-es/wallet-api/Exchange/server.js.map +1 -1
- package/lib-es/wallet-api/Exchange/server.test.js +3 -1
- package/lib-es/wallet-api/Exchange/server.test.js.map +1 -1
- package/package.json +40 -40
- package/src/e2e/enum/Provider.ts +3 -0
- package/src/exchange/error.ts +10 -0
- package/src/exchange/swap/api/v5/actions.ts +36 -0
- package/src/exchange/swap/getCompleteSwapHistory.ts +1 -1
- package/src/exchange/swap/postSwapState.ts +1 -1
- package/src/exchange/swap/setBroadcastTransaction.ts +2 -2
- package/src/exchange/swap/transactionStrategies.ts +234 -0
- package/src/exchange/swap/types.ts +63 -0
- package/src/hooks/useAppVersionBlockCheck.test.ts +51 -0
- package/src/hooks/useAppVersionBlockCheck.ts +17 -23
- package/src/wallet-api/Exchange/server.test.ts +7 -5
- package/src/wallet-api/Exchange/server.ts +335 -32
@@ -0,0 +1,36 @@
|
|
1
|
+
import axios from "axios";
|
2
|
+
import { getSwapAPIBaseURL } from "../..";
|
3
|
+
import { SwapPayloadRequestData, SwapPayloadResponse } from "../../types";
|
4
|
+
|
5
|
+
export async function retrieveSwapPayload(
|
6
|
+
data: SwapPayloadRequestData,
|
7
|
+
): Promise<SwapPayloadResponse> {
|
8
|
+
const SWAP_API_BASE = getSwapAPIBaseURL();
|
9
|
+
|
10
|
+
const swapAxiosClient = axios.create({
|
11
|
+
baseURL: SWAP_API_BASE,
|
12
|
+
});
|
13
|
+
|
14
|
+
const request = {
|
15
|
+
provider: data.provider,
|
16
|
+
deviceTransactionId: data.deviceTransactionId,
|
17
|
+
from: data.fromAccountCurrency,
|
18
|
+
to: data.toNewTokenId || data.toAccountCurrency,
|
19
|
+
address: data.toAccountAddress,
|
20
|
+
refundAddress: data.fromAccountAddress,
|
21
|
+
amountFrom: data.amount,
|
22
|
+
amountFromInSmallestDenomination: Number(data.amountInAtomicUnit),
|
23
|
+
rateId: data.quoteId,
|
24
|
+
};
|
25
|
+
|
26
|
+
const res = await swapAxiosClient.post(`${SWAP_API_BASE}/swap`, request);
|
27
|
+
|
28
|
+
return {
|
29
|
+
binaryPayload: res.data?.binaryPayload,
|
30
|
+
signature: res.data?.signature,
|
31
|
+
payinAddress: res.data?.payinAddress,
|
32
|
+
swapId: res.data?.swapId,
|
33
|
+
payinExtraId: res.data?.payinExtraId,
|
34
|
+
extraTransactionParameters: res.data?.extraTransactionParameters,
|
35
|
+
};
|
36
|
+
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import network from "@ledgerhq/live-network
|
1
|
+
import network from "@ledgerhq/live-network";
|
2
2
|
import { mockPostSwapAccepted, mockPostSwapCancelled } from "./mock";
|
3
3
|
import type { PostSwapAccepted, PostSwapCancelled } from "./types";
|
4
4
|
import { isIntegrationTestEnv } from "./utils/isIntegrationTestEnv";
|
@@ -12,7 +12,7 @@ export const setBroadcastTransaction = ({
|
|
12
12
|
hardwareWalletType,
|
13
13
|
swapType,
|
14
14
|
}: {
|
15
|
-
result: { operation: Operation; swapId: string };
|
15
|
+
result: { operation: Operation | string; swapId: string };
|
16
16
|
provider: string;
|
17
17
|
sourceCurrencyId?: string;
|
18
18
|
targetCurrencyId?: string;
|
@@ -41,7 +41,7 @@ export const setBroadcastTransaction = ({
|
|
41
41
|
postSwapAccepted({
|
42
42
|
provider,
|
43
43
|
swapId,
|
44
|
-
transactionId: operation.hash,
|
44
|
+
transactionId: typeof operation === "string" ? operation : operation.hash,
|
45
45
|
sourceCurrencyId,
|
46
46
|
targetCurrencyId,
|
47
47
|
hardwareWalletType,
|
@@ -0,0 +1,234 @@
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
2
|
+
|
3
|
+
import {
|
4
|
+
CosmosTransaction,
|
5
|
+
ElrondTransaction,
|
6
|
+
RippleTransaction,
|
7
|
+
SolanaTransaction,
|
8
|
+
StellarTransaction,
|
9
|
+
TonTransaction,
|
10
|
+
Transaction,
|
11
|
+
TransactionCommon,
|
12
|
+
} from "@ledgerhq/wallet-api-client";
|
13
|
+
|
14
|
+
export type { SwapLiveError } from "@ledgerhq/wallet-api-exchange-module";
|
15
|
+
|
16
|
+
export function defaultTransaction({
|
17
|
+
family,
|
18
|
+
amount,
|
19
|
+
recipient,
|
20
|
+
customFeeConfig,
|
21
|
+
}: TransactionWithCustomFee): Transaction {
|
22
|
+
return <Transaction>{
|
23
|
+
family,
|
24
|
+
amount,
|
25
|
+
recipient,
|
26
|
+
...customFeeConfig,
|
27
|
+
};
|
28
|
+
}
|
29
|
+
|
30
|
+
export function modeSendTransaction({
|
31
|
+
family,
|
32
|
+
amount,
|
33
|
+
recipient,
|
34
|
+
customFeeConfig,
|
35
|
+
}: TransactionWithCustomFee): Transaction {
|
36
|
+
return {
|
37
|
+
...defaultTransaction({ family, amount, recipient, customFeeConfig }),
|
38
|
+
mode: "send",
|
39
|
+
};
|
40
|
+
}
|
41
|
+
|
42
|
+
export function stellarTransaction({
|
43
|
+
family,
|
44
|
+
amount,
|
45
|
+
recipient,
|
46
|
+
customFeeConfig,
|
47
|
+
payinExtraId,
|
48
|
+
customErrorType,
|
49
|
+
}: TransactionWithCustomFee): StellarTransaction {
|
50
|
+
if (!payinExtraId)
|
51
|
+
throw {
|
52
|
+
error: new Error("Missing payinExtraId"),
|
53
|
+
step: "PayinExtraIdStepError",
|
54
|
+
customErrorType,
|
55
|
+
};
|
56
|
+
|
57
|
+
return {
|
58
|
+
...defaultTransaction({ family, amount, recipient, customFeeConfig }),
|
59
|
+
family: "stellar",
|
60
|
+
memoValue: payinExtraId,
|
61
|
+
memoType: "MEMO_TEXT",
|
62
|
+
};
|
63
|
+
}
|
64
|
+
|
65
|
+
export function rippleTransaction({
|
66
|
+
amount,
|
67
|
+
recipient,
|
68
|
+
customFeeConfig,
|
69
|
+
payinExtraId,
|
70
|
+
customErrorType,
|
71
|
+
}: TransactionWithCustomFee): RippleTransaction {
|
72
|
+
if (!payinExtraId)
|
73
|
+
throw {
|
74
|
+
error: new Error("Missing payinExtraId"),
|
75
|
+
step: "PayinExtraIdStepError",
|
76
|
+
customErrorType,
|
77
|
+
};
|
78
|
+
|
79
|
+
const transaction: RippleTransaction = {
|
80
|
+
family: "ripple",
|
81
|
+
amount,
|
82
|
+
recipient,
|
83
|
+
...customFeeConfig,
|
84
|
+
tag: new BigNumber(payinExtraId).toNumber(),
|
85
|
+
};
|
86
|
+
return transaction;
|
87
|
+
}
|
88
|
+
|
89
|
+
// Function to remove gasLimit from customFeeConfig for Ethereum or Bitcoin
|
90
|
+
export function withoutGasLimitTransaction({
|
91
|
+
family,
|
92
|
+
amount,
|
93
|
+
recipient,
|
94
|
+
customFeeConfig,
|
95
|
+
extraTransactionParameters,
|
96
|
+
}: TransactionWithCustomFee): Transaction {
|
97
|
+
if (customFeeConfig?.gasLimit) {
|
98
|
+
delete customFeeConfig.gasLimit;
|
99
|
+
}
|
100
|
+
|
101
|
+
if (extraTransactionParameters) {
|
102
|
+
return <Transaction>{
|
103
|
+
family,
|
104
|
+
amount,
|
105
|
+
recipient,
|
106
|
+
...customFeeConfig,
|
107
|
+
data: Buffer.from(extraTransactionParameters, "hex"),
|
108
|
+
};
|
109
|
+
}
|
110
|
+
return defaultTransaction({ family, amount, recipient, customFeeConfig });
|
111
|
+
}
|
112
|
+
|
113
|
+
export function bitcoinTransaction({
|
114
|
+
amount,
|
115
|
+
recipient,
|
116
|
+
customFeeConfig,
|
117
|
+
extraTransactionParameters,
|
118
|
+
}: TransactionWithCustomFee): Transaction {
|
119
|
+
if (extraTransactionParameters) {
|
120
|
+
return {
|
121
|
+
family: "bitcoin",
|
122
|
+
amount,
|
123
|
+
recipient,
|
124
|
+
...customFeeConfig,
|
125
|
+
opReturnData: Buffer.from(extraTransactionParameters, "utf-8"),
|
126
|
+
};
|
127
|
+
}
|
128
|
+
return {
|
129
|
+
family: "bitcoin",
|
130
|
+
amount,
|
131
|
+
recipient,
|
132
|
+
...customFeeConfig,
|
133
|
+
};
|
134
|
+
}
|
135
|
+
|
136
|
+
export function solanaTransaction({
|
137
|
+
family,
|
138
|
+
amount,
|
139
|
+
recipient,
|
140
|
+
customFeeConfig,
|
141
|
+
}: TransactionWithCustomFee): SolanaTransaction {
|
142
|
+
return {
|
143
|
+
...defaultTransaction({ family, amount, recipient, customFeeConfig }),
|
144
|
+
family: "solana",
|
145
|
+
model: { kind: "transfer", uiState: {} },
|
146
|
+
};
|
147
|
+
}
|
148
|
+
|
149
|
+
export function elrondTransaction({
|
150
|
+
amount,
|
151
|
+
recipient,
|
152
|
+
customFeeConfig,
|
153
|
+
}: TransactionWithCustomFee): ElrondTransaction {
|
154
|
+
const transaction: ElrondTransaction = {
|
155
|
+
family: "elrond",
|
156
|
+
amount,
|
157
|
+
recipient,
|
158
|
+
mode: "send",
|
159
|
+
...customFeeConfig,
|
160
|
+
gasLimit: 0, // FIXME: Placeholder, adjust as needed
|
161
|
+
};
|
162
|
+
return transaction;
|
163
|
+
}
|
164
|
+
|
165
|
+
function tonTransaction({
|
166
|
+
family,
|
167
|
+
amount,
|
168
|
+
recipient,
|
169
|
+
customFeeConfig,
|
170
|
+
}: TransactionWithCustomFee): TonTransaction {
|
171
|
+
return {
|
172
|
+
...defaultTransaction({ family, amount, recipient, customFeeConfig }),
|
173
|
+
family: "ton",
|
174
|
+
comment: { isEncrypted: false, text: "" },
|
175
|
+
fees: new BigNumber(0), // Set default value as completeExchange call prepareTransaction, which set again fees.
|
176
|
+
};
|
177
|
+
}
|
178
|
+
|
179
|
+
export function cosmosTransaction({
|
180
|
+
family,
|
181
|
+
amount,
|
182
|
+
recipient,
|
183
|
+
customFeeConfig,
|
184
|
+
payinExtraId,
|
185
|
+
}: TransactionWithCustomFee): CosmosTransaction {
|
186
|
+
return <CosmosTransaction>{
|
187
|
+
...defaultTransaction({ family, amount, recipient, customFeeConfig }),
|
188
|
+
family: "cosmos",
|
189
|
+
mode: "send",
|
190
|
+
memo: payinExtraId ?? undefined,
|
191
|
+
};
|
192
|
+
}
|
193
|
+
|
194
|
+
export type TransactionWithCustomFee = TransactionCommon & {
|
195
|
+
customFeeConfig: {
|
196
|
+
[key: string]: BigNumber;
|
197
|
+
};
|
198
|
+
payinExtraId?: string;
|
199
|
+
customErrorType?: "swap";
|
200
|
+
extraTransactionParameters?: string;
|
201
|
+
};
|
202
|
+
|
203
|
+
// Define a specific type for the strategy functions, assuming they might need parameters
|
204
|
+
export type TransactionStrategyFunction = (params: TransactionWithCustomFee) => Transaction;
|
205
|
+
|
206
|
+
export const transactionStrategy: {
|
207
|
+
[K in Transaction["family"]]: TransactionStrategyFunction;
|
208
|
+
} = {
|
209
|
+
algorand: defaultTransaction,
|
210
|
+
aptos: defaultTransaction,
|
211
|
+
bitcoin: bitcoinTransaction,
|
212
|
+
cardano: modeSendTransaction,
|
213
|
+
celo: defaultTransaction,
|
214
|
+
cosmos: cosmosTransaction,
|
215
|
+
crypto_org: defaultTransaction,
|
216
|
+
elrond: elrondTransaction,
|
217
|
+
ethereum: withoutGasLimitTransaction,
|
218
|
+
filecoin: defaultTransaction,
|
219
|
+
hedera: defaultTransaction,
|
220
|
+
near: modeSendTransaction,
|
221
|
+
neo: defaultTransaction,
|
222
|
+
polkadot: defaultTransaction,
|
223
|
+
ripple: rippleTransaction,
|
224
|
+
solana: solanaTransaction,
|
225
|
+
stacks: defaultTransaction,
|
226
|
+
stellar: stellarTransaction,
|
227
|
+
tezos: modeSendTransaction,
|
228
|
+
ton: tonTransaction,
|
229
|
+
tron: modeSendTransaction,
|
230
|
+
vechain: defaultTransaction,
|
231
|
+
casper: defaultTransaction,
|
232
|
+
sui: defaultTransaction,
|
233
|
+
internet_computer: defaultTransaction,
|
234
|
+
};
|
@@ -4,6 +4,7 @@ import { Account, AccountLike, AccountRaw, AccountRawLike, Operation } from "@le
|
|
4
4
|
import { BigNumber } from "bignumber.js";
|
5
5
|
import { Result as UseBridgeTransactionResult } from "../../bridge/useBridgeTransaction";
|
6
6
|
import { Transaction, TransactionRaw } from "../../generated/types";
|
7
|
+
|
7
8
|
export type { SwapLiveError } from "@ledgerhq/wallet-api-exchange-module";
|
8
9
|
|
9
10
|
export type ExchangeSwap = {
|
@@ -336,3 +337,65 @@ export type SwapTransactionType = UseBridgeTransactionResult & {
|
|
336
337
|
fromAmountError?: Error;
|
337
338
|
fromAmountWarning?: Error;
|
338
339
|
};
|
340
|
+
|
341
|
+
export type SwapPayloadRequestData = {
|
342
|
+
provider: string;
|
343
|
+
deviceTransactionId: string;
|
344
|
+
fromAccountAddress: string;
|
345
|
+
toAccountAddress: string;
|
346
|
+
fromAccountCurrency: string;
|
347
|
+
toAccountCurrency: string;
|
348
|
+
amount: string;
|
349
|
+
amountInAtomicUnit: number;
|
350
|
+
quoteId?: string;
|
351
|
+
toNewTokenId?: string;
|
352
|
+
};
|
353
|
+
export type SwapPayloadResponse = {
|
354
|
+
binaryPayload: string;
|
355
|
+
signature: string;
|
356
|
+
payinAddress: string;
|
357
|
+
swapId: string;
|
358
|
+
payinExtraId?: string;
|
359
|
+
extraTransactionParameters?: string;
|
360
|
+
};
|
361
|
+
|
362
|
+
export type ConfirmSwapRequest = {
|
363
|
+
provider: string;
|
364
|
+
swapId: string;
|
365
|
+
transactionId: string;
|
366
|
+
sourceCurrencyId?: string;
|
367
|
+
targetCurrencyId?: string;
|
368
|
+
hardwareWalletType?: string;
|
369
|
+
};
|
370
|
+
|
371
|
+
export type CancelSwapRequest = {
|
372
|
+
provider: string;
|
373
|
+
swapId: string;
|
374
|
+
statusCode?: string;
|
375
|
+
errorMessage?: string;
|
376
|
+
sourceCurrencyId?: string;
|
377
|
+
targetCurrencyId?: string;
|
378
|
+
hardwareWalletType?: string;
|
379
|
+
swapType?: string;
|
380
|
+
swapStep?: string;
|
381
|
+
};
|
382
|
+
|
383
|
+
export type SwapBackendResponse = {
|
384
|
+
provider: string;
|
385
|
+
swapId: string;
|
386
|
+
apiExtraFee: number;
|
387
|
+
apiFee: number;
|
388
|
+
refundAddress: string;
|
389
|
+
amountExpectedFrom: number;
|
390
|
+
amountExpectedTo: number;
|
391
|
+
status: string;
|
392
|
+
from: string;
|
393
|
+
to: string;
|
394
|
+
payinAddress: string;
|
395
|
+
payoutAddress: string;
|
396
|
+
createdAt: string; // ISO-8601
|
397
|
+
binaryPayload: string;
|
398
|
+
signature: string;
|
399
|
+
payinExtraId?: string;
|
400
|
+
extraTransactionParameters?: string;
|
401
|
+
};
|
@@ -131,4 +131,55 @@ describe("useAppVersionBlockCheck", () => {
|
|
131
131
|
},
|
132
132
|
);
|
133
133
|
});
|
134
|
+
describe("LLD", () => {
|
135
|
+
it.each([
|
136
|
+
["windows", "2.110.9"],
|
137
|
+
["windows", "2.110.4-next.9"],
|
138
|
+
["macOS", "2.0.112"],
|
139
|
+
["macOS", "2.099.122-next.8"],
|
140
|
+
["linux", "1.9.33"],
|
141
|
+
["linux", "1.9.33-next.1"],
|
142
|
+
])("should not update on %s from app version version %s", (platform, appVersion) => {
|
143
|
+
// given
|
144
|
+
const getConfigValue = () => ({
|
145
|
+
lld: {
|
146
|
+
[platform]: "1.9.33",
|
147
|
+
},
|
148
|
+
});
|
149
|
+
// when
|
150
|
+
const { shouldUpdate } = useAppVersionBlockCheck({
|
151
|
+
appVersion,
|
152
|
+
platform: platform as "windows" | "macOS" | "linux",
|
153
|
+
appKey: "lld",
|
154
|
+
getConfigValue,
|
155
|
+
});
|
156
|
+
// then
|
157
|
+
expect(shouldUpdate).toBe(false);
|
158
|
+
});
|
159
|
+
|
160
|
+
it.each([
|
161
|
+
["windows", "2.110.9"],
|
162
|
+
["windows", "2.110.4-next.9"],
|
163
|
+
["macOS", "2.0.112"],
|
164
|
+
["macOS", "2.99.122-next.8"],
|
165
|
+
["linux", "1.9.33"],
|
166
|
+
["linux", "1.9.33-next.1"],
|
167
|
+
])("should update on %s from app version version %s", (platform, appVersion) => {
|
168
|
+
// given
|
169
|
+
const getConfigValue = () => ({
|
170
|
+
lld: {
|
171
|
+
[platform]: "2.111.5-next.9",
|
172
|
+
},
|
173
|
+
});
|
174
|
+
// when
|
175
|
+
const { shouldUpdate } = useAppVersionBlockCheck({
|
176
|
+
appVersion,
|
177
|
+
platform: platform as "windows" | "macOS" | "linux",
|
178
|
+
appKey: "lld",
|
179
|
+
getConfigValue,
|
180
|
+
});
|
181
|
+
// then
|
182
|
+
expect(shouldUpdate).toBe(true);
|
183
|
+
});
|
184
|
+
});
|
134
185
|
});
|
@@ -18,25 +18,6 @@ type LLMinVersionConfig = {
|
|
18
18
|
};
|
19
19
|
};
|
20
20
|
|
21
|
-
const checkLLmVersion = (
|
22
|
-
appVersion: string,
|
23
|
-
osVersion: string,
|
24
|
-
platform: "ios" | "android",
|
25
|
-
llmMinVersionConfig: LLMinVersionConfig["llm"],
|
26
|
-
) => {
|
27
|
-
if (!llmMinVersionConfig[platform]) {
|
28
|
-
return false;
|
29
|
-
}
|
30
|
-
|
31
|
-
return llmMinVersionConfig[platform]
|
32
|
-
.filter(minVersionConfig =>
|
33
|
-
semver.satisfies(semver.coerce(osVersion), `>=${minVersionConfig.minOsVersion}`),
|
34
|
-
)
|
35
|
-
.reduce((acc, curr) => {
|
36
|
-
return acc || semver.satisfies(appVersion, `<${curr.version}`);
|
37
|
-
}, false);
|
38
|
-
};
|
39
|
-
|
40
21
|
export const useAppVersionBlockCheck = ({
|
41
22
|
appVersion: uncoercedAppVersion,
|
42
23
|
appKey,
|
@@ -50,16 +31,29 @@ export const useAppVersionBlockCheck = ({
|
|
50
31
|
platform: "ios" | "android" | "macOS" | "windows" | "linux";
|
51
32
|
getConfigValue?: typeof LiveConfig.getValueByKey;
|
52
33
|
}) => {
|
53
|
-
const llMinVersionConfig = getConfigValue("config_ll_min_version");
|
34
|
+
const llMinVersionConfig: LLMinVersionConfig = getConfigValue("config_ll_min_version");
|
54
35
|
const appVersion = semver.coerce(uncoercedAppVersion)?.version || "";
|
55
36
|
let shouldUpdate = false;
|
56
37
|
|
57
|
-
if (!llMinVersionConfig) {
|
38
|
+
if (!llMinVersionConfig || !llMinVersionConfig[appKey][platform]) {
|
58
39
|
return { shouldUpdate };
|
59
40
|
}
|
60
|
-
|
61
41
|
if (appKey === "llm" && (platform === "android" || platform === "ios") && osVersion) {
|
62
|
-
shouldUpdate =
|
42
|
+
shouldUpdate = llMinVersionConfig[appKey][platform]
|
43
|
+
.filter(minVersionConfig =>
|
44
|
+
semver.satisfies(semver.coerce(osVersion), `>=${minVersionConfig.minOsVersion}`),
|
45
|
+
)
|
46
|
+
.reduce((acc, curr) => {
|
47
|
+
return acc || semver.satisfies(appVersion, `<${semver.coerce(curr.version)}`);
|
48
|
+
}, false);
|
49
|
+
} else if (
|
50
|
+
appKey === "lld" &&
|
51
|
+
(platform === "windows" || platform === "macOS" || platform === "linux")
|
52
|
+
) {
|
53
|
+
shouldUpdate = semver.satisfies(
|
54
|
+
appVersion,
|
55
|
+
`<${semver.coerce(llMinVersionConfig[appKey][platform])}`,
|
56
|
+
);
|
63
57
|
}
|
64
58
|
return { shouldUpdate };
|
65
59
|
};
|
@@ -1,14 +1,14 @@
|
|
1
|
-
import {
|
2
|
-
import { AppBranch, AppPlatform, Visibility } from "../types";
|
3
|
-
import { of } from "rxjs";
|
1
|
+
import { RpcRequest } from "@ledgerhq/wallet-api-core";
|
4
2
|
import {
|
5
3
|
ExchangeStartParams,
|
6
4
|
ExchangeStartSellParams,
|
7
5
|
ExchangeStartSwapParams,
|
8
6
|
} from "@ledgerhq/wallet-api-exchange-module";
|
9
|
-
import { RpcRequest } from "@ledgerhq/wallet-api-core";
|
10
|
-
import { genAccount } from "../../mock/account";
|
11
7
|
import { WalletContext, WalletHandlers } from "@ledgerhq/wallet-api-server";
|
8
|
+
import { of } from "rxjs";
|
9
|
+
import { genAccount } from "../../mock/account";
|
10
|
+
import { AppBranch, AppPlatform, Visibility } from "../types";
|
11
|
+
import { handlers } from "./server";
|
12
12
|
|
13
13
|
const mockTracking = {
|
14
14
|
startExchangeRequested: jest.fn(),
|
@@ -46,6 +46,7 @@ const testAppManifest = {
|
|
46
46
|
|
47
47
|
const mockUiStartExchange = jest.fn();
|
48
48
|
const mockUiCompleteExchange = jest.fn();
|
49
|
+
const mockUiSwap = jest.fn();
|
49
50
|
const mockUiError = jest.fn();
|
50
51
|
const mockIsReady = jest.fn();
|
51
52
|
|
@@ -54,6 +55,7 @@ const mockUiHooks = {
|
|
54
55
|
"custom.exchange.complete": mockUiCompleteExchange,
|
55
56
|
"custom.exchange.error": mockUiError,
|
56
57
|
"custom.isReady": mockIsReady,
|
58
|
+
"custom.exchange.swap": mockUiSwap,
|
57
59
|
};
|
58
60
|
|
59
61
|
// Mock converter id to send back the id received in params.
|