@rango-dev/queue-manager-rango-preset 0.1.10-next.96 → 0.1.10
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/actions/scheduleNextStep.d.ts.map +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/helpers.d.ts +46 -14
- package/dist/helpers.d.ts.map +1 -1
- package/dist/hooks.d.ts.map +1 -1
- package/dist/index.d.ts +4 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/queue-manager-rango-preset.cjs.development.js +397 -302
- 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 +376 -288
- package/dist/queue-manager-rango-preset.esm.js.map +1 -1
- package/dist/shared-errors.d.ts +5 -37
- package/dist/shared-errors.d.ts.map +1 -1
- package/dist/shared.d.ts +20 -17
- package/dist/shared.d.ts.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/readme.md +1 -9
- package/src/actions/checkStatus.ts +54 -5
- package/src/actions/createTransaction.ts +2 -3
- package/src/actions/executeTransaction.ts +3 -3
- package/src/actions/scheduleNextStep.ts +1 -0
- package/src/constants.ts +1 -1
- package/src/helpers.ts +225 -174
- package/src/hooks.ts +2 -1
- package/src/index.ts +19 -44
- package/src/shared-errors.ts +53 -76
- package/src/shared.ts +34 -54
- package/src/types.ts +1 -0
package/src/hooks.ts
CHANGED
|
@@ -54,8 +54,9 @@ function useQueueManager(params: UseQueueManagerParams): void {
|
|
|
54
54
|
evmChains: params.evmChains,
|
|
55
55
|
wallet_network: params.lastConnectedWallet,
|
|
56
56
|
manager,
|
|
57
|
+
notifier: params.notifier,
|
|
57
58
|
});
|
|
58
|
-
retryOn(params.lastConnectedWallet, manager);
|
|
59
|
+
retryOn(params.lastConnectedWallet, params.notifier, manager);
|
|
59
60
|
}
|
|
60
61
|
}, [params.lastConnectedWallet]);
|
|
61
62
|
|
package/src/index.ts
CHANGED
|
@@ -1,52 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
import { checkStatus } from './actions/checkStatus';
|
|
3
|
-
import { createTransaction } from './actions/createTransaction';
|
|
4
|
-
import { executeTransaction } from './actions/executeTransaction';
|
|
5
|
-
import { scheduleNextStep } from './actions/scheduleNextStep';
|
|
6
|
-
import { start } from './actions/start';
|
|
7
|
-
import {
|
|
8
|
-
onBlockForChangeNetwork,
|
|
9
|
-
onBlockForConnectWallet,
|
|
10
|
-
onDependsOnOtherQueues,
|
|
11
|
-
} from './helpers';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* The idea behind this queue is to be able dynamically add some steps.
|
|
16
|
-
* After running a swap, it can be blocked (like on waiting for switch netwrok)
|
|
17
|
-
* or waits for something happend (like checking status of a transaction from server)
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
export const swapQueueDef: SwapQueueDef = {
|
|
21
|
-
name: 'swap',
|
|
22
|
-
actions: {
|
|
23
|
-
[SwapActionTypes.START]: start,
|
|
24
|
-
[SwapActionTypes.SCHEDULE_NEXT_STEP]: scheduleNextStep,
|
|
25
|
-
[SwapActionTypes.CREATE_TRANSACTION]: createTransaction,
|
|
26
|
-
[SwapActionTypes.EXECUTE_TRANSACTION]: executeTransaction,
|
|
27
|
-
[SwapActionTypes.CHECK_TRANSACTION_STATUS]: checkStatus,
|
|
28
|
-
},
|
|
29
|
-
run: [SwapActionTypes.START],
|
|
30
|
-
whenTaskBlocked: (event: any, meta: any) => {
|
|
31
|
-
if (event.reason.reason === BlockReason.WAIT_FOR_CONNECT_WALLET) {
|
|
32
|
-
onBlockForConnectWallet(event, meta);
|
|
33
|
-
} else if (event.reason.reason === BlockReason.WAIT_FOR_NETWORK_CHANGE) {
|
|
34
|
-
onBlockForChangeNetwork(event, meta);
|
|
35
|
-
} else if (event.reason.reason === BlockReason.DEPENDS_ON_OTHER_QUEUES) {
|
|
36
|
-
onDependsOnOtherQueues(event, meta);
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
|
|
1
|
+
export { PrettyError, prettifyErrorMessage } from './shared-errors';
|
|
41
2
|
export { SwapQueueContext, SwapStorage } from './types';
|
|
42
|
-
export {
|
|
43
|
-
|
|
44
|
-
|
|
3
|
+
export {
|
|
4
|
+
PendingSwapWithQueueID,
|
|
5
|
+
getCurrentBlockchainOfOrNull,
|
|
6
|
+
getRelatedWalletOrNull,
|
|
7
|
+
getRelatedWallet,
|
|
8
|
+
MessageSeverity,
|
|
9
|
+
PendingSwapStep,
|
|
10
|
+
PendingSwapNetworkStatus,
|
|
11
|
+
PendingSwap,
|
|
12
|
+
EventType,
|
|
13
|
+
SwapProgressNotification,
|
|
14
|
+
} from './shared';
|
|
45
15
|
export {
|
|
46
16
|
updateSwapStatus,
|
|
47
17
|
checkWaitingForNetworkChange,
|
|
48
18
|
getCurrentStep,
|
|
49
19
|
getEvmProvider,
|
|
50
|
-
|
|
20
|
+
cancelSwap,
|
|
21
|
+
getRequiredWallet,
|
|
22
|
+
getRunningSwaps,
|
|
23
|
+
splitWalletNetwork,
|
|
24
|
+
resetRunningSwapNotifsOnPageLoad,
|
|
51
25
|
} from './helpers';
|
|
26
|
+
export { swapQueueDef } from './queueDef';
|
|
52
27
|
export { useMigration, useQueueManager } from './hooks';
|
package/src/shared-errors.ts
CHANGED
|
@@ -1,61 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
APIErrorCode,
|
|
3
|
+
SignerError,
|
|
4
|
+
SignerErrorCode,
|
|
5
|
+
isAPIErrorCode,
|
|
6
|
+
isSignerErrorCode,
|
|
7
|
+
} from 'rango-types';
|
|
3
8
|
|
|
4
9
|
export type ErrorDetail = {
|
|
5
10
|
extraMessage: string;
|
|
6
11
|
extraMessageDetail?: string | null | undefined;
|
|
7
|
-
extraMessageErrorCode:
|
|
12
|
+
extraMessageErrorCode: SignerErrorCode | APIErrorCode | null;
|
|
8
13
|
};
|
|
9
14
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
USER_REJECT = 'USER_REJECT',
|
|
14
|
-
CALL_WALLET_FAILED = 'CALL_WALLET_FAILED',
|
|
15
|
-
SEND_TX_FAILED = 'SEND_TX_FAILED',
|
|
16
|
-
CALL_OR_SEND_FAILED = 'CALL_OR_SEND_FAILED',
|
|
17
|
-
USER_CANCEL = 'USER_CANCEL',
|
|
18
|
-
CLIENT_UNEXPECTED_BEHAVIOUR = 'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export enum ApiMethodName {
|
|
22
|
-
RequestingSwapTransaction = 'Requesting Swap Transaction',
|
|
23
|
-
CreatingSwap = 'Creating Swap',
|
|
24
|
-
CheckingTransactionStatus = 'Checking transaction status',
|
|
25
|
-
CreateTransaction = 'Create Transaction',
|
|
26
|
-
CheckApproval = 'Check TX Approval',
|
|
27
|
-
GettingSwapDetail = 'Getting Swap Detail',
|
|
28
|
-
GettingUserLimits = 'Getting user limits',
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export enum TransactionName {
|
|
32
|
-
GenericTransaction = 'transaction',
|
|
33
|
-
SendingOneInchTransaction = '1inch transaction',
|
|
34
|
-
Approval = 'approve transaction',
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const ERROR_ASSERTION_FAILED = 'Assertion failed (Unexpected behaviour)';
|
|
38
|
-
|
|
39
|
-
export const ERROR_COMMUNICATING_WITH_API = (
|
|
40
|
-
apiMethodName: ApiMethodName
|
|
41
|
-
): string => `Unexpected response from API (${apiMethodName})`;
|
|
42
|
-
|
|
43
|
-
export const ERROR_DESCRIPTION_UNSUPPORTED_TRANSACTION = (
|
|
44
|
-
method: string,
|
|
45
|
-
walletType: WalletType
|
|
46
|
-
): string => `method: ${method} call is unsupported for wallet ${walletType}`;
|
|
47
|
-
|
|
48
|
-
export const ERROR_SIGNING_TRANSACTION = (
|
|
49
|
-
transactionName: TransactionName
|
|
50
|
-
): string => `Error sending ${transactionName}`;
|
|
51
|
-
export const ERROR_REJECTING_TRANSACTION = 'User rejected the message signing';
|
|
52
|
-
|
|
53
|
-
export const ERROR_CREATE_TRANSACTION =
|
|
54
|
-
'Create transaction failed in Rango Server';
|
|
55
|
-
export const ERROR_INPUT_WALLET_NOT_FOUND = 'Input wallet not found';
|
|
56
|
-
|
|
57
|
-
export const DEFAULT_WALLET_INJECTION_ERROR =
|
|
58
|
-
'Failed to connect to wallet, if you have turned injection off (disable default wallet for xDefi), turn it on and refresh the page';
|
|
15
|
+
const ERROR_ASSERTION_FAILED = 'Assertion failed (Unexpected behaviour)';
|
|
16
|
+
const ERROR_CREATE_TRANSACTION = 'Create transaction failed in Rango Server';
|
|
17
|
+
const ERROR_INPUT_WALLET_NOT_FOUND = 'Input wallet not found';
|
|
59
18
|
|
|
60
19
|
type ErrorRoot = string | Record<string, string> | null;
|
|
61
20
|
|
|
@@ -63,6 +22,7 @@ export class PrettyError extends Error {
|
|
|
63
22
|
private readonly detail?: string;
|
|
64
23
|
private readonly root?: ErrorRoot;
|
|
65
24
|
private readonly code?: APIErrorCode;
|
|
25
|
+
public _isPrettyError = true;
|
|
66
26
|
|
|
67
27
|
constructor(
|
|
68
28
|
code: APIErrorCode,
|
|
@@ -72,11 +32,19 @@ export class PrettyError extends Error {
|
|
|
72
32
|
) {
|
|
73
33
|
super(m);
|
|
74
34
|
Object.setPrototypeOf(this, PrettyError.prototype);
|
|
35
|
+
PrettyError.prototype._isPrettyError = true;
|
|
75
36
|
this.code = code;
|
|
76
37
|
this.detail = detail;
|
|
77
38
|
this.root = root;
|
|
78
39
|
}
|
|
79
40
|
|
|
41
|
+
static isPrettyError(obj: unknown): obj is PrettyError {
|
|
42
|
+
return (
|
|
43
|
+
obj instanceof PrettyError ||
|
|
44
|
+
Object.prototype.hasOwnProperty('_isPrettyError')
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
80
48
|
getErrorDetail(): ErrorDetail {
|
|
81
49
|
const rawMessage =
|
|
82
50
|
typeof this.root === 'object' && this.root && this.root.error
|
|
@@ -97,7 +65,7 @@ export class PrettyError extends Error {
|
|
|
97
65
|
|
|
98
66
|
static AssertionFailed(m: string): PrettyError {
|
|
99
67
|
return new PrettyError(
|
|
100
|
-
|
|
68
|
+
'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
101
69
|
ERROR_ASSERTION_FAILED,
|
|
102
70
|
m
|
|
103
71
|
);
|
|
@@ -108,7 +76,7 @@ export class PrettyError extends Error {
|
|
|
108
76
|
statusCode: number | string
|
|
109
77
|
): PrettyError {
|
|
110
78
|
return new PrettyError(
|
|
111
|
-
|
|
79
|
+
'TX_FAIL',
|
|
112
80
|
message,
|
|
113
81
|
null,
|
|
114
82
|
`status code = ${statusCode}`
|
|
@@ -117,7 +85,7 @@ export class PrettyError extends Error {
|
|
|
117
85
|
|
|
118
86
|
static CreateTransaction(detail: string): PrettyError {
|
|
119
87
|
return new PrettyError(
|
|
120
|
-
|
|
88
|
+
'FETCH_TX_FAILED',
|
|
121
89
|
ERROR_CREATE_TRANSACTION,
|
|
122
90
|
null,
|
|
123
91
|
detail
|
|
@@ -126,7 +94,7 @@ export class PrettyError extends Error {
|
|
|
126
94
|
|
|
127
95
|
static WalletMissing(): PrettyError {
|
|
128
96
|
return new PrettyError(
|
|
129
|
-
|
|
97
|
+
'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
130
98
|
ERROR_INPUT_WALLET_NOT_FOUND,
|
|
131
99
|
null,
|
|
132
100
|
'Server requested for a blockchain or address not selected by user'
|
|
@@ -135,7 +103,7 @@ export class PrettyError extends Error {
|
|
|
135
103
|
|
|
136
104
|
static BlockchainMissing(): PrettyError {
|
|
137
105
|
return new PrettyError(
|
|
138
|
-
|
|
106
|
+
'CLIENT_UNEXPECTED_BEHAVIOUR',
|
|
139
107
|
ERROR_INPUT_WALLET_NOT_FOUND,
|
|
140
108
|
null,
|
|
141
109
|
'Server requested for a blockchain or address not selected by user'
|
|
@@ -143,33 +111,18 @@ export class PrettyError extends Error {
|
|
|
143
111
|
}
|
|
144
112
|
}
|
|
145
113
|
|
|
146
|
-
export const ERROR_GETTING_BEST_ROUTE = (status: number | string): string =>
|
|
147
|
-
`Failed to get best route (status: ${status}), please try again.`;
|
|
148
|
-
|
|
149
|
-
export const ERROR_CONFIRM_SWAP = (status?: number | string): string =>
|
|
150
|
-
`Failed to confirm swap (${!!status ? 'status' : 'route'}: ${
|
|
151
|
-
status || null
|
|
152
|
-
}), please try again.`;
|
|
153
|
-
|
|
154
|
-
export const WARNING_STARKNET_FOUND =
|
|
155
|
-
'StarknNet blockchain is still an ALPHA version. As such, delays may occur, and catastrophic bugs may lurk.';
|
|
156
|
-
|
|
157
|
-
function isAPIErrorCode(value: string): value is APIErrorCode {
|
|
158
|
-
return (Object.values(APIErrorCode) as string[]).includes(value);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
114
|
export function mapAppErrorCodesToAPIErrorCode(
|
|
162
115
|
errorCode: string | null
|
|
163
116
|
): APIErrorCode {
|
|
164
|
-
const defaultErrorCode =
|
|
117
|
+
const defaultErrorCode = 'CLIENT_UNEXPECTED_BEHAVIOUR';
|
|
165
118
|
try {
|
|
166
119
|
if (!errorCode) return defaultErrorCode;
|
|
167
120
|
if (isAPIErrorCode(errorCode)) return errorCode;
|
|
168
121
|
if (isSignerErrorCode(errorCode)) {
|
|
169
122
|
const t: { [key in SignerErrorCode]: APIErrorCode } = {
|
|
170
|
-
[SignerErrorCode.REJECTED_BY_USER]:
|
|
171
|
-
[SignerErrorCode.SIGN_TX_ERROR]:
|
|
172
|
-
[SignerErrorCode.SEND_TX_ERROR]:
|
|
123
|
+
[SignerErrorCode.REJECTED_BY_USER]: 'USER_REJECT',
|
|
124
|
+
[SignerErrorCode.SIGN_TX_ERROR]: 'CALL_WALLET_FAILED',
|
|
125
|
+
[SignerErrorCode.SEND_TX_ERROR]: 'SEND_TX_FAILED',
|
|
173
126
|
[SignerErrorCode.NOT_IMPLEMENTED]: defaultErrorCode,
|
|
174
127
|
[SignerErrorCode.OPERATION_UNSUPPORTED]: defaultErrorCode,
|
|
175
128
|
[SignerErrorCode.UNEXPECTED_BEHAVIOUR]: defaultErrorCode,
|
|
@@ -181,3 +134,27 @@ export function mapAppErrorCodesToAPIErrorCode(
|
|
|
181
134
|
return defaultErrorCode;
|
|
182
135
|
}
|
|
183
136
|
}
|
|
137
|
+
|
|
138
|
+
export const prettifyErrorMessage = (obj: unknown): ErrorDetail => {
|
|
139
|
+
if (!obj) return { extraMessage: '', extraMessageErrorCode: null };
|
|
140
|
+
if (PrettyError.isPrettyError(obj)) return obj.getErrorDetail();
|
|
141
|
+
if (SignerError.isSignerError(obj)) {
|
|
142
|
+
const t = obj.getErrorDetail();
|
|
143
|
+
return {
|
|
144
|
+
extraMessage: t.message,
|
|
145
|
+
extraMessageDetail: t.detail,
|
|
146
|
+
extraMessageErrorCode: t.code,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
if (obj instanceof Error)
|
|
150
|
+
return {
|
|
151
|
+
extraMessage: obj.toString(),
|
|
152
|
+
extraMessageErrorCode: null,
|
|
153
|
+
};
|
|
154
|
+
if (typeof obj !== 'string')
|
|
155
|
+
return {
|
|
156
|
+
extraMessage: JSON.stringify(obj),
|
|
157
|
+
extraMessageErrorCode: null,
|
|
158
|
+
};
|
|
159
|
+
return { extraMessage: obj, extraMessageErrorCode: null };
|
|
160
|
+
};
|
package/src/shared.ts
CHANGED
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
StarknetTransaction,
|
|
9
9
|
TronTransaction,
|
|
10
10
|
Transfer as TransferTransaction,
|
|
11
|
+
AmountRestrictionType,
|
|
11
12
|
} from 'rango-sdk';
|
|
12
13
|
|
|
13
|
-
import {
|
|
14
|
-
import { SignerError } from 'rango-types';
|
|
14
|
+
import { PrettyError } from './shared-errors';
|
|
15
15
|
|
|
16
16
|
export interface PendingSwapWithQueueID {
|
|
17
17
|
id: string;
|
|
@@ -57,8 +57,10 @@ export type EventType =
|
|
|
57
57
|
| 'task_canceled'
|
|
58
58
|
| 'task_paused'
|
|
59
59
|
| 'contract_confirmed'
|
|
60
|
+
| 'confirm_approve_contract'
|
|
60
61
|
| 'contract_rejected'
|
|
61
|
-
| '
|
|
62
|
+
| 'check_tx_status'
|
|
63
|
+
| 'check_approve_tx_status'
|
|
62
64
|
| 'transfer_rejected'
|
|
63
65
|
| 'calling_smart_contract'
|
|
64
66
|
| 'smart_contract_called'
|
|
@@ -66,8 +68,10 @@ export type EventType =
|
|
|
66
68
|
| 'step_completed_with_output'
|
|
67
69
|
| 'waiting_for_network_change'
|
|
68
70
|
| 'waiting_for_connecting_wallet'
|
|
71
|
+
| 'waiting_for_change_wallet_account'
|
|
69
72
|
| 'network_changed'
|
|
70
73
|
| 'not_enough_balance'
|
|
74
|
+
| 'waiting_for_queue'
|
|
71
75
|
| 'check_fee_failed'
|
|
72
76
|
| 'route_failed_to_find'
|
|
73
77
|
| 'transaction_expired';
|
|
@@ -105,19 +109,6 @@ export type SwapExplorerUrl = {
|
|
|
105
109
|
description: string | null;
|
|
106
110
|
};
|
|
107
111
|
|
|
108
|
-
export type SwapperId =
|
|
109
|
-
| 'ThorChain'
|
|
110
|
-
| 'OneInchEth'
|
|
111
|
-
| 'Binance Bridge'
|
|
112
|
-
| 'OneInchBsc'
|
|
113
|
-
| 'OneInchPolygon'
|
|
114
|
-
| 'Terra Bridge'
|
|
115
|
-
| 'TerraSwap'
|
|
116
|
-
| 'Osmosis'
|
|
117
|
-
| 'Lido'
|
|
118
|
-
| 'PoS Bridge'
|
|
119
|
-
| 'Wormhole';
|
|
120
|
-
|
|
121
112
|
export type StepStatus =
|
|
122
113
|
| 'created'
|
|
123
114
|
| 'running'
|
|
@@ -127,39 +118,47 @@ export type StepStatus =
|
|
|
127
118
|
| 'approved';
|
|
128
119
|
|
|
129
120
|
export type PendingSwapStep = {
|
|
121
|
+
// routing data
|
|
130
122
|
id: number;
|
|
131
123
|
fromBlockchain: Network;
|
|
132
124
|
fromSymbol: string;
|
|
133
125
|
fromSymbolAddress: string | null;
|
|
134
126
|
fromDecimals: number;
|
|
135
|
-
fromAmountPrecision:
|
|
136
|
-
fromAmountMinValue:
|
|
137
|
-
fromAmountMaxValue:
|
|
127
|
+
fromAmountPrecision: string | null;
|
|
128
|
+
fromAmountMinValue: string | null;
|
|
129
|
+
fromAmountMaxValue: string | null;
|
|
130
|
+
fromAmountRestrictionType: AmountRestrictionType | null;
|
|
138
131
|
fromLogo: string;
|
|
139
132
|
toBlockchain: string;
|
|
140
133
|
toSymbol: string;
|
|
141
134
|
toSymbolAddress: string | null;
|
|
142
135
|
toDecimals: number;
|
|
143
136
|
toLogo: string;
|
|
144
|
-
swapperId:
|
|
137
|
+
swapperId: string;
|
|
145
138
|
expectedOutputAmountHumanReadable: string | null;
|
|
146
139
|
startTransactionTime: number;
|
|
147
|
-
|
|
140
|
+
internalSteps: SwapperStatusStep[] | null;
|
|
141
|
+
estimatedTimeInSeconds: number | null;
|
|
142
|
+
|
|
143
|
+
// status data
|
|
148
144
|
status: StepStatus;
|
|
149
145
|
networkStatus: PendingSwapNetworkStatus | null;
|
|
150
146
|
executedTransactionId: string | null;
|
|
147
|
+
executedTransactionTime: string | null;
|
|
151
148
|
explorerUrl: SwapExplorerUrl[] | null;
|
|
152
|
-
|
|
153
|
-
|
|
149
|
+
diagnosisUrl: string | null;
|
|
150
|
+
outputAmount: string | null;
|
|
151
|
+
|
|
152
|
+
// txs data
|
|
154
153
|
cosmosTransaction: CosmosTransaction | null;
|
|
155
154
|
transferTransaction: TransferTransaction | null;
|
|
156
155
|
solanaTransaction: SolanaTransaction | null;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
tronTransaction: TronTransaction | null;
|
|
156
|
+
evmApprovalTransaction: EvmTransaction | null;
|
|
157
|
+
evmTransaction: EvmTransaction | null;
|
|
160
158
|
tronApprovalTransaction: TronTransaction | null;
|
|
161
|
-
|
|
162
|
-
|
|
159
|
+
tronTransaction: TronTransaction | null;
|
|
160
|
+
starknetApprovalTransaction: StarknetTransaction | null;
|
|
161
|
+
starknetTransaction: StarknetTransaction | null;
|
|
163
162
|
};
|
|
164
163
|
|
|
165
164
|
export type WalletTypeAndAddress = {
|
|
@@ -273,30 +272,6 @@ export const getTronApproveUrl = (tx: string): string => {
|
|
|
273
272
|
);
|
|
274
273
|
};
|
|
275
274
|
|
|
276
|
-
export const prettifyErrorMessage = (obj: unknown): ErrorDetail => {
|
|
277
|
-
if (!obj) return { extraMessage: '', extraMessageErrorCode: null };
|
|
278
|
-
if (obj instanceof PrettyError) return obj.getErrorDetail();
|
|
279
|
-
if (obj instanceof SignerError) {
|
|
280
|
-
const t = obj.getErrorDetail();
|
|
281
|
-
return {
|
|
282
|
-
extraMessage: t.message,
|
|
283
|
-
extraMessageDetail: t.detail,
|
|
284
|
-
extraMessageErrorCode: t.code,
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
if (obj instanceof Error)
|
|
288
|
-
return {
|
|
289
|
-
extraMessage: obj.toString(),
|
|
290
|
-
extraMessageErrorCode: null,
|
|
291
|
-
};
|
|
292
|
-
if (typeof obj !== 'string')
|
|
293
|
-
return {
|
|
294
|
-
extraMessage: JSON.stringify(obj),
|
|
295
|
-
extraMessageErrorCode: null,
|
|
296
|
-
};
|
|
297
|
-
return { extraMessage: obj, extraMessageErrorCode: null };
|
|
298
|
-
};
|
|
299
|
-
|
|
300
275
|
export function getNextStep(
|
|
301
276
|
swap: PendingSwap,
|
|
302
277
|
currentStep: PendingSwapStep
|
|
@@ -311,7 +286,9 @@ export function getNextStep(
|
|
|
311
286
|
);
|
|
312
287
|
}
|
|
313
288
|
|
|
314
|
-
|
|
289
|
+
/**
|
|
290
|
+
* Returns the wallet address, based on the current step of `PendingSwap`.
|
|
291
|
+
*/
|
|
315
292
|
export const getCurrentAddressOf = (
|
|
316
293
|
swap: PendingSwap,
|
|
317
294
|
step: PendingSwapStep
|
|
@@ -319,6 +296,10 @@ export const getCurrentAddressOf = (
|
|
|
319
296
|
const result =
|
|
320
297
|
swap.wallets[step.evmTransaction?.blockChain || ''] ||
|
|
321
298
|
swap.wallets[step.evmApprovalTransaction?.blockChain || ''] ||
|
|
299
|
+
swap.wallets[step.tronTransaction?.blockChain || ''] ||
|
|
300
|
+
swap.wallets[step.tronApprovalTransaction?.blockChain || ''] ||
|
|
301
|
+
swap.wallets[step.starknetTransaction?.blockChain || ''] ||
|
|
302
|
+
swap.wallets[step.starknetApprovalTransaction?.blockChain || ''] ||
|
|
322
303
|
swap.wallets[step.cosmosTransaction?.blockChain || ''] ||
|
|
323
304
|
swap.wallets[step.solanaTransaction?.blockChain || ''] ||
|
|
324
305
|
(step.transferTransaction?.fromWalletAddress
|
|
@@ -329,7 +310,6 @@ export const getCurrentAddressOf = (
|
|
|
329
310
|
return result.address;
|
|
330
311
|
};
|
|
331
312
|
|
|
332
|
-
// TODO: we have samething in `helpers`, for fixing circular dependency, we copied and should be removed eventually.
|
|
333
313
|
export function getRelatedWallet(
|
|
334
314
|
swap: PendingSwap,
|
|
335
315
|
currentStep: PendingSwapStep
|