@dynamic-labs/sdk-react-core 0.18.10 → 0.18.12
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 +22 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -8
- package/src/lib/context/DynamicContext/DynamicContext.cjs +2 -1
- package/src/lib/context/DynamicContext/DynamicContext.d.ts +10 -1
- package/src/lib/context/DynamicContext/DynamicContext.js +2 -1
- 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 +8 -12
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.d.ts +1 -2
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.js +8 -12
- package/src/lib/utils/hooks/useWallets/useWallets.cjs +3 -1
- package/src/lib/utils/hooks/useWallets/useWallets.d.ts +3 -2
- package/src/lib/utils/hooks/useWallets/useWallets.js +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
|
|
2
|
+
### [0.18.12](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.11...v0.18.12) (2023-08-30)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add deepLinkPreference prop ([#3174](https://github.com/dynamic-labs/DynamicAuth/issues/3174)) ([#3176](https://github.com/dynamic-labs/DynamicAuth/issues/3176)) ([8a6e389](https://github.com/dynamic-labs/DynamicAuth/commit/8a6e389e84bd74e80dc9df37ba6df5d46e6ba831))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* end connector session when unlinking from bridge ([#3120](https://github.com/dynamic-labs/DynamicAuth/issues/3120)) ([#3178](https://github.com/dynamic-labs/DynamicAuth/issues/3178)) ([0a69e21](https://github.com/dynamic-labs/DynamicAuth/commit/0a69e218dc9a9a0709bb74b901ed0ca08c7f463c))
|
|
13
|
+
* **bridge:** update address when switching networks ([#3171](https://github.com/dynamic-labs/DynamicAuth/issues/3171)) ([#3180](https://github.com/dynamic-labs/DynamicAuth/issues/3180)) ([8ab5ce4](https://github.com/dynamic-labs/DynamicAuth/commit/8ab5ce4add675ae326c052fc1510d54d56d0d665))
|
|
14
|
+
|
|
15
|
+
### [0.18.11](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.10...v0.18.11) (2023-08-29)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **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))
|
|
21
|
+
* 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))
|
|
22
|
+
* **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)
|
|
23
|
+
|
|
2
24
|
### [0.18.10](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.9...v0.18.10) (2023-08-25)
|
|
3
25
|
|
|
4
26
|
|
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.12",
|
|
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.12",
|
|
20
|
+
"@dynamic-labs/multi-wallet": "0.18.12",
|
|
21
|
+
"@dynamic-labs/rpc-providers": "0.18.12",
|
|
22
|
+
"@dynamic-labs/types": "0.18.12",
|
|
23
|
+
"@dynamic-labs/utils": "0.18.12",
|
|
24
|
+
"@dynamic-labs/wallet-book": "0.18.12",
|
|
25
|
+
"@dynamic-labs/wallet-connector-core": "0.18.12",
|
|
26
26
|
"eventemitter3": "5.0.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
@@ -101,7 +101,7 @@ const EMPTY_INITIAL_USER = undefined;
|
|
|
101
101
|
const DynamicContext = React.createContext(undefined);
|
|
102
102
|
const DynamicContextProvider = ({ children, theme, settings, }) => {
|
|
103
103
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
104
|
-
const { accessDeniedMessagePrimary, accessDeniedMessageSecondary, accessDeniedButton, apiBaseUrl, walletsByChain, cssOverrides, defaultNumberOfWalletsToShow = values.DEFAULT_NUMBER_OF_WALLETS_TO_SHOW, flowNetwork, initialAuthenticationMode = 'connect-and-sign', debugError = false, displaySiweStatement = true, newToWeb3WalletChainMap, enableVisitTrackingOnConnectOnly = true, environmentId, localStorageSuffix, eventsCallbacks, evmNetworks, walletsFilter, logLevel = 'WARN', notInTheListImageUrl, onboardingImageUrl, policiesConsentInnerComponent, customPrivacyPolicy, privacyPolicyUrl, signWithEmailWalletName, socialMediaLinkText, socialMediaIconUrl, socialMediaUrl, customTermsOfServices, termsOfServiceUrl, toolkitEnabled, siweStatement, shadowDOMEnabled = true, walletConnectors: walletConnectorsProp, socialProvidersFilter, } = settings;
|
|
104
|
+
const { accessDeniedMessagePrimary, accessDeniedMessageSecondary, accessDeniedButton, apiBaseUrl, deepLinkPreference = 'native', walletsByChain, cssOverrides, defaultNumberOfWalletsToShow = values.DEFAULT_NUMBER_OF_WALLETS_TO_SHOW, flowNetwork, initialAuthenticationMode = 'connect-and-sign', debugError = false, displaySiweStatement = true, newToWeb3WalletChainMap, enableVisitTrackingOnConnectOnly = true, environmentId, localStorageSuffix, eventsCallbacks, evmNetworks, walletsFilter, logLevel = 'WARN', notInTheListImageUrl, onboardingImageUrl, policiesConsentInnerComponent, customPrivacyPolicy, privacyPolicyUrl, signWithEmailWalletName, socialMediaLinkText, socialMediaIconUrl, socialMediaUrl, customTermsOfServices, termsOfServiceUrl, toolkitEnabled, siweStatement, shadowDOMEnabled = true, walletConnectors: walletConnectorsProp, socialProvidersFilter, } = settings;
|
|
105
105
|
// The following event related methods are temporary and should be removed after QNTM-180 is done
|
|
106
106
|
// ============ START REMOVE AFTER QNTM-180 ============
|
|
107
107
|
const internalEventsRef = React.useRef(internalEvents.getInternalEvents());
|
|
@@ -174,6 +174,7 @@ const DynamicContextProvider = ({ children, theme, settings, }) => {
|
|
|
174
174
|
const { wallets } = useWallets.useWallets({
|
|
175
175
|
appLogoUrl,
|
|
176
176
|
appName,
|
|
177
|
+
deepLinkPreference,
|
|
177
178
|
flowNetwork,
|
|
178
179
|
networkConfigurations: serverNetworkConfigurations,
|
|
179
180
|
projectSettings,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { LogLevel } from '@dynamic-labs/logger';
|
|
3
3
|
import { EvmNetwork, SocialProviderFilter } from '@dynamic-labs/types';
|
|
4
|
-
import { WalletConnectorsMethod } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import { DeepLinkVariant, WalletConnectorsMethod } from '@dynamic-labs/wallet-connector-core';
|
|
5
5
|
import { AccessDeniedCustomButton, AuthModeType, ChainToWalletMap, DynamicEventsCallbacks, WalletOption } from '../../shared';
|
|
6
6
|
import { SocialNetworkIconType } from '../../utils/functions/getSocialNetworkIcon';
|
|
7
7
|
import { ThemeData, ThemeSetting } from '../ThemeContext';
|
|
@@ -19,6 +19,15 @@ export interface DynamicContextProps {
|
|
|
19
19
|
appName?: string;
|
|
20
20
|
cssOverrides?: string | JSX.Element;
|
|
21
21
|
debugError?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Used to control the type of deep link used when connecting
|
|
24
|
+
* a mobile wallet. Defaults to 'native'. This is useful for
|
|
25
|
+
* example if your app is running in a webview of a native
|
|
26
|
+
* mobile app, and you want to be able to link out to any
|
|
27
|
+
* wallet without having to modify your iOS build config.
|
|
28
|
+
* In this case, you can set this to 'universal'.
|
|
29
|
+
*/
|
|
30
|
+
deepLinkPreference?: DeepLinkVariant;
|
|
22
31
|
defaultNumberOfWalletsToShow?: number;
|
|
23
32
|
displaySiweStatement?: boolean;
|
|
24
33
|
enableVisitTrackingOnConnectOnly?: boolean;
|
|
@@ -97,7 +97,7 @@ const EMPTY_INITIAL_USER = undefined;
|
|
|
97
97
|
const DynamicContext = createContext(undefined);
|
|
98
98
|
const DynamicContextProvider = ({ children, theme, settings, }) => {
|
|
99
99
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
100
|
-
const { accessDeniedMessagePrimary, accessDeniedMessageSecondary, accessDeniedButton, apiBaseUrl, walletsByChain, cssOverrides, defaultNumberOfWalletsToShow = DEFAULT_NUMBER_OF_WALLETS_TO_SHOW, flowNetwork, initialAuthenticationMode = 'connect-and-sign', debugError = false, displaySiweStatement = true, newToWeb3WalletChainMap, enableVisitTrackingOnConnectOnly = true, environmentId, localStorageSuffix, eventsCallbacks, evmNetworks, walletsFilter, logLevel = 'WARN', notInTheListImageUrl, onboardingImageUrl, policiesConsentInnerComponent, customPrivacyPolicy, privacyPolicyUrl, signWithEmailWalletName, socialMediaLinkText, socialMediaIconUrl, socialMediaUrl, customTermsOfServices, termsOfServiceUrl, toolkitEnabled, siweStatement, shadowDOMEnabled = true, walletConnectors: walletConnectorsProp, socialProvidersFilter, } = settings;
|
|
100
|
+
const { accessDeniedMessagePrimary, accessDeniedMessageSecondary, accessDeniedButton, apiBaseUrl, deepLinkPreference = 'native', walletsByChain, cssOverrides, defaultNumberOfWalletsToShow = DEFAULT_NUMBER_OF_WALLETS_TO_SHOW, flowNetwork, initialAuthenticationMode = 'connect-and-sign', debugError = false, displaySiweStatement = true, newToWeb3WalletChainMap, enableVisitTrackingOnConnectOnly = true, environmentId, localStorageSuffix, eventsCallbacks, evmNetworks, walletsFilter, logLevel = 'WARN', notInTheListImageUrl, onboardingImageUrl, policiesConsentInnerComponent, customPrivacyPolicy, privacyPolicyUrl, signWithEmailWalletName, socialMediaLinkText, socialMediaIconUrl, socialMediaUrl, customTermsOfServices, termsOfServiceUrl, toolkitEnabled, siweStatement, shadowDOMEnabled = true, walletConnectors: walletConnectorsProp, socialProvidersFilter, } = settings;
|
|
101
101
|
// The following event related methods are temporary and should be removed after QNTM-180 is done
|
|
102
102
|
// ============ START REMOVE AFTER QNTM-180 ============
|
|
103
103
|
const internalEventsRef = useRef(getInternalEvents());
|
|
@@ -170,6 +170,7 @@ const DynamicContextProvider = ({ children, theme, settings, }) => {
|
|
|
170
170
|
const { wallets } = useWallets({
|
|
171
171
|
appLogoUrl,
|
|
172
172
|
appName,
|
|
173
|
+
deepLinkPreference,
|
|
173
174
|
flowNetwork,
|
|
174
175
|
networkConfigurations: serverNetworkConfigurations,
|
|
175
176
|
projectSettings,
|
|
@@ -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
|
});
|
|
@@ -47,12 +47,7 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
47
47
|
const walletNetwork = yield walletConnector.getNetwork();
|
|
48
48
|
const walletChain = walletConnector.connectedChain;
|
|
49
49
|
const walletObject = {
|
|
50
|
-
address:
|
|
51
|
-
// We use `storedConnectedWalletInfo.lastWalletAddress` as a workaround to Braavos issue
|
|
52
|
-
// Braavos during initialization returns an empty string as a wallet address
|
|
53
|
-
walletAddress ||
|
|
54
|
-
storedConnectedWalletInfo.lastWalletAddress ||
|
|
55
|
-
'',
|
|
50
|
+
address: walletAddress || '',
|
|
56
51
|
chain: walletChain || '',
|
|
57
52
|
connected: true,
|
|
58
53
|
connector: walletConnector,
|
|
@@ -89,11 +84,10 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
89
84
|
}, [connectedWallets]);
|
|
90
85
|
const connectedWallet = connectedWallets[0] || null;
|
|
91
86
|
// Keeps connected wallet data inside localStorage
|
|
92
|
-
const applyConnectedWalletToStore = ({ walletId,
|
|
87
|
+
const applyConnectedWalletToStore = ({ walletId, walletConnectorKey, walletChain, provider, }) => {
|
|
93
88
|
const nextConnectedWalletsInfo = [...connectedWalletsInfo];
|
|
94
89
|
nextConnectedWalletsInfo.push({
|
|
95
90
|
id: walletId,
|
|
96
|
-
lastWalletAddress: walletAddress,
|
|
97
91
|
provider,
|
|
98
92
|
walletChain,
|
|
99
93
|
walletConnectorKey,
|
|
@@ -124,10 +118,10 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
124
118
|
walletConnectorCore.logger.error('Could not refresh the wallet. The wallet address is not available');
|
|
125
119
|
return;
|
|
126
120
|
}
|
|
127
|
-
const
|
|
121
|
+
const currentWalletConnectorNetwork = yield walletConnector.getNetwork();
|
|
128
122
|
updateConnectedWalletById(walletId, {
|
|
129
123
|
address: currentWalletConnectorAddress,
|
|
130
|
-
network:
|
|
124
|
+
network: currentWalletConnectorNetwork,
|
|
131
125
|
});
|
|
132
126
|
});
|
|
133
127
|
const shouldSkipCreatingVisit = authMode === 'connect-only' && !enableVisitTrackingOnConnectOnly;
|
|
@@ -183,14 +177,16 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
183
177
|
}
|
|
184
178
|
return Promise.resolve(publicWalletAddress);
|
|
185
179
|
});
|
|
186
|
-
const unlinkConnectedWallet = (walletId) => {
|
|
180
|
+
const unlinkConnectedWallet = (walletId) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
181
|
+
const connectedWalletToUnlink = connectedWallets.find((wallet) => wallet.id === walletId);
|
|
182
|
+
yield (connectedWalletToUnlink === null || connectedWalletToUnlink === void 0 ? void 0 : connectedWalletToUnlink.connector.endSession());
|
|
187
183
|
const filteredWallets = connectedWalletsInfo.filter((wallet) => wallet.id !== walletId);
|
|
188
184
|
if (walletId === primaryWalletId) {
|
|
189
185
|
clearPrimaryWalletId();
|
|
190
186
|
}
|
|
191
187
|
setConnectedWalletsInfo(filteredWallets);
|
|
192
188
|
onUnlink === null || onUnlink === void 0 ? void 0 : onUnlink(walletId, filteredWallets);
|
|
193
|
-
};
|
|
189
|
+
});
|
|
194
190
|
const getConnectedWalletById = React.useCallback((walletId) => connectedWallets.find((wallet) => wallet.id === walletId), [connectedWallets]);
|
|
195
191
|
return {
|
|
196
192
|
connectWallet,
|
|
@@ -6,7 +6,6 @@ export type ConnectedWalletConnectorType = {
|
|
|
6
6
|
walletChain?: Chain;
|
|
7
7
|
walletConnectorKey: string;
|
|
8
8
|
provider: string;
|
|
9
|
-
lastWalletAddress?: string;
|
|
10
9
|
};
|
|
11
10
|
type Props = {
|
|
12
11
|
authMode: AuthModeType;
|
|
@@ -28,6 +27,6 @@ export declare const useConnectWallet: ({ authMode, clearPrimaryWalletId, enable
|
|
|
28
27
|
getConnectedWalletById: (walletId: string) => Wallet | undefined;
|
|
29
28
|
refreshConnectedWallet: (walletId: string, walletConnector: WalletConnector) => Promise<void>;
|
|
30
29
|
removeConnectedWalletsInfo: () => void;
|
|
31
|
-
unlinkConnectedWallet: (walletId: string) => void
|
|
30
|
+
unlinkConnectedWallet: (walletId: string) => Promise<void>;
|
|
32
31
|
};
|
|
33
32
|
export {};
|
|
@@ -43,12 +43,7 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
43
43
|
const walletNetwork = yield walletConnector.getNetwork();
|
|
44
44
|
const walletChain = walletConnector.connectedChain;
|
|
45
45
|
const walletObject = {
|
|
46
|
-
address:
|
|
47
|
-
// We use `storedConnectedWalletInfo.lastWalletAddress` as a workaround to Braavos issue
|
|
48
|
-
// Braavos during initialization returns an empty string as a wallet address
|
|
49
|
-
walletAddress ||
|
|
50
|
-
storedConnectedWalletInfo.lastWalletAddress ||
|
|
51
|
-
'',
|
|
46
|
+
address: walletAddress || '',
|
|
52
47
|
chain: walletChain || '',
|
|
53
48
|
connected: true,
|
|
54
49
|
connector: walletConnector,
|
|
@@ -85,11 +80,10 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
85
80
|
}, [connectedWallets]);
|
|
86
81
|
const connectedWallet = connectedWallets[0] || null;
|
|
87
82
|
// Keeps connected wallet data inside localStorage
|
|
88
|
-
const applyConnectedWalletToStore = ({ walletId,
|
|
83
|
+
const applyConnectedWalletToStore = ({ walletId, walletConnectorKey, walletChain, provider, }) => {
|
|
89
84
|
const nextConnectedWalletsInfo = [...connectedWalletsInfo];
|
|
90
85
|
nextConnectedWalletsInfo.push({
|
|
91
86
|
id: walletId,
|
|
92
|
-
lastWalletAddress: walletAddress,
|
|
93
87
|
provider,
|
|
94
88
|
walletChain,
|
|
95
89
|
walletConnectorKey,
|
|
@@ -120,10 +114,10 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
120
114
|
logger.error('Could not refresh the wallet. The wallet address is not available');
|
|
121
115
|
return;
|
|
122
116
|
}
|
|
123
|
-
const
|
|
117
|
+
const currentWalletConnectorNetwork = yield walletConnector.getNetwork();
|
|
124
118
|
updateConnectedWalletById(walletId, {
|
|
125
119
|
address: currentWalletConnectorAddress,
|
|
126
|
-
network:
|
|
120
|
+
network: currentWalletConnectorNetwork,
|
|
127
121
|
});
|
|
128
122
|
});
|
|
129
123
|
const shouldSkipCreatingVisit = authMode === 'connect-only' && !enableVisitTrackingOnConnectOnly;
|
|
@@ -179,14 +173,16 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
179
173
|
}
|
|
180
174
|
return Promise.resolve(publicWalletAddress);
|
|
181
175
|
});
|
|
182
|
-
const unlinkConnectedWallet = (walletId) => {
|
|
176
|
+
const unlinkConnectedWallet = (walletId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
177
|
+
const connectedWalletToUnlink = connectedWallets.find((wallet) => wallet.id === walletId);
|
|
178
|
+
yield (connectedWalletToUnlink === null || connectedWalletToUnlink === void 0 ? void 0 : connectedWalletToUnlink.connector.endSession());
|
|
183
179
|
const filteredWallets = connectedWalletsInfo.filter((wallet) => wallet.id !== walletId);
|
|
184
180
|
if (walletId === primaryWalletId) {
|
|
185
181
|
clearPrimaryWalletId();
|
|
186
182
|
}
|
|
187
183
|
setConnectedWalletsInfo(filteredWallets);
|
|
188
184
|
onUnlink === null || onUnlink === void 0 ? void 0 : onUnlink(walletId, filteredWallets);
|
|
189
|
-
};
|
|
185
|
+
});
|
|
190
186
|
const getConnectedWalletById = useCallback((walletId) => connectedWallets.find((wallet) => wallet.id === walletId), [connectedWallets]);
|
|
191
187
|
return {
|
|
192
188
|
connectWallet,
|
|
@@ -6,7 +6,7 @@ var React = require('react');
|
|
|
6
6
|
var data = require('../../../views/WalletList/data.cjs');
|
|
7
7
|
var verifyMagicIsSetup = require('./utils/verifyMagicIsSetup/verifyMagicIsSetup.cjs');
|
|
8
8
|
|
|
9
|
-
const useWallets = ({ projectSettings, appLogoUrl, appName, flowNetwork, networkConfigurations, walletBook, walletConnectV1Bridge, walletUiUtils, walletConnectorsProp, }) => {
|
|
9
|
+
const useWallets = ({ projectSettings, appLogoUrl, appName, deepLinkPreference, flowNetwork, networkConfigurations, walletBook, walletConnectV1Bridge, walletUiUtils, walletConnectorsProp, }) => {
|
|
10
10
|
const wallets = React.useMemo(() => {
|
|
11
11
|
if (!projectSettings || !Object.keys(walletBook !== null && walletBook !== void 0 ? walletBook : {}).length)
|
|
12
12
|
return [];
|
|
@@ -14,6 +14,7 @@ const useWallets = ({ projectSettings, appLogoUrl, appName, flowNetwork, network
|
|
|
14
14
|
appLogoUrl,
|
|
15
15
|
appName,
|
|
16
16
|
customerApiProviders: projectSettings.providers || [],
|
|
17
|
+
deepLinkPreference,
|
|
17
18
|
flowNetwork,
|
|
18
19
|
networkConfigurations,
|
|
19
20
|
skipMemo: true,
|
|
@@ -26,6 +27,7 @@ const useWallets = ({ projectSettings, appLogoUrl, appName, flowNetwork, network
|
|
|
26
27
|
appLogoUrl,
|
|
27
28
|
appName,
|
|
28
29
|
customerApiProviders: projectSettings.providers || [],
|
|
30
|
+
deepLinkPreference,
|
|
29
31
|
flowNetwork,
|
|
30
32
|
networkConfigurations,
|
|
31
33
|
skipMemo: true,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ProjectSettings } from '@dynamic-labs/sdk-api';
|
|
2
2
|
import { NetworkConfigurationMap, WalletUiUtils } from '@dynamic-labs/types';
|
|
3
|
-
import { WalletConnector, WalletConnectorsMethod } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { DeepLinkVariant, WalletConnector, WalletConnectorsMethod } from '@dynamic-labs/wallet-connector-core';
|
|
4
4
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
5
5
|
type Props = {
|
|
6
6
|
appLogoUrl?: string;
|
|
7
7
|
appName?: string;
|
|
8
|
+
deepLinkPreference?: DeepLinkVariant;
|
|
8
9
|
flowNetwork?: 'mainnet' | 'testnet';
|
|
9
10
|
networkConfigurations: NetworkConfigurationMap | undefined;
|
|
10
11
|
projectSettings: ProjectSettings | undefined;
|
|
@@ -13,7 +14,7 @@ type Props = {
|
|
|
13
14
|
walletConnectorsProp?: WalletConnectorsMethod[];
|
|
14
15
|
walletUiUtils: WalletUiUtils<WalletConnector>;
|
|
15
16
|
};
|
|
16
|
-
export declare const useWallets: ({ projectSettings, appLogoUrl, appName, flowNetwork, networkConfigurations, walletBook, walletConnectV1Bridge, walletUiUtils, walletConnectorsProp, }: Props) => {
|
|
17
|
+
export declare const useWallets: ({ projectSettings, appLogoUrl, appName, deepLinkPreference, flowNetwork, networkConfigurations, walletBook, walletConnectV1Bridge, walletUiUtils, walletConnectorsProp, }: Props) => {
|
|
17
18
|
wallets: import("../../../shared").WalletOption[];
|
|
18
19
|
};
|
|
19
20
|
export {};
|
|
@@ -2,7 +2,7 @@ import { useMemo, useEffect } from 'react';
|
|
|
2
2
|
import { getInstalledWallets, getNotInstalledWallets } from '../../../views/WalletList/data.js';
|
|
3
3
|
import { verifyMagicIsSetup } from './utils/verifyMagicIsSetup/verifyMagicIsSetup.js';
|
|
4
4
|
|
|
5
|
-
const useWallets = ({ projectSettings, appLogoUrl, appName, flowNetwork, networkConfigurations, walletBook, walletConnectV1Bridge, walletUiUtils, walletConnectorsProp, }) => {
|
|
5
|
+
const useWallets = ({ projectSettings, appLogoUrl, appName, deepLinkPreference, flowNetwork, networkConfigurations, walletBook, walletConnectV1Bridge, walletUiUtils, walletConnectorsProp, }) => {
|
|
6
6
|
const wallets = useMemo(() => {
|
|
7
7
|
if (!projectSettings || !Object.keys(walletBook !== null && walletBook !== void 0 ? walletBook : {}).length)
|
|
8
8
|
return [];
|
|
@@ -10,6 +10,7 @@ const useWallets = ({ projectSettings, appLogoUrl, appName, flowNetwork, network
|
|
|
10
10
|
appLogoUrl,
|
|
11
11
|
appName,
|
|
12
12
|
customerApiProviders: projectSettings.providers || [],
|
|
13
|
+
deepLinkPreference,
|
|
13
14
|
flowNetwork,
|
|
14
15
|
networkConfigurations,
|
|
15
16
|
skipMemo: true,
|
|
@@ -22,6 +23,7 @@ const useWallets = ({ projectSettings, appLogoUrl, appName, flowNetwork, network
|
|
|
22
23
|
appLogoUrl,
|
|
23
24
|
appName,
|
|
24
25
|
customerApiProviders: projectSettings.providers || [],
|
|
26
|
+
deepLinkPreference,
|
|
25
27
|
flowNetwork,
|
|
26
28
|
networkConfigurations,
|
|
27
29
|
skipMemo: true,
|