@dynamic-labs/sdk-react-core 0.18.100-viem.0 → 0.18.100-viem.10
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 +111 -1
- package/package.cjs +3 -3
- package/package.js +3 -3
- package/package.json +10 -10
- package/src/index.cjs +4 -0
- package/src/index.js +2 -0
- package/src/lib/Main.cjs +5 -0
- package/src/lib/Main.js +5 -0
- package/src/lib/components/Button/Button.cjs +10 -7
- package/src/lib/components/Button/Button.js +10 -7
- package/src/lib/components/DynamicConnectButton/components/ConnectButton.cjs +1 -1
- package/src/lib/components/DynamicConnectButton/components/ConnectButton.js +1 -1
- package/src/lib/components/ErrorContainer/ErrorContainer.d.ts +1 -1
- package/src/lib/components/ListTile/ListTile.cjs +1 -1
- package/src/lib/components/ListTile/ListTile.js +1 -1
- package/src/lib/components/ListTile/ListTile.types.d.ts +1 -0
- 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 +5 -3
- package/src/lib/components/OTPVerificationView/OTPVerificationView.d.ts +2 -0
- package/src/lib/components/OTPVerificationView/OTPVerificationView.js +5 -3
- package/src/lib/components/TransactionConfirmationPageLayout/TransactionConfirmationPageLayout.cjs +3 -1
- package/src/lib/components/TransactionConfirmationPageLayout/TransactionConfirmationPageLayout.js +3 -1
- package/src/lib/components/TransactionStatusLayout/TransactionStatusLayout.cjs +2 -2
- package/src/lib/components/TransactionStatusLayout/TransactionStatusLayout.js +2 -2
- 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/context/DynamicContext/DynamicContext.cjs +15 -4
- package/src/lib/context/DynamicContext/DynamicContext.js +17 -6
- package/src/lib/context/DynamicContext/hooks/useVerificationInProgress/useVerificationInProgress.cjs +13 -3
- package/src/lib/context/DynamicContext/hooks/useVerificationInProgress/useVerificationInProgress.js +13 -3
- 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 +6 -3
- 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/SendBalanceContext/SendBalanceContext.types.d.ts +2 -2
- 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/data/api.cjs +33 -1
- package/src/lib/data/api.d.ts +3 -1
- package/src/lib/data/api.js +34 -4
- package/src/lib/layout/DynamicAuthLayout/Header/header.cjs +10 -2
- package/src/lib/layout/DynamicAuthLayout/Header/header.js +10 -2
- package/src/lib/main.global.cjs +1 -1
- package/src/lib/main.global.js +1 -1
- package/src/lib/modals/SendBalanceModal/SendBalanceModal.d.ts +2 -2
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.cjs +11 -2
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.js +11 -2
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.types.d.ts +6 -3
- package/src/lib/shared/assets/double-arrow-right.cjs +53 -0
- package/src/lib/shared/assets/double-arrow-right.js +29 -0
- package/src/lib/shared/assets/index.d.ts +1 -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/errors.cjs +7 -0
- package/src/lib/utils/constants/errors.d.ts +1 -0
- package/src/lib/utils/constants/errors.js +3 -0
- package/src/lib/utils/constants/index.d.ts +1 -1
- package/src/lib/utils/constants/localStorage.cjs +2 -0
- package/src/lib/utils/constants/localStorage.d.ts +1 -0
- package/src/lib/utils/constants/localStorage.js +2 -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/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/getUserProfileFields/getUserProfileFields.cjs +14 -2
- package/src/lib/utils/functions/getUserProfileFields/getUserProfileFields.d.ts +3 -2
- package/src/lib/utils/functions/getUserProfileFields/getUserProfileFields.js +14 -2
- package/src/lib/utils/functions/index.d.ts +7 -0
- package/src/lib/utils/functions/isMagicConnector/index.d.ts +1 -0
- package/src/lib/utils/functions/isMagicConnector/isMagicConnector.cjs +10 -0
- package/src/lib/utils/functions/isMagicConnector/isMagicConnector.d.ts +2 -0
- package/src/lib/utils/functions/isMagicConnector/isMagicConnector.js +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 -4
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.d.ts +2 -1
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.js +11 -5
- package/src/lib/utils/hooks/index.d.ts +2 -0
- package/src/lib/utils/hooks/multiWallet/useMultiWallet/useMultiWallet.cjs +19 -3
- package/src/lib/utils/hooks/multiWallet/useMultiWallet/useMultiWallet.d.ts +1 -2
- package/src/lib/utils/hooks/multiWallet/useMultiWallet/useMultiWallet.js +20 -4
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.cjs +15 -9
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.d.ts +1 -1
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.js +15 -9
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.cjs +2 -1
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js +2 -1
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.cjs +16 -18
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.d.ts +1 -1
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.js +17 -19
- 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/useFetchNetworkConfigurations/useFetchNetworkConfigurations.cjs +2 -7
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/useFetchNetworkConfigurations.js +2 -7
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/utils/index.d.ts +1 -0
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/utils/mergeCustomerEvmNetworksWithServerNetworks/index.d.ts +1 -0
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/utils/mergeCustomerEvmNetworksWithServerNetworks/mergeCustomerEvmNetworksWithServerNetworks.cjs +16 -0
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/utils/mergeCustomerEvmNetworksWithServerNetworks/mergeCustomerEvmNetworksWithServerNetworks.d.ts +2 -0
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/utils/mergeCustomerEvmNetworksWithServerNetworks/mergeCustomerEvmNetworksWithServerNetworks.js +12 -0
- 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 +149 -26
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.d.ts +5 -1
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.js +151 -28
- package/src/lib/utils/hooks/useTransactionEstimatedGas/index.d.ts +1 -0
- package/src/lib/utils/hooks/useTransactionEstimatedGas/useTransactionEstimatedGas.cjs +31 -0
- package/src/lib/utils/hooks/useTransactionEstimatedGas/useTransactionEstimatedGas.d.ts +20 -0
- package/src/lib/utils/hooks/useTransactionEstimatedGas/useTransactionEstimatedGas.js +27 -0
- package/src/lib/utils/hooks/useTransactionWithGasPrice/index.d.ts +1 -0
- package/src/lib/utils/hooks/useTransactionWithGasPrice/useTransactionWithGasPrice.cjs +56 -0
- package/src/lib/utils/hooks/useTransactionWithGasPrice/useTransactionWithGasPrice.d.ts +32 -0
- package/src/lib/utils/hooks/useTransactionWithGasPrice/useTransactionWithGasPrice.js +52 -0
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.cjs +1 -0
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.js +1 -0
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.d.ts +1 -1
- package/src/lib/utils/hooks/useWalletUiUtils/useWalletUiUtils.cjs +2 -2
- package/src/lib/utils/hooks/useWalletUiUtils/useWalletUiUtils.d.ts +5 -1
- package/src/lib/utils/hooks/useWalletUiUtils/useWalletUiUtils.js +2 -2
- package/src/lib/utils/hooks/useWallets/useWallets.d.ts +2 -2
- package/src/lib/views/CaptchaVerifyUser/CaptchaVerifyUser.cjs +9 -3
- package/src/lib/views/CaptchaVerifyUser/CaptchaVerifyUser.js +9 -3
- package/src/lib/views/CollectUserDataView/UserDataFields/index.cjs +4 -0
- package/src/lib/views/CollectUserDataView/UserDataFields/index.js +4 -0
- package/src/lib/views/EmailUpdate/EmailUpdate.cjs +13 -4
- package/src/lib/views/EmailUpdate/EmailUpdate.js +13 -4
- package/src/lib/views/EmailVerification/EmailVerification.cjs +12 -1
- package/src/lib/views/EmailVerification/EmailVerification.js +14 -3
- package/src/lib/views/EmailWalletOTPVerificationView/EmailWalletOTPVerificationView.cjs +3 -2
- package/src/lib/views/EmailWalletOTPVerificationView/EmailWalletOTPVerificationView.js +3 -2
- package/src/lib/views/LoginWithEmailView/components/LoginWithEmailWalletList/LoginWithEmailWalletList.cjs +4 -1
- package/src/lib/views/LoginWithEmailView/components/LoginWithEmailWalletList/LoginWithEmailWalletList.js +4 -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/MergeUserAccountsView/MergeUserAccountsView.cjs +111 -0
- package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.d.ts +2 -0
- package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.js +107 -0
- package/src/lib/views/MergeUserAccountsView/index.d.ts +1 -0
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.cjs +4 -2
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.js +4 -2
- package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.cjs +4 -2
- package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.js +4 -2
- package/src/lib/views/SendBalanceView/SendBalanceView.cjs +14 -35
- package/src/lib/views/SendBalanceView/SendBalanceView.d.ts +2 -2
- package/src/lib/views/SendBalanceView/SendBalanceView.js +15 -36
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.cjs +67 -0
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.d.ts +8 -0
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.js +63 -0
- package/src/lib/views/SendBalanceView/components/TransactionStage/index.d.ts +1 -0
- package/src/lib/views/SendBalanceView/components/index.d.ts +1 -0
- package/src/lib/views/SocialRedirectView/SocialRedirectView.cjs +1 -2
- package/src/lib/views/SocialRedirectView/SocialRedirectView.js +1 -2
- package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.cjs +31 -8
- package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.d.ts +4 -3
- package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.js +32 -9
- package/src/lib/views/TransactionConfirmationView/hooks/index.d.ts +2 -1
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionGas/index.d.ts +1 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionGas/useTransactionGas.cjs +69 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionGas/useTransactionGas.d.ts +11 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionGas/useTransactionGas.js +65 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionTotal/index.d.ts +1 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionTotal/useTransactionTotal.cjs +14 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionTotal/useTransactionTotal.d.ts +6 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionTotal/useTransactionTotal.js +10 -0
- 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/WalletList.cjs +4 -1
- package/src/lib/views/WalletList/WalletList.js +4 -1
- package/src/lib/views/WalletList/WalletListItem/WalletListItem.cjs +1 -1
- package/src/lib/views/WalletList/WalletListItem/WalletListItem.js +1 -1
- package/src/lib/views/WalletLockedView/WalletLockedView.cjs +20 -4
- package/src/lib/views/WalletLockedView/WalletLockedView.js +20 -4
- package/src/lib/views/viewToComponentMap.cjs +2 -0
- package/src/lib/views/viewToComponentMap.js +2 -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/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
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/index.d.ts +0 -1
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.cjs +0 -104
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.d.ts +0 -17
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.js +0 -100
|
@@ -68,7 +68,8 @@ const useAuthLayoutChecks = (walletConnector) => {
|
|
|
68
68
|
view === 'login-with-email-or-wallet-full-wallet-list' ||
|
|
69
69
|
view === 'wallet-group' ||
|
|
70
70
|
view === 'pending-connect' ||
|
|
71
|
-
view === 'account-exists'
|
|
71
|
+
view === 'account-exists' ||
|
|
72
|
+
(view === 'merge-user-accounts' && !user);
|
|
72
73
|
const showQrCodePreHeader = view === 'qr-code' && showQrCodeMessage && !showQrCodeImage;
|
|
73
74
|
return {
|
|
74
75
|
isWalletListTypeView,
|
|
@@ -64,7 +64,8 @@ const useAuthLayoutChecks = (walletConnector) => {
|
|
|
64
64
|
view === 'login-with-email-or-wallet-full-wallet-list' ||
|
|
65
65
|
view === 'wallet-group' ||
|
|
66
66
|
view === 'pending-connect' ||
|
|
67
|
-
view === 'account-exists'
|
|
67
|
+
view === 'account-exists' ||
|
|
68
|
+
(view === 'merge-user-accounts' && !user);
|
|
68
69
|
const showQrCodePreHeader = view === 'qr-code' && showQrCodeMessage && !showQrCodeImage;
|
|
69
70
|
return {
|
|
70
71
|
isWalletListTypeView,
|
|
@@ -130,16 +130,15 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
130
130
|
network: currentWalletConnectoNetwork,
|
|
131
131
|
});
|
|
132
132
|
});
|
|
133
|
-
const shouldSkipCreatingVisit =
|
|
134
|
-
|
|
135
|
-
const connectWallet = (walletConnector, fetchPublicAddressOpts) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
133
|
+
const shouldSkipCreatingVisit = authMode === 'connect-only' && !enableVisitTrackingOnConnectOnly;
|
|
134
|
+
const connectWallet = (walletConnector, fetchPublicAddressOpts, shouldCallCallback = true) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
136
135
|
const publicWalletAddress = yield walletConnector.fetchPublicAddress(fetchPublicAddressOpts);
|
|
137
136
|
if (!publicWalletAddress) {
|
|
138
137
|
const error = new Error();
|
|
139
138
|
error.code = 'missing-public-address';
|
|
140
139
|
throw error;
|
|
141
140
|
}
|
|
142
|
-
if (onBeforeConnectSuccessConfirmation) {
|
|
141
|
+
if (onBeforeConnectSuccessConfirmation && shouldCallCallback) {
|
|
143
142
|
const shouldProceedWithConnection = yield onBeforeConnectSuccessConfirmation({
|
|
144
143
|
address: publicWalletAddress,
|
|
145
144
|
chain: walletConnector.connectedChain,
|
|
@@ -168,21 +167,20 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
168
167
|
walletConnectorKey: walletConnector.name,
|
|
169
168
|
walletId,
|
|
170
169
|
});
|
|
170
|
+
if (!shouldSkipCreatingVisit) {
|
|
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
|
+
api.createVisit({
|
|
175
|
+
authMode,
|
|
176
|
+
chain: walletChain || '',
|
|
177
|
+
environmentId,
|
|
178
|
+
publicWalletAddress,
|
|
179
|
+
walletName: walletConnector.name,
|
|
180
|
+
walletProvider: getWalletProvider.getWalletProvider(walletConnector),
|
|
181
|
+
});
|
|
182
|
+
}
|
|
171
183
|
}
|
|
172
|
-
if (shouldSkipCreatingVisit) {
|
|
173
|
-
return Promise.resolve(publicWalletAddress);
|
|
174
|
-
}
|
|
175
|
-
// send information to backend to kick off background jobs
|
|
176
|
-
// so verify/sign on the next step could go by more quickly
|
|
177
|
-
// this is async work, but DO NOT AWAIT
|
|
178
|
-
api.createVisit({
|
|
179
|
-
authMode,
|
|
180
|
-
chain: walletChain || '',
|
|
181
|
-
environmentId,
|
|
182
|
-
publicWalletAddress,
|
|
183
|
-
walletName: walletConnector.name,
|
|
184
|
-
walletProvider: getWalletProvider.getWalletProvider(walletConnector),
|
|
185
|
-
});
|
|
186
184
|
return Promise.resolve(publicWalletAddress);
|
|
187
185
|
});
|
|
188
186
|
const unlinkConnectedWallet = (walletId) => {
|
|
@@ -21,7 +21,7 @@ type Props = {
|
|
|
21
21
|
setShowAuthFlow: Dispatch<SetStateAction<boolean>>;
|
|
22
22
|
};
|
|
23
23
|
export declare const useConnectWallet: ({ authMode, clearPrimaryWalletId, enableVisitTrackingOnConnectOnly, environmentId, primaryWalletId, setPrimaryWalletId, wallets, onUnlink, onBeforeConnectSuccessConfirmation, setShowAuthFlow, }: Props) => {
|
|
24
|
-
connectWallet: (walletConnector: WalletConnector, fetchPublicAddressOpts?: FetchPublicAddressOpts) => Promise<string | undefined>;
|
|
24
|
+
connectWallet: (walletConnector: WalletConnector, fetchPublicAddressOpts?: FetchPublicAddressOpts, shouldCallCallback?: boolean) => Promise<string | undefined>;
|
|
25
25
|
connectedWallet: Wallet;
|
|
26
26
|
connectedWallets: Wallet[];
|
|
27
27
|
connectedWalletsInfo: ConnectedWalletConnectorType[] | [];
|
|
@@ -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';
|
|
@@ -126,16 +126,15 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
126
126
|
network: currentWalletConnectoNetwork,
|
|
127
127
|
});
|
|
128
128
|
});
|
|
129
|
-
const shouldSkipCreatingVisit =
|
|
130
|
-
|
|
131
|
-
const connectWallet = (walletConnector, fetchPublicAddressOpts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
129
|
+
const shouldSkipCreatingVisit = authMode === 'connect-only' && !enableVisitTrackingOnConnectOnly;
|
|
130
|
+
const connectWallet = (walletConnector, fetchPublicAddressOpts, shouldCallCallback = true) => __awaiter(void 0, void 0, void 0, function* () {
|
|
132
131
|
const publicWalletAddress = yield walletConnector.fetchPublicAddress(fetchPublicAddressOpts);
|
|
133
132
|
if (!publicWalletAddress) {
|
|
134
133
|
const error = new Error();
|
|
135
134
|
error.code = 'missing-public-address';
|
|
136
135
|
throw error;
|
|
137
136
|
}
|
|
138
|
-
if (onBeforeConnectSuccessConfirmation) {
|
|
137
|
+
if (onBeforeConnectSuccessConfirmation && shouldCallCallback) {
|
|
139
138
|
const shouldProceedWithConnection = yield onBeforeConnectSuccessConfirmation({
|
|
140
139
|
address: publicWalletAddress,
|
|
141
140
|
chain: walletConnector.connectedChain,
|
|
@@ -164,21 +163,20 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
164
163
|
walletConnectorKey: walletConnector.name,
|
|
165
164
|
walletId,
|
|
166
165
|
});
|
|
166
|
+
if (!shouldSkipCreatingVisit) {
|
|
167
|
+
// send information to backend to kick off background jobs
|
|
168
|
+
// so verify/sign on the next step could go by more quickly
|
|
169
|
+
// this is async work, but DO NOT AWAIT
|
|
170
|
+
createVisit({
|
|
171
|
+
authMode,
|
|
172
|
+
chain: walletChain || '',
|
|
173
|
+
environmentId,
|
|
174
|
+
publicWalletAddress,
|
|
175
|
+
walletName: walletConnector.name,
|
|
176
|
+
walletProvider: getWalletProvider(walletConnector),
|
|
177
|
+
});
|
|
178
|
+
}
|
|
167
179
|
}
|
|
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
180
|
return Promise.resolve(publicWalletAddress);
|
|
183
181
|
});
|
|
184
182
|
const unlinkConnectedWallet = (walletId) => {
|
|
@@ -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
|
|
|
@@ -19,6 +19,7 @@ require('viem');
|
|
|
19
19
|
var useLocalStorage = require('../../../shared/utils/hooks/useLocalStorage/useLocalStorage.cjs');
|
|
20
20
|
require('../../../shared/consts/index.cjs');
|
|
21
21
|
var validators = require('../../../context/DynamicContext/validators.cjs');
|
|
22
|
+
var mergeCustomerEvmNetworksWithServerNetworks = require('./utils/mergeCustomerEvmNetworksWithServerNetworks/mergeCustomerEvmNetworksWithServerNetworks.cjs');
|
|
22
23
|
|
|
23
24
|
const MAX_RETRIES = 2;
|
|
24
25
|
const useFetchNetworkConfigurations = ({ authToken, environmentId, evmNetworks: customerEvmNetworks, maxRetries = MAX_RETRIES, }) => {
|
|
@@ -113,13 +114,7 @@ const useFetchNetworkConfigurations = ({ authToken, environmentId, evmNetworks:
|
|
|
113
114
|
serverNetworks.length &&
|
|
114
115
|
customerEvmNetworks !== undefined &&
|
|
115
116
|
customerEvmNetworks.length) {
|
|
116
|
-
mergedEvmNetworks =
|
|
117
|
-
serverNetworks.forEach((network) => {
|
|
118
|
-
const existingNetwork = mergedEvmNetworks === null || mergedEvmNetworks === void 0 ? void 0 : mergedEvmNetworks.find((item) => item.chainId === network.chainId);
|
|
119
|
-
if (!existingNetwork) {
|
|
120
|
-
mergedEvmNetworks === null || mergedEvmNetworks === void 0 ? void 0 : mergedEvmNetworks.push(network);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
117
|
+
mergedEvmNetworks = mergeCustomerEvmNetworksWithServerNetworks.mergeCustomerEvmNetworksWithServerNetworks(customerEvmNetworks, serverNetworks);
|
|
123
118
|
}
|
|
124
119
|
setLsNetworks({
|
|
125
120
|
configurations: {
|
|
@@ -15,6 +15,7 @@ import 'viem';
|
|
|
15
15
|
import { useLocalStorage } from '../../../shared/utils/hooks/useLocalStorage/useLocalStorage.js';
|
|
16
16
|
import '../../../shared/consts/index.js';
|
|
17
17
|
import { validateLocalStorageExpiry } from '../../../context/DynamicContext/validators.js';
|
|
18
|
+
import { mergeCustomerEvmNetworksWithServerNetworks } from './utils/mergeCustomerEvmNetworksWithServerNetworks/mergeCustomerEvmNetworksWithServerNetworks.js';
|
|
18
19
|
|
|
19
20
|
const MAX_RETRIES = 2;
|
|
20
21
|
const useFetchNetworkConfigurations = ({ authToken, environmentId, evmNetworks: customerEvmNetworks, maxRetries = MAX_RETRIES, }) => {
|
|
@@ -109,13 +110,7 @@ const useFetchNetworkConfigurations = ({ authToken, environmentId, evmNetworks:
|
|
|
109
110
|
serverNetworks.length &&
|
|
110
111
|
customerEvmNetworks !== undefined &&
|
|
111
112
|
customerEvmNetworks.length) {
|
|
112
|
-
mergedEvmNetworks = customerEvmNetworks
|
|
113
|
-
serverNetworks.forEach((network) => {
|
|
114
|
-
const existingNetwork = mergedEvmNetworks === null || mergedEvmNetworks === void 0 ? void 0 : mergedEvmNetworks.find((item) => item.chainId === network.chainId);
|
|
115
|
-
if (!existingNetwork) {
|
|
116
|
-
mergedEvmNetworks === null || mergedEvmNetworks === void 0 ? void 0 : mergedEvmNetworks.push(network);
|
|
117
|
-
}
|
|
118
|
-
});
|
|
113
|
+
mergedEvmNetworks = mergeCustomerEvmNetworksWithServerNetworks(customerEvmNetworks, serverNetworks);
|
|
119
114
|
}
|
|
120
115
|
setLsNetworks({
|
|
121
116
|
configurations: {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './mergeCustomerEvmNetworksWithServerNetworks';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { mergeCustomerEvmNetworksWithServerNetworks } from './mergeCustomerEvmNetworksWithServerNetworks';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const mergeCustomerEvmNetworksWithServerNetworks = (customerEvmNetworks, serverNetworks) => {
|
|
6
|
+
const evmNetworks = [...customerEvmNetworks];
|
|
7
|
+
serverNetworks.forEach((network) => {
|
|
8
|
+
const existingNetwork = evmNetworks === null || evmNetworks === void 0 ? void 0 : evmNetworks.find((item) => item.chainId === network.chainId);
|
|
9
|
+
if (!existingNetwork) {
|
|
10
|
+
evmNetworks === null || evmNetworks === void 0 ? void 0 : evmNetworks.unshift(network);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
return evmNetworks;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.mergeCustomerEvmNetworksWithServerNetworks = mergeCustomerEvmNetworksWithServerNetworks;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const mergeCustomerEvmNetworksWithServerNetworks = (customerEvmNetworks, serverNetworks) => {
|
|
2
|
+
const evmNetworks = [...customerEvmNetworks];
|
|
3
|
+
serverNetworks.forEach((network) => {
|
|
4
|
+
const existingNetwork = evmNetworks === null || evmNetworks === void 0 ? void 0 : evmNetworks.find((item) => item.chainId === network.chainId);
|
|
5
|
+
if (!existingNetwork) {
|
|
6
|
+
evmNetworks === null || evmNetworks === void 0 ? void 0 : evmNetworks.unshift(network);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
return evmNetworks;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { mergeCustomerEvmNetworksWithServerNetworks };
|
|
@@ -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,
|
|
@@ -23,13 +23,35 @@ require('@dynamic-labs/multi-wallet');
|
|
|
23
23
|
var getAuthToken = require('../../functions/getAuthToken/getAuthToken.cjs');
|
|
24
24
|
var index = require('../../functions/getEnabledOAuthProviders/index.cjs');
|
|
25
25
|
var isSocialKycEnabled = require('../../functions/isSocialKycEnabled/isSocialKycEnabled.cjs');
|
|
26
|
+
var randomString = require('../../functions/randomString/randomString.cjs');
|
|
27
|
+
var stringifyURIQuery = require('../../functions/stringifyURIQuery/stringifyURIQuery.cjs');
|
|
28
|
+
var digestSHA256 = require('../../functions/digestSHA256/digestSHA256.cjs');
|
|
29
|
+
var encodeBase64URL = require('../../functions/encodeBase64URL/encodeBase64URL.cjs');
|
|
30
|
+
var getRedirectURIOrigin = require('../../functions/getRedirectURIOrigin/getRedirectURIOrigin.cjs');
|
|
26
31
|
|
|
27
|
-
const
|
|
32
|
+
const socialProviders = [
|
|
33
|
+
'discord',
|
|
34
|
+
'facebook',
|
|
35
|
+
'github',
|
|
36
|
+
'google',
|
|
37
|
+
'instagram',
|
|
38
|
+
'twitch',
|
|
39
|
+
'twitter',
|
|
40
|
+
];
|
|
41
|
+
// pkce params are only required for twitter and break if added for other providers, like google
|
|
42
|
+
// so we should only add provider that support pkce to this list
|
|
43
|
+
const providersRequiringPkce = ['twitter', 'github'];
|
|
44
|
+
const providersWithoutWindowOpenerRefence = ['twitter'];
|
|
45
|
+
const useSocialAccounts = ({ sessionTimeout } = {
|
|
46
|
+
sessionTimeout: 10000,
|
|
47
|
+
}) => {
|
|
28
48
|
var _a;
|
|
29
49
|
const { environmentId, user, projectSettings, onboardingOnlyJwt } = useInternalDynamicContext.useInternalDynamicContext();
|
|
30
50
|
const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback.useUpdateUserProfileByJWTCallback();
|
|
31
51
|
const [isProcessing, setIsProcessing] = React.useState(false);
|
|
32
52
|
const [error, setError] = React.useState();
|
|
53
|
+
const providersWaitingOauthMessages = React.useRef({});
|
|
54
|
+
const authWindowInterval = React.useRef();
|
|
33
55
|
const userJwt = (_a = getAuthToken.getAuthToken()) !== null && _a !== void 0 ? _a : onboardingOnlyJwt;
|
|
34
56
|
const oauthProviders = index.getEnabledOAuthProviders(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
|
|
35
57
|
const verifiedOAuthCredentialsMap = React.useMemo(() => {
|
|
@@ -48,39 +70,101 @@ const useSocialAccounts = () => {
|
|
|
48
70
|
setIsProcessing(false);
|
|
49
71
|
setError(message);
|
|
50
72
|
};
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (!
|
|
55
|
-
handleError('Social linking is not enabled on the dashboard');
|
|
73
|
+
const addOAuthIFrame = (url) => {
|
|
74
|
+
const container = document.getElementById('oauth-iframe-container');
|
|
75
|
+
let oauthIFrame = document.getElementById('oauth-iframe');
|
|
76
|
+
if (!container || oauthIFrame) {
|
|
56
77
|
return;
|
|
57
78
|
}
|
|
79
|
+
oauthIFrame = document.createElement('iframe');
|
|
80
|
+
oauthIFrame.setAttribute('id', 'oauth-iframe');
|
|
81
|
+
oauthIFrame.setAttribute('src', url);
|
|
82
|
+
container.appendChild(oauthIFrame);
|
|
83
|
+
};
|
|
84
|
+
const removeOAuthIFrame = () => {
|
|
85
|
+
const oauthIFrame = document.getElementById('oauth-iframe');
|
|
86
|
+
if (oauthIFrame) {
|
|
87
|
+
oauthIFrame.remove();
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const checkValidProvider = (provider) => {
|
|
58
91
|
if (!provider) {
|
|
59
92
|
handleError('Provider is required');
|
|
60
|
-
return;
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (!socialProviders.includes(provider)) {
|
|
96
|
+
handleError(`Invalid social provider. Valid providers are: ${socialProviders.join(', ')}`);
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
};
|
|
101
|
+
const checkValidOAuthLinking = (provider) => {
|
|
102
|
+
if (!isSocialKycEnabled.isSocialKycEnabled(projectSettings)) {
|
|
103
|
+
handleError('Social linking is not enabled on the dashboard');
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
if (!checkValidProvider(provider)) {
|
|
107
|
+
return false;
|
|
61
108
|
}
|
|
62
109
|
const verifiedCredential = verifiedOAuthCredentialsMap[provider];
|
|
63
110
|
if (verifiedCredential) {
|
|
64
111
|
handleError(`Account already linked for provider: ${provider}`);
|
|
65
|
-
return;
|
|
112
|
+
return false;
|
|
66
113
|
}
|
|
67
114
|
const oauthProvider = oauthProviders.find((p) => p.provider === provider);
|
|
68
115
|
if (!oauthProvider) {
|
|
69
116
|
handleError(`Provider is not enabled on the dashboard: ${provider}`);
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
};
|
|
121
|
+
const linkSocialAccount = (provider) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
122
|
+
var _b;
|
|
123
|
+
clearInterval(authWindowInterval.current);
|
|
124
|
+
setError(undefined);
|
|
125
|
+
setIsProcessing(true);
|
|
126
|
+
// invalid linking request
|
|
127
|
+
if (!checkValidOAuthLinking(provider)) {
|
|
70
128
|
return;
|
|
71
129
|
}
|
|
130
|
+
const state = randomString.randomString(8);
|
|
131
|
+
const verifier = randomString.randomString(43);
|
|
132
|
+
const clearListeners = () => {
|
|
133
|
+
removeOAuthIFrame();
|
|
134
|
+
window.removeEventListener('message', handleAuthWindowMessage);
|
|
135
|
+
providersWaitingOauthMessages.current = Object.assign(Object.assign({}, providersWaitingOauthMessages.current), { [provider]: false });
|
|
136
|
+
};
|
|
72
137
|
const handleAuthWindowMessage = (event) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
-
var
|
|
74
|
-
|
|
75
|
-
|
|
138
|
+
var _c;
|
|
139
|
+
const message = event.data;
|
|
140
|
+
const isAuthorizationMessage = (message === null || message === void 0 ? void 0 : message.type) === 'authorization_response';
|
|
141
|
+
if (isAuthorizationMessage) {
|
|
142
|
+
logger.logger.debug('Message received', { data: message });
|
|
143
|
+
}
|
|
144
|
+
const isValidMessage = isAuthorizationMessage && (message === null || message === void 0 ? void 0 : message.provider) === provider;
|
|
145
|
+
// don't process imvalid messages for provider
|
|
146
|
+
if (!isValidMessage) {
|
|
147
|
+
return;
|
|
76
148
|
}
|
|
77
|
-
|
|
78
|
-
|
|
149
|
+
setIsProcessing(true);
|
|
150
|
+
if (!((_c = providersWaitingOauthMessages.current) === null || _c === void 0 ? void 0 : _c[provider])) {
|
|
151
|
+
handleError(`Linking ${provider} account session timeout.`);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
clearListeners();
|
|
155
|
+
const { code, error } = message;
|
|
156
|
+
if (error && error !== 'undefined') {
|
|
157
|
+
handleError(`Failed to link ${provider} social account: ${error}`);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (!code) {
|
|
161
|
+
handleError(`Failed to link ${provider} social account: no authorization code`);
|
|
79
162
|
return;
|
|
80
163
|
}
|
|
81
|
-
const { code } = event.data;
|
|
82
164
|
const jwt = yield api.verifyOAuth(environmentId, provider, {
|
|
83
165
|
code,
|
|
166
|
+
codeVerifier: verifier,
|
|
167
|
+
state,
|
|
84
168
|
}, String(userJwt));
|
|
85
169
|
if (!jwt) {
|
|
86
170
|
handleError(`Failed to link social account: ${provider}`);
|
|
@@ -89,22 +173,61 @@ const useSocialAccounts = () => {
|
|
|
89
173
|
yield updateUserProfileByJWT(jwt);
|
|
90
174
|
setIsProcessing(false);
|
|
91
175
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
176
|
+
const loginUrl = yield api.getOauthLoginUrl(environmentId, provider, String(userJwt));
|
|
177
|
+
if (!loginUrl) {
|
|
178
|
+
handleError(`Failed to get login url to link social account: ${provider}`);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
// we need to use an iframe to be the intermediary in communications between the popup and the sdk
|
|
182
|
+
// because of twitter limitations with accessing the window.opener and BroadcastChannel not working between
|
|
183
|
+
// different origins (our api redirect page and the app where the sdk is running)
|
|
184
|
+
const oauthIFrameUrl = `${getRedirectURIOrigin.getRedirectURIOrigin(loginUrl)}/sdkoauth`;
|
|
185
|
+
addOAuthIFrame(oauthIFrameUrl);
|
|
186
|
+
let oauthLoginUrl = loginUrl;
|
|
187
|
+
if (providersRequiringPkce.includes(provider)) {
|
|
188
|
+
const digest = yield digestSHA256.digestSHA256(verifier);
|
|
189
|
+
const pkceParams = stringifyURIQuery.stringifyURIQuery({
|
|
190
|
+
code_challenge: encodeBase64URL.encodeBase64URL(digest),
|
|
191
|
+
code_challenge_method: 'S256',
|
|
192
|
+
state: state,
|
|
193
|
+
});
|
|
194
|
+
oauthLoginUrl = `${loginUrl}&${pkceParams}`;
|
|
195
|
+
}
|
|
196
|
+
if (!((_b = providersWaitingOauthMessages.current) === null || _b === void 0 ? void 0 : _b[provider])) {
|
|
197
|
+
window.addEventListener('message', handleAuthWindowMessage);
|
|
198
|
+
providersWaitingOauthMessages.current = Object.assign(Object.assign({}, providersWaitingOauthMessages.current), { [provider]: true });
|
|
199
|
+
}
|
|
200
|
+
const authWindow = window.open(oauthLoginUrl, '_blank', 'width=500,height=600');
|
|
201
|
+
if (!providersWithoutWindowOpenerRefence.includes(provider)) {
|
|
202
|
+
// For provider that support window.opener, we need to clear all states/listeners when the window is closed
|
|
203
|
+
authWindowInterval.current = setInterval(() => {
|
|
204
|
+
if (!(authWindow === null || authWindow === void 0 ? void 0 : authWindow.closed)) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
clearInterval(authWindowInterval.current);
|
|
98
208
|
setIsProcessing(false);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
// For provider that don't support window.opener, we need to use a timeout to try to detect when the
|
|
213
|
+
// window is closed
|
|
214
|
+
authWindowInterval.current = setInterval(() => {
|
|
215
|
+
var _a;
|
|
216
|
+
// user didn't complete oauth
|
|
217
|
+
if ((_a = providersWaitingOauthMessages.current) === null || _a === void 0 ? void 0 : _a[provider]) {
|
|
218
|
+
clearListeners();
|
|
219
|
+
handleError(`Linking ${provider} account window timeout.`);
|
|
220
|
+
}
|
|
221
|
+
setIsProcessing(false);
|
|
222
|
+
clearInterval(authWindowInterval.current);
|
|
223
|
+
}, sessionTimeout);
|
|
224
|
+
}
|
|
101
225
|
});
|
|
102
226
|
const unlinkSocialAccount = (provider) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
103
|
-
var
|
|
227
|
+
var _d;
|
|
104
228
|
setError(undefined);
|
|
105
229
|
setIsProcessing(true);
|
|
106
|
-
if (!provider) {
|
|
107
|
-
handleError('Provider is required');
|
|
230
|
+
if (!checkValidProvider(provider)) {
|
|
108
231
|
return;
|
|
109
232
|
}
|
|
110
233
|
const verifiedCredential = verifiedOAuthCredentialsMap[provider];
|
|
@@ -115,7 +238,7 @@ const useSocialAccounts = () => {
|
|
|
115
238
|
try {
|
|
116
239
|
const jwt = yield api.unlinkOAuth({
|
|
117
240
|
environmentId,
|
|
118
|
-
verifiedCrentialId: (
|
|
241
|
+
verifiedCrentialId: (_d = verifiedCredential.id) !== null && _d !== void 0 ? _d : '',
|
|
119
242
|
}, String(userJwt));
|
|
120
243
|
if (!jwt) {
|
|
121
244
|
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 {};
|