@dynamic-labs/sdk-react-core 0.18.10 → 0.18.11
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 +9 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -8
- package/src/lib/context/ErrorContext/ErrorContext.cjs +1 -0
- package/src/lib/context/ErrorContext/ErrorContext.js +1 -0
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.cjs +31 -16
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.js +31 -16
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.cjs +2 -2
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
|
|
2
|
+
### [0.18.11](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.10...v0.18.11) (2023-08-29)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* **bridge:** connect L2 wallet after updating network ([#3162](https://github.com/dynamic-labs/DynamicAuth/issues/3162)) ([6a90668](https://github.com/dynamic-labs/DynamicAuth/commit/6a906687d793fdfa03df87895f9c44b7a5e099dc))
|
|
8
|
+
* resend magic OTP on back click ([#3123](https://github.com/dynamic-labs/DynamicAuth/issues/3123)) ([#3150](https://github.com/dynamic-labs/DynamicAuth/issues/3150)) ([bcba905](https://github.com/dynamic-labs/DynamicAuth/commit/bcba905f22e796c122bb3bb156ec0e0f2a8fb3c6))
|
|
9
|
+
* **WagmiConnector:** sync wagmi with wallet connector events ([#3161](https://github.com/dynamic-labs/DynamicAuth/issues/3161)) ([7cd1da1](https://github.com/dynamic-labs/DynamicAuth/commit/7cd1da173ff7fca50cf2e92e0fad4dfbe651717c)), closes [#3149](https://github.com/dynamic-labs/DynamicAuth/issues/3149)
|
|
10
|
+
|
|
2
11
|
### [0.18.10](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.9...v0.18.10) (2023-08-25)
|
|
3
12
|
|
|
4
13
|
|
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": "0.18.
|
|
3
|
+
"version": "0.18.11",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"formik": "2.2.9",
|
|
17
17
|
"qrcode": "1.5.1",
|
|
18
18
|
"ethers": "5.7.2",
|
|
19
|
-
"@dynamic-labs/logger": "0.18.
|
|
20
|
-
"@dynamic-labs/multi-wallet": "0.18.
|
|
21
|
-
"@dynamic-labs/rpc-providers": "0.18.
|
|
22
|
-
"@dynamic-labs/types": "0.18.
|
|
23
|
-
"@dynamic-labs/utils": "0.18.
|
|
24
|
-
"@dynamic-labs/wallet-book": "0.18.
|
|
25
|
-
"@dynamic-labs/wallet-connector-core": "0.18.
|
|
19
|
+
"@dynamic-labs/logger": "0.18.11",
|
|
20
|
+
"@dynamic-labs/multi-wallet": "0.18.11",
|
|
21
|
+
"@dynamic-labs/rpc-providers": "0.18.11",
|
|
22
|
+
"@dynamic-labs/types": "0.18.11",
|
|
23
|
+
"@dynamic-labs/utils": "0.18.11",
|
|
24
|
+
"@dynamic-labs/wallet-book": "0.18.11",
|
|
25
|
+
"@dynamic-labs/wallet-connector-core": "0.18.11",
|
|
26
26
|
"eventemitter3": "5.0.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
@@ -20,6 +20,7 @@ const errorMessageMap = {
|
|
|
20
20
|
'missing-nonce': 'Something went wrong. Please try again.',
|
|
21
21
|
'missing-public-address': 'Connection cancelled. Please try again',
|
|
22
22
|
too_many_email_verification_attempts: 'Too many email verification attempts, please try again later',
|
|
23
|
+
'user-cancelled': '',
|
|
23
24
|
wallet_not_deployed: 'Your smart wallet has not been deployed.',
|
|
24
25
|
wrong_email_verification_token: 'The code you entered is incorrect. Please try again.',
|
|
25
26
|
};
|
|
@@ -16,6 +16,7 @@ const errorMessageMap = {
|
|
|
16
16
|
'missing-nonce': 'Something went wrong. Please try again.',
|
|
17
17
|
'missing-public-address': 'Connection cancelled. Please try again',
|
|
18
18
|
too_many_email_verification_attempts: 'Too many email verification attempts, please try again later',
|
|
19
|
+
'user-cancelled': '',
|
|
19
20
|
wallet_not_deployed: 'Your smart wallet has not been deployed.',
|
|
20
21
|
wrong_email_verification_token: 'The code you entered is incorrect. Please try again.',
|
|
21
22
|
};
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var _tslib = require('../../../../../../_virtual/_tslib.cjs');
|
|
6
6
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
7
|
+
var utils = require('@dynamic-labs/utils');
|
|
7
8
|
var showPendingConnectView = require('../helpers/showPendingConnectView.cjs');
|
|
8
9
|
var isConnectOnly = require('../helpers/isConnectOnly.cjs');
|
|
9
10
|
var useInternalDynamicContext = require('../../../../context/DynamicContext/useInternalDynamicContext.cjs');
|
|
@@ -15,7 +16,6 @@ require('@dynamic-labs/iconic');
|
|
|
15
16
|
require('react/jsx-runtime');
|
|
16
17
|
require('react');
|
|
17
18
|
require('@dynamic-labs/wallet-book');
|
|
18
|
-
require('@dynamic-labs/utils');
|
|
19
19
|
var localStorage$1 = require('../../../constants/localStorage.cjs');
|
|
20
20
|
require('../../../constants/colors.cjs');
|
|
21
21
|
var localStorage = require('../../../../shared/utils/classes/storage/localStorage.cjs');
|
|
@@ -32,7 +32,7 @@ const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = tr
|
|
|
32
32
|
const { setView, goToInitialView } = ViewContext.useViewContext();
|
|
33
33
|
const { setErrorMessage } = ErrorContext.useErrorContext();
|
|
34
34
|
const { captchaToken } = CaptchaContext.useCaptchaContext();
|
|
35
|
-
const { authMode, connectWallet, consumeNonce, displaySiweStatement, environmentId, projectSettings, setIsSingleWalletAccount, user, walletUiUtils, setCallback, setIsVerificationInProgress, isFullyConnected, walletsToConnectByChain, connectedWallets, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
35
|
+
const { authMode, connectWallet, consumeNonce, displaySiweStatement, environmentId, projectSettings, setIsSingleWalletAccount, user, walletUiUtils, setCallback, setIsVerificationInProgress, isFullyConnected, walletsToConnectByChain = [], connectedWallets, isBridgeFlow, selectedWalletConnector, walletsByChain, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
36
36
|
const { handleWalletsToConnect } = useHandleWalletsToConnect.useHandleWalletsToConnect();
|
|
37
37
|
const verifyWallet = useVerifyWallet.useVerifyWallet({
|
|
38
38
|
consumeNonce,
|
|
@@ -42,7 +42,7 @@ const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = tr
|
|
|
42
42
|
setIsSingleWalletAccount,
|
|
43
43
|
});
|
|
44
44
|
return ({ walletConnector, fetchPublicAddressOpts = undefined, }) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
-
var _a, _b;
|
|
45
|
+
var _a, _b, _c;
|
|
46
46
|
// Raise verification ongoing flag
|
|
47
47
|
setIsVerificationInProgress(true);
|
|
48
48
|
try {
|
|
@@ -72,22 +72,32 @@ const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = tr
|
|
|
72
72
|
}
|
|
73
73
|
if (isConnectOnly.isConnectOnly(user, authMode)) {
|
|
74
74
|
localStorage.LocalStorage.setToLS(localStorage$1.LAST_USED_WALLET, walletConnector.name);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
if (isBridgeFlow) {
|
|
76
|
+
const didConnectLastWallet = (selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.connectedChain) ===
|
|
77
|
+
((_a = utils.last(walletsByChain || [])) === null || _a === void 0 ? void 0 : _a.chain);
|
|
78
|
+
// we don't want to re-calculate wallets to connect state if wallet is already connected.
|
|
79
|
+
// it may happen when user switch network in connect flow on already connected wallet
|
|
80
|
+
const isAlreadyConnected = connectedWallets.find((wallet) => walletConnectorCore.isSameAddress(publicWalletAddress, wallet.address, wallet.chain));
|
|
81
|
+
if (shouldUpdateWallets &&
|
|
82
|
+
(!isAlreadyConnected || didConnectLastWallet)) {
|
|
83
|
+
handleWalletsToConnect();
|
|
84
|
+
}
|
|
85
|
+
if (isAlreadyConnected && !didConnectLastWallet) {
|
|
86
|
+
setView('bridge-next-wallet-connection');
|
|
87
|
+
}
|
|
80
88
|
}
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
else {
|
|
90
|
+
if (shouldUpdateWallets) {
|
|
91
|
+
handleWalletsToConnect();
|
|
92
|
+
}
|
|
83
93
|
}
|
|
84
|
-
if (!isFullyConnected ||
|
|
94
|
+
if (!isFullyConnected || walletsToConnectByChain.length) {
|
|
85
95
|
setCallback('connectSuccess');
|
|
86
96
|
}
|
|
87
97
|
return;
|
|
88
98
|
}
|
|
89
99
|
setCallback('connectSuccess');
|
|
90
|
-
if ((
|
|
100
|
+
if ((_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.security.hCaptcha) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
91
101
|
setView('captcha');
|
|
92
102
|
return;
|
|
93
103
|
}
|
|
@@ -105,11 +115,16 @@ const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = tr
|
|
|
105
115
|
});
|
|
106
116
|
}
|
|
107
117
|
catch (err) {
|
|
108
|
-
|
|
109
|
-
|
|
118
|
+
const userCancelled = (err === null || err === void 0 ? void 0 : err.code) === 'user-cancelled';
|
|
119
|
+
if (!userCancelled)
|
|
120
|
+
logger.logger.debug(err);
|
|
121
|
+
setErrorMessage((_c = err === null || err === void 0 ? void 0 : err.code) === null || _c === void 0 ? void 0 : _c.toString());
|
|
110
122
|
goToInitialView();
|
|
111
|
-
// Since auth failed,
|
|
112
|
-
|
|
123
|
+
// Since auth failed, clear verification flag
|
|
124
|
+
// But if user cancelled, clearStatesOnBackClick will have already cleared it. So avoid
|
|
125
|
+
// clearing again since that would trigger a warning
|
|
126
|
+
if (!userCancelled)
|
|
127
|
+
setIsVerificationInProgress(false);
|
|
113
128
|
return;
|
|
114
129
|
}
|
|
115
130
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __awaiter } from '../../../../../../_virtual/_tslib.js';
|
|
2
2
|
import { isEmailWalletConnector, isEmailOTPWalletConnector, isBloctoConnector, isSameAddress } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { last } from '@dynamic-labs/utils';
|
|
3
4
|
import { showPendingConnectView } from '../helpers/showPendingConnectView.js';
|
|
4
5
|
import { isConnectOnly } from '../helpers/isConnectOnly.js';
|
|
5
6
|
import { useInternalDynamicContext } from '../../../../context/DynamicContext/useInternalDynamicContext.js';
|
|
@@ -11,7 +12,6 @@ import '@dynamic-labs/iconic';
|
|
|
11
12
|
import 'react/jsx-runtime';
|
|
12
13
|
import 'react';
|
|
13
14
|
import '@dynamic-labs/wallet-book';
|
|
14
|
-
import '@dynamic-labs/utils';
|
|
15
15
|
import { LAST_USED_WALLET } from '../../../constants/localStorage.js';
|
|
16
16
|
import '../../../constants/colors.js';
|
|
17
17
|
import { LocalStorage } from '../../../../shared/utils/classes/storage/localStorage.js';
|
|
@@ -28,7 +28,7 @@ const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = tr
|
|
|
28
28
|
const { setView, goToInitialView } = useViewContext();
|
|
29
29
|
const { setErrorMessage } = useErrorContext();
|
|
30
30
|
const { captchaToken } = useCaptchaContext();
|
|
31
|
-
const { authMode, connectWallet, consumeNonce, displaySiweStatement, environmentId, projectSettings, setIsSingleWalletAccount, user, walletUiUtils, setCallback, setIsVerificationInProgress, isFullyConnected, walletsToConnectByChain, connectedWallets, } = useInternalDynamicContext();
|
|
31
|
+
const { authMode, connectWallet, consumeNonce, displaySiweStatement, environmentId, projectSettings, setIsSingleWalletAccount, user, walletUiUtils, setCallback, setIsVerificationInProgress, isFullyConnected, walletsToConnectByChain = [], connectedWallets, isBridgeFlow, selectedWalletConnector, walletsByChain, } = useInternalDynamicContext();
|
|
32
32
|
const { handleWalletsToConnect } = useHandleWalletsToConnect();
|
|
33
33
|
const verifyWallet = useVerifyWallet({
|
|
34
34
|
consumeNonce,
|
|
@@ -38,7 +38,7 @@ const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = tr
|
|
|
38
38
|
setIsSingleWalletAccount,
|
|
39
39
|
});
|
|
40
40
|
return ({ walletConnector, fetchPublicAddressOpts = undefined, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
-
var _a, _b;
|
|
41
|
+
var _a, _b, _c;
|
|
42
42
|
// Raise verification ongoing flag
|
|
43
43
|
setIsVerificationInProgress(true);
|
|
44
44
|
try {
|
|
@@ -68,22 +68,32 @@ const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = tr
|
|
|
68
68
|
}
|
|
69
69
|
if (isConnectOnly(user, authMode)) {
|
|
70
70
|
LocalStorage.setToLS(LAST_USED_WALLET, walletConnector.name);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
if (isBridgeFlow) {
|
|
72
|
+
const didConnectLastWallet = (selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.connectedChain) ===
|
|
73
|
+
((_a = last(walletsByChain || [])) === null || _a === void 0 ? void 0 : _a.chain);
|
|
74
|
+
// we don't want to re-calculate wallets to connect state if wallet is already connected.
|
|
75
|
+
// it may happen when user switch network in connect flow on already connected wallet
|
|
76
|
+
const isAlreadyConnected = connectedWallets.find((wallet) => isSameAddress(publicWalletAddress, wallet.address, wallet.chain));
|
|
77
|
+
if (shouldUpdateWallets &&
|
|
78
|
+
(!isAlreadyConnected || didConnectLastWallet)) {
|
|
79
|
+
handleWalletsToConnect();
|
|
80
|
+
}
|
|
81
|
+
if (isAlreadyConnected && !didConnectLastWallet) {
|
|
82
|
+
setView('bridge-next-wallet-connection');
|
|
83
|
+
}
|
|
76
84
|
}
|
|
77
|
-
|
|
78
|
-
|
|
85
|
+
else {
|
|
86
|
+
if (shouldUpdateWallets) {
|
|
87
|
+
handleWalletsToConnect();
|
|
88
|
+
}
|
|
79
89
|
}
|
|
80
|
-
if (!isFullyConnected ||
|
|
90
|
+
if (!isFullyConnected || walletsToConnectByChain.length) {
|
|
81
91
|
setCallback('connectSuccess');
|
|
82
92
|
}
|
|
83
93
|
return;
|
|
84
94
|
}
|
|
85
95
|
setCallback('connectSuccess');
|
|
86
|
-
if ((
|
|
96
|
+
if ((_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.security.hCaptcha) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
87
97
|
setView('captcha');
|
|
88
98
|
return;
|
|
89
99
|
}
|
|
@@ -101,11 +111,16 @@ const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = tr
|
|
|
101
111
|
});
|
|
102
112
|
}
|
|
103
113
|
catch (err) {
|
|
104
|
-
|
|
105
|
-
|
|
114
|
+
const userCancelled = (err === null || err === void 0 ? void 0 : err.code) === 'user-cancelled';
|
|
115
|
+
if (!userCancelled)
|
|
116
|
+
logger.debug(err);
|
|
117
|
+
setErrorMessage((_c = err === null || err === void 0 ? void 0 : err.code) === null || _c === void 0 ? void 0 : _c.toString());
|
|
106
118
|
goToInitialView();
|
|
107
|
-
// Since auth failed,
|
|
108
|
-
|
|
119
|
+
// Since auth failed, clear verification flag
|
|
120
|
+
// But if user cancelled, clearStatesOnBackClick will have already cleared it. So avoid
|
|
121
|
+
// clearing again since that would trigger a warning
|
|
122
|
+
if (!userCancelled)
|
|
123
|
+
setIsVerificationInProgress(false);
|
|
109
124
|
return;
|
|
110
125
|
}
|
|
111
126
|
});
|
|
@@ -124,10 +124,10 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
124
124
|
walletConnectorCore.logger.error('Could not refresh the wallet. The wallet address is not available');
|
|
125
125
|
return;
|
|
126
126
|
}
|
|
127
|
-
const
|
|
127
|
+
const currentWalletConnectorNetwork = yield walletConnector.getNetwork();
|
|
128
128
|
updateConnectedWalletById(walletId, {
|
|
129
129
|
address: currentWalletConnectorAddress,
|
|
130
|
-
network:
|
|
130
|
+
network: currentWalletConnectorNetwork,
|
|
131
131
|
});
|
|
132
132
|
});
|
|
133
133
|
const shouldSkipCreatingVisit = authMode === 'connect-only' && !enableVisitTrackingOnConnectOnly;
|
|
@@ -120,10 +120,10 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
120
120
|
logger.error('Could not refresh the wallet. The wallet address is not available');
|
|
121
121
|
return;
|
|
122
122
|
}
|
|
123
|
-
const
|
|
123
|
+
const currentWalletConnectorNetwork = yield walletConnector.getNetwork();
|
|
124
124
|
updateConnectedWalletById(walletId, {
|
|
125
125
|
address: currentWalletConnectorAddress,
|
|
126
|
-
network:
|
|
126
|
+
network: currentWalletConnectorNetwork,
|
|
127
127
|
});
|
|
128
128
|
});
|
|
129
129
|
const shouldSkipCreatingVisit = authMode === 'connect-only' && !enableVisitTrackingOnConnectOnly;
|