@dynamic-labs/sdk-react-core 0.18.100-viem.2 → 0.18.100-viem.20
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 +171 -0
- package/package.cjs +3 -3
- package/package.js +3 -3
- package/package.json +10 -10
- package/src/index.cjs +3 -2
- package/src/index.d.ts +1 -1
- package/src/index.js +2 -1
- package/src/lib/components/MenuList/Dropdown/Dropdown.cjs +1 -1
- package/src/lib/components/MenuList/Dropdown/Dropdown.js +1 -1
- package/src/lib/components/ModalHeaderBanner/ModalHeaderBanner.cjs +6 -2
- package/src/lib/components/ModalHeaderBanner/ModalHeaderBanner.d.ts +2 -1
- package/src/lib/components/ModalHeaderBanner/ModalHeaderBanner.js +6 -2
- package/src/lib/components/OTPVerificationView/OTPVerificationView.cjs +2 -2
- package/src/lib/components/OTPVerificationView/OTPVerificationView.d.ts +1 -0
- package/src/lib/components/OTPVerificationView/OTPVerificationView.js +2 -2
- package/src/lib/components/SignMessagePreview/SignMessagePreview.cjs +27 -0
- package/src/lib/components/SignMessagePreview/SignMessagePreview.d.ts +6 -0
- package/src/lib/components/SignMessagePreview/SignMessagePreview.js +23 -0
- package/src/lib/components/SignMessagePreview/SignMessagePreview.types.d.ts +8 -0
- package/src/lib/components/SignMessagePreview/components/SignTypedDataPreview/SignTypedDataPreview.cjs +44 -0
- package/src/lib/components/SignMessagePreview/components/SignTypedDataPreview/SignTypedDataPreview.d.ts +8 -0
- package/src/lib/components/SignMessagePreview/components/SignTypedDataPreview/SignTypedDataPreview.js +40 -0
- package/src/lib/components/SignMessagePreview/components/SignTypedDataPreview/index.d.ts +1 -0
- package/src/lib/components/SignMessagePreview/components/index.d.ts +1 -0
- package/src/lib/components/SignMessagePreview/index.d.ts +1 -0
- package/src/lib/components/SignMessagePreview/utils/index.d.ts +1 -0
- package/src/lib/components/SignMessagePreview/utils/isSignTypedData/index.d.ts +1 -0
- package/src/lib/components/SignMessagePreview/utils/isSignTypedData/isSignTypedData.cjs +17 -0
- package/src/lib/components/SignMessagePreview/utils/isSignTypedData/isSignTypedData.d.ts +2 -0
- package/src/lib/components/SignMessagePreview/utils/isSignTypedData/isSignTypedData.js +13 -0
- package/src/lib/components/Typography/Typography.cjs +1 -0
- package/src/lib/components/Typography/Typography.js +1 -0
- package/src/lib/components/Typography/Typography.types.d.ts +1 -1
- package/src/lib/components/UserProfile/UserProfile.cjs +1 -1
- package/src/lib/components/UserProfile/UserProfile.js +1 -1
- package/src/lib/components/UserProfile/parts/UserProfileSocialAccount/UserProfileSocialAccount.cjs +1 -1
- package/src/lib/components/UserProfile/parts/UserProfileSocialAccount/UserProfileSocialAccount.js +1 -1
- package/src/lib/components/index.d.ts +1 -0
- package/src/lib/context/DynamicContext/DynamicContext.cjs +22 -7
- package/src/lib/context/DynamicContext/DynamicContext.d.ts +11 -1
- package/src/lib/context/DynamicContext/DynamicContext.js +23 -8
- package/src/lib/context/DynamicContext/helpers.cjs +42 -3
- package/src/lib/context/DynamicContext/helpers.d.ts +7 -1
- package/src/lib/context/DynamicContext/helpers.js +38 -4
- package/src/lib/context/DynamicContext/hooks/useSetShowAuthFlowWithInit/useSetShowAuthFlowWithInit.cjs +5 -2
- package/src/lib/context/DynamicContext/hooks/useSetShowAuthFlowWithInit/useSetShowAuthFlowWithInit.d.ts +4 -2
- package/src/lib/context/DynamicContext/hooks/useSetShowAuthFlowWithInit/useSetShowAuthFlowWithInit.js +5 -2
- package/src/lib/context/DynamicContext/internalEvents/index.d.ts +2 -0
- package/src/lib/context/DynamicContext/internalEvents/internalEvents.cjs +14 -0
- package/src/lib/context/DynamicContext/internalEvents/internalEvents.d.ts +8 -0
- package/src/lib/context/DynamicContext/internalEvents/internalEvents.js +6 -0
- package/src/lib/context/DynamicContext/types/index.d.ts +7 -1
- package/src/lib/context/DynamicContext/useDynamicContext.cjs +2 -1
- package/src/lib/context/DynamicContext/useDynamicContext.d.ts +1 -1
- package/src/lib/context/DynamicContext/useDynamicContext.js +2 -1
- package/src/lib/context/ErrorContext/ErrorContext.cjs +1 -0
- package/src/lib/context/ErrorContext/ErrorContext.js +1 -0
- package/src/lib/context/SocialRedirectContext/SocialRedirectContext.cjs +2 -1
- package/src/lib/context/SocialRedirectContext/SocialRedirectContext.js +2 -1
- package/src/lib/context/ViewContext/ViewContext.d.ts +1 -1
- package/src/lib/context/WalletContext/WalletContext.cjs +2 -16
- package/src/lib/context/WalletContext/WalletContext.js +2 -16
- package/src/lib/data/api.cjs +37 -13
- package/src/lib/data/api.d.ts +5 -3
- package/src/lib/data/api.js +37 -14
- package/src/lib/main.global.cjs +1 -1
- package/src/lib/main.global.js +1 -1
- package/src/lib/modals/SignMessageConfirmationModal/SignMessageConfirmationModal.cjs +2 -1
- package/src/lib/modals/SignMessageConfirmationModal/SignMessageConfirmationModal.js +2 -1
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.cjs +2 -1
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.js +2 -1
- package/src/lib/shared/types/index.d.ts +4 -0
- package/src/lib/shared/utils/hooks/usePreventPageScroll/usePreventPageScroll.cjs +28 -2
- package/src/lib/shared/utils/hooks/usePreventPageScroll/usePreventPageScroll.js +28 -2
- package/src/lib/styles/index.shadow.cjs +1 -1
- package/src/lib/styles/index.shadow.js +1 -1
- package/src/lib/utils/constants/localStorage.cjs +4 -0
- package/src/lib/utils/constants/localStorage.d.ts +2 -0
- package/src/lib/utils/constants/localStorage.js +3 -1
- package/src/lib/utils/functions/createUserProfile/createUserProfile.cjs +1 -1
- package/src/lib/utils/functions/createUserProfile/createUserProfile.js +1 -1
- package/src/lib/utils/functions/digestSHA256/digestSHA256.cjs +11 -0
- package/src/lib/utils/functions/digestSHA256/digestSHA256.d.ts +1 -0
- package/src/lib/utils/functions/digestSHA256/digestSHA256.js +7 -0
- package/src/lib/utils/functions/digestSHA256/index.d.ts +1 -0
- package/src/lib/utils/functions/encodeBase64URL/encodeBase64URL.cjs +14 -0
- package/src/lib/utils/functions/encodeBase64URL/encodeBase64URL.d.ts +1 -0
- package/src/lib/utils/functions/encodeBase64URL/encodeBase64URL.js +10 -0
- package/src/lib/utils/functions/encodeBase64URL/index.d.ts +1 -0
- package/src/lib/utils/functions/getDynamicLayoutData/getDynamicLayoutData.cjs +6 -1
- package/src/lib/utils/functions/getDynamicLayoutData/getDynamicLayoutData.js +6 -1
- package/src/lib/utils/functions/getRedirectURIOrigin/getRedirectURIOrigin.cjs +33 -0
- package/src/lib/utils/functions/getRedirectURIOrigin/getRedirectURIOrigin.d.ts +1 -0
- package/src/lib/utils/functions/getRedirectURIOrigin/getRedirectURIOrigin.js +29 -0
- package/src/lib/utils/functions/getRedirectURIOrigin/index.d.ts +1 -0
- package/src/lib/utils/functions/index.d.ts +6 -0
- package/src/lib/utils/functions/randomString/index.d.ts +1 -0
- package/src/lib/utils/functions/randomString/randomString.cjs +14 -0
- package/src/lib/utils/functions/randomString/randomString.d.ts +1 -0
- package/src/lib/utils/functions/randomString/randomString.js +10 -0
- package/src/lib/utils/functions/sendTransactionWithAutoNonce/index.d.ts +1 -0
- package/src/lib/utils/functions/sendTransactionWithAutoNonce/sendTransactionWithAutoNonce.cjs +48 -0
- package/src/lib/utils/functions/sendTransactionWithAutoNonce/sendTransactionWithAutoNonce.d.ts +18 -0
- package/src/lib/utils/functions/sendTransactionWithAutoNonce/sendTransactionWithAutoNonce.js +43 -0
- package/src/lib/utils/functions/stringifyURIQuery/index.d.ts +1 -0
- package/src/lib/utils/functions/stringifyURIQuery/stringifyURIQuery.cjs +13 -0
- package/src/lib/utils/functions/stringifyURIQuery/stringifyURIQuery.d.ts +1 -0
- package/src/lib/utils/functions/stringifyURIQuery/stringifyURIQuery.js +9 -0
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.cjs +10 -5
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.js +10 -5
- package/src/lib/utils/hooks/authenticationHooks/useSignConnectOnlyUser/useSignConnectOnlyUser.cjs +6 -2
- package/src/lib/utils/hooks/authenticationHooks/useSignConnectOnlyUser/useSignConnectOnlyUser.js +6 -2
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.cjs +13 -4
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.d.ts +1 -19
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.js +13 -4
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.cjs +22 -28
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.d.ts +1 -2
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.js +23 -29
- package/src/lib/utils/hooks/useConnectedWalletsNetworkValidation/useConnectedWalletsNetworkValidation.cjs +7 -6
- package/src/lib/utils/hooks/useConnectedWalletsNetworkValidation/useConnectedWalletsNetworkValidation.js +7 -6
- package/src/lib/utils/hooks/useFetchProjectSettings/useFetchProjectSettings.cjs +10 -1
- package/src/lib/utils/hooks/useFetchProjectSettings/useFetchProjectSettings.js +10 -1
- package/src/lib/utils/hooks/useHandleWalletsToConnect/useHandleWalletsToConnect.cjs +15 -1
- package/src/lib/utils/hooks/useHandleWalletsToConnect/useHandleWalletsToConnect.js +15 -1
- package/src/lib/utils/hooks/usePrimaryWalletId/usePrimaryWalletId.cjs +6 -2
- package/src/lib/utils/hooks/usePrimaryWalletId/usePrimaryWalletId.d.ts +2 -1
- package/src/lib/utils/hooks/usePrimaryWalletId/usePrimaryWalletId.js +6 -2
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.cjs +132 -24
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.d.ts +5 -1
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.js +134 -26
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.cjs +13 -3
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.js +13 -3
- package/src/lib/utils/hooks/useWallets/useWallets.cjs +16 -25
- package/src/lib/utils/hooks/useWallets/useWallets.d.ts +3 -2
- package/src/lib/utils/hooks/useWallets/useWallets.js +17 -26
- package/src/lib/views/CollectUserDataView/OnboardingUserDataForm/OnboardingUserDataForm.cjs +3 -3
- package/src/lib/views/CollectUserDataView/OnboardingUserDataForm/OnboardingUserDataForm.js +3 -3
- package/src/lib/views/EmailWalletOTPVerificationView/EmailWalletOTPVerificationView.cjs +1 -1
- package/src/lib/views/EmailWalletOTPVerificationView/EmailWalletOTPVerificationView.js +1 -1
- package/src/lib/views/LoginWithEmailView/components/SocialSignIn/SocialSignIn.cjs +1 -1
- package/src/lib/views/LoginWithEmailView/components/SocialSignIn/SocialSignIn.js +1 -1
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.cjs +3 -2
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.js +3 -2
- package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.cjs +3 -2
- package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.js +3 -2
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.cjs +4 -10
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.js +4 -10
- package/src/lib/views/WalletGroupView/components/WalletGroupItem/WalletGroupItem.cjs +1 -0
- package/src/lib/views/WalletGroupView/components/WalletGroupItem/WalletGroupItem.js +1 -0
- package/src/lib/views/WalletList/WalletListItem/WalletListItem.cjs +1 -1
- package/src/lib/views/WalletList/WalletListItem/WalletListItem.js +1 -1
- package/src/lib/views/WalletList/data.cjs +2 -14
- package/src/lib/views/WalletList/data.d.ts +4 -2
- package/src/lib/views/WalletList/data.js +2 -13
- package/src/lib/views/viewToComponentMap.cjs +1 -0
- package/src/lib/views/viewToComponentMap.js +1 -0
- package/src/lib/widgets/DynamicBridgeWidget/views/EditProfileView/EditProfileView.cjs +3 -3
- package/src/lib/widgets/DynamicBridgeWidget/views/EditProfileView/EditProfileView.js +3 -3
- package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.cjs +7 -10
- package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.js +8 -11
- package/src/lib/widgets/DynamicWidget/hooks/index.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/hooks/useFetchCurrency/useFetchCurrency.cjs +4 -1
- package/src/lib/widgets/DynamicWidget/hooks/useFetchCurrency/useFetchCurrency.js +4 -1
- package/src/lib/widgets/DynamicWidget/hooks/useViewController/index.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/hooks/useViewController/useViewController.cjs +17 -0
- package/src/lib/widgets/DynamicWidget/hooks/useViewController/useViewController.d.ts +6 -0
- package/src/lib/widgets/DynamicWidget/hooks/useViewController/useViewController.js +13 -0
- package/src/lib/widgets/DynamicWidget/views/EditProfileView/EditProfileView.cjs +3 -3
- package/src/lib/widgets/DynamicWidget/views/EditProfileView/EditProfileView.js +3 -3
- package/src/lib/widgets/DynamicWidget/views/SendBalanceWidgetView/SendBalanceWidgetView.cjs +2 -3
- package/src/lib/widgets/DynamicWidget/views/SendBalanceWidgetView/SendBalanceWidgetView.js +2 -3
- package/src/lib/widgets/OAuthIFrameContainer/OAuthIFrameContainer.cjs +13 -0
- package/src/lib/widgets/OAuthIFrameContainer/OAuthIFrameContainer.d.ts +2 -0
- package/src/lib/widgets/OAuthIFrameContainer/OAuthIFrameContainer.js +9 -0
- package/src/lib/widgets/OAuthIFrameContainer/index.d.ts +1 -0
- package/src/lib/widgets/index.d.ts +1 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
2
|
-
import { useState, useCallback, useEffect
|
|
2
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
3
3
|
import { getWalletConnectorByName, logger } from '@dynamic-labs/wallet-connector-core';
|
|
4
4
|
import '@dynamic-labs/sdk-api';
|
|
5
5
|
import '../../../shared/logger.js';
|
|
@@ -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,14 +114,13 @@ 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
|
-
const shouldSkipCreatingVisit =
|
|
130
|
-
connectedWallet, [authMode, connectedWallet, enableVisitTrackingOnConnectOnly]);
|
|
123
|
+
const shouldSkipCreatingVisit = authMode === 'connect-only' && !enableVisitTrackingOnConnectOnly;
|
|
131
124
|
const connectWallet = (walletConnector, fetchPublicAddressOpts, shouldCallCallback = true) => __awaiter(void 0, void 0, void 0, function* () {
|
|
132
125
|
const publicWalletAddress = yield walletConnector.fetchPublicAddress(fetchPublicAddressOpts);
|
|
133
126
|
if (!publicWalletAddress) {
|
|
@@ -164,31 +157,32 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
164
157
|
walletConnectorKey: walletConnector.name,
|
|
165
158
|
walletId,
|
|
166
159
|
});
|
|
160
|
+
if (!shouldSkipCreatingVisit) {
|
|
161
|
+
// send information to backend to kick off background jobs
|
|
162
|
+
// so verify/sign on the next step could go by more quickly
|
|
163
|
+
// this is async work, but DO NOT AWAIT
|
|
164
|
+
createVisit({
|
|
165
|
+
authMode,
|
|
166
|
+
chain: walletChain || '',
|
|
167
|
+
environmentId,
|
|
168
|
+
publicWalletAddress,
|
|
169
|
+
walletName: walletConnector.name,
|
|
170
|
+
walletProvider: getWalletProvider(walletConnector),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
167
173
|
}
|
|
168
|
-
if (shouldSkipCreatingVisit) {
|
|
169
|
-
return Promise.resolve(publicWalletAddress);
|
|
170
|
-
}
|
|
171
|
-
// send information to backend to kick off background jobs
|
|
172
|
-
// so verify/sign on the next step could go by more quickly
|
|
173
|
-
// this is async work, but DO NOT AWAIT
|
|
174
|
-
createVisit({
|
|
175
|
-
authMode,
|
|
176
|
-
chain: walletChain || '',
|
|
177
|
-
environmentId,
|
|
178
|
-
publicWalletAddress,
|
|
179
|
-
walletName: walletConnector.name,
|
|
180
|
-
walletProvider: getWalletProvider(walletConnector),
|
|
181
|
-
});
|
|
182
174
|
return Promise.resolve(publicWalletAddress);
|
|
183
175
|
});
|
|
184
|
-
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());
|
|
185
179
|
const filteredWallets = connectedWalletsInfo.filter((wallet) => wallet.id !== walletId);
|
|
186
180
|
if (walletId === primaryWalletId) {
|
|
187
181
|
clearPrimaryWalletId();
|
|
188
182
|
}
|
|
189
183
|
setConnectedWalletsInfo(filteredWallets);
|
|
190
184
|
onUnlink === null || onUnlink === void 0 ? void 0 : onUnlink(walletId, filteredWallets);
|
|
191
|
-
};
|
|
185
|
+
});
|
|
192
186
|
const getConnectedWalletById = useCallback((walletId) => connectedWallets.find((wallet) => wallet.id === walletId), [connectedWallets]);
|
|
193
187
|
return {
|
|
194
188
|
connectWallet,
|
|
@@ -22,7 +22,7 @@ var isProgrammableNetworkSwitchSupported = require('../../functions/isProgrammab
|
|
|
22
22
|
|
|
23
23
|
const useConnectedWalletsNetworkValidation = () => {
|
|
24
24
|
const { connectedWallets, selectedWalletConnector, setSelectedWalletConnector, setShowAuthFlow, showAuthFlow, walletsToConnectByChain, isBridgeFlow, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
25
|
-
const {
|
|
25
|
+
const { setView } = ViewContext.useViewContext();
|
|
26
26
|
React.useEffect(() => {
|
|
27
27
|
if (!isBridgeFlow) {
|
|
28
28
|
return;
|
|
@@ -53,16 +53,17 @@ const useConnectedWalletsNetworkValidation = () => {
|
|
|
53
53
|
}
|
|
54
54
|
setView(networkNotSupportedView);
|
|
55
55
|
}
|
|
56
|
+
// we need it to remove 'showAuthFlow' property. we don't want to react to it,
|
|
57
|
+
// because closing modal on network switch causes it to re-open
|
|
58
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
56
59
|
}, [
|
|
57
|
-
isBridgeFlow,
|
|
58
60
|
connectedWallets,
|
|
59
|
-
|
|
61
|
+
isBridgeFlow,
|
|
60
62
|
selectedWalletConnector,
|
|
61
|
-
walletsToConnectByChain,
|
|
62
|
-
showAuthFlow,
|
|
63
|
-
setView,
|
|
64
63
|
setSelectedWalletConnector,
|
|
65
64
|
setShowAuthFlow,
|
|
65
|
+
setView,
|
|
66
|
+
walletsToConnectByChain,
|
|
66
67
|
]);
|
|
67
68
|
};
|
|
68
69
|
|
|
@@ -18,7 +18,7 @@ import { isProgrammableNetworkSwitchSupported } from '../../functions/isProgramm
|
|
|
18
18
|
|
|
19
19
|
const useConnectedWalletsNetworkValidation = () => {
|
|
20
20
|
const { connectedWallets, selectedWalletConnector, setSelectedWalletConnector, setShowAuthFlow, showAuthFlow, walletsToConnectByChain, isBridgeFlow, } = useInternalDynamicContext();
|
|
21
|
-
const {
|
|
21
|
+
const { setView } = useViewContext();
|
|
22
22
|
useEffect(() => {
|
|
23
23
|
if (!isBridgeFlow) {
|
|
24
24
|
return;
|
|
@@ -49,16 +49,17 @@ const useConnectedWalletsNetworkValidation = () => {
|
|
|
49
49
|
}
|
|
50
50
|
setView(networkNotSupportedView);
|
|
51
51
|
}
|
|
52
|
+
// we need it to remove 'showAuthFlow' property. we don't want to react to it,
|
|
53
|
+
// because closing modal on network switch causes it to re-open
|
|
54
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
55
|
}, [
|
|
53
|
-
isBridgeFlow,
|
|
54
56
|
connectedWallets,
|
|
55
|
-
|
|
57
|
+
isBridgeFlow,
|
|
56
58
|
selectedWalletConnector,
|
|
57
|
-
walletsToConnectByChain,
|
|
58
|
-
showAuthFlow,
|
|
59
|
-
setView,
|
|
60
59
|
setSelectedWalletConnector,
|
|
61
60
|
setShowAuthFlow,
|
|
61
|
+
setView,
|
|
62
|
+
walletsToConnectByChain,
|
|
62
63
|
]);
|
|
63
64
|
};
|
|
64
65
|
|
|
@@ -44,7 +44,16 @@ const useFetchProjectSettings = ({ authToken, environmentId, maxRetries = 2, dyn
|
|
|
44
44
|
environmentId &&
|
|
45
45
|
retries < maxRetries) {
|
|
46
46
|
setLoading(true);
|
|
47
|
-
|
|
47
|
+
// we ReactNode components are not being serialized properly
|
|
48
|
+
// remove them for now and deal with them later
|
|
49
|
+
// context: https://linear.app/dynamic-labs/issue/GVTY-328/[starknet]-sdk-api-is-not-serializing-react-components
|
|
50
|
+
// future work: https://linear.app/dynamic-labs/issue/GVTY-330/bug-figure-out-why-react-components-are-not
|
|
51
|
+
const updatedDynamicProps = {
|
|
52
|
+
settings: Object.assign(Object.assign({}, dynamicContextProps.settings), { customPrivacyPolicy: Boolean(dynamicContextProps.settings.customPrivacyPolicy), customTermsOfServices: Boolean(dynamicContextProps.settings.customTermsOfServices), policiesConsentInnerComponent: Boolean(dynamicContextProps.settings.policiesConsentInnerComponent) }),
|
|
53
|
+
};
|
|
54
|
+
api.sendDynamicProps(environmentId, {
|
|
55
|
+
dynamicContextProps: updatedDynamicProps,
|
|
56
|
+
});
|
|
48
57
|
api.fetchProjectSettings(environmentId)
|
|
49
58
|
.then((response) => {
|
|
50
59
|
if (!response)
|
|
@@ -40,7 +40,16 @@ const useFetchProjectSettings = ({ authToken, environmentId, maxRetries = 2, dyn
|
|
|
40
40
|
environmentId &&
|
|
41
41
|
retries < maxRetries) {
|
|
42
42
|
setLoading(true);
|
|
43
|
-
|
|
43
|
+
// we ReactNode components are not being serialized properly
|
|
44
|
+
// remove them for now and deal with them later
|
|
45
|
+
// context: https://linear.app/dynamic-labs/issue/GVTY-328/[starknet]-sdk-api-is-not-serializing-react-components
|
|
46
|
+
// future work: https://linear.app/dynamic-labs/issue/GVTY-330/bug-figure-out-why-react-components-are-not
|
|
47
|
+
const updatedDynamicProps = {
|
|
48
|
+
settings: Object.assign(Object.assign({}, dynamicContextProps.settings), { customPrivacyPolicy: Boolean(dynamicContextProps.settings.customPrivacyPolicy), customTermsOfServices: Boolean(dynamicContextProps.settings.customTermsOfServices), policiesConsentInnerComponent: Boolean(dynamicContextProps.settings.policiesConsentInnerComponent) }),
|
|
49
|
+
};
|
|
50
|
+
sendDynamicProps(environmentId, {
|
|
51
|
+
dynamicContextProps: updatedDynamicProps,
|
|
52
|
+
});
|
|
44
53
|
fetchProjectSettings(environmentId)
|
|
45
54
|
.then((response) => {
|
|
46
55
|
if (!response)
|
|
@@ -6,7 +6,7 @@ var useInternalDynamicContext = require('../../../context/DynamicContext/useInte
|
|
|
6
6
|
var ViewContext = require('../../../context/ViewContext/ViewContext.cjs');
|
|
7
7
|
|
|
8
8
|
const useHandleWalletsToConnect = () => {
|
|
9
|
-
const { walletsToConnectByChain, setWalletsToConnectByChain, setShowAuthFlow, setIsFullyConnected, isFullyConnected, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
9
|
+
const { walletsToConnectByChain, setWalletsToConnectByChain, setShowAuthFlow, setIsFullyConnected, selectedWalletConnector, isFullyConnected, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
10
10
|
const { setView, goToInitialView } = ViewContext.useViewContext();
|
|
11
11
|
const handleWalletsToConnect = () => {
|
|
12
12
|
if (!walletsToConnectByChain) {
|
|
@@ -19,6 +19,20 @@ const useHandleWalletsToConnect = () => {
|
|
|
19
19
|
setShowAuthFlow(false);
|
|
20
20
|
return goToInitialView();
|
|
21
21
|
}
|
|
22
|
+
if (!selectedWalletConnector || !selectedWalletConnector.connectedChain) {
|
|
23
|
+
setShowAuthFlow(false);
|
|
24
|
+
return goToInitialView();
|
|
25
|
+
}
|
|
26
|
+
// Assuming based on the logic above that we have at least one more chain/wallet to connect
|
|
27
|
+
// If the current connected wallet is already connected to the bridge,
|
|
28
|
+
// we can go directly to bridge-next-wallet-connection since we know there is a different chain to connect
|
|
29
|
+
const walletChainsToConnect = walletsToConnectByChain
|
|
30
|
+
.filter((wallet) => wallet.numberOfWallets > 0)
|
|
31
|
+
.map((wallet) => wallet.chain.toString());
|
|
32
|
+
if (!walletChainsToConnect.includes(selectedWalletConnector.connectedChain)) {
|
|
33
|
+
setView('bridge-next-wallet-connection');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
22
36
|
const [firstWallet, ...restOfTheWallets] = walletsToConnectByChain;
|
|
23
37
|
if (firstWallet.numberOfWallets > 1) {
|
|
24
38
|
const updatedWallets = [
|
|
@@ -2,7 +2,7 @@ import { useInternalDynamicContext } from '../../../context/DynamicContext/useIn
|
|
|
2
2
|
import { useViewContext } from '../../../context/ViewContext/ViewContext.js';
|
|
3
3
|
|
|
4
4
|
const useHandleWalletsToConnect = () => {
|
|
5
|
-
const { walletsToConnectByChain, setWalletsToConnectByChain, setShowAuthFlow, setIsFullyConnected, isFullyConnected, } = useInternalDynamicContext();
|
|
5
|
+
const { walletsToConnectByChain, setWalletsToConnectByChain, setShowAuthFlow, setIsFullyConnected, selectedWalletConnector, isFullyConnected, } = useInternalDynamicContext();
|
|
6
6
|
const { setView, goToInitialView } = useViewContext();
|
|
7
7
|
const handleWalletsToConnect = () => {
|
|
8
8
|
if (!walletsToConnectByChain) {
|
|
@@ -15,6 +15,20 @@ const useHandleWalletsToConnect = () => {
|
|
|
15
15
|
setShowAuthFlow(false);
|
|
16
16
|
return goToInitialView();
|
|
17
17
|
}
|
|
18
|
+
if (!selectedWalletConnector || !selectedWalletConnector.connectedChain) {
|
|
19
|
+
setShowAuthFlow(false);
|
|
20
|
+
return goToInitialView();
|
|
21
|
+
}
|
|
22
|
+
// Assuming based on the logic above that we have at least one more chain/wallet to connect
|
|
23
|
+
// If the current connected wallet is already connected to the bridge,
|
|
24
|
+
// we can go directly to bridge-next-wallet-connection since we know there is a different chain to connect
|
|
25
|
+
const walletChainsToConnect = walletsToConnectByChain
|
|
26
|
+
.filter((wallet) => wallet.numberOfWallets > 0)
|
|
27
|
+
.map((wallet) => wallet.chain.toString());
|
|
28
|
+
if (!walletChainsToConnect.includes(selectedWalletConnector.connectedChain)) {
|
|
29
|
+
setView('bridge-next-wallet-connection');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
18
32
|
const [firstWallet, ...restOfTheWallets] = walletsToConnectByChain;
|
|
19
33
|
if (firstWallet.numberOfWallets > 1) {
|
|
20
34
|
const updatedWallets = [
|
|
@@ -20,11 +20,15 @@ require('../../../shared/consts/index.cjs');
|
|
|
20
20
|
var primaryWalletIdValidator = require('../useWalletConnectors/utils/primaryWalletIdValidator/primaryWalletIdValidator.cjs');
|
|
21
21
|
require('@dynamic-labs/multi-wallet');
|
|
22
22
|
|
|
23
|
-
const usePrimaryWalletId = () => {
|
|
24
|
-
const [primaryWalletId, setPrimaryWalletIdState,
|
|
23
|
+
const usePrimaryWalletId = (internalEvents) => {
|
|
24
|
+
const [primaryWalletId, setPrimaryWalletIdState, clearPrimaryWalletIdStorage,] = useLocalStorage.useLocalStorage(localStorage.PRIMARY_WALLET_ID, undefined, primaryWalletIdValidator.primaryWalletIdValidator);
|
|
25
25
|
const setPrimaryWalletId = React.useCallback((walletId) => {
|
|
26
26
|
setPrimaryWalletIdState(walletId);
|
|
27
27
|
}, [setPrimaryWalletIdState]);
|
|
28
|
+
const clearPrimaryWalletId = () => {
|
|
29
|
+
clearPrimaryWalletIdStorage();
|
|
30
|
+
internalEvents.emit('clearPrimaryWallet');
|
|
31
|
+
};
|
|
28
32
|
return {
|
|
29
33
|
clearPrimaryWalletId,
|
|
30
34
|
primaryWalletId,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { InternalEventEmitter } from '../../../context/DynamicContext/internalEvents';
|
|
2
|
+
export declare const usePrimaryWalletId: (internalEvents: InternalEventEmitter) => {
|
|
2
3
|
clearPrimaryWalletId: () => void;
|
|
3
4
|
primaryWalletId: string | undefined;
|
|
4
5
|
setPrimaryWalletId: (walletId: string) => void;
|
|
@@ -16,11 +16,15 @@ import '../../../shared/consts/index.js';
|
|
|
16
16
|
import { primaryWalletIdValidator } from '../useWalletConnectors/utils/primaryWalletIdValidator/primaryWalletIdValidator.js';
|
|
17
17
|
import '@dynamic-labs/multi-wallet';
|
|
18
18
|
|
|
19
|
-
const usePrimaryWalletId = () => {
|
|
20
|
-
const [primaryWalletId, setPrimaryWalletIdState,
|
|
19
|
+
const usePrimaryWalletId = (internalEvents) => {
|
|
20
|
+
const [primaryWalletId, setPrimaryWalletIdState, clearPrimaryWalletIdStorage,] = useLocalStorage(PRIMARY_WALLET_ID, undefined, primaryWalletIdValidator);
|
|
21
21
|
const setPrimaryWalletId = useCallback((walletId) => {
|
|
22
22
|
setPrimaryWalletIdState(walletId);
|
|
23
23
|
}, [setPrimaryWalletIdState]);
|
|
24
|
+
const clearPrimaryWalletId = () => {
|
|
25
|
+
clearPrimaryWalletIdStorage();
|
|
26
|
+
internalEvents.emit('clearPrimaryWallet');
|
|
27
|
+
};
|
|
24
28
|
return {
|
|
25
29
|
clearPrimaryWalletId,
|
|
26
30
|
primaryWalletId,
|
|
@@ -15,14 +15,20 @@ require('react/jsx-runtime');
|
|
|
15
15
|
require('../../../context/ViewContext/ViewContext.cjs');
|
|
16
16
|
require('@dynamic-labs/wallet-book');
|
|
17
17
|
require('@dynamic-labs/utils');
|
|
18
|
+
var localStorage$1 = require('../../constants/localStorage.cjs');
|
|
18
19
|
require('../../constants/colors.cjs');
|
|
19
|
-
require('../../../shared/utils/classes/storage/localStorage.cjs');
|
|
20
|
+
var localStorage = require('../../../shared/utils/classes/storage/localStorage.cjs');
|
|
20
21
|
require('viem');
|
|
21
22
|
require('../../../shared/consts/index.cjs');
|
|
22
23
|
require('@dynamic-labs/multi-wallet');
|
|
23
24
|
var getAuthToken = require('../../functions/getAuthToken/getAuthToken.cjs');
|
|
24
25
|
var index = require('../../functions/getEnabledOAuthProviders/index.cjs');
|
|
25
26
|
var isSocialKycEnabled = require('../../functions/isSocialKycEnabled/isSocialKycEnabled.cjs');
|
|
27
|
+
var randomString = require('../../functions/randomString/randomString.cjs');
|
|
28
|
+
var stringifyURIQuery = require('../../functions/stringifyURIQuery/stringifyURIQuery.cjs');
|
|
29
|
+
var digestSHA256 = require('../../functions/digestSHA256/digestSHA256.cjs');
|
|
30
|
+
var encodeBase64URL = require('../../functions/encodeBase64URL/encodeBase64URL.cjs');
|
|
31
|
+
var getRedirectURIOrigin = require('../../functions/getRedirectURIOrigin/getRedirectURIOrigin.cjs');
|
|
26
32
|
|
|
27
33
|
const socialProviders = [
|
|
28
34
|
'discord',
|
|
@@ -33,12 +39,20 @@ const socialProviders = [
|
|
|
33
39
|
'twitch',
|
|
34
40
|
'twitter',
|
|
35
41
|
];
|
|
36
|
-
|
|
42
|
+
// pkce params are only required for twitter and break if added for other providers, like google
|
|
43
|
+
// so we should only add provider that support pkce to this list
|
|
44
|
+
const providersRequiringPkce = ['twitter', 'github'];
|
|
45
|
+
const providersWithoutWindowOpenerRefence = ['twitter'];
|
|
46
|
+
const useSocialAccounts = ({ sessionTimeout } = {
|
|
47
|
+
sessionTimeout: 10000,
|
|
48
|
+
}) => {
|
|
37
49
|
var _a;
|
|
38
50
|
const { environmentId, user, projectSettings, onboardingOnlyJwt } = useInternalDynamicContext.useInternalDynamicContext();
|
|
39
51
|
const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback.useUpdateUserProfileByJWTCallback();
|
|
40
52
|
const [isProcessing, setIsProcessing] = React.useState(false);
|
|
41
53
|
const [error, setError] = React.useState();
|
|
54
|
+
const providersWaitingOauthMessages = React.useRef({});
|
|
55
|
+
const authWindowInterval = React.useRef();
|
|
42
56
|
const userJwt = (_a = getAuthToken.getAuthToken()) !== null && _a !== void 0 ? _a : onboardingOnlyJwt;
|
|
43
57
|
const oauthProviders = index.getEnabledOAuthProviders(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
|
|
44
58
|
const verifiedOAuthCredentialsMap = React.useMemo(() => {
|
|
@@ -57,6 +71,23 @@ const useSocialAccounts = () => {
|
|
|
57
71
|
setIsProcessing(false);
|
|
58
72
|
setError(message);
|
|
59
73
|
};
|
|
74
|
+
const addOAuthIFrame = (url) => {
|
|
75
|
+
const container = document.getElementById('oauth-iframe-container');
|
|
76
|
+
let oauthIFrame = document.getElementById('oauth-iframe');
|
|
77
|
+
if (!container || oauthIFrame) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
oauthIFrame = document.createElement('iframe');
|
|
81
|
+
oauthIFrame.setAttribute('id', 'oauth-iframe');
|
|
82
|
+
oauthIFrame.setAttribute('src', url);
|
|
83
|
+
container.appendChild(oauthIFrame);
|
|
84
|
+
};
|
|
85
|
+
const removeOAuthIFrame = () => {
|
|
86
|
+
const oauthIFrame = document.getElementById('oauth-iframe');
|
|
87
|
+
if (oauthIFrame) {
|
|
88
|
+
oauthIFrame.remove();
|
|
89
|
+
}
|
|
90
|
+
};
|
|
60
91
|
const checkValidProvider = (provider) => {
|
|
61
92
|
if (!provider) {
|
|
62
93
|
handleError('Provider is required');
|
|
@@ -68,38 +99,73 @@ const useSocialAccounts = () => {
|
|
|
68
99
|
}
|
|
69
100
|
return true;
|
|
70
101
|
};
|
|
71
|
-
const
|
|
72
|
-
setError(undefined);
|
|
73
|
-
setIsProcessing(true);
|
|
102
|
+
const checkValidOAuthLinking = (provider) => {
|
|
74
103
|
if (!isSocialKycEnabled.isSocialKycEnabled(projectSettings)) {
|
|
75
104
|
handleError('Social linking is not enabled on the dashboard');
|
|
76
|
-
return;
|
|
105
|
+
return false;
|
|
77
106
|
}
|
|
78
107
|
if (!checkValidProvider(provider)) {
|
|
79
|
-
return;
|
|
108
|
+
return false;
|
|
80
109
|
}
|
|
81
110
|
const verifiedCredential = verifiedOAuthCredentialsMap[provider];
|
|
82
111
|
if (verifiedCredential) {
|
|
83
112
|
handleError(`Account already linked for provider: ${provider}`);
|
|
84
|
-
return;
|
|
113
|
+
return false;
|
|
85
114
|
}
|
|
86
115
|
const oauthProvider = oauthProviders.find((p) => p.provider === provider);
|
|
87
116
|
if (!oauthProvider) {
|
|
88
117
|
handleError(`Provider is not enabled on the dashboard: ${provider}`);
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
return true;
|
|
121
|
+
};
|
|
122
|
+
const linkSocialAccount = (provider) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
123
|
+
var _b;
|
|
124
|
+
clearInterval(authWindowInterval.current);
|
|
125
|
+
setError(undefined);
|
|
126
|
+
setIsProcessing(true);
|
|
127
|
+
// invalid linking request
|
|
128
|
+
if (!checkValidOAuthLinking(provider)) {
|
|
89
129
|
return;
|
|
90
130
|
}
|
|
131
|
+
const state = randomString.randomString(8);
|
|
132
|
+
const verifier = randomString.randomString(43);
|
|
133
|
+
const clearListeners = () => {
|
|
134
|
+
removeOAuthIFrame();
|
|
135
|
+
window.removeEventListener('message', handleAuthWindowMessage);
|
|
136
|
+
providersWaitingOauthMessages.current = Object.assign(Object.assign({}, providersWaitingOauthMessages.current), { [provider]: false });
|
|
137
|
+
};
|
|
91
138
|
const handleAuthWindowMessage = (event) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
-
var
|
|
93
|
-
|
|
94
|
-
|
|
139
|
+
var _c;
|
|
140
|
+
const message = event.data;
|
|
141
|
+
const isAuthorizationMessage = (message === null || message === void 0 ? void 0 : message.type) === 'authorization_response';
|
|
142
|
+
if (isAuthorizationMessage) {
|
|
143
|
+
logger.logger.debug('Message received', { data: message });
|
|
144
|
+
}
|
|
145
|
+
const isValidMessage = isAuthorizationMessage && (message === null || message === void 0 ? void 0 : message.provider) === provider;
|
|
146
|
+
// don't process imvalid messages for provider
|
|
147
|
+
if (!isValidMessage) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
setIsProcessing(true);
|
|
151
|
+
if (!((_c = providersWaitingOauthMessages.current) === null || _c === void 0 ? void 0 : _c[provider])) {
|
|
152
|
+
handleError(`Linking ${provider} account session timeout.`);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
clearListeners();
|
|
156
|
+
const { code, error } = message;
|
|
157
|
+
if (error && error !== 'undefined') {
|
|
158
|
+
handleError(`Failed to link ${provider} social account: ${error}`);
|
|
159
|
+
return;
|
|
95
160
|
}
|
|
96
|
-
if (
|
|
97
|
-
(
|
|
161
|
+
if (!code) {
|
|
162
|
+
handleError(`Failed to link ${provider} social account: no authorization code`);
|
|
98
163
|
return;
|
|
99
164
|
}
|
|
100
|
-
const { code } = event.data;
|
|
101
165
|
const jwt = yield api.verifyOAuth(environmentId, provider, {
|
|
102
166
|
code,
|
|
167
|
+
codeVerifier: verifier,
|
|
168
|
+
state,
|
|
103
169
|
}, String(userJwt));
|
|
104
170
|
if (!jwt) {
|
|
105
171
|
handleError(`Failed to link social account: ${provider}`);
|
|
@@ -108,18 +174,58 @@ const useSocialAccounts = () => {
|
|
|
108
174
|
yield updateUserProfileByJWT(jwt);
|
|
109
175
|
setIsProcessing(false);
|
|
110
176
|
});
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
177
|
+
const loginUrl = yield api.getOauthLoginUrl(environmentId, provider, String(userJwt));
|
|
178
|
+
if (!loginUrl) {
|
|
179
|
+
handleError(`Failed to get login url to link social account: ${provider}`);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
// we need to use an iframe to be the intermediary in communications between the popup and the sdk
|
|
183
|
+
// because of twitter limitations with accessing the window.opener and BroadcastChannel not working between
|
|
184
|
+
// different origins (our api redirect page and the app where the sdk is running)
|
|
185
|
+
const oauthIFrameUrl = `${getRedirectURIOrigin.getRedirectURIOrigin(loginUrl)}/sdkoauth`;
|
|
186
|
+
addOAuthIFrame(oauthIFrameUrl);
|
|
187
|
+
let oauthLoginUrl = loginUrl;
|
|
188
|
+
if (providersRequiringPkce.includes(provider)) {
|
|
189
|
+
const digest = yield digestSHA256.digestSHA256(verifier);
|
|
190
|
+
const pkceParams = stringifyURIQuery.stringifyURIQuery({
|
|
191
|
+
code_challenge: encodeBase64URL.encodeBase64URL(digest),
|
|
192
|
+
code_challenge_method: 'S256',
|
|
193
|
+
state: state,
|
|
194
|
+
});
|
|
195
|
+
oauthLoginUrl = `${loginUrl}&${pkceParams}`;
|
|
196
|
+
}
|
|
197
|
+
if (!((_b = providersWaitingOauthMessages.current) === null || _b === void 0 ? void 0 : _b[provider])) {
|
|
198
|
+
window.addEventListener('message', handleAuthWindowMessage);
|
|
199
|
+
providersWaitingOauthMessages.current = Object.assign(Object.assign({}, providersWaitingOauthMessages.current), { [provider]: true });
|
|
200
|
+
}
|
|
201
|
+
const authWindow = window.open(oauthLoginUrl, '_blank', 'width=500,height=600');
|
|
202
|
+
if (!providersWithoutWindowOpenerRefence.includes(provider)) {
|
|
203
|
+
// For provider that support window.opener, we need to clear all states/listeners when the window is closed
|
|
204
|
+
authWindowInterval.current = setInterval(() => {
|
|
205
|
+
if (!(authWindow === null || authWindow === void 0 ? void 0 : authWindow.closed)) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
clearInterval(authWindowInterval.current);
|
|
117
209
|
setIsProcessing(false);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
// For provider that don't support window.opener, we need to use a timeout to try to detect when the
|
|
214
|
+
// window is closed
|
|
215
|
+
authWindowInterval.current = setInterval(() => {
|
|
216
|
+
var _a;
|
|
217
|
+
// user didn't complete oauth
|
|
218
|
+
if ((_a = providersWaitingOauthMessages.current) === null || _a === void 0 ? void 0 : _a[provider]) {
|
|
219
|
+
clearListeners();
|
|
220
|
+
handleError(`Linking ${provider} account window timeout.`);
|
|
221
|
+
}
|
|
222
|
+
setIsProcessing(false);
|
|
223
|
+
clearInterval(authWindowInterval.current);
|
|
224
|
+
}, sessionTimeout);
|
|
225
|
+
}
|
|
120
226
|
});
|
|
121
227
|
const unlinkSocialAccount = (provider) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
122
|
-
var
|
|
228
|
+
var _d;
|
|
123
229
|
setError(undefined);
|
|
124
230
|
setIsProcessing(true);
|
|
125
231
|
if (!checkValidProvider(provider)) {
|
|
@@ -131,9 +237,11 @@ const useSocialAccounts = () => {
|
|
|
131
237
|
return;
|
|
132
238
|
}
|
|
133
239
|
try {
|
|
240
|
+
const primaryWalletId = localStorage.LocalStorage.getFromLS(localStorage$1.PRIMARY_WALLET_ID);
|
|
134
241
|
const jwt = yield api.unlinkOAuth({
|
|
135
242
|
environmentId,
|
|
136
|
-
|
|
243
|
+
primaryWalletId,
|
|
244
|
+
verifiedCrentialId: (_d = verifiedCredential.id) !== null && _d !== void 0 ? _d : '',
|
|
137
245
|
}, String(userJwt));
|
|
138
246
|
if (!jwt) {
|
|
139
247
|
handleError(`Failed to unlink social account: ${provider} | ${verifiedCredential.id}`);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ProviderEnum } from '@dynamic-labs/sdk-api';
|
|
2
2
|
import { SocialAccountInformation } from '@dynamic-labs/types';
|
|
3
|
-
|
|
3
|
+
type UseSocialAccountsProps = {
|
|
4
|
+
sessionTimeout: number;
|
|
5
|
+
};
|
|
6
|
+
export declare const useSocialAccounts: ({ sessionTimeout }?: UseSocialAccountsProps) => {
|
|
4
7
|
readonly error: string | undefined;
|
|
5
8
|
readonly getLinkedAccountInformation: (provider: ProviderEnum) => SocialAccountInformation | undefined;
|
|
6
9
|
readonly isLinked: (provider: ProviderEnum) => boolean;
|
|
@@ -8,3 +11,4 @@ export declare const useSocialAccounts: () => {
|
|
|
8
11
|
readonly linkSocialAccount: (provider: ProviderEnum) => Promise<void>;
|
|
9
12
|
readonly unlinkSocialAccount: (provider: ProviderEnum) => Promise<void>;
|
|
10
13
|
};
|
|
14
|
+
export {};
|