@rango-dev/widget-embedded 0.1.11-next.10 → 0.1.11-next.12
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/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
- package/dist/utils/routing.d.ts +4 -4
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +2 -2
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +247 -216
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +247 -216
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +247 -216
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/TokenInfo.tsx +5 -5
- package/src/hooks/useConfirmSwap.ts +2 -2
- package/src/pages/ConfirmSwapPage.tsx +4 -2
- package/src/pages/Home.tsx +3 -3
- package/src/pages/SwapDetailsPage.tsx +6 -12
- package/src/store/bestRoute.ts +2 -2
- package/src/store/wallets.ts +1 -1
- package/src/utils/routing.ts +31 -11
- package/src/utils/swap.ts +16 -5
package/package.json
CHANGED
|
@@ -132,6 +132,7 @@ export function TokenInfo(props: PropTypes) {
|
|
|
132
132
|
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
133
133
|
const inputAmount = useBestRouteStore.use.inputAmount();
|
|
134
134
|
const balances = useWalletsStore.use.balances();
|
|
135
|
+
const fetchingBestRoute = useBestRouteStore.use.loading();
|
|
135
136
|
const navigate = useNavigate();
|
|
136
137
|
const { t } = useTranslation();
|
|
137
138
|
|
|
@@ -307,11 +308,10 @@ export function TokenInfo(props: PropTypes) {
|
|
|
307
308
|
) : (
|
|
308
309
|
<OutputContainer>
|
|
309
310
|
<Typography variant="h4">
|
|
310
|
-
{
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
: '0'}
|
|
311
|
+
{fetchingBestRoute && '?'}
|
|
312
|
+
{!!bestRoute?.result &&
|
|
313
|
+
`≈ ${numberToString(props.outputAmount)}`}
|
|
314
|
+
{(!inputAmount || inputAmount === '0') && '0'}
|
|
315
315
|
</Typography>
|
|
316
316
|
</OutputContainer>
|
|
317
317
|
)}
|
|
@@ -47,6 +47,7 @@ export function ConfirmSwapPage() {
|
|
|
47
47
|
const customSlippage = useSettingsStore.use.customSlippage();
|
|
48
48
|
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
49
49
|
const outputUsdValue = useBestRouteStore.use.outputUsdValue();
|
|
50
|
+
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
50
51
|
|
|
51
52
|
const bestRouteloadingStatus = getBestRouteStatus(
|
|
52
53
|
fetchingBestRoute,
|
|
@@ -96,7 +97,6 @@ export function ConfirmSwapPage() {
|
|
|
96
97
|
|
|
97
98
|
return (
|
|
98
99
|
<ConfirmSwap
|
|
99
|
-
// @ts-ignore
|
|
100
100
|
requiredWallets={getRequiredChains(bestRoute)}
|
|
101
101
|
selectableWallets={selectableWallets}
|
|
102
102
|
onBack={navigateBackFrom.bind(null, navigationRoutes.confirmSwap)}
|
|
@@ -106,13 +106,15 @@ export function ConfirmSwapPage() {
|
|
|
106
106
|
manager?.create(
|
|
107
107
|
'swap',
|
|
108
108
|
{ swapDetails: swap },
|
|
109
|
-
// @ts-ignore
|
|
110
109
|
{ id: swap.requestId }
|
|
111
110
|
);
|
|
112
111
|
setSelectedSwap(swap.requestId);
|
|
113
112
|
navigate(navigationRoutes.swaps + `/${swap.requestId}`, {
|
|
114
113
|
replace: true,
|
|
115
114
|
});
|
|
115
|
+
setTimeout(() => {
|
|
116
|
+
setInputAmount('');
|
|
117
|
+
}, 0);
|
|
116
118
|
}
|
|
117
119
|
});
|
|
118
120
|
}}
|
package/src/pages/Home.tsx
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
import BigNumber from 'bignumber.js';
|
|
37
37
|
import { HeaderButtons } from '../components/HeaderButtons';
|
|
38
38
|
import { useUiStore } from '../store/ui';
|
|
39
|
+
import { getFormatedBestRoute } from '../utils/routing';
|
|
39
40
|
|
|
40
41
|
const Container = styled('div', {
|
|
41
42
|
display: 'flex',
|
|
@@ -110,7 +111,6 @@ export function Home() {
|
|
|
110
111
|
outputUsdValue
|
|
111
112
|
);
|
|
112
113
|
|
|
113
|
-
const inputIsZero = inputAmount === '0';
|
|
114
114
|
const swapButtonState = getSwapButtonState(
|
|
115
115
|
loadingMetaStatus,
|
|
116
116
|
accounts,
|
|
@@ -120,7 +120,7 @@ export function Home() {
|
|
|
120
120
|
highValueLoss,
|
|
121
121
|
priceImpactCanNotBeComputed,
|
|
122
122
|
needsToWarnEthOnPath,
|
|
123
|
-
|
|
123
|
+
inputAmount
|
|
124
124
|
);
|
|
125
125
|
|
|
126
126
|
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
@@ -178,7 +178,7 @@ export function Home() {
|
|
|
178
178
|
<BestRoute
|
|
179
179
|
error={bestRouteError}
|
|
180
180
|
loading={fetchingBestRoute}
|
|
181
|
-
data={bestRoute}
|
|
181
|
+
data={getFormatedBestRoute(bestRoute)}
|
|
182
182
|
totalFee={numberToString(totalFeeInUsd, 0, 2)}
|
|
183
183
|
feeWarning={highFee}
|
|
184
184
|
totalTime={secondsToString(totalArrivalTime(bestRoute))}
|
|
@@ -4,7 +4,7 @@ import useCopyToClipboard from '../hooks/useCopyToClipboard';
|
|
|
4
4
|
import { useManager } from '@rango-dev/queue-manager-react';
|
|
5
5
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
6
6
|
import { getPendingSwaps } from '../utils/queue';
|
|
7
|
-
import { SwapHistory
|
|
7
|
+
import { SwapHistory } from '@rango-dev/ui';
|
|
8
8
|
import { useUiStore } from '../store/ui';
|
|
9
9
|
import {
|
|
10
10
|
cancelSwap,
|
|
@@ -25,11 +25,10 @@ import {
|
|
|
25
25
|
isNetworkStatusInWarningState,
|
|
26
26
|
shouldRetrySwap,
|
|
27
27
|
} from '../utils/swap';
|
|
28
|
-
import { TokenPreview } from '../components/TokenPreview';
|
|
29
|
-
import { numberToString } from '../utils/numbers';
|
|
30
28
|
//@ts-ignore
|
|
31
29
|
import { t } from 'i18next';
|
|
32
30
|
import { SwapDetailsPlaceholder } from '../components/SwapDetailsPlaceholder';
|
|
31
|
+
import { getFormatedPendingSwap } from '../utils/routing';
|
|
33
32
|
|
|
34
33
|
export function SwapDetailsPage() {
|
|
35
34
|
const selectedSwapRequestId = useUiStore.use.selectedSwapRequestId();
|
|
@@ -68,11 +67,6 @@ export function SwapDetailsPage() {
|
|
|
68
67
|
/>
|
|
69
68
|
);
|
|
70
69
|
|
|
71
|
-
const firstStep = swap.steps[0];
|
|
72
|
-
const lastStep = swap.steps[swap.steps.length - 1];
|
|
73
|
-
const fromAmount = numberToString(swap.inputAmount);
|
|
74
|
-
const toAmount = numberToString(swap.simulationResult.outputAmount);
|
|
75
|
-
|
|
76
70
|
const currentStep = getCurrentStep(swap);
|
|
77
71
|
|
|
78
72
|
const currentStepBlockchain = currentStep
|
|
@@ -106,12 +100,13 @@ export function SwapDetailsPage() {
|
|
|
106
100
|
return (
|
|
107
101
|
<SwapHistory
|
|
108
102
|
onBack={navigateBackFrom.bind(null, navigationRoutes.swapDetails)}
|
|
103
|
+
/* TODO: It was temporarily removed to find a better solution*/
|
|
104
|
+
/*
|
|
109
105
|
previewInputs={
|
|
110
106
|
<>
|
|
111
107
|
<TokenPreview
|
|
112
108
|
chain={{
|
|
113
109
|
displayName: firstStep?.fromBlockchain || '',
|
|
114
|
-
// @ts-ignore
|
|
115
110
|
logo: firstStep?.fromBlockchainLogo || '',
|
|
116
111
|
}}
|
|
117
112
|
token={{
|
|
@@ -126,7 +121,6 @@ export function SwapDetailsPage() {
|
|
|
126
121
|
<TokenPreview
|
|
127
122
|
chain={{
|
|
128
123
|
displayName: lastStep?.toBlockchain || '',
|
|
129
|
-
//@ts-ignore
|
|
130
124
|
logo: lastStep?.toBlockchainLogo || '',
|
|
131
125
|
}}
|
|
132
126
|
token={{
|
|
@@ -139,8 +133,8 @@ export function SwapDetailsPage() {
|
|
|
139
133
|
/>
|
|
140
134
|
</>
|
|
141
135
|
}
|
|
142
|
-
|
|
143
|
-
pendingSwap={swap}
|
|
136
|
+
*/
|
|
137
|
+
pendingSwap={getFormatedPendingSwap(swap)}
|
|
144
138
|
onCopy={handleCopy}
|
|
145
139
|
isCopied={isCopied}
|
|
146
140
|
onCancel={onCancel}
|
package/src/store/bestRoute.ts
CHANGED
|
@@ -263,7 +263,6 @@ const bestRoute = (
|
|
|
263
263
|
[],
|
|
264
264
|
disabledLiquiditySources,
|
|
265
265
|
userSlippage,
|
|
266
|
-
false,
|
|
267
266
|
affiliateRef
|
|
268
267
|
);
|
|
269
268
|
if (!bestRouteStore.getState().loading)
|
|
@@ -297,7 +296,8 @@ const bestRoute = (
|
|
|
297
296
|
const bestRouteParamsListener = () => {
|
|
298
297
|
const { fromToken, toToken, inputAmount, inputUsdValue } =
|
|
299
298
|
useBestRouteStore.getState();
|
|
300
|
-
if (!inputAmount || inputAmount === '0' || inputUsdValue.eq(0))
|
|
299
|
+
if (!inputAmount || inputAmount === '0' || inputUsdValue.eq(0))
|
|
300
|
+
return bestRouteStore.setState({ loading: false });
|
|
301
301
|
|
|
302
302
|
if (tokensAreEqual(fromToken, toToken))
|
|
303
303
|
return bestRouteStore.setState({
|
package/src/store/wallets.ts
CHANGED
package/src/utils/routing.ts
CHANGED
|
@@ -7,10 +7,8 @@ import { BestRouteResponse, BlockchainMeta, Token } from 'rango-sdk';
|
|
|
7
7
|
import { areEqual } from './common';
|
|
8
8
|
import { SelectedWallet } from './wallets';
|
|
9
9
|
import { BestRouteEqualityParams } from '../types';
|
|
10
|
-
import { TokenMeta } from '@rango-dev/ui/dist/types/meta';
|
|
11
10
|
import { numberToString } from './numbers';
|
|
12
|
-
import {
|
|
13
|
-
import { BestRouteWithFee } from '@rango-dev/ui';
|
|
11
|
+
import { PendingSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
14
12
|
|
|
15
13
|
export function searchParamsToToken(
|
|
16
14
|
tokens: Token[],
|
|
@@ -142,19 +140,41 @@ export function isRouteParametersChanged(params: BestRouteEqualityParams) {
|
|
|
142
140
|
return false;
|
|
143
141
|
}
|
|
144
142
|
|
|
145
|
-
export function
|
|
146
|
-
bestRoute: BestRouteResponse | null
|
|
147
|
-
|
|
148
|
-
)
|
|
149
|
-
|
|
150
|
-
const
|
|
143
|
+
export function getFormatedBestRoute(
|
|
144
|
+
bestRoute: BestRouteResponse | null
|
|
145
|
+
): BestRouteResponse | null {
|
|
146
|
+
if (!bestRoute) return null;
|
|
147
|
+
|
|
148
|
+
const formatedSwaps = (bestRoute.result?.swaps || []).map((swap) => ({
|
|
151
149
|
...swap,
|
|
152
|
-
|
|
150
|
+
fromAmount: numberToString(swap.fromAmount, 6, 6),
|
|
151
|
+
toAmount: numberToString(swap.toAmount, 6, 6),
|
|
153
152
|
}));
|
|
154
153
|
|
|
155
154
|
return {
|
|
156
155
|
...bestRoute,
|
|
157
|
-
|
|
156
|
+
...(bestRoute.result && {
|
|
157
|
+
result: { ...bestRoute.result, swaps: formatedSwaps },
|
|
158
|
+
}),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function getFormatedPendingSwap(pendingSwap: PendingSwap): PendingSwap {
|
|
163
|
+
const formatedSteps = pendingSwap.steps.map((step) => ({
|
|
164
|
+
...step,
|
|
165
|
+
feeInUsd: numberToString(step.feeInUsd, 4, 4),
|
|
166
|
+
outputAmount: numberToString(step.outputAmount, 6, 6),
|
|
167
|
+
expectedOutputAmountHumanReadable: numberToString(
|
|
168
|
+
step.expectedOutputAmountHumanReadable,
|
|
169
|
+
6,
|
|
170
|
+
6
|
|
171
|
+
),
|
|
172
|
+
}));
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
...pendingSwap,
|
|
176
|
+
inputAmount: numberToString(pendingSwap.inputAmount, 6, 6),
|
|
177
|
+
steps: formatedSteps,
|
|
158
178
|
};
|
|
159
179
|
}
|
|
160
180
|
|
package/src/utils/swap.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
PendingSwapStep,
|
|
20
20
|
} from '@rango-dev/queue-manager-rango-preset';
|
|
21
21
|
import { PendingSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
22
|
+
import { removeDuplicateFrom } from './common';
|
|
22
23
|
|
|
23
24
|
export function getOutputRatio(
|
|
24
25
|
inputUsdValue: BigNumber,
|
|
@@ -128,13 +129,14 @@ export function getSwapButtonState(
|
|
|
128
129
|
highValueLoss: boolean,
|
|
129
130
|
priceImpactCanNotBeComputed: boolean,
|
|
130
131
|
needsToWarnEthOnPath: boolean,
|
|
131
|
-
|
|
132
|
+
inputAmount: string
|
|
132
133
|
): SwapButtonState {
|
|
133
134
|
if (loadingMetaStatus !== 'success')
|
|
134
135
|
return { title: 'Connect Wallet', disabled: true };
|
|
135
136
|
if (accounts.length == 0) return { title: 'Connect Wallet', disabled: false };
|
|
136
137
|
if (loading) return { title: 'Finding Best Route...', disabled: true };
|
|
137
|
-
else if (
|
|
138
|
+
else if (!inputAmount || inputAmount === '0')
|
|
139
|
+
return { title: 'Enter an amount', disabled: true };
|
|
138
140
|
else if (!bestRoute || !bestRoute.result)
|
|
139
141
|
return { title: 'Swap', disabled: true };
|
|
140
142
|
else if (hasLimitError) return { title: 'Limit Error', disabled: true };
|
|
@@ -313,8 +315,8 @@ export function createBestRouteRequestBody(
|
|
|
313
315
|
selectedWallets: SelectedWallet[],
|
|
314
316
|
disabledLiquiditySources: string[],
|
|
315
317
|
slippage: number,
|
|
316
|
-
|
|
317
|
-
|
|
318
|
+
affiliateRef: string | null,
|
|
319
|
+
initialRoute?: BestRouteResponse
|
|
318
320
|
): BestRouteRequest {
|
|
319
321
|
const selectedWalletsMap = selectedWallets.reduce(
|
|
320
322
|
(
|
|
@@ -341,7 +343,16 @@ export function createBestRouteRequestBody(
|
|
|
341
343
|
});
|
|
342
344
|
});
|
|
343
345
|
|
|
344
|
-
const
|
|
346
|
+
const checkPrerequisites = !!initialRoute;
|
|
347
|
+
|
|
348
|
+
const filteredBlockchains = removeDuplicateFrom(
|
|
349
|
+
(initialRoute?.result?.swaps || []).reduce(
|
|
350
|
+
(blockchains: string[], swap) => (
|
|
351
|
+
blockchains.push(swap.from.blockchain, swap.to.blockchain), blockchains
|
|
352
|
+
),
|
|
353
|
+
[]
|
|
354
|
+
)
|
|
355
|
+
);
|
|
345
356
|
|
|
346
357
|
const requestBody: BestRouteRequest = {
|
|
347
358
|
amount: inputAmount.toString(),
|