@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/globalStyles.ts
CHANGED
|
@@ -2,9 +2,10 @@ import { globalCss } from '@rango-dev/ui';
|
|
|
2
2
|
|
|
3
3
|
export const globalStyles = globalCss({
|
|
4
4
|
'*': {
|
|
5
|
-
'&::-webkit-scrollbar': { width: '$8' },
|
|
5
|
+
'&::-webkit-scrollbar': { width: '$8', height: '$8' },
|
|
6
6
|
'&::-webkit-scrollbar-thumb': {
|
|
7
7
|
backgroundColor: '$neutrals400',
|
|
8
|
+
borderRadius: '$10',
|
|
8
9
|
},
|
|
9
10
|
'&::-webkit-scrollbar-thumb:hover': {
|
|
10
11
|
backgroundColor: '$neutrals500',
|
|
@@ -93,6 +93,7 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
93
93
|
meta
|
|
94
94
|
);
|
|
95
95
|
|
|
96
|
+
//@ts-ignore
|
|
96
97
|
return newSwap;
|
|
97
98
|
}
|
|
98
99
|
return;
|
|
@@ -228,7 +229,7 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
228
229
|
false,
|
|
229
230
|
meta
|
|
230
231
|
);
|
|
231
|
-
|
|
232
|
+
//@ts-ignore
|
|
232
233
|
return newSwap;
|
|
233
234
|
} else if (!proceedAnywayRef.current) {
|
|
234
235
|
proceedAnywayRef.current = true;
|
|
@@ -8,6 +8,8 @@ export function useNavigateBack() {
|
|
|
8
8
|
navigationRoutes;
|
|
9
9
|
|
|
10
10
|
const navigateBackFrom = (currentRoute: string) => {
|
|
11
|
+
if (currentRoute === navigationRoutes.swapDetails)
|
|
12
|
+
return navigate(navigationRoutes.swaps, { replace: true });
|
|
11
13
|
if (
|
|
12
14
|
!isRouterInContext ||
|
|
13
15
|
(window.history.state && window.history.state.idx > 0)
|
|
@@ -23,7 +25,7 @@ export function useNavigateBack() {
|
|
|
23
25
|
navigationRoutes.settings,
|
|
24
26
|
navigationRoutes.wallets,
|
|
25
27
|
navigationRoutes.swaps,
|
|
26
|
-
navigationRoutes.
|
|
28
|
+
navigationRoutes.confirmSwap,
|
|
27
29
|
].includes(currentRoute)
|
|
28
30
|
)
|
|
29
31
|
navigate(navigationRoutes.home, { replace: true });
|
|
@@ -31,8 +33,6 @@ export function useNavigateBack() {
|
|
|
31
33
|
navigate(navigationRoutes.settings, { replace: true });
|
|
32
34
|
else if (currentRoute === navigationRoutes.swapDetails)
|
|
33
35
|
navigate(navigationRoutes.swaps, { replace: true });
|
|
34
|
-
else if (currentRoute === navigationRoutes.confirmSwap)
|
|
35
|
-
navigate(navigationRoutes.confirmWallets, { replace: true });
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
|
package/src/lib.tsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { SwapContainer } from '@rango-dev/ui';
|
|
2
|
-
import React, { useEffect } from 'react';
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
3
3
|
import { AppRouter } from './components/AppRouter';
|
|
4
4
|
import { useMetaStore } from './store/meta';
|
|
5
5
|
import { Events, Provider } from '@rango-dev/wallets-core';
|
|
6
6
|
import { allProviders } from '@rango-dev/provider-all';
|
|
7
7
|
import { EventHandler } from '@rango-dev/wallets-core/dist/wallet';
|
|
8
|
-
import { Network } from '@rango-dev/wallets-shared';
|
|
8
|
+
import { Network, WalletType } from '@rango-dev/wallets-shared';
|
|
9
9
|
import {
|
|
10
10
|
prepareAccountsForWalletStore,
|
|
11
11
|
walletAndSupportedChainsNames,
|
|
@@ -41,6 +41,10 @@ export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
|
|
|
41
41
|
const { changeLanguage } = useSelectLanguage();
|
|
42
42
|
const clearConnectedWallet = useWalletsStore.use.clearConnectedWallet();
|
|
43
43
|
|
|
44
|
+
const [lastConnectedWalletWithNetwork, setLastConnectedWalletWithNetwork] =
|
|
45
|
+
useState<string>('');
|
|
46
|
+
const [disconnectedWallet, setDisconnectedWallet] = useState<WalletType>();
|
|
47
|
+
|
|
44
48
|
const evmBasedChainNames = blockchains
|
|
45
49
|
.filter(isEvmBlockchain)
|
|
46
50
|
.map((chain) => chain.name);
|
|
@@ -49,7 +53,7 @@ export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
|
|
|
49
53
|
type,
|
|
50
54
|
event,
|
|
51
55
|
value,
|
|
52
|
-
|
|
56
|
+
state,
|
|
53
57
|
supportedChains
|
|
54
58
|
) => {
|
|
55
59
|
if (event === Events.ACCOUNTS) {
|
|
@@ -67,6 +71,19 @@ export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
|
|
|
67
71
|
disconnectWallet(type);
|
|
68
72
|
}
|
|
69
73
|
}
|
|
74
|
+
|
|
75
|
+
if (event === Events.ACCOUNTS && state.connected) {
|
|
76
|
+
const key = `${type}-${state.network}-${value}`;
|
|
77
|
+
|
|
78
|
+
if (state.connected) {
|
|
79
|
+
setLastConnectedWalletWithNetwork(key);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (event === Events.NETWORK && state.network) {
|
|
84
|
+
const key = `${type}-${state.network}`;
|
|
85
|
+
setLastConnectedWalletWithNetwork(key);
|
|
86
|
+
}
|
|
70
87
|
};
|
|
71
88
|
let providers = allProviders();
|
|
72
89
|
|
|
@@ -108,6 +125,11 @@ export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
|
|
|
108
125
|
title={configs.title}
|
|
109
126
|
titleSize={configs.titleSize}
|
|
110
127
|
titleWeight={configs.titleWeight}
|
|
128
|
+
lastConnectedWallet={lastConnectedWalletWithNetwork}
|
|
129
|
+
disconnectedWallet={disconnectedWallet}
|
|
130
|
+
clearDisconnectedWallet={() => {
|
|
131
|
+
setDisconnectedWallet(undefined);
|
|
132
|
+
}}
|
|
111
133
|
>
|
|
112
134
|
<Layout configs={configs} />
|
|
113
135
|
</AppRouter>
|
|
@@ -1,41 +1,104 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
2
|
import { useNavigate } from 'react-router-dom';
|
|
3
|
-
import { ConfirmSwap } from '@rango-dev/ui';
|
|
4
3
|
import { useBestRouteStore } from '../store/bestRoute';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
4
|
+
import { useWalletsStore } from '../store/wallets';
|
|
5
|
+
import { useWallets } from '@rango-dev/wallets-core';
|
|
8
6
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
9
|
-
import {
|
|
10
|
-
|
|
7
|
+
import {
|
|
8
|
+
getKeplrCompatibleConnectedWallets,
|
|
9
|
+
getRequiredChains,
|
|
10
|
+
getSelectableWallets,
|
|
11
|
+
isExperimentalChain,
|
|
12
|
+
} from '../utils/wallets';
|
|
13
|
+
import { getTotalFeeInUsd, requiredWallets } from '../utils/swap';
|
|
14
|
+
import { decimalNumber, numberToString } from '../utils/numbers';
|
|
15
|
+
import { useMetaStore } from '../store/meta';
|
|
16
|
+
import { Network, WalletType } from '@rango-dev/wallets-shared';
|
|
17
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
18
|
+
import { TokenPreview } from '../components/TokenPreview';
|
|
19
|
+
// @ts-ignore // TODO: fix error in tsc build
|
|
20
|
+
import { t } from 'i18next';
|
|
21
|
+
import { Spacer, ConfirmSwap } from '@rango-dev/ui';
|
|
22
|
+
import RoutesOverview from '../components/RoutesOverview';
|
|
11
23
|
import { useManager } from '@rango-dev/queue-manager-react';
|
|
12
|
-
import { useUiStore } from '../store/ui';
|
|
13
24
|
import { useConfirmSwap } from '../hooks/useConfirmSwap';
|
|
25
|
+
import { useSettingsStore } from '../store/settings';
|
|
26
|
+
import { useUiStore } from '../store/ui';
|
|
14
27
|
import { ConfirmSwapErrorTypes } from '../types';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
28
|
+
import { ConfirmSwapErrors } from '../components/ConfirmSwapErrors';
|
|
29
|
+
import { ConfirmSwapWarnings } from '../components/ConfirmSwapWarnings';
|
|
30
|
+
import { ConfirmSwapExtraMessages } from '../components/warnings/ConfirmSwapExtraMessages';
|
|
31
|
+
import { getBestRouteStatus } from '../utils/routing';
|
|
32
|
+
import { PercentageChange } from '../components/PercentageChange';
|
|
17
33
|
|
|
18
34
|
export function ConfirmSwapPage() {
|
|
19
|
-
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
20
|
-
const { navigateBackFrom } = useNavigateBack();
|
|
21
|
-
const { manager } = useManager();
|
|
22
35
|
const navigate = useNavigate();
|
|
23
|
-
|
|
36
|
+
const { navigateBackFrom } = useNavigateBack();
|
|
24
37
|
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
25
38
|
const fetchingBestRoute = useBestRouteStore.use.loading();
|
|
26
|
-
const
|
|
27
|
-
|
|
39
|
+
const fetchingBestRouteError = useBestRouteStore.use.error();
|
|
40
|
+
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
41
|
+
const { blockchains, tokens } = useMetaStore.use.meta();
|
|
42
|
+
const accounts = useWalletsStore.use.accounts();
|
|
43
|
+
const selectedWallets = useWalletsStore.use.selectedWallets();
|
|
44
|
+
const initSelectedWallets = useWalletsStore.use.initSelectedWallets();
|
|
45
|
+
const setSelectedWallet = useWalletsStore.use.setSelectedWallet();
|
|
28
46
|
const slippage = useSettingsStore.use.slippage();
|
|
29
47
|
const customSlippage = useSettingsStore.use.customSlippage();
|
|
30
|
-
const
|
|
48
|
+
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
49
|
+
const outputUsdValue = useBestRouteStore.use.outputUsdValue();
|
|
50
|
+
|
|
51
|
+
const bestRouteloadingStatus = getBestRouteStatus(
|
|
52
|
+
fetchingBestRoute,
|
|
53
|
+
!!fetchingBestRouteError
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const { manager } = useManager();
|
|
31
57
|
const { loading, errors, warnings, confirmSwap } = useConfirmSwap();
|
|
32
58
|
|
|
59
|
+
const selectedSlippage = customSlippage || slippage;
|
|
60
|
+
|
|
33
61
|
const showHighSlippageWarning = !errors.find(
|
|
34
62
|
(error) => error.type === ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE
|
|
35
63
|
);
|
|
36
64
|
|
|
65
|
+
const { getWalletInfo, connect } = useWallets();
|
|
66
|
+
const confirmDisabled =
|
|
67
|
+
fetchingBestRoute ||
|
|
68
|
+
!requiredWallets(bestRoute).every((chain) =>
|
|
69
|
+
selectedWallets.map((wallet) => wallet.chain).includes(chain)
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const firstStep = bestRoute?.result?.swaps[0];
|
|
73
|
+
const lastStep =
|
|
74
|
+
bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1];
|
|
75
|
+
|
|
76
|
+
const fromAmount = decimalNumber(firstStep?.fromAmount, 3);
|
|
77
|
+
const toAmount = decimalNumber(lastStep?.toAmount, 3);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
initSelectedWallets();
|
|
80
|
+
}, []);
|
|
81
|
+
|
|
82
|
+
const selectableWallets = getSelectableWallets(
|
|
83
|
+
accounts,
|
|
84
|
+
selectedWallets,
|
|
85
|
+
getWalletInfo
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const handleConnectChain = (wallet: string) => {
|
|
89
|
+
const network = wallet as Network;
|
|
90
|
+
getKeplrCompatibleConnectedWallets(selectableWallets).forEach(
|
|
91
|
+
(compatibleWallet: WalletType) => connect?.(compatibleWallet, network)
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
96
|
+
|
|
37
97
|
return (
|
|
38
98
|
<ConfirmSwap
|
|
99
|
+
requiredWallets={getRequiredChains(bestRoute)}
|
|
100
|
+
selectableWallets={selectableWallets}
|
|
101
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.confirmSwap)}
|
|
39
102
|
onConfirm={() => {
|
|
40
103
|
confirmSwap?.().then((swap) => {
|
|
41
104
|
if (swap) {
|
|
@@ -51,8 +114,59 @@ export function ConfirmSwapPage() {
|
|
|
51
114
|
}
|
|
52
115
|
});
|
|
53
116
|
}}
|
|
54
|
-
|
|
55
|
-
|
|
117
|
+
onChange={(wallet) => setSelectedWallet(wallet)}
|
|
118
|
+
confirmDisabled={confirmDisabled}
|
|
119
|
+
handleConnectChain={(wallet) => handleConnectChain(wallet)}
|
|
120
|
+
isExperimentalChain={(wallet) =>
|
|
121
|
+
getKeplrCompatibleConnectedWallets(selectableWallets).length > 0
|
|
122
|
+
? isExperimentalChain(blockchains, wallet)
|
|
123
|
+
: false
|
|
124
|
+
}
|
|
125
|
+
previewInputs={
|
|
126
|
+
<>
|
|
127
|
+
<TokenPreview
|
|
128
|
+
chain={{
|
|
129
|
+
displayName: firstStep?.from.blockchain || '',
|
|
130
|
+
logo: firstStep?.from.blockchainLogo || '',
|
|
131
|
+
}}
|
|
132
|
+
token={{
|
|
133
|
+
symbol: firstStep?.from.symbol || '',
|
|
134
|
+
image: firstStep?.from.logo || '',
|
|
135
|
+
}}
|
|
136
|
+
usdValue={inputUsdValue}
|
|
137
|
+
amount={fromAmount}
|
|
138
|
+
label={t('From')}
|
|
139
|
+
loadingStatus={bestRouteloadingStatus}
|
|
140
|
+
/>
|
|
141
|
+
<Spacer size={12} direction="vertical" />
|
|
142
|
+
<TokenPreview
|
|
143
|
+
chain={{
|
|
144
|
+
displayName: lastStep?.to.blockchain || '',
|
|
145
|
+
logo: lastStep?.to.blockchainLogo || '',
|
|
146
|
+
}}
|
|
147
|
+
token={{
|
|
148
|
+
symbol: lastStep?.to.symbol || '',
|
|
149
|
+
image: lastStep?.to.logo || '',
|
|
150
|
+
}}
|
|
151
|
+
usdValue={outputUsdValue}
|
|
152
|
+
amount={toAmount}
|
|
153
|
+
label={t('To')}
|
|
154
|
+
loadingStatus={bestRouteloadingStatus}
|
|
155
|
+
percentageChange={
|
|
156
|
+
<PercentageChange
|
|
157
|
+
inputUsdValue={inputUsdValue}
|
|
158
|
+
outputUsdValue={outputUsdValue}
|
|
159
|
+
/>
|
|
160
|
+
}
|
|
161
|
+
/>
|
|
162
|
+
</>
|
|
163
|
+
}
|
|
164
|
+
previewRoutes={
|
|
165
|
+
<RoutesOverview
|
|
166
|
+
routes={bestRoute}
|
|
167
|
+
totalFee={numberToString(totalFeeInUsd, 0, 2)}
|
|
168
|
+
/>
|
|
169
|
+
}
|
|
56
170
|
loading={loading}
|
|
57
171
|
errors={ConfirmSwapErrors(errors)}
|
|
58
172
|
warnings={ConfirmSwapWarnings(warnings)}
|
|
@@ -66,7 +180,6 @@ export function ConfirmSwapPage() {
|
|
|
66
180
|
? 'Proceed anyway!'
|
|
67
181
|
: 'Confirm swap!'
|
|
68
182
|
}
|
|
69
|
-
confirmButtonDisabled={fetchingBestRoute}
|
|
70
183
|
/>
|
|
71
184
|
);
|
|
72
185
|
}
|
|
@@ -6,6 +6,7 @@ import { navigationRoutes } from '../constants/navigationRoutes';
|
|
|
6
6
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
7
7
|
import { getPendingSwaps } from '../utils/queue';
|
|
8
8
|
import { useUiStore } from '../store/ui';
|
|
9
|
+
import { groupSwapsByDate } from '../utils/date';
|
|
9
10
|
|
|
10
11
|
export function HistoryPage() {
|
|
11
12
|
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
@@ -16,12 +17,11 @@ export function HistoryPage() {
|
|
|
16
17
|
|
|
17
18
|
return (
|
|
18
19
|
<History
|
|
19
|
-
//todo: move PendingSwap type to rango-types
|
|
20
|
-
//@ts-ignore
|
|
21
20
|
list={pendingSwaps}
|
|
22
|
-
|
|
21
|
+
groupBy={groupSwapsByDate}
|
|
22
|
+
onSwapClick={requestId => {
|
|
23
23
|
setSelectedSwap(requestId);
|
|
24
|
-
navigate(navigationRoutes.swaps + `/${requestId}
|
|
24
|
+
navigate(navigationRoutes.swaps + `/${requestId}`, { replace: true });
|
|
25
25
|
}}
|
|
26
26
|
onBack={navigateBackFrom.bind(null, navigationRoutes.swaps)}
|
|
27
27
|
/>
|
package/src/pages/Home.tsx
CHANGED
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
styled,
|
|
6
6
|
Typography,
|
|
7
7
|
VerticalSwapIcon,
|
|
8
|
+
Header,
|
|
8
9
|
} from '@rango-dev/ui';
|
|
9
|
-
import React, { useState } from 'react';
|
|
10
|
+
import React, { useEffect, useState } from 'react';
|
|
10
11
|
import { useInRouterContext, useNavigate } from 'react-router-dom';
|
|
11
|
-
import { Header } from '../components/Header';
|
|
12
12
|
import { TokenInfo } from '../components/TokenInfo';
|
|
13
13
|
import { fetchBestRoute, useBestRouteStore } from '../store/bestRoute';
|
|
14
14
|
import { BottomLogo } from '../components/BottomLogo';
|
|
@@ -34,6 +34,8 @@ import {
|
|
|
34
34
|
totalArrivalTime,
|
|
35
35
|
} from '../utils/numbers';
|
|
36
36
|
import BigNumber from 'bignumber.js';
|
|
37
|
+
import { HeaderButtons } from '../components/HeaderButtons';
|
|
38
|
+
import { useUiStore } from '../store/ui';
|
|
37
39
|
|
|
38
40
|
const Container = styled('div', {
|
|
39
41
|
display: 'flex',
|
|
@@ -67,7 +69,7 @@ interface PropTypes {
|
|
|
67
69
|
titleWeight?: number;
|
|
68
70
|
}
|
|
69
71
|
export function Home(props: PropTypes) {
|
|
70
|
-
const { title = 'SWAP'
|
|
72
|
+
const { title = 'SWAP' } = props;
|
|
71
73
|
|
|
72
74
|
const isRouterInContext = useInRouterContext();
|
|
73
75
|
const navigate = useNavigate();
|
|
@@ -76,10 +78,6 @@ export function Home(props: PropTypes) {
|
|
|
76
78
|
const fromToken = useBestRouteStore.use.fromToken();
|
|
77
79
|
const toChain = useBestRouteStore.use.toChain();
|
|
78
80
|
const toToken = useBestRouteStore.use.toToken();
|
|
79
|
-
const setFromChain = useBestRouteStore.use.setFromChain();
|
|
80
|
-
const setFromToken = useBestRouteStore.use.setFromToken();
|
|
81
|
-
const setToChain = useBestRouteStore.use.setToChain();
|
|
82
|
-
const setToToken = useBestRouteStore.use.setToToken();
|
|
83
81
|
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
84
82
|
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
85
83
|
const inputAmount = useBestRouteStore.use.inputAmount();
|
|
@@ -91,15 +89,8 @@ export function Home(props: PropTypes) {
|
|
|
91
89
|
const bestRouteError = useBestRouteStore.use.error();
|
|
92
90
|
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
93
91
|
const accounts = useWalletsStore.use.accounts();
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
setFromChain(toChain);
|
|
97
|
-
setFromToken(toToken);
|
|
98
|
-
setToChain(fromChain);
|
|
99
|
-
setToToken(fromToken);
|
|
100
|
-
setInputAmount(outputAmount?.toString() || '');
|
|
101
|
-
setCount((prev) => prev + 1);
|
|
102
|
-
};
|
|
92
|
+
const setCurrentPage = useUiStore.use.setCurrentPage();
|
|
93
|
+
const switchFromAndTo = useBestRouteStore.use.switchFromAndTo();
|
|
103
94
|
|
|
104
95
|
const errorMessage =
|
|
105
96
|
loadingMetaStatus === 'failed'
|
|
@@ -142,13 +133,21 @@ export function Home(props: PropTypes) {
|
|
|
142
133
|
|
|
143
134
|
const highFee = hasHighFee(totalFeeInUsd);
|
|
144
135
|
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
setCurrentPage(navigationRoutes.home);
|
|
138
|
+
|
|
139
|
+
return setCurrentPage.bind(null, '');
|
|
140
|
+
}, []);
|
|
141
|
+
|
|
145
142
|
return (
|
|
146
143
|
<Container>
|
|
147
144
|
<Header
|
|
148
145
|
title={title}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
146
|
+
suffix={
|
|
147
|
+
<HeaderButtons
|
|
148
|
+
onClickRefresh={!!bestRoute ? fetchBestRoute : undefined}
|
|
149
|
+
/>
|
|
150
|
+
}
|
|
152
151
|
/>
|
|
153
152
|
<FromContainer>
|
|
154
153
|
<TokenInfo
|
|
@@ -159,8 +158,14 @@ export function Home(props: PropTypes) {
|
|
|
159
158
|
inputAmount={inputAmount}
|
|
160
159
|
/>
|
|
161
160
|
<SwitchButtonContainer>
|
|
162
|
-
<Button
|
|
163
|
-
|
|
161
|
+
<Button
|
|
162
|
+
variant="ghost"
|
|
163
|
+
onClick={() => {
|
|
164
|
+
switchFromAndTo();
|
|
165
|
+
setCount((prev) => prev + 1);
|
|
166
|
+
}}
|
|
167
|
+
>
|
|
168
|
+
<VerticalSwapIcon size={32} />
|
|
164
169
|
{isRouterInContext && <SwithFromAndTo count={count} />}
|
|
165
170
|
</Button>
|
|
166
171
|
</SwitchButtonContainer>
|
|
@@ -215,7 +220,7 @@ export function Home(props: PropTypes) {
|
|
|
215
220
|
if (swapButtonState.title === 'Connect Wallet')
|
|
216
221
|
navigate(navigationRoutes.wallets);
|
|
217
222
|
else {
|
|
218
|
-
navigate(navigationRoutes.
|
|
223
|
+
navigate(navigationRoutes.confirmSwap, { replace: true });
|
|
219
224
|
}
|
|
220
225
|
}}
|
|
221
226
|
>
|
|
@@ -11,6 +11,7 @@ interface PropTypes {
|
|
|
11
11
|
}
|
|
12
12
|
export function LiquiditySourcePage({ supportedSwappers }: PropTypes) {
|
|
13
13
|
const swappers = useMetaStore.use.meta().swappers;
|
|
14
|
+
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
14
15
|
const toggleLiquiditySource = useSettingsStore.use.toggleLiquiditySource();
|
|
15
16
|
const disabledLiquiditySources =
|
|
16
17
|
useSettingsStore.use.disabledLiquiditySources();
|
|
@@ -59,6 +60,7 @@ export function LiquiditySourcePage({ supportedSwappers }: PropTypes) {
|
|
|
59
60
|
toggleLiquiditySource(liquiditySource.title)
|
|
60
61
|
}
|
|
61
62
|
onBack={navigateBackFrom.bind(null, navigationRoutes.liquiditySources)}
|
|
63
|
+
loadingStatus={loadingMetaStatus}
|
|
62
64
|
/>
|
|
63
65
|
);
|
|
64
66
|
}
|
|
@@ -5,6 +5,7 @@ import { Token } from 'rango-sdk';
|
|
|
5
5
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
6
6
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
7
7
|
import { tokensAreEqual } from '../utils/wallets';
|
|
8
|
+
import { useMetaStore } from '../store/meta';
|
|
8
9
|
|
|
9
10
|
interface PropTypes {
|
|
10
11
|
type: 'from' | 'to';
|
|
@@ -41,12 +42,12 @@ export function SelectTokenPage(props: PropTypes) {
|
|
|
41
42
|
tokensAreEqual(supportedToken, token)
|
|
42
43
|
)
|
|
43
44
|
);
|
|
44
|
-
console.log(supportedSourceTokens);
|
|
45
45
|
|
|
46
46
|
const fromToken = useBestRouteStore.use.fromToken();
|
|
47
47
|
const toToken = useBestRouteStore.use.toToken();
|
|
48
48
|
const setFromToken = useBestRouteStore.use.setFromToken();
|
|
49
49
|
const setToToken = useBestRouteStore.use.setToToken();
|
|
50
|
+
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
50
51
|
|
|
51
52
|
return (
|
|
52
53
|
<TokenSelector
|
|
@@ -59,6 +60,7 @@ export function SelectTokenPage(props: PropTypes) {
|
|
|
59
60
|
navigateBackFrom(navigationRoutes.fromToken);
|
|
60
61
|
}}
|
|
61
62
|
onBack={navigateBackFrom.bind(null, navigationRoutes.fromToken)}
|
|
63
|
+
loadingStatus={loadingMetaStatus}
|
|
62
64
|
/>
|
|
63
65
|
);
|
|
64
66
|
}
|
|
@@ -30,6 +30,8 @@ export function SettingsPage({ supportedSwappers }: PropTypes) {
|
|
|
30
30
|
|
|
31
31
|
const infiniteApprove = useSettingsStore.use.infiniteApprove();
|
|
32
32
|
const toggleInfiniteApprove = useSettingsStore.use.toggleInfiniteApprove();
|
|
33
|
+
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
34
|
+
|
|
33
35
|
const uniqueSwappersGroups: Array<{
|
|
34
36
|
title: string;
|
|
35
37
|
logo: string;
|
|
@@ -93,6 +95,7 @@ export function SettingsPage({ supportedSwappers }: PropTypes) {
|
|
|
93
95
|
onThemeChange={setTheme}
|
|
94
96
|
infiniteApprove={infiniteApprove}
|
|
95
97
|
toggleInfiniteApprove={toggleInfiniteApprove}
|
|
98
|
+
loadingStatus={loadingMetaStatus}
|
|
96
99
|
/>
|
|
97
100
|
);
|
|
98
101
|
}
|