@dynamic-labs/sdk-react-core 0.17.0-RC.15 → 0.17.0-RC.17
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 +32 -0
- package/package.cjs +2 -2
- package/package.js +2 -2
- package/package.json +8 -8
- package/src/lib/components/Divider/Divider.cjs +4 -1
- package/src/lib/components/Divider/Divider.d.ts +6 -2
- package/src/lib/components/Divider/Divider.js +4 -1
- package/src/lib/components/TransactionConfirmationPageLayout/TransactionConfirmationPageLayout.cjs +40 -0
- package/src/lib/components/TransactionConfirmationPageLayout/TransactionConfirmationPageLayout.d.ts +17 -0
- package/src/lib/components/TransactionConfirmationPageLayout/TransactionConfirmationPageLayout.js +36 -0
- package/src/lib/components/TransactionConfirmationPageLayout/components/TransactionRow/TransactionRow.cjs +11 -0
- package/src/lib/components/TransactionConfirmationPageLayout/components/TransactionRow/TransactionRow.d.ts +12 -0
- package/src/lib/components/TransactionConfirmationPageLayout/components/TransactionRow/TransactionRow.js +7 -0
- package/src/lib/components/TransactionConfirmationPageLayout/components/TransactionRow/index.d.ts +1 -0
- package/src/lib/components/TransactionConfirmationPageLayout/components/index.d.ts +1 -0
- package/src/lib/components/TransactionConfirmationPageLayout/index.d.ts +2 -0
- package/src/lib/components/index.d.ts +1 -0
- package/src/lib/context/DynamicContext/DynamicContext.cjs +19 -7
- package/src/lib/context/DynamicContext/DynamicContext.d.ts +2 -0
- package/src/lib/context/DynamicContext/DynamicContext.js +19 -7
- package/src/lib/context/SocialRedirectContext/SocialRedirectContext.cjs +6 -1
- package/src/lib/context/SocialRedirectContext/SocialRedirectContext.js +6 -1
- package/src/lib/data/api.cjs +2 -1
- package/src/lib/data/api.d.ts +1 -1
- package/src/lib/data/api.js +2 -1
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.cjs +18 -25
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.js +18 -25
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.types.d.ts +0 -1
- package/src/lib/shared/types/index.d.ts +4 -2
- package/src/lib/styles/index.shadow.cjs +1 -1
- package/src/lib/styles/index.shadow.js +1 -1
- package/src/lib/utils/functions/isWalletLinked/index.d.ts +1 -0
- package/src/lib/utils/functions/isWalletLinked/isWalletLinked.cjs +15 -0
- package/src/lib/utils/functions/isWalletLinked/isWalletLinked.d.ts +2 -0
- package/src/lib/utils/functions/isWalletLinked/isWalletLinked.js +11 -0
- package/src/lib/utils/hooks/multiWallet/index.d.ts +1 -0
- package/src/lib/utils/hooks/multiWallet/useMultiWalletWidgetState/useMultiWalletWidgetState.cjs +0 -2
- package/src/lib/utils/hooks/multiWallet/useMultiWalletWidgetState/useMultiWalletWidgetState.js +0 -2
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.cjs +53 -6
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.d.ts +8 -1
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.js +54 -7
- package/src/lib/utils/hooks/useConnectedAccountWallet/index.d.ts +1 -0
- package/src/lib/utils/hooks/useConnectedAccountWallet/useConnectedAccountWallet.cjs +30 -0
- package/src/lib/utils/hooks/useConnectedAccountWallet/useConnectedAccountWallet.d.ts +2 -0
- package/src/lib/utils/hooks/useConnectedAccountWallet/useConnectedAccountWallet.js +26 -0
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.cjs +5 -4
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.d.ts +1 -1
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.js +5 -4
- package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.cjs +18 -6
- package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.js +18 -6
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.cjs +4 -5
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.js +4 -5
- package/src/lib/utils/hooks/useWalletItemActions/useWalletItemActions.cjs +2 -1
- package/src/lib/utils/hooks/useWalletItemActions/useWalletItemActions.js +2 -1
- package/src/lib/widgets/DynamicWidget/components/DynamicWidgetPrompts/DynamicWidgetPrompts.cjs +15 -5
- package/src/lib/widgets/DynamicWidget/components/DynamicWidgetPrompts/DynamicWidgetPrompts.js +15 -5
- package/src/lib/widgets/DynamicWidget/components/Wallet/Wallet.cjs +2 -1
- package/src/lib/widgets/DynamicWidget/components/Wallet/Wallet.js +2 -1
- package/src/lib/widgets/DynamicWidget/components/WidgetPortal/WidgetPortal.cjs +38 -6
- package/src/lib/widgets/DynamicWidget/components/WidgetPortal/WidgetPortal.d.ts +2 -1
- package/src/lib/widgets/DynamicWidget/components/WidgetPortal/WidgetPortal.js +39 -7
- package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.cjs +2 -2
- package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.js +2 -2
- package/src/lib/widgets/DynamicWidget/{components/DefaultPendingSignModalContent/DefaultPendingSignModalContent.cjs → prompts/DefaultPromptModal/DefaultPromptModal.cjs} +6 -13
- package/src/lib/widgets/DynamicWidget/prompts/DefaultPromptModal/DefaultPromptModal.d.ts +13 -0
- package/src/lib/widgets/DynamicWidget/{components/DefaultPendingSignModalContent/DefaultPendingSignModalContent.js → prompts/DefaultPromptModal/DefaultPromptModal.js} +6 -13
- package/src/lib/widgets/DynamicWidget/prompts/NoQrNotInstalledModalView/NoQrNotInstalledModalView.cjs +1 -1
- package/src/lib/widgets/DynamicWidget/prompts/NoQrNotInstalledModalView/NoQrNotInstalledModalView.js +1 -1
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchModal/PendingAccountSwitchModal.cjs +17 -42
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchModal/PendingAccountSwitchModal.js +18 -43
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchModal/SwitchAccountView/SwitchAccountView.cjs +40 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchModal/SwitchAccountView/SwitchAccountView.d.ts +7 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchModal/SwitchAccountView/SwitchAccountView.js +36 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchModal/SwitchAccountView/index.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchModal/SwitchOrUseActiveAccountView/SwitchOrUseActiveAccountView.cjs +67 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchModal/SwitchOrUseActiveAccountView/SwitchOrUseActiveAccountView.d.ts +8 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchModal/SwitchOrUseActiveAccountView/SwitchOrUseActiveAccountView.js +63 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchModal/SwitchOrUseActiveAccountView/index.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchToLinkModal/PendingAccountSwitchToLinkModal.cjs +57 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchToLinkModal/PendingAccountSwitchToLinkModal.d.ts +2 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchToLinkModal/PendingAccountSwitchToLinkModal.js +53 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchToLinkModal/index.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingConnectionModal/PendingConnectionModal.cjs +44 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingConnectionModal/PendingConnectionModal.d.ts +2 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingConnectionModal/PendingConnectionModal.js +40 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingConnectionModal/index.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingSignModal/DefaultPendingSignModalContent/DefaultPendingSignModalContent.cjs +64 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingSignModal/DefaultPendingSignModalContent/DefaultPendingSignModalContent.d.ts +2 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingSignModal/DefaultPendingSignModalContent/DefaultPendingSignModalContent.js +60 -0
- package/src/lib/widgets/DynamicWidget/prompts/PendingSignModal/PendingSignModal.cjs +2 -33
- package/src/lib/widgets/DynamicWidget/prompts/PendingSignModal/PendingSignModal.js +2 -33
- package/src/lib/widgets/DynamicWidget/prompts/PrimaryNotConnectedModal/PrimaryNotConnectedModal.cjs +4 -6
- package/src/lib/widgets/DynamicWidget/prompts/PrimaryNotConnectedModal/PrimaryNotConnectedModal.js +5 -7
- package/src/lib/widgets/DynamicWidget/prompts/QrCodeModalView/QrCodeModalView.cjs +1 -1
- package/src/lib/widgets/DynamicWidget/prompts/QrCodeModalView/QrCodeModalView.js +1 -1
- package/src/lib/widgets/DynamicWidget/components/DefaultPendingSignModalContent/DefaultPendingSignModalContent.d.ts +0 -2
- package/src/lib/widgets/DynamicWidget/components/DefaultPendingSignModalContent/DefaultPendingSignModalContent.types.d.ts +0 -7
- package/src/lib/widgets/DynamicWidget/prompts/DetectedKnownSecondaryWalletModal/DetectedKnownSecondaryWalletModal.cjs +0 -61
- package/src/lib/widgets/DynamicWidget/prompts/DetectedKnownSecondaryWalletModal/DetectedKnownSecondaryWalletModal.d.ts +0 -7
- package/src/lib/widgets/DynamicWidget/prompts/DetectedKnownSecondaryWalletModal/DetectedKnownSecondaryWalletModal.js +0 -57
- package/src/lib/widgets/DynamicWidget/prompts/DetectedKnownSecondaryWalletModal/index.d.ts +0 -1
- /package/src/lib/widgets/DynamicWidget/{components → prompts/PendingSignModal}/DefaultPendingSignModalContent/index.d.ts +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
2
|
+
import { useState, useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
const useConnectedAccountWallet = (connector, secondaryWallets) => {
|
|
5
|
+
const [wallet, setWallet] = useState();
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const getConnectedAccounts = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
+
var _a;
|
|
9
|
+
if (!connector) {
|
|
10
|
+
setWallet(undefined);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const connectedAccounts = (_a = (yield connector.getConnectedAccounts())) !== null && _a !== void 0 ? _a : [];
|
|
14
|
+
const connectedWallet = secondaryWallets.find((secondaryWallet) => {
|
|
15
|
+
var _a;
|
|
16
|
+
return secondaryWallet.address.toLowerCase() ===
|
|
17
|
+
((_a = connectedAccounts[0]) === null || _a === void 0 ? void 0 : _a.toLowerCase());
|
|
18
|
+
});
|
|
19
|
+
setWallet(connectedWallet);
|
|
20
|
+
});
|
|
21
|
+
getConnectedAccounts();
|
|
22
|
+
}, [connector, secondaryWallets]);
|
|
23
|
+
return wallet;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { useConnectedAccountWallet };
|
|
@@ -40,7 +40,7 @@ const useVerifyWallet = ({ consumeNonce, displayTermsOfService, environmentId, p
|
|
|
40
40
|
// We need this boolean for the part of the logic where we already persisted a new authToken,
|
|
41
41
|
// and need to distinguish between logic for verify or linking.
|
|
42
42
|
const verifyOnly = !authToken;
|
|
43
|
-
const generateJWT = (walletConnector, walletProvider, fetchPublicAddressOpts, publicWalletAddress, captchaToken) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
const generateJWT = (walletConnector, walletProvider, fetchPublicAddressOpts, publicWalletAddress, captchaToken, oauth) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
44
44
|
let Jwt;
|
|
45
45
|
const nonce = consumeNonce();
|
|
46
46
|
if (nonce === undefined)
|
|
@@ -56,7 +56,8 @@ const useVerifyWallet = ({ consumeNonce, displayTermsOfService, environmentId, p
|
|
|
56
56
|
walletProvider,
|
|
57
57
|
});
|
|
58
58
|
if (authToken === undefined || !multiWalletEnabled) {
|
|
59
|
-
Jwt = yield api.verifyWallet(environmentId, Object.assign(Object.assign({}, verifyArgs), { captchaToken
|
|
59
|
+
Jwt = yield api.verifyWallet(environmentId, Object.assign(Object.assign({}, verifyArgs), { captchaToken,
|
|
60
|
+
oauth }));
|
|
60
61
|
}
|
|
61
62
|
else {
|
|
62
63
|
Jwt = yield api.linkWallet(environmentId, verifyArgs, authToken);
|
|
@@ -119,7 +120,7 @@ const useVerifyWallet = ({ consumeNonce, displayTermsOfService, environmentId, p
|
|
|
119
120
|
setErrorMessage(e.code);
|
|
120
121
|
}
|
|
121
122
|
};
|
|
122
|
-
return ({ walletConnector, fetchPublicAddressOpts, publicWalletAddress, captchaToken, }) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
123
|
+
return ({ walletConnector, fetchPublicAddressOpts, publicWalletAddress, captchaToken, oauth, }) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
123
124
|
const walletProvider = getWalletProvider.getWalletProvider(walletConnector);
|
|
124
125
|
const network = yield walletConnector.getNetwork();
|
|
125
126
|
const _isSupportedNetwork = isSupportedNetwork.isSupportedNetwork({
|
|
@@ -127,7 +128,7 @@ const useVerifyWallet = ({ consumeNonce, displayTermsOfService, environmentId, p
|
|
|
127
128
|
walletConnector,
|
|
128
129
|
});
|
|
129
130
|
try {
|
|
130
|
-
const Jwt = yield generateJWT(walletConnector, walletProvider, fetchPublicAddressOpts, publicWalletAddress, captchaToken);
|
|
131
|
+
const Jwt = yield generateJWT(walletConnector, walletProvider, fetchPublicAddressOpts, publicWalletAddress, captchaToken, oauth);
|
|
131
132
|
const decodedJwt = decodeJwt.decodeJwt(Jwt);
|
|
132
133
|
if (decodedJwt === undefined)
|
|
133
134
|
throw new utils.DynamicError('Invalid token!');
|
|
@@ -5,5 +5,5 @@ type UseVerifyWalletArgs = VerifyProps & ProjectSettingsProps & {
|
|
|
5
5
|
displayTermsOfService: boolean;
|
|
6
6
|
setIsSingleWalletAccount: Dispatch<SetStateAction<boolean>>;
|
|
7
7
|
};
|
|
8
|
-
export declare const useVerifyWallet: ({ consumeNonce, displayTermsOfService, environmentId, projectSettings, setIsSingleWalletAccount, }: UseVerifyWalletArgs) => ({ walletConnector, fetchPublicAddressOpts, publicWalletAddress, captchaToken, }: VerifyCallbackArgs) => Promise<void>;
|
|
8
|
+
export declare const useVerifyWallet: ({ consumeNonce, displayTermsOfService, environmentId, projectSettings, setIsSingleWalletAccount, }: UseVerifyWalletArgs) => ({ walletConnector, fetchPublicAddressOpts, publicWalletAddress, captchaToken, oauth, }: VerifyCallbackArgs) => Promise<void>;
|
|
9
9
|
export {};
|
|
@@ -36,7 +36,7 @@ const useVerifyWallet = ({ consumeNonce, displayTermsOfService, environmentId, p
|
|
|
36
36
|
// We need this boolean for the part of the logic where we already persisted a new authToken,
|
|
37
37
|
// and need to distinguish between logic for verify or linking.
|
|
38
38
|
const verifyOnly = !authToken;
|
|
39
|
-
const generateJWT = (walletConnector, walletProvider, fetchPublicAddressOpts, publicWalletAddress, captchaToken) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
const generateJWT = (walletConnector, walletProvider, fetchPublicAddressOpts, publicWalletAddress, captchaToken, oauth) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
40
|
let Jwt;
|
|
41
41
|
const nonce = consumeNonce();
|
|
42
42
|
if (nonce === undefined)
|
|
@@ -52,7 +52,8 @@ const useVerifyWallet = ({ consumeNonce, displayTermsOfService, environmentId, p
|
|
|
52
52
|
walletProvider,
|
|
53
53
|
});
|
|
54
54
|
if (authToken === undefined || !multiWalletEnabled) {
|
|
55
|
-
Jwt = yield verifyWallet(environmentId, Object.assign(Object.assign({}, verifyArgs), { captchaToken
|
|
55
|
+
Jwt = yield verifyWallet(environmentId, Object.assign(Object.assign({}, verifyArgs), { captchaToken,
|
|
56
|
+
oauth }));
|
|
56
57
|
}
|
|
57
58
|
else {
|
|
58
59
|
Jwt = yield linkWallet(environmentId, verifyArgs, authToken);
|
|
@@ -115,7 +116,7 @@ const useVerifyWallet = ({ consumeNonce, displayTermsOfService, environmentId, p
|
|
|
115
116
|
setErrorMessage(e.code);
|
|
116
117
|
}
|
|
117
118
|
};
|
|
118
|
-
return ({ walletConnector, fetchPublicAddressOpts, publicWalletAddress, captchaToken, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
119
|
+
return ({ walletConnector, fetchPublicAddressOpts, publicWalletAddress, captchaToken, oauth, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
119
120
|
const walletProvider = getWalletProvider(walletConnector);
|
|
120
121
|
const network = yield walletConnector.getNetwork();
|
|
121
122
|
const _isSupportedNetwork = isSupportedNetwork({
|
|
@@ -123,7 +124,7 @@ const useVerifyWallet = ({ consumeNonce, displayTermsOfService, environmentId, p
|
|
|
123
124
|
walletConnector,
|
|
124
125
|
});
|
|
125
126
|
try {
|
|
126
|
-
const Jwt = yield generateJWT(walletConnector, walletProvider, fetchPublicAddressOpts, publicWalletAddress, captchaToken);
|
|
127
|
+
const Jwt = yield generateJWT(walletConnector, walletProvider, fetchPublicAddressOpts, publicWalletAddress, captchaToken, oauth);
|
|
127
128
|
const decodedJwt = decodeJwt(Jwt);
|
|
128
129
|
if (decodedJwt === undefined)
|
|
129
130
|
throw new DynamicError('Invalid token!');
|
|
@@ -97,9 +97,7 @@ const useWalletConnectors = ({ authToken, wallets: availableWallets, multiWallet
|
|
|
97
97
|
const connectedAccounts = yield newWallet.connector.getConnectedAccounts();
|
|
98
98
|
return { connectedAccounts, newWallet };
|
|
99
99
|
}), [wallets]);
|
|
100
|
-
const checkIfAccountChangeIsRequired = React.useCallback((primaryWallet, newPrimaryWallet) => {
|
|
101
|
-
if (!primaryWallet)
|
|
102
|
-
return;
|
|
100
|
+
const checkIfAccountChangeIsRequired = React.useCallback((primaryWallet, newPrimaryWallet, connectedAccounts) => {
|
|
103
101
|
/**
|
|
104
102
|
* we need to check multiWalletWidgetState here because `setPrimaryWallet` currently gets
|
|
105
103
|
* called twice: once when the user clicks "make active" and once when the user performs
|
|
@@ -107,8 +105,12 @@ const useWalletConnectors = ({ authToken, wallets: availableWallets, multiWallet
|
|
|
107
105
|
* (https://github.com/dynamic-labs/DynamicAuth/pull/550) is merged, since setting the
|
|
108
106
|
* primary wallet will be simpler, so we won't need to call `setPrimaryWallet` twice.
|
|
109
107
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
if (!primaryWallet || multiWalletWidgetState !== 'idle')
|
|
109
|
+
return;
|
|
110
|
+
const accountIsNotConnectedInSecondaryWallet = connectedAccounts &&
|
|
111
|
+
!connectedAccounts.find((connectedAccount) => connectedAccount.toLowerCase() ===
|
|
112
|
+
newPrimaryWallet.address.toLowerCase());
|
|
113
|
+
return (isSameWalletName.isSameWalletName(newPrimaryWallet.connector.name, primaryWallet.connector.name) || accountIsNotConnectedInSecondaryWallet);
|
|
112
114
|
}, [multiWalletWidgetState]);
|
|
113
115
|
const checkIfShowQrCodeModal = React.useCallback((wallet) => !wallet.connector.isInstalledOnBrowser() &&
|
|
114
116
|
!wallet.connector.canConnectViaCustodialService, []);
|
|
@@ -123,7 +125,8 @@ const useWalletConnectors = ({ authToken, wallets: availableWallets, multiWallet
|
|
|
123
125
|
return;
|
|
124
126
|
const primaryWallet = getPrimaryWallet();
|
|
125
127
|
if (checkIfAccountChangeIsRequired(primaryWallet, newPrimaryWallet)) {
|
|
126
|
-
|
|
128
|
+
yield newPrimaryWallet.connector.connect();
|
|
129
|
+
setPrimaryWalletId(walletId);
|
|
127
130
|
return;
|
|
128
131
|
}
|
|
129
132
|
if (!connectedAccounts.length) {
|
|
@@ -146,6 +149,15 @@ const useWalletConnectors = ({ authToken, wallets: availableWallets, multiWallet
|
|
|
146
149
|
setQrcodeUri(uri);
|
|
147
150
|
}),
|
|
148
151
|
});
|
|
152
|
+
/**
|
|
153
|
+
* need to check for connected account again for wallets that disconnect on refresh
|
|
154
|
+
* and only reconnect upon fetching public address above
|
|
155
|
+
*/
|
|
156
|
+
const updatedConnectedAccounts = yield newPrimaryWallet.connector.getConnectedAccounts();
|
|
157
|
+
if (checkIfAccountChangeIsRequired(primaryWallet, newPrimaryWallet, updatedConnectedAccounts)) {
|
|
158
|
+
setMultiWalletWidgetState('awaiting_account_switch', 'switching_primary');
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
149
161
|
if (publicAddress) {
|
|
150
162
|
setPrimaryWalletId(walletId);
|
|
151
163
|
setMultiWalletWidgetState('idle');
|
|
@@ -93,9 +93,7 @@ const useWalletConnectors = ({ authToken, wallets: availableWallets, multiWallet
|
|
|
93
93
|
const connectedAccounts = yield newWallet.connector.getConnectedAccounts();
|
|
94
94
|
return { connectedAccounts, newWallet };
|
|
95
95
|
}), [wallets]);
|
|
96
|
-
const checkIfAccountChangeIsRequired = useCallback((primaryWallet, newPrimaryWallet) => {
|
|
97
|
-
if (!primaryWallet)
|
|
98
|
-
return;
|
|
96
|
+
const checkIfAccountChangeIsRequired = useCallback((primaryWallet, newPrimaryWallet, connectedAccounts) => {
|
|
99
97
|
/**
|
|
100
98
|
* we need to check multiWalletWidgetState here because `setPrimaryWallet` currently gets
|
|
101
99
|
* called twice: once when the user clicks "make active" and once when the user performs
|
|
@@ -103,8 +101,12 @@ const useWalletConnectors = ({ authToken, wallets: availableWallets, multiWallet
|
|
|
103
101
|
* (https://github.com/dynamic-labs/DynamicAuth/pull/550) is merged, since setting the
|
|
104
102
|
* primary wallet will be simpler, so we won't need to call `setPrimaryWallet` twice.
|
|
105
103
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
if (!primaryWallet || multiWalletWidgetState !== 'idle')
|
|
105
|
+
return;
|
|
106
|
+
const accountIsNotConnectedInSecondaryWallet = connectedAccounts &&
|
|
107
|
+
!connectedAccounts.find((connectedAccount) => connectedAccount.toLowerCase() ===
|
|
108
|
+
newPrimaryWallet.address.toLowerCase());
|
|
109
|
+
return (isSameWalletName(newPrimaryWallet.connector.name, primaryWallet.connector.name) || accountIsNotConnectedInSecondaryWallet);
|
|
108
110
|
}, [multiWalletWidgetState]);
|
|
109
111
|
const checkIfShowQrCodeModal = useCallback((wallet) => !wallet.connector.isInstalledOnBrowser() &&
|
|
110
112
|
!wallet.connector.canConnectViaCustodialService, []);
|
|
@@ -119,7 +121,8 @@ const useWalletConnectors = ({ authToken, wallets: availableWallets, multiWallet
|
|
|
119
121
|
return;
|
|
120
122
|
const primaryWallet = getPrimaryWallet();
|
|
121
123
|
if (checkIfAccountChangeIsRequired(primaryWallet, newPrimaryWallet)) {
|
|
122
|
-
|
|
124
|
+
yield newPrimaryWallet.connector.connect();
|
|
125
|
+
setPrimaryWalletId(walletId);
|
|
123
126
|
return;
|
|
124
127
|
}
|
|
125
128
|
if (!connectedAccounts.length) {
|
|
@@ -142,6 +145,15 @@ const useWalletConnectors = ({ authToken, wallets: availableWallets, multiWallet
|
|
|
142
145
|
setQrcodeUri(uri);
|
|
143
146
|
}),
|
|
144
147
|
});
|
|
148
|
+
/**
|
|
149
|
+
* need to check for connected account again for wallets that disconnect on refresh
|
|
150
|
+
* and only reconnect upon fetching public address above
|
|
151
|
+
*/
|
|
152
|
+
const updatedConnectedAccounts = yield newPrimaryWallet.connector.getConnectedAccounts();
|
|
153
|
+
if (checkIfAccountChangeIsRequired(primaryWallet, newPrimaryWallet, updatedConnectedAccounts)) {
|
|
154
|
+
setMultiWalletWidgetState('awaiting_account_switch', 'switching_primary');
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
145
157
|
if (publicAddress) {
|
|
146
158
|
setPrimaryWalletId(walletId);
|
|
147
159
|
setMultiWalletWidgetState('idle');
|
|
@@ -92,6 +92,7 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
92
92
|
onAccountChange: (accounts) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
93
93
|
const [newAddress] = accounts;
|
|
94
94
|
yield computeConnectedStateForWallets();
|
|
95
|
+
const newWallet = secondaryWallets.find((wallet) => walletConnectorCore.isSameAddress(wallet.address, newAddress, wallet.chain));
|
|
95
96
|
if (walletConnectorCore.isSameAddress(newAddress, primaryWallet.address, primaryWallet.chain)) {
|
|
96
97
|
setMultiWalletWidgetState('idle');
|
|
97
98
|
}
|
|
@@ -102,12 +103,10 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
102
103
|
handleAccountChangeWhenAwaitingAccountSwitch(true, newAddress);
|
|
103
104
|
yield computeConnectedStateForWallets();
|
|
104
105
|
}
|
|
105
|
-
else if (multiWalletWidgetState === 'idle' &&
|
|
106
|
-
|
|
107
|
-
setMultiWalletWidgetState('detected_known_secondary_wallet');
|
|
106
|
+
else if (multiWalletWidgetState === 'idle' && newWallet) {
|
|
107
|
+
setPrimaryWalletId(newWallet.id);
|
|
108
108
|
}
|
|
109
|
-
else if (multiWalletWidgetState === 'idle' &&
|
|
110
|
-
!secondaryWallets.some((wallet) => walletConnectorCore.isSameAddress(wallet.address, newAddress, wallet.chain))) {
|
|
109
|
+
else if (multiWalletWidgetState === 'idle' && !newWallet) {
|
|
111
110
|
if (user) {
|
|
112
111
|
setMultiWalletWidgetState('detected_new_wallet');
|
|
113
112
|
setSelectedWalletConnector(primaryWallet.connector);
|
|
@@ -88,6 +88,7 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
88
88
|
onAccountChange: (accounts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
89
|
const [newAddress] = accounts;
|
|
90
90
|
yield computeConnectedStateForWallets();
|
|
91
|
+
const newWallet = secondaryWallets.find((wallet) => isSameAddress(wallet.address, newAddress, wallet.chain));
|
|
91
92
|
if (isSameAddress(newAddress, primaryWallet.address, primaryWallet.chain)) {
|
|
92
93
|
setMultiWalletWidgetState('idle');
|
|
93
94
|
}
|
|
@@ -98,12 +99,10 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
98
99
|
handleAccountChangeWhenAwaitingAccountSwitch(true, newAddress);
|
|
99
100
|
yield computeConnectedStateForWallets();
|
|
100
101
|
}
|
|
101
|
-
else if (multiWalletWidgetState === 'idle' &&
|
|
102
|
-
|
|
103
|
-
setMultiWalletWidgetState('detected_known_secondary_wallet');
|
|
102
|
+
else if (multiWalletWidgetState === 'idle' && newWallet) {
|
|
103
|
+
setPrimaryWalletId(newWallet.id);
|
|
104
104
|
}
|
|
105
|
-
else if (multiWalletWidgetState === 'idle' &&
|
|
106
|
-
!secondaryWallets.some((wallet) => isSameAddress(wallet.address, newAddress, wallet.chain))) {
|
|
105
|
+
else if (multiWalletWidgetState === 'idle' && !newWallet) {
|
|
107
106
|
if (user) {
|
|
108
107
|
setMultiWalletWidgetState('detected_new_wallet');
|
|
109
108
|
setSelectedWalletConnector(primaryWallet.connector);
|
|
@@ -25,7 +25,7 @@ var useConnectAndSignSplitSteps = require('../authenticationHooks/useConnectAndS
|
|
|
25
25
|
var isSelectedWalletAlreadyConnected = require('../../functions/isSelectedWalletAlreadyConnected/isSelectedWalletAlreadyConnected.cjs');
|
|
26
26
|
|
|
27
27
|
const useWalletItemActions = () => {
|
|
28
|
-
const { setMultiWalletWidgetState, setShowAuthFlow, setSelectedWalletConnector, wallets, setQrcodeUri, setDesktopUri, user, connectedWallets, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
28
|
+
const { setMultiWalletWidgetState, setShowAuthFlow, setSelectedWalletConnector, wallets, setQrcodeUri, setDesktopUri, user, connectedWallets, setIsVerifying, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
29
29
|
const { mockedSDK } = MockContext.useMockContext();
|
|
30
30
|
const { setError } = ErrorContext.useErrorContext();
|
|
31
31
|
const { setView } = ViewContext.useViewContext();
|
|
@@ -108,6 +108,7 @@ const useWalletItemActions = () => {
|
|
|
108
108
|
if (walletConnector.connectedChain === 'FLOW') {
|
|
109
109
|
yield walletConnector.endSession();
|
|
110
110
|
}
|
|
111
|
+
setIsVerifying(false);
|
|
111
112
|
if (isSelectedWalletAlreadyConnected.isSelectedWalletAlreadyConnected(connectedWallets, walletConnector, user) &&
|
|
112
113
|
walletConnector.connectedChain !== 'FLOW') {
|
|
113
114
|
// wallet is already connected
|
|
@@ -21,7 +21,7 @@ import { useConnectAndSignSplitSteps } from '../authenticationHooks/useConnectAn
|
|
|
21
21
|
import { isSelectedWalletAlreadyConnected } from '../../functions/isSelectedWalletAlreadyConnected/isSelectedWalletAlreadyConnected.js';
|
|
22
22
|
|
|
23
23
|
const useWalletItemActions = () => {
|
|
24
|
-
const { setMultiWalletWidgetState, setShowAuthFlow, setSelectedWalletConnector, wallets, setQrcodeUri, setDesktopUri, user, connectedWallets, } = useInternalDynamicContext();
|
|
24
|
+
const { setMultiWalletWidgetState, setShowAuthFlow, setSelectedWalletConnector, wallets, setQrcodeUri, setDesktopUri, user, connectedWallets, setIsVerifying, } = useInternalDynamicContext();
|
|
25
25
|
const { mockedSDK } = useMockContext();
|
|
26
26
|
const { setError } = useErrorContext();
|
|
27
27
|
const { setView } = useViewContext();
|
|
@@ -104,6 +104,7 @@ const useWalletItemActions = () => {
|
|
|
104
104
|
if (walletConnector.connectedChain === 'FLOW') {
|
|
105
105
|
yield walletConnector.endSession();
|
|
106
106
|
}
|
|
107
|
+
setIsVerifying(false);
|
|
107
108
|
if (isSelectedWalletAlreadyConnected(connectedWallets, walletConnector, user) &&
|
|
108
109
|
walletConnector.connectedChain !== 'FLOW') {
|
|
109
110
|
// wallet is already connected
|
package/src/lib/widgets/DynamicWidget/components/DynamicWidgetPrompts/DynamicWidgetPrompts.cjs
CHANGED
|
@@ -4,35 +4,45 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var React = require('react');
|
|
7
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
7
8
|
var useInternalDynamicContext = require('../../../../context/DynamicContext/useInternalDynamicContext.cjs');
|
|
8
|
-
var DetectedKnownSecondaryWalletModal = require('../../prompts/DetectedKnownSecondaryWalletModal/DetectedKnownSecondaryWalletModal.cjs');
|
|
9
9
|
var DetectedNewWalletModal = require('../../prompts/DetectedNewWalletModal/DetectedNewWalletModal.cjs');
|
|
10
10
|
var PendingAccountSwitchModal = require('../../prompts/PendingAccountSwitchModal/PendingAccountSwitchModal.cjs');
|
|
11
|
+
var PendingAccountSwitchToLinkModal = require('../../prompts/PendingAccountSwitchToLinkModal/PendingAccountSwitchToLinkModal.cjs');
|
|
11
12
|
var PendingSignModal = require('../../prompts/PendingSignModal/PendingSignModal.cjs');
|
|
12
13
|
var PrimaryNotConnectedModal = require('../../prompts/PrimaryNotConnectedModal/PrimaryNotConnectedModal.cjs');
|
|
13
14
|
var QrCodeModalView = require('../../prompts/QrCodeModalView/QrCodeModalView.cjs');
|
|
14
15
|
var UnlinkWalletPopUp = require('../../prompts/UnlinkWalletPopUp/UnlinkWalletPopUp.cjs');
|
|
15
16
|
var WidgetPortal = require('../WidgetPortal/WidgetPortal.cjs');
|
|
16
17
|
var NoQrNotInstalledModalView = require('../../prompts/NoQrNotInstalledModalView/NoQrNotInstalledModalView.cjs');
|
|
18
|
+
var PendingConnectionModal = require('../../prompts/PendingConnectionModal/PendingConnectionModal.cjs');
|
|
17
19
|
|
|
18
20
|
const mapAccountSwitchStateToPromptComponent = {
|
|
19
|
-
linking_new_wallet:
|
|
21
|
+
linking_new_wallet: PendingAccountSwitchToLinkModal.PendingAccountSwitchToLinkModal,
|
|
20
22
|
primary_not_connected: PrimaryNotConnectedModal.PrimaryNotConnectedModal,
|
|
21
23
|
switching_primary: PendingAccountSwitchModal.PendingAccountSwitchModal,
|
|
22
24
|
};
|
|
23
25
|
const DynamicWidgetPrompts = () => {
|
|
24
26
|
var _a, _b, _c;
|
|
25
|
-
const { setDesktopUri, accountSwitchState, multiWalletWidgetState, showQrcodeModal, setShowQrcodeModal, selectedWalletConnector, selectedWalletWithAction,
|
|
27
|
+
const { setDesktopUri, accountSwitchState, multiWalletWidgetState, showQrcodeModal, setShowQrcodeModal, selectedWalletConnector, selectedWalletWithAction, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
26
28
|
const AccountSwitchModal = React.useMemo(() => {
|
|
27
29
|
if (multiWalletWidgetState !== 'awaiting_account_switch')
|
|
28
30
|
return null;
|
|
29
31
|
return mapAccountSwitchStateToPromptComponent[accountSwitchState] || null;
|
|
30
32
|
}, [accountSwitchState, multiWalletWidgetState]);
|
|
33
|
+
const AwaitingConnectionModal = React.useMemo(() => {
|
|
34
|
+
if (selectedWalletConnector &&
|
|
35
|
+
(walletConnectorCore.isEmailOTPWalletConnector(selectedWalletConnector) ||
|
|
36
|
+
walletConnectorCore.isEmailWalletConnector(selectedWalletConnector))) {
|
|
37
|
+
return PendingSignModal.PendingSignModal;
|
|
38
|
+
}
|
|
39
|
+
return PendingConnectionModal.PendingConnectionModal;
|
|
40
|
+
}, [selectedWalletConnector]);
|
|
31
41
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [multiWalletWidgetState === 'awaiting_signature' && jsxRuntime.jsx(PendingSignModal.PendingSignModal, {}), AccountSwitchModal && jsxRuntime.jsx(AccountSwitchModal, {}), (selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.action) === 'unlink' && (jsxRuntime.jsx(UnlinkWalletPopUp.UnlinkWalletPopUp, { walletId: (_a = selectedWalletWithAction.wallet) === null || _a === void 0 ? void 0 : _a.id })), multiWalletWidgetState === 'awaiting_connection' &&
|
|
32
|
-
(showQrcodeModal ? (jsxRuntime.jsx(WidgetPortal.WidgetPortal, Object.assign({ onBackdropClick: () => {
|
|
42
|
+
(showQrcodeModal ? (jsxRuntime.jsx(WidgetPortal.WidgetPortal, Object.assign({ showCloseButton: true, onBackdropClick: () => {
|
|
33
43
|
setShowQrcodeModal(false);
|
|
34
44
|
setDesktopUri('');
|
|
35
|
-
} }, { children: (selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.canConnectViaQrCode) ? (jsxRuntime.jsx(QrCodeModalView.QrCodeModalView, { walletId: (_c = (_b = selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.wallet) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : '' })) : (jsxRuntime.jsx(NoQrNotInstalledModalView.NoQrNotInstalledModalView, {})) }))) : (jsxRuntime.jsx(
|
|
45
|
+
} }, { children: (selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.canConnectViaQrCode) ? (jsxRuntime.jsx(QrCodeModalView.QrCodeModalView, { walletId: (_c = (_b = selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.wallet) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : '' })) : (jsxRuntime.jsx(NoQrNotInstalledModalView.NoQrNotInstalledModalView, {})) }))) : (jsxRuntime.jsx(AwaitingConnectionModal, {}))), multiWalletWidgetState === 'detected_new_wallet' && (jsxRuntime.jsx(DetectedNewWalletModal.DetectedNewWalletModal, {}))] }));
|
|
36
46
|
};
|
|
37
47
|
|
|
38
48
|
exports.DynamicWidgetPrompts = DynamicWidgetPrompts;
|
package/src/lib/widgets/DynamicWidget/components/DynamicWidgetPrompts/DynamicWidgetPrompts.js
CHANGED
|
@@ -1,34 +1,44 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
|
+
import { isEmailOTPWalletConnector, isEmailWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
3
4
|
import { useInternalDynamicContext } from '../../../../context/DynamicContext/useInternalDynamicContext.js';
|
|
4
|
-
import { DetectedKnownSecondaryWalletModal } from '../../prompts/DetectedKnownSecondaryWalletModal/DetectedKnownSecondaryWalletModal.js';
|
|
5
5
|
import { DetectedNewWalletModal } from '../../prompts/DetectedNewWalletModal/DetectedNewWalletModal.js';
|
|
6
6
|
import { PendingAccountSwitchModal } from '../../prompts/PendingAccountSwitchModal/PendingAccountSwitchModal.js';
|
|
7
|
+
import { PendingAccountSwitchToLinkModal } from '../../prompts/PendingAccountSwitchToLinkModal/PendingAccountSwitchToLinkModal.js';
|
|
7
8
|
import { PendingSignModal } from '../../prompts/PendingSignModal/PendingSignModal.js';
|
|
8
9
|
import { PrimaryNotConnectedModal } from '../../prompts/PrimaryNotConnectedModal/PrimaryNotConnectedModal.js';
|
|
9
10
|
import { QrCodeModalView } from '../../prompts/QrCodeModalView/QrCodeModalView.js';
|
|
10
11
|
import { UnlinkWalletPopUp } from '../../prompts/UnlinkWalletPopUp/UnlinkWalletPopUp.js';
|
|
11
12
|
import { WidgetPortal } from '../WidgetPortal/WidgetPortal.js';
|
|
12
13
|
import { NoQrNotInstalledModalView } from '../../prompts/NoQrNotInstalledModalView/NoQrNotInstalledModalView.js';
|
|
14
|
+
import { PendingConnectionModal } from '../../prompts/PendingConnectionModal/PendingConnectionModal.js';
|
|
13
15
|
|
|
14
16
|
const mapAccountSwitchStateToPromptComponent = {
|
|
15
|
-
linking_new_wallet:
|
|
17
|
+
linking_new_wallet: PendingAccountSwitchToLinkModal,
|
|
16
18
|
primary_not_connected: PrimaryNotConnectedModal,
|
|
17
19
|
switching_primary: PendingAccountSwitchModal,
|
|
18
20
|
};
|
|
19
21
|
const DynamicWidgetPrompts = () => {
|
|
20
22
|
var _a, _b, _c;
|
|
21
|
-
const { setDesktopUri, accountSwitchState, multiWalletWidgetState, showQrcodeModal, setShowQrcodeModal, selectedWalletConnector, selectedWalletWithAction,
|
|
23
|
+
const { setDesktopUri, accountSwitchState, multiWalletWidgetState, showQrcodeModal, setShowQrcodeModal, selectedWalletConnector, selectedWalletWithAction, } = useInternalDynamicContext();
|
|
22
24
|
const AccountSwitchModal = useMemo(() => {
|
|
23
25
|
if (multiWalletWidgetState !== 'awaiting_account_switch')
|
|
24
26
|
return null;
|
|
25
27
|
return mapAccountSwitchStateToPromptComponent[accountSwitchState] || null;
|
|
26
28
|
}, [accountSwitchState, multiWalletWidgetState]);
|
|
29
|
+
const AwaitingConnectionModal = useMemo(() => {
|
|
30
|
+
if (selectedWalletConnector &&
|
|
31
|
+
(isEmailOTPWalletConnector(selectedWalletConnector) ||
|
|
32
|
+
isEmailWalletConnector(selectedWalletConnector))) {
|
|
33
|
+
return PendingSignModal;
|
|
34
|
+
}
|
|
35
|
+
return PendingConnectionModal;
|
|
36
|
+
}, [selectedWalletConnector]);
|
|
27
37
|
return (jsxs(Fragment, { children: [multiWalletWidgetState === 'awaiting_signature' && jsx(PendingSignModal, {}), AccountSwitchModal && jsx(AccountSwitchModal, {}), (selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.action) === 'unlink' && (jsx(UnlinkWalletPopUp, { walletId: (_a = selectedWalletWithAction.wallet) === null || _a === void 0 ? void 0 : _a.id })), multiWalletWidgetState === 'awaiting_connection' &&
|
|
28
|
-
(showQrcodeModal ? (jsx(WidgetPortal, Object.assign({ onBackdropClick: () => {
|
|
38
|
+
(showQrcodeModal ? (jsx(WidgetPortal, Object.assign({ showCloseButton: true, onBackdropClick: () => {
|
|
29
39
|
setShowQrcodeModal(false);
|
|
30
40
|
setDesktopUri('');
|
|
31
|
-
} }, { children: (selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.canConnectViaQrCode) ? (jsx(QrCodeModalView, { walletId: (_c = (_b = selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.wallet) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : '' })) : (jsx(NoQrNotInstalledModalView, {})) }))) : (jsx(
|
|
41
|
+
} }, { children: (selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.canConnectViaQrCode) ? (jsx(QrCodeModalView, { walletId: (_c = (_b = selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.wallet) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : '' })) : (jsx(NoQrNotInstalledModalView, {})) }))) : (jsx(AwaitingConnectionModal, {}))), multiWalletWidgetState === 'detected_new_wallet' && (jsx(DetectedNewWalletModal, {}))] }));
|
|
32
42
|
};
|
|
33
43
|
|
|
34
44
|
export { DynamicWidgetPrompts };
|
|
@@ -44,7 +44,7 @@ var WalletIconWithStatus = require('../WalletIconWithStatus/WalletIconWithStatus
|
|
|
44
44
|
|
|
45
45
|
const Wallet = ({ wallet, ens }) => {
|
|
46
46
|
const { id: walletId, connector, address, connected } = wallet;
|
|
47
|
-
const { computeConnectedStateForWallets, setPrimaryWallet, setSelectedWalletConnector, setSelectedWalletWithAction, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
47
|
+
const { computeConnectedStateForWallets, setPrimaryWallet, setSelectedWalletConnector, setShowWidgetStatePopup, setSelectedWalletWithAction, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
48
48
|
const iconSize = 20;
|
|
49
49
|
const options = [
|
|
50
50
|
{
|
|
@@ -74,6 +74,7 @@ const Wallet = ({ wallet, ens }) => {
|
|
|
74
74
|
if (connector.connectedChain === 'FLOW') {
|
|
75
75
|
(_a = connector.endSession) === null || _a === void 0 ? void 0 : _a.call(connector);
|
|
76
76
|
}
|
|
77
|
+
setShowWidgetStatePopup(true);
|
|
77
78
|
setSelectedWalletWithAction({ action: 'select', wallet });
|
|
78
79
|
setPrimaryWallet(walletId);
|
|
79
80
|
computeConnectedStateForWallets();
|
|
@@ -40,7 +40,7 @@ import { WalletIconWithStatus } from '../WalletIconWithStatus/WalletIconWithStat
|
|
|
40
40
|
|
|
41
41
|
const Wallet = ({ wallet, ens }) => {
|
|
42
42
|
const { id: walletId, connector, address, connected } = wallet;
|
|
43
|
-
const { computeConnectedStateForWallets, setPrimaryWallet, setSelectedWalletConnector, setSelectedWalletWithAction, } = useInternalDynamicContext();
|
|
43
|
+
const { computeConnectedStateForWallets, setPrimaryWallet, setSelectedWalletConnector, setShowWidgetStatePopup, setSelectedWalletWithAction, } = useInternalDynamicContext();
|
|
44
44
|
const iconSize = 20;
|
|
45
45
|
const options = [
|
|
46
46
|
{
|
|
@@ -70,6 +70,7 @@ const Wallet = ({ wallet, ens }) => {
|
|
|
70
70
|
if (connector.connectedChain === 'FLOW') {
|
|
71
71
|
(_a = connector.endSession) === null || _a === void 0 ? void 0 : _a.call(connector);
|
|
72
72
|
}
|
|
73
|
+
setShowWidgetStatePopup(true);
|
|
73
74
|
setSelectedWalletWithAction({ action: 'select', wallet });
|
|
74
75
|
setPrimaryWallet(walletId);
|
|
75
76
|
computeConnectedStateForWallets();
|
|
@@ -3,23 +3,55 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
-
|
|
6
|
+
require('react');
|
|
7
7
|
var classNames = require('../../../../utils/functions/classNames/classNames.cjs');
|
|
8
|
+
require('@dynamic-labs/sdk-api');
|
|
9
|
+
require('../../../../shared/logger.cjs');
|
|
10
|
+
require('@dynamic-labs/iconic');
|
|
11
|
+
require('@dynamic-labs/wallet-connector-core');
|
|
12
|
+
require('../../../../context/ViewContext/ViewContext.cjs');
|
|
13
|
+
var close = require('../../../../shared/assets/close.cjs');
|
|
14
|
+
require('@dynamic-labs/utils');
|
|
15
|
+
require('../../../../utils/constants/colors.cjs');
|
|
16
|
+
require('ethers');
|
|
17
|
+
require('../../../../shared/consts/index.cjs');
|
|
18
|
+
var useInternalDynamicContext = require('../../../../context/DynamicContext/useInternalDynamicContext.cjs');
|
|
19
|
+
require('@dynamic-labs/multi-wallet');
|
|
20
|
+
require('../../../../components/ShadowDOM/ShadowDOM.cjs');
|
|
21
|
+
require('../../../../context/ThemeContext/ThemeContext.cjs');
|
|
22
|
+
require('react-dom');
|
|
23
|
+
require('react-focus-lock');
|
|
24
|
+
require('../../../../components/Transition/ZoomTransition/ZoomTransition.cjs');
|
|
25
|
+
require('../../../../components/Transition/SlideInUpTransition/SlideInUpTransition.cjs');
|
|
26
|
+
require('../../../../components/Transition/OpacityTransition/OpacityTransition.cjs');
|
|
27
|
+
require('../../../../config/ApiEndpoint.cjs');
|
|
28
|
+
require('@dynamic-labs/rpc-providers');
|
|
29
|
+
require('../../../../context/ErrorContext/ErrorContext.cjs');
|
|
30
|
+
require('../../../../context/MockContext/MockContext.cjs');
|
|
31
|
+
require('../../../../context/CaptchaContext/CaptchaContext.cjs');
|
|
32
|
+
require('../../../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.cjs');
|
|
33
|
+
var IconButton = require('../../../../components/IconButton/IconButton.cjs');
|
|
34
|
+
require('../../../../components/Alert/Alert.cjs');
|
|
35
|
+
require('../../../../components/Popper/Popper/Popper.cjs');
|
|
36
|
+
require('../../../../components/Popper/PopperContext/PopperContext.cjs');
|
|
8
37
|
|
|
9
|
-
const WidgetPortal = ({ children, onBackdropClick, disablePadding, }) => {
|
|
10
|
-
const { setMultiWalletWidgetState,
|
|
38
|
+
const WidgetPortal = ({ children, onBackdropClick, disablePadding, showCloseButton, }) => {
|
|
39
|
+
const { accountSwitchState, setMultiWalletWidgetState, setSelectedWalletWithAction, selectedWalletWithAction, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
11
40
|
const handleBackdropClick = (e) => {
|
|
12
41
|
e.stopPropagation();
|
|
13
|
-
if (
|
|
42
|
+
if (!selectedWalletWithAction &&
|
|
43
|
+
accountSwitchState === 'primary_not_connected') {
|
|
14
44
|
return;
|
|
45
|
+
}
|
|
46
|
+
setSelectedWalletWithAction(null);
|
|
15
47
|
setMultiWalletWidgetState('idle');
|
|
16
48
|
if (!onBackdropClick)
|
|
17
49
|
return;
|
|
18
50
|
onBackdropClick();
|
|
19
51
|
};
|
|
20
|
-
return (jsxRuntime.jsx("div", Object.assign({ className: 'widget-portal', onClick: (e) => handleBackdropClick(e), "data-testid": 'backdrop' }, { children: jsxRuntime.
|
|
52
|
+
return (jsxRuntime.jsx("div", Object.assign({ className: 'widget-portal', onClick: (e) => handleBackdropClick(e), "data-testid": 'backdrop' }, { children: jsxRuntime.jsxs("div", Object.assign({ className: classNames.classNames('widget-portal__container', {
|
|
21
53
|
'widget-portal__container--no-padding': disablePadding,
|
|
22
|
-
}), onClick: (e) => e.stopPropagation() }, { children: children })) })));
|
|
54
|
+
}), onClick: (e) => e.stopPropagation() }, { children: [showCloseButton && (jsxRuntime.jsx("div", Object.assign({ className: 'widget-portal__container__header' }, { children: jsxRuntime.jsx(IconButton.IconButton, Object.assign({ className: 'widget-portal__container__close-button', onClick: (e) => handleBackdropClick(e), type: 'button', "data-testid": 'close-button' }, { children: jsxRuntime.jsx(close.ReactComponent, {}) })) }))), children] })) })));
|
|
23
55
|
};
|
|
24
56
|
|
|
25
57
|
exports.WidgetPortal = WidgetPortal;
|
|
@@ -3,6 +3,7 @@ type Props = {
|
|
|
3
3
|
children: ReactNode;
|
|
4
4
|
disablePadding?: boolean;
|
|
5
5
|
onBackdropClick?: VoidFunction;
|
|
6
|
+
showCloseButton?: boolean;
|
|
6
7
|
};
|
|
7
|
-
export declare const WidgetPortal: ({ children, onBackdropClick, disablePadding, }: Props) => JSX.Element;
|
|
8
|
+
export declare const WidgetPortal: ({ children, onBackdropClick, disablePadding, showCloseButton, }: Props) => JSX.Element;
|
|
8
9
|
export {};
|
|
@@ -1,21 +1,53 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import 'react';
|
|
3
3
|
import { classNames } from '../../../../utils/functions/classNames/classNames.js';
|
|
4
|
+
import '@dynamic-labs/sdk-api';
|
|
5
|
+
import '../../../../shared/logger.js';
|
|
6
|
+
import '@dynamic-labs/iconic';
|
|
7
|
+
import '@dynamic-labs/wallet-connector-core';
|
|
8
|
+
import '../../../../context/ViewContext/ViewContext.js';
|
|
9
|
+
import { ReactComponent as SvgClose } from '../../../../shared/assets/close.js';
|
|
10
|
+
import '@dynamic-labs/utils';
|
|
11
|
+
import '../../../../utils/constants/colors.js';
|
|
12
|
+
import 'ethers';
|
|
13
|
+
import '../../../../shared/consts/index.js';
|
|
14
|
+
import { useInternalDynamicContext } from '../../../../context/DynamicContext/useInternalDynamicContext.js';
|
|
15
|
+
import '@dynamic-labs/multi-wallet';
|
|
16
|
+
import '../../../../components/ShadowDOM/ShadowDOM.js';
|
|
17
|
+
import '../../../../context/ThemeContext/ThemeContext.js';
|
|
18
|
+
import 'react-dom';
|
|
19
|
+
import 'react-focus-lock';
|
|
20
|
+
import '../../../../components/Transition/ZoomTransition/ZoomTransition.js';
|
|
21
|
+
import '../../../../components/Transition/SlideInUpTransition/SlideInUpTransition.js';
|
|
22
|
+
import '../../../../components/Transition/OpacityTransition/OpacityTransition.js';
|
|
23
|
+
import '../../../../config/ApiEndpoint.js';
|
|
24
|
+
import '@dynamic-labs/rpc-providers';
|
|
25
|
+
import '../../../../context/ErrorContext/ErrorContext.js';
|
|
26
|
+
import '../../../../context/MockContext/MockContext.js';
|
|
27
|
+
import '../../../../context/CaptchaContext/CaptchaContext.js';
|
|
28
|
+
import '../../../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.js';
|
|
29
|
+
import { IconButton } from '../../../../components/IconButton/IconButton.js';
|
|
30
|
+
import '../../../../components/Alert/Alert.js';
|
|
31
|
+
import '../../../../components/Popper/Popper/Popper.js';
|
|
32
|
+
import '../../../../components/Popper/PopperContext/PopperContext.js';
|
|
4
33
|
|
|
5
|
-
const WidgetPortal = ({ children, onBackdropClick, disablePadding, }) => {
|
|
6
|
-
const { setMultiWalletWidgetState,
|
|
34
|
+
const WidgetPortal = ({ children, onBackdropClick, disablePadding, showCloseButton, }) => {
|
|
35
|
+
const { accountSwitchState, setMultiWalletWidgetState, setSelectedWalletWithAction, selectedWalletWithAction, } = useInternalDynamicContext();
|
|
7
36
|
const handleBackdropClick = (e) => {
|
|
8
37
|
e.stopPropagation();
|
|
9
|
-
if (
|
|
38
|
+
if (!selectedWalletWithAction &&
|
|
39
|
+
accountSwitchState === 'primary_not_connected') {
|
|
10
40
|
return;
|
|
41
|
+
}
|
|
42
|
+
setSelectedWalletWithAction(null);
|
|
11
43
|
setMultiWalletWidgetState('idle');
|
|
12
44
|
if (!onBackdropClick)
|
|
13
45
|
return;
|
|
14
46
|
onBackdropClick();
|
|
15
47
|
};
|
|
16
|
-
return (jsx("div", Object.assign({ className: 'widget-portal', onClick: (e) => handleBackdropClick(e), "data-testid": 'backdrop' }, { children:
|
|
48
|
+
return (jsx("div", Object.assign({ className: 'widget-portal', onClick: (e) => handleBackdropClick(e), "data-testid": 'backdrop' }, { children: jsxs("div", Object.assign({ className: classNames('widget-portal__container', {
|
|
17
49
|
'widget-portal__container--no-padding': disablePadding,
|
|
18
|
-
}), onClick: (e) => e.stopPropagation() }, { children: children })) })));
|
|
50
|
+
}), onClick: (e) => e.stopPropagation() }, { children: [showCloseButton && (jsx("div", Object.assign({ className: 'widget-portal__container__header' }, { children: jsx(IconButton, Object.assign({ className: 'widget-portal__container__close-button', onClick: (e) => handleBackdropClick(e), type: 'button', "data-testid": 'close-button' }, { children: jsx(SvgClose, {}) })) }))), children] })) })));
|
|
19
51
|
};
|
|
20
52
|
|
|
21
53
|
export { WidgetPortal };
|
|
@@ -58,12 +58,12 @@ const DynamicWidgetContextProvider = ({ children, }) => {
|
|
|
58
58
|
setDynamicWidgetView(initialView);
|
|
59
59
|
}, 200);
|
|
60
60
|
}
|
|
61
|
-
}, [showDynamicUserProfile]);
|
|
61
|
+
}, [initialView, showDynamicUserProfile]);
|
|
62
62
|
// set correct initial view once isKYCEnabled and isMultiWalletEnabled values are correctly set
|
|
63
63
|
// *isKYCEnabled is always false when the context initializes, so the initial view is set to index
|
|
64
64
|
React.useEffect(() => {
|
|
65
65
|
setDynamicWidgetView(initialView);
|
|
66
|
-
}, [isKYCEnabled, isMultiWalletEnabled]);
|
|
66
|
+
}, [initialView, isKYCEnabled, isMultiWalletEnabled]);
|
|
67
67
|
const value = React.useMemo(() => ({
|
|
68
68
|
availableWalletsContainerRef,
|
|
69
69
|
dynamicWidgetView,
|
|
@@ -54,12 +54,12 @@ const DynamicWidgetContextProvider = ({ children, }) => {
|
|
|
54
54
|
setDynamicWidgetView(initialView);
|
|
55
55
|
}, 200);
|
|
56
56
|
}
|
|
57
|
-
}, [showDynamicUserProfile]);
|
|
57
|
+
}, [initialView, showDynamicUserProfile]);
|
|
58
58
|
// set correct initial view once isKYCEnabled and isMultiWalletEnabled values are correctly set
|
|
59
59
|
// *isKYCEnabled is always false when the context initializes, so the initial view is set to index
|
|
60
60
|
useEffect(() => {
|
|
61
61
|
setDynamicWidgetView(initialView);
|
|
62
|
-
}, [isKYCEnabled, isMultiWalletEnabled]);
|
|
62
|
+
}, [initialView, isKYCEnabled, isMultiWalletEnabled]);
|
|
63
63
|
const value = useMemo(() => ({
|
|
64
64
|
availableWalletsContainerRef,
|
|
65
65
|
dynamicWidgetView,
|