@ledgerhq/live-common 34.40.0-nightly.1 → 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/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/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/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/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 +4 -4
- 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/wallet-api/Exchange/server.test.ts +7 -5
- package/src/wallet-api/Exchange/server.ts +335 -32
@@ -1,6 +1,6 @@
|
|
1
|
-
import { handlers } from "./server";
|
2
1
|
import { of } from "rxjs";
|
3
2
|
import { genAccount } from "../../mock/account";
|
3
|
+
import { handlers } from "./server";
|
4
4
|
const mockTracking = {
|
5
5
|
startExchangeRequested: jest.fn(),
|
6
6
|
startExchangeSuccess: jest.fn(),
|
@@ -36,6 +36,7 @@ const testAppManifest = {
|
|
36
36
|
};
|
37
37
|
const mockUiStartExchange = jest.fn();
|
38
38
|
const mockUiCompleteExchange = jest.fn();
|
39
|
+
const mockUiSwap = jest.fn();
|
39
40
|
const mockUiError = jest.fn();
|
40
41
|
const mockIsReady = jest.fn();
|
41
42
|
const mockUiHooks = {
|
@@ -43,6 +44,7 @@ const mockUiHooks = {
|
|
43
44
|
"custom.exchange.complete": mockUiCompleteExchange,
|
44
45
|
"custom.exchange.error": mockUiError,
|
45
46
|
"custom.isReady": mockIsReady,
|
47
|
+
"custom.exchange.swap": mockUiSwap,
|
46
48
|
};
|
47
49
|
// Mock converter id to send back the id received in params.
|
48
50
|
jest.mock("../converters", () => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"server.test.js","sourceRoot":"","sources":["../../../src/wallet-api/Exchange/server.test.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"server.test.js","sourceRoot":"","sources":["../../../src/wallet-api/Exchange/server.test.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,MAAM,YAAY,GAAG;IACnB,sBAAsB,EAAE,IAAI,CAAC,EAAE,EAAE;IACjC,oBAAoB,EAAE,IAAI,CAAC,EAAE,EAAE;IAC/B,iBAAiB,EAAE,IAAI,CAAC,EAAE,EAAE;IAC5B,qBAAqB,EAAE,IAAI,CAAC,EAAE,EAAE;IAChC,yBAAyB,EAAE,IAAI,CAAC,EAAE,EA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QAAQ;YAChB,QAAQ,EAAE,KAAK;YACf,MAAM,EAAE;gBACN,IAAI,EAAE,aAAa;gBACnB,OAAO,EAAE,GAAG;aACb;YACD,KAAK,EAAE,OAAO;SACf;KACF,CAAC;IAEF,OAAO;QACL,OAAO;QACP,OAAO;QACP,cAAc,EAAE,EAAE;KACnB,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,MAA2B;IACrD,MAAM,OAAO,GAA4C;QACvD,OAAO,EAAE,KAAK;QACd,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE,MAAM;QACd,EAAE,EAAE,kBAAkB;KACvB,CAAC;IAEF,MAAM,OAAO,GAAG;QACd,WAAW,EAAE,EAAE,CAAC,EAAE,CAAC;QACnB,SAAS,EAAE,EAAE,CAAC,EAAE,CAAC;QACjB,MAAM,EAAE;YACN,MAAM,EAAE,QAAQ;YAChB,QAAQ,EAAE,KAAK;YACf,MAAM,EAAE;gBACN,IAAI,EAAE,aAAa;gBACnB,OAAO,EAAE,GAAG;aACb;YACD,KAAK,EAAE,OAAO;SACf;KACF,CAAC;IAEF,OAAO;QACL,OAAO;QACP,OAAO;QACP,cAAc,EAAE,EAAE;KACnB,CAAC;AACJ,CAAC"}
|
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.40.0-nightly.
|
4
|
+
"version": "34.40.0-nightly.2",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
7
7
|
"url": "https://github.com/LedgerHQ/ledger-live.git"
|
@@ -173,7 +173,7 @@
|
|
173
173
|
"@ledgerhq/coin-filecoin": "^1.9.12-nightly.1",
|
174
174
|
"@ledgerhq/coin-framework": "^5.5.0-nightly.1",
|
175
175
|
"@ledgerhq/coin-hedera": "^1.8.1-nightly.1",
|
176
|
-
"@ledgerhq/coin-icon": "^0.
|
176
|
+
"@ledgerhq/coin-icon": "^0.11.0-nightly.2",
|
177
177
|
"@ledgerhq/coin-internet_computer": "^1.7.12-nightly.1",
|
178
178
|
"@ledgerhq/coin-mina": "^1.1.11-nightly.1",
|
179
179
|
"@ledgerhq/coin-multiversx": "^0.4.12-nightly.1",
|
@@ -188,7 +188,7 @@
|
|
188
188
|
"@ledgerhq/coin-tron": "^4.4.0-nightly.1",
|
189
189
|
"@ledgerhq/coin-vechain": "^2.7.12-nightly.1",
|
190
190
|
"@ledgerhq/coin-xrp": "^6.3.0-nightly.1",
|
191
|
-
"@ledgerhq/crypto-icons-ui": "^1.
|
191
|
+
"@ledgerhq/crypto-icons-ui": "^1.16.0-nightly.0",
|
192
192
|
"@ledgerhq/cryptoassets": "^13.21.0-nightly.1",
|
193
193
|
"@ledgerhq/device-core": "^0.5.0",
|
194
194
|
"@ledgerhq/devices": "8.4.7",
|
@@ -229,7 +229,7 @@
|
|
229
229
|
"@ledgerhq/logs": "^6.13.0",
|
230
230
|
"@ledgerhq/speculos-transport": "^0.2.5",
|
231
231
|
"@ledgerhq/wallet-api-acre-module": "^0.5.0",
|
232
|
-
"@ledgerhq/wallet-api-exchange-module": "^0.
|
232
|
+
"@ledgerhq/wallet-api-exchange-module": "^0.14.0-nightly.0"
|
233
233
|
},
|
234
234
|
"devDependencies": {
|
235
235
|
"@solana/web3.js": "1.95.4",
|
package/src/exchange/error.ts
CHANGED
@@ -31,3 +31,13 @@ export function convertTransportError(
|
|
31
31
|
}
|
32
32
|
return err;
|
33
33
|
}
|
34
|
+
|
35
|
+
export function getSwapStepFromError(error: Error): string {
|
36
|
+
if ((error as CompleteExchangeError).step) {
|
37
|
+
return (error as CompleteExchangeError).step;
|
38
|
+
} else if (error.name === "DisabledTransactionBroadcastError") {
|
39
|
+
return "SIGN_COIN_TRANSACTION";
|
40
|
+
}
|
41
|
+
|
42
|
+
return "UNKNOWN_STEP";
|
43
|
+
}
|
@@ -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
|
+
};
|
@@ -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.
|