@rango-dev/widget-embedded 0.1.10 → 0.1.11-next.4
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 +3 -3
- package/dist/App.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts +1 -7
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts +2 -2
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/Layout.d.ts +3 -3
- 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/TokenInfo.d.ts.map +1 -1
- package/dist/components/TokenPreview.d.ts +2 -1
- package/dist/components/TokenPreview.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap.d.ts.map +1 -1
- package/dist/hooks/useTheme.d.ts +2 -5
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/lib.d.ts +2 -2
- package/dist/lib.d.ts.map +1 -1
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts +1 -7
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/LiquiditySourcesPage.d.ts +1 -2
- package/dist/pages/LiquiditySourcesPage.d.ts.map +1 -1
- package/dist/pages/SelectChainPage.d.ts +1 -2
- package/dist/pages/SelectChainPage.d.ts.map +1 -1
- package/dist/pages/SelectTokenPage.d.ts +2 -2
- package/dist/pages/SelectTokenPage.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts +1 -2
- 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 -1
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/store/bestRoute.d.ts +1 -0
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/settings.d.ts +2 -0
- package/dist/store/settings.d.ts.map +1 -1
- package/dist/types/config.d.ts +26 -29
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/routing.d.ts +14 -1
- package/dist/types/routing.d.ts.map +1 -1
- package/dist/utils/routing.d.ts +2 -2
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +2 -6
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +181 -193
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +181 -193
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +181 -193
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +6 -4
- package/readme.md +1 -1
- package/src/App.tsx +21 -13
- package/src/components/AppRouter.tsx +7 -16
- package/src/components/AppRoutes.tsx +13 -32
- package/src/components/Layout.tsx +32 -23
- package/src/components/PercentageChange.tsx +33 -0
- package/src/components/TokenInfo.tsx +20 -4
- package/src/components/TokenPreview.tsx +16 -8
- package/src/hooks/useConfirmSwap.ts +5 -4
- package/src/hooks/useTheme.ts +15 -9
- package/src/lib.tsx +30 -36
- package/src/pages/ConfirmSwapPage.tsx +14 -7
- package/src/pages/Home.tsx +10 -22
- package/src/pages/LiquiditySourcesPage.tsx +3 -6
- package/src/pages/SelectChainPage.tsx +6 -6
- package/src/pages/SelectTokenPage.tsx +16 -18
- package/src/pages/SettingsPage.tsx +8 -18
- package/src/pages/SwapDetailsPage.tsx +2 -4
- package/src/pages/WalletsPage.tsx +2 -2
- package/src/store/bestRoute.ts +38 -8
- package/src/store/settings.ts +7 -0
- package/src/types/config.ts +27 -29
- package/src/types/routing.ts +17 -1
- package/src/utils/routing.ts +29 -23
- package/src/utils/swap.ts +5 -97
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { WalletState, InfoCircleIcon, AngleDownIcon,
|
|
1
|
+
import { WalletState, Typography, InfoCircleIcon, AngleDownIcon, Spacer, Button, TextField, styled, Tooltip, RetryIcon, HistoryIcon, SettingsIcon, Header as Header$1, VerticalSwapIcon, BestRoute, Alert, ChevronRightIcon, GasIcon, ConfirmSwap, History, LiquiditySourcesSelector, BlockchainSelector, TokenSelector, Settings, SecondaryPage, Spinner, LoadingFailedAlert, Wallet, SwapHistory, AddWalletIcon, globalCss, createTheme, SwapContainer } from '@rango-dev/ui';
|
|
2
2
|
import React, { useRef, useEffect, useState, useLayoutEffect } from 'react';
|
|
3
3
|
import { useInRouterContext as useInRouterContext$1, MemoryRouter, useLocation as useLocation$1, useNavigate as useNavigate$1 } from 'react-router';
|
|
4
|
-
import { PendingSwapNetworkStatus, useQueueManager, getCurrentStep, getCurrentBlockchainOfOrNull, getRelatedWalletOrNull, cancelSwap, swapQueueDef, checkWaitingForNetworkChange } from '@rango-dev/queue-manager-rango-preset';
|
|
4
|
+
import { PendingSwapNetworkStatus, useQueueManager, calculatePendingSwap, getCurrentStep, getCurrentBlockchainOfOrNull, getRelatedWalletOrNull, cancelSwap, swapQueueDef, checkWaitingForNetworkChange } from '@rango-dev/queue-manager-rango-preset';
|
|
5
5
|
import { isCosmosBlockchain, isEvmBlockchain } from 'rango-types';
|
|
6
6
|
import { useSearchParams, useLocation, createSearchParams, useNavigate, useInRouterContext, useRoutes } from 'react-router-dom';
|
|
7
7
|
import { create } from 'zustand';
|
|
@@ -436,7 +436,7 @@ function getSwapButtonState(loadingMetaStatus, accounts, loading, bestRoute, has
|
|
|
436
436
|
};else if (inputIsZero) return {
|
|
437
437
|
title: 'Enter an amount',
|
|
438
438
|
disabled: true
|
|
439
|
-
};else if (!bestRoute) return {
|
|
439
|
+
};else if (!bestRoute || !bestRoute.result) return {
|
|
440
440
|
title: 'Swap',
|
|
441
441
|
disabled: true
|
|
442
442
|
};else if (hasLimitError) return {
|
|
@@ -461,80 +461,6 @@ function getSwapButtonState(loadingMetaStatus, accounts, loading, bestRoute, has
|
|
|
461
461
|
function canComputePriceImpact(bestRoute, inputAmount, inputUsdValue, outputUsdValue) {
|
|
462
462
|
return !((inputUsdValue.lte(ZERO) || outputUsdValue.lte(ZERO)) && !!bestRoute?.result && !!inputAmount && inputAmount !== '0' && parseFloat(inputAmount || '0') !== 0 && !!bestRoute.result);
|
|
463
463
|
}
|
|
464
|
-
function calculatePendingSwap(inputAmount, bestRoute, wallets, settings, validateBalanceOrFee, meta) {
|
|
465
|
-
const simulationResult = bestRoute.result;
|
|
466
|
-
if (!simulationResult) throw Error('Simulation result should not be null');
|
|
467
|
-
return {
|
|
468
|
-
creationTime: new Date().getTime().toString(),
|
|
469
|
-
finishTime: null,
|
|
470
|
-
requestId: bestRoute.requestId || '',
|
|
471
|
-
inputAmount: inputAmount,
|
|
472
|
-
//@ts-ignore
|
|
473
|
-
wallets,
|
|
474
|
-
status: 'running',
|
|
475
|
-
isPaused: false,
|
|
476
|
-
extraMessage: null,
|
|
477
|
-
extraMessageSeverity: null,
|
|
478
|
-
extraMessageDetail: null,
|
|
479
|
-
extraMessageErrorCode: null,
|
|
480
|
-
networkStatusExtraMessage: null,
|
|
481
|
-
networkStatusExtraMessageDetail: null,
|
|
482
|
-
lastNotificationTime: null,
|
|
483
|
-
//@ts-ignore
|
|
484
|
-
settings: settings,
|
|
485
|
-
simulationResult: simulationResult,
|
|
486
|
-
validateBalanceOrFee,
|
|
487
|
-
//@ts-ignore
|
|
488
|
-
steps: bestRoute.result?.swaps?.map((swap, index) => {
|
|
489
|
-
const swapper = meta.swappers.find(swapper => swapper.id === swap.swapperId);
|
|
490
|
-
const swapperType = swapper?.types[0];
|
|
491
|
-
const fromBlockchain = meta.blockchains.find(blockchain => blockchain.name === swap.from.blockchain);
|
|
492
|
-
const toBlockchain = meta.blockchains.find(blockchain => blockchain.name === swap.to.blockchain);
|
|
493
|
-
return {
|
|
494
|
-
id: index + 1,
|
|
495
|
-
fromBlockchain: swap.from.blockchain,
|
|
496
|
-
fromSymbol: swap.from.symbol,
|
|
497
|
-
fromSymbolAddress: swap.from.address,
|
|
498
|
-
fromDecimals: swap.from.decimals,
|
|
499
|
-
fromAmountPrecision: swap.fromAmountPrecision,
|
|
500
|
-
fromAmountMinValue: swap.fromAmountMinValue,
|
|
501
|
-
fromAmountMaxValue: swap.fromAmountMaxValue,
|
|
502
|
-
toBlockchain: swap.to.blockchain,
|
|
503
|
-
fromLogo: swap.from.logo,
|
|
504
|
-
toSymbol: swap.to.symbol,
|
|
505
|
-
toSymbolAddress: swap.to.address,
|
|
506
|
-
toDecimals: swap.to.decimals,
|
|
507
|
-
toLogo: swap.to.logo,
|
|
508
|
-
startTransactionTime: new Date().getTime(),
|
|
509
|
-
swapperId: swap.swapperId,
|
|
510
|
-
feeInUsd: numberToString(getUsdFeeOfStep(swap, meta.tokens), null, 2),
|
|
511
|
-
expectedOutputAmountHumanReadable: swap.toAmount,
|
|
512
|
-
outputAmount: '',
|
|
513
|
-
status: 'created',
|
|
514
|
-
networkStatus: null,
|
|
515
|
-
executedTransactionId: null,
|
|
516
|
-
externalTransactionId: null,
|
|
517
|
-
explorerUrl: null,
|
|
518
|
-
trackingCode: null,
|
|
519
|
-
cosmosTransaction: null,
|
|
520
|
-
solanaTransaction: null,
|
|
521
|
-
starknetTransaction: null,
|
|
522
|
-
starknetApprovalTransaction: null,
|
|
523
|
-
tronTransaction: null,
|
|
524
|
-
tronApprovalTransaction: null,
|
|
525
|
-
evmTransaction: null,
|
|
526
|
-
evmApprovalTransaction: null,
|
|
527
|
-
transferTransaction: null,
|
|
528
|
-
diagnosisUrl: null,
|
|
529
|
-
internalSteps: null,
|
|
530
|
-
fromBlockchainLogo: fromBlockchain?.logo || '',
|
|
531
|
-
toBlockchainLogo: toBlockchain?.logo || '',
|
|
532
|
-
swapperLogo: swapper?.logo || '',
|
|
533
|
-
swapperType: swapperType || ''
|
|
534
|
-
};
|
|
535
|
-
}) || []
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
464
|
function requiredWallets(route) {
|
|
539
465
|
const wallets = [];
|
|
540
466
|
route?.result?.swaps.forEach(swap => {
|
|
@@ -576,7 +502,7 @@ function hasProperSlippage(userSlippage, minRequiredSlippage) {
|
|
|
576
502
|
if (!minRequiredSlippage) return true;
|
|
577
503
|
return parseFloat(userSlippage) >= parseFloat(minRequiredSlippage);
|
|
578
504
|
}
|
|
579
|
-
function createBestRouteRequestBody(fromToken, toToken, inputAmount, wallets, selectedWallets, disabledLiquiditySources, slippage, checkPrerequisites) {
|
|
505
|
+
function createBestRouteRequestBody(fromToken, toToken, inputAmount, wallets, selectedWallets, disabledLiquiditySources, slippage, checkPrerequisites, affiliateRef) {
|
|
580
506
|
const selectedWalletsMap = selectedWallets.reduce((selectedWalletsMap, selectedWallet) => (selectedWalletsMap[selectedWallet.chain] = selectedWallet.address, selectedWalletsMap), {});
|
|
581
507
|
const connectedWallets = [];
|
|
582
508
|
wallets.forEach(wallet => {
|
|
@@ -589,6 +515,7 @@ function createBestRouteRequestBody(fromToken, toToken, inputAmount, wallets, se
|
|
|
589
515
|
const filteredBlockchains = selectedWallets.map(wallet => wallet.chain);
|
|
590
516
|
const requestBody = {
|
|
591
517
|
amount: inputAmount.toString(),
|
|
518
|
+
affiliateRef,
|
|
592
519
|
checkPrerequisites,
|
|
593
520
|
from: {
|
|
594
521
|
address: fromToken.address,
|
|
@@ -744,8 +671,21 @@ function getRequiredBalanceOfWallet(selectedWallet, fee) {
|
|
|
744
671
|
if (!relatedFeeStatus) return null;
|
|
745
672
|
return relatedFeeStatus.requiredAssets;
|
|
746
673
|
}
|
|
747
|
-
function isRouteParametersChanged(
|
|
748
|
-
|
|
674
|
+
function isRouteParametersChanged(params) {
|
|
675
|
+
if (params.store === 'bestRoute') {
|
|
676
|
+
const {
|
|
677
|
+
prevState,
|
|
678
|
+
currentState
|
|
679
|
+
} = params;
|
|
680
|
+
return !!currentState.fromToken && !!currentState.toToken && (prevState.fromChain?.name !== currentState.fromChain?.name || prevState.toChain?.name !== currentState.toChain?.name || prevState.fromToken?.symbol !== currentState.fromToken?.symbol || prevState.toToken?.symbol !== currentState.toToken?.symbol || prevState.fromToken?.blockchain !== prevState.fromToken?.blockchain || prevState.toToken?.blockchain !== currentState.toToken?.blockchain || prevState.fromToken?.address !== currentState.fromToken?.address || prevState.toToken?.address !== currentState.toToken?.address || prevState.inputAmount !== currentState.inputAmount);
|
|
681
|
+
} else if (params.store === 'settings') {
|
|
682
|
+
const {
|
|
683
|
+
prevState,
|
|
684
|
+
currentState
|
|
685
|
+
} = params;
|
|
686
|
+
return prevState.slippage !== currentState.slippage || prevState.customSlippage !== currentState.customSlippage || prevState.disabledLiquiditySources?.length !== currentState.disabledLiquiditySources?.length || prevState.infiniteApprove || currentState.infiniteApprove;
|
|
687
|
+
}
|
|
688
|
+
return false;
|
|
749
689
|
}
|
|
750
690
|
//todo: refactor bestRoute store and add loadingStatus
|
|
751
691
|
const getBestRouteStatus = (loading, error) => {
|
|
@@ -800,6 +740,7 @@ const useSettingsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /*
|
|
|
800
740
|
slippage: DEFAULT_SLIPPAGE,
|
|
801
741
|
customSlippage: null,
|
|
802
742
|
infiniteApprove: false,
|
|
743
|
+
affiliateRef: null,
|
|
803
744
|
disabledLiquiditySources: [],
|
|
804
745
|
theme: 'auto',
|
|
805
746
|
setSlippage: slippage => set(() => ({
|
|
@@ -808,6 +749,9 @@ const useSettingsStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /*
|
|
|
808
749
|
setCustomSlippage: customSlippage => set(() => ({
|
|
809
750
|
customSlippage: customSlippage
|
|
810
751
|
})),
|
|
752
|
+
setAffiliateRef: affiliateRef => set(() => ({
|
|
753
|
+
affiliateRef
|
|
754
|
+
})),
|
|
811
755
|
toggleAllLiquiditySources: () => set(state => {
|
|
812
756
|
const {
|
|
813
757
|
swappers
|
|
@@ -1011,7 +955,6 @@ const useBestRouteStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /
|
|
|
1011
955
|
toToken: token
|
|
1012
956
|
})),
|
|
1013
957
|
setInputAmount: amount => {
|
|
1014
|
-
console.log(amount, typeof amount);
|
|
1015
958
|
set(state => ({
|
|
1016
959
|
inputAmount: amount,
|
|
1017
960
|
...(!amount && {
|
|
@@ -1064,7 +1007,17 @@ const useBestRouteStore = /*#__PURE__*/createSelectors( /*#__PURE__*/create()( /
|
|
|
1064
1007
|
sourceTokens: sortedSourceTokens,
|
|
1065
1008
|
destinationTokens: sortedDestinationTokens
|
|
1066
1009
|
});
|
|
1067
|
-
}
|
|
1010
|
+
},
|
|
1011
|
+
switchFromAndTo: () => set(state => ({
|
|
1012
|
+
fromChain: state.toChain,
|
|
1013
|
+
fromToken: state.toToken,
|
|
1014
|
+
toChain: state.fromChain,
|
|
1015
|
+
toToken: state.fromToken,
|
|
1016
|
+
sourceTokens: state.destinationTokens,
|
|
1017
|
+
destinationTokens: state.sourceTokens,
|
|
1018
|
+
inputAmount: state.outputAmount?.toString() || '',
|
|
1019
|
+
inputUsdValue: getUsdValue(state.toToken, state.outputAmount?.toString() || '')
|
|
1020
|
+
}))
|
|
1068
1021
|
}))));
|
|
1069
1022
|
const bestRoute = (bestRouteStore, settingsStore) => {
|
|
1070
1023
|
let abortController = null;
|
|
@@ -1077,13 +1030,14 @@ const bestRoute = (bestRouteStore, settingsStore) => {
|
|
|
1077
1030
|
const {
|
|
1078
1031
|
slippage,
|
|
1079
1032
|
customSlippage,
|
|
1080
|
-
disabledLiquiditySources
|
|
1033
|
+
disabledLiquiditySources,
|
|
1034
|
+
affiliateRef
|
|
1081
1035
|
} = settingsStore.getState();
|
|
1082
1036
|
if (!fromToken || !toToken || !inputAmount || inputAmount === '0') return;
|
|
1083
1037
|
abortController?.abort();
|
|
1084
1038
|
abortController = new AbortController();
|
|
1085
1039
|
const userSlippage = !!customSlippage ? customSlippage : slippage;
|
|
1086
|
-
const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, [], [], disabledLiquiditySources, userSlippage, false);
|
|
1040
|
+
const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, [], [], disabledLiquiditySources, userSlippage, false, affiliateRef);
|
|
1087
1041
|
if (!bestRouteStore.getState().loading) bestRouteStore.setState({
|
|
1088
1042
|
loading: true,
|
|
1089
1043
|
bestRoute: null,
|
|
@@ -1117,7 +1071,7 @@ const bestRoute = (bestRouteStore, settingsStore) => {
|
|
|
1117
1071
|
inputAmount,
|
|
1118
1072
|
inputUsdValue
|
|
1119
1073
|
} = useBestRouteStore.getState();
|
|
1120
|
-
if (!inputAmount || inputAmount === '0') return;
|
|
1074
|
+
if (!inputAmount || inputAmount === '0' || inputUsdValue.eq(0)) return;
|
|
1121
1075
|
if (tokensAreEqual(fromToken, toToken)) return bestRouteStore.setState({
|
|
1122
1076
|
loading: false,
|
|
1123
1077
|
bestRoute: null,
|
|
@@ -1139,17 +1093,26 @@ const bestRoute = (bestRouteStore, settingsStore) => {
|
|
|
1139
1093
|
toToken: state.toToken,
|
|
1140
1094
|
inputAmount: state.inputAmount
|
|
1141
1095
|
}), bestRouteParamsListener, {
|
|
1142
|
-
equalityFn: (prevState,
|
|
1143
|
-
if (isRouteParametersChanged(
|
|
1096
|
+
equalityFn: (prevState, currentState) => {
|
|
1097
|
+
if (isRouteParametersChanged({
|
|
1098
|
+
store: 'bestRoute',
|
|
1099
|
+
prevState,
|
|
1100
|
+
currentState
|
|
1101
|
+
})) return false;else return true;
|
|
1144
1102
|
}
|
|
1145
1103
|
});
|
|
1146
1104
|
useSettingsStore.subscribe(state => ({
|
|
1147
1105
|
slippage: state.slippage,
|
|
1148
1106
|
customSlippage: state.customSlippage,
|
|
1149
|
-
disabledLiquiditySources: state.disabledLiquiditySources
|
|
1107
|
+
disabledLiquiditySources: state.disabledLiquiditySources,
|
|
1108
|
+
infiniteApprove: state.infiniteApprove
|
|
1150
1109
|
}), bestRouteParamsListener, {
|
|
1151
|
-
equalityFn: (prevState,
|
|
1152
|
-
if (isRouteParametersChanged(
|
|
1110
|
+
equalityFn: (prevState, currentState) => {
|
|
1111
|
+
if (isRouteParametersChanged({
|
|
1112
|
+
store: 'settings',
|
|
1113
|
+
prevState,
|
|
1114
|
+
currentState
|
|
1115
|
+
})) return false;else return true;
|
|
1153
1116
|
}
|
|
1154
1117
|
});
|
|
1155
1118
|
return {
|
|
@@ -1314,6 +1277,20 @@ function UpdateUrl() {
|
|
|
1314
1277
|
return null;
|
|
1315
1278
|
}
|
|
1316
1279
|
|
|
1280
|
+
function PercentageChange(props) {
|
|
1281
|
+
const {
|
|
1282
|
+
inputUsdValue,
|
|
1283
|
+
outputUsdValue
|
|
1284
|
+
} = props;
|
|
1285
|
+
if (!inputUsdValue || !outputUsdValue || !outputUsdValue.gt(0)) return null;
|
|
1286
|
+
const percentageChange = getPercentageChange(inputUsdValue.toNumber(), outputUsdValue.toNumber());
|
|
1287
|
+
const showPercentageChange = percentageChange?.lt(0);
|
|
1288
|
+
return React.createElement(React.Fragment, null, showPercentageChange && React.createElement(Typography, {
|
|
1289
|
+
variant: "caption",
|
|
1290
|
+
color: "$error500"
|
|
1291
|
+
}, `(${numberToString(percentageChange, 0, 2)}%)`));
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1317
1294
|
const Box = /*#__PURE__*/styled('div', {
|
|
1318
1295
|
display: 'flex',
|
|
1319
1296
|
flexDirection: 'column',
|
|
@@ -1357,6 +1334,13 @@ const Container = /*#__PURE__*/styled('div', {
|
|
|
1357
1334
|
'.amount': {
|
|
1358
1335
|
width: '30%'
|
|
1359
1336
|
}
|
|
1337
|
+
},
|
|
1338
|
+
'.output-usd': {
|
|
1339
|
+
display: 'flex',
|
|
1340
|
+
div: {
|
|
1341
|
+
display: 'flex',
|
|
1342
|
+
paddingLeft: '$8'
|
|
1343
|
+
}
|
|
1360
1344
|
}
|
|
1361
1345
|
});
|
|
1362
1346
|
const StyledImage = /*#__PURE__*/styled('img', {
|
|
@@ -1441,10 +1425,15 @@ function TokenInfo(props) {
|
|
|
1441
1425
|
type: "primary",
|
|
1442
1426
|
variant: "ghost",
|
|
1443
1427
|
size: "compact"
|
|
1444
|
-
}, t('Max')))) : React.createElement(
|
|
1428
|
+
}, t('Max')))) : React.createElement("div", {
|
|
1429
|
+
className: "output-usd"
|
|
1430
|
+
}, React.createElement(PercentageChange, {
|
|
1431
|
+
inputUsdValue: inputUsdValue,
|
|
1432
|
+
outputUsdValue: props.outputUsdValue
|
|
1433
|
+
}), React.createElement("div", null, React.createElement(Typography, {
|
|
1445
1434
|
variant: "caption",
|
|
1446
1435
|
color: "neutrals600"
|
|
1447
|
-
}, `$${numberToString(props.outputUsdValue)}`)), React.createElement("div", {
|
|
1436
|
+
}, `$${numberToString(props.outputUsdValue)}`)))), React.createElement("div", {
|
|
1448
1437
|
className: "form"
|
|
1449
1438
|
}, React.createElement(Button, {
|
|
1450
1439
|
className: "selectors",
|
|
@@ -1656,10 +1645,7 @@ const Alerts = /*#__PURE__*/styled('div', {
|
|
|
1656
1645
|
width: '100%',
|
|
1657
1646
|
paddingTop: '$16'
|
|
1658
1647
|
});
|
|
1659
|
-
function Home(
|
|
1660
|
-
const {
|
|
1661
|
-
title = 'SWAP'
|
|
1662
|
-
} = props;
|
|
1648
|
+
function Home() {
|
|
1663
1649
|
const isRouterInContext = useInRouterContext();
|
|
1664
1650
|
const navigate = useNavigate();
|
|
1665
1651
|
const [count, setCount] = useState(0);
|
|
@@ -1667,10 +1653,6 @@ function Home(props) {
|
|
|
1667
1653
|
const fromToken = useBestRouteStore.use.fromToken();
|
|
1668
1654
|
const toChain = useBestRouteStore.use.toChain();
|
|
1669
1655
|
const toToken = useBestRouteStore.use.toToken();
|
|
1670
|
-
const setFromChain = useBestRouteStore.use.setFromChain();
|
|
1671
|
-
const setFromToken = useBestRouteStore.use.setFromToken();
|
|
1672
|
-
const setToChain = useBestRouteStore.use.setToChain();
|
|
1673
|
-
const setToToken = useBestRouteStore.use.setToToken();
|
|
1674
1656
|
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
1675
1657
|
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
1676
1658
|
const inputAmount = useBestRouteStore.use.inputAmount();
|
|
@@ -1683,14 +1665,7 @@ function Home(props) {
|
|
|
1683
1665
|
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
1684
1666
|
const accounts = useWalletsStore.use.accounts();
|
|
1685
1667
|
const setCurrentPage = useUiStore.use.setCurrentPage();
|
|
1686
|
-
const
|
|
1687
|
-
setFromChain(toChain);
|
|
1688
|
-
setFromToken(toToken);
|
|
1689
|
-
setToChain(fromChain);
|
|
1690
|
-
setToToken(fromToken);
|
|
1691
|
-
setInputAmount(outputAmount?.toString() || '');
|
|
1692
|
-
setCount(prev => prev + 1);
|
|
1693
|
-
};
|
|
1668
|
+
const switchFromAndTo = useBestRouteStore.use.switchFromAndTo();
|
|
1694
1669
|
const errorMessage = loadingMetaStatus === 'failed' ? errorMessages.genericServerError : bestRouteError;
|
|
1695
1670
|
const needsToWarnEthOnPath = false;
|
|
1696
1671
|
const showBestRoute = inputAmount && (!!bestRoute || fetchingBestRoute || bestRouteError);
|
|
@@ -1711,7 +1686,7 @@ function Home(props) {
|
|
|
1711
1686
|
return setCurrentPage.bind(null, '');
|
|
1712
1687
|
}, []);
|
|
1713
1688
|
return React.createElement(Container$2, null, React.createElement(Header$1, {
|
|
1714
|
-
title:
|
|
1689
|
+
title: "SWAP",
|
|
1715
1690
|
suffix: React.createElement(HeaderButtons, {
|
|
1716
1691
|
onClickRefresh: !!bestRoute ? fetchBestRoute : undefined
|
|
1717
1692
|
})
|
|
@@ -1723,7 +1698,10 @@ function Home(props) {
|
|
|
1723
1698
|
inputAmount: inputAmount
|
|
1724
1699
|
}), React.createElement(SwitchButtonContainer, null, React.createElement(Button, {
|
|
1725
1700
|
variant: "ghost",
|
|
1726
|
-
onClick:
|
|
1701
|
+
onClick: () => {
|
|
1702
|
+
switchFromAndTo();
|
|
1703
|
+
setCount(prev => prev + 1);
|
|
1704
|
+
}
|
|
1727
1705
|
}, React.createElement(VerticalSwapIcon, {
|
|
1728
1706
|
size: 32
|
|
1729
1707
|
}), isRouterInContext && React.createElement(SwithFromAndTo, {
|
|
@@ -1769,8 +1747,7 @@ function Home(props) {
|
|
|
1769
1747
|
|
|
1770
1748
|
const Route = _ref => {
|
|
1771
1749
|
let {
|
|
1772
|
-
children
|
|
1773
|
-
...props
|
|
1750
|
+
children
|
|
1774
1751
|
} = _ref;
|
|
1775
1752
|
const location = useLocation$1();
|
|
1776
1753
|
const navigate = useNavigate$1();
|
|
@@ -1781,7 +1758,7 @@ const Route = _ref => {
|
|
|
1781
1758
|
});
|
|
1782
1759
|
ref.current = false;
|
|
1783
1760
|
}, []);
|
|
1784
|
-
if (location.pathname === navigationRoutes.confirmSwap && ref.current) return React.createElement(Home,
|
|
1761
|
+
if (location.pathname === navigationRoutes.confirmSwap && ref.current) return React.createElement(Home, null);
|
|
1785
1762
|
return React.createElement(React.Fragment, null, " ", children);
|
|
1786
1763
|
};
|
|
1787
1764
|
function AppRouter(_ref2) {
|
|
@@ -1853,7 +1830,10 @@ const Container$3 = /*#__PURE__*/styled('div', {
|
|
|
1853
1830
|
display: 'flex',
|
|
1854
1831
|
justifyContent: 'space-between',
|
|
1855
1832
|
alignItems: 'center',
|
|
1856
|
-
minHeight: '32px'
|
|
1833
|
+
minHeight: '32px',
|
|
1834
|
+
'.usd-value': {
|
|
1835
|
+
paddingLeft: '$8'
|
|
1836
|
+
}
|
|
1857
1837
|
},
|
|
1858
1838
|
'.form': {
|
|
1859
1839
|
display: 'flex',
|
|
@@ -1898,7 +1878,8 @@ function TokenPreview(props) {
|
|
|
1898
1878
|
const {
|
|
1899
1879
|
chain,
|
|
1900
1880
|
token,
|
|
1901
|
-
loadingStatus
|
|
1881
|
+
loadingStatus,
|
|
1882
|
+
percentageChange
|
|
1902
1883
|
} = props;
|
|
1903
1884
|
const {
|
|
1904
1885
|
t
|
|
@@ -1920,10 +1901,11 @@ function TokenPreview(props) {
|
|
|
1920
1901
|
}, React.createElement(Typography, {
|
|
1921
1902
|
variant: "body2",
|
|
1922
1903
|
color: "neutrals800"
|
|
1923
|
-
}, props.label), props.usdValue && React.createElement(Typography, {
|
|
1904
|
+
}, props.label), React.createElement("div", null, percentageChange, props.usdValue && React.createElement(Typography, {
|
|
1924
1905
|
variant: "caption",
|
|
1925
|
-
color: "neutrals600"
|
|
1926
|
-
|
|
1906
|
+
color: "neutrals600",
|
|
1907
|
+
className: "usd-value"
|
|
1908
|
+
}, `$${numberToString(props.usdValue)}`))), React.createElement("div", {
|
|
1927
1909
|
className: "form"
|
|
1928
1910
|
}, React.createElement(Button, {
|
|
1929
1911
|
className: "selectors",
|
|
@@ -2020,6 +2002,7 @@ function useConfirmSwap() {
|
|
|
2020
2002
|
const initialRoute = useBestRouteStore.use.bestRoute();
|
|
2021
2003
|
const setBestRoute = useBestRouteStore.use.setBestRoute();
|
|
2022
2004
|
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
2005
|
+
const affiliateRef = useSettingsStore.use.affiliateRef();
|
|
2023
2006
|
const accounts = useWalletsStore.use.accounts();
|
|
2024
2007
|
const selectedWallets = useWalletsStore.use.selectedWallets();
|
|
2025
2008
|
const meta = useMetaStore.use.meta();
|
|
@@ -2053,14 +2036,13 @@ function useConfirmSwap() {
|
|
|
2053
2036
|
proceedAnywayRef.current = false;
|
|
2054
2037
|
if (confiremedRouteRef.current) {
|
|
2055
2038
|
const newSwap = calculatePendingSwap(inputAmount.toString(), confiremedRouteRef.current, getWalletsForNewSwap(selectedWallets), swapSettings, false, meta);
|
|
2056
|
-
//@ts-ignore
|
|
2057
2039
|
return newSwap;
|
|
2058
2040
|
}
|
|
2059
2041
|
return;
|
|
2060
2042
|
}
|
|
2061
2043
|
abortControllerRef.current = new AbortController();
|
|
2062
2044
|
setLoading(true);
|
|
2063
|
-
const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, accounts, selectedWallets, disabledLiquiditySources, userSlippage, true);
|
|
2045
|
+
const requestBody = createBestRouteRequestBody(fromToken, toToken, inputAmount, accounts, selectedWallets, disabledLiquiditySources, userSlippage, true, affiliateRef);
|
|
2064
2046
|
try {
|
|
2065
2047
|
const confiremedRoute = await httpService.getBestRoute(requestBody, {
|
|
2066
2048
|
signal: abortControllerRef.current?.signal
|
|
@@ -2116,7 +2098,6 @@ function useConfirmSwap() {
|
|
|
2116
2098
|
disabledSwappersGroups: disabledLiquiditySources
|
|
2117
2099
|
};
|
|
2118
2100
|
const newSwap = calculatePendingSwap(inputAmount.toString(), confiremedRoute, getWalletsForNewSwap(selectedWallets), swapSettings, false, meta);
|
|
2119
|
-
//@ts-ignore
|
|
2120
2101
|
return newSwap;
|
|
2121
2102
|
} else if (!proceedAnywayRef.current) {
|
|
2122
2103
|
proceedAnywayRef.current = true;
|
|
@@ -2302,6 +2283,8 @@ function ConfirmSwapPage() {
|
|
|
2302
2283
|
const setSelectedWallet = useWalletsStore.use.setSelectedWallet();
|
|
2303
2284
|
const slippage = useSettingsStore.use.slippage();
|
|
2304
2285
|
const customSlippage = useSettingsStore.use.customSlippage();
|
|
2286
|
+
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
2287
|
+
const outputUsdValue = useBestRouteStore.use.outputUsdValue();
|
|
2305
2288
|
const bestRouteloadingStatus = getBestRouteStatus(fetchingBestRoute, !!fetchingBestRouteError);
|
|
2306
2289
|
const {
|
|
2307
2290
|
manager
|
|
@@ -2332,7 +2315,10 @@ function ConfirmSwapPage() {
|
|
|
2332
2315
|
getKeplrCompatibleConnectedWallets(selectableWallets).forEach(compatibleWallet => connect?.(compatibleWallet, network));
|
|
2333
2316
|
};
|
|
2334
2317
|
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
2335
|
-
return React.createElement(ConfirmSwap
|
|
2318
|
+
return React.createElement(ConfirmSwap
|
|
2319
|
+
// @ts-ignore
|
|
2320
|
+
, {
|
|
2321
|
+
// @ts-ignore
|
|
2336
2322
|
requiredWallets: getRequiredChains(bestRoute),
|
|
2337
2323
|
selectableWallets: selectableWallets,
|
|
2338
2324
|
onBack: navigateBackFrom.bind(null, navigationRoutes.confirmSwap),
|
|
@@ -2341,7 +2327,9 @@ function ConfirmSwapPage() {
|
|
|
2341
2327
|
if (swap) {
|
|
2342
2328
|
manager?.create('swap', {
|
|
2343
2329
|
swapDetails: swap
|
|
2344
|
-
},
|
|
2330
|
+
},
|
|
2331
|
+
// @ts-ignore
|
|
2332
|
+
{
|
|
2345
2333
|
id: swap.requestId
|
|
2346
2334
|
});
|
|
2347
2335
|
setSelectedSwap(swap.requestId);
|
|
@@ -2364,7 +2352,7 @@ function ConfirmSwapPage() {
|
|
|
2364
2352
|
symbol: firstStep?.from.symbol || '',
|
|
2365
2353
|
image: firstStep?.from.logo || ''
|
|
2366
2354
|
},
|
|
2367
|
-
usdValue:
|
|
2355
|
+
usdValue: inputUsdValue,
|
|
2368
2356
|
amount: fromAmount,
|
|
2369
2357
|
label: t('From'),
|
|
2370
2358
|
loadingStatus: bestRouteloadingStatus
|
|
@@ -2380,10 +2368,14 @@ function ConfirmSwapPage() {
|
|
|
2380
2368
|
symbol: lastStep?.to.symbol || '',
|
|
2381
2369
|
image: lastStep?.to.logo || ''
|
|
2382
2370
|
},
|
|
2383
|
-
usdValue:
|
|
2371
|
+
usdValue: outputUsdValue,
|
|
2384
2372
|
amount: toAmount,
|
|
2385
2373
|
label: t('To'),
|
|
2386
|
-
loadingStatus: bestRouteloadingStatus
|
|
2374
|
+
loadingStatus: bestRouteloadingStatus,
|
|
2375
|
+
percentageChange: React.createElement(PercentageChange, {
|
|
2376
|
+
inputUsdValue: inputUsdValue,
|
|
2377
|
+
outputUsdValue: outputUsdValue
|
|
2378
|
+
})
|
|
2387
2379
|
})),
|
|
2388
2380
|
previewRoutes: React.createElement(RoutesOverview, {
|
|
2389
2381
|
routes: bestRoute,
|
|
@@ -2495,7 +2487,7 @@ function LiquiditySourcePage(_ref) {
|
|
|
2495
2487
|
});
|
|
2496
2488
|
return React.createElement(LiquiditySourcesSelector, {
|
|
2497
2489
|
toggleAll: toggleAllLiquiditySources,
|
|
2498
|
-
list: supportedSwappers
|
|
2490
|
+
list: supportedSwappers ? uniqueSwappersGroups.filter(item => supportedSwappers.filter(s => s === item.title).length > 0) : uniqueSwappersGroups,
|
|
2499
2491
|
onChange: liquiditySource => toggleLiquiditySource(liquiditySource.title),
|
|
2500
2492
|
onBack: navigateBackFrom.bind(null, navigationRoutes.liquiditySources),
|
|
2501
2493
|
loadingStatus: loadingMetaStatus
|
|
@@ -2507,7 +2499,7 @@ function SelectChainPage(props) {
|
|
|
2507
2499
|
type,
|
|
2508
2500
|
supportedChains
|
|
2509
2501
|
} = props;
|
|
2510
|
-
const blockchains = supportedChains
|
|
2502
|
+
const blockchains = supportedChains ? useMetaStore.use.meta().blockchains.filter(chain => supportedChains.includes(chain.name)) : useMetaStore.use.meta().blockchains;
|
|
2511
2503
|
const loadingStatus = useMetaStore.use.loadingStatus();
|
|
2512
2504
|
const fromChain = useBestRouteStore.use.fromChain();
|
|
2513
2505
|
const toChain = useBestRouteStore.use.toChain();
|
|
@@ -2539,8 +2531,8 @@ function SelectTokenPage(props) {
|
|
|
2539
2531
|
} = props;
|
|
2540
2532
|
const sourceTokens = useBestRouteStore.use.sourceTokens();
|
|
2541
2533
|
const destinationTokens = useBestRouteStore.use.destinationTokens();
|
|
2542
|
-
const supportedSourceTokens = supportedTokens
|
|
2543
|
-
const supportedDestinationTokens = supportedTokens
|
|
2534
|
+
const supportedSourceTokens = supportedTokens ? sourceTokens.filter(token => supportedTokens.some(supportedToken => tokensAreEqual(supportedToken, token))) : sourceTokens;
|
|
2535
|
+
const supportedDestinationTokens = supportedTokens ? destinationTokens.filter(token => supportedTokens.some(supportedToken => tokensAreEqual(supportedToken, token))) : destinationTokens;
|
|
2544
2536
|
const fromToken = useBestRouteStore.use.fromToken();
|
|
2545
2537
|
const toToken = useBestRouteStore.use.toToken();
|
|
2546
2538
|
const setFromToken = useBestRouteStore.use.setFromToken();
|
|
@@ -2593,8 +2585,8 @@ function SettingsPage(_ref) {
|
|
|
2593
2585
|
}
|
|
2594
2586
|
}
|
|
2595
2587
|
});
|
|
2596
|
-
supportedSwappers
|
|
2597
|
-
const supportedUniqueSwappersGroups = supportedSwappers
|
|
2588
|
+
supportedSwappers && uniqueSwappersGroups.filter(item => supportedSwappers.filter(s => s === item.title).length > 0);
|
|
2589
|
+
const supportedUniqueSwappersGroups = supportedSwappers ? uniqueSwappersGroups.filter(item => supportedSwappers.filter(s => s === item.title).length > 0) : uniqueSwappersGroups;
|
|
2598
2590
|
return React.createElement(Settings, {
|
|
2599
2591
|
slippages: SLIPPAGES,
|
|
2600
2592
|
selectedSlippage: slippage,
|
|
@@ -2647,7 +2639,7 @@ function WalletsPage(_ref) {
|
|
|
2647
2639
|
getWalletInfo,
|
|
2648
2640
|
connect
|
|
2649
2641
|
} = useWallets();
|
|
2650
|
-
const wallets = getlistWallet(state, getWalletInfo, supportedWallets
|
|
2642
|
+
const wallets = getlistWallet(state, getWalletInfo, supportedWallets || Object.values(WalletType));
|
|
2651
2643
|
const walletsRef = useRef();
|
|
2652
2644
|
let sortedWallets = detectMobileScreens() ? wallets.filter(wallet => wallet.showOnMobile) : wallets;
|
|
2653
2645
|
sortedWallets = sortWalletsBasedOnState(sortedWallets);
|
|
@@ -2856,7 +2848,7 @@ function SwapDetailsPage() {
|
|
|
2856
2848
|
}), React.createElement(TokenPreview, {
|
|
2857
2849
|
chain: {
|
|
2858
2850
|
displayName: lastStep?.toBlockchain || '',
|
|
2859
|
-
|
|
2851
|
+
//@ts-ignore
|
|
2860
2852
|
logo: lastStep?.toBlockchainLogo || ''
|
|
2861
2853
|
},
|
|
2862
2854
|
token: {
|
|
@@ -2868,7 +2860,6 @@ function SwapDetailsPage() {
|
|
|
2868
2860
|
loadingStatus: 'success'
|
|
2869
2861
|
})),
|
|
2870
2862
|
//todo: move PendingSwap type to rango-types
|
|
2871
|
-
//@ts-ignore
|
|
2872
2863
|
pendingSwap: swap,
|
|
2873
2864
|
onCopy: handleCopy,
|
|
2874
2865
|
isCopied: isCopied,
|
|
@@ -2898,48 +2889,44 @@ function SwapDetailsPage() {
|
|
|
2898
2889
|
const getAbsolutePath = path => path.replace('/', '');
|
|
2899
2890
|
function AppRoutes(props) {
|
|
2900
2891
|
const {
|
|
2901
|
-
|
|
2892
|
+
config
|
|
2902
2893
|
} = props;
|
|
2903
2894
|
return useRoutes([{
|
|
2904
2895
|
path: getAbsolutePath(navigationRoutes.home),
|
|
2905
|
-
element: React.createElement(Home,
|
|
2906
|
-
title: configs?.title,
|
|
2907
|
-
titleSize: configs?.titleSize,
|
|
2908
|
-
titleWeight: configs?.titleWeight
|
|
2909
|
-
})
|
|
2896
|
+
element: React.createElement(Home, null)
|
|
2910
2897
|
}, {
|
|
2911
2898
|
path: getAbsolutePath(navigationRoutes.fromChain),
|
|
2912
2899
|
element: React.createElement(SelectChainPage, {
|
|
2913
2900
|
type: "from",
|
|
2914
|
-
supportedChains:
|
|
2901
|
+
supportedChains: config?.from?.blockchains
|
|
2915
2902
|
})
|
|
2916
2903
|
}, {
|
|
2917
2904
|
path: getAbsolutePath(navigationRoutes.toChain),
|
|
2918
2905
|
element: React.createElement(SelectChainPage, {
|
|
2919
2906
|
type: "to",
|
|
2920
|
-
supportedChains:
|
|
2907
|
+
supportedChains: config?.to?.blockchains
|
|
2921
2908
|
})
|
|
2922
2909
|
}, {
|
|
2923
2910
|
path: getAbsolutePath(navigationRoutes.fromToken),
|
|
2924
2911
|
element: React.createElement(SelectTokenPage, {
|
|
2925
2912
|
type: "from",
|
|
2926
|
-
supportedTokens:
|
|
2913
|
+
supportedTokens: config?.from?.tokens
|
|
2927
2914
|
})
|
|
2928
2915
|
}, {
|
|
2929
2916
|
path: getAbsolutePath(navigationRoutes.toToken),
|
|
2930
2917
|
element: React.createElement(SelectTokenPage, {
|
|
2931
2918
|
type: "to",
|
|
2932
|
-
supportedTokens:
|
|
2919
|
+
supportedTokens: config?.to?.tokens
|
|
2933
2920
|
})
|
|
2934
2921
|
}, {
|
|
2935
2922
|
path: getAbsolutePath(navigationRoutes.settings),
|
|
2936
2923
|
element: React.createElement(SettingsPage, {
|
|
2937
|
-
supportedSwappers:
|
|
2924
|
+
supportedSwappers: config?.liquiditySources
|
|
2938
2925
|
})
|
|
2939
2926
|
}, {
|
|
2940
2927
|
path: getAbsolutePath(navigationRoutes.liquiditySources),
|
|
2941
2928
|
element: React.createElement(LiquiditySourcePage, {
|
|
2942
|
-
supportedSwappers:
|
|
2929
|
+
supportedSwappers: config?.liquiditySources
|
|
2943
2930
|
})
|
|
2944
2931
|
}, {
|
|
2945
2932
|
path: getAbsolutePath(navigationRoutes.swaps),
|
|
@@ -2950,8 +2937,8 @@ function AppRoutes(props) {
|
|
|
2950
2937
|
}, {
|
|
2951
2938
|
path: getAbsolutePath(navigationRoutes.wallets),
|
|
2952
2939
|
element: React.createElement(WalletsPage, {
|
|
2953
|
-
supportedWallets:
|
|
2954
|
-
multiWallets: typeof
|
|
2940
|
+
supportedWallets: config?.wallets,
|
|
2941
|
+
multiWallets: typeof config?.multiWallets === 'undefined' ? true : config.multiWallets
|
|
2955
2942
|
})
|
|
2956
2943
|
}, {
|
|
2957
2944
|
path: getAbsolutePath(navigationRoutes.confirmSwap),
|
|
@@ -2976,7 +2963,7 @@ const WalletImage = /*#__PURE__*/styled('img', {
|
|
|
2976
2963
|
});
|
|
2977
2964
|
function Layout(_ref) {
|
|
2978
2965
|
let {
|
|
2979
|
-
|
|
2966
|
+
config
|
|
2980
2967
|
} = _ref;
|
|
2981
2968
|
const navigate = useNavigate();
|
|
2982
2969
|
const {
|
|
@@ -2988,11 +2975,16 @@ function Layout(_ref) {
|
|
|
2988
2975
|
getWalletInfo
|
|
2989
2976
|
} = useWallets();
|
|
2990
2977
|
const connectedWalletsImages = removeDuplicateFrom(getSelectableWallets(accounts, selectedWallets, getWalletInfo).map(w => w.image));
|
|
2978
|
+
const {
|
|
2979
|
+
blockchains,
|
|
2980
|
+
tokens
|
|
2981
|
+
} = useMetaStore.use.meta();
|
|
2991
2982
|
const setFromChain = useBestRouteStore.use.setFromChain();
|
|
2992
2983
|
const setFromToken = useBestRouteStore.use.setFromToken();
|
|
2993
2984
|
const setToChain = useBestRouteStore.use.setToChain();
|
|
2994
2985
|
const setToToken = useBestRouteStore.use.setToToken();
|
|
2995
2986
|
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
2987
|
+
const setAffiliateRef = useSettingsStore.use.setAffiliateRef();
|
|
2996
2988
|
const totalBalance = calculateWalletUsdValue(balances);
|
|
2997
2989
|
const connectWalletsButtonDisabled = useUiStore.use.connectWalletsButtonDisabled();
|
|
2998
2990
|
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
@@ -3001,22 +2993,23 @@ function Layout(_ref) {
|
|
|
3001
2993
|
t
|
|
3002
2994
|
} = useTranslation();
|
|
3003
2995
|
useEffect(() => {
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
2996
|
+
const chain = blockchains.find(chain => chain.name === config?.to?.blockchain);
|
|
2997
|
+
const token = tokens.find(t => tokensAreEqual(t, config?.to?.token || null));
|
|
2998
|
+
setToChain(chain || null);
|
|
2999
|
+
setToToken(token || null);
|
|
3000
|
+
}, [config?.to?.token, config?.to?.blockchain]);
|
|
3007
3001
|
useEffect(() => {
|
|
3008
|
-
setInputAmount(
|
|
3009
|
-
}, [
|
|
3002
|
+
setInputAmount(config?.amount?.toString() || '');
|
|
3003
|
+
}, [config?.amount]);
|
|
3010
3004
|
useEffect(() => {
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3005
|
+
const chain = blockchains.find(chain => chain.name === config?.from?.blockchain);
|
|
3006
|
+
const token = tokens.find(t => tokensAreEqual(t, config?.from?.token || null));
|
|
3007
|
+
setFromChain(chain || null);
|
|
3008
|
+
setFromToken(token || null);
|
|
3009
|
+
}, [config?.from?.token, config?.from?.blockchain]);
|
|
3014
3010
|
useEffect(() => {
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
setFromToken(null);
|
|
3018
|
-
setToToken(null);
|
|
3019
|
-
}, [configs?.fromChains, configs?.toChains, configs?.fromTokens, configs?.toTokens]);
|
|
3011
|
+
setAffiliateRef(config?.affiliateRef || null);
|
|
3012
|
+
}, [config?.affiliateRef]);
|
|
3020
3013
|
return React.createElement(React.Fragment, null, React.createElement(Header, null, React.createElement(Button, {
|
|
3021
3014
|
size: "small",
|
|
3022
3015
|
suffix: React.createElement(AddWalletIcon, {
|
|
@@ -3037,7 +3030,7 @@ function Layout(_ref) {
|
|
|
3037
3030
|
}, React.createElement(Typography, {
|
|
3038
3031
|
variant: "body2"
|
|
3039
3032
|
}, !accounts?.length ? t('Connect Wallet') : `$${totalBalance || 0}`), fetchingBalance && React.createElement(Spinner, null)))), React.createElement(AppRoutes, {
|
|
3040
|
-
|
|
3033
|
+
config: config
|
|
3041
3034
|
}));
|
|
3042
3035
|
}
|
|
3043
3036
|
|
|
@@ -3080,17 +3073,20 @@ function usePrevious(value) {
|
|
|
3080
3073
|
|
|
3081
3074
|
function useTheme(_ref) {
|
|
3082
3075
|
let {
|
|
3083
|
-
|
|
3084
|
-
background = '#fff',
|
|
3085
|
-
foreground = '#000',
|
|
3086
|
-
error = '#FF0000',
|
|
3087
|
-
warning = '#F5A623',
|
|
3088
|
-
success = '#0070F3',
|
|
3076
|
+
colors: themeColors,
|
|
3089
3077
|
fontFamily = 'Robot',
|
|
3090
|
-
borderRadius = 8
|
|
3078
|
+
borderRadius = 8,
|
|
3079
|
+
mode = 'auto'
|
|
3091
3080
|
} = _ref;
|
|
3092
3081
|
const theme = useSettingsStore.use.theme();
|
|
3093
3082
|
const fetchMeta = useMetaStore.use.fetchMeta();
|
|
3083
|
+
const setTheme = useSettingsStore.use.setTheme();
|
|
3084
|
+
const primary = themeColors?.primary || '#5FA425',
|
|
3085
|
+
background = themeColors?.background || '#fff',
|
|
3086
|
+
foreground = themeColors?.foreground || '#000',
|
|
3087
|
+
error = themeColors?.error || '#FF0000',
|
|
3088
|
+
warning = themeColors?.warning || '#F5A623',
|
|
3089
|
+
success = themeColors?.success || '#0070F3';
|
|
3094
3090
|
const colors = {
|
|
3095
3091
|
neutrals200: '#FAFAFA',
|
|
3096
3092
|
neutrals300: '#f2f2f2',
|
|
@@ -3168,6 +3164,9 @@ function useTheme(_ref) {
|
|
|
3168
3164
|
window.matchMedia('(prefers-color-scheme: dark)').removeEventListener('change', switchTheme);
|
|
3169
3165
|
};
|
|
3170
3166
|
}, []);
|
|
3167
|
+
useEffect(() => {
|
|
3168
|
+
if (mode !== 'auto') setTheme(mode);
|
|
3169
|
+
}, [mode]);
|
|
3171
3170
|
const prevFont = usePrevious(fontFamily);
|
|
3172
3171
|
useLayoutEffect(() => {
|
|
3173
3172
|
const {
|
|
@@ -3332,29 +3331,27 @@ function QueueManager(props) {
|
|
|
3332
3331
|
|
|
3333
3332
|
const SwapBox = _ref => {
|
|
3334
3333
|
let {
|
|
3335
|
-
|
|
3334
|
+
config
|
|
3336
3335
|
} = _ref;
|
|
3337
3336
|
globalStyles();
|
|
3338
|
-
globalFont(
|
|
3337
|
+
globalFont(config?.theme?.fontFamily || 'Roboto');
|
|
3339
3338
|
const {
|
|
3340
3339
|
activeTheme
|
|
3341
3340
|
} = useTheme({
|
|
3342
|
-
...
|
|
3343
|
-
borderRadius: configs?.borderRadius,
|
|
3344
|
-
fontFamily: configs?.fontFamily
|
|
3341
|
+
...config?.theme
|
|
3345
3342
|
});
|
|
3346
3343
|
const {
|
|
3347
3344
|
blockchains
|
|
3348
3345
|
} = useMetaStore.use.meta();
|
|
3349
3346
|
const disconnectWallet = useWalletsStore.use.disconnectWallet();
|
|
3350
3347
|
const connectWallet = useWalletsStore.use.connectWallet();
|
|
3351
|
-
const setTheme = useSettingsStore.use.setTheme();
|
|
3352
3348
|
const {
|
|
3353
3349
|
changeLanguage
|
|
3354
3350
|
} = useSelectLanguage();
|
|
3355
3351
|
const clearConnectedWallet = useWalletsStore.use.clearConnectedWallet();
|
|
3356
3352
|
const [lastConnectedWalletWithNetwork, setLastConnectedWalletWithNetwork] = useState('');
|
|
3357
3353
|
const [disconnectedWallet, setDisconnectedWallet] = useState();
|
|
3354
|
+
const currentPage = useUiStore.use.currentPage();
|
|
3358
3355
|
const evmBasedChainNames = blockchains.filter(isEvmBlockchain$1).map(chain => chain.name);
|
|
3359
3356
|
const onUpdateState = (type, event, value, state, supportedChains) => {
|
|
3360
3357
|
if (event === Events.ACCOUNTS) {
|
|
@@ -3379,19 +3376,16 @@ const SwapBox = _ref => {
|
|
|
3379
3376
|
};
|
|
3380
3377
|
let providers = allProviders();
|
|
3381
3378
|
useEffect(() => {
|
|
3382
|
-
|
|
3383
|
-
}, [configs.theme]);
|
|
3384
|
-
useEffect(() => {
|
|
3385
|
-
const wallets = configs.wallets;
|
|
3379
|
+
const wallets = config?.wallets;
|
|
3386
3380
|
clearConnectedWallet();
|
|
3387
|
-
providers = wallets
|
|
3381
|
+
providers = !wallets ? allProviders() : allProviders().filter(provider => {
|
|
3388
3382
|
const type = provider.config.type;
|
|
3389
3383
|
return wallets.find(w => w === type);
|
|
3390
3384
|
});
|
|
3391
|
-
}, [
|
|
3385
|
+
}, [config?.wallets]);
|
|
3392
3386
|
useEffect(() => {
|
|
3393
|
-
changeLanguage(
|
|
3394
|
-
}, [
|
|
3387
|
+
changeLanguage(config?.language || 'en');
|
|
3388
|
+
}, [config?.language]);
|
|
3395
3389
|
return React.createElement(Provider$1, {
|
|
3396
3390
|
allBlockChains: blockchains,
|
|
3397
3391
|
providers: providers,
|
|
@@ -3400,21 +3394,15 @@ const SwapBox = _ref => {
|
|
|
3400
3394
|
id: "pageContainer",
|
|
3401
3395
|
className: activeTheme
|
|
3402
3396
|
}, React.createElement(QueueManager, null, React.createElement(SwapContainer, {
|
|
3403
|
-
|
|
3404
|
-
width: configs?.width || 'auto',
|
|
3405
|
-
height: configs?.height || 'auto'
|
|
3406
|
-
}
|
|
3397
|
+
fixedHeight: currentPage !== navigationRoutes.home
|
|
3407
3398
|
}, React.createElement(AppRouter, {
|
|
3408
|
-
title: configs.title,
|
|
3409
|
-
titleSize: configs.titleSize,
|
|
3410
|
-
titleWeight: configs.titleWeight,
|
|
3411
3399
|
lastConnectedWallet: lastConnectedWalletWithNetwork,
|
|
3412
3400
|
disconnectedWallet: disconnectedWallet,
|
|
3413
3401
|
clearDisconnectedWallet: () => {
|
|
3414
3402
|
setDisconnectedWallet(undefined);
|
|
3415
3403
|
}
|
|
3416
3404
|
}, React.createElement(Layout, {
|
|
3417
|
-
|
|
3405
|
+
config: config
|
|
3418
3406
|
}))))));
|
|
3419
3407
|
};
|
|
3420
3408
|
|