@rango-dev/widget-embedded 0.20.1-next.21 → 0.20.1-next.22
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/components/AppRouter.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/Layout/Layout.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.d.ts.map +1 -1
- package/dist/constants/searchParams.d.ts +6 -6
- package/dist/constants/searchParams.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
- package/dist/hooks/useSyncUrlAndStore/index.d.ts +2 -0
- package/dist/hooks/useSyncUrlAndStore/index.d.ts.map +1 -0
- package/dist/hooks/useSyncUrlAndStore/useSyncUrlAndStore.d.ts +2 -0
- package/dist/hooks/useSyncUrlAndStore/useSyncUrlAndStore.d.ts.map +1 -0
- package/dist/hooks/useSyncUrlAndStore/useSyncUrlAndStore.helpers.d.ts +4 -0
- package/dist/hooks/useSyncUrlAndStore/useSyncUrlAndStore.helpers.d.ts.map +1 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- 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/SwapDetailsPage.d.ts.map +1 -1
- package/dist/utils/quote.d.ts +0 -1
- package/dist/utils/quote.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/components/AppRouter.tsx +1 -8
- package/src/components/AppRoutes.tsx +11 -0
- package/src/components/Layout/Layout.tsx +1 -6
- package/src/components/NotificationContent/NotificationContent.tsx +0 -3
- package/src/constants/searchParams.ts +6 -6
- package/src/containers/Wallets/Wallets.tsx +0 -2
- package/src/hooks/useSwapInput.ts +6 -1
- package/src/hooks/useSyncStoresWithConfig.ts +3 -17
- package/src/hooks/useSyncUrlAndStore/index.ts +1 -0
- package/src/hooks/useSyncUrlAndStore/useSyncUrlAndStore.helpers.ts +35 -0
- package/src/hooks/useSyncUrlAndStore/useSyncUrlAndStore.ts +135 -0
- package/src/pages/ConfirmSwapPage.tsx +3 -5
- package/src/pages/HistoryPage.tsx +1 -6
- package/src/pages/Home.tsx +9 -6
- package/src/pages/SwapDetailsPage.tsx +21 -7
- package/src/utils/quote.ts +0 -27
- package/dist/components/UpdateUrl.d.ts +0 -2
- package/dist/components/UpdateUrl.d.ts.map +0 -1
- package/dist/store/ui.d.ts +0 -22
- package/dist/store/ui.d.ts.map +0 -1
- package/src/components/UpdateUrl.tsx +0 -158
- package/src/store/ui.ts +0 -21
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfirmSwapPage.d.ts","sourceRoot":"","sources":["../../src/pages/ConfirmSwapPage.tsx"],"names":[],"mappings":"AAoBA,OAAO,KAAuD,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ConfirmSwapPage.d.ts","sourceRoot":"","sources":["../../src/pages/ConfirmSwapPage.tsx"],"names":[],"mappings":"AAoBA,OAAO,KAAuD,MAAM,OAAO,CAAC;AAkD5E,wBAAgB,eAAe,sBA0T9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HistoryPage.d.ts","sourceRoot":"","sources":["../../src/pages/HistoryPage.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAmB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"HistoryPage.d.ts","sourceRoot":"","sources":["../../src/pages/HistoryPage.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAiCxC,wBAAgB,WAAW,sBAiE1B"}
|
package/dist/pages/Home.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Home.d.ts","sourceRoot":"","sources":["../../src/pages/Home.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA8B,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Home.d.ts","sourceRoot":"","sources":["../../src/pages/Home.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAsCnD,wBAAgB,IAAI,sBAuPnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwapDetailsPage.d.ts","sourceRoot":"","sources":["../../src/pages/SwapDetailsPage.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SwapDetailsPage.d.ts","sourceRoot":"","sources":["../../src/pages/SwapDetailsPage.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAC;AAS1B,wBAAgB,eAAe,sBAgE9B"}
|
package/dist/utils/quote.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type { SimulationAssetAndAmount, SimulationValidationStatus } from '@rang
|
|
|
4
4
|
import type { Asset, BestRouteResponse, BlockchainMeta, Token } from 'rango-sdk';
|
|
5
5
|
import type { PendingSwap } from 'rango-types';
|
|
6
6
|
import BigNumber from 'bignumber.js';
|
|
7
|
-
export declare function searchParamsToToken(tokens: Token[], searchParams: string | null, chain: BlockchainMeta | null): Token | null;
|
|
8
7
|
export declare function getQuoteToTokenUsdPrice(quote: BestRouteResponse | null): number | null | undefined;
|
|
9
8
|
export declare function isNumberOfSwapsChanged(quoteA: BestRouteResponse, quoteB: BestRouteResponse): boolean;
|
|
10
9
|
export declare function isQuoteSwappersUpdated(quoteA: BestRouteResponse, quoteB: BestRouteResponse): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quote.d.ts","sourceRoot":"","sources":["../../src/utils/quote.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACjE,OAAO,KAAK,EAAE,uBAAuB,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACn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S,MAAM;GAanD,CAAC"}
|
package/package.json
CHANGED
|
@@ -10,8 +10,6 @@ import { MemoryRouter, useInRouterContext } from 'react-router';
|
|
|
10
10
|
import { useForceAutoConnect } from '../hooks/useForceAutoConnect';
|
|
11
11
|
import { useAppStore } from '../store/AppStore';
|
|
12
12
|
|
|
13
|
-
import { UpdateUrl } from './UpdateUrl';
|
|
14
|
-
|
|
15
13
|
export function AppRouter({
|
|
16
14
|
children,
|
|
17
15
|
...props
|
|
@@ -37,10 +35,5 @@ export function AppRouter({
|
|
|
37
35
|
canSwitchNetworkTo,
|
|
38
36
|
});
|
|
39
37
|
|
|
40
|
-
return
|
|
41
|
-
<>
|
|
42
|
-
<Router>{children}</Router>
|
|
43
|
-
{isRouterInContext && <UpdateUrl />}
|
|
44
|
-
</>
|
|
45
|
-
);
|
|
38
|
+
return <Router>{children}</Router>;
|
|
46
39
|
}
|
|
@@ -2,6 +2,8 @@ import React from 'react';
|
|
|
2
2
|
import { useRoutes } from 'react-router-dom';
|
|
3
3
|
|
|
4
4
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
5
|
+
import { useSyncStoresWithConfig } from '../hooks/useSyncStoresWithConfig';
|
|
6
|
+
import { useSyncUrlAndStore } from '../hooks/useSyncUrlAndStore';
|
|
5
7
|
import { ConfirmSwapPage } from '../pages/ConfirmSwapPage';
|
|
6
8
|
import { HistoryPage } from '../pages/HistoryPage';
|
|
7
9
|
import { Home } from '../pages/Home';
|
|
@@ -15,6 +17,15 @@ import { ThemePage } from '../pages/ThemePage';
|
|
|
15
17
|
import { WalletsPage } from '../pages/WalletsPage';
|
|
16
18
|
|
|
17
19
|
export function AppRoutes() {
|
|
20
|
+
/**
|
|
21
|
+
* The configuration of the widget should initially be applied to the widget state.
|
|
22
|
+
* If search parameters exist in the URL,
|
|
23
|
+
* they should be applied later and take precedence over the widget configuration.
|
|
24
|
+
* To achieve this, it is crucial to execute these hooks in the correct sequence.
|
|
25
|
+
*/
|
|
26
|
+
useSyncStoresWithConfig();
|
|
27
|
+
useSyncUrlAndStore();
|
|
28
|
+
|
|
18
29
|
return useRoutes([
|
|
19
30
|
{
|
|
20
31
|
path: navigationRoutes.home,
|
|
@@ -8,7 +8,6 @@ import { RANGO_SWAP_BOX_ID } from '../../constants';
|
|
|
8
8
|
import { useNavigateBack } from '../../hooks/useNavigateBack';
|
|
9
9
|
import { useTheme } from '../../hooks/useTheme';
|
|
10
10
|
import { useAppStore } from '../../store/AppStore';
|
|
11
|
-
import { useUiStore } from '../../store/ui';
|
|
12
11
|
import { useWalletsStore } from '../../store/wallets';
|
|
13
12
|
import { getContainer } from '../../utils/common';
|
|
14
13
|
import { isFeatureHidden } from '../../utils/settings';
|
|
@@ -30,14 +29,10 @@ function Layout(props: PropsWithChildren<PropTypes>) {
|
|
|
30
29
|
features
|
|
31
30
|
);
|
|
32
31
|
|
|
33
|
-
const connectWalletsButtonDisabled =
|
|
34
|
-
useUiStore.use.connectWalletsButtonDisabled();
|
|
35
32
|
const navigateBack = useNavigateBack();
|
|
36
33
|
|
|
37
34
|
const onConnectWallet = () => {
|
|
38
|
-
|
|
39
|
-
header.onWallet();
|
|
40
|
-
}
|
|
35
|
+
header.onWallet?.();
|
|
41
36
|
};
|
|
42
37
|
|
|
43
38
|
const showBackButton =
|
|
@@ -14,7 +14,6 @@ import { useNavigate } from 'react-router-dom';
|
|
|
14
14
|
import { navigationRoutes } from '../../constants/navigationRoutes';
|
|
15
15
|
import { useAppStore } from '../../store/AppStore';
|
|
16
16
|
import { useNotificationStore } from '../../store/notification';
|
|
17
|
-
import { useUiStore } from '../../store/ui';
|
|
18
17
|
|
|
19
18
|
import { Container, Images, List } from './NotificationContent.styles';
|
|
20
19
|
import { NotificationNotFound } from './NotificationNotFound';
|
|
@@ -23,7 +22,6 @@ const MAX_NOTIFICATIONS_DISPLAYED = 4;
|
|
|
23
22
|
|
|
24
23
|
export function NotificationContent() {
|
|
25
24
|
const navigate = useNavigate();
|
|
26
|
-
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
27
25
|
|
|
28
26
|
const { getUnreadNotifications } = useNotificationStore();
|
|
29
27
|
|
|
@@ -35,7 +33,6 @@ export function NotificationContent() {
|
|
|
35
33
|
.slice(0, MAX_NOTIFICATIONS_DISPLAYED);
|
|
36
34
|
|
|
37
35
|
const handleOnClick = (requestId: Notification['requestId']) => {
|
|
38
|
-
setSelectedSwap(requestId);
|
|
39
36
|
navigate(`${navigationRoutes.swaps}/${requestId}`);
|
|
40
37
|
};
|
|
41
38
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export enum SearchParams {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
FROM_BLOCKCHAIN = 'fromBlockchain',
|
|
3
|
+
FROM_TOKEN = 'fromToken',
|
|
4
|
+
TO_BLOCKCHAIN = 'toBlockchain',
|
|
5
|
+
TO_TOKEN = 'toToken',
|
|
6
|
+
FROM_AMOUNT = 'fromAmount',
|
|
7
|
+
AUTO_CONNECT = 'autoConnect',
|
|
8
8
|
}
|
|
@@ -13,7 +13,6 @@ import { Events, Provider } from '@rango-dev/wallets-react';
|
|
|
13
13
|
import { isEvmBlockchain } from 'rango-sdk';
|
|
14
14
|
import React, { createContext, useEffect, useRef, useState } from 'react';
|
|
15
15
|
|
|
16
|
-
import { useSyncStoresWithConfig } from '../../hooks/useSyncStoresWithConfig';
|
|
17
16
|
import { useWalletProviders } from '../../hooks/useWalletProviders';
|
|
18
17
|
import { AppStoreProvider, useAppStore } from '../../store/AppStore';
|
|
19
18
|
import { useWalletsStore } from '../../store/wallets';
|
|
@@ -39,7 +38,6 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
39
38
|
const { providers } = useWalletProviders(props.config.wallets, walletOptions);
|
|
40
39
|
const { connectWallet, disconnectWallet } = useWalletsStore();
|
|
41
40
|
const onConnectWalletHandler = useRef<OnConnectHandler>();
|
|
42
|
-
useSyncStoresWithConfig();
|
|
43
41
|
|
|
44
42
|
useEffect(() => {
|
|
45
43
|
void fetchMeta().catch(console.log);
|
|
@@ -59,8 +59,9 @@ export function useSwapInput(): UseSwapInput {
|
|
|
59
59
|
affiliateRef,
|
|
60
60
|
affiliateWallets,
|
|
61
61
|
disabledLiquiditySources,
|
|
62
|
+
fetchStatus,
|
|
62
63
|
} = useAppStore();
|
|
63
|
-
const [loading, setLoading] = useState(
|
|
64
|
+
const [loading, setLoading] = useState(true);
|
|
64
65
|
const [error, setError] = useState<QuoteError | null>(null);
|
|
65
66
|
const [warning, setWarning] = useState<QuoteWarning | null>(null);
|
|
66
67
|
const userSlippage = customSlippage ?? slippage;
|
|
@@ -148,6 +149,9 @@ export function useSwapInput(): UseSwapInput {
|
|
|
148
149
|
);
|
|
149
150
|
|
|
150
151
|
useEffect(() => {
|
|
152
|
+
if (fetchStatus !== 'success') {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
151
155
|
if (!isPositiveNumber(inputAmount) || inputUsdValue?.eq(0)) {
|
|
152
156
|
resetState(false);
|
|
153
157
|
cancelFetch();
|
|
@@ -175,6 +179,7 @@ export function useSwapInput(): UseSwapInput {
|
|
|
175
179
|
});
|
|
176
180
|
return cancelFetch;
|
|
177
181
|
}, [
|
|
182
|
+
fetchStatus,
|
|
178
183
|
inputAmount,
|
|
179
184
|
fromToken?.symbol,
|
|
180
185
|
fromToken?.address,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Asset } from 'rango-sdk';
|
|
2
2
|
|
|
3
|
-
import { useEffect,
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
4
|
|
|
5
5
|
import { useAppStore } from '../store/AppStore';
|
|
6
6
|
import { useQuoteStore } from '../store/quote';
|
|
@@ -44,14 +44,7 @@ export function useSyncStoresWithConfig() {
|
|
|
44
44
|
setInputAmount(config?.amount?.toString() || '');
|
|
45
45
|
}, [config?.amount]);
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
* We update quote tokens in two scenarios.
|
|
49
|
-
* If default values exist in widget config or search parameters exist in URL.
|
|
50
|
-
* The logic for updating quote store exists in two useEffect in two locations, and they run in order.If default tokens for quote exist in widget config and also exist in URL, widget config values take precedence over URL values, and URL search parameters don’t affect the widget.
|
|
51
|
-
* Using useLayoutEffect causes widget config values to apply first.
|
|
52
|
-
* We may consider replacing this with a better solution in the future.
|
|
53
|
-
*/
|
|
54
|
-
useLayoutEffect(() => {
|
|
47
|
+
useEffect(() => {
|
|
55
48
|
if (fetchMetaStatus === 'success') {
|
|
56
49
|
const chain = blockchains.find(
|
|
57
50
|
(chain) => chain.name === config?.from?.blockchain
|
|
@@ -100,14 +93,7 @@ export function useSyncStoresWithConfig() {
|
|
|
100
93
|
}
|
|
101
94
|
}, [toTokensConfig, toBlockchainsConfig]);
|
|
102
95
|
|
|
103
|
-
|
|
104
|
-
* We update quote tokens in two scenarios.
|
|
105
|
-
* If default values exist in widget config or search parameters exist in URL.
|
|
106
|
-
* The logic for updating quote store exists in two useEffect in two locations, and they run in order.If default tokens for quote exist in widget config and also exist in URL, widget config values take precedence over URL values, and URL search parameters don’t affect the widget.
|
|
107
|
-
* Using useLayoutEffect causes widget config values to apply first.
|
|
108
|
-
* We may consider replacing this with a better solution in the future.
|
|
109
|
-
*/
|
|
110
|
-
useLayoutEffect(() => {
|
|
96
|
+
useEffect(() => {
|
|
111
97
|
if (fetchMetaStatus === 'success') {
|
|
112
98
|
const chain = blockchains.find(
|
|
113
99
|
(chain) => chain.name === config?.to?.blockchain
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useSyncUrlAndStore } from './useSyncUrlAndStore';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { BlockchainMeta, Token } from 'rango-sdk';
|
|
2
|
+
|
|
3
|
+
export function searchParamToToken(
|
|
4
|
+
tokens: Token[],
|
|
5
|
+
searchParam: string | null,
|
|
6
|
+
chain: BlockchainMeta | null
|
|
7
|
+
): Token | null {
|
|
8
|
+
if (!chain) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
return (
|
|
12
|
+
tokens.find((token) => {
|
|
13
|
+
const symbolAndAddress = searchParam?.split('--');
|
|
14
|
+
if (symbolAndAddress?.length === 1) {
|
|
15
|
+
return (
|
|
16
|
+
token.symbol === symbolAndAddress[0] &&
|
|
17
|
+
token.address === null &&
|
|
18
|
+
token.blockchain === chain.name
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return (
|
|
22
|
+
token.symbol === symbolAndAddress?.[0] &&
|
|
23
|
+
token.address === symbolAndAddress?.[1] &&
|
|
24
|
+
token.blockchain === chain.name
|
|
25
|
+
);
|
|
26
|
+
}) || null
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function tokenToSearchParam(token: Token | null): string | undefined {
|
|
31
|
+
if (token) {
|
|
32
|
+
return `${token.symbol}${token.address ? `--${token.address}` : ''}`;
|
|
33
|
+
}
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
useInRouterContext,
|
|
4
|
+
useLocation,
|
|
5
|
+
useSearchParams,
|
|
6
|
+
} from 'react-router-dom';
|
|
7
|
+
|
|
8
|
+
import { SearchParams } from '../../constants/searchParams';
|
|
9
|
+
import { useAppStore } from '../../store/AppStore';
|
|
10
|
+
import { useQuoteStore } from '../../store/quote';
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
searchParamToToken,
|
|
14
|
+
tokenToSearchParam,
|
|
15
|
+
} from './useSyncUrlAndStore.helpers';
|
|
16
|
+
|
|
17
|
+
export function useSyncUrlAndStore() {
|
|
18
|
+
const location = useLocation();
|
|
19
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
20
|
+
const {
|
|
21
|
+
fromBlockchain,
|
|
22
|
+
toBlockchain,
|
|
23
|
+
fromToken,
|
|
24
|
+
toToken,
|
|
25
|
+
inputAmount,
|
|
26
|
+
setFromBlockchain,
|
|
27
|
+
setToBlockchain,
|
|
28
|
+
setFromToken,
|
|
29
|
+
setToToken,
|
|
30
|
+
setInputAmount,
|
|
31
|
+
} = useQuoteStore();
|
|
32
|
+
const fetchMetaStatus = useAppStore().fetchStatus;
|
|
33
|
+
const blockchains = useAppStore().blockchains();
|
|
34
|
+
const tokens = useAppStore().tokens();
|
|
35
|
+
const isInRouterContext = useInRouterContext();
|
|
36
|
+
|
|
37
|
+
const getUrlSearchParams = () => {
|
|
38
|
+
const fromAmount = searchParams.get(SearchParams.FROM_AMOUNT);
|
|
39
|
+
const fromBlockchain = searchParams.get(SearchParams.FROM_BLOCKCHAIN);
|
|
40
|
+
const fromToken = searchParams.get(SearchParams.FROM_TOKEN);
|
|
41
|
+
const toBlockchain = searchParams.get(SearchParams.TO_BLOCKCHAIN);
|
|
42
|
+
const toToken = searchParams.get(SearchParams.TO_TOKEN);
|
|
43
|
+
const autoConnect = searchParams.get(SearchParams.AUTO_CONNECT);
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
fromAmount,
|
|
47
|
+
fromBlockchain,
|
|
48
|
+
fromToken,
|
|
49
|
+
toBlockchain,
|
|
50
|
+
toToken,
|
|
51
|
+
autoConnect,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const updateUrlSearchParams = (
|
|
56
|
+
searchParams: Record<string, string | undefined>
|
|
57
|
+
) => {
|
|
58
|
+
for (const property in searchParams) {
|
|
59
|
+
if (!searchParams[property]) {
|
|
60
|
+
delete searchParams[property];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
setSearchParams(searchParams as Record<string, string>, { replace: true });
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
const { autoConnect } = getUrlSearchParams();
|
|
68
|
+
if (isInRouterContext && fetchMetaStatus === 'success') {
|
|
69
|
+
updateUrlSearchParams({
|
|
70
|
+
[SearchParams.FROM_BLOCKCHAIN]: fromBlockchain?.name,
|
|
71
|
+
[SearchParams.FROM_TOKEN]: tokenToSearchParam(fromToken),
|
|
72
|
+
[SearchParams.TO_BLOCKCHAIN]: toBlockchain?.name,
|
|
73
|
+
[SearchParams.TO_TOKEN]: tokenToSearchParam(toToken),
|
|
74
|
+
[SearchParams.FROM_AMOUNT]: inputAmount,
|
|
75
|
+
[SearchParams.AUTO_CONNECT]: autoConnect ?? undefined,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}, [
|
|
79
|
+
location.pathname,
|
|
80
|
+
inputAmount,
|
|
81
|
+
fromBlockchain,
|
|
82
|
+
fromToken,
|
|
83
|
+
toBlockchain,
|
|
84
|
+
toToken,
|
|
85
|
+
]);
|
|
86
|
+
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (!isInRouterContext) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const searchParams = getUrlSearchParams();
|
|
92
|
+
if (searchParams.fromAmount) {
|
|
93
|
+
setInputAmount(searchParams.fromAmount);
|
|
94
|
+
}
|
|
95
|
+
if (fetchMetaStatus === 'success') {
|
|
96
|
+
const fromBlockchain = blockchains.find(
|
|
97
|
+
(blockchain) => blockchain.name === searchParams.fromBlockchain
|
|
98
|
+
);
|
|
99
|
+
const fromToken = searchParamToToken(
|
|
100
|
+
tokens,
|
|
101
|
+
searchParams.fromToken,
|
|
102
|
+
fromBlockchain ?? null
|
|
103
|
+
);
|
|
104
|
+
const toBlockchain = blockchains.find(
|
|
105
|
+
(blockchain) => blockchain.name === searchParams.toBlockchain
|
|
106
|
+
);
|
|
107
|
+
const toToken = searchParamToToken(
|
|
108
|
+
tokens,
|
|
109
|
+
searchParams.toToken,
|
|
110
|
+
toBlockchain ?? null
|
|
111
|
+
);
|
|
112
|
+
if (!!fromBlockchain) {
|
|
113
|
+
setFromBlockchain(fromBlockchain);
|
|
114
|
+
if (!!fromToken) {
|
|
115
|
+
setFromToken({
|
|
116
|
+
token: fromToken,
|
|
117
|
+
meta: {
|
|
118
|
+
blockchains: blockchains,
|
|
119
|
+
tokens: tokens,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (!!toBlockchain) {
|
|
125
|
+
setToBlockchain(toBlockchain);
|
|
126
|
+
if (!!toToken) {
|
|
127
|
+
setToToken({
|
|
128
|
+
token: toToken,
|
|
129
|
+
meta: { blockchains: blockchains, tokens: tokens },
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}, [fetchMetaStatus]);
|
|
135
|
+
}
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
} from '@rango-dev/ui';
|
|
21
21
|
import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
22
22
|
import { flushSync } from 'react-dom';
|
|
23
|
-
import { useNavigate } from 'react-router-dom';
|
|
23
|
+
import { useLocation, useNavigate } from 'react-router-dom';
|
|
24
24
|
|
|
25
25
|
import { getRequiredWallets } from '../components/ConfirmWalletsModal/ConfirmWallets.helpers';
|
|
26
26
|
import { ConfirmWalletsModal } from '../components/ConfirmWalletsModal/ConfirmWalletsModal';
|
|
@@ -34,7 +34,6 @@ import { QuoteInfo } from '../containers/QuoteInfo';
|
|
|
34
34
|
import { useConfirmSwap } from '../hooks/useConfirmSwap';
|
|
35
35
|
import { useAppStore } from '../store/AppStore';
|
|
36
36
|
import { useQuoteStore } from '../store/quote';
|
|
37
|
-
import { useUiStore } from '../store/ui';
|
|
38
37
|
import { useWalletsStore } from '../store/wallets';
|
|
39
38
|
import { QuoteWarningType } from '../types';
|
|
40
39
|
import { getContainer } from '../utils/common';
|
|
@@ -81,12 +80,12 @@ export function ConfirmSwapPage() {
|
|
|
81
80
|
quoteWarningsConfirmed,
|
|
82
81
|
} = useQuoteStore();
|
|
83
82
|
const navigate = useNavigate();
|
|
83
|
+
const location = useLocation();
|
|
84
84
|
const [dbErrorMessage, setDbErrorMessage] = useState<string>('');
|
|
85
85
|
|
|
86
86
|
const { connectedWallets } = useWalletsStore();
|
|
87
87
|
const showWalletsOnInit = !quoteWalletsConfirmed;
|
|
88
88
|
const [showWallets, setShowWallets] = useState(false);
|
|
89
|
-
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
90
89
|
const disabledLiquiditySources = useAppStore().disabledLiquiditySources;
|
|
91
90
|
const prevDisabledLiquiditySources = useRef(disabledLiquiditySources);
|
|
92
91
|
const { manager } = useManager();
|
|
@@ -121,7 +120,6 @@ export function ConfirmSwapPage() {
|
|
|
121
120
|
{ swapDetails: confirmSwapResult.swap },
|
|
122
121
|
{ id: confirmSwapResult.swap.requestId }
|
|
123
122
|
);
|
|
124
|
-
setSelectedSwap(confirmSwapResult.swap.requestId);
|
|
125
123
|
|
|
126
124
|
const swap_url = `../${navigationRoutes.swaps}/${confirmSwapResult.swap.requestId}`;
|
|
127
125
|
navigate(swap_url, {
|
|
@@ -252,7 +250,7 @@ export function ConfirmSwapPage() {
|
|
|
252
250
|
|
|
253
251
|
useLayoutEffect(() => {
|
|
254
252
|
if (!quote) {
|
|
255
|
-
navigate(
|
|
253
|
+
navigate(`../${location.search}`);
|
|
256
254
|
}
|
|
257
255
|
}, []);
|
|
258
256
|
|
|
@@ -10,7 +10,6 @@ import { Layout, PageContainer } from '../components/Layout';
|
|
|
10
10
|
import { SearchInput } from '../components/SearchInput';
|
|
11
11
|
import { SwapsGroup } from '../components/SwapsGroup';
|
|
12
12
|
import { NotFoundContainer } from '../components/SwapsGroup/SwapsGroup.styles';
|
|
13
|
-
import { useUiStore } from '../store/ui';
|
|
14
13
|
import { groupSwapsByDate } from '../utils/date';
|
|
15
14
|
import { containsText } from '../utils/numbers';
|
|
16
15
|
import { getPendingSwaps } from '../utils/queue';
|
|
@@ -38,7 +37,6 @@ const isStepContainsText = (steps: PendingSwapStep[], value: string) => {
|
|
|
38
37
|
};
|
|
39
38
|
|
|
40
39
|
export function HistoryPage() {
|
|
41
|
-
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
42
40
|
const navigate = useNavigate();
|
|
43
41
|
const { manager, state } = useManager();
|
|
44
42
|
const list: PendingSwap[] = getPendingSwaps(manager).map(({ swap }) => swap);
|
|
@@ -94,10 +92,7 @@ export function HistoryPage() {
|
|
|
94
92
|
{!isEmpty && (
|
|
95
93
|
<SwapsGroup
|
|
96
94
|
list={filteredList}
|
|
97
|
-
onSwapClick={
|
|
98
|
-
setSelectedSwap(requestId);
|
|
99
|
-
navigate(requestId);
|
|
100
|
-
}}
|
|
95
|
+
onSwapClick={navigate}
|
|
101
96
|
groupBy={groupSwapsByDate}
|
|
102
97
|
isLoading={loading}
|
|
103
98
|
/>
|
package/src/pages/Home.tsx
CHANGED
|
@@ -21,7 +21,6 @@ import { QuoteInfo } from '../containers/QuoteInfo';
|
|
|
21
21
|
import { useSwapInput } from '../hooks/useSwapInput';
|
|
22
22
|
import { useAppStore } from '../store/AppStore';
|
|
23
23
|
import { useQuoteStore } from '../store/quote';
|
|
24
|
-
import { useUiStore } from '../store/ui';
|
|
25
24
|
import { useWalletsStore } from '../store/wallets';
|
|
26
25
|
import { getContainer } from '../utils/common';
|
|
27
26
|
import { formatTooltipNumbers, numberToString } from '../utils/numbers';
|
|
@@ -43,7 +42,7 @@ export function Home() {
|
|
|
43
42
|
const navigate = useNavigate();
|
|
44
43
|
const {
|
|
45
44
|
fetch: fetchQuote,
|
|
46
|
-
loading
|
|
45
|
+
loading,
|
|
47
46
|
error: quoteError,
|
|
48
47
|
warning: quoteWarning,
|
|
49
48
|
} = useSwapInput();
|
|
@@ -65,7 +64,6 @@ export function Home() {
|
|
|
65
64
|
const fetchMetaStatus = useAppStore().fetchStatus;
|
|
66
65
|
|
|
67
66
|
const { connectedWallets, getBalanceFor } = useWalletsStore();
|
|
68
|
-
const setCurrentPage = useUiStore.use.setCurrentPage();
|
|
69
67
|
const [showQuoteWarningModal, setShowQuoteWarningModal] = useState(false);
|
|
70
68
|
const fetchingBalance =
|
|
71
69
|
!!fromBlockchain &&
|
|
@@ -87,7 +85,7 @@ export function Home() {
|
|
|
87
85
|
|
|
88
86
|
const swapButtonState = getSwapButtonState({
|
|
89
87
|
fetchMetaStatus,
|
|
90
|
-
fetchingQuote,
|
|
88
|
+
fetchingQuote: loading,
|
|
91
89
|
inputAmount,
|
|
92
90
|
quote,
|
|
93
91
|
anyWalletConnected: connectedWallets.length > 0,
|
|
@@ -106,10 +104,15 @@ export function Home() {
|
|
|
106
104
|
? numberToString(fromTokenBalance?.amount, fromTokenBalance?.decimals)
|
|
107
105
|
: '0';
|
|
108
106
|
|
|
107
|
+
const fetchingQuote =
|
|
108
|
+
fetchMetaStatus === 'success' &&
|
|
109
|
+
!!inputAmount &&
|
|
110
|
+
!!fromToken &&
|
|
111
|
+
!!toToken &&
|
|
112
|
+
loading;
|
|
113
|
+
|
|
109
114
|
useEffect(() => {
|
|
110
|
-
setCurrentPage(navigationRoutes.home);
|
|
111
115
|
resetQuoteWallets();
|
|
112
|
-
return setCurrentPage.bind(null, '');
|
|
113
116
|
}, []);
|
|
114
117
|
|
|
115
118
|
const percentageChange =
|
|
@@ -1,27 +1,41 @@
|
|
|
1
|
+
import { i18n } from '@lingui/core';
|
|
1
2
|
import { cancelSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
2
3
|
import { useManager } from '@rango-dev/queue-manager-react';
|
|
4
|
+
import { Alert } from '@rango-dev/ui';
|
|
3
5
|
import React from 'react';
|
|
6
|
+
import { useParams } from 'react-router-dom';
|
|
4
7
|
|
|
5
8
|
import { SwapDetails } from '../components/SwapDetails';
|
|
6
9
|
import { SwapDetailsPlaceholder } from '../components/SwapDetails/SwapDetails.Placeholder';
|
|
7
10
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
8
11
|
import { useAppStore } from '../store/AppStore';
|
|
9
|
-
import { useUiStore } from '../store/ui';
|
|
10
12
|
import { getPendingSwaps } from '../utils/queue';
|
|
11
13
|
|
|
12
14
|
export function SwapDetailsPage() {
|
|
13
15
|
const { manager, state } = useManager();
|
|
14
16
|
const loading = !state.loadedFromPersistor;
|
|
15
17
|
const pendingSwaps = getPendingSwaps(manager);
|
|
16
|
-
const requestId =
|
|
18
|
+
const { requestId } = useParams<{ requestId: string }>();
|
|
17
19
|
const navigateBack = useNavigateBack();
|
|
18
20
|
const { fetchStatus: fetchMetaStatus } = useAppStore();
|
|
19
21
|
|
|
22
|
+
if (!requestId) {
|
|
23
|
+
return (
|
|
24
|
+
<Alert
|
|
25
|
+
containerStyles={{ margin: '20px' }}
|
|
26
|
+
type="error"
|
|
27
|
+
title={i18n.t(
|
|
28
|
+
'The request ID is necessary to display the swap details.'
|
|
29
|
+
)}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
20
34
|
const showSkeleton = loading || fetchMetaStatus === 'loading';
|
|
21
35
|
|
|
22
|
-
const selectedSwap =
|
|
23
|
-
({ swap }) => swap.requestId === requestId
|
|
24
|
-
|
|
36
|
+
const selectedSwap = requestId
|
|
37
|
+
? pendingSwaps.find(({ swap }) => swap.requestId === requestId)
|
|
38
|
+
: undefined;
|
|
25
39
|
|
|
26
40
|
const onCancel = () => {
|
|
27
41
|
if (selectedSwap?.id) {
|
|
@@ -47,7 +61,7 @@ export function SwapDetailsPage() {
|
|
|
47
61
|
if (!swap || showSkeleton) {
|
|
48
62
|
return (
|
|
49
63
|
<SwapDetailsPlaceholder
|
|
50
|
-
requestId={requestId
|
|
64
|
+
requestId={requestId}
|
|
51
65
|
showSkeleton={showSkeleton}
|
|
52
66
|
/>
|
|
53
67
|
);
|
|
@@ -56,7 +70,7 @@ export function SwapDetailsPage() {
|
|
|
56
70
|
return (
|
|
57
71
|
<SwapDetails
|
|
58
72
|
swap={swap}
|
|
59
|
-
requestId={requestId
|
|
73
|
+
requestId={requestId}
|
|
60
74
|
onCancel={onCancel}
|
|
61
75
|
onDelete={onDelete}
|
|
62
76
|
/>
|
package/src/utils/quote.ts
CHANGED
|
@@ -35,33 +35,6 @@ import {
|
|
|
35
35
|
hasProperSlippage,
|
|
36
36
|
} from './swap';
|
|
37
37
|
|
|
38
|
-
export function searchParamsToToken(
|
|
39
|
-
tokens: Token[],
|
|
40
|
-
searchParams: string | null,
|
|
41
|
-
chain: BlockchainMeta | null
|
|
42
|
-
): Token | null {
|
|
43
|
-
if (!chain) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
return (
|
|
47
|
-
tokens.find((token) => {
|
|
48
|
-
const symbolAndAddress = searchParams?.split('--');
|
|
49
|
-
if (symbolAndAddress?.length === 1) {
|
|
50
|
-
return (
|
|
51
|
-
token.symbol === symbolAndAddress[0] &&
|
|
52
|
-
token.address === null &&
|
|
53
|
-
token.blockchain === chain.name
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
return (
|
|
57
|
-
token.symbol === symbolAndAddress?.[0] &&
|
|
58
|
-
token.address === symbolAndAddress?.[1] &&
|
|
59
|
-
token.blockchain === chain.name
|
|
60
|
-
);
|
|
61
|
-
}) || null
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
38
|
export function getQuoteToTokenUsdPrice(
|
|
66
39
|
quote: BestRouteResponse | null
|
|
67
40
|
): number | null | undefined {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UpdateUrl.d.ts","sourceRoot":"","sources":["../../src/components/UpdateUrl.tsx"],"names":[],"mappings":"AAcA,wBAAgB,SAAS,SA+IxB"}
|