@rango-dev/widget-embedded 0.1.13-next.0 → 0.1.13-next.5

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 (55) 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.map +1 -1
  4. package/dist/components/Layout.d.ts.map +1 -1
  5. package/dist/components/TokenInfo.d.ts.map +1 -1
  6. package/dist/components/TokenPreview.d.ts.map +1 -1
  7. package/dist/components/UpdateUrl.d.ts.map +1 -1
  8. package/dist/components/warnings/BalanceErrors.d.ts.map +1 -1
  9. package/dist/globalStyles.d.ts +0 -1
  10. package/dist/globalStyles.d.ts.map +1 -1
  11. package/dist/hooks/useNavigateBack.d.ts.map +1 -1
  12. package/dist/lib.d.ts +1 -1
  13. package/dist/lib.d.ts.map +1 -1
  14. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  15. package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
  16. package/dist/store/bestRoute.d.ts +1 -0
  17. package/dist/store/bestRoute.d.ts.map +1 -1
  18. package/dist/store/wallets.d.ts +1 -0
  19. package/dist/store/wallets.d.ts.map +1 -1
  20. package/dist/utils/numbers.d.ts +1 -2
  21. package/dist/utils/numbers.d.ts.map +1 -1
  22. package/dist/widget-embedded.cjs.development.js +1087 -1149
  23. package/dist/widget-embedded.cjs.development.js.map +1 -1
  24. package/dist/widget-embedded.cjs.production.min.js +1087 -1149
  25. package/dist/widget-embedded.cjs.production.min.js.map +1 -1
  26. package/dist/widget-embedded.esm.js +1090 -1152
  27. package/dist/widget-embedded.esm.js.map +1 -1
  28. package/package.json +3 -3
  29. package/src/App.tsx +1 -2
  30. package/src/QueueManager.tsx +28 -3
  31. package/src/components/AppRouter.tsx +4 -29
  32. package/src/components/AppRoutes.tsx +9 -9
  33. package/src/components/BottomLogo.tsx +1 -1
  34. package/src/components/ChangeSlippageButton.tsx +1 -1
  35. package/src/components/Layout.tsx +3 -1
  36. package/src/components/RoutesOverview.tsx +2 -2
  37. package/src/components/TokenInfo.tsx +3 -2
  38. package/src/components/TokenPreview.tsx +1 -0
  39. package/src/components/UpdateUrl.tsx +19 -50
  40. package/src/components/warnings/BalanceErrors.tsx +4 -2
  41. package/src/constants/navigationRoutes.ts +9 -9
  42. package/src/globalStyles.ts +0 -19
  43. package/src/hooks/useNavigateBack.ts +3 -4
  44. package/src/index.tsx +1 -1
  45. package/src/lib.tsx +16 -8
  46. package/src/pages/ConfirmSwapPage.tsx +33 -13
  47. package/src/pages/HistoryPage.tsx +1 -1
  48. package/src/pages/Home.tsx +1 -1
  49. package/src/pages/SwapDetailsPage.tsx +1 -2
  50. package/src/store/bestRoute.ts +18 -16
  51. package/src/store/wallets.ts +38 -28
  52. package/src/utils/numbers.ts +2 -5
  53. package/dist/hooks/useCopyToClipboard.d.ts +0 -2
  54. package/dist/hooks/useCopyToClipboard.d.ts.map +0 -1
  55. package/src/hooks/useCopyToClipboard.ts +0 -23
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.1.13-next.0",
3
+ "version": "0.1.13-next.5",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -30,9 +30,9 @@
30
30
  "dependencies": {
31
31
  "@rango-dev/provider-all": "^0.1.12",
32
32
  "@rango-dev/queue-manager-core": "^0.1.12-next.0",
33
- "@rango-dev/queue-manager-rango-preset": "^0.1.11",
33
+ "@rango-dev/queue-manager-rango-preset": "^0.1.12-next.4",
34
34
  "@rango-dev/queue-manager-react": "^0.1.11-next.0",
35
- "@rango-dev/ui": "^0.1.12",
35
+ "@rango-dev/ui": "^0.1.13-next.2",
36
36
  "@rango-dev/wallets-core": "^0.1.12",
37
37
  "@rango-dev/wallets-shared": "^0.1.11",
38
38
  "bignumber.js": "^9.1.1",
package/src/App.tsx CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  } from './utils/wallets';
14
14
  import { useWalletsStore } from './store/wallets';
15
15
  import { Layout } from './components/Layout';
16
- import { globalFont, globalStyles } from './globalStyles';
16
+ import { globalFont } from './globalStyles';
17
17
  import { useTheme } from './hooks/useTheme';
18
18
  import QueueManager from './QueueManager';
19
19
  import { isEvmBlockchain } from 'rango-sdk';
@@ -30,7 +30,6 @@ export type WidgetProps = {
30
30
  };
31
31
 
32
32
  export function App({ config }: WidgetProps) {
33
- globalStyles();
34
33
  globalFont(config?.theme?.fontFamily || 'Roboto');
35
34
  const { activeTheme } = useTheme({ ...config?.theme });
36
35
  useMemo(() => {
@@ -4,6 +4,7 @@ import {
4
4
  makeQueueDefinition,
5
5
  SwapQueueContext,
6
6
  checkWaitingForNetworkChange,
7
+ SwapProgressNotification,
7
8
  } from '@rango-dev/queue-manager-rango-preset';
8
9
  import { useWallets } from '@rango-dev/wallets-core';
9
10
  import {
@@ -32,6 +33,9 @@ function QueueManager(props: PropsWithChildren<{}>) {
32
33
  API_KEY: getConfig('API_KEY'),
33
34
  });
34
35
  }, []);
36
+ const getOneOfWalletsDetails = useWalletsStore.use.getOneOfWalletsDetails();
37
+ const accounts = useWalletsStore.use.accounts();
38
+
35
39
  const { blockchains } = useMetaStore.use.meta();
36
40
  const balances = useWalletsStore.use.balances();
37
41
 
@@ -64,6 +68,29 @@ function QueueManager(props: PropsWithChildren<{}>) {
64
68
  return walletAndSupportedChainsNames(supportedChains);
65
69
  };
66
70
  const allProviders = providers();
71
+ const notifier = (data: SwapProgressNotification) => {
72
+ const lastStep = data.swap?.steps[data.swap.steps.length - 1];
73
+ const outputAmount = data.step?.outputAmount || '';
74
+ const step = data.step || lastStep;
75
+
76
+ if (
77
+ data.eventType === 'task_completed' ||
78
+ (data.eventType === 'step_completed_with_output' &&
79
+ lastStep?.id !== data.step?.id) ||
80
+ !!outputAmount
81
+ ) {
82
+ const fromAccount = accounts.find(
83
+ (account) => account.chain === step?.fromBlockchain
84
+ );
85
+ const toAccount =
86
+ step?.fromBlockchain !== step?.toBlockchain &&
87
+ accounts.find((account) => account.chain === step?.toBlockchain);
88
+
89
+ fromAccount && getOneOfWalletsDetails(fromAccount);
90
+ toAccount && getOneOfWalletsDetails(toAccount);
91
+ }
92
+ };
93
+
67
94
  const context: SwapQueueContext = {
68
95
  meta: {
69
96
  blockchains: allBlockchains,
@@ -80,9 +107,7 @@ function QueueManager(props: PropsWithChildren<{}>) {
80
107
  switchNetwork,
81
108
  connect,
82
109
  state,
83
- notifier: (message) => {
84
- console.log('[notifier]', message);
85
- },
110
+ notifier,
86
111
  };
87
112
 
88
113
  return (
@@ -1,36 +1,11 @@
1
- import React, { PropsWithChildren, useEffect, useRef } from 'react';
2
- import {
3
- MemoryRouter,
4
- useInRouterContext,
5
- useLocation,
6
- useNavigate,
7
- } from 'react-router';
1
+ import React, { Fragment, PropsWithChildren } from 'react';
2
+ import { MemoryRouter, useInRouterContext } from 'react-router';
8
3
  import { useQueueManager } from '@rango-dev/queue-manager-rango-preset';
9
- import { navigationRoutes } from '../constants/navigationRoutes';
10
4
  import { WalletType } from '@rango-dev/wallets-shared';
11
5
  import { isEvmBlockchain } from 'rango-types';
12
6
  import { UpdateUrl } from './UpdateUrl';
13
- import { Home } from '../pages/Home';
14
7
  import { useMetaStore } from '../store/meta';
15
8
 
16
- const Route: React.FC = ({ children }: PropsWithChildren) => {
17
- const location = useLocation();
18
- const navigate = useNavigate();
19
- const ref = useRef(true);
20
-
21
- useEffect(() => {
22
- if (location.pathname === navigationRoutes.confirmSwap && ref.current)
23
- navigate(navigationRoutes.home + location.search, { state: 'redirect' });
24
-
25
- ref.current = false;
26
- }, []);
27
-
28
- if (location.pathname === navigationRoutes.confirmSwap && ref.current)
29
- return <Home />;
30
-
31
- return <> {children}</>;
32
- };
33
-
34
9
  export function AppRouter({
35
10
  children,
36
11
  ...props
@@ -40,7 +15,7 @@ export function AppRouter({
40
15
  clearDisconnectedWallet: () => void;
41
16
  }) {
42
17
  const isRouterInContext = useInRouterContext();
43
- const Router = isRouterInContext ? Route : MemoryRouter;
18
+ const Router = isRouterInContext ? Fragment : MemoryRouter;
44
19
  const { blockchains } = useMetaStore.use.meta();
45
20
 
46
21
  const evmChains = blockchains.filter(isEvmBlockchain);
@@ -55,7 +30,7 @@ export function AppRouter({
55
30
 
56
31
  return (
57
32
  <>
58
- <Router {...props}>{children}</Router>
33
+ <Router>{children}</Router>
59
34
  {isRouterInContext && <UpdateUrl />}
60
35
  </>
61
36
  );
@@ -23,11 +23,11 @@ export function AppRoutes(props: PropTypes) {
23
23
 
24
24
  return useRoutes([
25
25
  {
26
- path: getAbsolutePath(navigationRoutes.home),
26
+ path: navigationRoutes.home,
27
27
  element: <Home />,
28
28
  },
29
29
  {
30
- path: getAbsolutePath(navigationRoutes.fromChain),
30
+ path: navigationRoutes.fromChain,
31
31
  element: (
32
32
  <SelectChainPage
33
33
  type="from"
@@ -36,40 +36,40 @@ export function AppRoutes(props: PropTypes) {
36
36
  ),
37
37
  },
38
38
  {
39
- path: getAbsolutePath(navigationRoutes.toChain),
39
+ path: navigationRoutes.toChain,
40
40
  element: (
41
41
  <SelectChainPage type="to" supportedChains={config?.to?.blockchains} />
42
42
  ),
43
43
  },
44
44
  {
45
- path: getAbsolutePath(navigationRoutes.fromToken),
45
+ path: navigationRoutes.fromToken,
46
46
  element: (
47
47
  <SelectTokenPage type="from" supportedTokens={config?.from?.tokens} />
48
48
  ),
49
49
  },
50
50
  {
51
- path: getAbsolutePath(navigationRoutes.toToken),
51
+ path: navigationRoutes.toToken,
52
52
  element: (
53
53
  <SelectTokenPage type="to" supportedTokens={config?.to?.tokens} />
54
54
  ),
55
55
  },
56
56
  {
57
- path: getAbsolutePath(navigationRoutes.settings),
57
+ path: navigationRoutes.settings,
58
58
  element: <SettingsPage supportedSwappers={config?.liquiditySources} />,
59
59
  },
60
60
  {
61
- path: getAbsolutePath(navigationRoutes.liquiditySources),
61
+ path: navigationRoutes.liquiditySources,
62
62
  element: (
63
63
  <LiquiditySourcePage supportedSwappers={config?.liquiditySources} />
64
64
  ),
65
65
  },
66
- { path: getAbsolutePath(navigationRoutes.swaps), element: <HistoryPage /> },
66
+ { path: navigationRoutes.swaps, element: <HistoryPage /> },
67
67
  {
68
68
  path: navigationRoutes.swapDetails,
69
69
  element: <SwapDetailsPage />,
70
70
  },
71
71
  {
72
- path: getAbsolutePath(navigationRoutes.wallets),
72
+ path: navigationRoutes.wallets,
73
73
  element: (
74
74
  <WalletsPage
75
75
  supportedWallets={config?.wallets}
@@ -29,7 +29,7 @@ export function BottomLogo() {
29
29
 
30
30
  return (
31
31
  <Container>
32
- <Typography variant="caption">{t('Powered By')}</Typography>
32
+ <Typography variant="caption" color='$neutrals600'>{t('Powered By')}</Typography>
33
33
  <StyledAnchor href="https://rango.exchange" target="_blank">
34
34
  <Logo xmlns="http://www.w3.org/2000/svg" viewBox="0 0 33.68 29">
35
35
  <defs></defs>
@@ -11,7 +11,7 @@ export function ChangeSlippageButton() {
11
11
  type="primary"
12
12
  variant="outlined"
13
13
  size="small"
14
- onClick={() => navigate(navigationRoutes.settings)}
14
+ onClick={() => navigate('/' + navigationRoutes.settings)}
15
15
  >
16
16
  Change Slippage
17
17
  </Button>
@@ -37,7 +37,9 @@ const Header = styled('div', {
37
37
  const WalletImageContainer = styled('div', {
38
38
  marginLeft: -15,
39
39
  marginRight: '$6',
40
- borderRadius: '99999px',
40
+ '& img': {
41
+ borderRadius: '50%',
42
+ }
41
43
  });
42
44
 
43
45
  export type LayoutProps = {
@@ -39,11 +39,11 @@ function RoutesOverview(props: PropTypes) {
39
39
  {swaps?.map((swap, idx) => {
40
40
  const isLast = idx + 1 == swaps.length;
41
41
  return (
42
- <>
42
+ <React.Fragment key={idx}>
43
43
  <div className="route">{swap.from.symbol}</div>
44
44
  <ChevronRightIcon size={12} />
45
45
  {isLast ? <div className="route">{swap.to.symbol}</div> : null}
46
- </>
46
+ </React.Fragment>
47
47
  );
48
48
  })}
49
49
  </div>
@@ -37,6 +37,7 @@ const Box = styled('div', {
37
37
  display: 'flex',
38
38
  flexDirection: 'column',
39
39
  width: '100%',
40
+ overflow: 'hidden'
40
41
  });
41
42
 
42
43
  const Container = styled('div', {
@@ -224,7 +225,7 @@ export function TokenInfo(props: PropTypes) {
224
225
  <Button
225
226
  className="selectors"
226
227
  onClick={() => {
227
- navigate(`/${props.type.toLowerCase()}-chain`);
228
+ navigate(`${props.type.toLowerCase()}-chain`);
228
229
  }}
229
230
  variant="outlined"
230
231
  disabled={loadingStatus === 'failed'}
@@ -248,7 +249,7 @@ export function TokenInfo(props: PropTypes) {
248
249
  <Button
249
250
  className="selectors"
250
251
  onClick={() => {
251
- navigate(`/${props.type.toLowerCase()}-token`);
252
+ navigate(`${props.type.toLowerCase()}-token`);
252
253
  }}
253
254
  variant="outlined"
254
255
  disabled={
@@ -11,6 +11,7 @@ const Box = styled('div', {
11
11
  display: 'flex',
12
12
  flexDirection: 'column',
13
13
  width: '100%',
14
+ overflow: 'hidden',
14
15
  });
15
16
 
16
17
  const Container = styled('div', {
@@ -45,37 +45,6 @@ export function UpdateUrl() {
45
45
  }, []);
46
46
 
47
47
  useEffect(() => {
48
- let fromChainString = '',
49
- fromTokenString = '',
50
- toChainString = '',
51
- toTokenString = '',
52
- fromAmount = '';
53
- if (
54
- loadingStatus !== 'success' &&
55
- location.pathname != navigationRoutes.confirmSwap
56
- ) {
57
- fromChainString = searchParamsRef.current[SearchParams.FROM_CHAIN];
58
- fromTokenString = searchParamsRef.current[SearchParams.FROM_TOKEN];
59
- toChainString = searchParamsRef.current[SearchParams.TO_CHAIN];
60
- toTokenString = searchParamsRef.current[SearchParams.TO_TOKEN];
61
- fromAmount = searchParamsRef.current[SearchParams.FROM_AMOUNT];
62
- setSearchParams(
63
- {
64
- ...(fromChainString && {
65
- [SearchParams.FROM_CHAIN]: fromChainString,
66
- }),
67
- ...(fromTokenString && {
68
- [SearchParams.FROM_TOKEN]: fromTokenString,
69
- }),
70
- ...(toChainString && { [SearchParams.TO_CHAIN]: toChainString }),
71
- ...(toTokenString && { [SearchParams.TO_TOKEN]: toTokenString }),
72
- ...(fromAmount && {
73
- [SearchParams.FROM_AMOUNT]: fromAmount.toString(),
74
- }),
75
- },
76
- { replace: true }
77
- );
78
- }
79
48
  if (!firstRender.current) {
80
49
  let fromChainString = '',
81
50
  fromTokenString = '',
@@ -87,7 +56,8 @@ export function UpdateUrl() {
87
56
  fromTokenString = searchParamsRef.current[SearchParams.FROM_TOKEN];
88
57
  toChainString = searchParamsRef.current[SearchParams.TO_CHAIN];
89
58
  toTokenString = searchParamsRef.current[SearchParams.TO_TOKEN];
90
- fromAmount = searchParamsRef.current[SearchParams.FROM_AMOUNT];
59
+ fromAmount =
60
+ searchParamsRef.current[SearchParams.FROM_AMOUNT] || inputAmount;
91
61
  } else {
92
62
  if (location.state === 'redirect') return;
93
63
  fromChainString = fromChain?.name || '';
@@ -99,27 +69,26 @@ export function UpdateUrl() {
99
69
  (toToken?.symbol || '') +
100
70
  (toToken?.address ? `--${toToken?.address}` : '');
101
71
  fromAmount = inputAmount;
102
-
103
- setSearchParams(
104
- {
105
- ...(fromChainString && {
106
- [SearchParams.FROM_CHAIN]: fromChainString,
107
- }),
108
- ...(fromTokenString && {
109
- [SearchParams.FROM_TOKEN]: fromTokenString,
110
- }),
111
- ...(toChainString && { [SearchParams.TO_CHAIN]: toChainString }),
112
- ...(toTokenString && { [SearchParams.TO_TOKEN]: toTokenString }),
113
- ...(fromAmount && {
114
- [SearchParams.FROM_AMOUNT]: fromAmount.toString(),
115
- }),
116
- },
117
- { replace: true }
118
- );
119
72
  }
73
+ setSearchParams(
74
+ {
75
+ ...(fromChainString && {
76
+ [SearchParams.FROM_CHAIN]: fromChainString,
77
+ }),
78
+ ...(fromTokenString && {
79
+ [SearchParams.FROM_TOKEN]: fromTokenString,
80
+ }),
81
+ ...(toChainString && { [SearchParams.TO_CHAIN]: toChainString }),
82
+ ...(toTokenString && { [SearchParams.TO_TOKEN]: toTokenString }),
83
+ ...(fromAmount && {
84
+ [SearchParams.FROM_AMOUNT]: fromAmount.toString(),
85
+ }),
86
+ },
87
+ { replace: true }
88
+ );
120
89
  }
121
90
  firstRender.current = false;
122
- }, [location.pathname, inputAmount]);
91
+ }, [location.pathname, inputAmount, fromChain, fromToken, toChain, toToken]);
123
92
 
124
93
  useEffect(() => {
125
94
  if (loadingStatus === 'success') {
@@ -6,6 +6,8 @@ interface PropTypes {
6
6
  }
7
7
 
8
8
  const List = styled('ul', {
9
+ padding: 0,
10
+ margin: 0,
9
11
  variants: {
10
12
  showListStyle: {
11
13
  true: { paddingLeft: '$24' },
@@ -34,8 +36,8 @@ export function BalanceErrors({ messages }: PropTypes) {
34
36
  </Typography>
35
37
  <Spacer size={8} direction="vertical" />
36
38
  <List showListStyle={showListStyle}>
37
- {messages.map((warning) => (
38
- <ListItem showListStyle={showListStyle}>
39
+ {messages.map((warning, index) => (
40
+ <ListItem showListStyle={showListStyle} key={index}>
39
41
  <Message variant="body2">{warning}</Message>
40
42
  </ListItem>
41
43
  ))}
@@ -1,13 +1,13 @@
1
1
  export const navigationRoutes = {
2
2
  home: '/',
3
- fromChain: '/from-chain',
4
- fromToken: '/from-token',
5
- toChain: '/to-chain',
6
- toToken: '/to-token',
7
- settings: '/settings',
3
+ fromChain: 'from-chain',
4
+ fromToken: 'from-token',
5
+ toChain: 'to-chain',
6
+ toToken: 'to-token',
7
+ settings: 'settings',
8
8
  liquiditySources: '/settings/liquidity-sources',
9
- swaps: '/swaps',
10
- wallets: '/wallets',
11
- confirmSwap: '/confirm-swap',
12
- swapDetails: '/swaps/:requestId',
9
+ swaps: 'swaps',
10
+ wallets: 'wallets',
11
+ confirmSwap: 'confirm-swap',
12
+ swapDetails: 'swaps/:requestId',
13
13
  };
@@ -1,24 +1,5 @@
1
1
  import { globalCss } from '@rango-dev/ui';
2
2
 
3
- export const globalStyles = globalCss({
4
- '*': {
5
- boxSizing: 'border-box',
6
- margin: 0,
7
- padding: 0,
8
- listStyleType: 'none',
9
- '&::-webkit-scrollbar': { width: '$8', height: '$8' },
10
- '&::-webkit-scrollbar-thumb': {
11
- backgroundColor: '$neutrals400',
12
- borderRadius: '$10',
13
- },
14
- '&::-webkit-scrollbar-thumb:hover': {
15
- backgroundColor: '$neutrals500',
16
- },
17
- '&::-webkit-scrollbar-track': {
18
- backgroundColor: '$neutrals300',
19
- },
20
- },
21
- });
22
3
  export const globalFont = (fontFamily: string) =>
23
4
  globalCss({
24
5
  '@import': [
@@ -9,7 +9,8 @@ export function useNavigateBack() {
9
9
 
10
10
  const navigateBackFrom = (currentRoute: string) => {
11
11
  if (currentRoute === navigationRoutes.swapDetails)
12
- return navigate(navigationRoutes.swaps, { replace: true });
12
+ return navigate('/' + navigationRoutes.swaps, { replace: true });
13
+
13
14
  if (
14
15
  !isRouterInContext ||
15
16
  (window.history.state && window.history.state.idx > 0)
@@ -30,9 +31,7 @@ export function useNavigateBack() {
30
31
  )
31
32
  navigate(navigationRoutes.home, { replace: true });
32
33
  else if (currentRoute === navigationRoutes.liquiditySources)
33
- navigate(navigationRoutes.settings, { replace: true });
34
- else if (currentRoute === navigationRoutes.swapDetails)
35
- navigate(navigationRoutes.swaps, { replace: true });
34
+ navigate('/' + navigationRoutes.settings, { replace: true });
36
35
  }
37
36
  };
38
37
 
package/src/index.tsx CHANGED
@@ -11,4 +11,4 @@ root.render(
11
11
  </BrowserRouter>
12
12
  );
13
13
 
14
- export { Widget } from './lib';
14
+ export { Widget } from './lib';
package/src/lib.tsx CHANGED
@@ -12,10 +12,15 @@ import {
12
12
  } from './utils/wallets';
13
13
  import { useWalletsStore } from './store/wallets';
14
14
  import { Layout } from './components/Layout';
15
- import { globalFont, globalStyles } from './globalStyles';
15
+ import { globalFont } from './globalStyles';
16
16
  import { useTheme } from './hooks/useTheme';
17
17
  import { isEvmBlockchain } from 'rango-sdk';
18
- import { WidgetTheme, WidgetConfig, WidgetColors, BlockchainAndTokenConfig } from './types';
18
+ import {
19
+ WidgetTheme,
20
+ WidgetConfig,
21
+ WidgetColors,
22
+ BlockchainAndTokenConfig,
23
+ } from './types';
19
24
  import useSelectLanguage from './hooks/useSelectLanguage';
20
25
  import './i18n';
21
26
  import QueueManager from './QueueManager';
@@ -23,15 +28,19 @@ import { useUiStore } from './store/ui';
23
28
  import { navigationRoutes } from './constants/navigationRoutes';
24
29
  import { initConfig } from './utils/configs';
25
30
 
26
-
27
- export {WidgetConfig, WalletType, WidgetTheme, WidgetColors, BlockchainAndTokenConfig}
31
+ export {
32
+ WidgetConfig,
33
+ WalletType,
34
+ WidgetTheme,
35
+ WidgetColors,
36
+ BlockchainAndTokenConfig,
37
+ };
28
38
 
29
39
  export type WidgetProps = {
30
40
  config?: WidgetConfig;
31
41
  };
32
42
 
33
43
  export const Widget: React.FC<WidgetProps> = ({ config }) => {
34
- globalStyles();
35
44
  globalFont(config?.theme?.fontFamily || 'Roboto');
36
45
 
37
46
  const { activeTheme } = useTheme({ ...config?.theme });
@@ -115,10 +124,9 @@ export const Widget: React.FC<WidgetProps> = ({ config }) => {
115
124
  providers={providers}
116
125
  onUpdateState={onUpdateState}
117
126
  >
118
- <div id="pageContainer" className={activeTheme}>
127
+ <div className={activeTheme}>
119
128
  <QueueManager>
120
- <SwapContainer
121
- fixedHeight={currentPage !== navigationRoutes.home}>
129
+ <SwapContainer fixedHeight={currentPage !== navigationRoutes.home}>
122
130
  <AppRouter
123
131
  lastConnectedWallet={lastConnectedWalletWithNetwork}
124
132
  disconnectedWallet={disconnectedWallet}
@@ -11,14 +11,14 @@ import {
11
11
  isExperimentalChain,
12
12
  } from '../utils/wallets';
13
13
  import { getTotalFeeInUsd, requiredWallets } from '../utils/swap';
14
- import { decimalNumber, numberToString } from '../utils/numbers';
14
+ import { numberToString } from '../utils/numbers';
15
15
  import { useMetaStore } from '../store/meta';
16
16
  import { Network, WalletType } from '@rango-dev/wallets-shared';
17
17
  import { useNavigateBack } from '../hooks/useNavigateBack';
18
18
  import { TokenPreview } from '../components/TokenPreview';
19
19
  // @ts-ignore // TODO: fix error in tsc build
20
20
  import { t } from 'i18next';
21
- import { Spacer, ConfirmSwap } from '@rango-dev/ui';
21
+ import { Spacer, ConfirmSwap, LoadingFailedAlert } from '@rango-dev/ui';
22
22
  import RoutesOverview from '../components/RoutesOverview';
23
23
  import { useManager } from '@rango-dev/queue-manager-react';
24
24
  import { useConfirmSwap } from '../hooks/useConfirmSwap';
@@ -39,6 +39,7 @@ export function ConfirmSwapPage() {
39
39
  const fetchingBestRouteError = useBestRouteStore.use.error();
40
40
  const setSelectedSwap = useUiStore.use.setSelectedSwap();
41
41
  const { blockchains, tokens } = useMetaStore.use.meta();
42
+ const loadingMetaStatus = useMetaStore.use.loadingStatus();
42
43
  const accounts = useWalletsStore.use.accounts();
43
44
  const selectedWallets = useWalletsStore.use.selectedWallets();
44
45
  const initSelectedWallets = useWalletsStore.use.initSelectedWallets();
@@ -55,7 +56,12 @@ export function ConfirmSwapPage() {
55
56
  );
56
57
 
57
58
  const { manager } = useManager();
58
- const { loading, errors, warnings, confirmSwap } = useConfirmSwap();
59
+ const {
60
+ loading: fetchingConfirmedRoute,
61
+ errors,
62
+ warnings,
63
+ confirmSwap,
64
+ } = useConfirmSwap();
59
65
 
60
66
  const selectedSlippage = customSlippage || slippage;
61
67
 
@@ -74,8 +80,8 @@ export function ConfirmSwapPage() {
74
80
  const lastStep =
75
81
  bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1];
76
82
 
77
- const fromAmount = decimalNumber(firstStep?.fromAmount, 3);
78
- const toAmount = decimalNumber(lastStep?.toAmount, 3);
83
+ const fromAmount = numberToString(firstStep?.fromAmount, 4, 6);
84
+ const toAmount = numberToString(lastStep?.toAmount, 4, 6);
79
85
  useEffect(() => {
80
86
  initSelectedWallets();
81
87
  }, []);
@@ -109,7 +115,7 @@ export function ConfirmSwapPage() {
109
115
  { id: swap.requestId }
110
116
  );
111
117
  setSelectedSwap(swap.requestId);
112
- navigate(navigationRoutes.swaps + `/${swap.requestId}`, {
118
+ navigate('/' + navigationRoutes.swaps + `/${swap.requestId}`, {
113
119
  replace: true,
114
120
  });
115
121
  setTimeout(() => {
@@ -119,7 +125,7 @@ export function ConfirmSwapPage() {
119
125
  });
120
126
  }}
121
127
  onChange={(wallet) => setSelectedWallet(wallet)}
122
- confirmDisabled={confirmDisabled}
128
+ confirmDisabled={loadingMetaStatus !== 'success' || confirmDisabled}
123
129
  handleConnectChain={(wallet) => handleConnectChain(wallet)}
124
130
  isExperimentalChain={(wallet) =>
125
131
  getKeplrCompatibleConnectedWallets(selectableWallets).length > 0
@@ -140,7 +146,11 @@ export function ConfirmSwapPage() {
140
146
  usdValue={inputUsdValue}
141
147
  amount={fromAmount}
142
148
  label={t('From')}
143
- loadingStatus={bestRouteloadingStatus}
149
+ loadingStatus={
150
+ loadingMetaStatus !== 'success'
151
+ ? loadingMetaStatus
152
+ : bestRouteloadingStatus
153
+ }
144
154
  />
145
155
  <Spacer size={12} direction="vertical" />
146
156
  <TokenPreview
@@ -155,7 +165,11 @@ export function ConfirmSwapPage() {
155
165
  usdValue={outputUsdValue}
156
166
  amount={toAmount}
157
167
  label={t('To')}
158
- loadingStatus={bestRouteloadingStatus}
168
+ loadingStatus={
169
+ loadingMetaStatus !== 'success'
170
+ ? loadingMetaStatus
171
+ : bestRouteloadingStatus
172
+ }
159
173
  percentageChange={
160
174
  <PercentageChange
161
175
  inputUsdValue={inputUsdValue}
@@ -171,13 +185,19 @@ export function ConfirmSwapPage() {
171
185
  totalFee={numberToString(totalFeeInUsd, 0, 2)}
172
186
  />
173
187
  }
174
- loading={loading}
188
+ loading={fetchingConfirmedRoute}
175
189
  errors={ConfirmSwapErrors(errors)}
176
190
  warnings={ConfirmSwapWarnings(warnings)}
177
191
  extraMessages={
178
- showHighSlippageWarning && (
179
- <ConfirmSwapExtraMessages selectedSlippage={selectedSlippage} />
180
- )
192
+ <>
193
+ {loadingMetaStatus === 'failed' && <LoadingFailedAlert />}
194
+ {loadingMetaStatus === 'failed' && showHighSlippageWarning && (
195
+ <Spacer direction="vertical" />
196
+ )}
197
+ {showHighSlippageWarning && (
198
+ <ConfirmSwapExtraMessages selectedSlippage={selectedSlippage} />
199
+ )}
200
+ </>
181
201
  }
182
202
  confirmButtonTitle={
183
203
  warnings.length > 0 || errors.length > 0
@@ -24,7 +24,7 @@ export function HistoryPage() {
24
24
  loading={loading}
25
25
  onSwapClick={(requestId) => {
26
26
  setSelectedSwap(requestId);
27
- navigate(navigationRoutes.swaps + `/${requestId}`, { replace: true });
27
+ navigate(`${requestId}`, { replace: true });
28
28
  }}
29
29
  onBack={navigateBackFrom.bind(null, navigationRoutes.swaps)}
30
30
  />