@dynamic-labs/sdk-react-core 0.18.100-viem.3 → 0.18.100-viem.30
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 +233 -0
- package/package.cjs +3 -3
- package/package.js +3 -3
- package/package.json +10 -10
- package/src/index.cjs +1 -2
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -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 +20 -6
- package/src/lib/context/DynamicContext/DynamicContext.d.ts +11 -1
- package/src/lib/context/DynamicContext/DynamicContext.js +21 -7
- 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 +33 -7
- package/src/lib/context/SocialRedirectContext/SocialRedirectContext.js +33 -7
- 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 +20 -12
- package/src/lib/data/api.d.ts +3 -2
- package/src/lib/data/api.js +20 -12
- 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/getDynamicLayoutData/getDynamicLayoutData.cjs +6 -1
- package/src/lib/utils/functions/getDynamicLayoutData/getDynamicLayoutData.js +6 -1
- package/src/lib/utils/functions/getProviderByType/getProviderByType.cjs +7 -0
- package/src/lib/utils/functions/getProviderByType/getProviderByType.d.ts +2 -0
- package/src/lib/utils/functions/getProviderByType/getProviderByType.js +3 -0
- package/src/lib/utils/functions/getProviderByType/index.d.ts +1 -0
- package/src/lib/utils/functions/index.d.ts +2 -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/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 +94 -16
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.d.ts +5 -1
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.js +94 -16
- package/src/lib/utils/hooks/useUserUpdateRequest/useUserUpdateRequest.cjs +5 -1
- package/src/lib/utils/hooks/useUserUpdateRequest/useUserUpdateRequest.js +5 -1
- 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/SendBalanceView.cjs +19 -3
- package/src/lib/views/SendBalanceView/SendBalanceView.js +19 -3
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.cjs +4 -16
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.d.ts +2 -0
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.js +5 -17
- 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/DynamicWidget.cjs +2 -2
- package/src/lib/widgets/DynamicWidget/DynamicWidget.js +3 -3
- package/src/lib/widgets/DynamicWidget/components/DynamicNav/DynamicNav.cjs +36 -1
- package/src/lib/widgets/DynamicWidget/components/DynamicNav/DynamicNav.js +36 -1
- package/src/lib/widgets/DynamicWidget/components/DynamicUserProfile/DynamicUserProfile.cjs +2 -2
- package/src/lib/widgets/DynamicWidget/components/DynamicUserProfile/DynamicUserProfile.js +2 -2
- 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/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
|
@@ -2,7 +2,7 @@ import { useInternalDynamicContext } from '../../../context/DynamicContext/useIn
|
|
|
2
2
|
import { useViewContext } from '../../../context/ViewContext/ViewContext.js';
|
|
3
3
|
|
|
4
4
|
const useHandleWalletsToConnect = () => {
|
|
5
|
-
const { walletsToConnectByChain, setWalletsToConnectByChain, setShowAuthFlow, setIsFullyConnected, isFullyConnected, } = useInternalDynamicContext();
|
|
5
|
+
const { walletsToConnectByChain, setWalletsToConnectByChain, setShowAuthFlow, setIsFullyConnected, selectedWalletConnector, isFullyConnected, } = useInternalDynamicContext();
|
|
6
6
|
const { setView, goToInitialView } = useViewContext();
|
|
7
7
|
const handleWalletsToConnect = () => {
|
|
8
8
|
if (!walletsToConnectByChain) {
|
|
@@ -15,6 +15,20 @@ const useHandleWalletsToConnect = () => {
|
|
|
15
15
|
setShowAuthFlow(false);
|
|
16
16
|
return goToInitialView();
|
|
17
17
|
}
|
|
18
|
+
if (!selectedWalletConnector || !selectedWalletConnector.connectedChain) {
|
|
19
|
+
setShowAuthFlow(false);
|
|
20
|
+
return goToInitialView();
|
|
21
|
+
}
|
|
22
|
+
// Assuming based on the logic above that we have at least one more chain/wallet to connect
|
|
23
|
+
// If the current connected wallet is already connected to the bridge,
|
|
24
|
+
// we can go directly to bridge-next-wallet-connection since we know there is a different chain to connect
|
|
25
|
+
const walletChainsToConnect = walletsToConnectByChain
|
|
26
|
+
.filter((wallet) => wallet.numberOfWallets > 0)
|
|
27
|
+
.map((wallet) => wallet.chain.toString());
|
|
28
|
+
if (!walletChainsToConnect.includes(selectedWalletConnector.connectedChain)) {
|
|
29
|
+
setView('bridge-next-wallet-connection');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
18
32
|
const [firstWallet, ...restOfTheWallets] = walletsToConnectByChain;
|
|
19
33
|
if (firstWallet.numberOfWallets > 1) {
|
|
20
34
|
const updatedWallets = [
|
|
@@ -20,11 +20,15 @@ require('../../../shared/consts/index.cjs');
|
|
|
20
20
|
var primaryWalletIdValidator = require('../useWalletConnectors/utils/primaryWalletIdValidator/primaryWalletIdValidator.cjs');
|
|
21
21
|
require('@dynamic-labs/multi-wallet');
|
|
22
22
|
|
|
23
|
-
const usePrimaryWalletId = () => {
|
|
24
|
-
const [primaryWalletId, setPrimaryWalletIdState,
|
|
23
|
+
const usePrimaryWalletId = (internalEvents) => {
|
|
24
|
+
const [primaryWalletId, setPrimaryWalletIdState, clearPrimaryWalletIdStorage,] = useLocalStorage.useLocalStorage(localStorage.PRIMARY_WALLET_ID, undefined, primaryWalletIdValidator.primaryWalletIdValidator);
|
|
25
25
|
const setPrimaryWalletId = React.useCallback((walletId) => {
|
|
26
26
|
setPrimaryWalletIdState(walletId);
|
|
27
27
|
}, [setPrimaryWalletIdState]);
|
|
28
|
+
const clearPrimaryWalletId = () => {
|
|
29
|
+
clearPrimaryWalletIdStorage();
|
|
30
|
+
internalEvents.emit('clearPrimaryWallet');
|
|
31
|
+
};
|
|
28
32
|
return {
|
|
29
33
|
clearPrimaryWalletId,
|
|
30
34
|
primaryWalletId,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { InternalEventEmitter } from '../../../context/DynamicContext/internalEvents';
|
|
2
|
+
export declare const usePrimaryWalletId: (internalEvents: InternalEventEmitter) => {
|
|
2
3
|
clearPrimaryWalletId: () => void;
|
|
3
4
|
primaryWalletId: string | undefined;
|
|
4
5
|
setPrimaryWalletId: (walletId: string) => void;
|
|
@@ -16,11 +16,15 @@ import '../../../shared/consts/index.js';
|
|
|
16
16
|
import { primaryWalletIdValidator } from '../useWalletConnectors/utils/primaryWalletIdValidator/primaryWalletIdValidator.js';
|
|
17
17
|
import '@dynamic-labs/multi-wallet';
|
|
18
18
|
|
|
19
|
-
const usePrimaryWalletId = () => {
|
|
20
|
-
const [primaryWalletId, setPrimaryWalletIdState,
|
|
19
|
+
const usePrimaryWalletId = (internalEvents) => {
|
|
20
|
+
const [primaryWalletId, setPrimaryWalletIdState, clearPrimaryWalletIdStorage,] = useLocalStorage(PRIMARY_WALLET_ID, undefined, primaryWalletIdValidator);
|
|
21
21
|
const setPrimaryWalletId = useCallback((walletId) => {
|
|
22
22
|
setPrimaryWalletIdState(walletId);
|
|
23
23
|
}, [setPrimaryWalletIdState]);
|
|
24
|
+
const clearPrimaryWalletId = () => {
|
|
25
|
+
clearPrimaryWalletIdStorage();
|
|
26
|
+
internalEvents.emit('clearPrimaryWallet');
|
|
27
|
+
};
|
|
24
28
|
return {
|
|
25
29
|
clearPrimaryWalletId,
|
|
26
30
|
primaryWalletId,
|
|
@@ -15,8 +15,9 @@ require('react/jsx-runtime');
|
|
|
15
15
|
require('../../../context/ViewContext/ViewContext.cjs');
|
|
16
16
|
require('@dynamic-labs/wallet-book');
|
|
17
17
|
require('@dynamic-labs/utils');
|
|
18
|
+
var localStorage$1 = require('../../constants/localStorage.cjs');
|
|
18
19
|
require('../../constants/colors.cjs');
|
|
19
|
-
require('../../../shared/utils/classes/storage/localStorage.cjs');
|
|
20
|
+
var localStorage = require('../../../shared/utils/classes/storage/localStorage.cjs');
|
|
20
21
|
require('viem');
|
|
21
22
|
require('../../../shared/consts/index.cjs');
|
|
22
23
|
require('@dynamic-labs/multi-wallet');
|
|
@@ -28,6 +29,7 @@ var stringifyURIQuery = require('../../functions/stringifyURIQuery/stringifyURIQ
|
|
|
28
29
|
var digestSHA256 = require('../../functions/digestSHA256/digestSHA256.cjs');
|
|
29
30
|
var encodeBase64URL = require('../../functions/encodeBase64URL/encodeBase64URL.cjs');
|
|
30
31
|
var getRedirectURIOrigin = require('../../functions/getRedirectURIOrigin/getRedirectURIOrigin.cjs');
|
|
32
|
+
var getProviderByType = require('../../functions/getProviderByType/getProviderByType.cjs');
|
|
31
33
|
|
|
32
34
|
const socialProviders = [
|
|
33
35
|
'discord',
|
|
@@ -41,13 +43,17 @@ const socialProviders = [
|
|
|
41
43
|
// pkce params are only required for twitter and break if added for other providers, like google
|
|
42
44
|
// so we should only add provider that support pkce to this list
|
|
43
45
|
const providersRequiringPkce = ['twitter', 'github'];
|
|
44
|
-
const
|
|
46
|
+
const providersWithoutWindowOpenerRefence = ['twitter'];
|
|
47
|
+
const useSocialAccounts = ({ sessionTimeout } = {
|
|
48
|
+
sessionTimeout: 10000,
|
|
49
|
+
}) => {
|
|
45
50
|
var _a;
|
|
46
51
|
const { environmentId, user, projectSettings, onboardingOnlyJwt } = useInternalDynamicContext.useInternalDynamicContext();
|
|
47
52
|
const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback.useUpdateUserProfileByJWTCallback();
|
|
48
53
|
const [isProcessing, setIsProcessing] = React.useState(false);
|
|
49
54
|
const [error, setError] = React.useState();
|
|
50
55
|
const providersWaitingOauthMessages = React.useRef({});
|
|
56
|
+
const authWindowInterval = React.useRef();
|
|
51
57
|
const userJwt = (_a = getAuthToken.getAuthToken()) !== null && _a !== void 0 ? _a : onboardingOnlyJwt;
|
|
52
58
|
const oauthProviders = index.getEnabledOAuthProviders(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
|
|
53
59
|
const verifiedOAuthCredentialsMap = React.useMemo(() => {
|
|
@@ -116,6 +122,7 @@ const useSocialAccounts = () => {
|
|
|
116
122
|
};
|
|
117
123
|
const linkSocialAccount = (provider) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
118
124
|
var _b;
|
|
125
|
+
clearInterval(authWindowInterval.current);
|
|
119
126
|
setError(undefined);
|
|
120
127
|
setIsProcessing(true);
|
|
121
128
|
// invalid linking request
|
|
@@ -124,25 +131,66 @@ const useSocialAccounts = () => {
|
|
|
124
131
|
}
|
|
125
132
|
const state = randomString.randomString(8);
|
|
126
133
|
const verifier = randomString.randomString(43);
|
|
134
|
+
const clearListeners = () => {
|
|
135
|
+
removeOAuthIFrame();
|
|
136
|
+
window.removeEventListener('message', handleAuthWindowMessage);
|
|
137
|
+
providersWaitingOauthMessages.current = Object.assign(Object.assign({}, providersWaitingOauthMessages.current), { [provider]: false });
|
|
138
|
+
};
|
|
127
139
|
const handleAuthWindowMessage = (event) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
140
|
+
var _c, _d;
|
|
128
141
|
const message = event.data;
|
|
142
|
+
const apiProvider = getProviderByType.getProviderByType((_c = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) !== null && _c !== void 0 ? _c : [], provider);
|
|
143
|
+
if (!(apiProvider === null || apiProvider === void 0 ? void 0 : apiProvider.redirectUrl)) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
let expectedOrigin = '';
|
|
147
|
+
try {
|
|
148
|
+
const redirectUri = new URL(apiProvider.redirectUrl);
|
|
149
|
+
expectedOrigin = redirectUri.origin;
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
logger.logger.error('Failed to parse social provider redirect url', {
|
|
153
|
+
error: e,
|
|
154
|
+
});
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if ((message === null || message === void 0 ? void 0 : message.type) === 'origin_check' && authWindow) {
|
|
158
|
+
logger.logger.debug('Origin check message received. Sending response now.', {
|
|
159
|
+
data: message,
|
|
160
|
+
expectedOrigin,
|
|
161
|
+
});
|
|
162
|
+
authWindow.postMessage('origin_check_response', expectedOrigin);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
129
165
|
const isAuthorizationMessage = (message === null || message === void 0 ? void 0 : message.type) === 'authorization_response';
|
|
130
166
|
if (isAuthorizationMessage) {
|
|
131
167
|
logger.logger.debug('Message received', { data: message });
|
|
132
168
|
}
|
|
133
|
-
const
|
|
169
|
+
const isExpectedOrigin = event.origin === expectedOrigin;
|
|
170
|
+
const isValidMessage = isAuthorizationMessage &&
|
|
171
|
+
(message === null || message === void 0 ? void 0 : message.provider) === provider &&
|
|
172
|
+
isExpectedOrigin;
|
|
134
173
|
// don't process imvalid messages for provider
|
|
135
174
|
if (!isValidMessage) {
|
|
136
175
|
return;
|
|
137
176
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
177
|
+
setIsProcessing(true);
|
|
178
|
+
if (!((_d = providersWaitingOauthMessages.current) === null || _d === void 0 ? void 0 : _d[provider])) {
|
|
179
|
+
handleError(`Linking ${provider} account session timeout.`);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
clearListeners();
|
|
183
|
+
const { code, error, state: authState } = message;
|
|
142
184
|
if (error && error !== 'undefined') {
|
|
143
185
|
handleError(`Failed to link ${provider} social account: ${error}`);
|
|
144
186
|
return;
|
|
145
187
|
}
|
|
188
|
+
// check that the state we receive from message is the same state we calculated earlier
|
|
189
|
+
// this could be an attack
|
|
190
|
+
if (state !== authState) {
|
|
191
|
+
handleError(`Failed to link ${provider} social account: invalid auth state`);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
146
194
|
if (!code) {
|
|
147
195
|
handleError(`Failed to link ${provider} social account: no authorization code`);
|
|
148
196
|
return;
|
|
@@ -169,24 +217,52 @@ const useSocialAccounts = () => {
|
|
|
169
217
|
// different origins (our api redirect page and the app where the sdk is running)
|
|
170
218
|
const oauthIFrameUrl = `${getRedirectURIOrigin.getRedirectURIOrigin(loginUrl)}/sdkoauth`;
|
|
171
219
|
addOAuthIFrame(oauthIFrameUrl);
|
|
172
|
-
|
|
220
|
+
if (!((_b = providersWaitingOauthMessages.current) === null || _b === void 0 ? void 0 : _b[provider])) {
|
|
221
|
+
window.addEventListener('message', handleAuthWindowMessage);
|
|
222
|
+
providersWaitingOauthMessages.current = Object.assign(Object.assign({}, providersWaitingOauthMessages.current), { [provider]: true });
|
|
223
|
+
}
|
|
224
|
+
// add state param for all providers
|
|
225
|
+
const stateParam = stringifyURIQuery.stringifyURIQuery({
|
|
226
|
+
state,
|
|
227
|
+
});
|
|
228
|
+
let oauthLoginUrl = `${loginUrl}&${stateParam}`;
|
|
229
|
+
// only add pkce params for providers that support/require it
|
|
173
230
|
if (providersRequiringPkce.includes(provider)) {
|
|
174
231
|
const digest = yield digestSHA256.digestSHA256(verifier);
|
|
175
232
|
const pkceParams = stringifyURIQuery.stringifyURIQuery({
|
|
176
233
|
code_challenge: encodeBase64URL.encodeBase64URL(digest),
|
|
177
234
|
code_challenge_method: 'S256',
|
|
178
|
-
state: state,
|
|
179
235
|
});
|
|
180
|
-
oauthLoginUrl = `${
|
|
236
|
+
oauthLoginUrl = `${oauthLoginUrl}&${pkceParams}`;
|
|
181
237
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
238
|
+
const authWindow = window.open(oauthLoginUrl, '_blank', 'width=500,height=600');
|
|
239
|
+
if (!providersWithoutWindowOpenerRefence.includes(provider)) {
|
|
240
|
+
// For provider that support window.opener, we need to clear all states/listeners when the window is closed
|
|
241
|
+
authWindowInterval.current = setInterval(() => {
|
|
242
|
+
if (!(authWindow === null || authWindow === void 0 ? void 0 : authWindow.closed)) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
clearInterval(authWindowInterval.current);
|
|
246
|
+
setIsProcessing(false);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
// For provider that don't support window.opener, we need to use a timeout to try to detect when the
|
|
251
|
+
// window is closed
|
|
252
|
+
authWindowInterval.current = setInterval(() => {
|
|
253
|
+
var _a;
|
|
254
|
+
// user didn't complete oauth
|
|
255
|
+
if ((_a = providersWaitingOauthMessages.current) === null || _a === void 0 ? void 0 : _a[provider]) {
|
|
256
|
+
clearListeners();
|
|
257
|
+
handleError(`Linking ${provider} account window timeout.`);
|
|
258
|
+
}
|
|
259
|
+
setIsProcessing(false);
|
|
260
|
+
clearInterval(authWindowInterval.current);
|
|
261
|
+
}, sessionTimeout);
|
|
185
262
|
}
|
|
186
|
-
window.open(oauthLoginUrl, '_blank', 'width=500,height=600');
|
|
187
263
|
});
|
|
188
264
|
const unlinkSocialAccount = (provider) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
189
|
-
var
|
|
265
|
+
var _e;
|
|
190
266
|
setError(undefined);
|
|
191
267
|
setIsProcessing(true);
|
|
192
268
|
if (!checkValidProvider(provider)) {
|
|
@@ -198,9 +274,11 @@ const useSocialAccounts = () => {
|
|
|
198
274
|
return;
|
|
199
275
|
}
|
|
200
276
|
try {
|
|
277
|
+
const primaryWalletId = localStorage.LocalStorage.getFromLS(localStorage$1.PRIMARY_WALLET_ID);
|
|
201
278
|
const jwt = yield api.unlinkOAuth({
|
|
202
279
|
environmentId,
|
|
203
|
-
|
|
280
|
+
primaryWalletId,
|
|
281
|
+
verifiedCrentialId: (_e = verifiedCredential.id) !== null && _e !== void 0 ? _e : '',
|
|
204
282
|
}, String(userJwt));
|
|
205
283
|
if (!jwt) {
|
|
206
284
|
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 {};
|
|
@@ -11,8 +11,9 @@ import 'react/jsx-runtime';
|
|
|
11
11
|
import '../../../context/ViewContext/ViewContext.js';
|
|
12
12
|
import '@dynamic-labs/wallet-book';
|
|
13
13
|
import '@dynamic-labs/utils';
|
|
14
|
+
import { PRIMARY_WALLET_ID } from '../../constants/localStorage.js';
|
|
14
15
|
import '../../constants/colors.js';
|
|
15
|
-
import '../../../shared/utils/classes/storage/localStorage.js';
|
|
16
|
+
import { LocalStorage } from '../../../shared/utils/classes/storage/localStorage.js';
|
|
16
17
|
import 'viem';
|
|
17
18
|
import '../../../shared/consts/index.js';
|
|
18
19
|
import '@dynamic-labs/multi-wallet';
|
|
@@ -24,6 +25,7 @@ import { stringifyURIQuery } from '../../functions/stringifyURIQuery/stringifyUR
|
|
|
24
25
|
import { digestSHA256 } from '../../functions/digestSHA256/digestSHA256.js';
|
|
25
26
|
import { encodeBase64URL } from '../../functions/encodeBase64URL/encodeBase64URL.js';
|
|
26
27
|
import { getRedirectURIOrigin } from '../../functions/getRedirectURIOrigin/getRedirectURIOrigin.js';
|
|
28
|
+
import { getProviderByType } from '../../functions/getProviderByType/getProviderByType.js';
|
|
27
29
|
|
|
28
30
|
const socialProviders = [
|
|
29
31
|
'discord',
|
|
@@ -37,13 +39,17 @@ const socialProviders = [
|
|
|
37
39
|
// pkce params are only required for twitter and break if added for other providers, like google
|
|
38
40
|
// so we should only add provider that support pkce to this list
|
|
39
41
|
const providersRequiringPkce = ['twitter', 'github'];
|
|
40
|
-
const
|
|
42
|
+
const providersWithoutWindowOpenerRefence = ['twitter'];
|
|
43
|
+
const useSocialAccounts = ({ sessionTimeout } = {
|
|
44
|
+
sessionTimeout: 10000,
|
|
45
|
+
}) => {
|
|
41
46
|
var _a;
|
|
42
47
|
const { environmentId, user, projectSettings, onboardingOnlyJwt } = useInternalDynamicContext();
|
|
43
48
|
const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback();
|
|
44
49
|
const [isProcessing, setIsProcessing] = useState(false);
|
|
45
50
|
const [error, setError] = useState();
|
|
46
51
|
const providersWaitingOauthMessages = useRef({});
|
|
52
|
+
const authWindowInterval = useRef();
|
|
47
53
|
const userJwt = (_a = getAuthToken()) !== null && _a !== void 0 ? _a : onboardingOnlyJwt;
|
|
48
54
|
const oauthProviders = getEnabledOAuthProviders(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
|
|
49
55
|
const verifiedOAuthCredentialsMap = useMemo(() => {
|
|
@@ -112,6 +118,7 @@ const useSocialAccounts = () => {
|
|
|
112
118
|
};
|
|
113
119
|
const linkSocialAccount = (provider) => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
120
|
var _b;
|
|
121
|
+
clearInterval(authWindowInterval.current);
|
|
115
122
|
setError(undefined);
|
|
116
123
|
setIsProcessing(true);
|
|
117
124
|
// invalid linking request
|
|
@@ -120,25 +127,66 @@ const useSocialAccounts = () => {
|
|
|
120
127
|
}
|
|
121
128
|
const state = randomString(8);
|
|
122
129
|
const verifier = randomString(43);
|
|
130
|
+
const clearListeners = () => {
|
|
131
|
+
removeOAuthIFrame();
|
|
132
|
+
window.removeEventListener('message', handleAuthWindowMessage);
|
|
133
|
+
providersWaitingOauthMessages.current = Object.assign(Object.assign({}, providersWaitingOauthMessages.current), { [provider]: false });
|
|
134
|
+
};
|
|
123
135
|
const handleAuthWindowMessage = (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
136
|
+
var _c, _d;
|
|
124
137
|
const message = event.data;
|
|
138
|
+
const apiProvider = getProviderByType((_c = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) !== null && _c !== void 0 ? _c : [], provider);
|
|
139
|
+
if (!(apiProvider === null || apiProvider === void 0 ? void 0 : apiProvider.redirectUrl)) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
let expectedOrigin = '';
|
|
143
|
+
try {
|
|
144
|
+
const redirectUri = new URL(apiProvider.redirectUrl);
|
|
145
|
+
expectedOrigin = redirectUri.origin;
|
|
146
|
+
}
|
|
147
|
+
catch (e) {
|
|
148
|
+
logger.error('Failed to parse social provider redirect url', {
|
|
149
|
+
error: e,
|
|
150
|
+
});
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if ((message === null || message === void 0 ? void 0 : message.type) === 'origin_check' && authWindow) {
|
|
154
|
+
logger.debug('Origin check message received. Sending response now.', {
|
|
155
|
+
data: message,
|
|
156
|
+
expectedOrigin,
|
|
157
|
+
});
|
|
158
|
+
authWindow.postMessage('origin_check_response', expectedOrigin);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
125
161
|
const isAuthorizationMessage = (message === null || message === void 0 ? void 0 : message.type) === 'authorization_response';
|
|
126
162
|
if (isAuthorizationMessage) {
|
|
127
163
|
logger.debug('Message received', { data: message });
|
|
128
164
|
}
|
|
129
|
-
const
|
|
165
|
+
const isExpectedOrigin = event.origin === expectedOrigin;
|
|
166
|
+
const isValidMessage = isAuthorizationMessage &&
|
|
167
|
+
(message === null || message === void 0 ? void 0 : message.provider) === provider &&
|
|
168
|
+
isExpectedOrigin;
|
|
130
169
|
// don't process imvalid messages for provider
|
|
131
170
|
if (!isValidMessage) {
|
|
132
171
|
return;
|
|
133
172
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
173
|
+
setIsProcessing(true);
|
|
174
|
+
if (!((_d = providersWaitingOauthMessages.current) === null || _d === void 0 ? void 0 : _d[provider])) {
|
|
175
|
+
handleError(`Linking ${provider} account session timeout.`);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
clearListeners();
|
|
179
|
+
const { code, error, state: authState } = message;
|
|
138
180
|
if (error && error !== 'undefined') {
|
|
139
181
|
handleError(`Failed to link ${provider} social account: ${error}`);
|
|
140
182
|
return;
|
|
141
183
|
}
|
|
184
|
+
// check that the state we receive from message is the same state we calculated earlier
|
|
185
|
+
// this could be an attack
|
|
186
|
+
if (state !== authState) {
|
|
187
|
+
handleError(`Failed to link ${provider} social account: invalid auth state`);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
142
190
|
if (!code) {
|
|
143
191
|
handleError(`Failed to link ${provider} social account: no authorization code`);
|
|
144
192
|
return;
|
|
@@ -165,24 +213,52 @@ const useSocialAccounts = () => {
|
|
|
165
213
|
// different origins (our api redirect page and the app where the sdk is running)
|
|
166
214
|
const oauthIFrameUrl = `${getRedirectURIOrigin(loginUrl)}/sdkoauth`;
|
|
167
215
|
addOAuthIFrame(oauthIFrameUrl);
|
|
168
|
-
|
|
216
|
+
if (!((_b = providersWaitingOauthMessages.current) === null || _b === void 0 ? void 0 : _b[provider])) {
|
|
217
|
+
window.addEventListener('message', handleAuthWindowMessage);
|
|
218
|
+
providersWaitingOauthMessages.current = Object.assign(Object.assign({}, providersWaitingOauthMessages.current), { [provider]: true });
|
|
219
|
+
}
|
|
220
|
+
// add state param for all providers
|
|
221
|
+
const stateParam = stringifyURIQuery({
|
|
222
|
+
state,
|
|
223
|
+
});
|
|
224
|
+
let oauthLoginUrl = `${loginUrl}&${stateParam}`;
|
|
225
|
+
// only add pkce params for providers that support/require it
|
|
169
226
|
if (providersRequiringPkce.includes(provider)) {
|
|
170
227
|
const digest = yield digestSHA256(verifier);
|
|
171
228
|
const pkceParams = stringifyURIQuery({
|
|
172
229
|
code_challenge: encodeBase64URL(digest),
|
|
173
230
|
code_challenge_method: 'S256',
|
|
174
|
-
state: state,
|
|
175
231
|
});
|
|
176
|
-
oauthLoginUrl = `${
|
|
232
|
+
oauthLoginUrl = `${oauthLoginUrl}&${pkceParams}`;
|
|
177
233
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
234
|
+
const authWindow = window.open(oauthLoginUrl, '_blank', 'width=500,height=600');
|
|
235
|
+
if (!providersWithoutWindowOpenerRefence.includes(provider)) {
|
|
236
|
+
// For provider that support window.opener, we need to clear all states/listeners when the window is closed
|
|
237
|
+
authWindowInterval.current = setInterval(() => {
|
|
238
|
+
if (!(authWindow === null || authWindow === void 0 ? void 0 : authWindow.closed)) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
clearInterval(authWindowInterval.current);
|
|
242
|
+
setIsProcessing(false);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
// For provider that don't support window.opener, we need to use a timeout to try to detect when the
|
|
247
|
+
// window is closed
|
|
248
|
+
authWindowInterval.current = setInterval(() => {
|
|
249
|
+
var _a;
|
|
250
|
+
// user didn't complete oauth
|
|
251
|
+
if ((_a = providersWaitingOauthMessages.current) === null || _a === void 0 ? void 0 : _a[provider]) {
|
|
252
|
+
clearListeners();
|
|
253
|
+
handleError(`Linking ${provider} account window timeout.`);
|
|
254
|
+
}
|
|
255
|
+
setIsProcessing(false);
|
|
256
|
+
clearInterval(authWindowInterval.current);
|
|
257
|
+
}, sessionTimeout);
|
|
181
258
|
}
|
|
182
|
-
window.open(oauthLoginUrl, '_blank', 'width=500,height=600');
|
|
183
259
|
});
|
|
184
260
|
const unlinkSocialAccount = (provider) => __awaiter(void 0, void 0, void 0, function* () {
|
|
185
|
-
var
|
|
261
|
+
var _e;
|
|
186
262
|
setError(undefined);
|
|
187
263
|
setIsProcessing(true);
|
|
188
264
|
if (!checkValidProvider(provider)) {
|
|
@@ -194,9 +270,11 @@ const useSocialAccounts = () => {
|
|
|
194
270
|
return;
|
|
195
271
|
}
|
|
196
272
|
try {
|
|
273
|
+
const primaryWalletId = LocalStorage.getFromLS(PRIMARY_WALLET_ID);
|
|
197
274
|
const jwt = yield unlinkOAuth({
|
|
198
275
|
environmentId,
|
|
199
|
-
|
|
276
|
+
primaryWalletId,
|
|
277
|
+
verifiedCrentialId: (_e = verifiedCredential.id) !== null && _e !== void 0 ? _e : '',
|
|
200
278
|
}, String(userJwt));
|
|
201
279
|
if (!jwt) {
|
|
202
280
|
handleError(`Failed to unlink social account: ${provider} | ${verifiedCredential.id}`);
|
|
@@ -40,6 +40,7 @@ const userFieldsSchema = yup.object().shape({
|
|
|
40
40
|
kdaWallet: yup.string(),
|
|
41
41
|
lastName: yup.string(),
|
|
42
42
|
ltcWallet: yup.string(),
|
|
43
|
+
metadata: yup.object(),
|
|
43
44
|
newsletterNotification: yup.boolean(),
|
|
44
45
|
phoneNumber: yup.string(),
|
|
45
46
|
tShirtSize: yup.string(),
|
|
@@ -55,10 +56,13 @@ const useUserUpdateRequestInternal = ({ validationSchemaStripUnknown, }) => {
|
|
|
55
56
|
const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback.useUpdateUserProfileByJWTCallback();
|
|
56
57
|
const updateUser = React.useCallback((userFields, userEnvironmentId) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
57
58
|
var _a, _b, _c;
|
|
59
|
+
// `stripUnknown: true` will automatically strip out any values in the metadata object
|
|
60
|
+
// so we need to pull out the metadata object here and then re-add it after stripping unknown fields
|
|
61
|
+
const { metadata } = userFields;
|
|
58
62
|
const validatedUserFields = yield userFieldsSchema.validate(userFields, {
|
|
59
63
|
stripUnknown: validationSchemaStripUnknown,
|
|
60
64
|
});
|
|
61
|
-
const updateUserProfileResponse = yield api.updateUserProfileFields(jwtToken, userEnvironmentId || environmentId, validatedUserFields);
|
|
65
|
+
const updateUserProfileResponse = yield api.updateUserProfileFields(jwtToken, userEnvironmentId || environmentId, Object.assign(Object.assign({}, validatedUserFields), { metadata }));
|
|
62
66
|
// check if decoded JWT still somehow has missing fields, we can't proceed if it does
|
|
63
67
|
const decodedJwt = decodeJwt.decodeJwt(updateUserProfileResponse.jwt);
|
|
64
68
|
const missingFields = (_a = decodedJwt === null || decodedJwt === void 0 ? void 0 : decodedJwt.missingFields) !== null && _a !== void 0 ? _a : [];
|
|
@@ -36,6 +36,7 @@ const userFieldsSchema = object().shape({
|
|
|
36
36
|
kdaWallet: string(),
|
|
37
37
|
lastName: string(),
|
|
38
38
|
ltcWallet: string(),
|
|
39
|
+
metadata: object(),
|
|
39
40
|
newsletterNotification: boolean(),
|
|
40
41
|
phoneNumber: string(),
|
|
41
42
|
tShirtSize: string(),
|
|
@@ -51,10 +52,13 @@ const useUserUpdateRequestInternal = ({ validationSchemaStripUnknown, }) => {
|
|
|
51
52
|
const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback();
|
|
52
53
|
const updateUser = useCallback((userFields, userEnvironmentId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
54
|
var _a, _b, _c;
|
|
55
|
+
// `stripUnknown: true` will automatically strip out any values in the metadata object
|
|
56
|
+
// so we need to pull out the metadata object here and then re-add it after stripping unknown fields
|
|
57
|
+
const { metadata } = userFields;
|
|
54
58
|
const validatedUserFields = yield userFieldsSchema.validate(userFields, {
|
|
55
59
|
stripUnknown: validationSchemaStripUnknown,
|
|
56
60
|
});
|
|
57
|
-
const updateUserProfileResponse = yield updateUserProfileFields(jwtToken, userEnvironmentId || environmentId, validatedUserFields);
|
|
61
|
+
const updateUserProfileResponse = yield updateUserProfileFields(jwtToken, userEnvironmentId || environmentId, Object.assign(Object.assign({}, validatedUserFields), { metadata }));
|
|
58
62
|
// check if decoded JWT still somehow has missing fields, we can't proceed if it does
|
|
59
63
|
const decodedJwt = decodeJwt(updateUserProfileResponse.jwt);
|
|
60
64
|
const missingFields = (_a = decodedJwt === null || decodedJwt === void 0 ? void 0 : decodedJwt.missingFields) !== null && _a !== void 0 ? _a : [];
|
|
@@ -38,7 +38,7 @@ const useVerifyWallet = ({ consumeNonce, displaySiweStatement, environmentId, pr
|
|
|
38
38
|
const { setExistentAccountData } = AccountExistsContext.useAccountExistsContext();
|
|
39
39
|
const { setView, goToInitialView } = ViewContext.useViewContext();
|
|
40
40
|
const { setErrorMessage, setError } = ErrorContext.useErrorContext();
|
|
41
|
-
const { setUser, multiWalletWidgetState, debugError, multiWallet: multiWalletEnabled, appName, primaryWalletId, setCallback, setShowAuthFlow, setPrimaryWalletId, siweStatement, connectedWallet, authMode, setOnboardingOnlyJwt, authToken, setAuthMode, removeConnectedWalletsInfo, setIsVerificationInProgress, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
41
|
+
const { setUser, multiWalletWidgetState, debugError, multiWallet: multiWalletEnabled, appName, primaryWalletId, setCallback, setShowAuthFlow, setPrimaryWalletId, siweStatement, connectedWallet, authMode, setOnboardingOnlyJwt, authToken, setAuthMode, removeConnectedWalletsInfo, setIsVerificationInProgress, eventsCallbacks, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
42
42
|
// If the user is not already logged it means that we only need to verify
|
|
43
43
|
// We need this boolean for the part of the logic where we already persisted a new authToken,
|
|
44
44
|
// and need to distinguish between logic for verify or linking.
|
|
@@ -68,7 +68,7 @@ const useVerifyWallet = ({ consumeNonce, displaySiweStatement, environmentId, pr
|
|
|
68
68
|
if (Jwt === undefined)
|
|
69
69
|
throw new utils.DynamicError('Could not obtain a valid JWT');
|
|
70
70
|
// TODO DYN-523: add verification here that the JWT is valid with the publicKey
|
|
71
|
-
return Jwt;
|
|
71
|
+
return { Jwt, verifyArgs };
|
|
72
72
|
});
|
|
73
73
|
// Overrides the stored primary wallet id when the
|
|
74
74
|
// user logs in for the first time.
|
|
@@ -143,13 +143,23 @@ const useVerifyWallet = ({ consumeNonce, displaySiweStatement, environmentId, pr
|
|
|
143
143
|
}
|
|
144
144
|
};
|
|
145
145
|
return ({ walletConnector, fetchPublicAddressOpts, publicWalletAddress, captchaToken, oauth, }) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
146
|
+
var _a;
|
|
146
147
|
const walletProvider = getWalletProvider.getWalletProvider(walletConnector);
|
|
147
148
|
try {
|
|
148
149
|
setIsVerificationInProgress(true);
|
|
149
|
-
const Jwt = yield generateJWT(walletConnector, walletProvider, fetchPublicAddressOpts, publicWalletAddress, captchaToken, oauth);
|
|
150
|
+
const { Jwt, verifyArgs } = yield generateJWT(walletConnector, walletProvider, fetchPublicAddressOpts, publicWalletAddress, captchaToken, oauth);
|
|
150
151
|
const decodedJwt = decodeJwt.decodeJwt(Jwt);
|
|
151
152
|
if (decodedJwt === undefined)
|
|
152
153
|
throw new utils.DynamicError('Invalid token!');
|
|
154
|
+
try {
|
|
155
|
+
(_a = eventsCallbacks === null || eventsCallbacks === void 0 ? void 0 : eventsCallbacks.onSignedMessage) === null || _a === void 0 ? void 0 : _a.call(eventsCallbacks, {
|
|
156
|
+
messageToSign: verifyArgs.messageToSign,
|
|
157
|
+
signedMessage: verifyArgs.signedMessage,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
catch (_b) {
|
|
161
|
+
logger.logger.warn('Error calling onSignedMessage callback');
|
|
162
|
+
}
|
|
153
163
|
const user = yield createUserProfile.createUserProfile(decodedJwt);
|
|
154
164
|
const isKycRequired = decodedJwt.missingFields.length;
|
|
155
165
|
setOnboardingOnlyJwt(Jwt);
|
|
@@ -34,7 +34,7 @@ const useVerifyWallet = ({ consumeNonce, displaySiweStatement, environmentId, pr
|
|
|
34
34
|
const { setExistentAccountData } = useAccountExistsContext();
|
|
35
35
|
const { setView, goToInitialView } = useViewContext();
|
|
36
36
|
const { setErrorMessage, setError } = useErrorContext();
|
|
37
|
-
const { setUser, multiWalletWidgetState, debugError, multiWallet: multiWalletEnabled, appName, primaryWalletId, setCallback, setShowAuthFlow, setPrimaryWalletId, siweStatement, connectedWallet, authMode, setOnboardingOnlyJwt, authToken, setAuthMode, removeConnectedWalletsInfo, setIsVerificationInProgress, } = useInternalDynamicContext();
|
|
37
|
+
const { setUser, multiWalletWidgetState, debugError, multiWallet: multiWalletEnabled, appName, primaryWalletId, setCallback, setShowAuthFlow, setPrimaryWalletId, siweStatement, connectedWallet, authMode, setOnboardingOnlyJwt, authToken, setAuthMode, removeConnectedWalletsInfo, setIsVerificationInProgress, eventsCallbacks, } = useInternalDynamicContext();
|
|
38
38
|
// If the user is not already logged it means that we only need to verify
|
|
39
39
|
// We need this boolean for the part of the logic where we already persisted a new authToken,
|
|
40
40
|
// and need to distinguish between logic for verify or linking.
|
|
@@ -64,7 +64,7 @@ const useVerifyWallet = ({ consumeNonce, displaySiweStatement, environmentId, pr
|
|
|
64
64
|
if (Jwt === undefined)
|
|
65
65
|
throw new DynamicError('Could not obtain a valid JWT');
|
|
66
66
|
// TODO DYN-523: add verification here that the JWT is valid with the publicKey
|
|
67
|
-
return Jwt;
|
|
67
|
+
return { Jwt, verifyArgs };
|
|
68
68
|
});
|
|
69
69
|
// Overrides the stored primary wallet id when the
|
|
70
70
|
// user logs in for the first time.
|
|
@@ -139,13 +139,23 @@ const useVerifyWallet = ({ consumeNonce, displaySiweStatement, environmentId, pr
|
|
|
139
139
|
}
|
|
140
140
|
};
|
|
141
141
|
return ({ walletConnector, fetchPublicAddressOpts, publicWalletAddress, captchaToken, oauth, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
142
|
+
var _a;
|
|
142
143
|
const walletProvider = getWalletProvider(walletConnector);
|
|
143
144
|
try {
|
|
144
145
|
setIsVerificationInProgress(true);
|
|
145
|
-
const Jwt = yield generateJWT(walletConnector, walletProvider, fetchPublicAddressOpts, publicWalletAddress, captchaToken, oauth);
|
|
146
|
+
const { Jwt, verifyArgs } = yield generateJWT(walletConnector, walletProvider, fetchPublicAddressOpts, publicWalletAddress, captchaToken, oauth);
|
|
146
147
|
const decodedJwt = decodeJwt(Jwt);
|
|
147
148
|
if (decodedJwt === undefined)
|
|
148
149
|
throw new DynamicError('Invalid token!');
|
|
150
|
+
try {
|
|
151
|
+
(_a = eventsCallbacks === null || eventsCallbacks === void 0 ? void 0 : eventsCallbacks.onSignedMessage) === null || _a === void 0 ? void 0 : _a.call(eventsCallbacks, {
|
|
152
|
+
messageToSign: verifyArgs.messageToSign,
|
|
153
|
+
signedMessage: verifyArgs.signedMessage,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
catch (_b) {
|
|
157
|
+
logger.warn('Error calling onSignedMessage callback');
|
|
158
|
+
}
|
|
149
159
|
const user = yield createUserProfile(decodedJwt);
|
|
150
160
|
const isKycRequired = decodedJwt.missingFields.length;
|
|
151
161
|
setOnboardingOnlyJwt(Jwt);
|