@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.
Files changed (99) 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/HeaderButtons.d.ts +4 -1
  7. package/dist/components/HeaderButtons.d.ts.map +1 -1
  8. package/dist/components/Layout.d.ts.map +1 -1
  9. package/dist/components/SwapDetailsPlaceholder.d.ts +9 -0
  10. package/dist/components/SwapDetailsPlaceholder.d.ts.map +1 -0
  11. package/dist/components/TokenPreview.d.ts +1 -1
  12. package/dist/components/TokenPreview.d.ts.map +1 -1
  13. package/dist/components/UpdateUrl.d.ts.map +1 -1
  14. package/dist/components/warnings/BalanceWarnings.d.ts.map +1 -1
  15. package/dist/components/warnings/MinRequiredSlippage.d.ts +1 -1
  16. package/dist/components/warnings/MinRequiredSlippage.d.ts.map +1 -1
  17. package/dist/constants/navigationRoutes.d.ts +0 -1
  18. package/dist/constants/navigationRoutes.d.ts.map +1 -1
  19. package/dist/globalStyles.d.ts.map +1 -1
  20. package/dist/hooks/useConfirmSwap.d.ts.map +1 -1
  21. package/dist/lib.d.ts.map +1 -1
  22. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  23. package/dist/pages/HistoryPage.d.ts.map +1 -1
  24. package/dist/pages/Home.d.ts.map +1 -1
  25. package/dist/pages/LiquiditySourcesPage.d.ts.map +1 -1
  26. package/dist/pages/SelectTokenPage.d.ts.map +1 -1
  27. package/dist/pages/SettingsPage.d.ts.map +1 -1
  28. package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
  29. package/dist/pages/WalletsPage.d.ts +1 -0
  30. package/dist/pages/WalletsPage.d.ts.map +1 -1
  31. package/dist/store/bestRoute.d.ts +2 -0
  32. package/dist/store/bestRoute.d.ts.map +1 -1
  33. package/dist/store/ui.d.ts.map +1 -1
  34. package/dist/store/wallets.d.ts +14 -0
  35. package/dist/store/wallets.d.ts.map +1 -1
  36. package/dist/types/routing.d.ts +1 -1
  37. package/dist/types/swap.d.ts +6 -0
  38. package/dist/types/swap.d.ts.map +1 -1
  39. package/dist/utils/common.d.ts +1 -0
  40. package/dist/utils/common.d.ts.map +1 -1
  41. package/dist/utils/date.d.ts +3 -0
  42. package/dist/utils/date.d.ts.map +1 -0
  43. package/dist/utils/routing.d.ts +1 -0
  44. package/dist/utils/routing.d.ts.map +1 -1
  45. package/dist/utils/swap.d.ts +16 -5
  46. package/dist/utils/swap.d.ts.map +1 -1
  47. package/dist/utils/time.d.ts +4 -0
  48. package/dist/utils/time.d.ts.map +1 -0
  49. package/dist/utils/wallets.d.ts +1 -1
  50. package/dist/utils/wallets.d.ts.map +1 -1
  51. package/dist/widget-embedded.cjs.development.js +1048 -705
  52. package/dist/widget-embedded.cjs.development.js.map +1 -1
  53. package/dist/widget-embedded.cjs.production.min.js +1048 -705
  54. package/dist/widget-embedded.cjs.production.min.js.map +1 -1
  55. package/dist/widget-embedded.esm.js +1057 -714
  56. package/dist/widget-embedded.esm.js.map +1 -1
  57. package/package.json +12 -11
  58. package/readme.md +1 -2
  59. package/src/App.tsx +30 -5
  60. package/src/QueueManager.tsx +5 -2
  61. package/src/components/AppRouter.tsx +24 -13
  62. package/src/components/AppRoutes.tsx +15 -12
  63. package/src/components/HeaderButtons.tsx +9 -2
  64. package/src/components/Layout.tsx +37 -5
  65. package/src/components/SwapDetailsPlaceholder.tsx +32 -0
  66. package/src/components/TokenPreview.tsx +7 -4
  67. package/src/components/UpdateUrl.tsx +1 -3
  68. package/src/components/warnings/BalanceWarnings.tsx +1 -0
  69. package/src/components/warnings/MinRequiredSlippage.tsx +9 -4
  70. package/src/constants/navigationRoutes.ts +0 -1
  71. package/src/globalStyles.ts +2 -1
  72. package/src/hooks/useConfirmSwap.ts +2 -1
  73. package/src/hooks/useNavigateBack.ts +3 -3
  74. package/src/lib.tsx +25 -3
  75. package/src/pages/ConfirmSwapPage.tsx +128 -20
  76. package/src/pages/HistoryPage.tsx +4 -4
  77. package/src/pages/Home.tsx +19 -8
  78. package/src/pages/LiquiditySourcesPage.tsx +2 -0
  79. package/src/pages/SelectTokenPage.tsx +3 -1
  80. package/src/pages/SettingsPage.tsx +3 -0
  81. package/src/pages/SwapDetailsPage.tsx +142 -6
  82. package/src/pages/WalletsPage.tsx +47 -11
  83. package/src/store/bestRoute.ts +110 -12
  84. package/src/store/ui.ts +4 -0
  85. package/src/store/wallets.ts +4 -1
  86. package/src/types/routing.ts +1 -1
  87. package/src/types/swap.ts +7 -0
  88. package/src/utils/common.ts +14 -0
  89. package/src/utils/date.ts +62 -0
  90. package/src/utils/routing.ts +23 -13
  91. package/src/utils/swap.ts +101 -10
  92. package/src/utils/time.ts +52 -0
  93. package/src/utils/wallets.ts +13 -4
  94. package/dist/components/Header.d.ts +0 -10
  95. package/dist/components/Header.d.ts.map +0 -1
  96. package/dist/pages/ConfirmWalletsPage.d.ts +0 -3
  97. package/dist/pages/ConfirmWalletsPage.d.ts.map +0 -1
  98. package/src/components/Header.tsx +0 -37
  99. 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.99",
3
+ "version": "0.1.10",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -10,8 +10,8 @@
10
10
  ],
11
11
  "browserslist": "> 0.5%, last 2 versions, not dead",
12
12
  "scripts": {
13
- "dev": "parcel public/index.html -p 3001",
14
- "build:app": "parcel build",
13
+ "dev": "parcel public/index.html -p 3001 --cache-dir=.parcel-cache",
14
+ "build:app": "parcel build --cache-dir=.parcel-cache",
15
15
  "build": "tsdx build --entry ./src/lib.tsx"
16
16
  },
17
17
  "husky": {
@@ -26,23 +26,24 @@
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
+ "dayjs": "^1.11.7",
38
39
  "i18next": "^22.4.11",
39
40
  "i18next-browser-languagedetector": "^7.0.1",
40
41
  "i18next-http-backend": "^2.1.1",
41
42
  "immer": "^9.0.19",
42
43
  "mitt": "^3.0.0",
43
44
  "parcel": "^2.8.0",
44
- "rango-sdk": "^0.1.19",
45
- "rango-types": "^0.1.23",
45
+ "rango-sdk": "^0.1.23",
46
+ "rango-types": "^0.1.28",
46
47
  "react": "^18.2.0",
47
48
  "react-dom": "^18.2.0",
48
49
  "react-i18next": "^12.2.0",
package/readme.md CHANGED
@@ -1,2 +1 @@
1
-
2
- Widget will use `components`, `queues` and `wallets` to make a react app to be embedded as widget.
1
+ # @rango-dev/widget-embedded
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,
@@ -19,10 +19,11 @@ import QueueManager from './QueueManager';
19
19
  import { isEvmBlockchain } from 'rango-sdk';
20
20
  import { Configs } from './types';
21
21
  import './i18n';
22
+ import { useUiStore } from './store/ui';
23
+ import { navigationRoutes } from './constants/navigationRoutes';
22
24
 
23
25
  const providers = allProviders();
24
26
 
25
- //todo: update interface and update widget state based on WidgetProps change
26
27
  export type WidgetProps = {
27
28
  configs?: Configs;
28
29
  };
@@ -38,6 +39,11 @@ export function App({ configs }: WidgetProps) {
38
39
  const { blockchains } = useMetaStore.use.meta();
39
40
  const disconnectWallet = useWalletsStore.use.disconnectWallet();
40
41
  const connectWallet = useWalletsStore.use.connectWallet();
42
+ const currentPage = useUiStore.use.currentPage();
43
+
44
+ const [lastConnectedWalletWithNetwork, setLastConnectedWalletWithNetwork] =
45
+ useState<string>('');
46
+ const [disconnectedWallet, setDisconnectedWallet] = useState<WalletType>();
41
47
 
42
48
  const evmBasedChainNames = blockchains
43
49
  .filter(isEvmBlockchain)
@@ -47,7 +53,7 @@ export function App({ configs }: WidgetProps) {
47
53
  type,
48
54
  event,
49
55
  value,
50
- _,
56
+ state,
51
57
  supportedChains
52
58
  ) => {
53
59
  if (event === Events.ACCOUNTS) {
@@ -63,8 +69,22 @@ export function App({ configs }: WidgetProps) {
63
69
  connectWallet(data);
64
70
  } else {
65
71
  disconnectWallet(type);
72
+ setDisconnectedWallet(type);
66
73
  }
67
74
  }
75
+
76
+ if (event === Events.ACCOUNTS && state.connected) {
77
+ const key = `${type}-${state.network}-${value}`;
78
+
79
+ if (state.connected) {
80
+ setLastConnectedWalletWithNetwork(key);
81
+ }
82
+ }
83
+
84
+ if (event === Events.NETWORK && state.network) {
85
+ const key = `${type}-${state.network}`;
86
+ setLastConnectedWalletWithNetwork(key);
87
+ }
68
88
  };
69
89
 
70
90
  return (
@@ -75,11 +95,16 @@ export function App({ configs }: WidgetProps) {
75
95
  >
76
96
  <div id="pageContainer" className={activeTheme}>
77
97
  <QueueManager>
78
- <SwapContainer>
98
+ <SwapContainer fixedHeight={currentPage != navigationRoutes.home}>
79
99
  <AppRouter
80
100
  title={configs?.title}
81
101
  titleSize={configs?.titleSize}
82
102
  titleWeight={configs?.titleWeight}
103
+ lastConnectedWallet={lastConnectedWalletWithNetwork}
104
+ disconnectedWallet={disconnectedWallet}
105
+ clearDisconnectedWallet={() => {
106
+ setDisconnectedWallet(undefined);
107
+ }}
83
108
  >
84
109
  <Layout configs={configs} />
85
110
  </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,10 +9,11 @@ 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
 
15
+ const getAbsolutePath = (path: string) => path.replace('/', '');
16
+
16
17
  interface PropTypes {
17
18
  configs?: Configs;
18
19
  }
@@ -22,7 +23,7 @@ export function AppRoutes(props: PropTypes) {
22
23
 
23
24
  return useRoutes([
24
25
  {
25
- path: navigationRoutes.home,
26
+ path: getAbsolutePath(navigationRoutes.home),
26
27
  element: (
27
28
  <Home
28
29
  title={configs?.title}
@@ -32,7 +33,7 @@ export function AppRoutes(props: PropTypes) {
32
33
  ),
33
34
  },
34
35
  {
35
- path: navigationRoutes.fromChain,
36
+ path: getAbsolutePath(navigationRoutes.fromChain),
36
37
  element: (
37
38
  <SelectChainPage
38
39
  type="from"
@@ -41,7 +42,7 @@ export function AppRoutes(props: PropTypes) {
41
42
  ),
42
43
  },
43
44
  {
44
- path: navigationRoutes.toChain,
45
+ path: getAbsolutePath(navigationRoutes.toChain),
45
46
  element: (
46
47
  <SelectChainPage
47
48
  type="to"
@@ -50,7 +51,7 @@ export function AppRoutes(props: PropTypes) {
50
51
  ),
51
52
  },
52
53
  {
53
- path: navigationRoutes.fromToken + '/*',
54
+ path: getAbsolutePath(navigationRoutes.fromToken),
54
55
  element: (
55
56
  <SelectTokenPage
56
57
  type="from"
@@ -59,7 +60,7 @@ export function AppRoutes(props: PropTypes) {
59
60
  ),
60
61
  },
61
62
  {
62
- path: navigationRoutes.toToken,
63
+ path: getAbsolutePath(navigationRoutes.toToken),
63
64
  element: (
64
65
  <SelectTokenPage
65
66
  type="to"
@@ -68,26 +69,26 @@ export function AppRoutes(props: PropTypes) {
68
69
  ),
69
70
  },
70
71
  {
71
- path: navigationRoutes.settings,
72
+ path: getAbsolutePath(navigationRoutes.settings),
72
73
  element: (
73
74
  <SettingsPage supportedSwappers={configs?.liquiditySources || 'all'} />
74
75
  ),
75
76
  },
76
77
  {
77
- path: navigationRoutes.liquiditySources,
78
+ path: getAbsolutePath(navigationRoutes.liquiditySources),
78
79
  element: (
79
80
  <LiquiditySourcePage
80
81
  supportedSwappers={configs?.liquiditySources || 'all'}
81
82
  />
82
83
  ),
83
84
  },
84
- { path: navigationRoutes.swaps, element: <HistoryPage /> },
85
+ { path: getAbsolutePath(navigationRoutes.swaps), element: <HistoryPage /> },
85
86
  {
86
87
  path: navigationRoutes.swapDetails,
87
88
  element: <SwapDetailsPage />,
88
89
  },
89
90
  {
90
- path: navigationRoutes.wallets,
91
+ path: getAbsolutePath(navigationRoutes.wallets),
91
92
  element: (
92
93
  <WalletsPage
93
94
  supportedWallets={configs?.wallets || 'all'}
@@ -99,7 +100,9 @@ export function AppRoutes(props: PropTypes) {
99
100
  />
100
101
  ),
101
102
  },
102
- { path: navigationRoutes.confirmSwap, element: <ConfirmSwapPage /> },
103
- { path: navigationRoutes.confirmWallets, element: <ConfirmWalletsPage /> },
103
+ {
104
+ path: getAbsolutePath(navigationRoutes.confirmSwap),
105
+ element: <ConfirmSwapPage />,
106
+ },
104
107
  ]);
105
108
  }
@@ -9,12 +9,15 @@ import {
9
9
  } from '@rango-dev/ui';
10
10
  import { useNavigate } from 'react-router-dom';
11
11
  import { navigationRoutes } from '../constants/navigationRoutes';
12
- import { PropTypes } from './Header';
13
12
 
14
13
  const ButtonsContainer = styled('div', {
15
14
  display: 'flex',
16
15
  });
17
16
 
17
+ interface PropTypes {
18
+ onClickRefresh?: () => void;
19
+ }
20
+
18
21
  export function HeaderButtons(props: PropTypes) {
19
22
  const { onClickRefresh } = props;
20
23
  const navigate = useNavigate();
@@ -22,7 +25,11 @@ export function HeaderButtons(props: PropTypes) {
22
25
  return (
23
26
  <ButtonsContainer>
24
27
  <Tooltip content="Refresh">
25
- <Button variant="ghost" onClick={onClickRefresh}>
28
+ <Button
29
+ variant="ghost"
30
+ onClick={onClickRefresh}
31
+ disabled={!onClickRefresh}
32
+ >
26
33
  <RetryIcon size={24} />
27
34
  </Button>
28
35
  </Tooltip>
@@ -1,11 +1,17 @@
1
- import { Button, AddWalletIcon, Typography, styled } from '@rango-dev/ui';
1
+ import {
2
+ Button,
3
+ AddWalletIcon,
4
+ Typography,
5
+ styled,
6
+ Spinner,
7
+ } from '@rango-dev/ui';
2
8
  import React, { useEffect } from 'react';
3
9
  import { useNavigate } from 'react-router-dom';
4
10
  import { useWallets } from '@rango-dev/wallets-core';
5
11
  import { navigationRoutes } from '../constants/navigationRoutes';
6
12
  import { useUiStore } from '../store/ui';
7
13
  import { AppRoutes } from './AppRoutes';
8
- import { useWalletsStore } from '../store/wallets';
14
+ import { fetchingBalanceSelector, useWalletsStore } from '../store/wallets';
9
15
  import {
10
16
  calculateWalletUsdValue,
11
17
  getSelectableWallets,
@@ -14,11 +20,15 @@ import { removeDuplicateFrom } from '../utils/common';
14
20
  import { Configs } from '../types';
15
21
  import { useTranslation } from 'react-i18next';
16
22
  import { useBestRouteStore } from '../store/bestRoute';
23
+ import { useMetaStore } from '../store/meta';
17
24
 
18
25
  const Header = styled('div', {
19
26
  display: 'flex',
20
27
  width: '100%',
21
28
  justifyContent: 'end',
29
+ '.balance': {
30
+ display: 'flex',
31
+ },
22
32
  });
23
33
 
24
34
  const WalletImage = styled('img', {
@@ -52,6 +62,9 @@ export function Layout({ configs }: LayoutProps) {
52
62
  const totalBalance = calculateWalletUsdValue(balances);
53
63
  const connectWalletsButtonDisabled =
54
64
  useUiStore.use.connectWalletsButtonDisabled();
65
+ const loadingMetaStatus = useMetaStore.use.loadingStatus();
66
+ const fetchingBalance = useWalletsStore(fetchingBalanceSelector);
67
+
55
68
  const { t } = useTranslation();
56
69
  useEffect(() => {
57
70
  setToChain(configs?.toChain || null);
@@ -65,6 +78,18 @@ export function Layout({ configs }: LayoutProps) {
65
78
  setFromToken(configs?.fromToken || null);
66
79
  setFromChain(configs?.fromChain || null);
67
80
  }, [configs?.fromToken, configs?.fromChain]);
81
+
82
+ useEffect(() => {
83
+ setToChain(null);
84
+ setFromChain(null);
85
+ setFromToken(null);
86
+ setToToken(null);
87
+ }, [
88
+ configs?.fromChains,
89
+ configs?.toChains,
90
+ configs?.fromTokens,
91
+ configs?.toTokens,
92
+ ]);
68
93
  return (
69
94
  <>
70
95
  <Header>
@@ -73,6 +98,8 @@ export function Layout({ configs }: LayoutProps) {
73
98
  suffix={<AddWalletIcon size={20} />}
74
99
  variant="ghost"
75
100
  flexContent
101
+ loading={loadingMetaStatus === 'loading'}
102
+ disabled={loadingMetaStatus === 'failed'}
76
103
  onClick={() => {
77
104
  if (!connectWalletsButtonDisabled)
78
105
  navigate(navigationRoutes.wallets);
@@ -85,9 +112,14 @@ export function Layout({ configs }: LayoutProps) {
85
112
  ) : (
86
113
  <></>
87
114
  )}
88
- <Typography variant="body2">
89
- {!accounts?.length ? t('Connect Wallet') : `$${totalBalance || 0}`}
90
- </Typography>
115
+ <div className="balance">
116
+ <Typography variant="body2">
117
+ {!accounts?.length
118
+ ? t('Connect Wallet')
119
+ : `$${totalBalance || 0}`}
120
+ </Typography>
121
+ {fetchingBalance && <Spinner />}
122
+ </div>
91
123
  </Button>
92
124
  </Header>
93
125
  <AppRoutes configs={configs} />
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import { SecondaryPage, Spinner, Alert, styled } from '@rango-dev/ui';
3
+ import { LoaderContainer } from '../pages/WalletsPage';
4
+
5
+ const PlaceholderContainer = styled('div', { height: '450px' });
6
+
7
+ interface PropTypes {
8
+ requestId: string;
9
+ loading: boolean;
10
+ onBack: () => void;
11
+ }
12
+
13
+ export function SwapDetailsPlaceholder(props: PropTypes) {
14
+ const { requestId, loading, onBack } = props;
15
+
16
+ return (
17
+ <SecondaryPage title="Swap Details" textField={false} onBack={onBack}>
18
+ <PlaceholderContainer>
19
+ {loading ? (
20
+ <LoaderContainer>
21
+ <Spinner size={24} />
22
+ </LoaderContainer>
23
+ ) : (
24
+ <Alert
25
+ type="secondary"
26
+ title={`Swap with request ID = ${requestId} not found.`}
27
+ />
28
+ )}
29
+ </PlaceholderContainer>
30
+ </SecondaryPage>
31
+ );
32
+ }
@@ -85,7 +85,7 @@ const OutputContainer = styled('div', {
85
85
  interface PropTypes {
86
86
  label: string;
87
87
  amount: string;
88
- usdValue: BigNumber;
88
+ usdValue?: BigNumber;
89
89
  loadingStatus: LoadingStatus;
90
90
  chain: {
91
91
  displayName: string;
@@ -120,9 +120,12 @@ export function TokenPreview(props: PropTypes) {
120
120
  <Typography variant="body2" color="neutrals800">
121
121
  {props.label}
122
122
  </Typography>
123
- <Typography variant="caption" color="neutrals600">{`$${numberToString(
124
- props.usdValue
125
- )}`}</Typography>
123
+ {props.usdValue && (
124
+ <Typography
125
+ variant="caption"
126
+ color="neutrals600"
127
+ >{`$${numberToString(props.usdValue)}`}</Typography>
128
+ )}
126
129
  </div>
127
130
  <div className="form">
128
131
  <Button
@@ -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
  };
@@ -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.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