@rango-dev/widget-embedded 0.1.10-next.98 → 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 (110) 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/ChangeSlippageButton.d.ts.map +1 -1
  7. package/dist/components/HeaderButtons.d.ts +4 -1
  8. package/dist/components/HeaderButtons.d.ts.map +1 -1
  9. package/dist/components/Layout.d.ts.map +1 -1
  10. package/dist/components/RoutesOverview.d.ts +10 -0
  11. package/dist/components/RoutesOverview.d.ts.map +1 -0
  12. package/dist/components/SwapDetailsPlaceholder.d.ts +9 -0
  13. package/dist/components/SwapDetailsPlaceholder.d.ts.map +1 -0
  14. package/dist/components/TokenInfo.d.ts.map +1 -1
  15. package/dist/components/TokenPreview.d.ts +20 -0
  16. package/dist/components/TokenPreview.d.ts.map +1 -0
  17. package/dist/components/UpdateUrl.d.ts.map +1 -1
  18. package/dist/components/warnings/BalanceWarnings.d.ts.map +1 -1
  19. package/dist/components/warnings/HighSlippageWarning.d.ts.map +1 -1
  20. package/dist/components/warnings/MinRequiredSlippage.d.ts +1 -1
  21. package/dist/components/warnings/MinRequiredSlippage.d.ts.map +1 -1
  22. package/dist/constants/navigationRoutes.d.ts +0 -1
  23. package/dist/constants/navigationRoutes.d.ts.map +1 -1
  24. package/dist/globalStyles.d.ts.map +1 -1
  25. package/dist/hooks/useConfirmSwap.d.ts.map +1 -1
  26. package/dist/lib.d.ts.map +1 -1
  27. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  28. package/dist/pages/HistoryPage.d.ts.map +1 -1
  29. package/dist/pages/Home.d.ts.map +1 -1
  30. package/dist/pages/LiquiditySourcesPage.d.ts.map +1 -1
  31. package/dist/pages/SelectTokenPage.d.ts.map +1 -1
  32. package/dist/pages/SettingsPage.d.ts.map +1 -1
  33. package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
  34. package/dist/pages/WalletsPage.d.ts +1 -0
  35. package/dist/pages/WalletsPage.d.ts.map +1 -1
  36. package/dist/store/bestRoute.d.ts +2 -0
  37. package/dist/store/bestRoute.d.ts.map +1 -1
  38. package/dist/store/ui.d.ts.map +1 -1
  39. package/dist/store/wallets.d.ts +14 -0
  40. package/dist/store/wallets.d.ts.map +1 -1
  41. package/dist/types/routing.d.ts +1 -1
  42. package/dist/types/swap.d.ts +6 -0
  43. package/dist/types/swap.d.ts.map +1 -1
  44. package/dist/utils/common.d.ts +1 -0
  45. package/dist/utils/common.d.ts.map +1 -1
  46. package/dist/utils/date.d.ts +3 -0
  47. package/dist/utils/date.d.ts.map +1 -0
  48. package/dist/utils/routing.d.ts +1 -0
  49. package/dist/utils/routing.d.ts.map +1 -1
  50. package/dist/utils/swap.d.ts +18 -6
  51. package/dist/utils/swap.d.ts.map +1 -1
  52. package/dist/utils/time.d.ts +4 -0
  53. package/dist/utils/time.d.ts.map +1 -0
  54. package/dist/utils/wallets.d.ts +1 -1
  55. package/dist/utils/wallets.d.ts.map +1 -1
  56. package/dist/widget-embedded.cjs.development.js +1004 -418
  57. package/dist/widget-embedded.cjs.development.js.map +1 -1
  58. package/dist/widget-embedded.cjs.production.min.js +1004 -418
  59. package/dist/widget-embedded.cjs.production.min.js.map +1 -1
  60. package/dist/widget-embedded.esm.js +1008 -423
  61. package/dist/widget-embedded.esm.js.map +1 -1
  62. package/package.json +12 -11
  63. package/readme.md +1 -2
  64. package/src/App.tsx +30 -5
  65. package/src/QueueManager.tsx +5 -2
  66. package/src/components/AppRouter.tsx +24 -13
  67. package/src/components/AppRoutes.tsx +15 -12
  68. package/src/components/ChangeSlippageButton.tsx +4 -8
  69. package/src/components/HeaderButtons.tsx +11 -4
  70. package/src/components/Layout.tsx +37 -5
  71. package/src/components/RoutesOverview.tsx +60 -0
  72. package/src/components/SwapDetailsPlaceholder.tsx +32 -0
  73. package/src/components/TokenInfo.tsx +125 -77
  74. package/src/components/TokenPreview.tsx +178 -0
  75. package/src/components/UpdateUrl.tsx +1 -3
  76. package/src/components/warnings/BalanceWarnings.tsx +1 -0
  77. package/src/components/warnings/HighSlippageWarning.tsx +4 -7
  78. package/src/components/warnings/MinRequiredSlippage.tsx +9 -4
  79. package/src/constants/navigationRoutes.ts +0 -1
  80. package/src/globalStyles.ts +3 -2
  81. package/src/hooks/useConfirmSwap.ts +2 -1
  82. package/src/hooks/useNavigateBack.ts +3 -3
  83. package/src/hooks/useTheme.ts +9 -9
  84. package/src/languages/en.json +9 -8
  85. package/src/lib.tsx +25 -3
  86. package/src/pages/ConfirmSwapPage.tsx +128 -20
  87. package/src/pages/HistoryPage.tsx +4 -4
  88. package/src/pages/Home.tsx +51 -42
  89. package/src/pages/LiquiditySourcesPage.tsx +2 -0
  90. package/src/pages/SelectTokenPage.tsx +3 -1
  91. package/src/pages/SettingsPage.tsx +3 -0
  92. package/src/pages/SwapDetailsPage.tsx +142 -6
  93. package/src/pages/WalletsPage.tsx +49 -16
  94. package/src/store/bestRoute.ts +114 -17
  95. package/src/store/ui.ts +4 -0
  96. package/src/store/wallets.ts +4 -1
  97. package/src/types/routing.ts +1 -1
  98. package/src/types/swap.ts +7 -0
  99. package/src/utils/common.ts +14 -0
  100. package/src/utils/date.ts +62 -0
  101. package/src/utils/routing.ts +23 -13
  102. package/src/utils/swap.ts +113 -11
  103. package/src/utils/time.ts +52 -0
  104. package/src/utils/wallets.ts +13 -4
  105. package/dist/components/Header.d.ts +0 -10
  106. package/dist/components/Header.d.ts.map +0 -1
  107. package/dist/pages/ConfirmWalletsPage.d.ts +0 -3
  108. package/dist/pages/ConfirmWalletsPage.d.ts.map +0 -1
  109. package/src/components/Header.tsx +0 -37
  110. package/src/pages/ConfirmWalletsPage.tsx +0 -80
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.1.10-next.98",
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
  }
@@ -1,23 +1,19 @@
1
1
  import React from 'react';
2
- import { Button, styled } from '@rango-dev/ui';
2
+ import { Button } from '@rango-dev/ui';
3
3
  import { useNavigate } from 'react-router-dom';
4
4
  import { navigationRoutes } from '../constants/navigationRoutes';
5
5
 
6
- const StyledButton = styled(Button, {
7
- marginTop: '$8',
8
- });
9
-
10
6
  export function ChangeSlippageButton() {
11
7
  const navigate = useNavigate();
12
8
 
13
9
  return (
14
- <StyledButton
10
+ <Button
15
11
  type="primary"
16
- variant="contained"
12
+ variant="outlined"
17
13
  size="small"
18
14
  onClick={() => navigate(navigationRoutes.settings)}
19
15
  >
20
16
  Change Slippage
21
- </StyledButton>
17
+ </Button>
22
18
  );
23
19
  }
@@ -9,21 +9,28 @@ 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();
21
24
 
22
25
  return (
23
26
  <ButtonsContainer>
24
- <Tooltip content="Retry">
25
- <Button variant="ghost" onClick={onClickRefresh}>
26
- <RetryIcon size={28} />
27
+ <Tooltip content="Refresh">
28
+ <Button
29
+ variant="ghost"
30
+ onClick={onClickRefresh}
31
+ disabled={!onClickRefresh}
32
+ >
33
+ <RetryIcon size={24} />
27
34
  </Button>
28
35
  </Tooltip>
29
36
  <Tooltip content="Transactions History">
@@ -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,60 @@
1
+ import React from 'react';
2
+ import { styled } from '@rango-dev/ui';
3
+ import { BestRouteResponse } from 'rango-sdk';
4
+ import { ChevronRightIcon } from '@rango-dev/ui';
5
+ import { GasIcon } from '@rango-dev/ui';
6
+ import { Spacer } from '@rango-dev/ui';
7
+
8
+ export const Container = styled('div', {
9
+ display: 'flex',
10
+ alignItems: 'center',
11
+ justifyContent: 'space-between',
12
+ padding: '$8',
13
+ borderRadius: '$5',
14
+ backgroundColor: '$neutrals300',
15
+ color: '$neutrals800',
16
+ fontSize: '$12',
17
+
18
+ '.routes': {
19
+ display: 'flex',
20
+ alignItems: 'center',
21
+ },
22
+ '.fee': {
23
+ display: 'flex',
24
+ alignItems: 'center',
25
+ },
26
+ });
27
+
28
+ interface PropTypes {
29
+ routes: BestRouteResponse | null;
30
+ totalFee?: string;
31
+ }
32
+ function RoutesOverview(props: PropTypes) {
33
+ if (!props.routes) return null;
34
+
35
+ const swaps = props.routes.result?.swaps;
36
+ return (
37
+ <Container>
38
+ <div className="routes">
39
+ {swaps?.map((swap, idx) => {
40
+ const isLast = idx + 1 == swaps.length;
41
+ return (
42
+ <>
43
+ <div className="route">{swap.from.symbol}</div>
44
+ <ChevronRightIcon size={12} />
45
+ {isLast ? <div className="route">{swap.to.symbol}</div> : null}
46
+ </>
47
+ );
48
+ })}
49
+ </div>
50
+ {props.totalFee ? (
51
+ <div className="fee">
52
+ <GasIcon size={12} />
53
+ <Spacer size={4} />${props.totalFee}
54
+ </div>
55
+ ) : null}
56
+ </Container>
57
+ );
58
+ }
59
+
60
+ export default RoutesOverview;
@@ -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
+ }