@rango-dev/widget-embedded 0.1.10-next.99 → 0.1.10
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/SwapDetailsPlaceholder.d.ts +9 -0
- package/dist/components/SwapDetailsPlaceholder.d.ts.map +1 -0
- package/dist/components/TokenPreview.d.ts +1 -1
- 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 +2 -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 +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 +1 -0
- 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 +1048 -705
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +1048 -705
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +1057 -714
- 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/SwapDetailsPlaceholder.tsx +32 -0
- package/src/components/TokenPreview.tsx +7 -4
- 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 +128 -20
- package/src/pages/HistoryPage.tsx +4 -4
- package/src/pages/Home.tsx +19 -8
- 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 +110 -12
- package/src/store/ui.ts +4 -0
- package/src/store/wallets.ts +4 -1
- package/src/types/routing.ts +1 -1
- 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 +23 -13
- package/src/utils/swap.ts +101 -10
- 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/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,105 @@
|
|
|
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 {
|
|
14
|
+
calcOutputUsdValue,
|
|
15
|
+
getTotalFeeInUsd,
|
|
16
|
+
requiredWallets,
|
|
17
|
+
} from '../utils/swap';
|
|
18
|
+
import { decimalNumber, numberToString } from '../utils/numbers';
|
|
19
|
+
import { useMetaStore } from '../store/meta';
|
|
20
|
+
import { Network, WalletType } from '@rango-dev/wallets-shared';
|
|
21
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
22
|
+
import { TokenPreview } from '../components/TokenPreview';
|
|
23
|
+
// @ts-ignore // TODO: fix error in tsc build
|
|
24
|
+
import { t } from 'i18next';
|
|
25
|
+
import { Spacer, ConfirmSwap } from '@rango-dev/ui';
|
|
26
|
+
import RoutesOverview from '../components/RoutesOverview';
|
|
11
27
|
import { useManager } from '@rango-dev/queue-manager-react';
|
|
12
|
-
import { useUiStore } from '../store/ui';
|
|
13
28
|
import { useConfirmSwap } from '../hooks/useConfirmSwap';
|
|
29
|
+
import { useSettingsStore } from '../store/settings';
|
|
30
|
+
import { useUiStore } from '../store/ui';
|
|
14
31
|
import { ConfirmSwapErrorTypes } from '../types';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
32
|
+
import { ConfirmSwapErrors } from '../components/ConfirmSwapErrors';
|
|
33
|
+
import { ConfirmSwapWarnings } from '../components/ConfirmSwapWarnings';
|
|
34
|
+
import { ConfirmSwapExtraMessages } from '../components/warnings/ConfirmSwapExtraMessages';
|
|
35
|
+
import { getBestRouteStatus } from '../utils/routing';
|
|
17
36
|
|
|
18
37
|
export function ConfirmSwapPage() {
|
|
19
|
-
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
20
|
-
const { navigateBackFrom } = useNavigateBack();
|
|
21
|
-
const { manager } = useManager();
|
|
22
38
|
const navigate = useNavigate();
|
|
23
|
-
|
|
39
|
+
const { navigateBackFrom } = useNavigateBack();
|
|
24
40
|
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
25
41
|
const fetchingBestRoute = useBestRouteStore.use.loading();
|
|
26
|
-
const
|
|
27
|
-
|
|
42
|
+
const fetchingBestRouteError = useBestRouteStore.use.error();
|
|
43
|
+
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
44
|
+
const { blockchains, tokens } = useMetaStore.use.meta();
|
|
45
|
+
const accounts = useWalletsStore.use.accounts();
|
|
46
|
+
const selectedWallets = useWalletsStore.use.selectedWallets();
|
|
47
|
+
const initSelectedWallets = useWalletsStore.use.initSelectedWallets();
|
|
48
|
+
const setSelectedWallet = useWalletsStore.use.setSelectedWallet();
|
|
28
49
|
const slippage = useSettingsStore.use.slippage();
|
|
29
50
|
const customSlippage = useSettingsStore.use.customSlippage();
|
|
30
|
-
|
|
51
|
+
|
|
52
|
+
const bestRouteloadingStatus = getBestRouteStatus(
|
|
53
|
+
fetchingBestRoute,
|
|
54
|
+
!!fetchingBestRouteError
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const { manager } = useManager();
|
|
31
58
|
const { loading, errors, warnings, confirmSwap } = useConfirmSwap();
|
|
32
59
|
|
|
60
|
+
const selectedSlippage = customSlippage || slippage;
|
|
61
|
+
|
|
33
62
|
const showHighSlippageWarning = !errors.find(
|
|
34
63
|
(error) => error.type === ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE
|
|
35
64
|
);
|
|
36
65
|
|
|
66
|
+
const { getWalletInfo, connect } = useWallets();
|
|
67
|
+
const confirmDisabled =
|
|
68
|
+
fetchingBestRoute ||
|
|
69
|
+
!requiredWallets(bestRoute).every((chain) =>
|
|
70
|
+
selectedWallets.map((wallet) => wallet.chain).includes(chain)
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const firstStep = bestRoute?.result?.swaps[0];
|
|
74
|
+
const lastStep =
|
|
75
|
+
bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1];
|
|
76
|
+
|
|
77
|
+
const fromAmount = decimalNumber(firstStep?.fromAmount, 3);
|
|
78
|
+
const toAmount = decimalNumber(lastStep?.toAmount, 3);
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
initSelectedWallets();
|
|
81
|
+
}, []);
|
|
82
|
+
|
|
83
|
+
const selectableWallets = getSelectableWallets(
|
|
84
|
+
accounts,
|
|
85
|
+
selectedWallets,
|
|
86
|
+
getWalletInfo
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const handleConnectChain = (wallet: string) => {
|
|
90
|
+
const network = wallet as Network;
|
|
91
|
+
getKeplrCompatibleConnectedWallets(selectableWallets).forEach(
|
|
92
|
+
(compatibleWallet: WalletType) => connect?.(compatibleWallet, network)
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
97
|
+
|
|
37
98
|
return (
|
|
38
99
|
<ConfirmSwap
|
|
100
|
+
requiredWallets={getRequiredChains(bestRoute)}
|
|
101
|
+
selectableWallets={selectableWallets}
|
|
102
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.confirmSwap)}
|
|
39
103
|
onConfirm={() => {
|
|
40
104
|
confirmSwap?.().then((swap) => {
|
|
41
105
|
if (swap) {
|
|
@@ -51,8 +115,53 @@ export function ConfirmSwapPage() {
|
|
|
51
115
|
}
|
|
52
116
|
});
|
|
53
117
|
}}
|
|
54
|
-
|
|
55
|
-
|
|
118
|
+
onChange={(wallet) => setSelectedWallet(wallet)}
|
|
119
|
+
confirmDisabled={confirmDisabled}
|
|
120
|
+
handleConnectChain={(wallet) => handleConnectChain(wallet)}
|
|
121
|
+
isExperimentalChain={(wallet) =>
|
|
122
|
+
getKeplrCompatibleConnectedWallets(selectableWallets).length > 0
|
|
123
|
+
? isExperimentalChain(blockchains, wallet)
|
|
124
|
+
: false
|
|
125
|
+
}
|
|
126
|
+
previewInputs={
|
|
127
|
+
<>
|
|
128
|
+
<TokenPreview
|
|
129
|
+
chain={{
|
|
130
|
+
displayName: firstStep?.from.blockchain || '',
|
|
131
|
+
logo: firstStep?.from.blockchainLogo || '',
|
|
132
|
+
}}
|
|
133
|
+
token={{
|
|
134
|
+
symbol: firstStep?.from.symbol || '',
|
|
135
|
+
image: firstStep?.from.logo || '',
|
|
136
|
+
}}
|
|
137
|
+
usdValue={calcOutputUsdValue(fromAmount, firstStep?.from.usdPrice)}
|
|
138
|
+
amount={fromAmount}
|
|
139
|
+
label={t('From')}
|
|
140
|
+
loadingStatus={bestRouteloadingStatus}
|
|
141
|
+
/>
|
|
142
|
+
<Spacer size={12} direction="vertical" />
|
|
143
|
+
<TokenPreview
|
|
144
|
+
chain={{
|
|
145
|
+
displayName: lastStep?.to.blockchain || '',
|
|
146
|
+
logo: lastStep?.to.blockchainLogo || '',
|
|
147
|
+
}}
|
|
148
|
+
token={{
|
|
149
|
+
symbol: lastStep?.to.symbol || '',
|
|
150
|
+
image: lastStep?.to.logo || '',
|
|
151
|
+
}}
|
|
152
|
+
usdValue={calcOutputUsdValue(toAmount, lastStep?.to.usdPrice)}
|
|
153
|
+
amount={toAmount}
|
|
154
|
+
label={t('To')}
|
|
155
|
+
loadingStatus={bestRouteloadingStatus}
|
|
156
|
+
/>
|
|
157
|
+
</>
|
|
158
|
+
}
|
|
159
|
+
previewRoutes={
|
|
160
|
+
<RoutesOverview
|
|
161
|
+
routes={bestRoute}
|
|
162
|
+
totalFee={numberToString(totalFeeInUsd, 0, 2)}
|
|
163
|
+
/>
|
|
164
|
+
}
|
|
56
165
|
loading={loading}
|
|
57
166
|
errors={ConfirmSwapErrors(errors)}
|
|
58
167
|
warnings={ConfirmSwapWarnings(warnings)}
|
|
@@ -66,7 +175,6 @@ export function ConfirmSwapPage() {
|
|
|
66
175
|
? 'Proceed anyway!'
|
|
67
176
|
: 'Confirm swap!'
|
|
68
177
|
}
|
|
69
|
-
confirmButtonDisabled={fetchingBestRoute}
|
|
70
178
|
/>
|
|
71
179
|
);
|
|
72
180
|
}
|
|
@@ -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();
|
|
@@ -91,6 +93,7 @@ export function Home(props: PropTypes) {
|
|
|
91
93
|
const bestRouteError = useBestRouteStore.use.error();
|
|
92
94
|
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
93
95
|
const accounts = useWalletsStore.use.accounts();
|
|
96
|
+
const setCurrentPage = useUiStore.use.setCurrentPage();
|
|
94
97
|
|
|
95
98
|
const swithFromAndTo = () => {
|
|
96
99
|
setFromChain(toChain);
|
|
@@ -142,13 +145,21 @@ export function Home(props: PropTypes) {
|
|
|
142
145
|
|
|
143
146
|
const highFee = hasHighFee(totalFeeInUsd);
|
|
144
147
|
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
setCurrentPage(navigationRoutes.home);
|
|
150
|
+
|
|
151
|
+
return setCurrentPage.bind(null, '');
|
|
152
|
+
}, []);
|
|
153
|
+
|
|
145
154
|
return (
|
|
146
155
|
<Container>
|
|
147
156
|
<Header
|
|
148
157
|
title={title}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
158
|
+
suffix={
|
|
159
|
+
<HeaderButtons
|
|
160
|
+
onClickRefresh={!!bestRoute ? fetchBestRoute : undefined}
|
|
161
|
+
/>
|
|
162
|
+
}
|
|
152
163
|
/>
|
|
153
164
|
<FromContainer>
|
|
154
165
|
<TokenInfo
|
|
@@ -160,7 +171,7 @@ export function Home(props: PropTypes) {
|
|
|
160
171
|
/>
|
|
161
172
|
<SwitchButtonContainer>
|
|
162
173
|
<Button variant="ghost" onClick={swithFromAndTo}>
|
|
163
|
-
<VerticalSwapIcon size={
|
|
174
|
+
<VerticalSwapIcon size={32} />
|
|
164
175
|
{isRouterInContext && <SwithFromAndTo count={count} />}
|
|
165
176
|
</Button>
|
|
166
177
|
</SwitchButtonContainer>
|
|
@@ -215,7 +226,7 @@ export function Home(props: PropTypes) {
|
|
|
215
226
|
if (swapButtonState.title === 'Connect Wallet')
|
|
216
227
|
navigate(navigationRoutes.wallets);
|
|
217
228
|
else {
|
|
218
|
-
navigate(navigationRoutes.
|
|
229
|
+
navigate(navigationRoutes.confirmSwap, { replace: true });
|
|
219
230
|
}
|
|
220
231
|
}}
|
|
221
232
|
>
|
|
@@ -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
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
3
3
|
import useCopyToClipboard from '../hooks/useCopyToClipboard';
|
|
4
4
|
import { useManager } from '@rango-dev/queue-manager-react';
|
|
@@ -6,33 +6,169 @@ import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
|
6
6
|
import { getPendingSwaps } from '../utils/queue';
|
|
7
7
|
import { SwapHistory } from '@rango-dev/ui';
|
|
8
8
|
import { useUiStore } from '../store/ui';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
cancelSwap,
|
|
11
|
+
PendingSwapNetworkStatus,
|
|
12
|
+
} from '@rango-dev/queue-manager-rango-preset';
|
|
13
|
+
import { useWallets } from '@rango-dev/wallets-core';
|
|
14
|
+
import {
|
|
15
|
+
getCurrentBlockchainOfOrNull,
|
|
16
|
+
getCurrentStep,
|
|
17
|
+
getRelatedWalletOrNull,
|
|
18
|
+
} from '@rango-dev/queue-manager-rango-preset';
|
|
19
|
+
import { getSwapDate } from '../utils/time';
|
|
20
|
+
import { useNavigate } from 'react-router-dom';
|
|
21
|
+
import { useBestRouteStore } from '../store/bestRoute';
|
|
22
|
+
import {
|
|
23
|
+
getLastConvertedTokenInFailedSwap,
|
|
24
|
+
getSwapMessages,
|
|
25
|
+
isNetworkStatusInWarningState,
|
|
26
|
+
shouldRetrySwap,
|
|
27
|
+
} from '../utils/swap';
|
|
28
|
+
import { TokenPreview } from '../components/TokenPreview';
|
|
29
|
+
import { Spacer } from '@rango-dev/ui';
|
|
30
|
+
import { numberToString } from '../utils/numbers';
|
|
31
|
+
//@ts-ignore
|
|
32
|
+
import { t } from 'i18next';
|
|
33
|
+
import { SwapDetailsPlaceholder } from '../components/SwapDetailsPlaceholder';
|
|
10
34
|
|
|
11
35
|
export function SwapDetailsPage() {
|
|
12
36
|
const selectedSwapRequestId = useUiStore.use.selectedSwapRequestId();
|
|
37
|
+
const { canSwitchNetworkTo, connect } = useWallets();
|
|
38
|
+
const retry = useBestRouteStore.use.retry();
|
|
39
|
+
const navigate = useNavigate();
|
|
13
40
|
const { navigateBackFrom } = useNavigateBack();
|
|
14
|
-
const { manager } = useManager();
|
|
15
41
|
const [isCopied, handleCopy] = useCopyToClipboard(2000);
|
|
42
|
+
const { manager } = useManager();
|
|
43
|
+
|
|
44
|
+
const [loading, setLoading] = useState(true);
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
setLoading(false);
|
|
49
|
+
}, 5000);
|
|
50
|
+
}, []);
|
|
16
51
|
|
|
17
52
|
const pendingSwaps = getPendingSwaps(manager);
|
|
18
53
|
const selectedSwap = pendingSwaps.find(
|
|
19
54
|
({ swap }) => swap.requestId === selectedSwapRequestId
|
|
20
55
|
);
|
|
21
56
|
|
|
22
|
-
//TODO: implement swap cancellation (move queueManager logic to queueManager/rango-preset)
|
|
23
57
|
const onCancel = () => {
|
|
24
|
-
const swap =
|
|
58
|
+
const swap = manager?.get(selectedSwap?.id!);
|
|
25
59
|
if (swap) cancelSwap(swap);
|
|
26
60
|
};
|
|
61
|
+
const swap = selectedSwap?.swap;
|
|
62
|
+
|
|
63
|
+
if (!swap)
|
|
64
|
+
return (
|
|
65
|
+
<SwapDetailsPlaceholder
|
|
66
|
+
requestId={selectedSwapRequestId || ''}
|
|
67
|
+
loading={loading}
|
|
68
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.swapDetails)}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const firstStep = swap.steps[0];
|
|
73
|
+
const lastStep = swap.steps[swap.steps.length - 1];
|
|
74
|
+
const fromAmount = numberToString(swap.inputAmount);
|
|
75
|
+
const toAmount = numberToString(swap.simulationResult.outputAmount);
|
|
76
|
+
|
|
77
|
+
const currentStep = getCurrentStep(swap);
|
|
78
|
+
|
|
79
|
+
const currentStepBlockchain = currentStep
|
|
80
|
+
? getCurrentBlockchainOfOrNull(swap, currentStep)
|
|
81
|
+
: null;
|
|
82
|
+
const currentStepWallet = currentStep
|
|
83
|
+
? getRelatedWalletOrNull(swap, currentStep)
|
|
84
|
+
: null;
|
|
85
|
+
const currentStepNetworkStatus = currentStep?.networkStatus;
|
|
86
|
+
|
|
87
|
+
const swapMessages = getSwapMessages(swap, currentStep);
|
|
88
|
+
|
|
89
|
+
const networkWarningState = isNetworkStatusInWarningState(currentStep);
|
|
90
|
+
|
|
91
|
+
const swapDate = getSwapDate(swap);
|
|
92
|
+
|
|
93
|
+
const shouldRetry = shouldRetrySwap(swap);
|
|
94
|
+
|
|
95
|
+
const switchNetwork =
|
|
96
|
+
!!currentStepBlockchain &&
|
|
97
|
+
!!currentStepWallet?.walletType &&
|
|
98
|
+
currentStepNetworkStatus ===
|
|
99
|
+
PendingSwapNetworkStatus.WaitingForNetworkChange &&
|
|
100
|
+
canSwitchNetworkTo(currentStepWallet?.walletType, currentStepBlockchain)
|
|
101
|
+
? connect.bind(null, currentStepWallet.walletType, currentStepBlockchain)
|
|
102
|
+
: undefined;
|
|
103
|
+
|
|
104
|
+
const lastConvertedTokenInFailedSwap =
|
|
105
|
+
getLastConvertedTokenInFailedSwap(swap);
|
|
106
|
+
|
|
27
107
|
return (
|
|
28
108
|
<SwapHistory
|
|
29
109
|
onBack={navigateBackFrom.bind(null, navigationRoutes.swapDetails)}
|
|
110
|
+
previewInputs={
|
|
111
|
+
<>
|
|
112
|
+
<TokenPreview
|
|
113
|
+
chain={{
|
|
114
|
+
displayName: firstStep?.fromBlockchain || '',
|
|
115
|
+
// @ts-ignore
|
|
116
|
+
logo: firstStep?.fromBlockchainLogo || '',
|
|
117
|
+
}}
|
|
118
|
+
token={{
|
|
119
|
+
symbol: firstStep?.fromSymbol || '',
|
|
120
|
+
image: firstStep?.fromLogo || '',
|
|
121
|
+
}}
|
|
122
|
+
amount={fromAmount}
|
|
123
|
+
label={t('From')}
|
|
124
|
+
loadingStatus={'success'}
|
|
125
|
+
/>
|
|
126
|
+
<Spacer size={12} direction="vertical" />
|
|
127
|
+
<TokenPreview
|
|
128
|
+
chain={{
|
|
129
|
+
displayName: lastStep?.toBlockchain || '',
|
|
130
|
+
// @ts-ignore
|
|
131
|
+
logo: lastStep?.toBlockchainLogo || '',
|
|
132
|
+
}}
|
|
133
|
+
token={{
|
|
134
|
+
symbol: lastStep?.toSymbol || '',
|
|
135
|
+
image: lastStep?.toLogo || '',
|
|
136
|
+
}}
|
|
137
|
+
amount={toAmount}
|
|
138
|
+
label={t('To')}
|
|
139
|
+
loadingStatus={'success'}
|
|
140
|
+
/>
|
|
141
|
+
</>
|
|
142
|
+
}
|
|
30
143
|
//todo: move PendingSwap type to rango-types
|
|
31
144
|
//@ts-ignore
|
|
32
|
-
pendingSwap={
|
|
145
|
+
pendingSwap={swap}
|
|
33
146
|
onCopy={handleCopy}
|
|
34
147
|
isCopied={isCopied}
|
|
35
148
|
onCancel={onCancel}
|
|
149
|
+
shortMessage={swapMessages.shortMessage}
|
|
150
|
+
detailedMessage={swapMessages.detailedMessage}
|
|
151
|
+
currentStepBlockchain={currentStepBlockchain || ''}
|
|
152
|
+
switchNetwork={switchNetwork}
|
|
153
|
+
type={
|
|
154
|
+
networkWarningState ? 'warning' : swap.extraMessageSeverity || undefined
|
|
155
|
+
}
|
|
156
|
+
date={swapDate}
|
|
157
|
+
{...(shouldRetry && {
|
|
158
|
+
onRetry: () => {
|
|
159
|
+
retry(swap);
|
|
160
|
+
setTimeout(() => {
|
|
161
|
+
navigate(navigationRoutes.home);
|
|
162
|
+
}, 0);
|
|
163
|
+
},
|
|
164
|
+
})}
|
|
165
|
+
{...(lastConvertedTokenInFailedSwap && {
|
|
166
|
+
lastConvertedTokenInFailedSwap: {
|
|
167
|
+
blockchain: lastConvertedTokenInFailedSwap.blockchain,
|
|
168
|
+
outputAmount: lastConvertedTokenInFailedSwap.outputAmount || '',
|
|
169
|
+
symbol: lastConvertedTokenInFailedSwap.symbol,
|
|
170
|
+
},
|
|
171
|
+
})}
|
|
36
172
|
/>
|
|
37
173
|
);
|
|
38
174
|
}
|