@rango-dev/queue-manager-rango-preset 0.1.10-next.77 → 0.1.10-next.80
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/dist/actions/checkStatus.d.ts.map +1 -1
- package/dist/actions/createTransaction.d.ts.map +1 -1
- package/dist/constants.d.ts +1 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/helpers.d.ts +2 -2
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/queue-manager-rango-preset.cjs.development.js +350 -294
- package/dist/queue-manager-rango-preset.cjs.development.js.map +1 -1
- package/dist/queue-manager-rango-preset.cjs.production.min.js +1 -1
- package/dist/queue-manager-rango-preset.cjs.production.min.js.map +1 -1
- package/dist/queue-manager-rango-preset.esm.js +345 -286
- package/dist/queue-manager-rango-preset.esm.js.map +1 -1
- package/dist/services/httpService.d.ts +3 -0
- package/dist/services/httpService.d.ts.map +1 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/shared-errors.d.ts +1 -0
- package/dist/shared-errors.d.ts.map +1 -1
- package/dist/shared.d.ts +11 -16
- package/dist/shared.d.ts.map +1 -1
- package/dist/types.d.ts +3 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/actions/checkStatus.ts +14 -12
- package/src/actions/createTransaction.ts +21 -3
- package/src/constants.ts +1 -3
- package/src/helpers.ts +530 -192
- package/src/index.ts +3 -0
- package/src/services/httpService.ts +4 -0
- package/src/services/index.ts +1 -0
- package/src/shared-errors.ts +28 -1
- package/src/shared-sentry.ts +1 -1
- package/src/shared.ts +62 -35
- package/src/types.ts +2 -3
- package/dist/shared-api.d.ts +0 -10
- package/dist/shared-api.d.ts.map +0 -1
- package/src/shared-api.ts +0 -175
package/src/index.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { httpService } from './httpService';
|
package/src/shared-errors.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WalletType } from '@rango-dev/wallets-shared';
|
|
2
|
+
import { SignerErrorCode, isSignerErrorCode } from 'rango-types';
|
|
2
3
|
|
|
3
4
|
export type ErrorDetail = {
|
|
4
5
|
extraMessage: string;
|
|
@@ -153,4 +154,30 @@ export const ERROR_CONFIRM_SWAP = (status?: number | string): string =>
|
|
|
153
154
|
export const WARNING_STARKNET_FOUND =
|
|
154
155
|
'StarknNet blockchain is still an ALPHA version. As such, delays may occur, and catastrophic bugs may lurk.';
|
|
155
156
|
|
|
156
|
-
|
|
157
|
+
function isAPIErrorCode(value: string): value is APIErrorCode {
|
|
158
|
+
return (Object.values(APIErrorCode) as string[]).includes(value);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function mapAppErrorCodesToAPIErrorCode(
|
|
162
|
+
errorCode: string | null
|
|
163
|
+
): APIErrorCode {
|
|
164
|
+
const defaultErrorCode = APIErrorCode.CLIENT_UNEXPECTED_BEHAVIOUR;
|
|
165
|
+
try {
|
|
166
|
+
if (!errorCode) return defaultErrorCode;
|
|
167
|
+
if (isAPIErrorCode(errorCode)) return errorCode;
|
|
168
|
+
if (isSignerErrorCode(errorCode)) {
|
|
169
|
+
const t: { [key in SignerErrorCode]: APIErrorCode } = {
|
|
170
|
+
[SignerErrorCode.REJECTED_BY_USER]: APIErrorCode.USER_REJECT,
|
|
171
|
+
[SignerErrorCode.SIGN_TX_ERROR]: APIErrorCode.CALL_WALLET_FAILED,
|
|
172
|
+
[SignerErrorCode.SEND_TX_ERROR]: APIErrorCode.SEND_TX_FAILED,
|
|
173
|
+
[SignerErrorCode.NOT_IMPLEMENTED]: defaultErrorCode,
|
|
174
|
+
[SignerErrorCode.OPERATION_UNSUPPORTED]: defaultErrorCode,
|
|
175
|
+
[SignerErrorCode.UNEXPECTED_BEHAVIOUR]: defaultErrorCode,
|
|
176
|
+
};
|
|
177
|
+
return t[errorCode];
|
|
178
|
+
}
|
|
179
|
+
return defaultErrorCode;
|
|
180
|
+
} catch (err) {
|
|
181
|
+
return defaultErrorCode;
|
|
182
|
+
}
|
|
183
|
+
}
|
package/src/shared-sentry.ts
CHANGED
package/src/shared.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Network,
|
|
3
|
-
Transaction,
|
|
4
|
-
TransferTransaction,
|
|
5
|
-
WalletError,
|
|
6
|
-
WalletType,
|
|
7
|
-
} from '@rango-dev/wallets-shared';
|
|
1
|
+
import { Network, WalletType } from '@rango-dev/wallets-shared';
|
|
8
2
|
import {
|
|
9
3
|
CosmosTransaction,
|
|
10
4
|
EvmBlockchainMeta,
|
|
@@ -13,23 +7,16 @@ import {
|
|
|
13
7
|
SolanaTransaction,
|
|
14
8
|
StarknetTransaction,
|
|
15
9
|
TronTransaction,
|
|
10
|
+
Transfer as TransferTransaction,
|
|
16
11
|
} from 'rango-sdk';
|
|
17
|
-
import { BigNumber } from 'bignumber.js';
|
|
18
12
|
|
|
19
13
|
import { ErrorDetail, PrettyError } from './shared-errors';
|
|
20
|
-
import {
|
|
14
|
+
import { SignerError } from 'rango-types';
|
|
21
15
|
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
outputAmount: BigNumber | null;
|
|
27
|
-
explorerUrl: SwapExplorerUrl[] | null;
|
|
28
|
-
trackingCode: string;
|
|
29
|
-
newTx: Transaction | null;
|
|
30
|
-
diagnosisUrl: string | null;
|
|
31
|
-
steps: SwapperStatusStep[] | null;
|
|
32
|
-
};
|
|
16
|
+
export interface PendingSwapWithQueueID {
|
|
17
|
+
id: string;
|
|
18
|
+
swap: PendingSwap;
|
|
19
|
+
}
|
|
33
20
|
|
|
34
21
|
export type SwapProgressNotification = {
|
|
35
22
|
eventType: EventType;
|
|
@@ -56,7 +43,7 @@ export type Account = {
|
|
|
56
43
|
walletType: WalletType;
|
|
57
44
|
error: boolean;
|
|
58
45
|
explorerUrl: string | null;
|
|
59
|
-
isConnected
|
|
46
|
+
isConnected?: boolean;
|
|
60
47
|
};
|
|
61
48
|
export type Blockchain = { name: string; accounts: Account[] };
|
|
62
49
|
export type Wallet = { blockchains: Blockchain[] };
|
|
@@ -270,10 +257,24 @@ export const getEvmApproveUrl = (
|
|
|
270
257
|
throw Error(`Explorer url for ${network} is not implemented`);
|
|
271
258
|
};
|
|
272
259
|
|
|
260
|
+
export const getStarknetApproveUrl = (tx: string): string => {
|
|
261
|
+
return 'https://starkscan.co/tx/{txHash}'.replace(
|
|
262
|
+
'{txHash}',
|
|
263
|
+
tx.toLowerCase()
|
|
264
|
+
);
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
export const getTronApproveUrl = (tx: string): string => {
|
|
268
|
+
return 'https://tronscan.org/#/transaction/{txHash}'.replace(
|
|
269
|
+
'{txHash}',
|
|
270
|
+
tx.toLowerCase()
|
|
271
|
+
);
|
|
272
|
+
};
|
|
273
|
+
|
|
273
274
|
export const prettifyErrorMessage = (obj: unknown): ErrorDetail => {
|
|
274
275
|
if (!obj) return { extraMessage: '', extraMessageErrorCode: null };
|
|
275
276
|
if (obj instanceof PrettyError) return obj.getErrorDetail();
|
|
276
|
-
if (obj instanceof
|
|
277
|
+
if (obj instanceof SignerError) {
|
|
277
278
|
const t = obj.getErrorDetail();
|
|
278
279
|
return {
|
|
279
280
|
extraMessage: t.message,
|
|
@@ -294,19 +295,6 @@ export const prettifyErrorMessage = (obj: unknown): ErrorDetail => {
|
|
|
294
295
|
return { extraMessage: obj, extraMessageErrorCode: null };
|
|
295
296
|
};
|
|
296
297
|
|
|
297
|
-
export function getCookieId(): string {
|
|
298
|
-
const key = 'X-Rango-Id';
|
|
299
|
-
const cookieId = window.localStorage.getItem(key);
|
|
300
|
-
if (cookieId) {
|
|
301
|
-
return cookieId;
|
|
302
|
-
}
|
|
303
|
-
const value =
|
|
304
|
-
Math.random().toString(36).substring(2, 15) +
|
|
305
|
-
Math.random().toString(36).substring(2, 15);
|
|
306
|
-
window.localStorage.setItem(key, value);
|
|
307
|
-
return value;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
298
|
export function getNextStep(
|
|
311
299
|
swap: PendingSwap,
|
|
312
300
|
currentStep: PendingSwapStep
|
|
@@ -321,6 +309,45 @@ export function getNextStep(
|
|
|
321
309
|
);
|
|
322
310
|
}
|
|
323
311
|
|
|
312
|
+
// TODO: we have samething in `helpers`, for fixing circular dependency, we copied and should be removed eventually.
|
|
313
|
+
export const getCurrentAddressOf = (
|
|
314
|
+
swap: PendingSwap,
|
|
315
|
+
step: PendingSwapStep
|
|
316
|
+
): string => {
|
|
317
|
+
const result =
|
|
318
|
+
swap.wallets[step.evmTransaction?.blockChain || ''] ||
|
|
319
|
+
swap.wallets[step.evmApprovalTransaction?.blockChain || ''] ||
|
|
320
|
+
swap.wallets[step.cosmosTransaction?.blockChain || ''] ||
|
|
321
|
+
swap.wallets[step.solanaTransaction?.blockChain || ''] ||
|
|
322
|
+
(step.transferTransaction?.fromWalletAddress
|
|
323
|
+
? { address: step.transferTransaction?.fromWalletAddress }
|
|
324
|
+
: null) ||
|
|
325
|
+
null;
|
|
326
|
+
if (result == null) throw PrettyError.WalletMissing();
|
|
327
|
+
return result.address;
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
// TODO: we have samething in `helpers`, for fixing circular dependency, we copied and should be removed eventually.
|
|
331
|
+
export function getRelatedWallet(
|
|
332
|
+
swap: PendingSwap,
|
|
333
|
+
currentStep: PendingSwapStep
|
|
334
|
+
): WalletTypeAndAddress {
|
|
335
|
+
const walletAddress = getCurrentAddressOf(swap, currentStep);
|
|
336
|
+
const walletKV =
|
|
337
|
+
Object.keys(swap.wallets)
|
|
338
|
+
.map((k) => ({ k, v: swap.wallets[k] }))
|
|
339
|
+
.find(({ v }) => v.address === walletAddress) || null;
|
|
340
|
+
const blockchain = walletKV?.k || null;
|
|
341
|
+
const wallet = walletKV?.v || null;
|
|
342
|
+
|
|
343
|
+
const walletType = wallet?.walletType;
|
|
344
|
+
if (walletType === WalletType.UNKNOWN || wallet === null)
|
|
345
|
+
throw PrettyError.AssertionFailed(
|
|
346
|
+
`Wallet for source ${blockchain} not passed: walletType: ${walletType}`
|
|
347
|
+
);
|
|
348
|
+
return wallet;
|
|
349
|
+
}
|
|
350
|
+
|
|
324
351
|
export function getRelatedWalletOrNull(
|
|
325
352
|
swap: PendingSwap,
|
|
326
353
|
currentStep: PendingSwapStep
|
package/src/types.ts
CHANGED
|
@@ -2,14 +2,13 @@ import { QueueStorage, QueueDef } from '@rango-dev/queue-manager-core';
|
|
|
2
2
|
import { QueueContext } from '@rango-dev/queue-manager-core/dist/queue';
|
|
3
3
|
import { ConnectResult, Providers } from '@rango-dev/wallets-core';
|
|
4
4
|
import {
|
|
5
|
-
EvmBlockchainMeta,
|
|
6
5
|
Meta,
|
|
7
6
|
Network,
|
|
8
|
-
WalletSigners,
|
|
9
7
|
WalletState,
|
|
10
8
|
WalletType,
|
|
11
9
|
} from '@rango-dev/wallets-shared';
|
|
12
10
|
import { PendingSwap, SwapProgressNotification, Wallet } from './shared';
|
|
11
|
+
import { EvmBlockchainMeta, SignerFactory } from 'rango-types';
|
|
13
12
|
|
|
14
13
|
export type SwapQueueDef = QueueDef<
|
|
15
14
|
SwapStorage,
|
|
@@ -51,7 +50,7 @@ export interface SwapQueueContext extends QueueContext {
|
|
|
51
50
|
meta: Meta;
|
|
52
51
|
wallets: Wallet | null;
|
|
53
52
|
providers: Providers;
|
|
54
|
-
getSigners: (type: WalletType) =>
|
|
53
|
+
getSigners: (type: WalletType) => SignerFactory;
|
|
55
54
|
switchNetwork: (
|
|
56
55
|
wallet: WalletType,
|
|
57
56
|
network: Network
|
package/dist/shared-api.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { WalletType } from '@rango-dev/wallets-shared';
|
|
2
|
-
import { SwapperStatusResponse } from './shared';
|
|
3
|
-
import { CheckApprovalResponse, CreateTransactionRequest, CreateTransactionResponse } from 'rango-sdk';
|
|
4
|
-
import { APIErrorCode } from './shared-errors';
|
|
5
|
-
export declare function checkSwapStatus(requestId: string, txId: string, step: number): Promise<SwapperStatusResponse | null>;
|
|
6
|
-
export declare function createTransaction(request: CreateTransactionRequest): Promise<CreateTransactionResponse>;
|
|
7
|
-
export declare function checkApproved(requestId: string): Promise<CheckApprovalResponse>;
|
|
8
|
-
export declare function mapAppErrorCodesToAPIErrorCode(errorCode: string | null): APIErrorCode;
|
|
9
|
-
export declare function reportFailed(requestId: string, step: number, eventType: APIErrorCode, reason: string, walletType: WalletType | null): Promise<void>;
|
|
10
|
-
//# sourceMappingURL=shared-api.d.ts.map
|
package/dist/shared-api.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shared-api.d.ts","sourceRoot":"","sources":["src/shared-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EACX,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAe,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,EACL,qBAAqB,EAErB,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,YAAY,EAIb,MAAM,iBAAiB,CAAC;AAQzB,wBAAsB,eAAe,CACnC,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CA4BvC;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,yBAAyB,CAAC,CAoCpC;AAED,wBAAsB,aAAa,CACjC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,qBAAqB,CAAC,CAmBhC;AAMD,wBAAgB,8BAA8B,CAC5C,SAAS,EAAE,MAAM,GAAG,IAAI,GACvB,YAAY,CAoBd;AAED,wBAAsB,YAAY,CAChC,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,YAAY,EACvB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,UAAU,GAAG,IAAI,GAC5B,OAAO,CAAC,IAAI,CAAC,CAkBf"}
|
package/src/shared-api.ts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isWalletErrorCode,
|
|
3
|
-
WalletErrorCode,
|
|
4
|
-
WalletType,
|
|
5
|
-
} from '@rango-dev/wallets-shared';
|
|
6
|
-
import { getCookieId, SwapperStatusResponse } from './shared';
|
|
7
|
-
import {
|
|
8
|
-
CheckApprovalResponse,
|
|
9
|
-
CheckTxStatusRequest,
|
|
10
|
-
CreateTransactionRequest,
|
|
11
|
-
CreateTransactionResponse,
|
|
12
|
-
} from 'rango-sdk';
|
|
13
|
-
import {
|
|
14
|
-
APIErrorCode,
|
|
15
|
-
ApiMethodName,
|
|
16
|
-
ERROR_COMMUNICATING_WITH_API,
|
|
17
|
-
PrettyError,
|
|
18
|
-
} from './shared-errors';
|
|
19
|
-
import { BigNumber } from 'bignumber.js';
|
|
20
|
-
import {
|
|
21
|
-
BASE_URL,
|
|
22
|
-
RANGO_COOKIE_HEADER,
|
|
23
|
-
RANGO_DAPP_ID_QUERY,
|
|
24
|
-
} from './constants';
|
|
25
|
-
|
|
26
|
-
export async function checkSwapStatus(
|
|
27
|
-
requestId: string,
|
|
28
|
-
txId: string,
|
|
29
|
-
step: number
|
|
30
|
-
): Promise<SwapperStatusResponse | null> {
|
|
31
|
-
const url = `${BASE_URL}/tx/check-status?${RANGO_DAPP_ID_QUERY}`;
|
|
32
|
-
const body: CheckTxStatusRequest = { step, txId, requestId };
|
|
33
|
-
|
|
34
|
-
const response = await fetch(url, {
|
|
35
|
-
method: 'POST',
|
|
36
|
-
headers: {
|
|
37
|
-
[RANGO_COOKIE_HEADER]: getCookieId(),
|
|
38
|
-
'content-type': 'application/json;charset=UTF-8',
|
|
39
|
-
},
|
|
40
|
-
body: JSON.stringify(body),
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
(!!response.status && (response.status < 200 || response.status >= 400)) ||
|
|
45
|
-
!response.ok
|
|
46
|
-
) {
|
|
47
|
-
const apiError = ERROR_COMMUNICATING_WITH_API(
|
|
48
|
-
ApiMethodName.CheckingTransactionStatus
|
|
49
|
-
);
|
|
50
|
-
throw PrettyError.BadStatusCode(apiError, response.status);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const res = await response.json();
|
|
54
|
-
return {
|
|
55
|
-
...res,
|
|
56
|
-
outputAmount: res.outputAmount ? new BigNumber(res.outputAmount) : null,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export async function createTransaction(
|
|
61
|
-
request: CreateTransactionRequest
|
|
62
|
-
): Promise<CreateTransactionResponse> {
|
|
63
|
-
const url = `${BASE_URL}/tx/create?${RANGO_DAPP_ID_QUERY}`;
|
|
64
|
-
try {
|
|
65
|
-
const response = await fetch(url, {
|
|
66
|
-
method: 'POST',
|
|
67
|
-
headers: {
|
|
68
|
-
'content-type': 'application/json;charset=UTF-8',
|
|
69
|
-
[RANGO_COOKIE_HEADER]: getCookieId(),
|
|
70
|
-
},
|
|
71
|
-
body: JSON.stringify(request),
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
if (
|
|
75
|
-
(!!response.status &&
|
|
76
|
-
(response.status < 200 || response.status >= 400)) ||
|
|
77
|
-
!response.ok
|
|
78
|
-
) {
|
|
79
|
-
throw PrettyError.CreateTransaction(
|
|
80
|
-
`Error creating the transaction, status code: ${response.status}`
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const result: CreateTransactionResponse = await response.json();
|
|
85
|
-
if (!result.ok || !result.transaction)
|
|
86
|
-
throw PrettyError.CreateTransaction(
|
|
87
|
-
result.error || 'bad response from create tx endpoint'
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
return result;
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
|
-
} catch (error) {
|
|
93
|
-
if (error instanceof Error) {
|
|
94
|
-
throw PrettyError.CreateTransaction(error.message);
|
|
95
|
-
}
|
|
96
|
-
throw error;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export async function checkApproved(
|
|
101
|
-
requestId: string
|
|
102
|
-
): Promise<CheckApprovalResponse> {
|
|
103
|
-
const url = `${BASE_URL}/tx/${requestId}/check-approval?${RANGO_DAPP_ID_QUERY}`;
|
|
104
|
-
const response = await fetch(url, {
|
|
105
|
-
method: 'GET',
|
|
106
|
-
headers: {
|
|
107
|
-
'content-type': 'application/json;charset=UTF-8',
|
|
108
|
-
[RANGO_COOKIE_HEADER]: getCookieId(),
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
if (
|
|
113
|
-
(!!response.status && (response.status < 200 || response.status >= 400)) ||
|
|
114
|
-
!response.ok
|
|
115
|
-
) {
|
|
116
|
-
const apiError = ERROR_COMMUNICATING_WITH_API(ApiMethodName.CheckApproval);
|
|
117
|
-
throw PrettyError.BadStatusCode(apiError, response.status);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return await response.json();
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function isAPIErrorCode(value: string): value is APIErrorCode {
|
|
124
|
-
return (Object.values(APIErrorCode) as string[]).includes(value);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function mapAppErrorCodesToAPIErrorCode(
|
|
128
|
-
errorCode: string | null
|
|
129
|
-
): APIErrorCode {
|
|
130
|
-
const defaultErrorCode = APIErrorCode.CLIENT_UNEXPECTED_BEHAVIOUR;
|
|
131
|
-
try {
|
|
132
|
-
if (!errorCode) return defaultErrorCode;
|
|
133
|
-
if (isAPIErrorCode(errorCode)) return errorCode;
|
|
134
|
-
if (isWalletErrorCode(errorCode)) {
|
|
135
|
-
const t: { [key in WalletErrorCode]: APIErrorCode } = {
|
|
136
|
-
[WalletErrorCode.REJECTED_BY_USER]: APIErrorCode.USER_REJECT,
|
|
137
|
-
[WalletErrorCode.SIGN_TX_ERROR]: APIErrorCode.CALL_WALLET_FAILED,
|
|
138
|
-
[WalletErrorCode.SEND_TX_ERROR]: APIErrorCode.SEND_TX_FAILED,
|
|
139
|
-
[WalletErrorCode.NOT_IMPLEMENTED]: defaultErrorCode,
|
|
140
|
-
[WalletErrorCode.OPERATION_UNSUPPORTED]: defaultErrorCode,
|
|
141
|
-
[WalletErrorCode.UNEXPECTED_BEHAVIOUR]: defaultErrorCode,
|
|
142
|
-
};
|
|
143
|
-
return t[errorCode];
|
|
144
|
-
}
|
|
145
|
-
return defaultErrorCode;
|
|
146
|
-
} catch (err) {
|
|
147
|
-
return defaultErrorCode;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export async function reportFailed(
|
|
152
|
-
requestId: string,
|
|
153
|
-
step: number,
|
|
154
|
-
eventType: APIErrorCode,
|
|
155
|
-
reason: string,
|
|
156
|
-
walletType: WalletType | null
|
|
157
|
-
): Promise<void> {
|
|
158
|
-
const url = `${BASE_URL}/tx/report-tx?${RANGO_DAPP_ID_QUERY}`;
|
|
159
|
-
await fetch(url, {
|
|
160
|
-
method: 'POST',
|
|
161
|
-
headers: {
|
|
162
|
-
'content-type': 'application/json;charset=UTF-8',
|
|
163
|
-
[RANGO_COOKIE_HEADER]: getCookieId(),
|
|
164
|
-
},
|
|
165
|
-
body: JSON.stringify({
|
|
166
|
-
requestId,
|
|
167
|
-
step,
|
|
168
|
-
eventType,
|
|
169
|
-
reason,
|
|
170
|
-
tags: {
|
|
171
|
-
wallet: walletType,
|
|
172
|
-
},
|
|
173
|
-
}),
|
|
174
|
-
});
|
|
175
|
-
}
|