@dynamic-labs/sdk-react-core 2.5.0 → 2.5.2
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/CHANGELOG.md +14 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +13 -13
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.cjs +14 -5
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.d.ts +1 -1
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.js +14 -5
- package/src/lib/utils/hooks/usePromise/utils/index.d.ts +2 -0
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.cjs +4 -4
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.d.ts +1 -1
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.js +4 -4
- package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.cjs +3 -2
- package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.js +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
|
|
2
|
+
### [2.5.2](https://github.com/dynamic-labs/DynamicAuth/compare/v2.5.1...v2.5.2) (2024-08-30)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* experience in Binance in-app browser ([#6765](https://github.com/dynamic-labs/DynamicAuth/issues/6765)) ([f3f7294](https://github.com/dynamic-labs/DynamicAuth/commit/f3f7294b0801e9219392658d0ff25dd97526e830))
|
|
8
|
+
|
|
9
|
+
### [2.5.1](https://github.com/dynamic-labs/DynamicAuth/compare/v2.5.0...v2.5.1) (2024-08-25)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* on mobile only check for connection state on the primary wallet ([#6705](https://github.com/dynamic-labs/DynamicAuth/issues/6705)) ([ac2bfe2](https://github.com/dynamic-labs/DynamicAuth/commit/ac2bfe224104da92ada2d57093d24e264a0e0993))
|
|
15
|
+
|
|
2
16
|
## [2.5.0](https://github.com/dynamic-labs/DynamicAuth/compare/v2.4.0...v2.5.0) (2024-08-22)
|
|
3
17
|
|
|
4
18
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/sdk-react-core",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
@@ -17,18 +17,18 @@
|
|
|
17
17
|
"react-i18next": "13.5.0",
|
|
18
18
|
"yup": "0.32.11",
|
|
19
19
|
"react-international-phone": "4.2.5",
|
|
20
|
-
"@dynamic-labs/iconic": "2.5.
|
|
21
|
-
"@dynamic-labs/logger": "2.5.
|
|
22
|
-
"@dynamic-labs/multi-wallet": "2.5.
|
|
23
|
-
"@dynamic-labs/rpc-provider-ethereum": "2.5.
|
|
24
|
-
"@dynamic-labs/rpc-provider-solana": "2.5.
|
|
25
|
-
"@dynamic-labs/rpc-providers": "2.5.
|
|
26
|
-
"@dynamic-labs/store": "2.5.
|
|
27
|
-
"@dynamic-labs/types": "2.5.
|
|
28
|
-
"@dynamic-labs/utils": "2.5.
|
|
29
|
-
"@dynamic-labs/viem-utils": "2.5.
|
|
30
|
-
"@dynamic-labs/wallet-book": "2.5.
|
|
31
|
-
"@dynamic-labs/wallet-connector-core": "2.5.
|
|
20
|
+
"@dynamic-labs/iconic": "2.5.2",
|
|
21
|
+
"@dynamic-labs/logger": "2.5.2",
|
|
22
|
+
"@dynamic-labs/multi-wallet": "2.5.2",
|
|
23
|
+
"@dynamic-labs/rpc-provider-ethereum": "2.5.2",
|
|
24
|
+
"@dynamic-labs/rpc-provider-solana": "2.5.2",
|
|
25
|
+
"@dynamic-labs/rpc-providers": "2.5.2",
|
|
26
|
+
"@dynamic-labs/store": "2.5.2",
|
|
27
|
+
"@dynamic-labs/types": "2.5.2",
|
|
28
|
+
"@dynamic-labs/utils": "2.5.2",
|
|
29
|
+
"@dynamic-labs/viem-utils": "2.5.2",
|
|
30
|
+
"@dynamic-labs/wallet-book": "2.5.2",
|
|
31
|
+
"@dynamic-labs/wallet-connector-core": "2.5.2",
|
|
32
32
|
"eventemitter3": "5.0.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
@@ -161,12 +161,21 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
161
161
|
setConnectedWalletsInfo(updatedConnectedWalletsInfo);
|
|
162
162
|
};
|
|
163
163
|
// Updates connected wallet (network and address) and verifies connected wallet connection
|
|
164
|
-
const refreshConnectedWallet = (
|
|
164
|
+
const refreshConnectedWallet = (wallet) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
165
|
+
const walletConnector = wallet.connector;
|
|
165
166
|
if (shouldManuallyReconnectOnRefresh.shouldManuallyReconnectOnRefresh(walletConnector)) {
|
|
166
167
|
yield walletConnector.connect();
|
|
167
168
|
}
|
|
168
|
-
|
|
169
|
-
|
|
169
|
+
// Hardcoded binance key for now because binance wallet keeps on
|
|
170
|
+
// firing network change event on getAddress() call, which leads to infinite loop
|
|
171
|
+
// and we need to call getAddress to get the most recent address of the wallet
|
|
172
|
+
// when the account was changed in the wallet
|
|
173
|
+
const currentWalletConnectorAddress = wallet.key === 'binance'
|
|
174
|
+
? wallet.address
|
|
175
|
+
: yield walletConnector.getAddress();
|
|
176
|
+
if (wallet.connected &&
|
|
177
|
+
currentWalletConnectorAddress &&
|
|
178
|
+
handleConnectedWallet) {
|
|
170
179
|
const shouldProceedWithConnection = yield handleConnectedWallet({
|
|
171
180
|
address: currentWalletConnectorAddress,
|
|
172
181
|
chain: walletConnector.connectedChain,
|
|
@@ -174,13 +183,13 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
174
183
|
});
|
|
175
184
|
if (!shouldProceedWithConnection) {
|
|
176
185
|
walletConnectorCore.logger.info('Connection was not established because handleConnectedWallet returned false');
|
|
177
|
-
disconnectWallet(
|
|
186
|
+
disconnectWallet(wallet.id);
|
|
178
187
|
setShowAuthFlow(false, { emitCancelAuth: true });
|
|
179
188
|
return;
|
|
180
189
|
}
|
|
181
190
|
}
|
|
182
191
|
const currentWalletConnectorNetwork = yield walletConnector.getNetwork();
|
|
183
|
-
updateConnectedWalletById(
|
|
192
|
+
updateConnectedWalletById(wallet.id, {
|
|
184
193
|
address: currentWalletConnectorAddress,
|
|
185
194
|
network: currentWalletConnectorNetwork,
|
|
186
195
|
});
|
|
@@ -31,7 +31,7 @@ type UseConnectWalletValue = {
|
|
|
31
31
|
connectedWallets: Wallet[];
|
|
32
32
|
connectedWalletsInfo: ConnectedWalletConnectorType[];
|
|
33
33
|
getConnectedWalletById: (walletId: string) => Wallet | undefined;
|
|
34
|
-
refreshConnectedWallet: (
|
|
34
|
+
refreshConnectedWallet: (wallet: Wallet) => Promise<void>;
|
|
35
35
|
removeConnectedWalletsInfo: () => void;
|
|
36
36
|
disconnectWallet: (walletId: string) => Promise<void>;
|
|
37
37
|
};
|
|
@@ -157,12 +157,21 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
157
157
|
setConnectedWalletsInfo(updatedConnectedWalletsInfo);
|
|
158
158
|
};
|
|
159
159
|
// Updates connected wallet (network and address) and verifies connected wallet connection
|
|
160
|
-
const refreshConnectedWallet = (
|
|
160
|
+
const refreshConnectedWallet = (wallet) => __awaiter(void 0, void 0, void 0, function* () {
|
|
161
|
+
const walletConnector = wallet.connector;
|
|
161
162
|
if (shouldManuallyReconnectOnRefresh(walletConnector)) {
|
|
162
163
|
yield walletConnector.connect();
|
|
163
164
|
}
|
|
164
|
-
|
|
165
|
-
|
|
165
|
+
// Hardcoded binance key for now because binance wallet keeps on
|
|
166
|
+
// firing network change event on getAddress() call, which leads to infinite loop
|
|
167
|
+
// and we need to call getAddress to get the most recent address of the wallet
|
|
168
|
+
// when the account was changed in the wallet
|
|
169
|
+
const currentWalletConnectorAddress = wallet.key === 'binance'
|
|
170
|
+
? wallet.address
|
|
171
|
+
: yield walletConnector.getAddress();
|
|
172
|
+
if (wallet.connected &&
|
|
173
|
+
currentWalletConnectorAddress &&
|
|
174
|
+
handleConnectedWallet) {
|
|
166
175
|
const shouldProceedWithConnection = yield handleConnectedWallet({
|
|
167
176
|
address: currentWalletConnectorAddress,
|
|
168
177
|
chain: walletConnector.connectedChain,
|
|
@@ -170,13 +179,13 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
170
179
|
});
|
|
171
180
|
if (!shouldProceedWithConnection) {
|
|
172
181
|
logger.info('Connection was not established because handleConnectedWallet returned false');
|
|
173
|
-
disconnectWallet(
|
|
182
|
+
disconnectWallet(wallet.id);
|
|
174
183
|
setShowAuthFlow(false, { emitCancelAuth: true });
|
|
175
184
|
return;
|
|
176
185
|
}
|
|
177
186
|
}
|
|
178
187
|
const currentWalletConnectorNetwork = yield walletConnector.getNetwork();
|
|
179
|
-
updateConnectedWalletById(
|
|
188
|
+
updateConnectedWalletById(wallet.id, {
|
|
180
189
|
address: currentWalletConnectorAddress,
|
|
181
190
|
network: currentWalletConnectorNetwork,
|
|
182
191
|
});
|
|
@@ -40,7 +40,7 @@ const useWalletEventListeners = ({ disconnectWallet, handleLogOut, multiWallet,
|
|
|
40
40
|
if (!primaryWallet) {
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
|
-
refreshConnectedWallet(primaryWallet
|
|
43
|
+
refreshConnectedWallet(primaryWallet);
|
|
44
44
|
});
|
|
45
45
|
const handleAccountChangeWhenAwaitingAccountSwitch = React.useCallback((isPrimaryWallet, newAddress) => {
|
|
46
46
|
logger.logger.debug('handleAccountChangeWhenAwaitingAccountSwitch', {
|
|
@@ -89,7 +89,7 @@ const useWalletEventListeners = ({ disconnectWallet, handleLogOut, multiWallet,
|
|
|
89
89
|
const [newAddress] = accounts;
|
|
90
90
|
const changedAddress = !walletConnectorCore.isSameAddress(newAddress, primaryWallet.address, primaryWallet.chain);
|
|
91
91
|
if (changedAddress && authMode === 'connect-only') {
|
|
92
|
-
refreshConnectedWallet(primaryWallet
|
|
92
|
+
refreshConnectedWallet(primaryWallet);
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
95
|
const newWallet = secondaryWallets.find((wallet) => walletConnectorCore.isSameAddress(wallet.address, newAddress, wallet.chain));
|
|
@@ -160,7 +160,7 @@ const useWalletEventListeners = ({ disconnectWallet, handleLogOut, multiWallet,
|
|
|
160
160
|
if (authMode === 'connect-only' && secondaryWallets.length) {
|
|
161
161
|
const affectedWallets = secondaryWallets.filter(({ connector }) => connector.key === changedConnector.key);
|
|
162
162
|
for (const wallet of affectedWallets)
|
|
163
|
-
refreshConnectedWallet(wallet
|
|
163
|
+
refreshConnectedWallet(wallet);
|
|
164
164
|
return;
|
|
165
165
|
}
|
|
166
166
|
if (multiWalletWidgetState === 'awaiting_account_switch') {
|
|
@@ -172,7 +172,7 @@ const useWalletEventListeners = ({ disconnectWallet, handleLogOut, multiWallet,
|
|
|
172
172
|
// Get all wallets with this connector
|
|
173
173
|
const affectedWallets = secondaryWallets.filter(({ connector }) => connector.key === changedConnector.key);
|
|
174
174
|
for (const wallet of affectedWallets)
|
|
175
|
-
refreshConnectedWallet(wallet
|
|
175
|
+
refreshConnectedWallet(wallet);
|
|
176
176
|
}));
|
|
177
177
|
useWalletConnectorEvent.useWalletConnectorEvent(uniqueNonPrimaryWallets, 'disconnect', (affectedConnector) => {
|
|
178
178
|
logger.logger.debug('secondary wallet disconnect');
|
|
@@ -18,6 +18,6 @@ export type UseWalletEventListenersArgs = {
|
|
|
18
18
|
setSelectedWalletWithAction(walletWithAction: WalletWithAction | null): void;
|
|
19
19
|
user: UserProfile | undefined;
|
|
20
20
|
authMode: AuthModeType;
|
|
21
|
-
refreshConnectedWallet: (
|
|
21
|
+
refreshConnectedWallet: (wallet: Wallet) => Promise<void>;
|
|
22
22
|
};
|
|
23
23
|
export declare const useWalletEventListeners: ({ disconnectWallet, handleLogOut, multiWallet, multiWalletWidgetState, primaryWallet, secondaryWallets, selectedWalletConnector, selectedWalletWithAction, setSelectedWalletConnectorKey, setSelectedWalletWithAction, setMultiWalletWidgetState, user, setPrimaryWalletId, authMode, refreshConnectedWallet, }: UseWalletEventListenersArgs) => void;
|
|
@@ -36,7 +36,7 @@ const useWalletEventListeners = ({ disconnectWallet, handleLogOut, multiWallet,
|
|
|
36
36
|
if (!primaryWallet) {
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
|
-
refreshConnectedWallet(primaryWallet
|
|
39
|
+
refreshConnectedWallet(primaryWallet);
|
|
40
40
|
});
|
|
41
41
|
const handleAccountChangeWhenAwaitingAccountSwitch = useCallback((isPrimaryWallet, newAddress) => {
|
|
42
42
|
logger.debug('handleAccountChangeWhenAwaitingAccountSwitch', {
|
|
@@ -85,7 +85,7 @@ const useWalletEventListeners = ({ disconnectWallet, handleLogOut, multiWallet,
|
|
|
85
85
|
const [newAddress] = accounts;
|
|
86
86
|
const changedAddress = !isSameAddress(newAddress, primaryWallet.address, primaryWallet.chain);
|
|
87
87
|
if (changedAddress && authMode === 'connect-only') {
|
|
88
|
-
refreshConnectedWallet(primaryWallet
|
|
88
|
+
refreshConnectedWallet(primaryWallet);
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
91
91
|
const newWallet = secondaryWallets.find((wallet) => isSameAddress(wallet.address, newAddress, wallet.chain));
|
|
@@ -156,7 +156,7 @@ const useWalletEventListeners = ({ disconnectWallet, handleLogOut, multiWallet,
|
|
|
156
156
|
if (authMode === 'connect-only' && secondaryWallets.length) {
|
|
157
157
|
const affectedWallets = secondaryWallets.filter(({ connector }) => connector.key === changedConnector.key);
|
|
158
158
|
for (const wallet of affectedWallets)
|
|
159
|
-
refreshConnectedWallet(wallet
|
|
159
|
+
refreshConnectedWallet(wallet);
|
|
160
160
|
return;
|
|
161
161
|
}
|
|
162
162
|
if (multiWalletWidgetState === 'awaiting_account_switch') {
|
|
@@ -168,7 +168,7 @@ const useWalletEventListeners = ({ disconnectWallet, handleLogOut, multiWallet,
|
|
|
168
168
|
// Get all wallets with this connector
|
|
169
169
|
const affectedWallets = secondaryWallets.filter(({ connector }) => connector.key === changedConnector.key);
|
|
170
170
|
for (const wallet of affectedWallets)
|
|
171
|
-
refreshConnectedWallet(wallet
|
|
171
|
+
refreshConnectedWallet(wallet);
|
|
172
172
|
}));
|
|
173
173
|
useWalletConnectorEvent(uniqueNonPrimaryWallets, 'disconnect', (affectedConnector) => {
|
|
174
174
|
logger.debug('secondary wallet disconnect');
|
|
@@ -7,6 +7,7 @@ var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
9
9
|
var walletBook = require('@dynamic-labs/wallet-book');
|
|
10
|
+
var utils = require('@dynamic-labs/utils');
|
|
10
11
|
require('@dynamic-labs/sdk-api-core');
|
|
11
12
|
require('../../../shared/logger.cjs');
|
|
12
13
|
require('@dynamic-labs/iconic');
|
|
@@ -16,7 +17,6 @@ require('../../constants/colors.cjs');
|
|
|
16
17
|
require('../../constants/values.cjs');
|
|
17
18
|
require('../../../shared/utils/classes/storage/localStorage.cjs');
|
|
18
19
|
require('@dynamic-labs/logger');
|
|
19
|
-
require('@dynamic-labs/utils');
|
|
20
20
|
var useThrottle = require('../../../shared/utils/hooks/useThrottle/useThrottle.cjs');
|
|
21
21
|
require('../../../shared/consts/index.cjs');
|
|
22
22
|
require('@dynamic-labs/multi-wallet');
|
|
@@ -41,7 +41,8 @@ const getConnectedWalletsMap = (wallets, walletBook$1, primaryWalletId) => _tsli
|
|
|
41
41
|
const newMap = {};
|
|
42
42
|
yield Promise.all(wallets
|
|
43
43
|
.filter((wallet) => wallet.id === primaryWalletId ||
|
|
44
|
-
|
|
44
|
+
(!utils.isMobile() &&
|
|
45
|
+
walletBook.isWalletMethodSupported(walletBook.findWalletBookWallet(walletBook$1, wallet.key), 'getConnectedAccounts', getPlatformForConnector.getPlatformForConnector(wallet.connector))))
|
|
45
46
|
.map((wallet) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
46
47
|
newMap[getWalletIdentifier.getWalletIdentifier(wallet)] = yield isWalletConnected.isWalletConnected(wallet);
|
|
47
48
|
})));
|
|
@@ -3,6 +3,7 @@ import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
|
3
3
|
import { useState, useRef, useCallback, useEffect } from 'react';
|
|
4
4
|
import { isSameAddress } from '@dynamic-labs/wallet-connector-core';
|
|
5
5
|
import { isWalletMethodSupported, findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
6
|
+
import { isMobile } from '@dynamic-labs/utils';
|
|
6
7
|
import '@dynamic-labs/sdk-api-core';
|
|
7
8
|
import '../../../shared/logger.js';
|
|
8
9
|
import '@dynamic-labs/iconic';
|
|
@@ -12,7 +13,6 @@ import '../../constants/colors.js';
|
|
|
12
13
|
import '../../constants/values.js';
|
|
13
14
|
import '../../../shared/utils/classes/storage/localStorage.js';
|
|
14
15
|
import '@dynamic-labs/logger';
|
|
15
|
-
import '@dynamic-labs/utils';
|
|
16
16
|
import { useThrottle } from '../../../shared/utils/hooks/useThrottle/useThrottle.js';
|
|
17
17
|
import '../../../shared/consts/index.js';
|
|
18
18
|
import '@dynamic-labs/multi-wallet';
|
|
@@ -37,7 +37,8 @@ const getConnectedWalletsMap = (wallets, walletBook, primaryWalletId) => __await
|
|
|
37
37
|
const newMap = {};
|
|
38
38
|
yield Promise.all(wallets
|
|
39
39
|
.filter((wallet) => wallet.id === primaryWalletId ||
|
|
40
|
-
|
|
40
|
+
(!isMobile() &&
|
|
41
|
+
isWalletMethodSupported(findWalletBookWallet(walletBook, wallet.key), 'getConnectedAccounts', getPlatformForConnector(wallet.connector))))
|
|
41
42
|
.map((wallet) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
43
|
newMap[getWalletIdentifier(wallet)] = yield isWalletConnected(wallet);
|
|
43
44
|
})));
|