@rango-dev/widget-embedded 0.1.10-next.84 → 0.1.10-next.86

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 (43) hide show
  1. package/dist/App.d.ts.map +1 -1
  2. package/dist/QueueManager.d.ts +4 -0
  3. package/dist/QueueManager.d.ts.map +1 -0
  4. package/dist/components/AppRoutes.d.ts.map +1 -1
  5. package/dist/components/HeaderButtons.d.ts.map +1 -1
  6. package/dist/components/UpdateUrl.d.ts.map +1 -1
  7. package/dist/constants/navigationRoutes.d.ts +1 -1
  8. package/dist/hooks/useCopyToClipboard.d.ts +2 -0
  9. package/dist/hooks/useCopyToClipboard.d.ts.map +1 -0
  10. package/dist/hooks/useNavigateBack.d.ts.map +1 -1
  11. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  12. package/dist/pages/ConfirmWalletsPage.d.ts.map +1 -1
  13. package/dist/pages/HistoryPage.d.ts +0 -2
  14. package/dist/pages/HistoryPage.d.ts.map +1 -1
  15. package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
  16. package/dist/store/confirmSwap.d.ts +2 -1
  17. package/dist/store/confirmSwap.d.ts.map +1 -1
  18. package/dist/store/ui.d.ts.map +1 -1
  19. package/dist/utils/queue.d.ts +4 -0
  20. package/dist/utils/queue.d.ts.map +1 -0
  21. package/dist/widget-embedded.cjs.development.js +154 -1132
  22. package/dist/widget-embedded.cjs.development.js.map +1 -1
  23. package/dist/widget-embedded.cjs.production.min.js +154 -1132
  24. package/dist/widget-embedded.cjs.production.min.js.map +1 -1
  25. package/dist/widget-embedded.esm.js +155 -1133
  26. package/dist/widget-embedded.esm.js.map +1 -1
  27. package/package.json +9 -4
  28. package/src/App.tsx +35 -12
  29. package/src/QueueManager.tsx +93 -0
  30. package/src/components/AppRoutes.tsx +5 -2
  31. package/src/components/HeaderButtons.tsx +17 -4
  32. package/src/components/UpdateUrl.tsx +15 -11
  33. package/src/constants/navigationRoutes.ts +2 -2
  34. package/src/hooks/useCopyToClipboard.ts +23 -0
  35. package/src/hooks/useNavigateBack.ts +7 -4
  36. package/src/pages/ConfirmSwapPage.tsx +17 -4
  37. package/src/pages/ConfirmWalletsPage.tsx +3 -1
  38. package/src/pages/HistoryPage.tsx +15 -822
  39. package/src/pages/Home.tsx +1 -1
  40. package/src/pages/SwapDetailsPage.tsx +21 -3
  41. package/src/store/confirmSwap.ts +24 -9
  42. package/src/store/ui.ts +8 -2
  43. package/src/utils/queue.ts +24 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.1.10-next.84",
3
+ "version": "0.1.10-next.86",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -10,7 +10,7 @@
10
10
  ],
11
11
  "browserslist": "> 0.5%, last 2 versions, not dead",
12
12
  "scripts": {
13
- "dev": "parcel public/index.html -p 3000",
13
+ "dev": "parcel public/index.html -p 3001",
14
14
  "build:app": "parcel build",
15
15
  "build": "tsdx build --entry ./src/lib.tsx --transpileOnly"
16
16
  },
@@ -26,14 +26,19 @@
26
26
  "trailingComma": "es5"
27
27
  },
28
28
  "dependencies": {
29
- "@rango-dev/provider-all": "^0.1.11-next.76",
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",
30
33
  "@rango-dev/ui": "^0.1.10-next.75",
31
34
  "@rango-dev/wallets-core": "^0.1.11-next.77",
32
35
  "bignumber.js": "^9.1.1",
36
+ "copy-to-clipboard": "^3.3.3",
33
37
  "immer": "^9.0.19",
34
38
  "mitt": "^3.0.0",
35
39
  "parcel": "^2.8.0",
36
- "rango-sdk": "^0.1.17",
40
+ "rango-sdk": "^0.1.18",
41
+ "rango-types": "^0.1.22",
37
42
  "react": "^18.2.0",
38
43
  "react-dom": "^18.2.0",
39
44
  "react-router-dom": "^6.8.0",
package/src/App.tsx CHANGED
@@ -1,5 +1,11 @@
1
- import { SwapContainer } from '@rango-dev/ui';
2
- import React from 'react';
1
+ import {
2
+ SwapContainer,
3
+ Alert,
4
+ Button,
5
+ Typography,
6
+ Drawer,
7
+ } from '@rango-dev/ui';
8
+ import React, { useState } from 'react';
3
9
  import { AppRouter } from './components/AppRouter';
4
10
  import { useMetaStore } from './store/meta';
5
11
  import './app.css';
@@ -7,11 +13,15 @@ import { Events, Provider } from '@rango-dev/wallets-core';
7
13
  import { allProviders } from '@rango-dev/provider-all';
8
14
  import { EventHandler } from '@rango-dev/wallets-core/dist/wallet';
9
15
  import { Network } from '@rango-dev/wallets-shared';
10
- import { prepareAccountsForWalletStore, walletAndSupportedChainsNames } from './utils/wallets';
16
+ import {
17
+ prepareAccountsForWalletStore,
18
+ walletAndSupportedChainsNames,
19
+ } from './utils/wallets';
11
20
  import { useWalletsStore } from './store/wallets';
12
21
  import { Layout } from './components/Layout';
13
22
  import { globalStyles } from './globalStyles';
14
23
  import { useTheme } from './hooks/useTheme';
24
+ import QueueManager from './QueueManager';
15
25
  import { isEvmBlockchain } from 'rango-sdk';
16
26
 
17
27
  const providers = allProviders();
@@ -40,11 +50,18 @@ export function App() {
40
50
  const { blockchains } = useMetaStore.use.meta();
41
51
  const disconnectWallet = useWalletsStore.use.disconnectWallet();
42
52
  const connectWallet = useWalletsStore.use.connectWallet();
53
+
43
54
  const evmBasedChainNames = blockchains
44
55
  .filter(isEvmBlockchain)
45
56
  .map((chain) => chain.name);
46
57
 
47
- const onUpdateState: EventHandler = (type, event, value, state, supportedChains) => {
58
+ const onUpdateState: EventHandler = (
59
+ type,
60
+ event,
61
+ value,
62
+ state,
63
+ supportedChains
64
+ ) => {
48
65
  if (event === Events.ACCOUNTS) {
49
66
  if (value) {
50
67
  const supportedChainNames: Network[] | null =
@@ -54,7 +71,7 @@ export function App() {
54
71
  type,
55
72
  value,
56
73
  evmBasedChainNames,
57
- supportedChainNames,
74
+ supportedChainNames
58
75
  );
59
76
  connectWallet(data);
60
77
  } else {
@@ -62,16 +79,22 @@ export function App() {
62
79
  }
63
80
  }
64
81
  };
65
-
82
+
66
83
  return (
67
84
  //@ts-ignore
68
- <Provider allBlockChains={blockchains} providers={providers} onUpdateState={onUpdateState}>
85
+ <Provider
86
+ allBlockChains={blockchains}
87
+ providers={providers}
88
+ onUpdateState={onUpdateState}
89
+ >
69
90
  <div id="pageContainer" className={activeTheme}>
70
- <SwapContainer>
71
- <AppRouter>
72
- <Layout />
73
- </AppRouter>
74
- </SwapContainer>
91
+ <QueueManager>
92
+ <SwapContainer>
93
+ <AppRouter>
94
+ <Layout />
95
+ </AppRouter>
96
+ </SwapContainer>
97
+ </QueueManager>
75
98
  </div>
76
99
  </Provider>
77
100
  );
@@ -0,0 +1,93 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+ import { Provider as ManagerProvider } from '@rango-dev/queue-manager-react';
3
+ import {
4
+ swapQueueDef,
5
+ SwapQueueContext,
6
+ } from '@rango-dev/queue-manager-rango-preset';
7
+ import { useWallets } from '@rango-dev/wallets-core';
8
+ import {
9
+ convertEvmBlockchainMetaToEvmChainInfo,
10
+ Network,
11
+ WalletType,
12
+ } from '@rango-dev/wallets-shared';
13
+ import { useMetaStore } from './store/meta';
14
+ import { useWalletsStore } from './store/wallets';
15
+ import { walletAndSupportedChainsNames } from './utils/wallets';
16
+ import { isEvmBlockchain } from 'rango-sdk';
17
+
18
+ function QueueManager(props: PropsWithChildren<{}>) {
19
+ const {
20
+ providers,
21
+ getSigners,
22
+ state,
23
+ connect,
24
+ canSwitchNetworkTo,
25
+ getWalletInfo,
26
+ } = useWallets();
27
+
28
+ const { blockchains } = useMetaStore.use.meta();
29
+ const balances = useWalletsStore.use.balances();
30
+
31
+ const wallets = {
32
+ blockchains: balances.map((wallet) => ({
33
+ accounts: [wallet],
34
+ name: wallet.chain,
35
+ })),
36
+ };
37
+
38
+ const switchNetwork = (wallet: WalletType, network: Network) => {
39
+ if (!canSwitchNetworkTo(wallet, network)) {
40
+ return undefined;
41
+ }
42
+ return connect(wallet, network);
43
+ };
44
+
45
+ // TODO: this code copy & pasted from rango, should be refactored.
46
+ const allBlockchains = blockchains
47
+ .filter((blockchain) => blockchain.enabled)
48
+ .reduce(
49
+ (blockchainsObj, blockchain) => (
50
+ (blockchainsObj[blockchain.name] = blockchain), blockchainsObj
51
+ ),
52
+ {}
53
+ );
54
+ const evmBasedChains = blockchains.filter(isEvmBlockchain);
55
+ const getSupportedChainNames = (type: WalletType) => {
56
+ const { supportedChains } = getWalletInfo(type);
57
+ return walletAndSupportedChainsNames(supportedChains);
58
+ };
59
+ const allProviders = providers();
60
+ const context: SwapQueueContext = {
61
+ meta: {
62
+ blockchains: allBlockchains,
63
+ evmBasedChains: evmBasedChains,
64
+ evmNetworkChainInfo:
65
+ convertEvmBlockchainMetaToEvmChainInfo(evmBasedChains),
66
+ getSupportedChainNames,
67
+ },
68
+ getSigners,
69
+ //todo: remove Network type
70
+ //@ts-ignore
71
+ wallets,
72
+ providers: allProviders,
73
+ switchNetwork,
74
+ connect,
75
+ state,
76
+ notifier: (message) => {
77
+ console.log('[notifier]', message);
78
+ },
79
+ };
80
+
81
+ return (
82
+ <ManagerProvider
83
+ queuesDefs={[swapQueueDef]}
84
+ context={context}
85
+ onPersistedDataLoaded={(_manager) => {}}
86
+ isPaused={false}
87
+ >
88
+ {props.children}
89
+ </ManagerProvider>
90
+ );
91
+ }
92
+
93
+ export default QueueManager;
@@ -30,9 +30,12 @@ export const AppRoutes = () =>
30
30
  path: navigationRoutes.liquiditySources,
31
31
  element: <LiquiditySourcePage />,
32
32
  },
33
- { path: navigationRoutes.history, element: <HistoryPage /> },
33
+ { path: navigationRoutes.swaps, element: <HistoryPage /> },
34
+ {
35
+ path: navigationRoutes.swapDetails,
36
+ element: <SwapDetailsPage />,
37
+ },
34
38
  { path: navigationRoutes.wallets, element: <WalletsPage /> },
35
39
  { path: navigationRoutes.confirmSwap, element: <ConfirmSwapPage /> },
36
40
  { path: navigationRoutes.confirmWallets, element: <ConfirmWalletsPage /> },
37
- { path: navigationRoutes.swapDetails, element: <SwapDetailsPage /> },
38
41
  ]);
@@ -1,5 +1,12 @@
1
1
  import React from 'react';
2
- import { SettingsIcon, Tooltip, styled, Button, HistoryIcon, RetryIcon } from '@rango-dev/ui';
2
+ import {
3
+ SettingsIcon,
4
+ Tooltip,
5
+ styled,
6
+ Button,
7
+ HistoryIcon,
8
+ RetryIcon,
9
+ } from '@rango-dev/ui';
3
10
  import { useNavigate } from 'react-router-dom';
4
11
  import { navigationRoutes } from '../constants/navigationRoutes';
5
12
  import { PropTypes } from './Header';
@@ -15,17 +22,23 @@ export function HeaderButtons(props: PropTypes) {
15
22
  return (
16
23
  <ButtonsContainer>
17
24
  <Tooltip content="Retry">
18
- <Button variant="ghost" onClick={onClickRefresh.bind(null)}>
25
+ <Button variant="ghost" onClick={onClickRefresh}>
19
26
  <RetryIcon size={28} />
20
27
  </Button>
21
28
  </Tooltip>
22
29
  <Tooltip content="Transactions History">
23
- <Button variant="ghost" onClick={() => navigate(navigationRoutes.history)}>
30
+ <Button
31
+ variant="ghost"
32
+ onClick={() => navigate(navigationRoutes.swaps)}
33
+ >
24
34
  <HistoryIcon size={24} />
25
35
  </Button>
26
36
  </Tooltip>
27
37
  <Tooltip content="Settings">
28
- <Button variant="ghost" onClick={() => navigate(navigationRoutes.settings)}>
38
+ <Button
39
+ variant="ghost"
40
+ onClick={() => navigate(navigationRoutes.settings)}
41
+ >
29
42
  <SettingsIcon size={24} />
30
43
  </Button>
31
44
  </Tooltip>
@@ -9,6 +9,7 @@ import { useBestRouteStore } from '../store/bestRoute';
9
9
  import { useMetaStore } from '../store/meta';
10
10
  import { SearchParams } from '../constants/searchParams';
11
11
  import { navigationRoutes } from '../constants/navigationRoutes';
12
+ import { useUiStore } from '../store/ui';
12
13
 
13
14
  function searchParamsToToken(
14
15
  tokens: Token[],
@@ -33,17 +34,6 @@ export function UpdateUrl() {
33
34
  const location = useLocation();
34
35
  const firstRenderSearchParams = useRef(location.search);
35
36
  const searchParamsRef = useRef<Record<string, string>>({});
36
-
37
- useEffect(() => {
38
- const params: Record<string, string> = {};
39
- createSearchParams(firstRenderSearchParams.current).forEach(
40
- (value, key) => {
41
- params[key] = value;
42
- }
43
- );
44
- searchParamsRef.current = params;
45
- }, []);
46
-
47
37
  const fromChain = useBestRouteStore.use.fromChain();
48
38
  const toChain = useBestRouteStore.use.toChain();
49
39
  const fromToken = useBestRouteStore.use.fromToken();
@@ -56,6 +46,20 @@ export function UpdateUrl() {
56
46
  const setInputAmount = useBestRouteStore.use.setInputAmount();
57
47
  const loadingStatus = useMetaStore.use.loadingStatus();
58
48
  const { blockchains, tokens } = useMetaStore.use.meta();
49
+ const setSelectedSwap = useUiStore.use.setSelectedSwap();
50
+
51
+ useEffect(() => {
52
+ const params: Record<string, string> = {};
53
+ createSearchParams(firstRenderSearchParams.current).forEach(
54
+ (value, key) => {
55
+ params[key] = value;
56
+ }
57
+ );
58
+ searchParamsRef.current = params;
59
+ const requestId =
60
+ location.pathname.split(navigationRoutes.swaps + '/')[1] || null;
61
+ if (requestId) setSelectedSwap(requestId);
62
+ }, []);
59
63
 
60
64
  useEffect(() => {
61
65
  let fromChainString = '',
@@ -6,9 +6,9 @@ export const navigationRoutes = {
6
6
  toToken: '/to-token',
7
7
  settings: '/settings',
8
8
  liquiditySources: '/settings/liquidity-sources',
9
- history: '/history',
9
+ swaps: '/swaps',
10
10
  wallets: '/wallets',
11
11
  confirmSwap: '/confirm-swap',
12
12
  confirmWallets: '/confirm-wallets',
13
- swapDetails: '/history/swap-details',
13
+ swapDetails: '/swaps/:requestId',
14
14
  };
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import copy from 'copy-to-clipboard';
3
+
4
+ export default function useCopyToClipboard(resetInterval?: number) {
5
+ const [isCopied, setCopied] = React.useState(false);
6
+
7
+ const handleCopy = React.useCallback((text: string | number) => {
8
+ copy(text.toString());
9
+ setCopied(true);
10
+ }, []);
11
+
12
+ React.useEffect(() => {
13
+ let timeout: NodeJS.Timeout;
14
+ if (isCopied && resetInterval) {
15
+ timeout = setTimeout(() => setCopied(false), resetInterval);
16
+ }
17
+ return () => {
18
+ clearTimeout(timeout);
19
+ };
20
+ }, [isCopied, resetInterval]);
21
+
22
+ return [isCopied, handleCopy] as const;
23
+ }
@@ -22,14 +22,17 @@ export function useNavigateBack() {
22
22
  navigationRoutes.toToken,
23
23
  navigationRoutes.settings,
24
24
  navigationRoutes.wallets,
25
- navigationRoutes.history,
25
+ navigationRoutes.swaps,
26
+ navigationRoutes.confirmWallets,
26
27
  ].includes(currentRoute)
27
28
  )
28
29
  navigate(navigationRoutes.home, { replace: true });
29
- else if (currentRoute === navigationRoutes.liquiditySources) {
30
+ else if (currentRoute === navigationRoutes.liquiditySources)
30
31
  navigate(navigationRoutes.settings, { replace: true });
31
- } else if (currentRoute === navigationRoutes.swapDetails)
32
- navigate(navigationRoutes.history, { replace: true });
32
+ else if (currentRoute === navigationRoutes.swapDetails)
33
+ navigate(navigationRoutes.swaps, { replace: true });
34
+ else if (currentRoute === navigationRoutes.confirmSwap)
35
+ navigate(navigationRoutes.confirmWallets, { replace: true });
33
36
  }
34
37
  };
35
38
 
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { useNavigate } from 'react-router-dom';
2
3
  import { ConfirmSwap } from '@rango-dev/ui';
3
4
  import { useBestRouteStore } from '../store/bestRoute';
4
5
  import { useSettingsStore } from '../store/settings';
@@ -8,25 +9,37 @@ import { navigationRoutes } from '../constants/navigationRoutes';
8
9
  import { confirmSwap, useConfirmSwapStore } from '../store/confirmSwap';
9
10
  import { ConfirmSwapErrors } from '../components/ConfirmSwapErrors';
10
11
  import { ConfirmSwapWarnings } from '../components/ConfirmSwapWarnings';
12
+ import { useManager } from '@rango-dev/queue-manager-react';
13
+ import { useUiStore } from '../store/ui';
11
14
 
12
15
  export function ConfirmSwapPage() {
16
+ const setSelectedSwap = useUiStore.use.setSelectedSwap();
13
17
  const { navigateBackFrom } = useNavigateBack();
18
+ const { manager } = useManager();
19
+ const navigate = useNavigate();
14
20
 
15
21
  const bestRoute = useBestRouteStore.use.bestRoute();
16
22
 
17
23
  const loading = useConfirmSwapStore.use.loading();
18
24
  const warnings = useConfirmSwapStore.use.warnings();
19
25
  const errors = useConfirmSwapStore.use.errors();
20
-
21
- console.log('loading:', loading, 'warnings:', warnings, 'errors:', errors);
22
-
23
26
  const slippage = useSettingsStore.use.slippage();
24
27
  const customSlippage = useSettingsStore.use.customSlippage();
25
28
  const selectedSlippage = customSlippage || slippage;
26
29
 
27
30
  return (
28
31
  <ConfirmSwap
29
- onConfirm={confirmSwap.bind(null)}
32
+ onConfirm={() => {
33
+ confirmSwap().then((swap) => {
34
+ if (swap) {
35
+ manager?.create('swap', { swapDetails: swap });
36
+ setSelectedSwap(swap.requestId);
37
+ navigate(navigationRoutes.swaps + `/${swap.requestId}`, {
38
+ replace: true,
39
+ });
40
+ }
41
+ });
42
+ }}
30
43
  onBack={navigateBackFrom.bind(null, navigationRoutes.confirmSwap)}
31
44
  bestRoute={bestRoute}
32
45
  loading={loading}
@@ -64,7 +64,9 @@ export function ConfirmWalletsPage() {
64
64
  swap={bestRoute!}
65
65
  fromAmount={fromAmount}
66
66
  toAmount={toAmount}
67
- onConfirm={navigate.bind(null, navigationRoutes.confirmSwap)}
67
+ onConfirm={() =>
68
+ navigate(navigationRoutes.confirmSwap, { replace: true })
69
+ }
68
70
  onChange={(wallet) => setSelectedWallet(wallet)}
69
71
  confirmDisabled={confirmDisabled}
70
72
  handleConnectChain={(wallet) => handleConnectChain(wallet)}