@rango-dev/widget-embedded 0.21.0 → 0.21.1-next.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"WalletsPage.d.ts","sourceRoot":"","sources":["../../src/pages/WalletsPage.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAuBxC,eAAO,MAAM,mBAAmB,OAAQ,CAAC;AACzC,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,wBAAgB,WAAW,sBAoE1B"}
1
+ {"version":3,"file":"WalletsPage.d.ts","sourceRoot":"","sources":["../../src/pages/WalletsPage.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAuBxC,eAAO,MAAM,mBAAmB,OAAQ,CAAC;AACzC,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,wBAAgB,WAAW,sBA0E1B"}
@@ -29,4 +29,5 @@ export declare function getAddress({ chain, connectedWallets, walletType, }: {
29
29
  export declare function createTokenHash(token: Asset): TokenHash;
30
30
  export declare function makeTokensBalance(connectedWallets: ConnectedWallet[]): TokensBalance;
31
31
  export declare const isFetchingBalance: (connectedWallets: ConnectedWallet[], blockchain: string) => boolean;
32
+ export declare function hashWalletsState(walletsInfo: ModalWalletInfo[]): string;
32
33
  //# sourceMappingURL=wallets.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallets.d.ts","sourceRoot":"","sources":["../../src/utils/wallets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,KAAK,EAAE,UAAU,IAAI,eAAe,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,KAAK,EACV,KAAK,EACL,OAAO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ED,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,gBAAgB,EAChB,UAAU,GACX,EAAE;IACD,gBAAgB,EAAE,eAAe,EAAE,CAAC;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,MAAM,GAAG,SAAS,CAMrB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,CAEvD;AAED,wBAAgB,iBAAiB,CAAC,gBAAgB,EAAE,eAAe,EAAE,iBAmCpE;AAED,eAAO,MAAM,iBAAiB,qBACV,eAAe,EAAE,cACvB,MAAM,YAIjB,CAAC;AAEJ,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,eAAe,EAAE,UAE9D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.21.0",
3
+ "version": "0.21.1-next.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -25,7 +25,7 @@
25
25
  "@rango-dev/queue-manager-core": "^0.25.0",
26
26
  "@rango-dev/queue-manager-rango-preset": "^0.26.0",
27
27
  "@rango-dev/queue-manager-react": "^0.25.0",
28
- "@rango-dev/ui": "^0.27.0",
28
+ "@rango-dev/ui": "^0.27.1-next.0",
29
29
  "@rango-dev/wallets-react": "^0.12.0",
30
30
  "@rango-dev/wallets-shared": "^0.26.0",
31
31
  "bignumber.js": "^9.1.1",
@@ -47,4 +47,4 @@
47
47
  "publishConfig": {
48
48
  "access": "public"
49
49
  }
50
- }
50
+ }
@@ -59,23 +59,24 @@ export function WalletList(props: PropTypes) {
59
59
  useState<'in-progress' | 'completed' | 'rejected' | null>(null);
60
60
  const { suggestAndConnect } = useWallets();
61
61
  let modalTimerId: ReturnType<typeof setTimeout> | null = null;
62
- const { list, error, handleClick } = useWalletList({
63
- config,
64
- chain,
65
- onBeforeConnect: (type) => {
66
- modalTimerId = setTimeout(() => {
67
- setOpenWalletStateModal(type);
68
- }, TIME_TO_IGNORE_MODAL);
69
- },
70
- onConnect: () => {
71
- if (modalTimerId) {
72
- clearTimeout(modalTimerId);
73
- }
74
- setTimeout(() => {
75
- setOpenWalletStateModal('');
76
- }, TIME_TO_CLOSE_MODAL);
77
- },
78
- });
62
+ const { list, error, handleClick, disconnectConnectingWallets } =
63
+ useWalletList({
64
+ config,
65
+ chain,
66
+ onBeforeConnect: (type) => {
67
+ modalTimerId = setTimeout(() => {
68
+ setOpenWalletStateModal(type);
69
+ }, TIME_TO_IGNORE_MODAL);
70
+ },
71
+ onConnect: () => {
72
+ if (modalTimerId) {
73
+ clearTimeout(modalTimerId);
74
+ }
75
+ setTimeout(() => {
76
+ setOpenWalletStateModal('');
77
+ }, TIME_TO_CLOSE_MODAL);
78
+ },
79
+ });
79
80
  const [sortedList, setSortedList] = useState<WalletInfo[]>(list);
80
81
  const numberOfSupportedWallets = list.length;
81
82
  const shouldShowMoreWallets = limit && numberOfSupportedWallets - limit > 0;
@@ -133,6 +134,11 @@ export function WalletList(props: PropTypes) {
133
134
  };
134
135
  }, [addingExperimentalChainStatus]);
135
136
 
137
+ const handleCloseWalletModal = () => {
138
+ disconnectConnectingWallets();
139
+ setOpenWalletStateModal('');
140
+ };
141
+
136
142
  return (
137
143
  <>
138
144
  {sortedList.slice(0, limit).map((wallet) => {
@@ -193,7 +199,7 @@ export function WalletList(props: PropTypes) {
193
199
  <>
194
200
  <WalletModal
195
201
  open={openWalletStateModal === wallet.type}
196
- onClose={() => setOpenWalletStateModal('')}
202
+ onClose={handleCloseWalletModal}
197
203
  image={wallet.image}
198
204
  state={wallet.state}
199
205
  error={error}
@@ -1,8 +1,8 @@
1
1
  import type { WalletStateContentProps } from './SwapDetailsModal.types';
2
2
 
3
- import { MessageBox, Wallet } from '@rango-dev/ui';
3
+ import { MessageBox, Wallet, WalletState } from '@rango-dev/ui';
4
4
  import { useWallets } from '@rango-dev/wallets-react';
5
- import React from 'react';
5
+ import React, { useEffect, useRef } from 'react';
6
6
 
7
7
  import { getContainer } from '../../utils/common';
8
8
  import { mapStatusToWalletState } from '../../utils/wallets';
@@ -18,14 +18,40 @@ export const WalletStateContent = (props: WalletStateContentProps) => {
18
18
  showWalletButton,
19
19
  walletButtonDisabled,
20
20
  } = props;
21
- const { connect, getWalletInfo, state } = useWallets();
21
+ const { connect, getWalletInfo, state, disconnect } = useWallets();
22
22
  const walletType = currentStepWallet?.walletType;
23
23
  const walletState = walletType
24
24
  ? mapStatusToWalletState(state(walletType))
25
25
  : null;
26
+ const componentWillUnmount = useRef(false);
27
+
26
28
  const walletInfo = walletType ? getWalletInfo(walletType) : null;
27
29
  const shouldShowWallet =
28
30
  showWalletButton && !!walletType && !!walletState && !!walletInfo;
31
+
32
+ /*
33
+ * The order of useEffects is crucial.
34
+ * 1- The first useEffect for componentWillUnmount sets its value to true
35
+ */
36
+ useEffect(() => {
37
+ return () => {
38
+ componentWillUnmount.current = true;
39
+ };
40
+ }, []);
41
+
42
+ // 2- The second useEffect checks if componentWillUnmount is true then it disconnects connecting wallet
43
+ useEffect(() => {
44
+ return () => {
45
+ if (
46
+ componentWillUnmount.current &&
47
+ walletType &&
48
+ walletState === WalletState.CONNECTING
49
+ ) {
50
+ void disconnect(walletType);
51
+ }
52
+ };
53
+ }, [walletState]);
54
+
29
55
  return (
30
56
  <>
31
57
  <MessageBox type={type} title={title} description={message} />
@@ -9,12 +9,13 @@ import {
9
9
  type WalletType,
10
10
  WalletTypes,
11
11
  } from '@rango-dev/wallets-shared';
12
- import { useEffect, useState } from 'react';
12
+ import { useCallback, useEffect, useRef, useState } from 'react';
13
13
 
14
14
  import { useAppStore } from '../store/AppStore';
15
15
  import { useWalletsStore } from '../store/wallets';
16
16
  import { configWalletsToWalletName } from '../utils/providers';
17
17
  import {
18
+ hashWalletsState,
18
19
  isExperimentalChain,
19
20
  mapWalletTypesToWalletInfo,
20
21
  sortWalletsBasedOnConnectionState,
@@ -39,6 +40,7 @@ export function useWalletList(params: Params) {
39
40
  const { state, disconnect, getWalletInfo, connect } = useWallets();
40
41
  const { connectedWallets } = useWalletsStore();
41
42
  const blockchains = useAppStore().blockchains();
43
+ const componentWillUnmount = useRef(false);
42
44
 
43
45
  /** It can be what has been set by widget config or as a fallback we use all the supported wallets by our library */
44
46
  const listAvailableWalletTypes =
@@ -87,21 +89,34 @@ export function useWalletList(params: Params) {
87
89
  }
88
90
  };
89
91
 
90
- const disconnectConnectingWallets = () => {
92
+ const disconnectConnectingWallets = useCallback(() => {
91
93
  const connectingWallets =
92
94
  wallets?.filter((wallet) => wallet.state === WalletState.CONNECTING) ||
93
95
  [];
94
96
  for (const wallet of connectingWallets) {
95
97
  void disconnect(wallet.type);
96
98
  }
97
- };
99
+ }, [hashWalletsState(wallets)]);
98
100
 
101
+ /*
102
+ * The order of useEffects is crucial.
103
+ * 1- The first useEffect for componentWillUnmount sets its value to true
104
+ */
99
105
  useEffect(() => {
100
106
  return () => {
101
- disconnectConnectingWallets();
107
+ componentWillUnmount.current = true;
102
108
  };
103
109
  }, []);
104
110
 
111
+ // 2- The second useEffect checks if componentWillUnmount is true then it disconnects connecting wallets
112
+ useEffect(() => {
113
+ return () => {
114
+ if (componentWillUnmount.current) {
115
+ disconnectConnectingWallets();
116
+ }
117
+ };
118
+ }, [disconnectConnectingWallets]);
119
+
105
120
  /*
106
121
  * Atm, we only support default injected wallet for the EVM
107
122
  * so we show default wallet when there is no other evm wallet installed
@@ -141,5 +156,6 @@ export function useWalletList(params: Params) {
141
156
  ),
142
157
  error,
143
158
  handleClick,
159
+ disconnectConnectingWallets,
144
160
  };
145
161
  }
@@ -35,23 +35,29 @@ export function WalletsPage() {
35
35
  let modalTimerId: ReturnType<typeof setTimeout> | null = null;
36
36
  const isActiveTab = useUiStore.use.isActiveTab();
37
37
 
38
- const { list, handleClick, error } = useWalletList({
39
- config,
40
- onBeforeConnect: (type) => {
41
- modalTimerId = setTimeout(() => {
42
- setOpenModal(true);
43
- setSelectedWalletType(type);
44
- }, TIME_TO_IGNORE_MODAL);
45
- },
46
- onConnect: () => {
47
- if (modalTimerId) {
48
- clearTimeout(modalTimerId);
49
- }
50
- setTimeout(() => {
51
- setOpenModal(false);
52
- }, TIME_TO_CLOSE_MODAL);
53
- },
54
- });
38
+ const { list, handleClick, error, disconnectConnectingWallets } =
39
+ useWalletList({
40
+ config,
41
+ onBeforeConnect: (type) => {
42
+ modalTimerId = setTimeout(() => {
43
+ setOpenModal(true);
44
+ setSelectedWalletType(type);
45
+ }, TIME_TO_IGNORE_MODAL);
46
+ },
47
+ onConnect: () => {
48
+ if (modalTimerId) {
49
+ clearTimeout(modalTimerId);
50
+ }
51
+ setTimeout(() => {
52
+ setOpenModal(false);
53
+ }, TIME_TO_CLOSE_MODAL);
54
+ },
55
+ });
56
+
57
+ const handleCloseWalletModal = () => {
58
+ disconnectConnectingWallets();
59
+ setOpenModal(false);
60
+ };
55
61
 
56
62
  const selectedWallet = list.find(
57
63
  (wallet) => wallet.type === selectedWalletType
@@ -87,7 +93,7 @@ export function WalletsPage() {
87
93
  })}
88
94
  <WalletModal
89
95
  open={!!openModal}
90
- onClose={() => setOpenModal(false)}
96
+ onClose={handleCloseWalletModal}
91
97
  image={selectedWalletImage}
92
98
  state={selectedWalletState}
93
99
  error={error}
@@ -551,3 +551,7 @@ export const isFetchingBalance = (
551
551
  !!connectedWallets.find(
552
552
  (wallet) => wallet.chain === blockchain && wallet.loading
553
553
  );
554
+
555
+ export function hashWalletsState(walletsInfo: ModalWalletInfo[]) {
556
+ return walletsInfo.map((w) => w.state).join('-');
557
+ }