@rango-dev/widget-embedded 0.1.11-next.9 → 0.1.12

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 (80) hide show
  1. package/dist/App.d.ts.map +1 -1
  2. package/dist/QueueManager.d.ts.map +1 -1
  3. package/dist/components/ConfirmSwapErrors.d.ts +1 -1
  4. package/dist/components/ConfirmSwapErrors.d.ts.map +1 -1
  5. package/dist/components/ConfirmSwapWarnings.d.ts +1 -2
  6. package/dist/components/ConfirmSwapWarnings.d.ts.map +1 -1
  7. package/dist/components/SwapDetailsPlaceholder.d.ts +1 -0
  8. package/dist/components/SwapDetailsPlaceholder.d.ts.map +1 -1
  9. package/dist/components/TokenInfo.d.ts.map +1 -1
  10. package/dist/components/warnings/BalanceErrors.d.ts +7 -0
  11. package/dist/components/warnings/BalanceErrors.d.ts.map +1 -0
  12. package/dist/globalStyles.d.ts.map +1 -1
  13. package/dist/hooks/useTheme.d.ts +2 -2
  14. package/dist/hooks/useTheme.d.ts.map +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/lib.d.ts +4 -2
  18. package/dist/lib.d.ts.map +1 -1
  19. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  20. package/dist/pages/HistoryPage.d.ts.map +1 -1
  21. package/dist/pages/Home.d.ts.map +1 -1
  22. package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
  23. package/dist/pages/WalletsPage.d.ts +0 -1
  24. package/dist/pages/WalletsPage.d.ts.map +1 -1
  25. package/dist/services/httpService.d.ts +2 -1
  26. package/dist/services/httpService.d.ts.map +1 -1
  27. package/dist/store/bestRoute.d.ts.map +1 -1
  28. package/dist/store/meta.d.ts.map +1 -1
  29. package/dist/types/config.d.ts +78 -9
  30. package/dist/types/config.d.ts.map +1 -1
  31. package/dist/types/routing.d.ts +8 -8
  32. package/dist/types/routing.d.ts.map +1 -1
  33. package/dist/utils/configs.d.ts +7 -0
  34. package/dist/utils/configs.d.ts.map +1 -0
  35. package/dist/utils/numbers.d.ts +1 -0
  36. package/dist/utils/numbers.d.ts.map +1 -1
  37. package/dist/utils/routing.d.ts +4 -4
  38. package/dist/utils/routing.d.ts.map +1 -1
  39. package/dist/utils/swap.d.ts +2 -2
  40. package/dist/utils/swap.d.ts.map +1 -1
  41. package/dist/utils/time.d.ts.map +1 -1
  42. package/dist/widget-embedded.cjs.development.js +346 -277
  43. package/dist/widget-embedded.cjs.development.js.map +1 -1
  44. package/dist/widget-embedded.cjs.production.min.js +346 -277
  45. package/dist/widget-embedded.cjs.production.min.js.map +1 -1
  46. package/dist/widget-embedded.esm.js +342 -278
  47. package/dist/widget-embedded.esm.js.map +1 -1
  48. package/package.json +9 -9
  49. package/src/App.tsx +10 -16
  50. package/src/QueueManager.tsx +9 -3
  51. package/src/app.css +0 -15
  52. package/src/components/ConfirmSwapErrors.tsx +8 -16
  53. package/src/components/ConfirmSwapWarnings.tsx +5 -15
  54. package/src/components/SwapDetailsPlaceholder.tsx +8 -1
  55. package/src/components/TokenInfo.tsx +6 -5
  56. package/src/components/warnings/BalanceErrors.tsx +45 -0
  57. package/src/globalStyles.ts +4 -0
  58. package/src/hooks/useConfirmSwap.ts +5 -5
  59. package/src/hooks/useTheme.ts +2 -2
  60. package/src/index.tsx +1 -1
  61. package/src/lib.tsx +16 -15
  62. package/src/pages/ConfirmSwapPage.tsx +4 -2
  63. package/src/pages/HistoryPage.tsx +4 -1
  64. package/src/pages/Home.tsx +6 -8
  65. package/src/pages/SwapDetailsPage.tsx +8 -21
  66. package/src/pages/WalletsPage.tsx +2 -2
  67. package/src/services/httpService.ts +9 -4
  68. package/src/store/bestRoute.ts +7 -5
  69. package/src/store/meta.ts +6 -4
  70. package/src/store/wallets.ts +2 -2
  71. package/src/types/config.ts +79 -12
  72. package/src/types/routing.ts +4 -4
  73. package/src/utils/configs.ts +30 -0
  74. package/src/utils/numbers.ts +4 -0
  75. package/src/utils/routing.ts +31 -11
  76. package/src/utils/swap.ts +16 -5
  77. package/src/utils/time.ts +2 -8
  78. package/dist/components/warnings/BalanceWarnings.d.ts +0 -7
  79. package/dist/components/warnings/BalanceWarnings.d.ts.map +0 -1
  80. package/src/components/warnings/BalanceWarnings.tsx +0 -40
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.1.11-next.9",
3
+ "version": "0.1.12",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -11,7 +11,7 @@
11
11
  "browserslist": "> 0.5%, last 2 versions, not dead",
12
12
  "scripts": {
13
13
  "watch-tsc": "tsc --watch --noEmit",
14
- "dev": "parcel public/index.html -p 3001 --cache-dir=.parcel-cache",
14
+ "dev": "parcel public/index.html -p 3001 --no-cache",
15
15
  "dev-tsc": "npm-run-all --parallel watch-tsc dev",
16
16
  "build:app": "parcel build --cache-dir=.parcel-cache",
17
17
  "build": "tsdx build --entry ./src/lib.tsx"
@@ -28,13 +28,13 @@
28
28
  "trailingComma": "es5"
29
29
  },
30
30
  "dependencies": {
31
- "@rango-dev/provider-all": "^0.1.11-next.84",
32
- "@rango-dev/queue-manager-core": "^0.1.11-next.0",
33
- "@rango-dev/queue-manager-rango-preset": "^0.1.11-next.3",
34
- "@rango-dev/queue-manager-react": "^0.1.10-next.76",
35
- "@rango-dev/ui": "^0.1.11-next.4",
36
- "@rango-dev/wallets-core": "^0.1.11-next.88",
37
- "@rango-dev/wallets-shared": "^0.1.11-next.84",
31
+ "@rango-dev/provider-all": "^0.1.11",
32
+ "@rango-dev/queue-manager-core": "^0.1.11",
33
+ "@rango-dev/queue-manager-rango-preset": "^0.1.11",
34
+ "@rango-dev/queue-manager-react": "^0.1.10",
35
+ "@rango-dev/ui": "^0.1.11",
36
+ "@rango-dev/wallets-core": "^0.1.11",
37
+ "@rango-dev/wallets-shared": "^0.1.11",
38
38
  "bignumber.js": "^9.1.1",
39
39
  "copy-to-clipboard": "^3.3.3",
40
40
  "dayjs": "^1.11.7",
package/src/App.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SwapContainer } from '@rango-dev/ui';
2
- import React, { useEffect, useState } from 'react';
2
+ import React, { useEffect, useMemo, useState } from 'react';
3
3
  import { AppRouter } from './components/AppRouter';
4
4
  import { useMetaStore } from './store/meta';
5
5
  import './app.css';
@@ -21,6 +21,7 @@ import { WidgetConfig } from './types';
21
21
  import './i18n';
22
22
  import { useUiStore } from './store/ui';
23
23
  import { navigationRoutes } from './constants/navigationRoutes';
24
+ import { initConfig } from './utils/configs';
24
25
 
25
26
  const providers = allProviders();
26
27
 
@@ -32,6 +33,13 @@ export function App({ config }: WidgetProps) {
32
33
  globalStyles();
33
34
  globalFont(config?.theme?.fontFamily || 'Roboto');
34
35
  const { activeTheme } = useTheme({ ...config?.theme });
36
+ useMemo(() => {
37
+ if (config?.apiKey) {
38
+ initConfig({
39
+ API_KEY: config?.apiKey,
40
+ });
41
+ }
42
+ }, [config]);
35
43
 
36
44
  const { blockchains } = useMetaStore.use.meta();
37
45
  const disconnectWallet = useWalletsStore.use.disconnectWallet();
@@ -98,21 +106,7 @@ export function App({ config }: WidgetProps) {
98
106
  >
99
107
  <div id="pageContainer" className={activeTheme}>
100
108
  <QueueManager>
101
- <SwapContainer
102
- // style={
103
- // currentPage !== navigationRoutes.home && config?.theme?.height
104
- // ? {
105
- // height: config?.theme?.height,
106
- // width: config?.theme?.width || 'auto',
107
- // }
108
- // : config?.theme?.width
109
- // ? {
110
- // width: config?.theme?.width || 'auto',
111
- // }
112
- // : undefined
113
- // }
114
- fixedHeight={currentPage !== navigationRoutes.home}
115
- >
109
+ <SwapContainer fixedHeight={currentPage !== navigationRoutes.home}>
116
110
  <AppRouter
117
111
  lastConnectedWallet={lastConnectedWalletWithNetwork}
118
112
  disconnectedWallet={disconnectedWallet}
@@ -1,7 +1,7 @@
1
- import React, { PropsWithChildren } from 'react';
1
+ import React, { PropsWithChildren, useMemo } from 'react';
2
2
  import { Provider as ManagerProvider } from '@rango-dev/queue-manager-react';
3
3
  import {
4
- swapQueueDef,
4
+ makeQueueDefinition,
5
5
  SwapQueueContext,
6
6
  checkWaitingForNetworkChange,
7
7
  } from '@rango-dev/queue-manager-rango-preset';
@@ -15,6 +15,7 @@ import { useMetaStore } from './store/meta';
15
15
  import { useWalletsStore } from './store/wallets';
16
16
  import { walletAndSupportedChainsNames } from './utils/wallets';
17
17
  import { isEvmBlockchain } from 'rango-sdk';
18
+ import { getConfig } from './utils/configs';
18
19
 
19
20
  function QueueManager(props: PropsWithChildren<{}>) {
20
21
  const {
@@ -26,6 +27,11 @@ function QueueManager(props: PropsWithChildren<{}>) {
26
27
  getWalletInfo,
27
28
  } = useWallets();
28
29
 
30
+ const swapQueueDef = useMemo(() => {
31
+ return makeQueueDefinition({
32
+ API_KEY: getConfig('API_KEY'),
33
+ });
34
+ }, []);
29
35
  const { blockchains } = useMetaStore.use.meta();
30
36
  const balances = useWalletsStore.use.balances();
31
37
 
@@ -63,7 +69,7 @@ function QueueManager(props: PropsWithChildren<{}>) {
63
69
  blockchains: allBlockchains,
64
70
  evmBasedChains: evmBasedChains,
65
71
  evmNetworkChainInfo:
66
- convertEvmBlockchainMetaToEvmChainInfo(evmBasedChains),
72
+ convertEvmBlockchainMetaToEvmChainInfo(evmBasedChains),
67
73
  getSupportedChainNames,
68
74
  },
69
75
  getSigners,
package/src/app.css CHANGED
@@ -1,19 +1,4 @@
1
1
  @import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap');
2
- * {
3
- box-sizing: border-box;
4
- margin: 0;
5
- padding: 0;
6
- list-style-type: none;
7
- }
8
-
9
- input::-webkit-outer-spin-button,
10
- input::-webkit-inner-spin-button {
11
- -webkit-appearance: none;
12
- margin: 0;
13
- }
14
- input[type='number'] {
15
- -moz-appearance: textfield;
16
- }
17
2
 
18
3
  #app {
19
4
  height: 100vh;
@@ -1,36 +1,28 @@
1
1
  import React from 'react';
2
- import { Typography } from '@rango-dev/ui';
3
2
  import { ConfirmSwapError, ConfirmSwapErrorTypes } from '../types';
4
3
  import { MinRequiredSlippage } from './warnings/MinRequiredSlippage';
4
+ import { BalanceErrors } from './warnings/BalanceErrors';
5
5
 
6
6
  export function ConfirmSwapErrors(errors: ConfirmSwapError[]) {
7
7
  return errors.flatMap((error) => {
8
8
  switch (error.type) {
9
9
  case ConfirmSwapErrorTypes.NO_ROUTE:
10
- return (
11
- <Typography variant="body2">
12
- No routes found. Please try again later.
13
- </Typography>
14
- );
10
+ return 'No routes found. Please try again later.';
15
11
  case ConfirmSwapErrorTypes.REQUEST_FAILED:
16
- return (
17
- <Typography variant="body2">{`Failed to confirm swap ${
18
- error.status ? `'status': ${error.status})` : ''
19
- }, please try again.`}</Typography>
20
- );
12
+ return `Failed to confirm swap ${
13
+ error.status ? `'status': ${error.status})` : ''
14
+ }, please try again.`;
21
15
 
22
16
  case ConfirmSwapErrorTypes.ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS:
23
- return (
24
- <Typography variant="body2">
25
- Route updated and price impact is too high, try again later!
26
- </Typography>
27
- );
17
+ return 'Route updated and price impact is too high, try again later!';
28
18
  case ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE:
29
19
  return (
30
20
  <MinRequiredSlippage
31
21
  minRequiredSlippage={error.minRequiredSlippage}
32
22
  />
33
23
  );
24
+ case ConfirmSwapErrorTypes.INSUFFICIENT_BALANCE:
25
+ return <BalanceErrors messages={error.messages} />;
34
26
  default:
35
27
  return [];
36
28
  }
@@ -1,35 +1,25 @@
1
- import React from 'react';
2
- import { Typography } from '@rango-dev/ui';
3
1
  import { ConfirmSwapWarningTypes, ConfirmSwapWarnings } from '../types';
4
- import { BalanceWarnings } from './warnings/BalanceWarnings';
5
2
 
6
3
  export function ConfirmSwapWarnings(warnings: ConfirmSwapWarnings[]) {
7
4
  return warnings.flatMap((warning) => {
8
5
  switch (warning.type) {
9
6
  case ConfirmSwapWarningTypes.ROUTE_UPDATED:
10
- return <Typography variant="body2">Route has been updated.</Typography>;
7
+ return "Route has been updated.";
11
8
  case ConfirmSwapWarningTypes.ROUTE_AND_OUTPUT_AMOUNT_UPDATED:
12
9
  return (
13
- <Typography variant="body2">{`Output amount changed to ${warning.newOutputAmount}
14
- (${warning.percentageChange}% change).`}</Typography>
10
+ `Output amount changed to ${warning.newOutputAmount} (${warning.percentageChange}% change).`
15
11
  );
16
12
 
17
13
  case ConfirmSwapWarningTypes.ROUTE_SWAPPERS_UPDATED:
18
14
  return (
19
- <Typography variant="body2">
20
- Route swappers has been updated.
21
- </Typography>
15
+ "Route swappers has been updated."
22
16
  );
23
17
  case ConfirmSwapWarningTypes.ROUTE_COINS_UPDATED:
24
18
  return (
25
- <Typography variant="body2">
26
- Route internal coins has been updated.
27
- </Typography>
19
+ "Route internal coins has been updated."
28
20
  );
29
- case ConfirmSwapWarningTypes.INSUFFICIENT_BALANCE:
30
- return <BalanceWarnings messages={warning.messages} />;
31
21
  default:
32
22
  return [];
33
23
  }
34
24
  });
35
- }
25
+ }
@@ -1,9 +1,16 @@
1
1
  import React from 'react';
2
2
  import { SecondaryPage, Spinner, Alert, styled } from '@rango-dev/ui';
3
- import { LoaderContainer } from '../pages/WalletsPage';
4
3
 
5
4
  const PlaceholderContainer = styled('div', { height: '450px' });
6
5
 
6
+ export const LoaderContainer = styled('div', {
7
+ display: 'flex',
8
+ justifyContent: 'center',
9
+ width: '100%',
10
+ paddingTop: '33%',
11
+ flex: 1,
12
+ });
13
+
7
14
  interface PropTypes {
8
15
  requestId: string;
9
16
  loading: boolean;
@@ -132,6 +132,7 @@ export function TokenInfo(props: PropTypes) {
132
132
  const bestRoute = useBestRouteStore.use.bestRoute();
133
133
  const inputAmount = useBestRouteStore.use.inputAmount();
134
134
  const balances = useWalletsStore.use.balances();
135
+ const fetchingBestRoute = useBestRouteStore.use.loading();
135
136
  const navigate = useNavigate();
136
137
  const { t } = useTranslation();
137
138
 
@@ -296,6 +297,7 @@ export function TokenInfo(props: PropTypes) {
296
297
  </span>
297
298
  }
298
299
  value={props.inputAmount || ''}
300
+ min={0}
299
301
  onChange={
300
302
  props.type === 'From'
301
303
  ? (event) => {
@@ -307,11 +309,10 @@ export function TokenInfo(props: PropTypes) {
307
309
  ) : (
308
310
  <OutputContainer>
309
311
  <Typography variant="h4">
310
- {bestRoute
311
- ? `≈ ${numberToString(props.outputAmount)}`
312
- : inputAmount
313
- ? '?'
314
- : '0'}
312
+ {fetchingBestRoute && '?'}
313
+ {!!bestRoute?.result &&
314
+ `≈ ${numberToString(props.outputAmount)}`}
315
+ {(!inputAmount || inputAmount === '0') && '0'}
315
316
  </Typography>
316
317
  </OutputContainer>
317
318
  )}
@@ -0,0 +1,45 @@
1
+ import { Spacer, styled, Typography } from '@rango-dev/ui';
2
+ import React from 'react';
3
+
4
+ interface PropTypes {
5
+ messages: string[];
6
+ }
7
+
8
+ const List = styled('ul', {
9
+ variants: {
10
+ showListStyle: {
11
+ true: { paddingLeft: '$24' },
12
+ },
13
+ },
14
+ });
15
+
16
+ const ListItem = styled('li', {
17
+ variants: {
18
+ showListStyle: {
19
+ true: { listStyleType: 'disc', listStylePosition: 'outside' },
20
+ },
21
+ },
22
+ });
23
+
24
+ const Message = styled(Typography, {
25
+ display: 'block',
26
+ });
27
+
28
+ export function BalanceErrors({ messages }: PropTypes) {
29
+ const showListStyle = messages.length > 1;
30
+ return (
31
+ <>
32
+ <Typography className="title" variant="title" color={'error'}>
33
+ Insufficent Balance:
34
+ </Typography>
35
+ <Spacer size={8} direction="vertical" />
36
+ <List showListStyle={showListStyle}>
37
+ {messages.map((warning) => (
38
+ <ListItem showListStyle={showListStyle}>
39
+ <Message variant="body2">{warning}</Message>
40
+ </ListItem>
41
+ ))}
42
+ </List>
43
+ </>
44
+ );
45
+ }
@@ -2,6 +2,10 @@ import { globalCss } from '@rango-dev/ui';
2
2
 
3
3
  export const globalStyles = globalCss({
4
4
  '*': {
5
+ boxSizing: 'border-box',
6
+ margin: 0,
7
+ padding: 0,
8
+ listStyleType: 'none',
5
9
  '&::-webkit-scrollbar': { width: '$8', height: '$8' },
6
10
  '&::-webkit-scrollbar-thumb': {
7
11
  backgroundColor: '$neutrals400',
@@ -112,12 +112,12 @@ export function useConfirmSwap(): ConfirmSwap {
112
112
  selectedWallets,
113
113
  disabledLiquiditySources,
114
114
  userSlippage,
115
- true,
116
- affiliateRef
115
+ affiliateRef,
116
+ initialRoute
117
117
  );
118
118
 
119
119
  try {
120
- const confiremedRoute = await httpService.getBestRoute(requestBody, {
120
+ const confiremedRoute = await httpService().getBestRoute(requestBody, {
121
121
  signal: abortControllerRef.current?.signal,
122
122
  });
123
123
 
@@ -198,8 +198,8 @@ export function useConfirmSwap(): ConfirmSwap {
198
198
  const enoughBalance = balanceWarnings.length === 0;
199
199
 
200
200
  if (!enoughBalance)
201
- confirmSwapState.warnings.push({
202
- type: ConfirmSwapWarningTypes.INSUFFICIENT_BALANCE,
201
+ confirmSwapState.errors.push({
202
+ type: ConfirmSwapErrorTypes.INSUFFICIENT_BALANCE,
203
203
  messages: balanceWarnings,
204
204
  });
205
205
 
@@ -2,7 +2,7 @@ import { createTheme } from '@rango-dev/ui';
2
2
  import { useState, useEffect, useLayoutEffect } from 'react';
3
3
  import { useMetaStore } from '../store/meta';
4
4
  import { useSettingsStore } from '../store/settings';
5
- import { Theme } from '../types';
5
+ import { WidgetTheme } from '../types';
6
6
  import { shadeColor } from '../utils/common';
7
7
  import usePrevious from './usePrevious';
8
8
 
@@ -11,7 +11,7 @@ export function useTheme({
11
11
  fontFamily = 'Robot',
12
12
  borderRadius = 8,
13
13
  mode = 'auto',
14
- }: Theme) {
14
+ }: WidgetTheme) {
15
15
  const theme = useSettingsStore.use.theme();
16
16
  const fetchMeta = useMetaStore.use.fetchMeta();
17
17
  const setTheme = useSettingsStore.use.setTheme();
package/src/index.tsx CHANGED
@@ -11,4 +11,4 @@ root.render(
11
11
  </BrowserRouter>
12
12
  );
13
13
 
14
- export { SwapBox } from './lib';
14
+ export { Widget } from './lib';
package/src/lib.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SwapContainer } from '@rango-dev/ui';
2
- import React, { useEffect, useState } from 'react';
2
+ import React, { useEffect, useMemo, useState } from 'react';
3
3
  import { AppRouter } from './components/AppRouter';
4
4
  import { useMetaStore } from './store/meta';
5
5
  import { Events, Provider } from '@rango-dev/wallets-core';
@@ -15,18 +15,22 @@ import { Layout } from './components/Layout';
15
15
  import { globalFont, globalStyles } from './globalStyles';
16
16
  import { useTheme } from './hooks/useTheme';
17
17
  import { isEvmBlockchain } from 'rango-sdk';
18
- import { WidgetConfig } from './types';
18
+ import { WidgetTheme, WidgetConfig, WidgetColors, BlockchainAndTokenConfig } from './types';
19
19
  import useSelectLanguage from './hooks/useSelectLanguage';
20
20
  import './i18n';
21
21
  import QueueManager from './QueueManager';
22
22
  import { useUiStore } from './store/ui';
23
23
  import { navigationRoutes } from './constants/navigationRoutes';
24
+ import { initConfig } from './utils/configs';
25
+
26
+
27
+ export {WidgetConfig, WalletType, WidgetTheme, WidgetColors, BlockchainAndTokenConfig}
24
28
 
25
29
  export type WidgetProps = {
26
30
  config?: WidgetConfig;
27
31
  };
28
32
 
29
- export const SwapBox: React.FC<WidgetProps> = ({ config }) => {
33
+ export const Widget: React.FC<WidgetProps> = ({ config }) => {
30
34
  globalStyles();
31
35
  globalFont(config?.theme?.fontFamily || 'Roboto');
32
36
 
@@ -45,6 +49,14 @@ export const SwapBox: React.FC<WidgetProps> = ({ config }) => {
45
49
  .filter(isEvmBlockchain)
46
50
  .map((chain) => chain.name);
47
51
 
52
+ useMemo(() => {
53
+ if (config?.apiKey) {
54
+ initConfig({
55
+ API_KEY: config?.apiKey,
56
+ });
57
+ }
58
+ }, [config]);
59
+
48
60
  const onUpdateState: EventHandler = (
49
61
  type,
50
62
  event,
@@ -106,18 +118,7 @@ export const SwapBox: React.FC<WidgetProps> = ({ config }) => {
106
118
  <div id="pageContainer" className={activeTheme}>
107
119
  <QueueManager>
108
120
  <SwapContainer
109
- fixedHeight={currentPage !== navigationRoutes.home}
110
- // style={
111
- // currentPage !== navigationRoutes.home && config?.theme?.height
112
- // ? {
113
- // height: config?.theme?.height,
114
- // width: config?.theme?.width || 'auto',
115
- // }
116
- // : {
117
- // width: config?.theme?.width || 'auto',
118
- // }
119
- // }
120
- >
121
+ fixedHeight={currentPage !== navigationRoutes.home}>
121
122
  <AppRouter
122
123
  lastConnectedWallet={lastConnectedWalletWithNetwork}
123
124
  disconnectedWallet={disconnectedWallet}
@@ -47,6 +47,7 @@ export function ConfirmSwapPage() {
47
47
  const customSlippage = useSettingsStore.use.customSlippage();
48
48
  const inputUsdValue = useBestRouteStore.use.inputUsdValue();
49
49
  const outputUsdValue = useBestRouteStore.use.outputUsdValue();
50
+ const setInputAmount = useBestRouteStore.use.setInputAmount();
50
51
 
51
52
  const bestRouteloadingStatus = getBestRouteStatus(
52
53
  fetchingBestRoute,
@@ -96,7 +97,6 @@ export function ConfirmSwapPage() {
96
97
 
97
98
  return (
98
99
  <ConfirmSwap
99
- // @ts-ignore
100
100
  requiredWallets={getRequiredChains(bestRoute)}
101
101
  selectableWallets={selectableWallets}
102
102
  onBack={navigateBackFrom.bind(null, navigationRoutes.confirmSwap)}
@@ -106,13 +106,15 @@ export function ConfirmSwapPage() {
106
106
  manager?.create(
107
107
  'swap',
108
108
  { swapDetails: swap },
109
- // @ts-ignore
110
109
  { id: swap.requestId }
111
110
  );
112
111
  setSelectedSwap(swap.requestId);
113
112
  navigate(navigationRoutes.swaps + `/${swap.requestId}`, {
114
113
  replace: true,
115
114
  });
115
+ setTimeout(() => {
116
+ setInputAmount('');
117
+ }, 0);
116
118
  }
117
119
  });
118
120
  }}
@@ -15,11 +15,14 @@ export function HistoryPage() {
15
15
  const { manager } = useManager();
16
16
  const pendingSwaps = getPendingSwaps(manager).map(({ swap }) => swap);
17
17
 
18
+ const loading = !manager?.isLoaded();
19
+
18
20
  return (
19
21
  <History
20
22
  list={pendingSwaps}
21
23
  groupBy={groupSwapsByDate}
22
- onSwapClick={requestId => {
24
+ loading={loading}
25
+ onSwapClick={(requestId) => {
23
26
  setSelectedSwap(requestId);
24
27
  navigate(navigationRoutes.swaps + `/${requestId}`, { replace: true });
25
28
  }}
@@ -36,6 +36,7 @@ import {
36
36
  import BigNumber from 'bignumber.js';
37
37
  import { HeaderButtons } from '../components/HeaderButtons';
38
38
  import { useUiStore } from '../store/ui';
39
+ import { getFormatedBestRoute } from '../utils/routing';
39
40
 
40
41
  const Container = styled('div', {
41
42
  display: 'flex',
@@ -110,7 +111,6 @@ export function Home() {
110
111
  outputUsdValue
111
112
  );
112
113
 
113
- const inputIsZero = inputAmount === '0';
114
114
  const swapButtonState = getSwapButtonState(
115
115
  loadingMetaStatus,
116
116
  accounts,
@@ -120,7 +120,7 @@ export function Home() {
120
120
  highValueLoss,
121
121
  priceImpactCanNotBeComputed,
122
122
  needsToWarnEthOnPath,
123
- inputIsZero
123
+ inputAmount
124
124
  );
125
125
 
126
126
  const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
@@ -178,7 +178,7 @@ export function Home() {
178
178
  <BestRoute
179
179
  error={bestRouteError}
180
180
  loading={fetchingBestRoute}
181
- data={bestRoute}
181
+ data={getFormatedBestRoute(bestRoute)}
182
182
  totalFee={numberToString(totalFeeInUsd, 0, 2)}
183
183
  feeWarning={highFee}
184
184
  totalTime={secondsToString(totalArrivalTime(bestRoute))}
@@ -191,13 +191,11 @@ export function Home() {
191
191
  {hasLimitError(bestRoute) && (
192
192
  <Alert type="error" title={`${swap?.swapperId} Limit`}>
193
193
  <>
194
- <Typography variant="body2">{fromAmountRangeError}</Typography>
195
- <br />
196
194
  <Typography variant="body2">
197
- Yours: {numberToString(swap?.fromAmount || null)}
198
- {swap?.from.symbol}
195
+ {`${fromAmountRangeError}, Yours: ${numberToString(
196
+ swap?.fromAmount || null
197
+ )} ${swap?.from.symbol}`}
199
198
  </Typography>
200
- <br />
201
199
  <Typography variant="body2">{recommendation}</Typography>
202
200
  </>
203
201
  </Alert>
@@ -1,10 +1,10 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React from 'react';
2
2
  import { navigationRoutes } from '../constants/navigationRoutes';
3
3
  import useCopyToClipboard from '../hooks/useCopyToClipboard';
4
4
  import { useManager } from '@rango-dev/queue-manager-react';
5
5
  import { useNavigateBack } from '../hooks/useNavigateBack';
6
6
  import { getPendingSwaps } from '../utils/queue';
7
- import { SwapHistory, Spacer } from '@rango-dev/ui';
7
+ import { SwapHistory } from '@rango-dev/ui';
8
8
  import { useUiStore } from '../store/ui';
9
9
  import {
10
10
  cancelSwap,
@@ -25,11 +25,10 @@ import {
25
25
  isNetworkStatusInWarningState,
26
26
  shouldRetrySwap,
27
27
  } from '../utils/swap';
28
- import { TokenPreview } from '../components/TokenPreview';
29
- import { numberToString } from '../utils/numbers';
30
28
  //@ts-ignore
31
29
  import { t } from 'i18next';
32
30
  import { SwapDetailsPlaceholder } from '../components/SwapDetailsPlaceholder';
31
+ import { getFormatedPendingSwap } from '../utils/routing';
33
32
 
34
33
  export function SwapDetailsPage() {
35
34
  const selectedSwapRequestId = useUiStore.use.selectedSwapRequestId();
@@ -40,14 +39,6 @@ export function SwapDetailsPage() {
40
39
  const [isCopied, handleCopy] = useCopyToClipboard(2000);
41
40
  const { manager } = useManager();
42
41
 
43
- const [loading, setLoading] = useState(true);
44
-
45
- useEffect(() => {
46
- setTimeout(() => {
47
- setLoading(false);
48
- }, 5000);
49
- }, []);
50
-
51
42
  const pendingSwaps = getPendingSwaps(manager);
52
43
  const selectedSwap = pendingSwaps.find(
53
44
  ({ swap }) => swap.requestId === selectedSwapRequestId
@@ -58,6 +49,7 @@ export function SwapDetailsPage() {
58
49
  if (swap) cancelSwap(swap);
59
50
  };
60
51
  const swap = selectedSwap?.swap;
52
+ const loading = !manager?.isLoaded();
61
53
 
62
54
  if (!swap)
63
55
  return (
@@ -68,11 +60,6 @@ export function SwapDetailsPage() {
68
60
  />
69
61
  );
70
62
 
71
- const firstStep = swap.steps[0];
72
- const lastStep = swap.steps[swap.steps.length - 1];
73
- const fromAmount = numberToString(swap.inputAmount);
74
- const toAmount = numberToString(swap.simulationResult.outputAmount);
75
-
76
63
  const currentStep = getCurrentStep(swap);
77
64
 
78
65
  const currentStepBlockchain = currentStep
@@ -106,12 +93,13 @@ export function SwapDetailsPage() {
106
93
  return (
107
94
  <SwapHistory
108
95
  onBack={navigateBackFrom.bind(null, navigationRoutes.swapDetails)}
96
+ /* TODO: It was temporarily removed to find a better solution*/
97
+ /*
109
98
  previewInputs={
110
99
  <>
111
100
  <TokenPreview
112
101
  chain={{
113
102
  displayName: firstStep?.fromBlockchain || '',
114
- // @ts-ignore
115
103
  logo: firstStep?.fromBlockchainLogo || '',
116
104
  }}
117
105
  token={{
@@ -126,7 +114,6 @@ export function SwapDetailsPage() {
126
114
  <TokenPreview
127
115
  chain={{
128
116
  displayName: lastStep?.toBlockchain || '',
129
- //@ts-ignore
130
117
  logo: lastStep?.toBlockchainLogo || '',
131
118
  }}
132
119
  token={{
@@ -139,8 +126,8 @@ export function SwapDetailsPage() {
139
126
  />
140
127
  </>
141
128
  }
142
- //todo: move PendingSwap type to rango-types
143
- pendingSwap={swap}
129
+ */
130
+ pendingSwap={getFormatedPendingSwap(swap)}
144
131
  onCopy={handleCopy}
145
132
  isCopied={isCopied}
146
133
  onCancel={onCancel}