@rango-dev/widget-embedded 0.12.1-next.19 → 0.12.1-next.20
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/dist/Widget.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts +3 -2
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/hooks/useNavigateBack.d.ts.map +1 -1
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Widget.tsx +5 -0
- package/src/components/AppRouter.tsx +36 -6
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +10 -1
- package/src/hooks/useNavigateBack.ts +10 -0
- package/src/hooks/useSwapInput.ts +7 -2
- package/src/pages/ConfirmSwapPage.tsx +1 -7
- package/src/pages/HistoryPage.tsx +1 -1
- package/src/pages/SelectSwapItemsPage.tsx +6 -1
- package/src/utils/wallets.ts +11 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfirmSwapPage.d.ts","sourceRoot":"","sources":["../../src/pages/ConfirmSwapPage.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAoB7C,OAAO,KAA8B,MAAM,OAAO,CAAC;AA4EnD,KAAK,SAAS,GAAG;IACf,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,CAAC;AAEF,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"ConfirmSwapPage.d.ts","sourceRoot":"","sources":["../../src/pages/ConfirmSwapPage.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAoB7C,OAAO,KAA8B,MAAM,OAAO,CAAC;AA4EnD,KAAK,SAAS,GAAG;IACf,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,CAAC;AAEF,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,qBAua/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectSwapItemsPage.d.ts","sourceRoot":"","sources":["../../src/pages/SelectSwapItemsPage.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAS,MAAM,WAAW,CAAC;AAI9C,OAAO,KAA8B,MAAM,OAAO,CAAC;AAgBnD,UAAU,SAAS;IACjB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,eAAe,CAAC,EAAE,KAAK,EAAE,CAAC;IAC1B,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC;CACxB;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"SelectSwapItemsPage.d.ts","sourceRoot":"","sources":["../../src/pages/SelectSwapItemsPage.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAS,MAAM,WAAW,CAAC;AAI9C,OAAO,KAA8B,MAAM,OAAO,CAAC;AAgBnD,UAAU,SAAS;IACjB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,eAAe,CAAC,EAAE,KAAK,EAAE,CAAC;IAC1B,YAAY,CAAC,EAAE,KAAK,EAAE,CAAC;CACxB;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,qBA4InD"}
|
package/package.json
CHANGED
package/src/Widget.tsx
CHANGED
|
@@ -25,6 +25,11 @@ const MainContainer = styled('div', {
|
|
|
25
25
|
justifyContent: 'center',
|
|
26
26
|
alignItems: 'center',
|
|
27
27
|
fontFamily: '$widget',
|
|
28
|
+
boxSizing: 'border-box',
|
|
29
|
+
'& *, *::before, *::after': {
|
|
30
|
+
boxSizing: 'inherit',
|
|
31
|
+
listStyleType: 'none',
|
|
32
|
+
},
|
|
28
33
|
});
|
|
29
34
|
|
|
30
35
|
export type WidgetProps = {
|
|
@@ -1,11 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import type { WalletType } from '@rango-dev/wallets-shared';
|
|
2
|
+
import type { PropsWithChildren } from 'react';
|
|
3
|
+
|
|
3
4
|
import { useQueueManager } from '@rango-dev/queue-manager-rango-preset';
|
|
4
|
-
import { WalletType } from '@rango-dev/wallets-shared';
|
|
5
|
-
import { UpdateUrl } from './UpdateUrl';
|
|
6
|
-
import { useMetaStore } from '../store/meta';
|
|
7
5
|
import { useWallets } from '@rango-dev/wallets-react';
|
|
8
6
|
import { isEvmBlockchain } from 'rango-types';
|
|
7
|
+
import React, { useEffect, useRef } from 'react';
|
|
8
|
+
import { MemoryRouter, useInRouterContext } from 'react-router';
|
|
9
|
+
import { useLocation, useNavigate } from 'react-router-dom';
|
|
10
|
+
|
|
11
|
+
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
12
|
+
import { Home } from '../pages/Home';
|
|
13
|
+
import { useMetaStore } from '../store/meta';
|
|
14
|
+
|
|
15
|
+
import { UpdateUrl } from './UpdateUrl';
|
|
16
|
+
|
|
17
|
+
function Route(props: PropsWithChildren) {
|
|
18
|
+
const location = useLocation();
|
|
19
|
+
const navigate = useNavigate();
|
|
20
|
+
const ref = useRef(true);
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (
|
|
24
|
+
location.pathname === '/' + navigationRoutes.confirmSwap &&
|
|
25
|
+
ref.current
|
|
26
|
+
) {
|
|
27
|
+
navigate(navigationRoutes.home + location.search, { state: 'redirect' });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
ref.current = false;
|
|
31
|
+
}, []);
|
|
32
|
+
|
|
33
|
+
if (location.pathname === '/' + navigationRoutes.confirmSwap && ref.current) {
|
|
34
|
+
return <Home />;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return <> {props.children}</>;
|
|
38
|
+
}
|
|
9
39
|
|
|
10
40
|
export function AppRouter({
|
|
11
41
|
children,
|
|
@@ -16,7 +46,7 @@ export function AppRouter({
|
|
|
16
46
|
clearDisconnectedWallet: () => void;
|
|
17
47
|
}) {
|
|
18
48
|
const isRouterInContext = useInRouterContext();
|
|
19
|
-
const Router = isRouterInContext ?
|
|
49
|
+
const Router = isRouterInContext ? Route : MemoryRouter;
|
|
20
50
|
const { blockchains } = useMetaStore.use.meta();
|
|
21
51
|
const { canSwitchNetworkTo } = useWallets();
|
|
22
52
|
|
|
@@ -15,8 +15,10 @@ import {
|
|
|
15
15
|
WalletIcon,
|
|
16
16
|
} from '@rango-dev/ui';
|
|
17
17
|
import React, { useEffect, useState } from 'react';
|
|
18
|
+
import { useNavigate } from 'react-router-dom';
|
|
18
19
|
|
|
19
20
|
import { getConfirmSwapErrorMessage } from '../../constants/errors';
|
|
21
|
+
import { navigationRoutes } from '../../constants/navigationRoutes';
|
|
20
22
|
import { getRouteWarningMessage } from '../../constants/warnings';
|
|
21
23
|
import { useBestRouteStore } from '../../store/bestRoute';
|
|
22
24
|
import { useMetaStore } from '../../store/meta';
|
|
@@ -51,6 +53,7 @@ export function ConfirmWalletsModal(props: PropTypes) {
|
|
|
51
53
|
const {
|
|
52
54
|
bestRoute,
|
|
53
55
|
setSelectedWallets: selectRouteWallets,
|
|
56
|
+
routeWalletsConfirmed,
|
|
54
57
|
setRouteWalletConfirmed,
|
|
55
58
|
customDestination,
|
|
56
59
|
setCustomDestination,
|
|
@@ -229,10 +232,16 @@ export function ConfirmWalletsModal(props: PropTypes) {
|
|
|
229
232
|
|
|
230
233
|
const modalContainer = document.querySelector('#swap-box') as HTMLDivElement;
|
|
231
234
|
|
|
235
|
+
const navigate = useNavigate();
|
|
232
236
|
return (
|
|
233
237
|
<Modal
|
|
234
238
|
open={open}
|
|
235
|
-
onClose={
|
|
239
|
+
onClose={() => {
|
|
240
|
+
if (!routeWalletsConfirmed) {
|
|
241
|
+
navigate(navigationRoutes.home, { replace: true });
|
|
242
|
+
}
|
|
243
|
+
onClose();
|
|
244
|
+
}}
|
|
236
245
|
dismissible={!showMoreWalletFor}
|
|
237
246
|
container={modalContainer}
|
|
238
247
|
{...(!showMoreWalletFor && {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { useInRouterContext, useNavigate } from 'react-router-dom';
|
|
2
2
|
|
|
3
3
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
4
|
+
import { useBestRouteStore } from '../store/bestRoute';
|
|
4
5
|
|
|
5
6
|
export function useNavigateBack() {
|
|
6
7
|
const isRouterInContext = useInRouterContext();
|
|
7
8
|
const navigate = useNavigate();
|
|
9
|
+
const routeWalletsConfirmed = useBestRouteStore.use.routeWalletsConfirmed();
|
|
8
10
|
|
|
9
11
|
navigationRoutes;
|
|
10
12
|
|
|
@@ -20,6 +22,14 @@ export function useNavigateBack() {
|
|
|
20
22
|
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
21
23
|
navigate(-1);
|
|
22
24
|
} else {
|
|
25
|
+
if (
|
|
26
|
+
[navigationRoutes.settings, navigationRoutes.wallets].includes(
|
|
27
|
+
currentRoute
|
|
28
|
+
) &&
|
|
29
|
+
routeWalletsConfirmed
|
|
30
|
+
) {
|
|
31
|
+
return navigate('/' + navigationRoutes.confirmSwap, { replace: true });
|
|
32
|
+
}
|
|
23
33
|
if (
|
|
24
34
|
[
|
|
25
35
|
navigationRoutes.fromSwap,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
import { useBestRouteStore } from '../store/bestRoute';
|
|
4
4
|
import { useSettingsStore } from '../store/settings';
|
|
@@ -41,6 +41,7 @@ export function useSwapInput(): UseSwapInput {
|
|
|
41
41
|
disabledLiquiditySources,
|
|
42
42
|
} = useSettingsStore();
|
|
43
43
|
const [error, setError] = useState('');
|
|
44
|
+
const prevDisabledLiquiditySources = useRef(disabledLiquiditySources);
|
|
44
45
|
const userSlippage = customSlippage ?? slippage;
|
|
45
46
|
const hasTokensValue = !fromToken || !toToken;
|
|
46
47
|
const shouldSkipRequest =
|
|
@@ -101,9 +102,13 @@ export function useSwapInput(): UseSwapInput {
|
|
|
101
102
|
}, [inputAmount, shouldSkipRequest]);
|
|
102
103
|
|
|
103
104
|
useEffect(() => {
|
|
104
|
-
|
|
105
|
+
const disabledLiquiditySourceReset =
|
|
106
|
+
!!prevDisabledLiquiditySources.current.length &&
|
|
107
|
+
!disabledLiquiditySources.length;
|
|
108
|
+
if (!shouldSkipRequest && disabledLiquiditySourceReset) {
|
|
105
109
|
fetch();
|
|
106
110
|
}
|
|
111
|
+
prevDisabledLiquiditySources.current = disabledLiquiditySources;
|
|
107
112
|
return cancelFetch;
|
|
108
113
|
}, [disabledLiquiditySources.length]);
|
|
109
114
|
|
|
@@ -250,12 +250,6 @@ export function ConfirmSwapPage(props: PropTypes) {
|
|
|
250
250
|
}
|
|
251
251
|
}, []);
|
|
252
252
|
|
|
253
|
-
useEffect(() => {
|
|
254
|
-
if (!showWallets && !routeWalletsConfirmed) {
|
|
255
|
-
navigate(navigationRoutes.home, { replace: true });
|
|
256
|
-
}
|
|
257
|
-
}, [showWallets, routeWalletsConfirmed]);
|
|
258
|
-
|
|
259
253
|
useEffect(() => {
|
|
260
254
|
const routeChanged =
|
|
261
255
|
confirmSwapResult.warnings?.route?.type &&
|
|
@@ -421,7 +415,7 @@ export function ConfirmSwapPage(props: PropTypes) {
|
|
|
421
415
|
{showWallets && (
|
|
422
416
|
<ConfirmWalletsModal
|
|
423
417
|
open={showWallets}
|
|
424
|
-
onClose={setShowWallets
|
|
418
|
+
onClose={() => setShowWallets(false)}
|
|
425
419
|
onCancel={cancelFetch}
|
|
426
420
|
loading={fetchingConfirmationRoute}
|
|
427
421
|
onCheckBalance={onConfirmSwap}
|
|
@@ -100,7 +100,12 @@ export function SelectSwapItemsPage(props: PropTypes) {
|
|
|
100
100
|
return (
|
|
101
101
|
<Layout
|
|
102
102
|
header={{
|
|
103
|
-
onBack:
|
|
103
|
+
onBack: () =>
|
|
104
|
+
navigateBackFrom(
|
|
105
|
+
type === 'from'
|
|
106
|
+
? navigationRoutes.fromSwap
|
|
107
|
+
: navigationRoutes.toSwap
|
|
108
|
+
),
|
|
104
109
|
title: i18n.t('Swap {type}', { type }),
|
|
105
110
|
}}>
|
|
106
111
|
<BlockchainsSection
|
package/src/utils/wallets.ts
CHANGED
|
@@ -135,19 +135,19 @@ export function prepareAccountsForWalletStore(
|
|
|
135
135
|
/*
|
|
136
136
|
* In some cases we can handle unknown network by checking its address
|
|
137
137
|
* pattern and act on it.
|
|
138
|
-
* Example: showing our evm compatible
|
|
138
|
+
* Example: showing our evm compatible network when the unknown network is evm.
|
|
139
139
|
* Otherwise, we stop executing this function.
|
|
140
140
|
*/
|
|
141
|
-
const
|
|
141
|
+
const isUnknownAndEvmBased =
|
|
142
142
|
network === Networks.Unknown && isEvmAddress(address);
|
|
143
|
-
if (isUnknown && !
|
|
143
|
+
if (isUnknown && !isUnknownAndEvmBased) {
|
|
144
144
|
return;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
const isEvmBasedChain = evmBasedChains.includes(network);
|
|
148
148
|
|
|
149
149
|
// If it's an evm network, we will add the address to all the evm chains.
|
|
150
|
-
if (isEvmBasedChain ||
|
|
150
|
+
if (isEvmBasedChain || isUnknownAndEvmBased) {
|
|
151
151
|
/*
|
|
152
152
|
* all evm chains are not supported in wallets, so we are adding
|
|
153
153
|
* only to those that are supported by wallet.
|
|
@@ -158,7 +158,7 @@ export function prepareAccountsForWalletStore(
|
|
|
158
158
|
|
|
159
159
|
evmChainsSupportedByWallet.forEach((network) => {
|
|
160
160
|
/*
|
|
161
|
-
* EVM addresses are not case
|
|
161
|
+
* EVM addresses are not case sensitive.
|
|
162
162
|
* Some wallets like Binance-chain return some letters in uppercase which produces bugs in our wallet state.
|
|
163
163
|
*/
|
|
164
164
|
addAccount(network, address.toLowerCase());
|
|
@@ -311,7 +311,7 @@ export function resetConnectedWalletState(
|
|
|
311
311
|
|
|
312
312
|
export const calculateWalletUsdValue = (connectedWallet: ConnectedWallet[]) => {
|
|
313
313
|
const uniqueAccountAddresses = new Set<string | null>();
|
|
314
|
-
const
|
|
314
|
+
const uniqueBalance: ConnectedWallet[] = connectedWallet?.reduce(
|
|
315
315
|
(acc: ConnectedWallet[], current: ConnectedWallet) => {
|
|
316
316
|
return acc.findIndex(
|
|
317
317
|
(i) => i.address === current.address && i.chain === current.chain
|
|
@@ -323,7 +323,7 @@ export const calculateWalletUsdValue = (connectedWallet: ConnectedWallet[]) => {
|
|
|
323
323
|
[]
|
|
324
324
|
);
|
|
325
325
|
|
|
326
|
-
const modifiedWalletBlockchains =
|
|
326
|
+
const modifiedWalletBlockchains = uniqueBalance?.map((chain) => {
|
|
327
327
|
const modifiedWalletBlockchain: Blockchain = {
|
|
328
328
|
name: chain.chain,
|
|
329
329
|
accounts: [],
|
|
@@ -348,10 +348,10 @@ export const calculateWalletUsdValue = (connectedWallet: ConnectedWallet[]) => {
|
|
|
348
348
|
?.reduce((a, b) => a.plus(b), ZERO) || ZERO
|
|
349
349
|
).toString();
|
|
350
350
|
|
|
351
|
-
return
|
|
351
|
+
return numberWithThousandSeparator(total);
|
|
352
352
|
};
|
|
353
353
|
|
|
354
|
-
function
|
|
354
|
+
function numberWithThousandSeparator(number: string | number): string {
|
|
355
355
|
const parts = number.toString().split('.');
|
|
356
356
|
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
357
357
|
return parts.join('.');
|
|
@@ -470,9 +470,9 @@ export function getSortedTokens(
|
|
|
470
470
|
connectedWallets: ConnectedWallet[],
|
|
471
471
|
otherChainTokens: TokenWithBalance[]
|
|
472
472
|
): TokenWithBalance[] {
|
|
473
|
-
const
|
|
473
|
+
const fromChainEqualsToToBlockchain =
|
|
474
474
|
chain?.name === otherChainTokens[0]?.name;
|
|
475
|
-
if (
|
|
475
|
+
if (fromChainEqualsToToBlockchain) {
|
|
476
476
|
return otherChainTokens;
|
|
477
477
|
}
|
|
478
478
|
const filteredTokens = tokens.filter(
|