@rango-dev/widget-embedded 0.1.10-next.100 → 0.1.10-next.106

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.
Files changed (64) hide show
  1. package/dist/App.d.ts.map +1 -1
  2. package/dist/QueueManager.d.ts.map +1 -1
  3. package/dist/components/AppRouter.d.ts +6 -1
  4. package/dist/components/AppRouter.d.ts.map +1 -1
  5. package/dist/components/AppRoutes.d.ts.map +1 -1
  6. package/dist/components/Layout.d.ts.map +1 -1
  7. package/dist/components/UpdateUrl.d.ts.map +1 -1
  8. package/dist/components/warnings/BalanceWarnings.d.ts.map +1 -1
  9. package/dist/components/warnings/MinRequiredSlippage.d.ts +1 -1
  10. package/dist/components/warnings/MinRequiredSlippage.d.ts.map +1 -1
  11. package/dist/constants/navigationRoutes.d.ts +0 -1
  12. package/dist/constants/navigationRoutes.d.ts.map +1 -1
  13. package/dist/hooks/useConfirmSwap.d.ts.map +1 -1
  14. package/dist/lib.d.ts.map +1 -1
  15. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  16. package/dist/pages/SelectTokenPage.d.ts.map +1 -1
  17. package/dist/pages/SwapDetailsPage.d.ts +1 -1
  18. package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
  19. package/dist/store/bestRoute.d.ts +3 -1
  20. package/dist/store/bestRoute.d.ts.map +1 -1
  21. package/dist/types/routing.d.ts +1 -1
  22. package/dist/types/swap.d.ts +6 -0
  23. package/dist/types/swap.d.ts.map +1 -1
  24. package/dist/utils/common.d.ts +1 -0
  25. package/dist/utils/common.d.ts.map +1 -1
  26. package/dist/utils/swap.d.ts +16 -5
  27. package/dist/utils/swap.d.ts.map +1 -1
  28. package/dist/utils/time.d.ts +4 -0
  29. package/dist/utils/time.d.ts.map +1 -0
  30. package/dist/utils/wallets.d.ts +1 -1
  31. package/dist/utils/wallets.d.ts.map +1 -1
  32. package/dist/widget-embedded.cjs.development.js +796 -600
  33. package/dist/widget-embedded.cjs.development.js.map +1 -1
  34. package/dist/widget-embedded.cjs.production.min.js +796 -600
  35. package/dist/widget-embedded.cjs.production.min.js.map +1 -1
  36. package/dist/widget-embedded.esm.js +805 -609
  37. package/dist/widget-embedded.esm.js.map +1 -1
  38. package/package.json +9 -9
  39. package/src/App.tsx +26 -4
  40. package/src/QueueManager.tsx +5 -2
  41. package/src/components/AppRouter.tsx +24 -13
  42. package/src/components/AppRoutes.tsx +0 -2
  43. package/src/components/Layout.tsx +13 -0
  44. package/src/components/UpdateUrl.tsx +1 -3
  45. package/src/components/warnings/BalanceWarnings.tsx +1 -0
  46. package/src/components/warnings/MinRequiredSlippage.tsx +9 -4
  47. package/src/constants/navigationRoutes.ts +0 -1
  48. package/src/hooks/useConfirmSwap.ts +2 -1
  49. package/src/hooks/useNavigateBack.ts +3 -3
  50. package/src/lib.tsx +25 -3
  51. package/src/pages/ConfirmSwapPage.tsx +121 -20
  52. package/src/pages/Home.tsx +1 -1
  53. package/src/pages/SelectTokenPage.tsx +0 -1
  54. package/src/pages/SwapDetailsPage.tsx +82 -5
  55. package/src/store/bestRoute.ts +75 -4
  56. package/src/types/routing.ts +1 -1
  57. package/src/types/swap.ts +7 -0
  58. package/src/utils/common.ts +14 -0
  59. package/src/utils/swap.ts +98 -9
  60. package/src/utils/time.ts +52 -0
  61. package/src/utils/wallets.ts +5 -2
  62. package/dist/pages/ConfirmWalletsPage.d.ts +0 -3
  63. package/dist/pages/ConfirmWalletsPage.d.ts.map +0 -1
  64. package/src/pages/ConfirmWalletsPage.tsx +0 -127
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.1.10-next.100",
3
+ "version": "0.1.10-next.106",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -26,13 +26,13 @@
26
26
  "trailingComma": "es5"
27
27
  },
28
28
  "dependencies": {
29
- "@rango-dev/provider-all": "^0.1.11-next.79",
30
- "@rango-dev/queue-manager-core": "^0.1.10-next.75",
31
- "@rango-dev/queue-manager-rango-preset": "^0.1.10-next.77",
32
- "@rango-dev/queue-manager-react": "^0.1.10-next.73",
29
+ "@rango-dev/provider-all": "^0.1.11-next.84",
30
+ "@rango-dev/queue-manager-core": "^0.1.10-next.82",
31
+ "@rango-dev/queue-manager-rango-preset": "^0.1.10-next.102",
32
+ "@rango-dev/queue-manager-react": "^0.1.10-next.76",
33
33
  "@rango-dev/ui": "^0.1.10-next.75",
34
- "@rango-dev/wallets-core": "^0.1.11-next.80",
35
- "@rango-dev/wallets-shared": "^0.1.11-next.78",
34
+ "@rango-dev/wallets-core": "^0.1.11-next.88",
35
+ "@rango-dev/wallets-shared": "^0.1.11-next.84",
36
36
  "bignumber.js": "^9.1.1",
37
37
  "copy-to-clipboard": "^3.3.3",
38
38
  "i18next": "^22.4.11",
@@ -41,8 +41,8 @@
41
41
  "immer": "^9.0.19",
42
42
  "mitt": "^3.0.0",
43
43
  "parcel": "^2.8.0",
44
- "rango-sdk": "^0.1.19",
45
- "rango-types": "^0.1.23",
44
+ "rango-sdk": "^0.1.23",
45
+ "rango-types": "^0.1.28",
46
46
  "react": "^18.2.0",
47
47
  "react-dom": "^18.2.0",
48
48
  "react-i18next": "^12.2.0",
package/src/App.tsx CHANGED
@@ -1,12 +1,12 @@
1
1
  import { SwapContainer } from '@rango-dev/ui';
2
- import React from 'react';
2
+ import React, { useState } from 'react';
3
3
  import { AppRouter } from './components/AppRouter';
4
4
  import { useMetaStore } from './store/meta';
5
5
  import './app.css';
6
6
  import { Events, Provider } from '@rango-dev/wallets-core';
7
7
  import { allProviders } from '@rango-dev/provider-all';
8
8
  import { EventHandler } from '@rango-dev/wallets-core/dist/wallet';
9
- import { Network } from '@rango-dev/wallets-shared';
9
+ import { Network, WalletType } from '@rango-dev/wallets-shared';
10
10
  import {
11
11
  prepareAccountsForWalletStore,
12
12
  walletAndSupportedChainsNames,
@@ -22,7 +22,6 @@ import './i18n';
22
22
 
23
23
  const providers = allProviders();
24
24
 
25
- //todo: update interface and update widget state based on WidgetProps change
26
25
  export type WidgetProps = {
27
26
  configs?: Configs;
28
27
  };
@@ -39,6 +38,10 @@ export function App({ configs }: WidgetProps) {
39
38
  const disconnectWallet = useWalletsStore.use.disconnectWallet();
40
39
  const connectWallet = useWalletsStore.use.connectWallet();
41
40
 
41
+ const [lastConnectedWalletWithNetwork, setLastConnectedWalletWithNetwork] =
42
+ useState<string>('');
43
+ const [disconnectedWallet, setDisconnectedWallet] = useState<WalletType>();
44
+
42
45
  const evmBasedChainNames = blockchains
43
46
  .filter(isEvmBlockchain)
44
47
  .map((chain) => chain.name);
@@ -47,7 +50,7 @@ export function App({ configs }: WidgetProps) {
47
50
  type,
48
51
  event,
49
52
  value,
50
- _,
53
+ state,
51
54
  supportedChains
52
55
  ) => {
53
56
  if (event === Events.ACCOUNTS) {
@@ -63,8 +66,22 @@ export function App({ configs }: WidgetProps) {
63
66
  connectWallet(data);
64
67
  } else {
65
68
  disconnectWallet(type);
69
+ setDisconnectedWallet(type);
66
70
  }
67
71
  }
72
+
73
+ if (event === Events.ACCOUNTS && state.connected) {
74
+ const key = `${type}-${state.network}-${value}`;
75
+
76
+ if (state.connected) {
77
+ setLastConnectedWalletWithNetwork(key);
78
+ }
79
+ }
80
+
81
+ if (event === Events.NETWORK && state.network) {
82
+ const key = `${type}-${state.network}`;
83
+ setLastConnectedWalletWithNetwork(key);
84
+ }
68
85
  };
69
86
 
70
87
  return (
@@ -80,6 +97,11 @@ export function App({ configs }: WidgetProps) {
80
97
  title={configs?.title}
81
98
  titleSize={configs?.titleSize}
82
99
  titleWeight={configs?.titleWeight}
100
+ lastConnectedWallet={lastConnectedWalletWithNetwork}
101
+ disconnectedWallet={disconnectedWallet}
102
+ clearDisconnectedWallet={() => {
103
+ setDisconnectedWallet(undefined);
104
+ }}
83
105
  >
84
106
  <Layout configs={configs} />
85
107
  </AppRouter>
@@ -3,6 +3,7 @@ import { Provider as ManagerProvider } from '@rango-dev/queue-manager-react';
3
3
  import {
4
4
  swapQueueDef,
5
5
  SwapQueueContext,
6
+ checkWaitingForNetworkChange,
6
7
  } from '@rango-dev/queue-manager-rango-preset';
7
8
  import { useWallets } from '@rango-dev/wallets-core';
8
9
  import {
@@ -62,7 +63,7 @@ function QueueManager(props: PropsWithChildren<{}>) {
62
63
  blockchains: allBlockchains,
63
64
  evmBasedChains: evmBasedChains,
64
65
  evmNetworkChainInfo:
65
- convertEvmBlockchainMetaToEvmChainInfo(evmBasedChains),
66
+ convertEvmBlockchainMetaToEvmChainInfo(evmBasedChains),
66
67
  getSupportedChainNames,
67
68
  },
68
69
  getSigners,
@@ -83,7 +84,9 @@ function QueueManager(props: PropsWithChildren<{}>) {
83
84
  //@ts-ignore
84
85
  queuesDefs={[swapQueueDef]}
85
86
  context={context}
86
- onPersistedDataLoaded={(_manager) => {}}
87
+ onPersistedDataLoaded={(manager) => {
88
+ checkWaitingForNetworkChange(manager);
89
+ }}
87
90
  isPaused={false}
88
91
  >
89
92
  {props.children}
@@ -5,9 +5,14 @@ import {
5
5
  useLocation,
6
6
  useNavigate,
7
7
  } from 'react-router';
8
+ import { useQueueManager } from '@rango-dev/queue-manager-rango-preset';
8
9
  import { navigationRoutes } from '../constants/navigationRoutes';
10
+ import { WalletType } from '@rango-dev/wallets-shared';
11
+ import { isEvmBlockchain } from 'rango-types';
9
12
  import { UpdateUrl } from './UpdateUrl';
10
13
  import { Home } from '../pages/Home';
14
+ import { useMetaStore } from '../store/meta';
15
+
11
16
  interface PropTypes {
12
17
  title?: string;
13
18
  titleSize?: number;
@@ -22,23 +27,13 @@ const Route: React.FC = ({
22
27
  const ref = useRef(true);
23
28
 
24
29
  useEffect(() => {
25
- if (
26
- [navigationRoutes.confirmWallets, navigationRoutes.confirmSwap].includes(
27
- location.pathname
28
- ) &&
29
- ref.current
30
- )
30
+ if (location.pathname === navigationRoutes.confirmSwap && ref.current)
31
31
  navigate(navigationRoutes.home + location.search, { state: 'redirect' });
32
32
 
33
33
  ref.current = false;
34
34
  }, []);
35
35
 
36
- if (
37
- [navigationRoutes.confirmWallets, navigationRoutes.confirmSwap].includes(
38
- location.pathname
39
- ) &&
40
- ref.current
41
- )
36
+ if (location.pathname === navigationRoutes.confirmSwap && ref.current)
42
37
  return <Home {...props} />;
43
38
 
44
39
  return <> {children}</>;
@@ -47,9 +42,25 @@ const Route: React.FC = ({
47
42
  export function AppRouter({
48
43
  children,
49
44
  ...props
50
- }: PropTypes & PropsWithChildren) {
45
+ }: PropTypes &
46
+ PropsWithChildren & {
47
+ lastConnectedWallet: string;
48
+ disconnectedWallet: WalletType | undefined;
49
+ clearDisconnectedWallet: () => void;
50
+ }) {
51
51
  const isRouterInContext = useInRouterContext();
52
52
  const Router = isRouterInContext ? Route : MemoryRouter;
53
+ const { blockchains } = useMetaStore.use.meta();
54
+
55
+ const evmChains = blockchains.filter(isEvmBlockchain);
56
+
57
+ useQueueManager({
58
+ lastConnectedWallet: props.lastConnectedWallet,
59
+ clearDisconnectedWallet: props.clearDisconnectedWallet,
60
+ disconnectedWallet: props.disconnectedWallet,
61
+ evmChains,
62
+ notifier: () => {},
63
+ });
53
64
 
54
65
  return (
55
66
  <>
@@ -9,7 +9,6 @@ import { SelectChainPage } from '../pages/SelectChainPage';
9
9
  import { SelectTokenPage } from '../pages/SelectTokenPage';
10
10
  import { SettingsPage } from '../pages/SettingsPage';
11
11
  import { WalletsPage } from '../pages/WalletsPage';
12
- import { ConfirmWalletsPage } from '../pages/ConfirmWalletsPage';
13
12
  import { SwapDetailsPage } from '../pages/SwapDetailsPage';
14
13
  import { Configs } from '../types';
15
14
 
@@ -100,6 +99,5 @@ export function AppRoutes(props: PropTypes) {
100
99
  ),
101
100
  },
102
101
  { path: navigationRoutes.confirmSwap, element: <ConfirmSwapPage /> },
103
- { path: navigationRoutes.confirmWallets, element: <ConfirmWalletsPage /> },
104
102
  ]);
105
103
  }
@@ -65,6 +65,19 @@ export function Layout({ configs }: LayoutProps) {
65
65
  setFromToken(configs?.fromToken || null);
66
66
  setFromChain(configs?.fromChain || null);
67
67
  }, [configs?.fromToken, configs?.fromChain]);
68
+
69
+ useEffect(() => {
70
+ setToChain(null);
71
+ setFromChain(null);
72
+ setFromToken(null);
73
+ setToToken(null);
74
+ }, [
75
+ configs?.fromChains,
76
+ configs?.toChains,
77
+ configs?.fromTokens,
78
+ configs?.toTokens,
79
+ ]);
80
+
68
81
  return (
69
82
  <>
70
83
  <Header>
@@ -52,9 +52,7 @@ export function UpdateUrl() {
52
52
  fromAmount = '';
53
53
  if (
54
54
  loadingStatus !== 'success' &&
55
- ![navigationRoutes.confirmWallets, navigationRoutes.confirmSwap].includes(
56
- location.pathname
57
- )
55
+ location.pathname != navigationRoutes.confirmSwap
58
56
  ) {
59
57
  fromChainString = searchParamsRef.current[SearchParams.FROM_CHAIN];
60
58
  fromTokenString = searchParamsRef.current[SearchParams.FROM_TOKEN];
@@ -23,6 +23,7 @@ const ListItem = styled('li', {
23
23
 
24
24
  const Message = styled(Typography, {
25
25
  display: 'block',
26
+ color: '$warning500 !important',
26
27
  });
27
28
 
28
29
  export function BalanceWarnings({ messages }: PropTypes) {
@@ -1,18 +1,23 @@
1
- import { Typography } from '@rango-dev/ui';
1
+ import { Spacer, Typography, styled } from '@rango-dev/ui';
2
2
  import React from 'react';
3
3
  import { ChangeSlippageButton } from '../ChangeSlippageButton';
4
4
 
5
5
  interface PropTypes {
6
- minRequiredSlippage: number | null;
6
+ minRequiredSlippage: string | null;
7
7
  }
8
8
 
9
+ const StyledMessage = styled(Typography, {
10
+ color: '$error500 !important',
11
+ });
12
+
9
13
  export function MinRequiredSlippage({ minRequiredSlippage }: PropTypes) {
10
14
  return (
11
- <Typography variant="body2">
15
+ <StyledMessage variant="body2">
12
16
  We recommend you to increase slippage to at least &nbsp;
13
17
  {minRequiredSlippage}
14
18
  &nbsp; for this route.
19
+ <Spacer size={8} direction="vertical" />
15
20
  <ChangeSlippageButton />
16
- </Typography>
21
+ </StyledMessage>
17
22
  );
18
23
  }
@@ -9,6 +9,5 @@ export const navigationRoutes = {
9
9
  swaps: '/swaps',
10
10
  wallets: '/wallets',
11
11
  confirmSwap: '/confirm-swap',
12
- confirmWallets: '/confirm-wallets',
13
12
  swapDetails: '/swaps/:requestId',
14
13
  };
@@ -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.confirmWallets,
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,98 @@
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 { useSettingsStore } from '../store/settings';
6
- import { ConfirmSwapExtraMessages } from '../components/warnings/ConfirmSwapExtraMessages';
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 { ConfirmSwapErrors } from '../components/ConfirmSwapErrors';
10
- import { ConfirmSwapWarnings } from '../components/ConfirmSwapWarnings';
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 { useMetaStore } from '../store/meta';
16
- import { getBestRouteWithCalculatedFees } from '../utils/routing';
32
+ import { ConfirmSwapErrors } from '../components/ConfirmSwapErrors';
33
+ import { ConfirmSwapWarnings } from '../components/ConfirmSwapWarnings';
34
+ import { ConfirmSwapExtraMessages } from '../components/warnings/ConfirmSwapExtraMessages';
17
35
 
18
36
  export function ConfirmSwapPage() {
19
- const setSelectedSwap = useUiStore.use.setSelectedSwap();
20
- const { navigateBackFrom } = useNavigateBack();
21
- const { manager } = useManager();
22
37
  const navigate = useNavigate();
23
-
38
+ const { navigateBackFrom } = useNavigateBack();
24
39
  const bestRoute = useBestRouteStore.use.bestRoute();
25
40
  const fetchingBestRoute = useBestRouteStore.use.loading();
26
- const { tokens } = useMetaStore.use.meta();
27
-
41
+ const setSelectedSwap = useUiStore.use.setSelectedSwap();
42
+ const { blockchains, tokens } = useMetaStore.use.meta();
43
+ const accounts = useWalletsStore.use.accounts();
44
+ const selectedWallets = useWalletsStore.use.selectedWallets();
45
+ const initSelectedWallets = useWalletsStore.use.initSelectedWallets();
46
+ const setSelectedWallet = useWalletsStore.use.setSelectedWallet();
28
47
  const slippage = useSettingsStore.use.slippage();
29
48
  const customSlippage = useSettingsStore.use.customSlippage();
30
- const selectedSlippage = customSlippage || slippage;
49
+
50
+ const { manager } = useManager();
31
51
  const { loading, errors, warnings, confirmSwap } = useConfirmSwap();
32
52
 
53
+ const selectedSlippage = customSlippage || slippage;
54
+
33
55
  const showHighSlippageWarning = !errors.find(
34
56
  (error) => error.type === ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE
35
57
  );
36
58
 
59
+ const { getWalletInfo, connect } = useWallets();
60
+ const confirmDisabled =
61
+ fetchingBestRoute ||
62
+ !requiredWallets(bestRoute).every((chain) =>
63
+ selectedWallets.map((wallet) => wallet.chain).includes(chain)
64
+ );
65
+
66
+ const firstStep = bestRoute?.result?.swaps[0];
67
+ const lastStep =
68
+ bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1];
69
+
70
+ const fromAmount = decimalNumber(firstStep?.fromAmount, 3);
71
+ const toAmount = decimalNumber(lastStep?.toAmount, 3);
72
+ useEffect(() => {
73
+ initSelectedWallets();
74
+ }, []);
75
+
76
+ const selectableWallets = getSelectableWallets(
77
+ accounts,
78
+ selectedWallets,
79
+ getWalletInfo
80
+ );
81
+
82
+ const handleConnectChain = (wallet: string) => {
83
+ const network = wallet as Network;
84
+ getKeplrCompatibleConnectedWallets(selectableWallets).forEach(
85
+ (compatibleWallet: WalletType) => connect?.(compatibleWallet, network)
86
+ );
87
+ };
88
+
89
+ const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
90
+
37
91
  return (
38
92
  <ConfirmSwap
93
+ requiredWallets={getRequiredChains(bestRoute)}
94
+ selectableWallets={selectableWallets}
95
+ onBack={navigateBackFrom.bind(null, navigationRoutes.confirmSwap)}
39
96
  onConfirm={() => {
40
97
  confirmSwap?.().then((swap) => {
41
98
  if (swap) {
@@ -51,8 +108,53 @@ export function ConfirmSwapPage() {
51
108
  }
52
109
  });
53
110
  }}
54
- onBack={navigateBackFrom.bind(null, navigationRoutes.confirmSwap)}
55
- bestRoute={getBestRouteWithCalculatedFees(bestRoute, tokens)}
111
+ onChange={(wallet) => setSelectedWallet(wallet)}
112
+ confirmDisabled={confirmDisabled}
113
+ handleConnectChain={(wallet) => handleConnectChain(wallet)}
114
+ isExperimentalChain={(wallet) =>
115
+ getKeplrCompatibleConnectedWallets(selectableWallets).length > 0
116
+ ? isExperimentalChain(blockchains, wallet)
117
+ : false
118
+ }
119
+ previewInputs={
120
+ <>
121
+ <TokenPreview
122
+ chain={{
123
+ displayName: firstStep?.from.blockchain || '',
124
+ logo: firstStep?.from.blockchainLogo || '',
125
+ }}
126
+ token={{
127
+ symbol: firstStep?.from.symbol || '',
128
+ image: firstStep?.from.logo || '',
129
+ }}
130
+ usdValue={calcOutputUsdValue(fromAmount, firstStep?.from.usdPrice)}
131
+ amount={fromAmount}
132
+ label={t('From')}
133
+ loadingStatus={'success'}
134
+ />
135
+ <Spacer size={12} direction="vertical" />
136
+ <TokenPreview
137
+ chain={{
138
+ displayName: lastStep?.to.blockchain || '',
139
+ logo: lastStep?.to.blockchainLogo || '',
140
+ }}
141
+ token={{
142
+ symbol: lastStep?.to.symbol || '',
143
+ image: lastStep?.to.logo || '',
144
+ }}
145
+ usdValue={calcOutputUsdValue(toAmount, lastStep?.to.usdPrice)}
146
+ amount={toAmount}
147
+ label={t('To')}
148
+ loadingStatus={'success'}
149
+ />
150
+ </>
151
+ }
152
+ previewRoutes={
153
+ <RoutesOverview
154
+ routes={bestRoute}
155
+ totalFee={numberToString(totalFeeInUsd, 0, 2)}
156
+ />
157
+ }
56
158
  loading={loading}
57
159
  errors={ConfirmSwapErrors(errors)}
58
160
  warnings={ConfirmSwapWarnings(warnings)}
@@ -66,7 +168,6 @@ export function ConfirmSwapPage() {
66
168
  ? 'Proceed anyway!'
67
169
  : 'Confirm swap!'
68
170
  }
69
- confirmButtonDisabled={fetchingBestRoute}
70
171
  />
71
172
  );
72
173
  }
@@ -215,7 +215,7 @@ export function Home(props: PropTypes) {
215
215
  if (swapButtonState.title === 'Connect Wallet')
216
216
  navigate(navigationRoutes.wallets);
217
217
  else {
218
- navigate(navigationRoutes.confirmWallets, { replace: true });
218
+ navigate(navigationRoutes.confirmSwap, { replace: true });
219
219
  }
220
220
  }}
221
221
  >
@@ -41,7 +41,6 @@ export function SelectTokenPage(props: PropTypes) {
41
41
  tokensAreEqual(supportedToken, token)
42
42
  )
43
43
  );
44
- console.log(supportedSourceTokens);
45
44
 
46
45
  const fromToken = useBestRouteStore.use.fromToken();
47
46
  const toToken = useBestRouteStore.use.toToken();