@rango-dev/widget-embedded 0.1.13-next.4 → 0.1.13

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.1.13-next.4",
3
+ "version": "0.1.13",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -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}
@@ -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>
@@ -225,7 +225,7 @@ export function TokenInfo(props: PropTypes) {
225
225
  <Button
226
226
  className="selectors"
227
227
  onClick={() => {
228
- navigate(`/${props.type.toLowerCase()}-chain`);
228
+ navigate(`${props.type.toLowerCase()}-chain`);
229
229
  }}
230
230
  variant="outlined"
231
231
  disabled={loadingStatus === 'failed'}
@@ -249,7 +249,7 @@ export function TokenInfo(props: PropTypes) {
249
249
  <Button
250
250
  className="selectors"
251
251
  onClick={() => {
252
- navigate(`/${props.type.toLowerCase()}-token`);
252
+ navigate(`${props.type.toLowerCase()}-token`);
253
253
  }}
254
254
  variant="outlined"
255
255
  disabled={
@@ -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') {
@@ -36,8 +36,8 @@ export function BalanceErrors({ messages }: PropTypes) {
36
36
  </Typography>
37
37
  <Spacer size={8} direction="vertical" />
38
38
  <List showListStyle={showListStyle}>
39
- {messages.map((warning) => (
40
- <ListItem showListStyle={showListStyle}>
39
+ {messages.map((warning, index) => (
40
+ <ListItem showListStyle={showListStyle} key={index}>
41
41
  <Message variant="body2">{warning}</Message>
42
42
  </ListItem>
43
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
  };
@@ -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/lib.tsx CHANGED
@@ -15,7 +15,12 @@ import { Layout } from './components/Layout';
15
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,8 +28,13 @@ 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;
@@ -116,8 +126,7 @@ export const Widget: React.FC<WidgetProps> = ({ config }) => {
116
126
  >
117
127
  <div className={activeTheme}>
118
128
  <QueueManager>
119
- <SwapContainer
120
- fixedHeight={currentPage !== navigationRoutes.home}>
129
+ <SwapContainer fixedHeight={currentPage !== navigationRoutes.home}>
121
130
  <AppRouter
122
131
  lastConnectedWallet={lastConnectedWalletWithNetwork}
123
132
  disconnectedWallet={disconnectedWallet}
@@ -18,7 +18,7 @@ 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
 
@@ -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
  />