@dynamic-labs/sdk-react-core 2.0.6 → 2.0.7

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 (40) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +12 -12
  5. package/src/index.d.ts +1 -1
  6. package/src/lib/context/DynamicContext/hooks/useTieCallbacksToEvents/useTieCallbacksToEvents.cjs +9 -1
  7. package/src/lib/context/DynamicContext/hooks/useTieCallbacksToEvents/useTieCallbacksToEvents.js +9 -1
  8. package/src/lib/context/LoadingContext/LoadingContext.cjs +1 -1
  9. package/src/lib/context/LoadingContext/LoadingContext.js +1 -1
  10. package/src/lib/events/auth.d.ts +25 -0
  11. package/src/lib/events/dynamicEvents.d.ts +8 -31
  12. package/src/lib/events/embeddedWallet.d.ts +14 -0
  13. package/src/lib/events/otp.d.ts +5 -0
  14. package/src/lib/events/passkey.d.ts +5 -0
  15. package/src/lib/events/social.d.ts +3 -0
  16. package/src/lib/events/ui.d.ts +10 -0
  17. package/src/lib/events/wallet.d.ts +7 -0
  18. package/src/lib/layout/DynamicAuthLayout/Header/header.cjs +21 -5
  19. package/src/lib/layout/DynamicAuthLayout/Header/header.js +21 -5
  20. package/src/lib/shared/types/dynamicEventsCallbacks.d.ts +12 -1
  21. package/src/lib/utils/hooks/events/useDynamicEvents/useDynamicEvents.d.ts +2 -2
  22. package/src/lib/utils/hooks/useEmailProvider/useEmailProvider.cjs +27 -14
  23. package/src/lib/utils/hooks/useEmailProvider/useEmailProvider.js +27 -14
  24. package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.cjs +6 -6
  25. package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.js +6 -6
  26. package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.cjs +35 -24
  27. package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.d.ts +1 -1
  28. package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.js +35 -24
  29. package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.cjs +13 -2
  30. package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.js +13 -2
  31. package/src/lib/views/EmailVerification/EmailVerification.cjs +2 -0
  32. package/src/lib/views/EmailVerification/EmailVerification.js +2 -0
  33. package/src/lib/views/EmailWalletOTPVerificationView/EmailWalletOTPVerificationView.cjs +4 -0
  34. package/src/lib/views/EmailWalletOTPVerificationView/EmailWalletOTPVerificationView.js +4 -0
  35. package/src/lib/views/LoginView/sections/PhoneNumberSignInSection/useSubmitPhoneNumber/useSubmitPhoneNumber.cjs +9 -1
  36. package/src/lib/views/LoginView/sections/PhoneNumberSignInSection/useSubmitPhoneNumber/useSubmitPhoneNumber.js +9 -1
  37. package/src/lib/views/SmsVerification/useSmsVerification/useSmsVerification.cjs +5 -2
  38. package/src/lib/views/SmsVerification/useSmsVerification/useSmsVerification.js +5 -2
  39. package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.cjs +1 -1
  40. package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.js +1 -1
package/CHANGELOG.md CHANGED
@@ -1,4 +1,11 @@
1
1
 
2
+ ### [2.0.7](https://github.com/dynamic-labs/DynamicAuth/compare/v2.0.6...v2.0.7) (2024-05-15)
3
+
4
+
5
+ ### Features
6
+
7
+ * add authFailure and authInit events ([#5461](https://github.com/dynamic-labs/DynamicAuth/issues/5461)) ([e02e1ad](https://github.com/dynamic-labs/DynamicAuth/commit/e02e1ad36b378e3b2c609fe5bfb2d37aa6a363e0))
8
+
2
9
  ### [2.0.6](https://github.com/dynamic-labs/DynamicAuth/compare/v2.0.5...v2.0.6) (2024-05-03)
3
10
 
4
11
 
package/package.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var version = "2.0.6";
5
+ var version = "2.0.7";
6
6
  var dependencies = {
7
7
  "@dynamic-labs/sdk-api-core": "0.0.418",
8
8
  "@hcaptcha/react-hcaptcha": "1.4.4",
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
- var version = "2.0.6";
1
+ var version = "2.0.7";
2
2
  var dependencies = {
3
3
  "@dynamic-labs/sdk-api-core": "0.0.418",
4
4
  "@hcaptcha/react-hcaptcha": "1.4.4",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/sdk-react-core",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -17,17 +17,17 @@
17
17
  "react-i18next": "13.5.0",
18
18
  "yup": "0.32.11",
19
19
  "react-international-phone": "4.2.5",
20
- "@dynamic-labs/iconic": "2.0.6",
21
- "@dynamic-labs/logger": "2.0.6",
22
- "@dynamic-labs/multi-wallet": "2.0.6",
23
- "@dynamic-labs/rpc-provider-ethereum": "2.0.6",
24
- "@dynamic-labs/rpc-provider-solana": "2.0.6",
25
- "@dynamic-labs/rpc-providers": "2.0.6",
26
- "@dynamic-labs/types": "2.0.6",
27
- "@dynamic-labs/utils": "2.0.6",
28
- "@dynamic-labs/viem-utils": "2.0.6",
29
- "@dynamic-labs/wallet-book": "2.0.6",
30
- "@dynamic-labs/wallet-connector-core": "2.0.6",
20
+ "@dynamic-labs/iconic": "2.0.7",
21
+ "@dynamic-labs/logger": "2.0.7",
22
+ "@dynamic-labs/multi-wallet": "2.0.7",
23
+ "@dynamic-labs/rpc-provider-ethereum": "2.0.7",
24
+ "@dynamic-labs/rpc-provider-solana": "2.0.7",
25
+ "@dynamic-labs/rpc-providers": "2.0.7",
26
+ "@dynamic-labs/types": "2.0.7",
27
+ "@dynamic-labs/utils": "2.0.7",
28
+ "@dynamic-labs/viem-utils": "2.0.7",
29
+ "@dynamic-labs/wallet-book": "2.0.7",
30
+ "@dynamic-labs/wallet-connector-core": "2.0.7",
31
31
  "eventemitter3": "5.0.1"
32
32
  },
33
33
  "devDependencies": {
package/src/index.d.ts CHANGED
@@ -94,7 +94,7 @@ export {
94
94
  type ViewType, } from './lib/context/ViewContext';
95
95
  export type { NotSupportedError, NoAccessError, ChainalysisError, EmailAlreadyExistsError, UsernameAlreadyExistsError, SocialAccountAlreadyExistsError, WalletNotDeployedError, WalletUsedError, EmailVerificationError, AccountExistsError, InvalidPhoneNumberError, } from '@dynamic-labs/utils';
96
96
  export type { WalletConnector, Chain, } from '@dynamic-labs/wallet-connector-core';
97
- export type { EvmNetwork } from '@dynamic-labs/types';
97
+ export type { EvmNetwork, AuthOption, AuthType } from '@dynamic-labs/types';
98
98
  export { mergeNetworks } from './lib/utils/functions/mergeNetworks';
99
99
  export {
100
100
  /** @deprecated use https://www.npmjs.com/package/classnames */
@@ -27,9 +27,9 @@ require('../../../../locale/locale.cjs');
27
27
  require('../../../AccessDeniedContext/AccessDeniedContext.cjs');
28
28
  require('../../../AccountExistsContext/AccountExistsContext.cjs');
29
29
  require('../../../UserWalletsContext/UserWalletsContext.cjs');
30
+ require('../../../../events/dynamicEvents.cjs');
30
31
  require('../../../VerificationContext/VerificationContext.cjs');
31
32
  require('react-dom');
32
- require('../../../../events/dynamicEvents.cjs');
33
33
  require('../../../WalletContext/WalletContext.cjs');
34
34
  require('../../../ThemeContext/ThemeContext.cjs');
35
35
  require('@dynamic-labs/types');
@@ -114,6 +114,14 @@ const useTieCallbacksToEvents = ({ clientCallbacks, user, setHasLoggedOut, }) =>
114
114
  var _a;
115
115
  (_a = clientCallbacks === null || clientCallbacks === void 0 ? void 0 : clientCallbacks.onLogout) === null || _a === void 0 ? void 0 : _a.call(clientCallbacks, user);
116
116
  });
117
+ useDynamicEvents.useInternalDynamicEvents('authFailure', (data, reason) => {
118
+ var _a;
119
+ (_a = clientCallbacks === null || clientCallbacks === void 0 ? void 0 : clientCallbacks.onAuthFailure) === null || _a === void 0 ? void 0 : _a.call(clientCallbacks, data, reason);
120
+ });
121
+ useDynamicEvents.useInternalDynamicEvents('authInit', (data) => {
122
+ var _a;
123
+ (_a = clientCallbacks === null || clientCallbacks === void 0 ? void 0 : clientCallbacks.onAuthInit) === null || _a === void 0 ? void 0 : _a.call(clientCallbacks, data);
124
+ });
117
125
  };
118
126
 
119
127
  exports.useTieCallbacksToEvents = useTieCallbacksToEvents;
@@ -23,9 +23,9 @@ import '../../../../locale/locale.js';
23
23
  import '../../../AccessDeniedContext/AccessDeniedContext.js';
24
24
  import '../../../AccountExistsContext/AccountExistsContext.js';
25
25
  import '../../../UserWalletsContext/UserWalletsContext.js';
26
+ import '../../../../events/dynamicEvents.js';
26
27
  import '../../../VerificationContext/VerificationContext.js';
27
28
  import 'react-dom';
28
- import '../../../../events/dynamicEvents.js';
29
29
  import '../../../WalletContext/WalletContext.js';
30
30
  import '../../../ThemeContext/ThemeContext.js';
31
31
  import '@dynamic-labs/types';
@@ -110,6 +110,14 @@ const useTieCallbacksToEvents = ({ clientCallbacks, user, setHasLoggedOut, }) =>
110
110
  var _a;
111
111
  (_a = clientCallbacks === null || clientCallbacks === void 0 ? void 0 : clientCallbacks.onLogout) === null || _a === void 0 ? void 0 : _a.call(clientCallbacks, user);
112
112
  });
113
+ useInternalDynamicEvents('authFailure', (data, reason) => {
114
+ var _a;
115
+ (_a = clientCallbacks === null || clientCallbacks === void 0 ? void 0 : clientCallbacks.onAuthFailure) === null || _a === void 0 ? void 0 : _a.call(clientCallbacks, data, reason);
116
+ });
117
+ useInternalDynamicEvents('authInit', (data) => {
118
+ var _a;
119
+ (_a = clientCallbacks === null || clientCallbacks === void 0 ? void 0 : clientCallbacks.onAuthInit) === null || _a === void 0 ? void 0 : _a.call(clientCallbacks, data);
120
+ });
113
121
  };
114
122
 
115
123
  export { useTieCallbacksToEvents };
@@ -27,9 +27,9 @@ require('../../locale/locale.cjs');
27
27
  require('../AccessDeniedContext/AccessDeniedContext.cjs');
28
28
  require('../AccountExistsContext/AccountExistsContext.cjs');
29
29
  require('../UserWalletsContext/UserWalletsContext.cjs');
30
+ require('../../events/dynamicEvents.cjs');
30
31
  require('../VerificationContext/VerificationContext.cjs');
31
32
  require('react-dom');
32
- require('../../events/dynamicEvents.cjs');
33
33
  require('../WalletContext/WalletContext.cjs');
34
34
  require('../ThemeContext/ThemeContext.cjs');
35
35
  require('@dynamic-labs/types');
@@ -23,9 +23,9 @@ import '../../locale/locale.js';
23
23
  import '../AccessDeniedContext/AccessDeniedContext.js';
24
24
  import '../AccountExistsContext/AccountExistsContext.js';
25
25
  import '../UserWalletsContext/UserWalletsContext.js';
26
+ import '../../events/dynamicEvents.js';
26
27
  import '../VerificationContext/VerificationContext.js';
27
28
  import 'react-dom';
28
- import '../../events/dynamicEvents.js';
29
29
  import '../WalletContext/WalletContext.js';
30
30
  import '../ThemeContext/ThemeContext.js';
31
31
  import '@dynamic-labs/types';
@@ -0,0 +1,25 @@
1
+ import { AuthOption, AuthType } from '@dynamic-labs/types';
2
+ /** Payload of auth events that provide insight into which auth method was selected */
3
+ export type AuthEventPayload = {
4
+ [K in AuthType]: {
5
+ type: K;
6
+ option: AuthOption[K];
7
+ };
8
+ }[AuthType];
9
+ export type AuthEvents = {
10
+ /**
11
+ * Informs an auth attempt failed.
12
+ * In general triggered when an error occurs or when user cancels out.
13
+ * For email/sms, specifically happens when users cancels the OTP verification.
14
+ */
15
+ authFailure: (method: AuthEventPayload,
16
+ /** Will be 'user-cancelled' when cancelled, or the error when there is an error */
17
+ reason: 'user-cancelled' | {
18
+ error: unknown;
19
+ }) => void;
20
+ /** Informs an auth attempt initialized, and provides insight into which auth option it is */
21
+ authInit: (method: AuthEventPayload) => void;
22
+ logout: () => void;
23
+ /** This event is used to trigger logout to be called, DO NOT listen to it. Listen to "logout" instead */
24
+ triggerLogout: () => void;
25
+ };
@@ -1,35 +1,12 @@
1
1
  import EventEmitter from 'eventemitter3';
2
- import { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core/models/JwtVerifiedCredential';
3
- import { PhoneData, Wallet } from '../shared';
2
+ import { AuthEvents } from './auth';
3
+ import { EmbeddedWalletEvents } from './embeddedWallet';
4
+ import { OTPEvents } from './otp';
5
+ import { PasskeyEvents } from './passkey';
6
+ import { SocialEvents } from './social';
7
+ import { UIEvents } from './ui';
8
+ import { WalletEvents } from './wallet';
4
9
  /** Maps internal event names to their listeners */
5
- export type DynamicEvents = {
6
- authFlowOpen: () => void;
7
- /** Triggered when auth is closed before reaching success (due to user cancel or fail) */
8
- authFlowClose: () => void;
9
- /** Triggered when auth is attempted but fails, like when user rejects connection or the network call fails */
10
- authFlowCancelled: () => void;
11
- emailVerificationResult: (param: boolean, email: string) => void;
12
- smsVerificationResult: (param: boolean, phone: PhoneData) => void;
13
- embeddedWalletCreated: (wallet: Wallet, verifiedCredential: JwtVerifiedCredential | undefined, authToken: string | undefined) => void;
14
- embeddedWalletFailed: (error: unknown) => void;
15
- passkeyRecoveryCompleted: (wallet: Wallet) => void;
16
- passkeyRecoveryFailed: (error: unknown) => void;
17
- embeddedWalletRevealCompleted: (wallet: Wallet) => void;
18
- embeddedWalletRevealFailed: (error: unknown) => void;
19
- embeddedWalletCreatePasswordCompleted: (password: string) => void;
20
- embeddedWalletCreatePasswordFailed: (error: unknown) => void;
21
- embeddedWalletRecoveryEmailCompleted: (email: string) => void;
22
- embeddedWalletRecoveryEmailFailed: (error: unknown) => void;
23
- embeddedWalletUpdatePasswordCompleted: (password: string) => void;
24
- embeddedWalletUpdatePasswordFailed: (error: unknown) => void;
25
- logout: () => void;
26
- /** Triggered when a new wallet is added to user wallets list */
27
- walletAdded: (wallet: Wallet, userWallets: Wallet[]) => void;
28
- /** Triggered when a wallet is removed from user wallets list */
29
- walletRemoved: (wallet: Wallet, userWallets: Wallet[]) => void;
30
- /** This event is used to trigger logout to be called, DO NOT listen to it. Listen to "logout" instead */
31
- triggerLogout: () => void;
32
- farcasterConnectCancelled: () => void;
33
- };
10
+ export type DynamicEvents = AuthEvents & UIEvents & OTPEvents & WalletEvents & PasskeyEvents & SocialEvents & EmbeddedWalletEvents;
34
11
  export declare const dynamicEvents: EventEmitter<DynamicEvents, any>;
35
12
  export type DynamicEventEmitter = typeof dynamicEvents;
@@ -0,0 +1,14 @@
1
+ import { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';
2
+ import { Wallet } from '../shared/types/wallets';
3
+ export type EmbeddedWalletEvents = {
4
+ embeddedWalletCreated: (wallet: Wallet, verifiedCredential: JwtVerifiedCredential | undefined, authToken: string | undefined) => void;
5
+ embeddedWalletFailed: (error: unknown) => void;
6
+ embeddedWalletRevealCompleted: (wallet: Wallet) => void;
7
+ embeddedWalletRevealFailed: (error: unknown) => void;
8
+ embeddedWalletCreatePasswordCompleted: (password: string) => void;
9
+ embeddedWalletCreatePasswordFailed: (error: unknown) => void;
10
+ embeddedWalletRecoveryEmailCompleted: (email: string) => void;
11
+ embeddedWalletRecoveryEmailFailed: (error: unknown) => void;
12
+ embeddedWalletUpdatePasswordCompleted: (password: string) => void;
13
+ embeddedWalletUpdatePasswordFailed: (error: unknown) => void;
14
+ };
@@ -0,0 +1,5 @@
1
+ import { PhoneData } from '../shared/types';
2
+ export type OTPEvents = {
3
+ emailVerificationResult: (param: boolean, email: string) => void;
4
+ smsVerificationResult: (param: boolean, phone: PhoneData) => void;
5
+ };
@@ -0,0 +1,5 @@
1
+ import { Wallet } from '../shared/types/wallets';
2
+ export type PasskeyEvents = {
3
+ passkeyRecoveryCompleted: (wallet: Wallet) => void;
4
+ passkeyRecoveryFailed: (error: unknown) => void;
5
+ };
@@ -0,0 +1,3 @@
1
+ export type SocialEvents = {
2
+ farcasterConnectCancelled: () => void;
3
+ };
@@ -0,0 +1,10 @@
1
+ export type UIEvents = {
2
+ authFlowOpen: () => void;
3
+ /** Triggered when auth is closed before reaching success (due to user cancel or fail) */
4
+ authFlowClose: () => void;
5
+ /**
6
+ * Triggered alongside authFlowClose when auth is attempted but fails
7
+ * like when user rejects connection or the network call fails
8
+ */
9
+ authFlowCancelled: () => void;
10
+ };
@@ -0,0 +1,7 @@
1
+ import { Wallet } from '../shared/types/wallets';
2
+ export type WalletEvents = {
3
+ /** Triggered when a new wallet is added to user wallets list */
4
+ walletAdded: (wallet: Wallet, userWallets: Wallet[]) => void;
5
+ /** Triggered when a wallet is removed from user wallets list */
6
+ walletRemoved: (wallet: Wallet, userWallets: Wallet[]) => void;
7
+ };
@@ -4,11 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
  var React = require('react');
7
+ var sdkApiCore = require('@dynamic-labs/sdk-api-core');
7
8
  var dynamicEvents = require('../../../events/dynamicEvents.cjs');
8
9
  require('../../../../../_virtual/_tslib.cjs');
9
10
  require('@dynamic-labs/utils');
10
11
  require('../../../context/DynamicContext/DynamicContext.cjs');
11
- require('@dynamic-labs/sdk-api-core');
12
12
  require('../../../shared/logger.cjs');
13
13
  require('@dynamic-labs/iconic');
14
14
  require('@dynamic-labs/wallet-connector-core');
@@ -90,16 +90,32 @@ const Header = ({ onClose: handleClose, heading, projectSettings, copykey, }) =>
90
90
  const { setExistentAccountData } = AccountExistsContext.useAccountExistsContext();
91
91
  const { setSocialProvider } = SocialRedirectContext.useSocialRedirectContext();
92
92
  const handleBackClick = React.useCallback(() => {
93
+ var _a, _b;
93
94
  if (view.type === 'farcaster-connect-view') {
94
95
  setSocialProvider(undefined);
95
96
  dynamicEvents.dynamicEvents.emit('farcasterConnectCancelled');
97
+ dynamicEvents.dynamicEvents.emit('authFailure', {
98
+ option: sdkApiCore.ProviderEnum.Farcaster,
99
+ type: 'social',
100
+ }, 'user-cancelled');
96
101
  }
97
102
  setExistentAccountData(undefined);
98
103
  setError(undefined);
99
- if (view.type === 'no-qr-not-installed' &&
100
- (selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.canConnectViaQrCode)) {
101
- setView('qr-code');
102
- return;
104
+ if (view.type === 'no-qr-not-installed') {
105
+ dynamicEvents.dynamicEvents.emit('authFailure', {
106
+ option: (_a = selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.name) !== null && _a !== void 0 ? _a : '',
107
+ type: 'wallet',
108
+ }, 'user-cancelled');
109
+ if (selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.canConnectViaQrCode) {
110
+ setView('qr-code');
111
+ return;
112
+ }
113
+ }
114
+ if (view.type === 'qr-code' || view.type === 'pending-signature') {
115
+ dynamicEvents.dynamicEvents.emit('authFailure', {
116
+ option: (_b = selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.name) !== null && _b !== void 0 ? _b : '',
117
+ type: 'wallet',
118
+ }, 'user-cancelled');
103
119
  }
104
120
  goToInitialView();
105
121
  }, [
@@ -1,10 +1,10 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
2
  import { useCallback } from 'react';
3
+ import { ProviderEnum } from '@dynamic-labs/sdk-api-core';
3
4
  import { dynamicEvents } from '../../../events/dynamicEvents.js';
4
5
  import '../../../../../_virtual/_tslib.js';
5
6
  import '@dynamic-labs/utils';
6
7
  import '../../../context/DynamicContext/DynamicContext.js';
7
- import '@dynamic-labs/sdk-api-core';
8
8
  import '../../../shared/logger.js';
9
9
  import '@dynamic-labs/iconic';
10
10
  import '@dynamic-labs/wallet-connector-core';
@@ -86,16 +86,32 @@ const Header = ({ onClose: handleClose, heading, projectSettings, copykey, }) =>
86
86
  const { setExistentAccountData } = useAccountExistsContext();
87
87
  const { setSocialProvider } = useSocialRedirectContext();
88
88
  const handleBackClick = useCallback(() => {
89
+ var _a, _b;
89
90
  if (view.type === 'farcaster-connect-view') {
90
91
  setSocialProvider(undefined);
91
92
  dynamicEvents.emit('farcasterConnectCancelled');
93
+ dynamicEvents.emit('authFailure', {
94
+ option: ProviderEnum.Farcaster,
95
+ type: 'social',
96
+ }, 'user-cancelled');
92
97
  }
93
98
  setExistentAccountData(undefined);
94
99
  setError(undefined);
95
- if (view.type === 'no-qr-not-installed' &&
96
- (selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.canConnectViaQrCode)) {
97
- setView('qr-code');
98
- return;
100
+ if (view.type === 'no-qr-not-installed') {
101
+ dynamicEvents.emit('authFailure', {
102
+ option: (_a = selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.name) !== null && _a !== void 0 ? _a : '',
103
+ type: 'wallet',
104
+ }, 'user-cancelled');
105
+ if (selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.canConnectViaQrCode) {
106
+ setView('qr-code');
107
+ return;
108
+ }
109
+ }
110
+ if (view.type === 'qr-code' || view.type === 'pending-signature') {
111
+ dynamicEvents.emit('authFailure', {
112
+ option: (_b = selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.name) !== null && _b !== void 0 ? _b : '',
113
+ type: 'wallet',
114
+ }, 'user-cancelled');
99
115
  }
100
116
  goToInitialView();
101
117
  }, [
@@ -1,7 +1,8 @@
1
1
  import { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';
2
+ import { AuthEventPayload } from '../../events/auth';
3
+ import { OtpDestination, PhoneData } from '.';
2
4
  import { UserProfile } from './user';
3
5
  import { Wallet } from './wallets';
4
- import { OtpDestination, PhoneData } from '.';
5
6
  export type DynamicEventsCallbacks = {
6
7
  onSignedMessage?: (params: {
7
8
  messageToSign: string;
@@ -19,6 +20,16 @@ export type DynamicEventsCallbacks = {
19
20
  onEmbeddedWalletCreated?: OnEmbeddedWalletCreated;
20
21
  onWalletAdded?: OnWalletAdded;
21
22
  onWalletRemoved?: OnWalletRemoved;
23
+ /**
24
+ * Informs an auth attempt failed.
25
+ * In general triggered when an error occurs or when user cancels out.
26
+ * For email/sms, specifically happens when users cancels the OTP verification.
27
+ */
28
+ onAuthFailure?: (data: AuthEventPayload, reason: 'user-cancelled' | {
29
+ error: unknown;
30
+ }) => void;
31
+ /** Informs an auth attempt initialized, and provides insight into which auth option it is */
32
+ onAuthInit?: (data: AuthEventPayload) => void;
22
33
  };
23
34
  export type OnAuthSuccess = (params: {
24
35
  authToken: string;
@@ -2,7 +2,7 @@ import { DynamicEvents } from '../../../../events';
2
2
  import { EventArgs } from '../types';
3
3
  type DynamicEventListener<E extends keyof DynamicEvents> = (...args: EventArgs<DynamicEvents, E>) => void;
4
4
  /** Allows us to subscribe to all dynamicEvents with a hook, even the internal ones */
5
- export declare const useInternalDynamicEvents: <E extends keyof DynamicEvents>(event: E, listener: DynamicEventListener<E>) => void;
5
+ export declare const useInternalDynamicEvents: <E extends keyof import("../../../../events/auth").AuthEvents | keyof import("../../../../events/ui").UIEvents | keyof import("../../../../events/otp").OTPEvents | keyof import("../../../../events/wallet").WalletEvents | keyof import("../../../../events/passkey").PasskeyEvents | "farcasterConnectCancelled" | keyof import("../../../../events/embeddedWallet").EmbeddedWalletEvents>(event: E, listener: DynamicEventListener<E>) => void;
6
6
  /** Allows subscribing to dynamic events directly inside components with a hook */
7
- export declare const useDynamicEvents: <E extends "emailVerificationResult" | "embeddedWalletCreated" | "logout">(event: E, listener: DynamicEventListener<E>) => void;
7
+ export declare const useDynamicEvents: <E extends "logout" | "emailVerificationResult" | "embeddedWalletCreated">(event: E, listener: DynamicEventListener<E>) => void;
8
8
  export {};
@@ -17,7 +17,7 @@ require('../../constants/values.cjs');
17
17
  require('../../../shared/utils/classes/storage/localStorage.cjs');
18
18
  require('@dynamic-labs/utils');
19
19
  require('../../../shared/consts/index.cjs');
20
- require('../../../events/dynamicEvents.cjs');
20
+ var dynamicEvents = require('../../../events/dynamicEvents.cjs');
21
21
  require('../../../context/CaptchaContext/CaptchaContext.cjs');
22
22
  require('../../../context/ErrorContext/ErrorContext.cjs');
23
23
  require('@dynamic-labs/multi-wallet');
@@ -115,21 +115,34 @@ const useEmailProvider = ({ emailWalletConnector }) => {
115
115
  yield handleEmailOnlyLoginSubmit(emailInput, captchaToken);
116
116
  });
117
117
  const handleEmailSubmitWithOptionalCaptcha = (emailInput, captchaToken) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
118
- if ((emailWalletConnector !== undefined ||
119
- isTurnkeyEnabled.isTurnkeyEnabled(projectSettings)) &&
120
- (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.confirmEmailProviderForVerify)) {
121
- // see: https://linear.app/dynamic-labs/issue/DYN-2517
122
- // if confirmWalletTransfers setting is true, check api first to confirm emailProvider
123
- const { emailProvider } = yield email.getEmailProvider({
124
- email: emailInput,
125
- environmentId,
126
- });
127
- if (emailProvider === sdkApiCore.ProviderEnum.Dynamic) {
128
- yield handleEmailOnlyLoginSubmit(emailInput, captchaToken);
129
- return;
118
+ dynamicEvents.dynamicEvents.emit('authInit', {
119
+ option: emailInput,
120
+ type: 'email',
121
+ });
122
+ try {
123
+ if ((emailWalletConnector !== undefined ||
124
+ isTurnkeyEnabled.isTurnkeyEnabled(projectSettings)) &&
125
+ (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.confirmEmailProviderForVerify)) {
126
+ // see: https://linear.app/dynamic-labs/issue/DYN-2517
127
+ // if confirmWalletTransfers setting is true, check api first to confirm emailProvider
128
+ const { emailProvider } = yield email.getEmailProvider({
129
+ email: emailInput,
130
+ environmentId,
131
+ });
132
+ if (emailProvider === sdkApiCore.ProviderEnum.Dynamic) {
133
+ yield handleEmailOnlyLoginSubmit(emailInput, captchaToken);
134
+ return;
135
+ }
130
136
  }
137
+ yield submitEmail(emailInput, captchaToken);
138
+ }
139
+ catch (error) {
140
+ dynamicEvents.dynamicEvents.emit('authFailure', {
141
+ option: emailInput,
142
+ type: 'email',
143
+ }, { error });
144
+ throw error;
131
145
  }
132
- yield submitEmail(emailInput, captchaToken);
133
146
  });
134
147
  return {
135
148
  handleEmailSubmitWithOptionalCaptcha,
@@ -13,7 +13,7 @@ import '../../constants/values.js';
13
13
  import '../../../shared/utils/classes/storage/localStorage.js';
14
14
  import '@dynamic-labs/utils';
15
15
  import '../../../shared/consts/index.js';
16
- import '../../../events/dynamicEvents.js';
16
+ import { dynamicEvents } from '../../../events/dynamicEvents.js';
17
17
  import '../../../context/CaptchaContext/CaptchaContext.js';
18
18
  import '../../../context/ErrorContext/ErrorContext.js';
19
19
  import '@dynamic-labs/multi-wallet';
@@ -111,21 +111,34 @@ const useEmailProvider = ({ emailWalletConnector }) => {
111
111
  yield handleEmailOnlyLoginSubmit(emailInput, captchaToken);
112
112
  });
113
113
  const handleEmailSubmitWithOptionalCaptcha = (emailInput, captchaToken) => __awaiter(void 0, void 0, void 0, function* () {
114
- if ((emailWalletConnector !== undefined ||
115
- isTurnkeyEnabled(projectSettings)) &&
116
- (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.confirmEmailProviderForVerify)) {
117
- // see: https://linear.app/dynamic-labs/issue/DYN-2517
118
- // if confirmWalletTransfers setting is true, check api first to confirm emailProvider
119
- const { emailProvider } = yield getEmailProvider({
120
- email: emailInput,
121
- environmentId,
122
- });
123
- if (emailProvider === ProviderEnum.Dynamic) {
124
- yield handleEmailOnlyLoginSubmit(emailInput, captchaToken);
125
- return;
114
+ dynamicEvents.emit('authInit', {
115
+ option: emailInput,
116
+ type: 'email',
117
+ });
118
+ try {
119
+ if ((emailWalletConnector !== undefined ||
120
+ isTurnkeyEnabled(projectSettings)) &&
121
+ (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.confirmEmailProviderForVerify)) {
122
+ // see: https://linear.app/dynamic-labs/issue/DYN-2517
123
+ // if confirmWalletTransfers setting is true, check api first to confirm emailProvider
124
+ const { emailProvider } = yield getEmailProvider({
125
+ email: emailInput,
126
+ environmentId,
127
+ });
128
+ if (emailProvider === ProviderEnum.Dynamic) {
129
+ yield handleEmailOnlyLoginSubmit(emailInput, captchaToken);
130
+ return;
131
+ }
126
132
  }
133
+ yield submitEmail(emailInput, captchaToken);
134
+ }
135
+ catch (error) {
136
+ dynamicEvents.emit('authFailure', {
137
+ option: emailInput,
138
+ type: 'email',
139
+ }, { error });
140
+ throw error;
127
141
  }
128
- yield submitEmail(emailInput, captchaToken);
129
142
  });
130
143
  return {
131
144
  handleEmailSubmitWithOptionalCaptcha,
@@ -105,17 +105,17 @@ const useSocialAccounts = ({ sessionTimeout } = {
105
105
  }, [user === null || user === void 0 ? void 0 : user.verifiedCredentials]);
106
106
  const checkValidOAuthLinking = (provider) => {
107
107
  if (!isSocialKycEnabled.isSocialKycEnabled(projectSettings)) {
108
- handleError(types.SocialOAuthErrorCode.SOCIAL_LINKING_NOT_ENABLED, 'Social linking is not enabled on the dashboard');
108
+ handleError(provider, types.SocialOAuthErrorCode.SOCIAL_LINKING_NOT_ENABLED, 'Social linking is not enabled on the dashboard');
109
109
  return false;
110
110
  }
111
111
  const verifiedCredential = verifiedOAuthCredentialsMap[provider];
112
112
  if (verifiedCredential) {
113
- handleError(types.SocialOAuthErrorCode.ACCOUNT_ALREADY_LINKED, `Account already linked for provider: ${provider}`);
113
+ handleError(provider, types.SocialOAuthErrorCode.ACCOUNT_ALREADY_LINKED, `Account already linked for provider: ${provider}`);
114
114
  return false;
115
115
  }
116
116
  const oauthProvider = oauthProviders.find((p) => p.provider === provider);
117
117
  if (!oauthProvider) {
118
- handleError(types.SocialOAuthErrorCode.PROVIDER_NOT_ENABLED, `Provider is not enabled on the dashboard: ${provider}`);
118
+ handleError(provider, types.SocialOAuthErrorCode.PROVIDER_NOT_ENABLED, `Provider is not enabled on the dashboard: ${provider}`);
119
119
  return false;
120
120
  }
121
121
  return true;
@@ -132,7 +132,7 @@ const useSocialAccounts = ({ sessionTimeout } = {
132
132
  }
133
133
  const verifiedCredential = verifiedOAuthCredentialsMap[provider];
134
134
  if (!verifiedCredential) {
135
- handleError(types.SocialOAuthErrorCode.NO_ACCOUNT_LINKED, `No account linked for provider: ${provider}`);
135
+ handleError(undefined, types.SocialOAuthErrorCode.NO_ACCOUNT_LINKED, `No account linked for provider: ${provider}`);
136
136
  return;
137
137
  }
138
138
  try {
@@ -143,14 +143,14 @@ const useSocialAccounts = ({ sessionTimeout } = {
143
143
  verifiedCrentialId: (_b = verifiedCredential.id) !== null && _b !== void 0 ? _b : '',
144
144
  }, String(userJwt));
145
145
  if (!response) {
146
- handleError(types.SocialOAuthErrorCode.UNLINK_ERROR, `Failed to unlink social account: ${provider} | ${verifiedCredential.id}`);
146
+ handleError(undefined, types.SocialOAuthErrorCode.UNLINK_ERROR, `Failed to unlink social account: ${provider} | ${verifiedCredential.id}`);
147
147
  return;
148
148
  }
149
149
  yield updateUserProfileByJWT(response.jwt, response.minifiedJwt);
150
150
  setIsProcessing(false);
151
151
  }
152
152
  catch (err) {
153
- handleError(types.SocialOAuthErrorCode.GENERAL_ERROR, `Failed to unlink social account: ${provider} | ${verifiedCredential.id}`);
153
+ handleError(undefined, types.SocialOAuthErrorCode.GENERAL_ERROR, `Failed to unlink social account: ${provider} | ${verifiedCredential.id}`);
154
154
  }
155
155
  });
156
156
  const isLinked = (provider) => Boolean(verifiedOAuthCredentialsMap[provider]);