@ledgerhq/live-common 24.0.0-next.0 → 24.0.0-next.3
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/env.d.ts +16 -6
- package/lib/env.d.ts.map +1 -1
- package/lib/env.js +11 -1
- package/lib/env.js.map +1 -1
- package/lib/env.react.d.ts +1 -1
- package/lib/env.react.d.ts.map +1 -1
- package/lib/errors.d.ts +0 -3
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +2 -3
- package/lib/errors.js.map +1 -1
- package/lib/exchange/index.d.ts +5 -0
- package/lib/exchange/index.d.ts.map +1 -1
- package/lib/exchange/index.js.map +1 -1
- package/lib/exchange/swap/checkQuote.d.ts +4 -0
- package/lib/exchange/swap/checkQuote.d.ts.map +1 -0
- package/lib/exchange/swap/checkQuote.js +80 -0
- package/lib/exchange/swap/checkQuote.js.map +1 -0
- package/lib/exchange/swap/checkQuote.test.d.ts +2 -0
- package/lib/exchange/swap/checkQuote.test.d.ts.map +1 -0
- package/lib/exchange/swap/checkQuote.test.js +103 -0
- package/lib/exchange/swap/checkQuote.test.js.map +1 -0
- package/lib/exchange/swap/completeExchange.d.ts.map +1 -1
- package/lib/exchange/swap/completeExchange.js +9 -9
- package/lib/exchange/swap/completeExchange.js.map +1 -1
- package/lib/exchange/swap/getExchangeRates.d.ts.map +1 -1
- package/lib/exchange/swap/getExchangeRates.js +3 -1
- package/lib/exchange/swap/getExchangeRates.js.map +1 -1
- package/lib/exchange/swap/getProviders.d.ts.map +1 -1
- package/lib/exchange/swap/getProviders.js +10 -4
- package/lib/exchange/swap/getProviders.js.map +1 -1
- package/lib/exchange/swap/getStatus.d.ts +1 -3
- package/lib/exchange/swap/getStatus.d.ts.map +1 -1
- package/lib/exchange/swap/getStatus.js +2 -30
- package/lib/exchange/swap/getStatus.js.map +1 -1
- package/lib/exchange/swap/hooks/useProviderRates.d.ts +3 -4
- package/lib/exchange/swap/hooks/useProviderRates.d.ts.map +1 -1
- package/lib/exchange/swap/hooks/useProviderRates.js +35 -5
- package/lib/exchange/swap/hooks/useProviderRates.js.map +1 -1
- package/lib/exchange/swap/hooks/useProviderRates.test.js +106 -1
- package/lib/exchange/swap/hooks/useProviderRates.test.js.map +1 -1
- package/lib/exchange/swap/hooks/useSwapTransaction.d.ts +5 -4
- package/lib/exchange/swap/hooks/useSwapTransaction.d.ts.map +1 -1
- package/lib/exchange/swap/hooks/useSwapTransaction.js +6 -6
- package/lib/exchange/swap/hooks/useSwapTransaction.js.map +1 -1
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts +4 -3
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts.map +1 -1
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.js +8 -5
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.js.map +1 -1
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js +35 -4
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js.map +1 -1
- package/lib/exchange/swap/index.d.ts +10 -8
- package/lib/exchange/swap/index.d.ts.map +1 -1
- package/lib/exchange/swap/index.js +43 -18
- package/lib/exchange/swap/index.js.map +1 -1
- package/lib/exchange/swap/index.test.d.ts +2 -0
- package/lib/exchange/swap/index.test.d.ts.map +1 -0
- package/lib/exchange/swap/index.test.js +30 -0
- package/lib/exchange/swap/index.test.js.map +1 -0
- package/lib/exchange/swap/initSwap.d.ts +1 -1
- package/lib/exchange/swap/initSwap.d.ts.map +1 -1
- package/lib/exchange/swap/initSwap.js +30 -25
- package/lib/exchange/swap/initSwap.js.map +1 -1
- package/lib/exchange/swap/mock.d.ts +5 -2
- package/lib/exchange/swap/mock.d.ts.map +1 -1
- package/lib/exchange/swap/mock.js +127 -6
- package/lib/exchange/swap/mock.js.map +1 -1
- package/lib/exchange/swap/postSwapState.d.ts +4 -0
- package/lib/exchange/swap/postSwapState.d.ts.map +1 -0
- package/lib/exchange/swap/postSwapState.js +121 -0
- package/lib/exchange/swap/postSwapState.js.map +1 -0
- package/lib/exchange/swap/types.d.ts +30 -2
- package/lib/exchange/swap/types.d.ts.map +1 -1
- package/lib/exchange/swap/updateAccountSwapStatus.d.ts.map +1 -1
- package/lib/exchange/swap/updateAccountSwapStatus.js +2 -2
- package/lib/exchange/swap/updateAccountSwapStatus.js.map +1 -1
- package/lib/exchange/swap/utils/index.d.ts +19 -2
- package/lib/exchange/swap/utils/index.d.ts.map +1 -1
- package/lib/exchange/swap/utils/index.js +96 -20
- package/lib/exchange/swap/utils/index.js.map +1 -1
- package/lib/exchange/swap/utils/index.test.js +95 -48
- package/lib/exchange/swap/utils/index.test.js.map +1 -1
- package/lib/families/ethereum/modules/erc1155.d.ts.map +1 -1
- package/lib/families/ethereum/modules/erc1155.js +5 -1
- package/lib/families/ethereum/modules/erc1155.js.map +1 -1
- package/lib/families/ethereum/modules/erc721.d.ts.map +1 -1
- package/lib/families/ethereum/modules/erc721.js +5 -0
- package/lib/families/ethereum/modules/erc721.js.map +1 -1
- package/lib/families/ethereum/nft.unit.test.js +35 -15
- package/lib/families/ethereum/nft.unit.test.js.map +1 -1
- package/lib/families/ethereum/synchronisation.d.ts.map +1 -1
- package/lib/families/ethereum/synchronisation.js +17 -13
- package/lib/families/ethereum/synchronisation.js.map +1 -1
- package/lib/families/solana/api/chain/account/token.d.ts +1 -1
- package/lib/families/solana/api/chain/account/vote.d.ts +12 -12
- package/lib/families/solana/api/chain/instruction/system/types.d.ts +4 -4
- package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
- package/lib/featureFlags/defaultFeatures.js +3 -0
- package/lib/featureFlags/defaultFeatures.js.map +1 -1
- package/lib/featureFlags/types.d.ts +1 -1
- package/lib/featureFlags/types.d.ts.map +1 -1
- package/lib/hw/actions/initSwap.d.ts +4 -3
- package/lib/hw/actions/initSwap.d.ts.map +1 -1
- package/lib/hw/actions/initSwap.js +7 -5
- package/lib/hw/actions/initSwap.js.map +1 -1
- package/lib/nft/hook.d.ts +3 -0
- package/lib/nft/hook.d.ts.map +1 -0
- package/lib/nft/hook.js +73 -0
- package/lib/nft/hook.js.map +1 -0
- package/lib/nft/index.d.ts +1 -0
- package/lib/nft/index.d.ts.map +1 -1
- package/lib/nft/index.js +1 -0
- package/lib/nft/index.js.map +1 -1
- package/lib/nft/nftOperationId.d.ts +15 -0
- package/lib/nft/nftOperationId.d.ts.map +1 -0
- package/lib/nft/nftOperationId.js +50 -0
- package/lib/nft/nftOperationId.js.map +1 -0
- package/lib/operation.d.ts +1 -1
- package/lib/operation.d.ts.map +1 -1
- package/lib/operation.js +23 -1
- package/lib/operation.js.map +1 -1
- package/lib/types/nft.d.ts +4 -0
- package/lib/types/nft.d.ts.map +1 -1
- package/package.json +4 -1
- package/src/env.ts +12 -2
- package/src/errors.ts +0 -1
- package/src/exchange/index.ts +7 -0
- package/src/exchange/swap/checkQuote.test.ts +53 -0
- package/src/exchange/swap/checkQuote.ts +34 -0
- package/src/exchange/swap/completeExchange.ts +9 -11
- package/src/exchange/swap/getExchangeRates.ts +5 -3
- package/src/exchange/swap/getProviders.ts +12 -4
- package/src/exchange/swap/getStatus.ts +2 -12
- package/src/exchange/swap/hooks/useProviderRates.test.ts +103 -1
- package/src/exchange/swap/hooks/useProviderRates.ts +57 -9
- package/src/exchange/swap/hooks/useSwapTransaction.ts +14 -13
- package/src/exchange/swap/hooks/useUpdateMaxAmount.test.ts +31 -4
- package/src/exchange/swap/hooks/useUpdateMaxAmount.ts +13 -7
- package/src/exchange/swap/index.test.ts +36 -0
- package/src/exchange/swap/index.ts +51 -30
- package/src/exchange/swap/initSwap.ts +54 -40
- package/src/exchange/swap/mock.ts +128 -13
- package/src/exchange/swap/postSwapState.ts +61 -0
- package/src/exchange/swap/types.ts +68 -5
- package/src/exchange/swap/updateAccountSwapStatus.ts +4 -4
- package/src/exchange/swap/utils/index.test.ts +127 -63
- package/src/exchange/swap/utils/index.ts +128 -23
- package/src/families/ethereum/modules/erc1155.ts +12 -5
- package/src/families/ethereum/modules/erc721.ts +11 -0
- package/src/families/ethereum/nft.unit.test.ts +24 -17
- package/src/families/ethereum/synchronisation.ts +22 -18
- package/src/featureFlags/defaultFeatures.ts +3 -0
- package/src/featureFlags/types.ts +1 -0
- package/src/hw/actions/initSwap.ts +20 -9
- package/src/nft/hook.ts +29 -0
- package/src/nft/index.ts +1 -0
- package/src/nft/nftOperationId.ts +47 -0
- package/src/operation.ts +50 -1
- package/src/types/nft.ts +5 -0
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
import { getAbandonSeedAddress } from "@ledgerhq/cryptoassets";
|
|
2
|
+
import { TransportStatusError, WrongDeviceForAccount } from "@ledgerhq/errors";
|
|
2
3
|
import { log } from "@ledgerhq/logs";
|
|
3
|
-
import {
|
|
4
|
-
import secp256k1 from "secp256k1";
|
|
4
|
+
import { BigNumber } from "bignumber.js";
|
|
5
5
|
import invariant from "invariant";
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { mockInitSwap } from "./mock";
|
|
10
|
-
import perFamily from "../../generated/exchange";
|
|
6
|
+
import { from, Observable } from "rxjs";
|
|
7
|
+
import secp256k1 from "secp256k1";
|
|
8
|
+
import { getCurrencyExchangeConfig } from "../";
|
|
11
9
|
import {
|
|
12
10
|
getAccountCurrency,
|
|
13
|
-
getMainAccount,
|
|
14
11
|
getAccountUnit,
|
|
12
|
+
getMainAccount,
|
|
15
13
|
} from "../../account";
|
|
16
|
-
import network from "../../network";
|
|
17
14
|
import { getAccountBridge } from "../../bridge";
|
|
18
|
-
import {
|
|
15
|
+
import { getEnv } from "../../env";
|
|
19
16
|
import { SwapGenericAPIError, TransactionRefusedOnDevice } from "../../errors";
|
|
20
|
-
import
|
|
21
|
-
import { Observable } from "rxjs";
|
|
17
|
+
import perFamily from "../../generated/exchange";
|
|
22
18
|
import { withDevice } from "../../hw/deviceAccess";
|
|
23
|
-
import
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
|
|
19
|
+
import network from "../../network";
|
|
20
|
+
import { delay } from "../../promise";
|
|
21
|
+
import Exchange, {
|
|
22
|
+
ExchangeTypes,
|
|
23
|
+
RateTypes,
|
|
24
|
+
} from "../hw-app-exchange/Exchange";
|
|
25
|
+
import { getProviderConfig, getSwapAPIBaseURL } from "./";
|
|
26
|
+
import { mockInitSwap } from "./mock";
|
|
27
|
+
import type { InitSwapInput, SwapRequestEvent } from "./types";
|
|
27
28
|
|
|
28
29
|
const withDevicePromise = (deviceId, fn) =>
|
|
29
30
|
withDevice(deviceId)((transport) => from(fn(transport))).toPromise();
|
|
@@ -32,14 +33,15 @@ const withDevicePromise = (deviceId, fn) =>
|
|
|
32
33
|
// throw if TransactionStatus have errors
|
|
33
34
|
// you get at the end a final Transaction to be done (it's not yet signed, nor broadcasted!) and a swapId
|
|
34
35
|
const initSwap = (input: InitSwapInput): Observable<SwapRequestEvent> => {
|
|
36
|
+
let swapId;
|
|
35
37
|
let { transaction } = input;
|
|
36
38
|
const { exchange, exchangeRate, deviceId, userId } = input;
|
|
39
|
+
|
|
37
40
|
if (getEnv("MOCK")) return mockInitSwap(exchange, exchangeRate, transaction);
|
|
38
41
|
return new Observable((o) => {
|
|
39
42
|
let unsubscribed = false;
|
|
40
43
|
|
|
41
44
|
const confirmSwap = async () => {
|
|
42
|
-
let swapId;
|
|
43
45
|
let ignoreTransportError;
|
|
44
46
|
log("swap", `attempt to connect to ${deviceId}`);
|
|
45
47
|
await withDevicePromise(deviceId, async (transport) => {
|
|
@@ -70,34 +72,45 @@ const initSwap = (input: InitSwapInput): Observable<SwapRequestEvent> => {
|
|
|
70
72
|
// NB Added the try/catch because of the API stability issues.
|
|
71
73
|
let res;
|
|
72
74
|
|
|
75
|
+
const swapProviderConfig = getProviderConfig(provider);
|
|
76
|
+
|
|
77
|
+
const { needsBearerToken } = swapProviderConfig;
|
|
78
|
+
|
|
79
|
+
const headers = {
|
|
80
|
+
EquipmentId: getEnv("USER_ID"),
|
|
81
|
+
...(needsBearerToken ? { Authorization: `Bearer ${userId}` } : {}),
|
|
82
|
+
...(userId ? { userId } : {}), // NB: only for Wyre AFAIK
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const data = {
|
|
86
|
+
provider,
|
|
87
|
+
amountFrom: apiAmount.toString(),
|
|
88
|
+
from: refundCurrency.id,
|
|
89
|
+
to: payoutCurrency.id,
|
|
90
|
+
address: payoutAccount.freshAddress,
|
|
91
|
+
refundAddress: refundAccount.freshAddress,
|
|
92
|
+
deviceTransactionId,
|
|
93
|
+
...(rateId && ratesFlag === RateTypes.Fixed
|
|
94
|
+
? {
|
|
95
|
+
rateId,
|
|
96
|
+
}
|
|
97
|
+
: {}), // NB float rates dont need rate ids.
|
|
98
|
+
};
|
|
99
|
+
|
|
73
100
|
try {
|
|
74
101
|
res = await network({
|
|
75
102
|
method: "POST",
|
|
76
103
|
url: `${getSwapAPIBaseURL()}/swap`,
|
|
77
|
-
headers
|
|
78
|
-
|
|
79
|
-
...(userId ? { userId } : {}),
|
|
80
|
-
},
|
|
81
|
-
data: {
|
|
82
|
-
provider,
|
|
83
|
-
amountFrom: apiAmount,
|
|
84
|
-
from: refundCurrency.id,
|
|
85
|
-
to: payoutCurrency.id,
|
|
86
|
-
address: payoutAccount.freshAddress,
|
|
87
|
-
refundAddress: refundAccount.freshAddress,
|
|
88
|
-
deviceTransactionId,
|
|
89
|
-
...(rateId
|
|
90
|
-
? {
|
|
91
|
-
rateId,
|
|
92
|
-
}
|
|
93
|
-
: {}), // NB float rates dont need rate ids.
|
|
94
|
-
},
|
|
104
|
+
headers,
|
|
105
|
+
data,
|
|
95
106
|
});
|
|
107
|
+
|
|
96
108
|
if (unsubscribed || !res || !res.data) return;
|
|
97
109
|
} catch (e) {
|
|
98
110
|
o.next({
|
|
99
111
|
type: "init-swap-error",
|
|
100
112
|
error: new SwapGenericAPIError(),
|
|
113
|
+
swapId,
|
|
101
114
|
});
|
|
102
115
|
o.complete();
|
|
103
116
|
return;
|
|
@@ -105,9 +118,7 @@ const initSwap = (input: InitSwapInput): Observable<SwapRequestEvent> => {
|
|
|
105
118
|
|
|
106
119
|
const swapResult = res.data;
|
|
107
120
|
swapId = swapResult.swapId;
|
|
108
|
-
|
|
109
|
-
swapResult.provider
|
|
110
|
-
);
|
|
121
|
+
|
|
111
122
|
const accountBridge = getAccountBridge(refundAccount);
|
|
112
123
|
transaction = accountBridge.updateTransaction(transaction, {
|
|
113
124
|
recipient: swapResult.payinAddress,
|
|
@@ -157,10 +168,12 @@ const initSwap = (input: InitSwapInput): Observable<SwapRequestEvent> => {
|
|
|
157
168
|
}
|
|
158
169
|
|
|
159
170
|
// Prepare swap app to receive the tx to forward.
|
|
160
|
-
await swap.setPartnerKey(
|
|
171
|
+
await swap.setPartnerKey(swapProviderConfig.nameAndPubkey);
|
|
161
172
|
if (unsubscribed) return;
|
|
162
|
-
|
|
173
|
+
|
|
174
|
+
await swap.checkPartner(swapProviderConfig.signature);
|
|
163
175
|
if (unsubscribed) return;
|
|
176
|
+
|
|
164
177
|
await swap.processTransaction(
|
|
165
178
|
Buffer.from(swapResult.binaryPayload, "hex"),
|
|
166
179
|
estimatedFees
|
|
@@ -304,6 +317,7 @@ const initSwap = (input: InitSwapInput): Observable<SwapRequestEvent> => {
|
|
|
304
317
|
o.next({
|
|
305
318
|
type: "init-swap-error",
|
|
306
319
|
error: e,
|
|
320
|
+
swapId,
|
|
307
321
|
});
|
|
308
322
|
o.complete();
|
|
309
323
|
unsubscribed = true;
|
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { Observable, of } from "rxjs";
|
|
3
|
+
import { getAccountUnit } from "../../account";
|
|
4
|
+
import { formatCurrencyUnit } from "../../currencies";
|
|
5
|
+
import { getEnv } from "../../env";
|
|
6
|
+
import {
|
|
7
|
+
SwapExchangeRateAmountTooHigh,
|
|
8
|
+
SwapExchangeRateAmountTooLow,
|
|
9
|
+
} from "../../errors";
|
|
10
|
+
import type { CryptoCurrency, TokenCurrency, Transaction } from "../../types";
|
|
11
|
+
import { getSwapAPIBaseURL } from "./";
|
|
2
12
|
import type {
|
|
13
|
+
CheckQuote,
|
|
3
14
|
Exchange,
|
|
4
15
|
ExchangeRate,
|
|
5
16
|
GetMultipleStatus,
|
|
6
17
|
GetProviders,
|
|
7
18
|
KYCStatus,
|
|
19
|
+
PostSwapAccepted,
|
|
20
|
+
PostSwapCancelled,
|
|
8
21
|
SwapRequestEvent,
|
|
9
22
|
ValidKYCStatus,
|
|
10
23
|
} from "./types";
|
|
11
|
-
import { getAccountUnit } from "../../account";
|
|
12
|
-
import type { Transaction, TokenCurrency, CryptoCurrency } from "../../types";
|
|
13
|
-
import { formatCurrencyUnit } from "../../currencies";
|
|
14
|
-
import {
|
|
15
|
-
SwapExchangeRateAmountTooLow,
|
|
16
|
-
SwapExchangeRateAmountTooHigh,
|
|
17
|
-
} from "../../errors";
|
|
18
|
-
import { Observable, of } from "rxjs";
|
|
19
|
-
import { getSwapAPIBaseURL } from "./";
|
|
20
24
|
|
|
21
25
|
export const getMockExchangeRate = ({
|
|
22
|
-
provider = "
|
|
26
|
+
provider = "ftx",
|
|
23
27
|
tradeMethod = "fixed",
|
|
24
28
|
}: {
|
|
25
29
|
provider?: string;
|
|
@@ -90,7 +94,7 @@ export const mockGetExchangeRates = async (
|
|
|
90
94
|
toAmount: amount.times(magnitudeAwareRate),
|
|
91
95
|
magnitudeAwareRate,
|
|
92
96
|
rateId: "mockedRateId",
|
|
93
|
-
provider: "
|
|
97
|
+
provider: "ftx",
|
|
94
98
|
expirationDate: new Date(),
|
|
95
99
|
tradeMethod: "fixed",
|
|
96
100
|
},
|
|
@@ -99,7 +103,7 @@ export const mockGetExchangeRates = async (
|
|
|
99
103
|
toAmount: amount.times(magnitudeAwareRate),
|
|
100
104
|
magnitudeAwareRate,
|
|
101
105
|
rateId: "mockedRateId",
|
|
102
|
-
provider: "
|
|
106
|
+
provider: "ftx",
|
|
103
107
|
expirationDate: new Date(),
|
|
104
108
|
tradeMethod: "float",
|
|
105
109
|
},
|
|
@@ -126,7 +130,7 @@ export const mockGetProviders: GetProviders = async () => {
|
|
|
126
130
|
return usesV3
|
|
127
131
|
? [
|
|
128
132
|
{
|
|
129
|
-
provider: "
|
|
133
|
+
provider: "ftx",
|
|
130
134
|
pairs: [
|
|
131
135
|
{ from: "bitcoin", to: "ethereum", tradeMethod: "float" },
|
|
132
136
|
{ from: "bitcoin", to: "ethereum", tradeMethod: "fixed" },
|
|
@@ -187,3 +191,114 @@ export const mockGetKYCStatus = async (
|
|
|
187
191
|
await new Promise((r) => setTimeout(r, 2000));
|
|
188
192
|
return { id, status };
|
|
189
193
|
};
|
|
194
|
+
|
|
195
|
+
const mockedCheckQuoteStatusCode = getEnv("MOCK_SWAP_CHECK_QUOTE");
|
|
196
|
+
|
|
197
|
+
export const mockCheckQuote: CheckQuote = async ({
|
|
198
|
+
provider: _provider,
|
|
199
|
+
quoteId: _quoteId,
|
|
200
|
+
bearerToken: _bearerToken,
|
|
201
|
+
}) => {
|
|
202
|
+
//Fake delay to show the pending state in the UI
|
|
203
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
204
|
+
|
|
205
|
+
switch (mockedCheckQuoteStatusCode) {
|
|
206
|
+
case "RATE_VALID":
|
|
207
|
+
return { codeName: mockedCheckQuoteStatusCode };
|
|
208
|
+
|
|
209
|
+
case "KYC_FAILED":
|
|
210
|
+
return {
|
|
211
|
+
codeName: mockedCheckQuoteStatusCode,
|
|
212
|
+
error: "KYC Failed",
|
|
213
|
+
description: "The KYC verification failed",
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
case "KYC_PENDING":
|
|
217
|
+
return {
|
|
218
|
+
codeName: mockedCheckQuoteStatusCode,
|
|
219
|
+
error: "KYC Pending",
|
|
220
|
+
description: "The KYC is pending",
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
case "KYC_UNDEFINED":
|
|
224
|
+
return {
|
|
225
|
+
codeName: mockedCheckQuoteStatusCode,
|
|
226
|
+
error: "KYC undifined",
|
|
227
|
+
description: "The KYC is undifined",
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
case "KYC_UPGRADE_REQUIRED":
|
|
231
|
+
return {
|
|
232
|
+
codeName: mockedCheckQuoteStatusCode,
|
|
233
|
+
error: "KYC upgrade requierd",
|
|
234
|
+
description: "Need to upgrade KYC level",
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
case "MFA_REQUIRED":
|
|
238
|
+
return {
|
|
239
|
+
codeName: mockedCheckQuoteStatusCode,
|
|
240
|
+
error: "MFA requierd",
|
|
241
|
+
description: "Need to enable MFA",
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
case "OVER_TRADE_LIMIT":
|
|
245
|
+
return {
|
|
246
|
+
codeName: mockedCheckQuoteStatusCode,
|
|
247
|
+
error: "Trade over the limit",
|
|
248
|
+
description: "You have reached your trade limit",
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
case "UNKNOW_USER":
|
|
252
|
+
return {
|
|
253
|
+
codeName: mockedCheckQuoteStatusCode,
|
|
254
|
+
error: "Unknown user",
|
|
255
|
+
description: "Provided bearerToken does not match any known user",
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
case "RATE_NOT_FOUND":
|
|
259
|
+
return {
|
|
260
|
+
codeName: mockedCheckQuoteStatusCode,
|
|
261
|
+
error: "Rate not found",
|
|
262
|
+
description: "Rate not found",
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
case "WITHDRAWALS_BLOCKED":
|
|
266
|
+
return {
|
|
267
|
+
codeName: mockedCheckQuoteStatusCode,
|
|
268
|
+
error: "Withdrawals blocked",
|
|
269
|
+
description: "Withdrawals blocked",
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
default:
|
|
273
|
+
return {
|
|
274
|
+
codeName: "UNKNOWN_ERROR",
|
|
275
|
+
error: "Unknown error",
|
|
276
|
+
description: "Something unexpected happened",
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
export const mockPostSwapAccepted: PostSwapAccepted = async ({
|
|
282
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
283
|
+
provider,
|
|
284
|
+
swapId,
|
|
285
|
+
transactionId,
|
|
286
|
+
/* eslint-enable */
|
|
287
|
+
}) => {
|
|
288
|
+
//Fake delay to simulate network
|
|
289
|
+
await new Promise((r) => setTimeout(r, 800));
|
|
290
|
+
|
|
291
|
+
return null;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
export const mockPostSwapCancelled: PostSwapCancelled = async ({
|
|
295
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
296
|
+
provider,
|
|
297
|
+
swapId,
|
|
298
|
+
/* eslint-enable */
|
|
299
|
+
}) => {
|
|
300
|
+
//Fake delay to simulate network
|
|
301
|
+
await new Promise((r) => setTimeout(r, 800));
|
|
302
|
+
|
|
303
|
+
return null;
|
|
304
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { getEnv } from "../../env";
|
|
2
|
+
import network from "../../network";
|
|
3
|
+
import { getSwapAPIBaseURL } from "./";
|
|
4
|
+
import { mockPostSwapAccepted, mockPostSwapCancelled } from "./mock";
|
|
5
|
+
import type { PostSwapAccepted, PostSwapCancelled } from "./types";
|
|
6
|
+
|
|
7
|
+
export const postSwapAccepted: PostSwapAccepted = async ({
|
|
8
|
+
provider,
|
|
9
|
+
swapId = "",
|
|
10
|
+
transactionId,
|
|
11
|
+
}) => {
|
|
12
|
+
if (getEnv("MOCK"))
|
|
13
|
+
return mockPostSwapAccepted({ provider, swapId, transactionId });
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Since swapId is requiered by the endpoit, don't call it if we don't have
|
|
17
|
+
* this info
|
|
18
|
+
*/
|
|
19
|
+
if (!swapId) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
await network({
|
|
25
|
+
method: "POST",
|
|
26
|
+
url: `${getSwapAPIBaseURL()}/swap/accepted`,
|
|
27
|
+
data: { provider, swapId, transactionId },
|
|
28
|
+
});
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error(error);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const postSwapCancelled: PostSwapCancelled = async ({
|
|
37
|
+
provider,
|
|
38
|
+
swapId = "",
|
|
39
|
+
}) => {
|
|
40
|
+
if (getEnv("MOCK")) return mockPostSwapCancelled({ provider, swapId });
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Since swapId is requiered by the endpoit, don't call it if we don't have
|
|
44
|
+
* this info
|
|
45
|
+
*/
|
|
46
|
+
if (!swapId) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
await network({
|
|
52
|
+
method: "POST",
|
|
53
|
+
url: `${getSwapAPIBaseURL()}/swap/cancelled`,
|
|
54
|
+
data: { provider, swapId },
|
|
55
|
+
});
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error(error);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return null;
|
|
61
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { BigNumber } from "bignumber.js";
|
|
2
|
-
import type { Account, AccountLike } from "../../types/account";
|
|
3
2
|
import type {
|
|
4
|
-
AccountRawLike,
|
|
5
3
|
AccountRaw,
|
|
6
|
-
|
|
7
|
-
Transaction,
|
|
4
|
+
AccountRawLike,
|
|
8
5
|
CryptoCurrency,
|
|
6
|
+
Operation,
|
|
9
7
|
TokenCurrency,
|
|
8
|
+
Transaction,
|
|
10
9
|
TransactionRaw,
|
|
11
10
|
} from "../../types";
|
|
11
|
+
import type { Account, AccountLike } from "../../types/account";
|
|
12
12
|
|
|
13
13
|
/// v3 changes here, move me to another folder soon
|
|
14
14
|
export type ValidKYCStatus = "open" | "pending" | "approved" | "closed";
|
|
@@ -81,6 +81,39 @@ export type AvailableProviderV3 = {
|
|
|
81
81
|
pairs: Array<{ from: string; to: string; tradeMethod: string }>;
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
+
type CheckQuoteOkStatus = {
|
|
85
|
+
codeName: "RATE_VALID";
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
type ValidCheckQuoteErrorCodes =
|
|
89
|
+
| "UNKNOW_USER"
|
|
90
|
+
| "KYC_UNDEFINED"
|
|
91
|
+
| "KYC_PENDING"
|
|
92
|
+
| "KYC_FAILED"
|
|
93
|
+
| "KYC_UPGRADE_REQUIRED"
|
|
94
|
+
| "OVER_TRADE_LIMIT"
|
|
95
|
+
| "UNKNOWN_ERROR"
|
|
96
|
+
| "WITHDRAWALS_BLOCKED"
|
|
97
|
+
| "MFA_REQUIRED"
|
|
98
|
+
| "RATE_NOT_FOUND";
|
|
99
|
+
|
|
100
|
+
type CheckQuoteErrorStatus = {
|
|
101
|
+
codeName: ValidCheckQuoteErrorCodes;
|
|
102
|
+
error: string;
|
|
103
|
+
description: string;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export type CheckQuoteStatus = CheckQuoteOkStatus | CheckQuoteErrorStatus;
|
|
107
|
+
|
|
108
|
+
export type CheckQuote = ({
|
|
109
|
+
provider,
|
|
110
|
+
quoteId,
|
|
111
|
+
bearerToken,
|
|
112
|
+
}: {
|
|
113
|
+
provider: string;
|
|
114
|
+
quoteId: string;
|
|
115
|
+
bearerToken: string;
|
|
116
|
+
}) => Promise<CheckQuoteStatus>;
|
|
84
117
|
export type AvailableProvider = AvailableProviderV2 | AvailableProviderV3;
|
|
85
118
|
export type GetExchangeRates = (
|
|
86
119
|
arg0: Exchange,
|
|
@@ -93,6 +126,7 @@ export type InitSwapResult = {
|
|
|
93
126
|
transaction: Transaction;
|
|
94
127
|
swapId: string;
|
|
95
128
|
};
|
|
129
|
+
|
|
96
130
|
type ValidSwapStatus =
|
|
97
131
|
| "pending"
|
|
98
132
|
| "onhold"
|
|
@@ -108,7 +142,31 @@ export type SwapStatus = {
|
|
|
108
142
|
swapId: string;
|
|
109
143
|
status: ValidSwapStatus;
|
|
110
144
|
};
|
|
111
|
-
|
|
145
|
+
|
|
146
|
+
// -----
|
|
147
|
+
// Related to Swap state API call (accepted or cancelled)
|
|
148
|
+
|
|
149
|
+
type SwapStateRequest = {
|
|
150
|
+
provider: string;
|
|
151
|
+
swapId: string;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export type SwapStateAcceptedRequest = SwapStateRequest & {
|
|
155
|
+
transactionId: string;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export type SwapStateCancelledRequest = SwapStateRequest;
|
|
159
|
+
|
|
160
|
+
export type PostSwapAccepted = (
|
|
161
|
+
arg0: SwapStateAcceptedRequest
|
|
162
|
+
) => Promise<null>;
|
|
163
|
+
|
|
164
|
+
export type PostSwapCancelled = (
|
|
165
|
+
arg0: SwapStateCancelledRequest
|
|
166
|
+
) => Promise<null>;
|
|
167
|
+
|
|
168
|
+
// -----
|
|
169
|
+
|
|
112
170
|
export type UpdateAccountSwapStatus = (
|
|
113
171
|
arg0: Account
|
|
114
172
|
) => Promise<Account | null | undefined>;
|
|
@@ -125,6 +183,7 @@ export type SwapRequestEvent =
|
|
|
125
183
|
| {
|
|
126
184
|
type: "init-swap-error";
|
|
127
185
|
error: Error;
|
|
186
|
+
swapId: string;
|
|
128
187
|
}
|
|
129
188
|
| {
|
|
130
189
|
type: "init-swap-result";
|
|
@@ -203,3 +262,7 @@ export type InitSwapInputRaw = {
|
|
|
203
262
|
deviceId: string;
|
|
204
263
|
userId?: string;
|
|
205
264
|
};
|
|
265
|
+
|
|
266
|
+
export interface CustomMinOrMaxError extends Error {
|
|
267
|
+
amount: BigNumber;
|
|
268
|
+
}
|
|
@@ -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 (
|
|
19
|
+
if (isSwapOperationPending(status)) {
|
|
20
20
|
pendingSwapIds.push({
|
|
21
21
|
provider,
|
|
22
22
|
swapId,
|