@dynamic-labs/sdk-react-core 0.18.100-viem.2 → 0.18.100-viem.21
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 +179 -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 -32
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.d.ts +1 -2
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.js +23 -33
- 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 +20 -26
- package/src/lib/utils/hooks/useWallets/useWallets.d.ts +3 -2
- package/src/lib/utils/hooks/useWallets/useWallets.js +21 -27
- 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
|
@@ -7,12 +7,16 @@ import 'react';
|
|
|
7
7
|
import '../../shared/logger.js';
|
|
8
8
|
import '@dynamic-labs/wallet-book';
|
|
9
9
|
import '@dynamic-labs/utils';
|
|
10
|
+
import { DYNAMIC_CONTEXT_LAST_SESSION_SETTINGS, WAGMI_LAST_SESSION_SETTINGS } from '../../utils/constants/localStorage.js';
|
|
10
11
|
import '../../utils/constants/colors.js';
|
|
11
|
-
import '../../shared/utils/classes/storage/localStorage.js';
|
|
12
|
+
import { LocalStorage } from '../../shared/utils/classes/storage/localStorage.js';
|
|
12
13
|
import 'viem';
|
|
13
14
|
import { getAuthToken } from '../../utils/functions/getAuthToken/getAuthToken.js';
|
|
14
15
|
|
|
15
16
|
let logoutTimer;
|
|
17
|
+
let dynamicContextSettingsTimer;
|
|
18
|
+
let wagmiSettingsTimer;
|
|
19
|
+
const sdkSettingsTimeout = 24 * 60 * 60 * 1000; // 24 hours
|
|
16
20
|
const isAuthTokenExpired = (token) => {
|
|
17
21
|
const decoded = decodeJwt(token);
|
|
18
22
|
if (!decoded) {
|
|
@@ -50,17 +54,47 @@ const initExpirationTime = (logout) => {
|
|
|
50
54
|
const expiryTimeout = Math.min(expirationTimeInMs, 2147483647);
|
|
51
55
|
logoutTimer = setTimeout(logout, expiryTimeout);
|
|
52
56
|
};
|
|
53
|
-
const getInitialView = ({ connectedWallets, loginWithEmail, isBridgeFlow, isFullyConnected, }) => {
|
|
57
|
+
const getInitialView = ({ connectedWallets, loginWithEmail, isBridgeFlow, isFullyConnected, isMultiWalletEnabled, }) => {
|
|
54
58
|
if (loginWithEmail) {
|
|
55
59
|
return 'login-with-email-or-wallet';
|
|
56
60
|
}
|
|
57
61
|
if (isFullyConnected) {
|
|
58
|
-
return 'wallet-list';
|
|
62
|
+
return isMultiWalletEnabled ? 'multi-wallet-wallet-list' : 'wallet-list';
|
|
59
63
|
}
|
|
60
64
|
if (isBridgeFlow && !connectedWallets.length) {
|
|
61
65
|
return 'bridge-welcome';
|
|
62
66
|
}
|
|
63
67
|
return 'wallet-list';
|
|
64
68
|
};
|
|
69
|
+
const setDynamicContextSessionSettings = () => {
|
|
70
|
+
setSessionSettings(DYNAMIC_CONTEXT_LAST_SESSION_SETTINGS);
|
|
71
|
+
dynamicContextSettingsTimer = setTimeout(isDynamicContextSessionSettingExpired, sdkSettingsTimeout);
|
|
72
|
+
};
|
|
73
|
+
const setWagmiSessionSettings = () => {
|
|
74
|
+
setSessionSettings(WAGMI_LAST_SESSION_SETTINGS);
|
|
75
|
+
wagmiSettingsTimer = setTimeout(isWagmiSessionSettingExpired, sdkSettingsTimeout);
|
|
76
|
+
};
|
|
77
|
+
const setSessionSettings = (lsKey) => {
|
|
78
|
+
const timestamp = new Date().getTime();
|
|
79
|
+
LocalStorage.setToLS(lsKey, timestamp.toString());
|
|
80
|
+
};
|
|
81
|
+
const isDynamicContextSessionSettingExpired = () => isSettingExpired(DYNAMIC_CONTEXT_LAST_SESSION_SETTINGS, dynamicContextSettingsTimer);
|
|
82
|
+
const isWagmiSessionSettingExpired = () => isSettingExpired(WAGMI_LAST_SESSION_SETTINGS, wagmiSettingsTimer);
|
|
83
|
+
const isSettingExpired = (lsKey, timer) => {
|
|
84
|
+
const lastSentTime = LocalStorage.getFromLS(lsKey);
|
|
85
|
+
// should set new time
|
|
86
|
+
if (!lastSentTime) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
const lastSentTimestamp = parseInt(lastSentTime);
|
|
90
|
+
const currentTime = new Date().getTime();
|
|
91
|
+
if (currentTime - lastSentTimestamp > sdkSettingsTimeout) {
|
|
92
|
+
// Reset session-related data here
|
|
93
|
+
clearTimeout(timer);
|
|
94
|
+
LocalStorage.removeFromLS(lsKey);
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
};
|
|
65
99
|
|
|
66
|
-
export { getInitialView, initExpirationTime, isAuthTokenExpired };
|
|
100
|
+
export { getInitialView, initExpirationTime, isAuthTokenExpired, isDynamicContextSessionSettingExpired, isWagmiSessionSettingExpired, sdkSettingsTimeout, setDynamicContextSessionSettings, setWagmiSessionSettings };
|
|
@@ -12,15 +12,18 @@ var React = require('react');
|
|
|
12
12
|
* "Connect" button in the WalletConnect modal, there is a uri ready to go
|
|
13
13
|
* to immediately trigger the deep link on mobile
|
|
14
14
|
*/
|
|
15
|
-
const useSetShowAuthFlowWithInit = ({ setShowAuthFlow, wallets, }) => {
|
|
15
|
+
const useSetShowAuthFlowWithInit = ({ setShowAuthFlow, wallets, user, isMultiWalletEnabled, }) => {
|
|
16
16
|
const setShowAuthFlowWithInit = React.useCallback((value) => {
|
|
17
17
|
var _a;
|
|
18
18
|
if (value) {
|
|
19
|
+
// if the uer is already signed in but multiwallet is not enabled, do not change state
|
|
20
|
+
if (user && !isMultiWalletEnabled)
|
|
21
|
+
return;
|
|
19
22
|
(_a = wallets
|
|
20
23
|
.find((wallet) => wallet.walletConnector.key === 'walletconnect')) === null || _a === void 0 ? void 0 : _a.walletConnector.init();
|
|
21
24
|
}
|
|
22
25
|
setShowAuthFlow(value);
|
|
23
|
-
}, [setShowAuthFlow, wallets]);
|
|
26
|
+
}, [setShowAuthFlow, wallets, user, isMultiWalletEnabled]);
|
|
24
27
|
return setShowAuthFlowWithInit;
|
|
25
28
|
};
|
|
26
29
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
import { WalletOption } from '../../../../shared';
|
|
2
|
+
import { UserProfile, WalletOption } from '../../../../shared';
|
|
3
3
|
/**
|
|
4
4
|
* this hook wraps `setShowAuthFlow`. WalletConnect requires initialization
|
|
5
5
|
* before we can connect a wallet. The goal here is that when a user clicks
|
|
@@ -8,7 +8,9 @@ import { WalletOption } from '../../../../shared';
|
|
|
8
8
|
* "Connect" button in the WalletConnect modal, there is a uri ready to go
|
|
9
9
|
* to immediately trigger the deep link on mobile
|
|
10
10
|
*/
|
|
11
|
-
export declare const useSetShowAuthFlowWithInit: ({ setShowAuthFlow, wallets, }: {
|
|
11
|
+
export declare const useSetShowAuthFlowWithInit: ({ setShowAuthFlow, wallets, user, isMultiWalletEnabled, }: {
|
|
12
12
|
setShowAuthFlow: Dispatch<SetStateAction<boolean>>;
|
|
13
13
|
wallets: WalletOption[];
|
|
14
|
+
user?: UserProfile | undefined;
|
|
15
|
+
isMultiWalletEnabled?: boolean | undefined;
|
|
14
16
|
}) => Dispatch<SetStateAction<boolean>>;
|
|
@@ -8,15 +8,18 @@ import { useCallback } from 'react';
|
|
|
8
8
|
* "Connect" button in the WalletConnect modal, there is a uri ready to go
|
|
9
9
|
* to immediately trigger the deep link on mobile
|
|
10
10
|
*/
|
|
11
|
-
const useSetShowAuthFlowWithInit = ({ setShowAuthFlow, wallets, }) => {
|
|
11
|
+
const useSetShowAuthFlowWithInit = ({ setShowAuthFlow, wallets, user, isMultiWalletEnabled, }) => {
|
|
12
12
|
const setShowAuthFlowWithInit = useCallback((value) => {
|
|
13
13
|
var _a;
|
|
14
14
|
if (value) {
|
|
15
|
+
// if the uer is already signed in but multiwallet is not enabled, do not change state
|
|
16
|
+
if (user && !isMultiWalletEnabled)
|
|
17
|
+
return;
|
|
15
18
|
(_a = wallets
|
|
16
19
|
.find((wallet) => wallet.walletConnector.key === 'walletconnect')) === null || _a === void 0 ? void 0 : _a.walletConnector.init();
|
|
17
20
|
}
|
|
18
21
|
setShowAuthFlow(value);
|
|
19
|
-
}, [setShowAuthFlow, wallets]);
|
|
22
|
+
}, [setShowAuthFlow, wallets, user, isMultiWalletEnabled]);
|
|
20
23
|
return setShowAuthFlowWithInit;
|
|
21
24
|
};
|
|
22
25
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var EventEmitter = require('eventemitter3');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
|
|
10
|
+
|
|
11
|
+
// This file is temporary and should be removed after QNTM-180 is done
|
|
12
|
+
const getInternalEvents = () => new EventEmitter__default["default"]();
|
|
13
|
+
|
|
14
|
+
exports.getInternalEvents = getInternalEvents;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import EventEmitter from 'eventemitter3';
|
|
2
|
+
/** Maps internal event names to their listeners */
|
|
3
|
+
export type InternalEventMap = {
|
|
4
|
+
emailVerificationResult: (param: boolean) => void;
|
|
5
|
+
clearPrimaryWallet: () => void;
|
|
6
|
+
};
|
|
7
|
+
export type InternalEventEmitter = EventEmitter<InternalEventMap>;
|
|
8
|
+
export declare const getInternalEvents: () => InternalEventEmitter;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Dispatch, ReactNode, SetStateAction } from 'react';
|
|
1
|
+
import { Dispatch, MutableRefObject, ReactNode, SetStateAction } from 'react';
|
|
2
2
|
import { DynamicJwt, NameServiceData, ProjectSettings } from '@dynamic-labs/sdk-api';
|
|
3
3
|
import { NetworkConfigurationMap, SocialProviderFilter, WalletUiUtils } from '@dynamic-labs/types';
|
|
4
4
|
import { Chain, FetchPublicAddressOpts, WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
@@ -8,6 +8,7 @@ import { MultiWalletWidgetStateSetter } from '../../../utils/hooks/multiWallet';
|
|
|
8
8
|
import { ThemeData, ThemeSetting } from '../../ThemeContext';
|
|
9
9
|
import { DisplayOrder, SetDisplayOrderPriority } from '../hooks';
|
|
10
10
|
import { Callback } from '../useCustomerCallbacks';
|
|
11
|
+
import { InternalEventEmitter } from '../internalEvents';
|
|
11
12
|
export type ChainsToConnect = {
|
|
12
13
|
chain: Chain;
|
|
13
14
|
numberOfWallets: number;
|
|
@@ -97,6 +98,8 @@ export interface IDynamicContext {
|
|
|
97
98
|
setSelectedWalletConnector: (connector: WalletConnector | null) => void;
|
|
98
99
|
setSelectedWalletWithAction: (walletWithAction: WalletWithAction | null) => void;
|
|
99
100
|
setShowAuthFlow: Dispatch<SetStateAction<boolean>>;
|
|
101
|
+
/** The unwrapped version of setShowAuthFlow. See useSetShowAuthFlowWithInit.ts for context */
|
|
102
|
+
internalSetShowAuthFlow: Dispatch<SetStateAction<boolean>>;
|
|
100
103
|
setShowDynamicUserProfile: Dispatch<SetStateAction<boolean>>;
|
|
101
104
|
setShowQrcodeModal: Dispatch<SetStateAction<boolean>>;
|
|
102
105
|
setShowWidgetStatePopup: Dispatch<SetStateAction<boolean>>;
|
|
@@ -112,6 +115,7 @@ export interface IDynamicContext {
|
|
|
112
115
|
* The boolean value representing the state of displaying the bridge widget
|
|
113
116
|
*/
|
|
114
117
|
showBridgeWidget: boolean;
|
|
118
|
+
showLockedWalletView?: boolean;
|
|
115
119
|
showQrcodeModal: boolean;
|
|
116
120
|
showWidgetStatePopup: boolean;
|
|
117
121
|
signWithEmailWalletName?: string;
|
|
@@ -143,4 +147,6 @@ export interface IDynamicContext {
|
|
|
143
147
|
legacyIsVerifying: boolean;
|
|
144
148
|
/** Legacy setter for legacyIsVerifying */
|
|
145
149
|
setLegacyIsVerifying: Dispatch<SetStateAction<boolean>>;
|
|
150
|
+
/** Temporary workaround, until QNTM-180 is complete */
|
|
151
|
+
internalEvents: MutableRefObject<InternalEventEmitter>;
|
|
146
152
|
}
|
|
@@ -11,7 +11,7 @@ const useDynamicContext = () => {
|
|
|
11
11
|
if (context === undefined) {
|
|
12
12
|
throw new Error('useDynamicContext must be used within a DynamicContextProvider');
|
|
13
13
|
}
|
|
14
|
-
const { accountSwitchState, authMode, authToken, awaitingSignatureState, connectedWallets, getNameService, handleLogOut, handleUnlinkWallet, isAuthenticated, isFullyConnected, isVerificationInProgress, linkedWallets, loadingNetwork, loginWithEmail, multiWalletWidgetState, network, networkConfigurations, qrcodeUri, rpcProviders, sdkHasLoaded, secondaryWallets, setLogInWithEmail, setMultiWalletWidgetState, setNetwork, setPrimaryWallet, setShowAuthFlow, setShowDynamicUserProfile, setShowQrcodeModal, shadowDOMEnabled, showAuthFlow, showQrcodeModal, user, walletConnector, wallets, walletsByChain, walletsToConnectByChain, primaryWallet, setShowBridgeWidget, sendWagmiSettings, } = context;
|
|
14
|
+
const { accountSwitchState, authMode, authToken, awaitingSignatureState, connectedWallets, getNameService, handleLogOut, handleUnlinkWallet, isAuthenticated, isFullyConnected, isVerificationInProgress, linkedWallets, loadingNetwork, loginWithEmail, multiWalletWidgetState, network, networkConfigurations, qrcodeUri, rpcProviders, sdkHasLoaded, secondaryWallets, setLogInWithEmail, setMultiWalletWidgetState, setNetwork, setPrimaryWallet, setShowAuthFlow, setShowDynamicUserProfile, setShowQrcodeModal, shadowDOMEnabled, showAuthFlow, showQrcodeModal, user, walletConnector, wallets, walletsByChain, walletsToConnectByChain, primaryWallet, setShowBridgeWidget, sendWagmiSettings, internalEvents, } = context;
|
|
15
15
|
return {
|
|
16
16
|
accountSwitchState,
|
|
17
17
|
authMode,
|
|
@@ -21,6 +21,7 @@ const useDynamicContext = () => {
|
|
|
21
21
|
getNameService,
|
|
22
22
|
handleLogOut,
|
|
23
23
|
handleUnlinkWallet,
|
|
24
|
+
internalEvents,
|
|
24
25
|
isAuthenticated,
|
|
25
26
|
isFullyConnected,
|
|
26
27
|
isVerificationInProgress,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { IDynamicContext } from './types';
|
|
2
|
-
export type UseDynamicContext = Pick<IDynamicContext, 'accountSwitchState' | 'authMode' | 'authToken' | 'awaitingSignatureState' | 'connectedWallets' | 'getNameService' | 'handleLogOut' | 'handleUnlinkWallet' | 'isAuthenticated' | 'isFullyConnected' | 'isVerificationInProgress' | 'linkedWallets' | 'loadingNetwork' | 'loginWithEmail' | 'multiWalletWidgetState' | 'network' | 'networkConfigurations' | 'primaryWallet' | 'qrcodeUri' | 'rpcProviders' | 'sdkHasLoaded' | 'secondaryWallets' | 'setLogInWithEmail' | 'setMultiWalletWidgetState' | 'setNetwork' | 'setPrimaryWallet' | 'setShowAuthFlow' | 'setShowDynamicUserProfile' | 'setShowQrcodeModal' | 'shadowDOMEnabled' | 'showAuthFlow' | 'showQrcodeModal' | 'user' | 'walletConnector' | 'wallets' | 'walletsByChain' | 'walletsToConnectByChain' | 'setShowBridgeWidget' | 'sendWagmiSettings'>;
|
|
2
|
+
export type UseDynamicContext = Pick<IDynamicContext, 'accountSwitchState' | 'authMode' | 'authToken' | 'awaitingSignatureState' | 'connectedWallets' | 'getNameService' | 'handleLogOut' | 'handleUnlinkWallet' | 'isAuthenticated' | 'isFullyConnected' | 'isVerificationInProgress' | 'linkedWallets' | 'loadingNetwork' | 'loginWithEmail' | 'multiWalletWidgetState' | 'network' | 'networkConfigurations' | 'primaryWallet' | 'qrcodeUri' | 'rpcProviders' | 'sdkHasLoaded' | 'secondaryWallets' | 'setLogInWithEmail' | 'setMultiWalletWidgetState' | 'setNetwork' | 'setPrimaryWallet' | 'setShowAuthFlow' | 'setShowDynamicUserProfile' | 'setShowQrcodeModal' | 'shadowDOMEnabled' | 'showAuthFlow' | 'showQrcodeModal' | 'user' | 'walletConnector' | 'wallets' | 'walletsByChain' | 'walletsToConnectByChain' | 'setShowBridgeWidget' | 'sendWagmiSettings' | 'internalEvents'>;
|
|
3
3
|
export declare const useDynamicContext: () => UseDynamicContext;
|
|
@@ -7,7 +7,7 @@ const useDynamicContext = () => {
|
|
|
7
7
|
if (context === undefined) {
|
|
8
8
|
throw new Error('useDynamicContext must be used within a DynamicContextProvider');
|
|
9
9
|
}
|
|
10
|
-
const { accountSwitchState, authMode, authToken, awaitingSignatureState, connectedWallets, getNameService, handleLogOut, handleUnlinkWallet, isAuthenticated, isFullyConnected, isVerificationInProgress, linkedWallets, loadingNetwork, loginWithEmail, multiWalletWidgetState, network, networkConfigurations, qrcodeUri, rpcProviders, sdkHasLoaded, secondaryWallets, setLogInWithEmail, setMultiWalletWidgetState, setNetwork, setPrimaryWallet, setShowAuthFlow, setShowDynamicUserProfile, setShowQrcodeModal, shadowDOMEnabled, showAuthFlow, showQrcodeModal, user, walletConnector, wallets, walletsByChain, walletsToConnectByChain, primaryWallet, setShowBridgeWidget, sendWagmiSettings, } = context;
|
|
10
|
+
const { accountSwitchState, authMode, authToken, awaitingSignatureState, connectedWallets, getNameService, handleLogOut, handleUnlinkWallet, isAuthenticated, isFullyConnected, isVerificationInProgress, linkedWallets, loadingNetwork, loginWithEmail, multiWalletWidgetState, network, networkConfigurations, qrcodeUri, rpcProviders, sdkHasLoaded, secondaryWallets, setLogInWithEmail, setMultiWalletWidgetState, setNetwork, setPrimaryWallet, setShowAuthFlow, setShowDynamicUserProfile, setShowQrcodeModal, shadowDOMEnabled, showAuthFlow, showQrcodeModal, user, walletConnector, wallets, walletsByChain, walletsToConnectByChain, primaryWallet, setShowBridgeWidget, sendWagmiSettings, internalEvents, } = context;
|
|
11
11
|
return {
|
|
12
12
|
accountSwitchState,
|
|
13
13
|
authMode,
|
|
@@ -17,6 +17,7 @@ const useDynamicContext = () => {
|
|
|
17
17
|
getNameService,
|
|
18
18
|
handleLogOut,
|
|
19
19
|
handleUnlinkWallet,
|
|
20
|
+
internalEvents,
|
|
20
21
|
isAuthenticated,
|
|
21
22
|
isFullyConnected,
|
|
22
23
|
isVerificationInProgress,
|
|
@@ -20,6 +20,7 @@ const errorMessageMap = {
|
|
|
20
20
|
'missing-nonce': 'Something went wrong. Please try again.',
|
|
21
21
|
'missing-public-address': 'Connection cancelled. Please try again',
|
|
22
22
|
too_many_email_verification_attempts: 'Too many email verification attempts, please try again later',
|
|
23
|
+
'user-cancelled': '',
|
|
23
24
|
wallet_not_deployed: 'Your smart wallet has not been deployed.',
|
|
24
25
|
wrong_email_verification_token: 'The code you entered is incorrect. Please try again.',
|
|
25
26
|
};
|
|
@@ -16,6 +16,7 @@ const errorMessageMap = {
|
|
|
16
16
|
'missing-nonce': 'Something went wrong. Please try again.',
|
|
17
17
|
'missing-public-address': 'Connection cancelled. Please try again',
|
|
18
18
|
too_many_email_verification_attempts: 'Too many email verification attempts, please try again later',
|
|
19
|
+
'user-cancelled': '',
|
|
19
20
|
wallet_not_deployed: 'Your smart wallet has not been deployed.',
|
|
20
21
|
wrong_email_verification_token: 'The code you entered is incorrect. Please try again.',
|
|
21
22
|
};
|
|
@@ -46,7 +46,7 @@ require('../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.cjs');
|
|
|
46
46
|
const SocialRedirectContext = React.createContext(undefined);
|
|
47
47
|
const SocialRedirectContextProvider = ({ children, }) => {
|
|
48
48
|
var _a, _b;
|
|
49
|
-
const { setShowAuthFlow, wallets, setSelectedWalletConnector, walletUiUtils, consumeNonce, displaySiweStatement, environmentId, projectSettings, setIsSingleWalletAccount, setShowDynamicUserProfile, isAuthenticated, setPrimaryWalletId, secondaryWallets, sdkHasLoaded, authToken, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
49
|
+
const { setShowAuthFlow, wallets, setSelectedWalletConnector, walletUiUtils, consumeNonce, displaySiweStatement, environmentId, projectSettings, setIsSingleWalletAccount, setShowDynamicUserProfile, isAuthenticated, setPrimaryWalletId, secondaryWallets, sdkHasLoaded, authToken, connectWallet, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
50
50
|
const { setErrorMessage } = ErrorContext.useErrorContext();
|
|
51
51
|
const { setView } = ViewContext.useViewContext();
|
|
52
52
|
const verifyWallet = useVerifyWallet.useVerifyWallet({
|
|
@@ -139,6 +139,7 @@ const SocialRedirectContextProvider = ({ children, }) => {
|
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
else {
|
|
142
|
+
yield connectWallet(socialWalletConnector);
|
|
142
143
|
const address = yield socialWalletConnector.fetchPublicAddress();
|
|
143
144
|
walletUiUtils.disabledConfirmationOnce();
|
|
144
145
|
yield verifyWallet({
|
|
@@ -42,7 +42,7 @@ import '../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.js';
|
|
|
42
42
|
const SocialRedirectContext = createContext(undefined);
|
|
43
43
|
const SocialRedirectContextProvider = ({ children, }) => {
|
|
44
44
|
var _a, _b;
|
|
45
|
-
const { setShowAuthFlow, wallets, setSelectedWalletConnector, walletUiUtils, consumeNonce, displaySiweStatement, environmentId, projectSettings, setIsSingleWalletAccount, setShowDynamicUserProfile, isAuthenticated, setPrimaryWalletId, secondaryWallets, sdkHasLoaded, authToken, } = useInternalDynamicContext();
|
|
45
|
+
const { setShowAuthFlow, wallets, setSelectedWalletConnector, walletUiUtils, consumeNonce, displaySiweStatement, environmentId, projectSettings, setIsSingleWalletAccount, setShowDynamicUserProfile, isAuthenticated, setPrimaryWalletId, secondaryWallets, sdkHasLoaded, authToken, connectWallet, } = useInternalDynamicContext();
|
|
46
46
|
const { setErrorMessage } = useErrorContext();
|
|
47
47
|
const { setView } = useViewContext();
|
|
48
48
|
const verifyWallet = useVerifyWallet({
|
|
@@ -135,6 +135,7 @@ const SocialRedirectContextProvider = ({ children, }) => {
|
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
else {
|
|
138
|
+
yield connectWallet(socialWalletConnector);
|
|
138
139
|
const address = yield socialWalletConnector.fetchPublicAddress();
|
|
139
140
|
walletUiUtils.disabledConfirmationOnce();
|
|
140
141
|
yield verifyWallet({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SetStateAction, Dispatch, PropsWithChildren, FC } from 'react';
|
|
2
|
-
export type ViewType = 'captcha' | 'chainalysis-blocked-wallet' | 'collect-user-data' | 'collect-user-data-login-with-email' | 'login-with-email-or-wallet-full-wallet-list' | 'login-with-email-or-wallet' | 'login-with-email-verification' | 'network-not-supported' | 'network-not-supported-manual' | 'no-access' | 'no-qr-not-installed' | 'pending-connect' | 'pending-signature-without-back-button' | 'pending-signature' | 'qr-code' | 'update-email' | 'verify-email' | 'wallet-connect-mobile-wallets-list' | 'wallet-list' | 'wallet-sign' | 'wallet-used' | 'wallet-group' | 'wait-for-email-confirmation-view' | 'email-wallet-otp-verification-view' | 'social-redirect-view' | 'wallet-locked-view' | 'social-wrong-account' | 'gate-blocked-wallet' | 'bridge-welcome' | 'bridge-summary' | 'bridge-next-wallet-connection' | 'account-exists' | 'merge-user-accounts';
|
|
2
|
+
export type ViewType = 'captcha' | 'chainalysis-blocked-wallet' | 'collect-user-data' | 'collect-user-data-login-with-email' | 'login-with-email-or-wallet-full-wallet-list' | 'login-with-email-or-wallet' | 'login-with-email-verification' | 'network-not-supported' | 'network-not-supported-manual' | 'no-access' | 'no-qr-not-installed' | 'pending-connect' | 'pending-signature-without-back-button' | 'pending-signature' | 'qr-code' | 'update-email' | 'verify-email' | 'wallet-connect-mobile-wallets-list' | 'wallet-list' | 'multi-wallet-wallet-list' | 'wallet-sign' | 'wallet-used' | 'wallet-group' | 'wait-for-email-confirmation-view' | 'email-wallet-otp-verification-view' | 'social-redirect-view' | 'wallet-locked-view' | 'social-wrong-account' | 'gate-blocked-wallet' | 'bridge-welcome' | 'bridge-summary' | 'bridge-next-wallet-connection' | 'account-exists' | 'merge-user-accounts';
|
|
3
3
|
export type ViewContextProps = {
|
|
4
4
|
setView: Dispatch<SetStateAction<ViewType>>;
|
|
5
5
|
view: ViewType;
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var React = require('react');
|
|
7
|
-
|
|
7
|
+
require('../DynamicContext/DynamicContext.cjs');
|
|
8
8
|
require('@dynamic-labs/sdk-api');
|
|
9
9
|
require('../../shared/logger.cjs');
|
|
10
10
|
require('@dynamic-labs/iconic');
|
|
@@ -26,21 +26,7 @@ var useSyncPrimaryWallet = require('../../utils/hooks/multiWallet/useSyncPrimary
|
|
|
26
26
|
|
|
27
27
|
const WalletContext = React.createContext(undefined);
|
|
28
28
|
const WalletContextProvider = ({ children, canSync, }) => {
|
|
29
|
-
|
|
30
|
-
useSyncPrimaryWallet.useSyncPrimaryWallet({
|
|
31
|
-
authMode,
|
|
32
|
-
canSync,
|
|
33
|
-
computeConnectedStateForWallets,
|
|
34
|
-
connectWallet,
|
|
35
|
-
handleLogOut,
|
|
36
|
-
multiWalletWidgetState,
|
|
37
|
-
primaryWallet,
|
|
38
|
-
secondaryWallets,
|
|
39
|
-
setMultiWalletWidgetState,
|
|
40
|
-
setPrimaryWallet,
|
|
41
|
-
setShowWidgetStatePopup,
|
|
42
|
-
showWidgetStatePopup,
|
|
43
|
-
});
|
|
29
|
+
useSyncPrimaryWallet.useSyncPrimaryWallet(canSync);
|
|
44
30
|
const value = undefined;
|
|
45
31
|
return (jsxRuntime.jsx(WalletContext.Provider, { value: value, children: children }));
|
|
46
32
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { createContext } from 'react';
|
|
3
|
-
import
|
|
3
|
+
import '../DynamicContext/DynamicContext.js';
|
|
4
4
|
import '@dynamic-labs/sdk-api';
|
|
5
5
|
import '../../shared/logger.js';
|
|
6
6
|
import '@dynamic-labs/iconic';
|
|
@@ -22,21 +22,7 @@ import { useSyncPrimaryWallet } from '../../utils/hooks/multiWallet/useSyncPrima
|
|
|
22
22
|
|
|
23
23
|
const WalletContext = createContext(undefined);
|
|
24
24
|
const WalletContextProvider = ({ children, canSync, }) => {
|
|
25
|
-
|
|
26
|
-
useSyncPrimaryWallet({
|
|
27
|
-
authMode,
|
|
28
|
-
canSync,
|
|
29
|
-
computeConnectedStateForWallets,
|
|
30
|
-
connectWallet,
|
|
31
|
-
handleLogOut,
|
|
32
|
-
multiWalletWidgetState,
|
|
33
|
-
primaryWallet,
|
|
34
|
-
secondaryWallets,
|
|
35
|
-
setMultiWalletWidgetState,
|
|
36
|
-
setPrimaryWallet,
|
|
37
|
-
setShowWidgetStatePopup,
|
|
38
|
-
showWidgetStatePopup,
|
|
39
|
-
});
|
|
25
|
+
useSyncPrimaryWallet(canSync);
|
|
40
26
|
const value = undefined;
|
|
41
27
|
return (jsx(WalletContext.Provider, { value: value, children: children }));
|
|
42
28
|
};
|
package/src/lib/data/api.cjs
CHANGED
|
@@ -18,6 +18,7 @@ require('../utils/constants/colors.cjs');
|
|
|
18
18
|
require('../shared/utils/classes/storage/localStorage.cjs');
|
|
19
19
|
require('viem');
|
|
20
20
|
require('../shared/consts/index.cjs');
|
|
21
|
+
var helpers = require('../context/DynamicContext/helpers.cjs');
|
|
21
22
|
|
|
22
23
|
const sdkApi = (jwt) => {
|
|
23
24
|
const settings = {
|
|
@@ -187,11 +188,12 @@ const unlinkWallet = ({ environmentId, primaryWalletId, walletId, }, userJwt) =>
|
|
|
187
188
|
return undefined;
|
|
188
189
|
}
|
|
189
190
|
});
|
|
190
|
-
const transferWallet = (environmentId, { messageToSign, signedMessage, publicWalletAddress, chain, walletName, walletProvider, skipEmptyAccountCheck = false, }, userJwt) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
191
|
+
const transferWallet = (environmentId, { network, messageToSign, signedMessage, publicWalletAddress, chain, walletName, walletProvider, skipEmptyAccountCheck = false, }, userJwt) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
191
192
|
// We should find a better way to do this than force type casting
|
|
192
193
|
const verifyRequest = {
|
|
193
194
|
chain,
|
|
194
195
|
messageToSign,
|
|
196
|
+
network,
|
|
195
197
|
publicWalletAddress,
|
|
196
198
|
signedMessage,
|
|
197
199
|
skipEmptyAccountCheck,
|
|
@@ -339,9 +341,24 @@ const updateUserProfileFields = (jwt, environmentId, fields) => _tslib.__awaiter
|
|
|
339
341
|
throw e;
|
|
340
342
|
}
|
|
341
343
|
});
|
|
342
|
-
const
|
|
344
|
+
const getOauthLoginUrl = (environmentId, providerType, userJwt) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
345
|
+
try {
|
|
346
|
+
const { url } = yield sdkApi(userJwt).oauthLoginUrl({
|
|
347
|
+
environmentId,
|
|
348
|
+
providerType,
|
|
349
|
+
});
|
|
350
|
+
return url;
|
|
351
|
+
}
|
|
352
|
+
catch (e) {
|
|
353
|
+
logger.logger.error(e);
|
|
354
|
+
return undefined;
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
const verifyOAuth = (environmentId, providerType, { code, codeVerifier, state }, userJwt) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
343
358
|
const oauthRequest = {
|
|
344
359
|
code,
|
|
360
|
+
codeVerifier,
|
|
361
|
+
state,
|
|
345
362
|
};
|
|
346
363
|
try {
|
|
347
364
|
const { jwt } = yield sdkApi(userJwt).oauthVerify({
|
|
@@ -356,11 +373,12 @@ const verifyOAuth = (environmentId, providerType, { code }, userJwt) => _tslib._
|
|
|
356
373
|
return undefined;
|
|
357
374
|
}
|
|
358
375
|
});
|
|
359
|
-
const unlinkOAuth = ({ environmentId, verifiedCrentialId, }, userJwt) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
376
|
+
const unlinkOAuth = ({ environmentId, primaryWalletId, verifiedCrentialId, }, userJwt) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
360
377
|
try {
|
|
361
378
|
const { jwt } = yield sdkApi(userJwt).verifyUnlink({
|
|
362
379
|
environmentId,
|
|
363
380
|
verifyUnlinkRequest: {
|
|
381
|
+
primaryWalletId,
|
|
364
382
|
verifiedCrentialId,
|
|
365
383
|
},
|
|
366
384
|
});
|
|
@@ -386,19 +404,24 @@ const getOnrampProviders = ({ chain, environmentId, networkId, token, walletAddr
|
|
|
386
404
|
const sendDynamicProps = (environmentId, settingsToSend) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
387
405
|
try {
|
|
388
406
|
const { dynamicContextProps, dynamicWagmiSettings } = settingsToSend;
|
|
389
|
-
if (dynamicContextProps
|
|
390
|
-
yield
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
dynamicWagmiSettings,
|
|
395
|
-
},
|
|
396
|
-
});
|
|
407
|
+
if (dynamicContextProps) {
|
|
408
|
+
yield sendDynamicContextSettings(environmentId, { dynamicContextProps }, helpers.isDynamicContextSessionSettingExpired, helpers.setDynamicContextSessionSettings);
|
|
409
|
+
}
|
|
410
|
+
if (dynamicWagmiSettings) {
|
|
411
|
+
yield sendDynamicContextSettings(environmentId, { dynamicWagmiSettings }, helpers.isWagmiSessionSettingExpired, helpers.setWagmiSessionSettings);
|
|
397
412
|
}
|
|
398
413
|
}
|
|
399
|
-
catch (
|
|
400
|
-
logger.logger.error
|
|
414
|
+
catch (error) {
|
|
415
|
+
logger.logger.warn('Error caught when sending sdkSettings to api. Please notify Dynamic, and send the DynamicContextProvider settings you currently have configured', { error });
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
const sendDynamicContextSettings = (environmentId, sdkSettingsRequest, isSdkSettingExpired, setSDKSessionSettings) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
419
|
+
// sent once. no need to send again
|
|
420
|
+
if (!isSdkSettingExpired()) {
|
|
421
|
+
return;
|
|
401
422
|
}
|
|
423
|
+
yield sdkApi().logDynamicSdkSettings({ environmentId, sdkSettingsRequest });
|
|
424
|
+
setSDKSessionSettings();
|
|
402
425
|
});
|
|
403
426
|
const mergeUserAccounts = (userJwt, environmentId) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
404
427
|
try {
|
|
@@ -419,6 +442,7 @@ exports.fetchNetworkSettings = fetchNetworkSettings;
|
|
|
419
442
|
exports.fetchNonce = fetchNonce;
|
|
420
443
|
exports.fetchProjectSettings = fetchProjectSettings;
|
|
421
444
|
exports.getEmailProvider = getEmailProvider;
|
|
445
|
+
exports.getOauthLoginUrl = getOauthLoginUrl;
|
|
422
446
|
exports.getOnrampProviders = getOnrampProviders;
|
|
423
447
|
exports.linkWallet = linkWallet;
|
|
424
448
|
exports.mapAuthModeTypeToEnum = mapAuthModeTypeToEnum;
|
package/src/lib/data/api.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare const unlinkWallet: ({ environmentId, primaryWalletId, walletId,
|
|
|
34
34
|
primaryWalletId: string | undefined;
|
|
35
35
|
walletId: string;
|
|
36
36
|
}, userJwt: string) => Promise<string | undefined>;
|
|
37
|
-
export declare const transferWallet: (environmentId: string, { messageToSign, signedMessage, publicWalletAddress, chain, walletName, walletProvider, skipEmptyAccountCheck, }: VerifyWallet, userJwt: string) => Promise<string | undefined>;
|
|
37
|
+
export declare const transferWallet: (environmentId: string, { network, messageToSign, signedMessage, publicWalletAddress, chain, walletName, walletProvider, skipEmptyAccountCheck, }: VerifyWallet, userJwt: string) => Promise<string | undefined>;
|
|
38
38
|
export declare const mapChainToChainEnum: (chain: string) => ChainEnum;
|
|
39
39
|
export declare const mapProviderToProviderEnum: (provider: string) => WalletProviderEnum;
|
|
40
40
|
export declare const mapAuthModeTypeToEnum: (authMode: string) => AuthModeEnum;
|
|
@@ -50,9 +50,11 @@ export declare const verifyWallet: (environmentId: string, { messageToSign, sign
|
|
|
50
50
|
export declare const fetchNetworkSettings: (environmentId: string) => Promise<NetworkConfigurationResponse[] | undefined>;
|
|
51
51
|
export declare const fetchProjectSettings: (environmentId: string) => Promise<ProjectSettings | undefined>;
|
|
52
52
|
export declare const updateUserProfileFields: (jwt: string | undefined, environmentId: string, fields: UserFields) => Promise<UpdateSelfResponse>;
|
|
53
|
-
export declare const
|
|
54
|
-
export declare const
|
|
53
|
+
export declare const getOauthLoginUrl: (environmentId: string, providerType: ProviderEnum, userJwt: string) => Promise<string | undefined>;
|
|
54
|
+
export declare const verifyOAuth: (environmentId: string, providerType: ProviderEnum, { code, codeVerifier, state }: OauthRequest, userJwt: string) => Promise<string | undefined>;
|
|
55
|
+
export declare const unlinkOAuth: ({ environmentId, primaryWalletId, verifiedCrentialId, }: {
|
|
55
56
|
environmentId: string;
|
|
57
|
+
primaryWalletId: string | undefined;
|
|
56
58
|
verifiedCrentialId: string;
|
|
57
59
|
}, userJwt: string) => Promise<string | undefined>;
|
|
58
60
|
export declare const getOnrampProviders: ({ chain, environmentId, networkId, token, walletAddress, }: {
|
package/src/lib/data/api.js
CHANGED
|
@@ -14,6 +14,7 @@ import '../utils/constants/colors.js';
|
|
|
14
14
|
import '../shared/utils/classes/storage/localStorage.js';
|
|
15
15
|
import 'viem';
|
|
16
16
|
import '../shared/consts/index.js';
|
|
17
|
+
import { isDynamicContextSessionSettingExpired, setDynamicContextSessionSettings, isWagmiSessionSettingExpired, setWagmiSessionSettings } from '../context/DynamicContext/helpers.js';
|
|
17
18
|
|
|
18
19
|
const sdkApi = (jwt) => {
|
|
19
20
|
const settings = {
|
|
@@ -183,11 +184,12 @@ const unlinkWallet = ({ environmentId, primaryWalletId, walletId, }, userJwt) =>
|
|
|
183
184
|
return undefined;
|
|
184
185
|
}
|
|
185
186
|
});
|
|
186
|
-
const transferWallet = (environmentId, { messageToSign, signedMessage, publicWalletAddress, chain, walletName, walletProvider, skipEmptyAccountCheck = false, }, userJwt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
187
|
+
const transferWallet = (environmentId, { network, messageToSign, signedMessage, publicWalletAddress, chain, walletName, walletProvider, skipEmptyAccountCheck = false, }, userJwt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
187
188
|
// We should find a better way to do this than force type casting
|
|
188
189
|
const verifyRequest = {
|
|
189
190
|
chain,
|
|
190
191
|
messageToSign,
|
|
192
|
+
network,
|
|
191
193
|
publicWalletAddress,
|
|
192
194
|
signedMessage,
|
|
193
195
|
skipEmptyAccountCheck,
|
|
@@ -335,9 +337,24 @@ const updateUserProfileFields = (jwt, environmentId, fields) => __awaiter(void 0
|
|
|
335
337
|
throw e;
|
|
336
338
|
}
|
|
337
339
|
});
|
|
338
|
-
const
|
|
340
|
+
const getOauthLoginUrl = (environmentId, providerType, userJwt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
341
|
+
try {
|
|
342
|
+
const { url } = yield sdkApi(userJwt).oauthLoginUrl({
|
|
343
|
+
environmentId,
|
|
344
|
+
providerType,
|
|
345
|
+
});
|
|
346
|
+
return url;
|
|
347
|
+
}
|
|
348
|
+
catch (e) {
|
|
349
|
+
logger.error(e);
|
|
350
|
+
return undefined;
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
const verifyOAuth = (environmentId, providerType, { code, codeVerifier, state }, userJwt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
339
354
|
const oauthRequest = {
|
|
340
355
|
code,
|
|
356
|
+
codeVerifier,
|
|
357
|
+
state,
|
|
341
358
|
};
|
|
342
359
|
try {
|
|
343
360
|
const { jwt } = yield sdkApi(userJwt).oauthVerify({
|
|
@@ -352,11 +369,12 @@ const verifyOAuth = (environmentId, providerType, { code }, userJwt) => __awaite
|
|
|
352
369
|
return undefined;
|
|
353
370
|
}
|
|
354
371
|
});
|
|
355
|
-
const unlinkOAuth = ({ environmentId, verifiedCrentialId, }, userJwt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
372
|
+
const unlinkOAuth = ({ environmentId, primaryWalletId, verifiedCrentialId, }, userJwt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
356
373
|
try {
|
|
357
374
|
const { jwt } = yield sdkApi(userJwt).verifyUnlink({
|
|
358
375
|
environmentId,
|
|
359
376
|
verifyUnlinkRequest: {
|
|
377
|
+
primaryWalletId,
|
|
360
378
|
verifiedCrentialId,
|
|
361
379
|
},
|
|
362
380
|
});
|
|
@@ -382,19 +400,24 @@ const getOnrampProviders = ({ chain, environmentId, networkId, token, walletAddr
|
|
|
382
400
|
const sendDynamicProps = (environmentId, settingsToSend) => __awaiter(void 0, void 0, void 0, function* () {
|
|
383
401
|
try {
|
|
384
402
|
const { dynamicContextProps, dynamicWagmiSettings } = settingsToSend;
|
|
385
|
-
if (dynamicContextProps
|
|
386
|
-
yield
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
dynamicWagmiSettings,
|
|
391
|
-
},
|
|
392
|
-
});
|
|
403
|
+
if (dynamicContextProps) {
|
|
404
|
+
yield sendDynamicContextSettings(environmentId, { dynamicContextProps }, isDynamicContextSessionSettingExpired, setDynamicContextSessionSettings);
|
|
405
|
+
}
|
|
406
|
+
if (dynamicWagmiSettings) {
|
|
407
|
+
yield sendDynamicContextSettings(environmentId, { dynamicWagmiSettings }, isWagmiSessionSettingExpired, setWagmiSessionSettings);
|
|
393
408
|
}
|
|
394
409
|
}
|
|
395
|
-
catch (
|
|
396
|
-
logger.error
|
|
410
|
+
catch (error) {
|
|
411
|
+
logger.warn('Error caught when sending sdkSettings to api. Please notify Dynamic, and send the DynamicContextProvider settings you currently have configured', { error });
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
const sendDynamicContextSettings = (environmentId, sdkSettingsRequest, isSdkSettingExpired, setSDKSessionSettings) => __awaiter(void 0, void 0, void 0, function* () {
|
|
415
|
+
// sent once. no need to send again
|
|
416
|
+
if (!isSdkSettingExpired()) {
|
|
417
|
+
return;
|
|
397
418
|
}
|
|
419
|
+
yield sdkApi().logDynamicSdkSettings({ environmentId, sdkSettingsRequest });
|
|
420
|
+
setSDKSessionSettings();
|
|
398
421
|
});
|
|
399
422
|
const mergeUserAccounts = (userJwt, environmentId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
400
423
|
try {
|
|
@@ -409,4 +432,4 @@ const mergeUserAccounts = (userJwt, environmentId) => __awaiter(void 0, void 0,
|
|
|
409
432
|
}
|
|
410
433
|
});
|
|
411
434
|
|
|
412
|
-
export { createEmailVerification, createVisit, fetchNetworkSettings, fetchNonce, fetchProjectSettings, getEmailProvider, getOnrampProviders, linkWallet, mapAuthModeTypeToEnum, mapChainToChainEnum, mapProviderToProviderEnum, mergeUserAccounts, retryEmailVerification, revokeSession, sendDynamicProps, signInWithEmailVerification, transferWallet, unlinkOAuth, unlinkWallet, updateUserProfileFields, verifyEmail, verifyOAuth, verifyWallet };
|
|
435
|
+
export { createEmailVerification, createVisit, fetchNetworkSettings, fetchNonce, fetchProjectSettings, getEmailProvider, getOauthLoginUrl, getOnrampProviders, linkWallet, mapAuthModeTypeToEnum, mapChainToChainEnum, mapProviderToProviderEnum, mergeUserAccounts, retryEmailVerification, revokeSession, sendDynamicProps, signInWithEmailVerification, transferWallet, unlinkOAuth, unlinkWallet, updateUserProfileFields, verifyEmail, verifyOAuth, verifyWallet };
|