@dynamic-labs/sdk-react-core 0.18.0-RC.11 → 0.18.0-RC.13

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.
Files changed (79) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/package.cjs +2 -2
  3. package/package.js +2 -2
  4. package/package.json +9 -9
  5. package/src/lib/Main.cjs +2 -2
  6. package/src/lib/Main.js +2 -2
  7. package/src/lib/assets/index.d.ts +1 -0
  8. package/src/lib/assets/no-wallet-found.cjs +75 -0
  9. package/src/lib/assets/no-wallet-found.js +51 -0
  10. package/src/lib/components/TosAndPp/TosAndPp.cjs +18 -3
  11. package/src/lib/components/TosAndPp/TosAndPp.d.ts +1 -6
  12. package/src/lib/components/TosAndPp/TosAndPp.js +19 -4
  13. package/src/lib/components/WalletInformationCard/WalletInformationCard.cjs +33 -0
  14. package/src/lib/components/WalletInformationCard/WalletInformationCard.d.ts +11 -0
  15. package/src/lib/components/WalletInformationCard/WalletInformationCard.js +29 -0
  16. package/src/lib/components/WalletInformationCard/index.d.ts +1 -0
  17. package/src/lib/components/index.d.ts +1 -0
  18. package/src/lib/context/DynamicContext/DynamicContext.cjs +10 -7
  19. package/src/lib/context/DynamicContext/DynamicContext.d.ts +8 -2
  20. package/src/lib/context/DynamicContext/DynamicContext.js +10 -7
  21. package/src/lib/context/WalletContext/WalletContext.cjs +4 -2
  22. package/src/lib/context/WalletContext/WalletContext.d.ts +3 -1
  23. package/src/lib/context/WalletContext/WalletContext.js +4 -2
  24. package/src/lib/layout/DynamicAuthLayout/ToSFooter/ToSFooter.cjs +4 -3
  25. package/src/lib/layout/DynamicAuthLayout/ToSFooter/ToSFooter.js +4 -3
  26. package/src/lib/styles/index.shadow.cjs +1 -1
  27. package/src/lib/styles/index.shadow.js +1 -1
  28. package/src/lib/utils/functions/isEmailProviderEnabled/isEmailProviderEnabled.cjs +1 -0
  29. package/src/lib/utils/functions/isEmailProviderEnabled/isEmailProviderEnabled.js +1 -0
  30. package/src/lib/utils/hooks/authenticationHooks/helpers/showPendingConnectView.cjs +1 -1
  31. package/src/lib/utils/hooks/authenticationHooks/helpers/showPendingConnectView.js +1 -1
  32. package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.cjs +5 -5
  33. package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.js +6 -6
  34. package/src/lib/utils/hooks/index.d.ts +1 -0
  35. package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.cjs +9 -2
  36. package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.d.ts +5 -2
  37. package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.js +9 -2
  38. package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.cjs +5 -3
  39. package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js +5 -3
  40. package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.cjs +14 -27
  41. package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.d.ts +1 -3
  42. package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.js +15 -28
  43. package/src/lib/utils/hooks/useConnectWithEmail/index.d.ts +1 -0
  44. package/src/lib/utils/hooks/useConnectWithEmail/useConnectWithEmail.cjs +1 -4
  45. package/src/lib/utils/hooks/useConnectWithEmail/useConnectWithEmail.d.ts +1 -4
  46. package/src/lib/utils/hooks/useConnectWithEmail/useConnectWithEmail.js +1 -4
  47. package/src/lib/utils/hooks/useEmailProvider/index.d.ts +1 -0
  48. package/src/lib/utils/hooks/useEmailProvider/useEmailProvider.cjs +54 -0
  49. package/src/lib/utils/hooks/useEmailProvider/useEmailProvider.d.ts +10 -0
  50. package/src/lib/utils/hooks/useEmailProvider/useEmailProvider.js +50 -0
  51. package/src/lib/utils/hooks/useValidateSession/useValidateSession.cjs +3 -0
  52. package/src/lib/utils/hooks/useValidateSession/useValidateSession.js +3 -0
  53. package/src/lib/utils/hooks/useWalletConnectorEvents/useWalletConnectorEvents.cjs +17 -0
  54. package/src/lib/utils/hooks/useWalletConnectorEvents/useWalletConnectorEvents.d.ts +2 -0
  55. package/src/lib/utils/hooks/useWalletConnectorEvents/useWalletConnectorEvents.js +13 -0
  56. package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.cjs +20 -3
  57. package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.d.ts +3 -2
  58. package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.js +20 -3
  59. package/src/lib/views/BridgeSummaryView/BridgeSummaryView.cjs +8 -8
  60. package/src/lib/views/BridgeSummaryView/BridgeSummaryView.js +8 -8
  61. package/src/lib/views/LoginWithEmailView/components/LoginWithEmailForm/LoginWithEmailForm.cjs +24 -51
  62. package/src/lib/views/LoginWithEmailView/components/LoginWithEmailForm/LoginWithEmailForm.js +24 -51
  63. package/src/lib/views/LoginWithEmailView/components/SocialSignIn/SocialSignIn.cjs +7 -5
  64. package/src/lib/views/LoginWithEmailView/components/SocialSignIn/SocialSignIn.js +7 -5
  65. package/src/lib/views/NetworkNotSupported/NetworkNotSupported.cjs +14 -14
  66. package/src/lib/views/NetworkNotSupported/NetworkNotSupported.js +14 -14
  67. package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.cjs +20 -24
  68. package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.js +21 -25
  69. package/src/lib/views/WalletList/{SearchInstead/SearchInstead.cjs → SearchNotFoundMessage/SearchNotFoundMessage.cjs} +2 -2
  70. package/src/lib/views/WalletList/SearchNotFoundMessage/SearchNotFoundMessage.d.ts +8 -0
  71. package/src/lib/views/WalletList/{SearchInstead/SearchInstead.js → SearchNotFoundMessage/SearchNotFoundMessage.js} +2 -2
  72. package/src/lib/views/WalletList/SearchNotFoundMessage/index.d.ts +1 -0
  73. package/src/lib/views/WalletList/WalletList.cjs +3 -2
  74. package/src/lib/views/WalletList/WalletList.js +3 -2
  75. package/src/lib/widgets/DynamicBridgeWidget/components/DynamicBridgeWalletCardBody/DynamicBridgeWalletCardBody.cjs +27 -8
  76. package/src/lib/widgets/DynamicBridgeWidget/components/DynamicBridgeWalletCardBody/DynamicBridgeWalletCardBody.d.ts +0 -1
  77. package/src/lib/widgets/DynamicBridgeWidget/components/DynamicBridgeWalletCardBody/DynamicBridgeWalletCardBody.js +28 -9
  78. package/src/lib/views/WalletList/SearchInstead/SearchInstead.d.ts +0 -2
  79. package/src/lib/views/WalletList/SearchInstead/index.d.ts +0 -1
@@ -4,12 +4,16 @@ import { isWalletLinked } from '../../../functions/isWalletLinked/isWalletLinked
4
4
  import { useViewContext } from '../../../../context/ViewContext/ViewContext.js';
5
5
  import { useInternalDynamicContext } from '../../../../context/DynamicContext/useInternalDynamicContext.js';
6
6
 
7
- const useSyncPrimaryWallet = ({ computeConnectedStateForWallets, handleLogOut, multiWalletWidgetState, primaryWallet, secondaryWallets, setMultiWalletWidgetState, setPrimaryWallet, setShowWidgetStatePopup, showWidgetStatePopup, canSync = true, }) => {
7
+ const useSyncPrimaryWallet = ({ computeConnectedStateForWallets, connectWalletByAddressAndChain, handleLogOut, multiWalletWidgetState, primaryWallet, secondaryWallets, setMultiWalletWidgetState, setPrimaryWallet, setShowWidgetStatePopup, showWidgetStatePopup, canSync = true, authMode, }) => {
8
8
  const { setShowAuthFlow } = useInternalDynamicContext();
9
9
  const { setView } = useViewContext();
10
10
  const handlePrimaryWalletNotActive = useCallback((connectedAddress) => {
11
11
  if (!primaryWallet)
12
12
  return;
13
+ if (authMode === 'connect-only') {
14
+ connectWalletByAddressAndChain(primaryWallet.connector.name, connectedAddress, primaryWallet.chain);
15
+ return;
16
+ }
13
17
  const connectedWalletIsLinked = isWalletLinked(connectedAddress, [
14
18
  primaryWallet,
15
19
  ...secondaryWallets,
@@ -44,12 +48,14 @@ const useSyncPrimaryWallet = ({ computeConnectedStateForWallets, handleLogOut, m
44
48
  setMultiWalletWidgetState('awaiting_account_switch', 'primary_not_connected');
45
49
  }, [
46
50
  primaryWallet,
51
+ authMode,
47
52
  secondaryWallets,
48
53
  showWidgetStatePopup,
49
- setShowWidgetStatePopup,
50
54
  setMultiWalletWidgetState,
55
+ connectWalletByAddressAndChain,
51
56
  setPrimaryWallet,
52
57
  computeConnectedStateForWallets,
58
+ setShowWidgetStatePopup,
53
59
  ]);
54
60
  useEffect(() => {
55
61
  if (!canSync)
@@ -91,6 +97,7 @@ const useSyncPrimaryWallet = ({ computeConnectedStateForWallets, handleLogOut, m
91
97
  canSync,
92
98
  setView,
93
99
  setShowAuthFlow,
100
+ authMode,
94
101
  ]);
95
102
  };
96
103
 
@@ -11,7 +11,7 @@ var getDynamicLayoutData = require('../../functions/getDynamicLayoutData/getDyna
11
11
 
12
12
  const useAuthLayoutChecks = (walletConnector) => {
13
13
  const { view } = ViewContext.useViewContext();
14
- const { user, privacyPolicyUrl, termsOfServiceUrl, isBridgeFlow } = useInternalDynamicContext.useInternalDynamicContext();
14
+ const { user, customPrivacyPolicy, customTermsOfServices, privacyPolicyUrl, termsOfServiceUrl, isBridgeFlow, } = useInternalDynamicContext.useInternalDynamicContext();
15
15
  const { showQrCodeMessage, showQrCodeImage } = QrCodeContext.useQrCodeContext();
16
16
  const { mockedSDK } = MockContext.useMockContext();
17
17
  const { helpHeaderData } = getDynamicLayoutData.getDynamicLayoutData({ view });
@@ -53,8 +53,10 @@ const useAuthLayoutChecks = (walletConnector) => {
53
53
  view === 'wallet-connect-mobile-wallets-list' ||
54
54
  // Don't show empty footer on login-with-email-or-wallet-full-wallet-list
55
55
  (view === 'login-with-email-or-wallet' &&
56
- termsOfServiceUrl &&
57
- privacyPolicyUrl) ||
56
+ (termsOfServiceUrl ||
57
+ privacyPolicyUrl ||
58
+ customPrivacyPolicy ||
59
+ customTermsOfServices)) ||
58
60
  view === 'login-with-email-or-wallet-full-wallet-list'));
59
61
  const showCloseButton = view !== 'login-with-email-or-wallet-full-wallet-list' &&
60
62
  view !== 'login-with-email-verification';
@@ -7,7 +7,7 @@ import { getDynamicLayoutData } from '../../functions/getDynamicLayoutData/getDy
7
7
 
8
8
  const useAuthLayoutChecks = (walletConnector) => {
9
9
  const { view } = useViewContext();
10
- const { user, privacyPolicyUrl, termsOfServiceUrl, isBridgeFlow } = useInternalDynamicContext();
10
+ const { user, customPrivacyPolicy, customTermsOfServices, privacyPolicyUrl, termsOfServiceUrl, isBridgeFlow, } = useInternalDynamicContext();
11
11
  const { showQrCodeMessage, showQrCodeImage } = useQrCodeContext();
12
12
  const { mockedSDK } = useMockContext();
13
13
  const { helpHeaderData } = getDynamicLayoutData({ view });
@@ -49,8 +49,10 @@ const useAuthLayoutChecks = (walletConnector) => {
49
49
  view === 'wallet-connect-mobile-wallets-list' ||
50
50
  // Don't show empty footer on login-with-email-or-wallet-full-wallet-list
51
51
  (view === 'login-with-email-or-wallet' &&
52
- termsOfServiceUrl &&
53
- privacyPolicyUrl) ||
52
+ (termsOfServiceUrl ||
53
+ privacyPolicyUrl ||
54
+ customPrivacyPolicy ||
55
+ customTermsOfServices)) ||
54
56
  view === 'login-with-email-or-wallet-full-wallet-list'));
55
57
  const showCloseButton = view !== 'login-with-email-or-wallet-full-wallet-list' &&
56
58
  view !== 'login-with-email-verification';
@@ -25,7 +25,6 @@ var shouldManuallyReconnectOnRefresh = require('../../functions/shouldManuallyRe
25
25
 
26
26
  const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingOnConnectOnly, environmentId, primaryWalletId, setPrimaryWalletId, wallets, }) => {
27
27
  const [connectedWalletsInfo, setConnectedWalletsInfo, removeConnectedWalletsInfo,] = useLocalStorage.useLocalStorage(localStorage.CONNECTED_WALLETS_INFO, []);
28
- const [connectedWallet, setConnectedWallet] = React.useState(null);
29
28
  const getNextIdAvailable = React.useCallback((currentWallets) => {
30
29
  const existingIds = currentWallets.map(({ id }) => id);
31
30
  const sortedIds = existingIds
@@ -53,19 +52,23 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
53
52
  };
54
53
  })
55
54
  .filter((wc) => wc !== null), [connectedWalletsInfo, wallets]);
55
+ const connectedWallet = connectedWallets[0] || null;
56
56
  const setConnectedStates = React.useCallback((walletConnector, address, chain) => {
57
- setConnectedWallet({
58
- address,
59
- chain,
60
- connected: true,
61
- connector: walletConnector,
62
- id: 'connect-only-wallet',
63
- });
64
57
  setConnectedWalletsInfo((currentWallets) => {
58
+ const existingWalletIndex = currentWallets.findIndex((currentWallet) => currentWallet.name === walletConnector.name);
65
59
  const exists = currentWallets.some((currentWallet) => currentWallet.walletPublicKey === address);
60
+ // this is done, to make sure we're not adding two wallets with the same address to the array
66
61
  if (exists) {
67
62
  return currentWallets;
68
63
  }
64
+ // when calling this function with a new wallet that has the same wallet connector as
65
+ // an existing one in the array, we intend to replace the existing wallet with the new one.
66
+ if (existingWalletIndex !== -1) {
67
+ const updatedWallets = [...currentWallets];
68
+ updatedWallets[existingWalletIndex] = Object.assign(Object.assign({}, updatedWallets[existingWalletIndex]), { chain, provider: getWalletProvider.getWalletProvider(walletConnector), walletPublicKey: address });
69
+ return updatedWallets;
70
+ }
71
+ // otherwise, add new wallet to connectedWalletsInfo array
69
72
  return [
70
73
  ...currentWallets,
71
74
  {
@@ -91,28 +94,13 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
91
94
  setConnectedStates(walletConnector, address, chain);
92
95
  }
93
96
  else {
94
- setConnectedWallet(null);
97
+ removeConnectedWalletsInfo();
95
98
  }
96
99
  }
97
100
  else {
98
- setConnectedWallet(null);
99
- }
100
- }), [setConnectedStates, wallets]);
101
- React.useEffect(() => {
102
- const shouldUpdateConnectedWalletsState = authMode === 'connect-only' && connectedWalletsInfo.length;
103
- if (shouldUpdateConnectedWalletsState) {
104
- connectedWalletsInfo.forEach(({ name, walletPublicKey, chain }) => {
105
- if (chain) {
106
- connectWalletByAddressAndChain(name, walletPublicKey, chain);
107
- }
108
- });
101
+ removeConnectedWalletsInfo();
109
102
  }
110
- }, [
111
- authMode,
112
- connectWalletByAddressAndChain,
113
- connectedWallets.length,
114
- connectedWalletsInfo,
115
- ]);
103
+ }), [removeConnectedWalletsInfo, setConnectedStates, wallets]);
116
104
  const shouldSkipCreatingVisit = React.useMemo(() => (authMode === 'connect-only' && !enableVisitTrackingOnConnectOnly) ||
117
105
  connectedWallet, [authMode, connectedWallet, enableVisitTrackingOnConnectOnly]);
118
106
  const connectWallet = (walletConnector, fetchPublicAddressOpts) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
@@ -161,7 +149,6 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
161
149
  connectedWalletsInfo,
162
150
  getConnectedWalletById,
163
151
  removeConnectedWalletsInfo,
164
- setConnectedWallet,
165
152
  unlinkConnectedWallet,
166
153
  };
167
154
  };
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { Chain, FetchPublicAddressOpts, WalletConnector } from '@dynamic-labs/wallet-connector-core';
3
2
  import { AuthModeType, Wallet, WalletOption } from '../../../shared';
4
3
  export type ConnectedWalletConnectorType = {
@@ -20,12 +19,11 @@ type Props = {
20
19
  export declare const useConnectWallet: ({ authMode, clearPrimaryWalletId, enableVisitTrackingOnConnectOnly, environmentId, primaryWalletId, setPrimaryWalletId, wallets, }: Props) => {
21
20
  connectWallet: (walletConnector: WalletConnector, fetchPublicAddressOpts?: FetchPublicAddressOpts) => Promise<string>;
22
21
  connectWalletByAddressAndChain: (name: string, address: string, chain: Chain) => Promise<void>;
23
- connectedWallet: Wallet | null;
22
+ connectedWallet: Wallet;
24
23
  connectedWallets: Wallet[];
25
24
  connectedWalletsInfo: [] | ConnectedWalletConnectorType[];
26
25
  getConnectedWalletById: (walletId: string) => Wallet | undefined;
27
26
  removeConnectedWalletsInfo: () => void;
28
- setConnectedWallet: import("react").Dispatch<import("react").SetStateAction<Wallet | null>>;
29
27
  unlinkConnectedWallet: (walletId: string) => void;
30
28
  };
31
29
  export {};
@@ -1,5 +1,5 @@
1
1
  import { __awaiter } from '../../../../../_virtual/_tslib.js';
2
- import { useState, useCallback, useMemo, useEffect } from 'react';
2
+ import { useCallback, useMemo } from 'react';
3
3
  import { getWalletConnectorByName, isSameAddress } from '@dynamic-labs/wallet-connector-core';
4
4
  import '@dynamic-labs/sdk-api';
5
5
  import '../../../shared/logger.js';
@@ -21,7 +21,6 @@ import { shouldManuallyReconnectOnRefresh } from '../../functions/shouldManually
21
21
 
22
22
  const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingOnConnectOnly, environmentId, primaryWalletId, setPrimaryWalletId, wallets, }) => {
23
23
  const [connectedWalletsInfo, setConnectedWalletsInfo, removeConnectedWalletsInfo,] = useLocalStorage(CONNECTED_WALLETS_INFO, []);
24
- const [connectedWallet, setConnectedWallet] = useState(null);
25
24
  const getNextIdAvailable = useCallback((currentWallets) => {
26
25
  const existingIds = currentWallets.map(({ id }) => id);
27
26
  const sortedIds = existingIds
@@ -49,19 +48,23 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
49
48
  };
50
49
  })
51
50
  .filter((wc) => wc !== null), [connectedWalletsInfo, wallets]);
51
+ const connectedWallet = connectedWallets[0] || null;
52
52
  const setConnectedStates = useCallback((walletConnector, address, chain) => {
53
- setConnectedWallet({
54
- address,
55
- chain,
56
- connected: true,
57
- connector: walletConnector,
58
- id: 'connect-only-wallet',
59
- });
60
53
  setConnectedWalletsInfo((currentWallets) => {
54
+ const existingWalletIndex = currentWallets.findIndex((currentWallet) => currentWallet.name === walletConnector.name);
61
55
  const exists = currentWallets.some((currentWallet) => currentWallet.walletPublicKey === address);
56
+ // this is done, to make sure we're not adding two wallets with the same address to the array
62
57
  if (exists) {
63
58
  return currentWallets;
64
59
  }
60
+ // when calling this function with a new wallet that has the same wallet connector as
61
+ // an existing one in the array, we intend to replace the existing wallet with the new one.
62
+ if (existingWalletIndex !== -1) {
63
+ const updatedWallets = [...currentWallets];
64
+ updatedWallets[existingWalletIndex] = Object.assign(Object.assign({}, updatedWallets[existingWalletIndex]), { chain, provider: getWalletProvider(walletConnector), walletPublicKey: address });
65
+ return updatedWallets;
66
+ }
67
+ // otherwise, add new wallet to connectedWalletsInfo array
65
68
  return [
66
69
  ...currentWallets,
67
70
  {
@@ -87,28 +90,13 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
87
90
  setConnectedStates(walletConnector, address, chain);
88
91
  }
89
92
  else {
90
- setConnectedWallet(null);
93
+ removeConnectedWalletsInfo();
91
94
  }
92
95
  }
93
96
  else {
94
- setConnectedWallet(null);
95
- }
96
- }), [setConnectedStates, wallets]);
97
- useEffect(() => {
98
- const shouldUpdateConnectedWalletsState = authMode === 'connect-only' && connectedWalletsInfo.length;
99
- if (shouldUpdateConnectedWalletsState) {
100
- connectedWalletsInfo.forEach(({ name, walletPublicKey, chain }) => {
101
- if (chain) {
102
- connectWalletByAddressAndChain(name, walletPublicKey, chain);
103
- }
104
- });
97
+ removeConnectedWalletsInfo();
105
98
  }
106
- }, [
107
- authMode,
108
- connectWalletByAddressAndChain,
109
- connectedWallets.length,
110
- connectedWalletsInfo,
111
- ]);
99
+ }), [removeConnectedWalletsInfo, setConnectedStates, wallets]);
112
100
  const shouldSkipCreatingVisit = useMemo(() => (authMode === 'connect-only' && !enableVisitTrackingOnConnectOnly) ||
113
101
  connectedWallet, [authMode, connectedWallet, enableVisitTrackingOnConnectOnly]);
114
102
  const connectWallet = (walletConnector, fetchPublicAddressOpts) => __awaiter(void 0, void 0, void 0, function* () {
@@ -157,7 +145,6 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
157
145
  connectedWalletsInfo,
158
146
  getConnectedWalletById,
159
147
  removeConnectedWalletsInfo,
160
- setConnectedWallet,
161
148
  unlinkConnectedWallet,
162
149
  };
163
150
  };
@@ -0,0 +1 @@
1
+ export { useConnectWithEmail } from './useConnectWithEmail';
@@ -20,9 +20,8 @@ var ErrorContext = require('../../../context/ErrorContext/ErrorContext.cjs');
20
20
 
21
21
  const useConnectWithEmail = ({ emailWalletConnector, handleConnect, }) => {
22
22
  const { error } = ErrorContext.useErrorContext();
23
- const [email, setEmail] = React.useState('');
24
23
  const [loading, setLoading] = React.useState(false);
25
- const connectWithEmail = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
24
+ const connectWithEmail = (email) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
26
25
  if (!email || !emailWalletConnector || loading)
27
26
  return;
28
27
  setLoading(true);
@@ -42,9 +41,7 @@ const useConnectWithEmail = ({ emailWalletConnector, handleConnect, }) => {
42
41
  }, [error, loading]);
43
42
  return {
44
43
  connectWithEmail,
45
- email,
46
44
  loading,
47
- setEmail,
48
45
  };
49
46
  };
50
47
 
@@ -1,13 +1,10 @@
1
- /// <reference types="react" />
2
1
  import { IEmailWalletConnector, WalletConnector } from '@dynamic-labs/wallet-connector-core';
3
2
  type ConnectWithEmailProps = {
4
3
  emailWalletConnector: IEmailWalletConnector | undefined;
5
4
  handleConnect: (walletConnector: WalletConnector) => Promise<void>;
6
5
  };
7
6
  export declare const useConnectWithEmail: ({ emailWalletConnector, handleConnect, }: ConnectWithEmailProps) => {
8
- connectWithEmail: () => Promise<void>;
9
- email: string;
7
+ connectWithEmail: (email: string) => Promise<void>;
10
8
  loading: boolean;
11
- setEmail: import("react").Dispatch<import("react").SetStateAction<string>>;
12
9
  };
13
10
  export {};
@@ -16,9 +16,8 @@ import { useErrorContext } from '../../../context/ErrorContext/ErrorContext.js';
16
16
 
17
17
  const useConnectWithEmail = ({ emailWalletConnector, handleConnect, }) => {
18
18
  const { error } = useErrorContext();
19
- const [email, setEmail] = useState('');
20
19
  const [loading, setLoading] = useState(false);
21
- const connectWithEmail = () => __awaiter(void 0, void 0, void 0, function* () {
20
+ const connectWithEmail = (email) => __awaiter(void 0, void 0, void 0, function* () {
22
21
  if (!email || !emailWalletConnector || loading)
23
22
  return;
24
23
  setLoading(true);
@@ -38,9 +37,7 @@ const useConnectWithEmail = ({ emailWalletConnector, handleConnect, }) => {
38
37
  }, [error, loading]);
39
38
  return {
40
39
  connectWithEmail,
41
- email,
42
40
  loading,
43
- setEmail,
44
41
  };
45
42
  };
46
43
 
@@ -0,0 +1 @@
1
+ export { useEmailProvider } from './useEmailProvider';
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('../../../../../_virtual/_tslib.cjs');
6
+ var sdkApi = require('@dynamic-labs/sdk-api');
7
+ var useInternalDynamicContext = require('../../../context/DynamicContext/useInternalDynamicContext.cjs');
8
+ var EmailVerificationContext = require('../../../context/EmailVerificationContext/EmailVerificationContext.cjs');
9
+ var ViewContext = require('../../../context/ViewContext/ViewContext.cjs');
10
+ var useWalletItemActions = require('../useWalletItemActions/useWalletItemActions.cjs');
11
+ var useConnectWithEmail = require('../useConnectWithEmail/useConnectWithEmail.cjs');
12
+ var api = require('../../../data/api.cjs');
13
+
14
+ const useEmailProvider = ({ emailWalletConnector }) => {
15
+ const { projectSettings, environmentId } = useInternalDynamicContext.useInternalDynamicContext();
16
+ const { setEmail: setEmailForVerification, setVerificationUUID } = EmailVerificationContext.useEmailVerificationContext();
17
+ const { setView } = ViewContext.useViewContext();
18
+ const { handleInstalledExtensionClick } = useWalletItemActions.useWalletItemActions();
19
+ const { connectWithEmail, loading: isEmailProviderLoading } = useConnectWithEmail.useConnectWithEmail({
20
+ emailWalletConnector,
21
+ handleConnect: handleInstalledExtensionClick,
22
+ });
23
+ const { providers } = projectSettings || {};
24
+ const isInjectedWalletProviderEnabled = emailWalletConnector !== undefined;
25
+ const isMagicOrBloctoEnabled = isInjectedWalletProviderEnabled &&
26
+ Boolean(providers === null || providers === void 0 ? void 0 : providers.filter((provider) => provider.provider === sdkApi.ProviderEnum.MagicLink ||
27
+ provider.provider === sdkApi.ProviderEnum.Blocto).length);
28
+ const handleEmailOnlyLoginSubmit = (emailInput) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
29
+ const { email, verificationUUID } = yield api.createEmailVerification({
30
+ email: emailInput,
31
+ environmentId,
32
+ });
33
+ setView('login-with-email-verification');
34
+ setEmailForVerification(email);
35
+ setVerificationUUID(verificationUUID);
36
+ });
37
+ const handleMagicLinkOrBloctoSubmit = (emailInput) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
38
+ yield connectWithEmail(emailInput);
39
+ });
40
+ const submitEmail = (emailInput) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
41
+ if (isMagicOrBloctoEnabled) {
42
+ yield handleMagicLinkOrBloctoSubmit(emailInput);
43
+ return;
44
+ }
45
+ yield handleEmailOnlyLoginSubmit(emailInput);
46
+ });
47
+ return {
48
+ handleEmailOnlyLoginSubmit,
49
+ isEmailProviderLoading,
50
+ submitEmail,
51
+ };
52
+ };
53
+
54
+ exports.useEmailProvider = useEmailProvider;
@@ -0,0 +1,10 @@
1
+ import { IEmailWalletConnector } from '@dynamic-labs/wallet-connector-core';
2
+ type Props = {
3
+ emailWalletConnector: IEmailWalletConnector | undefined;
4
+ };
5
+ export declare const useEmailProvider: ({ emailWalletConnector }: Props) => {
6
+ handleEmailOnlyLoginSubmit: (emailInput: string) => Promise<void>;
7
+ isEmailProviderLoading: boolean;
8
+ submitEmail: (emailInput: string) => Promise<void>;
9
+ };
10
+ export {};
@@ -0,0 +1,50 @@
1
+ import { __awaiter } from '../../../../../_virtual/_tslib.js';
2
+ import { ProviderEnum } from '@dynamic-labs/sdk-api';
3
+ import { useInternalDynamicContext } from '../../../context/DynamicContext/useInternalDynamicContext.js';
4
+ import { useEmailVerificationContext } from '../../../context/EmailVerificationContext/EmailVerificationContext.js';
5
+ import { useViewContext } from '../../../context/ViewContext/ViewContext.js';
6
+ import { useWalletItemActions } from '../useWalletItemActions/useWalletItemActions.js';
7
+ import { useConnectWithEmail } from '../useConnectWithEmail/useConnectWithEmail.js';
8
+ import { createEmailVerification } from '../../../data/api.js';
9
+
10
+ const useEmailProvider = ({ emailWalletConnector }) => {
11
+ const { projectSettings, environmentId } = useInternalDynamicContext();
12
+ const { setEmail: setEmailForVerification, setVerificationUUID } = useEmailVerificationContext();
13
+ const { setView } = useViewContext();
14
+ const { handleInstalledExtensionClick } = useWalletItemActions();
15
+ const { connectWithEmail, loading: isEmailProviderLoading } = useConnectWithEmail({
16
+ emailWalletConnector,
17
+ handleConnect: handleInstalledExtensionClick,
18
+ });
19
+ const { providers } = projectSettings || {};
20
+ const isInjectedWalletProviderEnabled = emailWalletConnector !== undefined;
21
+ const isMagicOrBloctoEnabled = isInjectedWalletProviderEnabled &&
22
+ Boolean(providers === null || providers === void 0 ? void 0 : providers.filter((provider) => provider.provider === ProviderEnum.MagicLink ||
23
+ provider.provider === ProviderEnum.Blocto).length);
24
+ const handleEmailOnlyLoginSubmit = (emailInput) => __awaiter(void 0, void 0, void 0, function* () {
25
+ const { email, verificationUUID } = yield createEmailVerification({
26
+ email: emailInput,
27
+ environmentId,
28
+ });
29
+ setView('login-with-email-verification');
30
+ setEmailForVerification(email);
31
+ setVerificationUUID(verificationUUID);
32
+ });
33
+ const handleMagicLinkOrBloctoSubmit = (emailInput) => __awaiter(void 0, void 0, void 0, function* () {
34
+ yield connectWithEmail(emailInput);
35
+ });
36
+ const submitEmail = (emailInput) => __awaiter(void 0, void 0, void 0, function* () {
37
+ if (isMagicOrBloctoEnabled) {
38
+ yield handleMagicLinkOrBloctoSubmit(emailInput);
39
+ return;
40
+ }
41
+ yield handleEmailOnlyLoginSubmit(emailInput);
42
+ });
43
+ return {
44
+ handleEmailOnlyLoginSubmit,
45
+ isEmailProviderLoading,
46
+ submitEmail,
47
+ };
48
+ };
49
+
50
+ export { useEmailProvider };
@@ -40,6 +40,9 @@ const useValidateSession = ({ handleLogOut, user, authToken, walletConnectV1Brid
40
40
  let currentWalletConnectV1Bridge;
41
41
  if (walletConnectors) {
42
42
  for (const connector of walletConnectors) {
43
+ if (!connector.isWalletConnect) {
44
+ continue;
45
+ }
43
46
  const session = yield connector.getSession();
44
47
  const bridge = session && (session === null || session === void 0 ? void 0 : session.bridge);
45
48
  if (bridge) {
@@ -36,6 +36,9 @@ const useValidateSession = ({ handleLogOut, user, authToken, walletConnectV1Brid
36
36
  let currentWalletConnectV1Bridge;
37
37
  if (walletConnectors) {
38
38
  for (const connector of walletConnectors) {
39
+ if (!connector.isWalletConnect) {
40
+ continue;
41
+ }
39
42
  const session = yield connector.getSession();
40
43
  const bridge = session && (session === null || session === void 0 ? void 0 : session.bridge);
41
44
  if (bridge) {
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+
7
+ const useWalletConnectorEvents = (walletConnector, listeners) => {
8
+ React.useEffect(() => {
9
+ if (!walletConnector || !listeners) {
10
+ return;
11
+ }
12
+ walletConnector.setupEventListeners(listeners);
13
+ return () => walletConnector.teardownEventListeners();
14
+ }, [walletConnector, listeners]);
15
+ };
16
+
17
+ exports.useWalletConnectorEvents = useWalletConnectorEvents;
@@ -0,0 +1,2 @@
1
+ import { WalletConnector, WalletEventListeners } from '@dynamic-labs/wallet-connector-core';
2
+ export declare const useWalletConnectorEvents: (walletConnector?: WalletConnector | null, listeners?: Partial<WalletEventListeners>) => void;
@@ -0,0 +1,13 @@
1
+ import { useEffect } from 'react';
2
+
3
+ const useWalletConnectorEvents = (walletConnector, listeners) => {
4
+ useEffect(() => {
5
+ if (!walletConnector || !listeners) {
6
+ return;
7
+ }
8
+ walletConnector.setupEventListeners(listeners);
9
+ return () => walletConnector.teardownEventListeners();
10
+ }, [walletConnector, listeners]);
11
+ };
12
+
13
+ export { useWalletConnectorEvents };
@@ -18,7 +18,7 @@ require('ethers');
18
18
  require('../../../shared/consts/index.cjs');
19
19
 
20
20
  const orderedSecondaryWalletAddresses = (wallets) => wallets.map((wallet) => wallet.address).sort();
21
- const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut, multiWallet, multiWalletWidgetState, primaryWallet, secondaryWallets, selectedWalletConnector, selectedWalletWithAction, setSelectedWalletConnector, setSelectedWalletWithAction, setMultiWalletWidgetState, user, setPrimaryWalletId, connectWalletByAddressAndChain, }) => {
21
+ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut, multiWallet, multiWalletWidgetState, primaryWallet, secondaryWallets, selectedWalletConnector, selectedWalletWithAction, setSelectedWalletConnector, setSelectedWalletWithAction, setMultiWalletWidgetState, user, setPrimaryWalletId, connectWalletByAddressAndChain, authMode, }) => {
22
22
  const [loadingNetwork, setLoadingNetwork] = React.useState(true);
23
23
  const [network, setNetwork] = React.useState(undefined);
24
24
  React.useEffect(() => {
@@ -95,6 +95,10 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
95
95
  onAccountChange: (accounts) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
96
96
  const [newAddress] = accounts;
97
97
  const newWallet = secondaryWallets.find((wallet) => walletConnectorCore.isSameAddress(wallet.address, newAddress, wallet.chain));
98
+ if (authMode === 'connect-only') {
99
+ connectWalletByAddressAndChain(primaryWallet.connector.name, newAddress, primaryWallet.chain);
100
+ return;
101
+ }
98
102
  if (walletConnectorCore.isSameAddress(newAddress, primaryWallet.address, primaryWallet.chain)) {
99
103
  setMultiWalletWidgetState('idle');
100
104
  }
@@ -124,11 +128,17 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
124
128
  yield computeConnectedStateForWallets();
125
129
  }),
126
130
  onChainChange: (chain) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
127
- setNetwork(parseInt(chain));
131
+ if (primaryWallet.chain === 'starknet') {
132
+ setNetwork(chain);
133
+ }
134
+ else {
135
+ setNetwork(parseInt(chain));
136
+ }
128
137
  }),
129
138
  onDisconnect: handleLogOut,
130
139
  });
131
140
  }, [
141
+ authMode,
132
142
  primaryWallet,
133
143
  setMultiWalletWidgetState,
134
144
  multiWallet,
@@ -144,7 +154,12 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
144
154
  ]);
145
155
  const addSecondaryWalletEventListeners = React.useCallback((seen) => {
146
156
  const secondaryListeners = {
147
- onAccountChange: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
157
+ onAccountChange: (accounts) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
158
+ if (authMode === 'connect-only' && secondaryWallets.length) {
159
+ const [newAddress] = accounts;
160
+ connectWalletByAddressAndChain(secondaryWallets[0].connector.name, newAddress, secondaryWallets[0].chain);
161
+ return;
162
+ }
148
163
  if (multiWalletWidgetState === 'awaiting_account_switch') {
149
164
  handleAccountChangeWhenAwaitingAccountSwitch(false, (selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.wallet.address) || '');
150
165
  }
@@ -166,7 +181,9 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
166
181
  wallet.connector.setupEventListeners(secondaryListeners);
167
182
  }
168
183
  }, [
184
+ authMode,
169
185
  computeConnectedStateForWallets,
186
+ connectWalletByAddressAndChain,
170
187
  selectedWalletConnector,
171
188
  selectedWalletWithAction,
172
189
  handleAccountChangeWhenAwaitingAccountSwitch,
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import type { Chain, WalletConnector } from '@dynamic-labs/wallet-connector-core';
3
- import { MultiWalletWidgetState, UserProfile, Wallet, WalletWithAction } from '../../../shared';
3
+ import { AuthModeType, MultiWalletWidgetState, UserProfile, Wallet, WalletWithAction } from '../../../shared';
4
4
  import { MultiWalletWidgetStateSetter } from '../multiWallet';
5
5
  export type UseWalletEventListenersArgs = {
6
6
  computeConnectedStateForWallets(): Promise<void>;
@@ -17,8 +17,9 @@ export type UseWalletEventListenersArgs = {
17
17
  setSelectedWalletConnector(connector: WalletConnector | null): void;
18
18
  setSelectedWalletWithAction(walletWithAction: WalletWithAction | null): void;
19
19
  user: UserProfile | undefined;
20
+ authMode: AuthModeType;
20
21
  };
21
- export declare const useWalletEventListeners: ({ computeConnectedStateForWallets, handleLogOut, multiWallet, multiWalletWidgetState, primaryWallet, secondaryWallets, selectedWalletConnector, selectedWalletWithAction, setSelectedWalletConnector, setSelectedWalletWithAction, setMultiWalletWidgetState, user, setPrimaryWalletId, connectWalletByAddressAndChain, }: UseWalletEventListenersArgs) => {
22
+ export declare const useWalletEventListeners: ({ computeConnectedStateForWallets, handleLogOut, multiWallet, multiWalletWidgetState, primaryWallet, secondaryWallets, selectedWalletConnector, selectedWalletWithAction, setSelectedWalletConnector, setSelectedWalletWithAction, setMultiWalletWidgetState, user, setPrimaryWalletId, connectWalletByAddressAndChain, authMode, }: UseWalletEventListenersArgs) => {
22
23
  loadingNetwork: boolean;
23
24
  network: string | number | undefined;
24
25
  setNetwork: import("react").Dispatch<import("react").SetStateAction<string | number | undefined>>;