@rango-dev/widget-embedded 0.1.10-next.99 → 0.1.11-next.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/App.d.ts.map +1 -1
- package/dist/QueueManager.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts +6 -1
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/HeaderButtons.d.ts +4 -1
- package/dist/components/HeaderButtons.d.ts.map +1 -1
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/PercentageChange.d.ts +9 -0
- package/dist/components/PercentageChange.d.ts.map +1 -0
- package/dist/components/SwapDetailsPlaceholder.d.ts +9 -0
- package/dist/components/SwapDetailsPlaceholder.d.ts.map +1 -0
- package/dist/components/TokenInfo.d.ts.map +1 -1
- package/dist/components/TokenPreview.d.ts +3 -2
- package/dist/components/TokenPreview.d.ts.map +1 -1
- package/dist/components/UpdateUrl.d.ts.map +1 -1
- package/dist/components/warnings/BalanceWarnings.d.ts.map +1 -1
- package/dist/components/warnings/MinRequiredSlippage.d.ts +1 -1
- package/dist/components/warnings/MinRequiredSlippage.d.ts.map +1 -1
- package/dist/constants/navigationRoutes.d.ts +0 -1
- package/dist/constants/navigationRoutes.d.ts.map +1 -1
- package/dist/globalStyles.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap.d.ts.map +1 -1
- package/dist/lib.d.ts.map +1 -1
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/HistoryPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/LiquiditySourcesPage.d.ts.map +1 -1
- package/dist/pages/SelectTokenPage.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts.map +1 -1
- package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts +1 -0
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/store/bestRoute.d.ts +3 -0
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/ui.d.ts.map +1 -1
- package/dist/store/wallets.d.ts +14 -0
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/routing.d.ts +15 -2
- package/dist/types/routing.d.ts.map +1 -1
- package/dist/types/swap.d.ts +6 -0
- package/dist/types/swap.d.ts.map +1 -1
- package/dist/utils/common.d.ts +1 -0
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/date.d.ts +3 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/routing.d.ts +3 -2
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +16 -5
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/time.d.ts +4 -0
- package/dist/utils/time.d.ts.map +1 -0
- package/dist/utils/wallets.d.ts +1 -1
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +1122 -719
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +1122 -719
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +1131 -728
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +12 -11
- package/readme.md +1 -2
- package/src/App.tsx +30 -5
- package/src/QueueManager.tsx +5 -2
- package/src/components/AppRouter.tsx +24 -13
- package/src/components/AppRoutes.tsx +15 -12
- package/src/components/HeaderButtons.tsx +9 -2
- package/src/components/Layout.tsx +37 -5
- package/src/components/PercentageChange.tsx +33 -0
- package/src/components/SwapDetailsPlaceholder.tsx +32 -0
- package/src/components/TokenInfo.tsx +20 -4
- package/src/components/TokenPreview.tsx +17 -6
- package/src/components/UpdateUrl.tsx +1 -3
- package/src/components/warnings/BalanceWarnings.tsx +1 -0
- package/src/components/warnings/MinRequiredSlippage.tsx +9 -4
- package/src/constants/navigationRoutes.ts +0 -1
- package/src/globalStyles.ts +2 -1
- package/src/hooks/useConfirmSwap.ts +2 -1
- package/src/hooks/useNavigateBack.ts +3 -3
- package/src/lib.tsx +25 -3
- package/src/pages/ConfirmSwapPage.tsx +133 -20
- package/src/pages/HistoryPage.tsx +4 -4
- package/src/pages/Home.tsx +27 -22
- package/src/pages/LiquiditySourcesPage.tsx +2 -0
- package/src/pages/SelectTokenPage.tsx +3 -1
- package/src/pages/SettingsPage.tsx +3 -0
- package/src/pages/SwapDetailsPage.tsx +142 -6
- package/src/pages/WalletsPage.tsx +47 -11
- package/src/store/bestRoute.ts +143 -16
- package/src/store/ui.ts +4 -0
- package/src/store/wallets.ts +4 -1
- package/src/types/routing.ts +18 -2
- package/src/types/swap.ts +7 -0
- package/src/utils/common.ts +14 -0
- package/src/utils/date.ts +62 -0
- package/src/utils/routing.ts +36 -20
- package/src/utils/swap.ts +103 -11
- package/src/utils/time.ts +52 -0
- package/src/utils/wallets.ts +13 -4
- package/dist/components/Header.d.ts +0 -10
- package/dist/components/Header.d.ts.map +0 -1
- package/dist/pages/ConfirmWalletsPage.d.ts +0 -3
- package/dist/pages/ConfirmWalletsPage.d.ts.map +0 -1
- package/src/components/Header.tsx +0 -37
- package/src/pages/ConfirmWalletsPage.tsx +0 -127
package/src/utils/routing.ts
CHANGED
|
@@ -6,7 +6,7 @@ import BigNumber from 'bignumber.js';
|
|
|
6
6
|
import { BestRouteResponse, BlockchainMeta, Token } from 'rango-sdk';
|
|
7
7
|
import { areEqual } from './common';
|
|
8
8
|
import { SelectedWallet } from './wallets';
|
|
9
|
-
import {
|
|
9
|
+
import { BestRouteEqualityParams } from '../types';
|
|
10
10
|
import { TokenMeta } from '@rango-dev/ui/dist/types/meta';
|
|
11
11
|
import { numberToString } from './numbers';
|
|
12
12
|
import { getUsdFeeOfStep } from './swap';
|
|
@@ -112,25 +112,34 @@ export function getRequiredBalanceOfWallet(
|
|
|
112
112
|
return relatedFeeStatus.requiredAssets;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
export function isRouteParametersChanged(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
115
|
+
export function isRouteParametersChanged(params: BestRouteEqualityParams) {
|
|
116
|
+
if (params.store === 'bestRoute') {
|
|
117
|
+
const { prevState, currentState } = params;
|
|
118
|
+
return (
|
|
119
|
+
!!currentState.fromToken &&
|
|
120
|
+
!!currentState.toToken &&
|
|
121
|
+
(prevState.fromChain?.name !== currentState.fromChain?.name ||
|
|
122
|
+
prevState.toChain?.name !== currentState.toChain?.name ||
|
|
123
|
+
prevState.fromToken?.symbol !== currentState.fromToken?.symbol ||
|
|
124
|
+
prevState.toToken?.symbol !== currentState.toToken?.symbol ||
|
|
125
|
+
prevState.fromToken?.blockchain !== prevState.fromToken?.blockchain ||
|
|
126
|
+
prevState.toToken?.blockchain !== currentState.toToken?.blockchain ||
|
|
127
|
+
prevState.fromToken?.address !== currentState.fromToken?.address ||
|
|
128
|
+
prevState.toToken?.address !== currentState.toToken?.address ||
|
|
129
|
+
prevState.inputAmount !== currentState.inputAmount)
|
|
130
|
+
);
|
|
131
|
+
} else if (params.store === 'settings') {
|
|
132
|
+
const { prevState, currentState } = params;
|
|
133
|
+
return (
|
|
134
|
+
prevState.slippage !== currentState.slippage ||
|
|
135
|
+
prevState.customSlippage !== currentState.customSlippage ||
|
|
136
|
+
prevState.disabledLiquiditySources?.length !==
|
|
137
|
+
currentState.disabledLiquiditySources?.length ||
|
|
138
|
+
prevState.infiniteApprove ||
|
|
139
|
+
currentState.infiniteApprove
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
134
143
|
}
|
|
135
144
|
|
|
136
145
|
export function getBestRouteWithCalculatedFees(
|
|
@@ -148,3 +157,10 @@ export function getBestRouteWithCalculatedFees(
|
|
|
148
157
|
result: { ...bestRoute.result, swaps: swapsWithFee },
|
|
149
158
|
};
|
|
150
159
|
}
|
|
160
|
+
|
|
161
|
+
//todo: refactor bestRoute store and add loadingStatus
|
|
162
|
+
export const getBestRouteStatus = (loading: boolean, error: boolean) => {
|
|
163
|
+
if (loading) return 'loading';
|
|
164
|
+
if (error) return 'failed';
|
|
165
|
+
else return 'success';
|
|
166
|
+
};
|
package/src/utils/swap.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { PendingSwap } from '@rango-dev/ui/dist/containers/History/types';
|
|
2
1
|
import {
|
|
3
2
|
WalletTypeAndAddress,
|
|
4
3
|
SwapSavedSettings,
|
|
@@ -19,7 +18,12 @@ import { WalletType } from '@rango-dev/wallets-shared';
|
|
|
19
18
|
import { getRequiredBalanceOfWallet } from './routing';
|
|
20
19
|
import { getRequiredChains, SelectedWallet } from './wallets';
|
|
21
20
|
import { LoadingStatus } from '../store/meta';
|
|
22
|
-
import { SwapButtonState } from '../types';
|
|
21
|
+
import { ConvertedToken, SwapButtonState } from '../types';
|
|
22
|
+
import {
|
|
23
|
+
PendingSwapNetworkStatus,
|
|
24
|
+
PendingSwapStep,
|
|
25
|
+
} from '@rango-dev/queue-manager-rango-preset';
|
|
26
|
+
import { PendingSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
23
27
|
|
|
24
28
|
export function getOutputRatio(
|
|
25
29
|
inputUsdValue: BigNumber,
|
|
@@ -136,7 +140,8 @@ export function getSwapButtonState(
|
|
|
136
140
|
if (accounts.length == 0) return { title: 'Connect Wallet', disabled: false };
|
|
137
141
|
if (loading) return { title: 'Finding Best Route...', disabled: true };
|
|
138
142
|
else if (inputIsZero) return { title: 'Enter an amount', disabled: true };
|
|
139
|
-
else if (!bestRoute
|
|
143
|
+
else if (!bestRoute || !bestRoute.result)
|
|
144
|
+
return { title: 'Swap', disabled: true };
|
|
140
145
|
else if (hasLimitError) return { title: 'Limit Error', disabled: true };
|
|
141
146
|
else if (highValueLoss)
|
|
142
147
|
return { title: 'Price impact is too high!', disabled: true };
|
|
@@ -187,6 +192,7 @@ export function calculatePendingSwap(
|
|
|
187
192
|
finishTime: null,
|
|
188
193
|
requestId: bestRoute.requestId || '',
|
|
189
194
|
inputAmount: inputAmount,
|
|
195
|
+
//@ts-ignore
|
|
190
196
|
wallets,
|
|
191
197
|
status: 'running',
|
|
192
198
|
isPaused: false,
|
|
@@ -201,6 +207,7 @@ export function calculatePendingSwap(
|
|
|
201
207
|
settings: settings,
|
|
202
208
|
simulationResult: simulationResult,
|
|
203
209
|
validateBalanceOrFee,
|
|
210
|
+
//@ts-ignore
|
|
204
211
|
steps:
|
|
205
212
|
bestRoute.result?.swaps?.map((swap, index) => {
|
|
206
213
|
const swapper = meta.swappers.find(
|
|
@@ -339,25 +346,24 @@ export function hasSlippageError(
|
|
|
339
346
|
|
|
340
347
|
export function getMinRequiredSlippage(
|
|
341
348
|
route: BestRouteResponse
|
|
342
|
-
):
|
|
349
|
+
): string | null {
|
|
343
350
|
const slippages = route.result?.swaps.map(
|
|
344
351
|
(slippage) => slippage.recommendedSlippage
|
|
345
352
|
);
|
|
346
353
|
return (
|
|
347
354
|
slippages
|
|
348
|
-
?.map((s) =>
|
|
349
|
-
?.filter((s) => s > 0)
|
|
350
|
-
?.sort((a, b) => b - a)
|
|
355
|
+
?.map((s) => s?.slippage || '0')
|
|
356
|
+
?.filter((s) => parseFloat(s) > 0)
|
|
357
|
+
?.sort((a, b) => parseFloat(b) - parseFloat(a))
|
|
351
358
|
?.find(() => true) || null
|
|
352
359
|
);
|
|
353
360
|
}
|
|
354
361
|
|
|
355
362
|
export function hasProperSlippage(
|
|
356
363
|
userSlippage: string,
|
|
357
|
-
minRequiredSlippage:
|
|
364
|
+
minRequiredSlippage: string | null
|
|
358
365
|
) {
|
|
359
366
|
if (!minRequiredSlippage) return true;
|
|
360
|
-
//@ts-ignore
|
|
361
367
|
return parseFloat(userSlippage) >= parseFloat(minRequiredSlippage);
|
|
362
368
|
}
|
|
363
369
|
|
|
@@ -386,7 +392,7 @@ export function hasEnoughBalanceAndProperSlippage(
|
|
|
386
392
|
route: BestRouteResponse,
|
|
387
393
|
selectedWallets: SelectedWallet[],
|
|
388
394
|
userSlippage: string,
|
|
389
|
-
minRequiredSlippage:
|
|
395
|
+
minRequiredSlippage: string | null
|
|
390
396
|
): boolean {
|
|
391
397
|
return (
|
|
392
398
|
hasEnoughBalance(route, selectedWallets) &&
|
|
@@ -429,6 +435,8 @@ export function createBestRouteRequestBody(
|
|
|
429
435
|
});
|
|
430
436
|
});
|
|
431
437
|
|
|
438
|
+
const filteredBlockchains = selectedWallets.map((wallet) => wallet.chain);
|
|
439
|
+
|
|
432
440
|
const requestBody: BestRouteRequest = {
|
|
433
441
|
amount: inputAmount.toString(),
|
|
434
442
|
checkPrerequisites,
|
|
@@ -446,8 +454,8 @@ export function createBestRouteRequestBody(
|
|
|
446
454
|
selectedWallets: selectedWalletsMap,
|
|
447
455
|
swapperGroups: disabledLiquiditySources,
|
|
448
456
|
swappersGroupsExclude: true,
|
|
449
|
-
//@ts-ignore
|
|
450
457
|
slippage: slippage.toString(),
|
|
458
|
+
...(checkPrerequisites && { blockchains: filteredBlockchains }),
|
|
451
459
|
};
|
|
452
460
|
|
|
453
461
|
return requestBody;
|
|
@@ -550,3 +558,87 @@ export function calcOutputUsdValue(
|
|
|
550
558
|
|
|
551
559
|
return amount.multipliedBy(tokenPrice || 0);
|
|
552
560
|
}
|
|
561
|
+
|
|
562
|
+
export function isNetworkStatusInWarningState(
|
|
563
|
+
pendingSwapStep: PendingSwapStep | null
|
|
564
|
+
): boolean {
|
|
565
|
+
return (
|
|
566
|
+
!!pendingSwapStep &&
|
|
567
|
+
pendingSwapStep.networkStatus !== null &&
|
|
568
|
+
pendingSwapStep.networkStatus !== PendingSwapNetworkStatus.NetworkChanged
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
export function getSwapMessages(
|
|
573
|
+
pendingSwap: PendingSwap,
|
|
574
|
+
currentStep: PendingSwapStep | null
|
|
575
|
+
): {
|
|
576
|
+
shortMessage: string;
|
|
577
|
+
detailedMessage: { content: string; long: boolean };
|
|
578
|
+
} {
|
|
579
|
+
const textForRemove = 'bellow button or';
|
|
580
|
+
let message = pendingSwap.extraMessage;
|
|
581
|
+
let detailedMessage = pendingSwap.extraMessageDetail;
|
|
582
|
+
|
|
583
|
+
if (pendingSwap.networkStatusExtraMessageDetail?.includes(textForRemove)) {
|
|
584
|
+
pendingSwap.networkStatusExtraMessageDetail =
|
|
585
|
+
pendingSwap.networkStatusExtraMessageDetail.replace(textForRemove, '');
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
const networkWarningState = isNetworkStatusInWarningState(currentStep);
|
|
589
|
+
|
|
590
|
+
if (networkWarningState) {
|
|
591
|
+
message = pendingSwap.networkStatusExtraMessage || '';
|
|
592
|
+
detailedMessage = pendingSwap.networkStatusExtraMessageDetail || '';
|
|
593
|
+
switch (currentStep?.networkStatus) {
|
|
594
|
+
case PendingSwapNetworkStatus.WaitingForConnectingWallet:
|
|
595
|
+
message = message || 'Waiting for connecting wallet';
|
|
596
|
+
break;
|
|
597
|
+
case PendingSwapNetworkStatus.WaitingForQueue:
|
|
598
|
+
message = message || 'Waiting for other running tasks to be finished';
|
|
599
|
+
break;
|
|
600
|
+
case PendingSwapNetworkStatus.WaitingForNetworkChange:
|
|
601
|
+
message = message || 'Waiting for changing wallet network';
|
|
602
|
+
break;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
detailedMessage = detailedMessage || '';
|
|
606
|
+
message = message || '';
|
|
607
|
+
const isRpc =
|
|
608
|
+
message?.indexOf('code') !== -1 && message?.indexOf('reason') !== -1;
|
|
609
|
+
|
|
610
|
+
return {
|
|
611
|
+
shortMessage: message,
|
|
612
|
+
detailedMessage: { content: detailedMessage, long: isRpc },
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
export function getLastConvertedTokenInFailedSwap(
|
|
617
|
+
pendingSwap: PendingSwap
|
|
618
|
+
): ConvertedToken {
|
|
619
|
+
let resultToken: ConvertedToken = null;
|
|
620
|
+
if (pendingSwap.status === 'failed') {
|
|
621
|
+
const lastSuccessStep = pendingSwap.steps
|
|
622
|
+
.slice()
|
|
623
|
+
.reverse()
|
|
624
|
+
.filter((step) => step.status === 'success')[0];
|
|
625
|
+
|
|
626
|
+
if (lastSuccessStep) {
|
|
627
|
+
resultToken = {
|
|
628
|
+
blockchain: lastSuccessStep.toBlockchain,
|
|
629
|
+
symbol: lastSuccessStep.toSymbol,
|
|
630
|
+
outputAmount: lastSuccessStep.outputAmount,
|
|
631
|
+
address: lastSuccessStep.toSymbolAddress,
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return resultToken;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
export function shouldRetrySwap(pendingSwap: PendingSwap) {
|
|
639
|
+
return (
|
|
640
|
+
pendingSwap.status === 'failed' &&
|
|
641
|
+
!!pendingSwap.finishTime &&
|
|
642
|
+
new Date().getTime() - parseInt(pendingSwap.finishTime) < 4 * 3600 * 1000
|
|
643
|
+
);
|
|
644
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { PendingSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
2
|
+
|
|
3
|
+
export function timeSince(timeMillis: number): string {
|
|
4
|
+
const seconds = Math.floor((new Date().getTime() - timeMillis) / 1000);
|
|
5
|
+
let intervalType: string;
|
|
6
|
+
|
|
7
|
+
let interval = Math.floor(seconds / 31536000);
|
|
8
|
+
if (interval >= 1) {
|
|
9
|
+
intervalType = 'year';
|
|
10
|
+
} else {
|
|
11
|
+
interval = Math.floor(seconds / 2592000);
|
|
12
|
+
if (interval >= 1) {
|
|
13
|
+
intervalType = 'month';
|
|
14
|
+
} else {
|
|
15
|
+
interval = Math.floor(seconds / 86400);
|
|
16
|
+
if (interval >= 1) {
|
|
17
|
+
intervalType = 'day';
|
|
18
|
+
} else {
|
|
19
|
+
interval = Math.floor(seconds / 3600);
|
|
20
|
+
if (interval >= 1) {
|
|
21
|
+
intervalType = 'hour';
|
|
22
|
+
} else {
|
|
23
|
+
interval = Math.floor(seconds / 60);
|
|
24
|
+
if (interval >= 1) {
|
|
25
|
+
intervalType = 'minute';
|
|
26
|
+
} else {
|
|
27
|
+
interval = seconds;
|
|
28
|
+
intervalType = 'second';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (interval > 1 || interval === 0) {
|
|
36
|
+
intervalType += 's';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return interval + ' ' + intervalType;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function getSwapDate(pendingSwap: PendingSwap) {
|
|
43
|
+
return pendingSwap.finishTime
|
|
44
|
+
? `Finished ${timeSince(parseInt(pendingSwap.finishTime))} ago @ ${new Date(
|
|
45
|
+
parseInt(pendingSwap.finishTime)
|
|
46
|
+
).toLocaleString()}`
|
|
47
|
+
: `Started ${timeSince(
|
|
48
|
+
parseInt(pendingSwap.creationTime)
|
|
49
|
+
)} ago @ ${new Date(
|
|
50
|
+
parseInt(pendingSwap.creationTime)
|
|
51
|
+
).toLocaleString()}`;
|
|
52
|
+
}
|
package/src/utils/wallets.ts
CHANGED
|
@@ -441,10 +441,13 @@ export function getSortedTokens(
|
|
|
441
441
|
return sortTokens(getTokensWithBalance(filteredTokens, balances));
|
|
442
442
|
}
|
|
443
443
|
|
|
444
|
-
export function tokensAreEqual(
|
|
444
|
+
export function tokensAreEqual(
|
|
445
|
+
tokenA: Pick<Token, 'blockchain' | 'symbol' | 'address'> | null,
|
|
446
|
+
tokenB: Pick<Token, 'blockchain' | 'symbol' | 'address'> | null
|
|
447
|
+
) {
|
|
445
448
|
return (
|
|
446
449
|
tokenA?.blockchain === tokenB?.blockchain &&
|
|
447
|
-
tokenA?.
|
|
450
|
+
tokenA?.symbol === tokenB?.symbol &&
|
|
448
451
|
tokenA?.address === tokenB?.address
|
|
449
452
|
);
|
|
450
453
|
}
|
|
@@ -469,7 +472,13 @@ export function sortWalletsBasedOnState(
|
|
|
469
472
|
(a, b) =>
|
|
470
473
|
Number(b.state === WalletStatus.CONNECTED) -
|
|
471
474
|
Number(a.state === WalletStatus.CONNECTED) ||
|
|
472
|
-
Number(
|
|
473
|
-
|
|
475
|
+
Number(
|
|
476
|
+
b.state === WalletStatus.DISCONNECTED ||
|
|
477
|
+
b.state === WalletStatus.CONNECTING
|
|
478
|
+
) -
|
|
479
|
+
Number(
|
|
480
|
+
a.state === WalletStatus.DISCONNECTED ||
|
|
481
|
+
a.state === WalletStatus.CONNECTING
|
|
482
|
+
)
|
|
474
483
|
);
|
|
475
484
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export declare const HeaderContainer: any;
|
|
3
|
-
export interface PropTypes {
|
|
4
|
-
onClickRefresh: () => void;
|
|
5
|
-
title?: string;
|
|
6
|
-
titleSize?: number;
|
|
7
|
-
titleWeight?: number;
|
|
8
|
-
}
|
|
9
|
-
export declare function Header(props: PropTypes): JSX.Element;
|
|
10
|
-
//# sourceMappingURL=Header.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Header.d.ts","sourceRoot":"","sources":["../src/components/Header.tsx"],"names":[],"mappings":";AAKA,eAAO,MAAM,eAAe,KAM1B,CAAC;AAEH,MAAM,WAAW,SAAS;IACxB,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,SAAS,eAgBtC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConfirmWalletsPage.d.ts","sourceRoot":"","sources":["../src/pages/ConfirmWalletsPage.tsx"],"names":[],"mappings":";AA4BA,wBAAgB,kBAAkB,gBAkGjC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { css, styled, Typography } from '@rango-dev/ui';
|
|
3
|
-
import { HeaderButtons } from './HeaderButtons';
|
|
4
|
-
import { useTranslation } from 'react-i18next';
|
|
5
|
-
|
|
6
|
-
export const HeaderContainer = styled('div', {
|
|
7
|
-
display: 'flex',
|
|
8
|
-
justifyContent: 'space-between',
|
|
9
|
-
alignItems: 'center',
|
|
10
|
-
width: '100%',
|
|
11
|
-
padding: '$16 0',
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
export interface PropTypes {
|
|
15
|
-
onClickRefresh: () => void;
|
|
16
|
-
title?: string;
|
|
17
|
-
titleSize?: number;
|
|
18
|
-
titleWeight?: number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function Header(props: PropTypes) {
|
|
22
|
-
const { onClickRefresh, title, titleSize, titleWeight } = props;
|
|
23
|
-
const { t } = useTranslation();
|
|
24
|
-
const titleStyle = css({
|
|
25
|
-
fontSize: `${titleSize}px !important`,
|
|
26
|
-
fontWeight: `${titleWeight} !important`,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<HeaderContainer>
|
|
31
|
-
<Typography variant="h4" className={titleStyle()}>
|
|
32
|
-
{title ? t(title.toLocaleLowerCase()) : ''}
|
|
33
|
-
</Typography>
|
|
34
|
-
<HeaderButtons onClickRefresh={onClickRefresh} />
|
|
35
|
-
</HeaderContainer>
|
|
36
|
-
);
|
|
37
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from 'react';
|
|
2
|
-
import { ConfirmWallets } from '@rango-dev/ui';
|
|
3
|
-
import { useNavigate } from 'react-router-dom';
|
|
4
|
-
import { useBestRouteStore } from '../store/bestRoute';
|
|
5
|
-
import { useWalletsStore } from '../store/wallets';
|
|
6
|
-
import { useWallets } from '@rango-dev/wallets-core';
|
|
7
|
-
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
8
|
-
import {
|
|
9
|
-
getKeplrCompatibleConnectedWallets,
|
|
10
|
-
getRequiredChains,
|
|
11
|
-
getSelectableWallets,
|
|
12
|
-
isExperimentalChain,
|
|
13
|
-
} from '../utils/wallets';
|
|
14
|
-
import {
|
|
15
|
-
calcOutputUsdValue,
|
|
16
|
-
getTotalFeeInUsd,
|
|
17
|
-
requiredWallets,
|
|
18
|
-
} from '../utils/swap';
|
|
19
|
-
import { decimalNumber, numberToString } from '../utils/numbers';
|
|
20
|
-
import { useMetaStore } from '../store/meta';
|
|
21
|
-
import { Network, WalletType } from '@rango-dev/wallets-shared';
|
|
22
|
-
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
23
|
-
import { TokenPreview } from '../components/TokenPreview';
|
|
24
|
-
// @ts-ignore // TODO: fix error in tsc build
|
|
25
|
-
import { t } from 'i18next';
|
|
26
|
-
import { Spacer } from '@rango-dev/ui';
|
|
27
|
-
import RoutesOverview from '../components/RoutesOverview';
|
|
28
|
-
|
|
29
|
-
export function ConfirmWalletsPage() {
|
|
30
|
-
const navigate = useNavigate();
|
|
31
|
-
const { navigateBackFrom } = useNavigateBack();
|
|
32
|
-
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
33
|
-
|
|
34
|
-
const { blockchains, tokens } = useMetaStore.use.meta();
|
|
35
|
-
const accounts = useWalletsStore.use.accounts();
|
|
36
|
-
const selectedWallets = useWalletsStore.use.selectedWallets();
|
|
37
|
-
const initSelectedWallets = useWalletsStore.use.initSelectedWallets();
|
|
38
|
-
const setSelectedWallet = useWalletsStore.use.setSelectedWallet();
|
|
39
|
-
|
|
40
|
-
const { getWalletInfo, connect } = useWallets();
|
|
41
|
-
const confirmDisabled = !requiredWallets(bestRoute).every((chain) =>
|
|
42
|
-
selectedWallets.map((wallet) => wallet.chain).includes(chain)
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const firstStep = bestRoute?.result?.swaps[0];
|
|
46
|
-
const lastStep =
|
|
47
|
-
bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1];
|
|
48
|
-
|
|
49
|
-
const fromAmount = decimalNumber(firstStep?.fromAmount, 3);
|
|
50
|
-
const toAmount = decimalNumber(lastStep?.toAmount, 3);
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
initSelectedWallets();
|
|
53
|
-
}, []);
|
|
54
|
-
|
|
55
|
-
const selectableWallets = getSelectableWallets(
|
|
56
|
-
accounts,
|
|
57
|
-
selectedWallets,
|
|
58
|
-
getWalletInfo
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
const handleConnectChain = (wallet: string) => {
|
|
62
|
-
const network = wallet as Network;
|
|
63
|
-
getKeplrCompatibleConnectedWallets(selectableWallets).forEach(
|
|
64
|
-
(compatibleWallet: WalletType) => connect?.(compatibleWallet, network)
|
|
65
|
-
);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
69
|
-
|
|
70
|
-
return (
|
|
71
|
-
<ConfirmWallets
|
|
72
|
-
requiredWallets={getRequiredChains(bestRoute)}
|
|
73
|
-
selectableWallets={selectableWallets}
|
|
74
|
-
onBack={navigateBackFrom.bind(null, navigationRoutes.confirmWallets)}
|
|
75
|
-
onConfirm={() =>
|
|
76
|
-
navigate(navigationRoutes.confirmSwap, { replace: true })
|
|
77
|
-
}
|
|
78
|
-
onChange={(wallet) => setSelectedWallet(wallet)}
|
|
79
|
-
confirmDisabled={confirmDisabled}
|
|
80
|
-
handleConnectChain={(wallet) => handleConnectChain(wallet)}
|
|
81
|
-
isExperimentalChain={(wallet) =>
|
|
82
|
-
getKeplrCompatibleConnectedWallets(selectableWallets).length > 0
|
|
83
|
-
? isExperimentalChain(blockchains, wallet)
|
|
84
|
-
: false
|
|
85
|
-
}
|
|
86
|
-
previewInputs={
|
|
87
|
-
<>
|
|
88
|
-
<TokenPreview
|
|
89
|
-
chain={{
|
|
90
|
-
displayName: firstStep?.from.blockchain || '',
|
|
91
|
-
logo: firstStep?.from.blockchainLogo || '',
|
|
92
|
-
}}
|
|
93
|
-
token={{
|
|
94
|
-
symbol: firstStep?.from.symbol || '',
|
|
95
|
-
image: firstStep?.from.logo || '',
|
|
96
|
-
}}
|
|
97
|
-
usdValue={calcOutputUsdValue(fromAmount, firstStep?.from.usdPrice)}
|
|
98
|
-
amount={fromAmount}
|
|
99
|
-
label={t('From')}
|
|
100
|
-
loadingStatus={'success'}
|
|
101
|
-
/>
|
|
102
|
-
<Spacer size={12} direction="vertical" />
|
|
103
|
-
<TokenPreview
|
|
104
|
-
chain={{
|
|
105
|
-
displayName: lastStep?.to.blockchain || '',
|
|
106
|
-
logo: lastStep?.to.blockchainLogo || '',
|
|
107
|
-
}}
|
|
108
|
-
token={{
|
|
109
|
-
symbol: lastStep?.to.symbol || '',
|
|
110
|
-
image: lastStep?.to.logo || '',
|
|
111
|
-
}}
|
|
112
|
-
usdValue={calcOutputUsdValue(toAmount, lastStep?.to.usdPrice)}
|
|
113
|
-
amount={toAmount}
|
|
114
|
-
label={t('To')}
|
|
115
|
-
loadingStatus={'success'}
|
|
116
|
-
/>
|
|
117
|
-
</>
|
|
118
|
-
}
|
|
119
|
-
previewRoutes={
|
|
120
|
-
<RoutesOverview
|
|
121
|
-
routes={bestRoute}
|
|
122
|
-
totalFee={numberToString(totalFeeInUsd, 0, 2)}
|
|
123
|
-
/>
|
|
124
|
-
}
|
|
125
|
-
/>
|
|
126
|
-
);
|
|
127
|
-
}
|