@rango-dev/widget-embedded 0.45.1-next.9 → 0.46.0
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/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +1 -1
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/types/quote.d.ts +1 -1
- package/dist/types/quote.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +11 -11
- package/src/components/Quote/Quote.tsx +4 -4
- package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +10 -23
- package/src/hooks/useConfirmSwap/useConfirmSwap.ts +19 -4
- package/src/hooks/useSwapInput.ts +13 -4
- package/src/types/quote.ts +1 -1
- package/src/utils/swap.ts +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -24,16 +24,16 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@lingui/core": "4.2.1",
|
|
26
26
|
"@lingui/react": "4.2.1",
|
|
27
|
-
"@rango-dev/logging-core": "^0.
|
|
28
|
-
"@rango-dev/provider-all": "^0.
|
|
29
|
-
"@rango-dev/queue-manager-core": "^0.
|
|
30
|
-
"@rango-dev/queue-manager-rango-preset": "^0.
|
|
31
|
-
"@rango-dev/queue-manager-react": "^0.
|
|
32
|
-
"@rango-dev/signer-solana": "^0.
|
|
33
|
-
"@rango-dev/ui": "^0.
|
|
34
|
-
"@rango-dev/wallets-core": "^0.
|
|
35
|
-
"@rango-dev/wallets-react": "^0.
|
|
36
|
-
"@rango-dev/wallets-shared": "^0.
|
|
27
|
+
"@rango-dev/logging-core": "^0.10.0",
|
|
28
|
+
"@rango-dev/provider-all": "^0.49.0",
|
|
29
|
+
"@rango-dev/queue-manager-core": "^0.31.0",
|
|
30
|
+
"@rango-dev/queue-manager-rango-preset": "^0.48.0",
|
|
31
|
+
"@rango-dev/queue-manager-react": "^0.31.0",
|
|
32
|
+
"@rango-dev/signer-solana": "^0.42.0",
|
|
33
|
+
"@rango-dev/ui": "^0.49.0",
|
|
34
|
+
"@rango-dev/wallets-core": "^0.46.0",
|
|
35
|
+
"@rango-dev/wallets-react": "^0.33.0",
|
|
36
|
+
"@rango-dev/wallets-shared": "^0.47.0",
|
|
37
37
|
"bignumber.js": "^9.1.1",
|
|
38
38
|
"copy-to-clipboard": "^3.3.3",
|
|
39
39
|
"dayjs": "^1.11.7",
|
|
@@ -134,11 +134,11 @@ export function Quote(props: QuoteProps) {
|
|
|
134
134
|
|
|
135
135
|
const hasSlippageError =
|
|
136
136
|
error?.type === QuoteErrorType.INSUFFICIENT_SLIPPAGE &&
|
|
137
|
-
error.recommendedSlippages?.
|
|
137
|
+
!!error.recommendedSlippages?.[index];
|
|
138
138
|
|
|
139
139
|
const hasSlippageWarning =
|
|
140
140
|
warning?.type === QuoteWarningType.INSUFFICIENT_SLIPPAGE &&
|
|
141
|
-
warning.recommendedSlippages?.
|
|
141
|
+
!!warning.recommendedSlippages?.[index];
|
|
142
142
|
|
|
143
143
|
const stepHasError = hasBridgeLimitError || hasSlippageError;
|
|
144
144
|
const stepHasWarning = hasSlippageWarning;
|
|
@@ -269,12 +269,12 @@ export function Quote(props: QuoteProps) {
|
|
|
269
269
|
...(error?.type ===
|
|
270
270
|
QuoteErrorType.INSUFFICIENT_SLIPPAGE && {
|
|
271
271
|
minRequiredSlippage:
|
|
272
|
-
error.recommendedSlippages?.
|
|
272
|
+
error.recommendedSlippages?.[index],
|
|
273
273
|
}),
|
|
274
274
|
...(warning?.type ===
|
|
275
275
|
QuoteWarningType.INSUFFICIENT_SLIPPAGE && {
|
|
276
276
|
minRequiredSlippage:
|
|
277
|
-
warning.recommendedSlippages?.
|
|
277
|
+
warning.recommendedSlippages?.[index],
|
|
278
278
|
}),
|
|
279
279
|
},
|
|
280
280
|
})}
|
|
@@ -124,42 +124,29 @@ export function generateWarnings(params: {
|
|
|
124
124
|
return output;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
export function handleQuoteErrors(
|
|
127
|
+
export function handleQuoteErrors(
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
129
|
+
error: any
|
|
130
|
+
): NonNullable<ConfirmSwapFetchResult['error']> {
|
|
128
131
|
if (error?.code === 'ERR_CANCELED') {
|
|
129
132
|
return {
|
|
130
|
-
|
|
131
|
-
error: {
|
|
132
|
-
type: QuoteErrorType.REQUEST_CANCELED,
|
|
133
|
-
},
|
|
134
|
-
warnings: null,
|
|
133
|
+
type: QuoteErrorType.REQUEST_CANCELED,
|
|
135
134
|
};
|
|
136
135
|
}
|
|
137
136
|
|
|
138
137
|
if (error.cause) {
|
|
139
|
-
return
|
|
140
|
-
swap: null,
|
|
141
|
-
error: error.cause,
|
|
142
|
-
warnings: null,
|
|
143
|
-
};
|
|
138
|
+
return error.cause;
|
|
144
139
|
}
|
|
145
140
|
|
|
146
141
|
if (error?.code === 'ERR_BAD_REQUEST') {
|
|
147
142
|
return {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
type: QuoteErrorType.NO_RESULT,
|
|
151
|
-
diagnosisMessage: error.response.data.error,
|
|
152
|
-
},
|
|
153
|
-
warnings: null,
|
|
143
|
+
type: QuoteErrorType.NO_RESULT,
|
|
144
|
+
diagnosisMessage: error.response.data.error,
|
|
154
145
|
};
|
|
155
146
|
}
|
|
156
147
|
|
|
157
148
|
return {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
type: QuoteErrorType.REQUEST_FAILED,
|
|
161
|
-
diagnosisMessage: error.message,
|
|
162
|
-
},
|
|
163
|
-
warnings: null,
|
|
149
|
+
type: QuoteErrorType.REQUEST_FAILED,
|
|
150
|
+
diagnosisMessage: error.message,
|
|
164
151
|
};
|
|
165
152
|
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import type { ConfirmSwap } from './useConfirmSwap.types';
|
|
2
|
-
import type { PendingSwapSettings, SelectedQuote } from '../../types';
|
|
3
2
|
import type { ConfirmRouteRequest } from 'rango-sdk';
|
|
4
3
|
|
|
4
|
+
import { warn } from '@rango-dev/logging-core';
|
|
5
5
|
import { calculatePendingSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
6
6
|
import { useEffect } from 'react';
|
|
7
7
|
|
|
8
8
|
import { useAppStore } from '../../store/AppStore';
|
|
9
9
|
import { useQuoteStore } from '../../store/quote';
|
|
10
|
+
import {
|
|
11
|
+
type PendingSwapSettings,
|
|
12
|
+
QuoteErrorType,
|
|
13
|
+
type SelectedQuote,
|
|
14
|
+
} from '../../types';
|
|
10
15
|
import { getWalletsForNewSwap } from '../../utils/swap';
|
|
11
16
|
import { useFetchConfirmQuote } from '../useFetchConfirmQuote';
|
|
12
17
|
|
|
@@ -125,9 +130,19 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
125
130
|
warnings: confirmSwapWarnings,
|
|
126
131
|
};
|
|
127
132
|
});
|
|
128
|
-
} catch (error:
|
|
129
|
-
const
|
|
130
|
-
|
|
133
|
+
} catch (error: unknown) {
|
|
134
|
+
const quoteError = handleQuoteErrors(error);
|
|
135
|
+
if (quoteError.type !== QuoteErrorType.REQUEST_CANCELED) {
|
|
136
|
+
warn(new Error('confirm swap error'), {
|
|
137
|
+
tags: {
|
|
138
|
+
...quoteError,
|
|
139
|
+
type: QuoteErrorType[quoteError.type],
|
|
140
|
+
initialQuote,
|
|
141
|
+
requestBody,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return { swap: null, error: quoteError, warnings: null };
|
|
131
146
|
}
|
|
132
147
|
};
|
|
133
148
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Token } from 'rango-sdk';
|
|
2
2
|
|
|
3
|
+
import { warn } from '@rango-dev/logging-core';
|
|
3
4
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
5
|
|
|
5
6
|
import { useAppStore } from '../store/AppStore';
|
|
@@ -168,16 +169,24 @@ export function useSwapInput({
|
|
|
168
169
|
updateQuotePartialState('warning', quoteWarning);
|
|
169
170
|
})
|
|
170
171
|
.catch((error) => {
|
|
171
|
-
const
|
|
172
|
+
const quoteError = handleQuoteErrors(error);
|
|
172
173
|
if (
|
|
173
|
-
quoteError
|
|
174
|
-
quoteError
|
|
174
|
+
quoteError.type === QuoteErrorType.NO_RESULT ||
|
|
175
|
+
quoteError.type === QuoteErrorType.REQUEST_FAILED
|
|
175
176
|
) {
|
|
176
177
|
resetQuote();
|
|
177
178
|
}
|
|
178
|
-
|
|
179
|
+
|
|
180
|
+
if (quoteError.type !== QuoteErrorType.REQUEST_CANCELED) {
|
|
179
181
|
updateQuotePartialState('error', quoteError);
|
|
180
182
|
setLoading(false);
|
|
183
|
+
warn(new Error('quote error'), {
|
|
184
|
+
tags: {
|
|
185
|
+
...quoteError,
|
|
186
|
+
type: QuoteErrorType[quoteError.type],
|
|
187
|
+
requestBody,
|
|
188
|
+
},
|
|
189
|
+
});
|
|
181
190
|
}
|
|
182
191
|
});
|
|
183
192
|
}
|
package/src/types/quote.ts
CHANGED
|
@@ -57,7 +57,7 @@ export enum QuoteWarningType {
|
|
|
57
57
|
EXCESSIVE_OUTPUT_AMOUNT_CHANGE,
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
export type RecommendedSlippages =
|
|
60
|
+
export type RecommendedSlippages = Record<number, string>;
|
|
61
61
|
|
|
62
62
|
export type InsufficientSlippageWarning = {
|
|
63
63
|
type: QuoteWarningType.INSUFFICIENT_SLIPPAGE;
|
package/src/utils/swap.ts
CHANGED
|
@@ -353,14 +353,14 @@ export function hasSlippageError(
|
|
|
353
353
|
export function checkSlippageErrors(
|
|
354
354
|
swaps: SwapResult[]
|
|
355
355
|
): RecommendedSlippages | null {
|
|
356
|
-
const recommendedSlippages
|
|
356
|
+
const recommendedSlippages = new Map<number, string>();
|
|
357
357
|
swaps.forEach((swap, index) => {
|
|
358
358
|
if (swap.recommendedSlippage?.error) {
|
|
359
359
|
recommendedSlippages.set(index, swap.recommendedSlippage.slippage);
|
|
360
360
|
}
|
|
361
361
|
});
|
|
362
362
|
if (recommendedSlippages.size > 0) {
|
|
363
|
-
return recommendedSlippages;
|
|
363
|
+
return Object.fromEntries(recommendedSlippages);
|
|
364
364
|
}
|
|
365
365
|
return null;
|
|
366
366
|
}
|
|
@@ -369,7 +369,7 @@ export function checkSlippageWarnings(
|
|
|
369
369
|
quote: SelectedQuote,
|
|
370
370
|
userSlippage: number
|
|
371
371
|
): RecommendedSlippages | null {
|
|
372
|
-
const recommendedSlippages
|
|
372
|
+
const recommendedSlippages = new Map<number, string>();
|
|
373
373
|
quote?.swaps.forEach((swap, index) => {
|
|
374
374
|
if (
|
|
375
375
|
swap.recommendedSlippage?.slippage &&
|
|
@@ -379,7 +379,7 @@ export function checkSlippageWarnings(
|
|
|
379
379
|
}
|
|
380
380
|
});
|
|
381
381
|
if (recommendedSlippages.size > 0) {
|
|
382
|
-
return recommendedSlippages;
|
|
382
|
+
return Object.fromEntries(recommendedSlippages);
|
|
383
383
|
}
|
|
384
384
|
return null;
|
|
385
385
|
}
|