@rango-dev/widget-embedded 0.17.1-next.7 → 0.17.1-next.9

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.17.1-next.7",
3
+ "version": "0.17.1-next.9",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -19,13 +19,13 @@
19
19
  "dependencies": {
20
20
  "@lingui/core": "4.2.1",
21
21
  "@lingui/react": "4.2.1",
22
- "@rango-dev/provider-all": "^0.22.1-next.3",
22
+ "@rango-dev/provider-all": "^0.22.1-next.4",
23
23
  "@rango-dev/queue-manager-core": "^0.22.1-next.0",
24
- "@rango-dev/queue-manager-rango-preset": "^0.22.1-next.4",
24
+ "@rango-dev/queue-manager-rango-preset": "^0.22.1-next.5",
25
25
  "@rango-dev/queue-manager-react": "^0.22.1-next.0",
26
- "@rango-dev/ui": "^0.22.1-next.5",
27
- "@rango-dev/wallets-react": "^0.8.1-next.2",
28
- "@rango-dev/wallets-shared": "^0.21.1-next.2",
26
+ "@rango-dev/ui": "^0.22.1-next.6",
27
+ "@rango-dev/wallets-react": "^0.8.1-next.3",
28
+ "@rango-dev/wallets-shared": "^0.21.1-next.3",
29
29
  "bignumber.js": "^9.1.1",
30
30
  "copy-to-clipboard": "^3.3.3",
31
31
  "dayjs": "^1.11.7",
@@ -9,6 +9,7 @@ import { MemoryRouter, useInRouterContext } from 'react-router';
9
9
  import { useLocation, useNavigate } from 'react-router-dom';
10
10
 
11
11
  import { navigationRoutes } from '../constants/navigationRoutes';
12
+ import { useForceAutoConnect } from '../hooks/useForceAutoConnect';
12
13
  import { Home } from '../pages/Home';
13
14
  import { useAppStore } from '../store/AppStore';
14
15
 
@@ -49,6 +50,8 @@ export function AppRouter({
49
50
  const blockchains = useAppStore().blockchains();
50
51
  const { canSwitchNetworkTo } = useWallets();
51
52
 
53
+ useForceAutoConnect();
54
+
52
55
  const evmChains = blockchains.filter(isEvmBlockchain);
53
56
 
54
57
  useQueueManager({
@@ -57,6 +57,7 @@ export function UpdateUrl() {
57
57
  toChainString = '',
58
58
  toTokenString = '',
59
59
  fromAmount = '';
60
+ const autoConnect = searchParamsRef.current[SearchParams.AUTO_CONNECT];
60
61
  if (fetchMetaStatus !== 'success') {
61
62
  fromChainString = searchParamsRef.current[SearchParams.FROM_CHAIN];
62
63
  fromTokenString = searchParamsRef.current[SearchParams.FROM_TOKEN];
@@ -91,6 +92,9 @@ export function UpdateUrl() {
91
92
  ...(fromAmount && {
92
93
  [SearchParams.FROM_AMOUNT]: fromAmount.toString(),
93
94
  }),
95
+ ...(autoConnect && {
96
+ [SearchParams.AUTO_CONNECT]: autoConnect,
97
+ }),
94
98
  },
95
99
  { replace: true }
96
100
  );
@@ -4,4 +4,5 @@ export enum SearchParams {
4
4
  'TO_CHAIN' = 'toBlockchain',
5
5
  'TO_TOKEN' = 'toToken',
6
6
  'FROM_AMOUNT' = 'fromAmount',
7
+ 'AUTO_CONNECT' = 'autoConnect',
7
8
  }
@@ -0,0 +1,27 @@
1
+ import { useWallets } from '@rango-dev/wallets-react';
2
+ import { useEffect, useRef } from 'react';
3
+
4
+ import { SearchParams } from '../constants/searchParams';
5
+ import { useAppStore } from '../store/AppStore';
6
+
7
+ export function useForceAutoConnect(): void {
8
+ const { connect, state } = useWallets();
9
+ const initiated = useRef<{ [key: string]: boolean }>({});
10
+ const { fetchStatus } = useAppStore();
11
+ const walletType =
12
+ new URLSearchParams(location.search).get(SearchParams.AUTO_CONNECT) || '';
13
+ const walletState = state(walletType);
14
+
15
+ useEffect(() => {
16
+ const shouldTryConnect =
17
+ fetchStatus === 'success' &&
18
+ walletType &&
19
+ walletState.installed &&
20
+ !walletState.connecting &&
21
+ !walletState.connected;
22
+ if (shouldTryConnect && !initiated.current[walletType]) {
23
+ initiated.current[walletType] = true;
24
+ void connect(walletType);
25
+ }
26
+ }, [walletState, fetchStatus]);
27
+ }