@dynamic-labs/sdk-react-core 0.17.0-RC.18 → 0.17.0-RC.19

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 (36) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/package.cjs +9 -9
  3. package/package.js +9 -9
  4. package/package.json +16 -16
  5. package/src/lib/components/ErrorContainer/ErrorContainer.cjs +2 -2
  6. package/src/lib/components/ErrorContainer/ErrorContainer.d.ts +3 -1
  7. package/src/lib/components/ErrorContainer/ErrorContainer.js +2 -2
  8. package/src/lib/components/Input/Input.cjs +6 -3
  9. package/src/lib/components/Input/Input.js +7 -4
  10. package/src/lib/components/Input/Input.types.d.ts +4 -0
  11. package/src/lib/context/SocialRedirectContext/SocialRedirectContext.cjs +56 -19
  12. package/src/lib/context/SocialRedirectContext/SocialRedirectContext.d.ts +3 -1
  13. package/src/lib/context/SocialRedirectContext/SocialRedirectContext.js +57 -20
  14. package/src/lib/context/ViewContext/ViewContext.d.ts +1 -1
  15. package/src/lib/layout/DynamicAuthLayout/Header/header.cjs +11 -3
  16. package/src/lib/layout/DynamicAuthLayout/Header/header.js +11 -3
  17. package/src/lib/styles/index.shadow.cjs +1 -1
  18. package/src/lib/styles/index.shadow.js +1 -1
  19. package/src/lib/utils/functions/getReferencedAccount/getReferencedAccount.cjs +29 -0
  20. package/src/lib/utils/functions/getReferencedAccount/getReferencedAccount.js +25 -0
  21. package/src/lib/utils/hooks/useWalletConnectors/reconnectSocialWallet.cjs +37 -0
  22. package/src/lib/utils/hooks/useWalletConnectors/reconnectSocialWallet.js +33 -0
  23. package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.cjs +7 -0
  24. package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.js +8 -1
  25. package/src/lib/views/NetworkNotSupported/NetworkNotSupported.cjs +1 -1
  26. package/src/lib/views/NetworkNotSupported/NetworkNotSupported.js +1 -1
  27. package/src/lib/views/SocialRedirectView/SocialRedirectView.cjs +3 -8
  28. package/src/lib/views/SocialRedirectView/SocialRedirectView.js +3 -8
  29. package/src/lib/views/SocialWrongAccountView/SocialWrongAccountView.cjs +58 -0
  30. package/src/lib/views/SocialWrongAccountView/SocialWrongAccountView.d.ts +2 -0
  31. package/src/lib/views/SocialWrongAccountView/SocialWrongAccountView.js +54 -0
  32. package/src/lib/views/SocialWrongAccountView/index.d.ts +1 -0
  33. package/src/lib/views/viewToComponentMap.cjs +2 -0
  34. package/src/lib/views/viewToComponentMap.js +2 -0
  35. package/src/lib/widgets/DynamicWidget/components/Wallet/Wallet.cjs +9 -5
  36. package/src/lib/widgets/DynamicWidget/components/Wallet/Wallet.js +9 -5
package/CHANGELOG.md CHANGED
@@ -1,4 +1,15 @@
1
1
 
2
+ ## [0.17.0-RC.19](https://github.com/dynamic-labs/DynamicAuth/compare/v0.17.0-RC.18...v0.17.0-RC.19) (2023-05-30)
3
+
4
+
5
+ ### Features
6
+
7
+ * add SocialWrongAccountView ([#2153](https://github.com/dynamic-labs/DynamicAuth/issues/2153)) ([531a29d](https://github.com/dynamic-labs/DynamicAuth/commit/531a29d7d87739d974ecc35c57ef0d333a5e7451))
8
+ * do not show unlink button for embedded wallets ([#2169](https://github.com/dynamic-labs/DynamicAuth/issues/2169)) ([f813058](https://github.com/dynamic-labs/DynamicAuth/commit/f8130585c82c7ae73d1e32e107f67ec86b4edb89))
9
+ * **DYN-2402:** coinbase issues after disconnecting ([#2149](https://github.com/dynamic-labs/DynamicAuth/issues/2149)) ([91d49fb](https://github.com/dynamic-labs/DynamicAuth/commit/91d49fb7f8c6fca3ab03098f3fba53d277c836ad))
10
+ * handle user reconnecting with wrong social account ([#2157](https://github.com/dynamic-labs/DynamicAuth/issues/2157)) ([4f7c6df](https://github.com/dynamic-labs/DynamicAuth/commit/4f7c6dff7df9a7966a644bf2510cb3825b2c6408))
11
+ * **social:** handle reconnect ([#2131](https://github.com/dynamic-labs/DynamicAuth/issues/2131)) ([2b3e5fb](https://github.com/dynamic-labs/DynamicAuth/commit/2b3e5fbb72bb7dafee3bd0bbfa73fae444055410))
12
+
2
13
  ## [0.17.0-RC.18](https://github.com/dynamic-labs/DynamicAuth/compare/v0.17.0-RC.17...v0.17.0-RC.18) (2023-05-19)
3
14
 
4
15
 
package/package.cjs CHANGED
@@ -2,18 +2,18 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var version = "0.17.0-RC.18";
5
+ var version = "0.17.0-RC.19";
6
6
  var dependencies = {
7
- "react-focus-lock": "^2.9.2",
8
- "@dynamic-labs/iconic": "^0.1.19",
7
+ "react-focus-lock": "2.9.2",
8
+ "@dynamic-labs/iconic": "0.1.19",
9
9
  "@dynamic-labs/sdk-api": "0.0.198",
10
- "@dynamic-labs/wallet-book": "^0.0.15",
11
- "@hcaptcha/react-hcaptcha": "~1.4.4",
12
- "country-list": "^2.3.0",
13
- yup: "^0.32.11",
14
- formik: "^2.2.9",
10
+ "@dynamic-labs/wallet-book": "0.0.18",
11
+ "@hcaptcha/react-hcaptcha": "1.4.4",
12
+ "country-list": "2.3.0",
13
+ yup: "0.32.11",
14
+ formik: "2.2.9",
15
15
  qrcode: "1.5.1",
16
- ethers: "^5.7.2"
16
+ ethers: "5.7.2"
17
17
  };
18
18
 
19
19
  exports.dependencies = dependencies;
package/package.js CHANGED
@@ -1,15 +1,15 @@
1
- var version = "0.17.0-RC.18";
1
+ var version = "0.17.0-RC.19";
2
2
  var dependencies = {
3
- "react-focus-lock": "^2.9.2",
4
- "@dynamic-labs/iconic": "^0.1.19",
3
+ "react-focus-lock": "2.9.2",
4
+ "@dynamic-labs/iconic": "0.1.19",
5
5
  "@dynamic-labs/sdk-api": "0.0.198",
6
- "@dynamic-labs/wallet-book": "^0.0.15",
7
- "@hcaptcha/react-hcaptcha": "~1.4.4",
8
- "country-list": "^2.3.0",
9
- yup: "^0.32.11",
10
- formik: "^2.2.9",
6
+ "@dynamic-labs/wallet-book": "0.0.18",
7
+ "@hcaptcha/react-hcaptcha": "1.4.4",
8
+ "country-list": "2.3.0",
9
+ yup: "0.32.11",
10
+ formik: "2.2.9",
11
11
  qrcode: "1.5.1",
12
- ethers: "^5.7.2"
12
+ ethers: "5.7.2"
13
13
  };
14
14
 
15
15
  export { dependencies, version };
package/package.json CHANGED
@@ -1,31 +1,31 @@
1
1
  {
2
2
  "name": "@dynamic-labs/sdk-react-core",
3
- "version": "0.17.0-RC.18",
3
+ "version": "0.17.0-RC.19",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
7
7
  "directory": "packages/sdk-react-core"
8
8
  },
9
9
  "dependencies": {
10
- "react-focus-lock": "^2.9.2",
11
- "@dynamic-labs/iconic": "^0.1.19",
10
+ "react-focus-lock": "2.9.2",
11
+ "@dynamic-labs/iconic": "0.1.19",
12
12
  "@dynamic-labs/sdk-api": "0.0.198",
13
- "@dynamic-labs/wallet-book": "^0.0.15",
14
- "@hcaptcha/react-hcaptcha": "~1.4.4",
15
- "country-list": "^2.3.0",
16
- "yup": "^0.32.11",
17
- "formik": "^2.2.9",
13
+ "@dynamic-labs/wallet-book": "0.0.18",
14
+ "@hcaptcha/react-hcaptcha": "1.4.4",
15
+ "country-list": "2.3.0",
16
+ "yup": "0.32.11",
17
+ "formik": "2.2.9",
18
18
  "qrcode": "1.5.1",
19
- "ethers": "^5.7.2",
20
- "@dynamic-labs/logger": "0.17.0-RC.18",
21
- "@dynamic-labs/multi-wallet": "0.17.0-RC.18",
22
- "@dynamic-labs/rpc-providers": "0.17.0-RC.18",
23
- "@dynamic-labs/types": "0.17.0-RC.18",
24
- "@dynamic-labs/utils": "0.17.0-RC.18",
25
- "@dynamic-labs/wallet-connector-core": "0.17.0-RC.18"
19
+ "ethers": "5.7.2",
20
+ "@dynamic-labs/logger": "0.17.0-RC.19",
21
+ "@dynamic-labs/multi-wallet": "0.17.0-RC.19",
22
+ "@dynamic-labs/rpc-providers": "0.17.0-RC.19",
23
+ "@dynamic-labs/types": "0.17.0-RC.19",
24
+ "@dynamic-labs/utils": "0.17.0-RC.19",
25
+ "@dynamic-labs/wallet-connector-core": "0.17.0-RC.19"
26
26
  },
27
27
  "devDependencies": {
28
- "semver": "^7.3.8"
28
+ "semver": "7.3.8"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "react": "^17.0.2 || ^18.0.0",
@@ -17,8 +17,8 @@ require('../../shared/consts/index.cjs');
17
17
  var classNames = require('../../utils/functions/classNames/classNames.cjs');
18
18
  var Typography = require('../Typography/Typography.cjs');
19
19
 
20
- const ErrorContainer = ({ children, className, isMultiWalletError = false, withIcon = true, }) => {
21
- const effectiveContainerClassName = classNames.classNames('error-container', className, {
20
+ const ErrorContainer = ({ children, className, isMultiWalletError = false, withIcon = true, variant = 'error', }) => {
21
+ const effectiveContainerClassName = classNames.classNames('error-container', `error-container--${variant}`, className, {
22
22
  'error-container--multi-wallet': isMultiWalletError,
23
23
  });
24
24
  const effectiveErrorClassName = classNames.classNames('error', {
@@ -1,9 +1,11 @@
1
1
  import { ReactNode } from 'react';
2
+ type Variant = 'error' | 'info';
2
3
  type Props = {
3
4
  children: ReactNode;
4
5
  className?: string;
5
6
  isMultiWalletError?: boolean;
7
+ variant?: Variant;
6
8
  withIcon?: boolean;
7
9
  };
8
- export declare const ErrorContainer: ({ children, className, isMultiWalletError, withIcon, }: Props) => JSX.Element;
10
+ export declare const ErrorContainer: ({ children, className, isMultiWalletError, withIcon, variant, }: Props) => JSX.Element;
9
11
  export {};
@@ -13,8 +13,8 @@ import '../../shared/consts/index.js';
13
13
  import { classNames } from '../../utils/functions/classNames/classNames.js';
14
14
  import { Typography } from '../Typography/Typography.js';
15
15
 
16
- const ErrorContainer = ({ children, className, isMultiWalletError = false, withIcon = true, }) => {
17
- const effectiveContainerClassName = classNames('error-container', className, {
16
+ const ErrorContainer = ({ children, className, isMultiWalletError = false, withIcon = true, variant = 'error', }) => {
17
+ const effectiveContainerClassName = classNames('error-container', `error-container--${variant}`, className, {
18
18
  'error-container--multi-wallet': isMultiWalletError,
19
19
  });
20
20
  const effectiveErrorClassName = classNames('error', {
@@ -8,11 +8,14 @@ var classNames = require('../../utils/functions/classNames/classNames.cjs');
8
8
  var Typography = require('../Typography/Typography.cjs');
9
9
 
10
10
  const Input = (_a) => {
11
- var { className = '', id, label, type, onChange, onBlur, name, value, optional, error = false, disabled, message } = _a, rest = _tslib.__rest(_a, ["className", "id", "label", "type", "onChange", "onBlur", "name", "value", "optional", "error", "disabled", "message"]);
12
- return (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsxs("div", Object.assign({ className: 'input__container' }, { children: [jsxRuntime.jsx("input", Object.assign({}, rest, { name: name, value: value, onChange: onChange, onBlur: onBlur, type: type, id: id, placeholder: label, disabled: disabled, className: classNames.classNames('input', className, {
11
+ var { className = '', id, label, type, onChange, onBlur, name, value, optional, error = false, disabled, message, placeholder, variant = 'dense', suffix } = _a, rest = _tslib.__rest(_a, ["className", "id", "label", "type", "onChange", "onBlur", "name", "value", "optional", "error", "disabled", "message", "placeholder", "variant", "suffix"]);
12
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", Object.assign({ className: classNames.classNames('input__container', {
13
+ 'input__container--dense': variant === 'dense',
14
+ 'input__container--regular': variant === 'regular',
15
+ }) }, { children: [jsxRuntime.jsx("input", Object.assign({}, rest, { name: name, value: value, onChange: onChange, onBlur: onBlur, type: type, id: id, placeholder: variant === 'regular' ? placeholder : label, disabled: disabled, className: classNames.classNames('input', className, {
13
16
  input__error: error,
14
17
  input__has_trailing: optional,
15
- }) })), jsxRuntime.jsx("label", Object.assign({ htmlFor: id, className: classNames.classNames('input__label') }, { children: label })), optional && jsxRuntime.jsx("span", Object.assign({ className: 'input__trailing' }, { children: "Optional" }))] })), Boolean(message) && (jsxRuntime.jsx(Typography.Typography, Object.assign({ variant: 'body_mini', className: classNames.classNames('input__message', {
18
+ }) })), jsxRuntime.jsx("label", Object.assign({ htmlFor: id, className: classNames.classNames('input__label') }, { children: label })), suffix && jsxRuntime.jsx("div", Object.assign({ className: classNames.classNames('input__suffix') }, { children: suffix })), optional && jsxRuntime.jsx("span", Object.assign({ className: 'input__trailing' }, { children: "Optional" }))] })), Boolean(message) && (jsxRuntime.jsx(Typography.Typography, Object.assign({ variant: 'body_mini', className: classNames.classNames('input__message', {
16
19
  input__message__error: error,
17
20
  }) }, { children: message })))] }));
18
21
  };
@@ -1,14 +1,17 @@
1
1
  import { __rest } from '../../../../_virtual/_tslib.js';
2
- import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
3
3
  import { classNames } from '../../utils/functions/classNames/classNames.js';
4
4
  import { Typography } from '../Typography/Typography.js';
5
5
 
6
6
  const Input = (_a) => {
7
- var { className = '', id, label, type, onChange, onBlur, name, value, optional, error = false, disabled, message } = _a, rest = __rest(_a, ["className", "id", "label", "type", "onChange", "onBlur", "name", "value", "optional", "error", "disabled", "message"]);
8
- return (jsxs("div", { children: [jsxs("div", Object.assign({ className: 'input__container' }, { children: [jsx("input", Object.assign({}, rest, { name: name, value: value, onChange: onChange, onBlur: onBlur, type: type, id: id, placeholder: label, disabled: disabled, className: classNames('input', className, {
7
+ var { className = '', id, label, type, onChange, onBlur, name, value, optional, error = false, disabled, message, placeholder, variant = 'dense', suffix } = _a, rest = __rest(_a, ["className", "id", "label", "type", "onChange", "onBlur", "name", "value", "optional", "error", "disabled", "message", "placeholder", "variant", "suffix"]);
8
+ return (jsxs(Fragment, { children: [jsxs("div", Object.assign({ className: classNames('input__container', {
9
+ 'input__container--dense': variant === 'dense',
10
+ 'input__container--regular': variant === 'regular',
11
+ }) }, { children: [jsx("input", Object.assign({}, rest, { name: name, value: value, onChange: onChange, onBlur: onBlur, type: type, id: id, placeholder: variant === 'regular' ? placeholder : label, disabled: disabled, className: classNames('input', className, {
9
12
  input__error: error,
10
13
  input__has_trailing: optional,
11
- }) })), jsx("label", Object.assign({ htmlFor: id, className: classNames('input__label') }, { children: label })), optional && jsx("span", Object.assign({ className: 'input__trailing' }, { children: "Optional" }))] })), Boolean(message) && (jsx(Typography, Object.assign({ variant: 'body_mini', className: classNames('input__message', {
14
+ }) })), jsx("label", Object.assign({ htmlFor: id, className: classNames('input__label') }, { children: label })), suffix && jsx("div", Object.assign({ className: classNames('input__suffix') }, { children: suffix })), optional && jsx("span", Object.assign({ className: 'input__trailing' }, { children: "Optional" }))] })), Boolean(message) && (jsx(Typography, Object.assign({ variant: 'body_mini', className: classNames('input__message', {
12
15
  input__message__error: error,
13
16
  }) }, { children: message })))] }));
14
17
  };
@@ -1,4 +1,5 @@
1
1
  import { FC, PropsWithChildren, ReactNode } from 'react';
2
+ export type InputVariant = 'dense' | 'regular';
2
3
  export type InputProps = React.ComponentPropsWithoutRef<'input'> & {
3
4
  className?: string;
4
5
  error?: boolean;
@@ -6,5 +7,8 @@ export type InputProps = React.ComponentPropsWithoutRef<'input'> & {
6
7
  label: string;
7
8
  message?: ReactNode;
8
9
  optional?: boolean;
10
+ placeholder?: string;
11
+ suffix?: ReactNode;
12
+ variant?: InputVariant;
9
13
  };
10
14
  export type InputComponent = FC<PropsWithChildren<InputProps>>;
@@ -17,6 +17,7 @@ require('../../utils/constants/colors.cjs');
17
17
  require('ethers');
18
18
  require('../../shared/consts/index.cjs');
19
19
  require('@dynamic-labs/multi-wallet');
20
+ var getReferencedAccount = require('../../utils/functions/getReferencedAccount/getReferencedAccount.cjs');
20
21
  require('@dynamic-labs/rpc-providers');
21
22
  var useVerifyWallet = require('../../utils/hooks/useVerifyWallet/useVerifyWallet.cjs');
22
23
  require('react-dom');
@@ -40,7 +41,7 @@ require('../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.cjs');
40
41
  const SocialRedirectContext = React.createContext(undefined);
41
42
  const SocialRedirectContextProvider = ({ children, }) => {
42
43
  var _a, _b;
43
- const { setShowAuthFlow, wallets, setSelectedWalletConnector, walletUiUtils, consumeNonce, displayTermsOfService, environmentId, projectSettings, setIsSingleWalletAccount, } = useInternalDynamicContext.useInternalDynamicContext();
44
+ const { setShowAuthFlow, wallets, setSelectedWalletConnector, walletUiUtils, consumeNonce, displayTermsOfService, environmentId, projectSettings, setIsSingleWalletAccount, setShowDynamicUserProfile, isAuthenticated, setPrimaryWalletId, secondaryWallets, sdkHasLoaded, authToken, } = useInternalDynamicContext.useInternalDynamicContext();
44
45
  const { setView } = ViewContext.useViewContext();
45
46
  const verifyWallet = useVerifyWallet.useVerifyWallet({
46
47
  consumeNonce,
@@ -58,12 +59,11 @@ const SocialRedirectContextProvider = ({ children, }) => {
58
59
  .find(walletConnectorCore.isSocialWalletConnector);
59
60
  const [redirectStatus, setRedirectStatus] = React.useState('idle');
60
61
  const [socialProvider, setSocialProvider] = React.useState();
62
+ const wallet = secondaryWallets.find((wallet) => wallet.connector.key === (socialWalletConnector === null || socialWalletConnector === void 0 ? void 0 : socialWalletConnector.key));
63
+ const socialAccount = React.useMemo(() => (wallet ? getReferencedAccount.getReferencedAccount(authToken, wallet.id) : undefined), [authToken, wallet]);
61
64
  React.useEffect(() => {
62
65
  var _a;
63
- if (!projectSettings) {
64
- return;
65
- }
66
- if (!socialWalletConnector) {
66
+ if (!projectSettings || !socialWalletConnector || !sdkHasLoaded) {
67
67
  return;
68
68
  }
69
69
  const params = new URLSearchParams(window.location.search);
@@ -73,23 +73,51 @@ const SocialRedirectContextProvider = ({ children, }) => {
73
73
  setRedirectStatus('loading');
74
74
  setView('social-redirect-view');
75
75
  setShowAuthFlow(true);
76
- setSelectedWalletConnector(socialWalletConnector);
76
+ if (!isAuthenticated) {
77
+ setSelectedWalletConnector(socialWalletConnector);
78
+ }
77
79
  (_a = socialWalletConnector
78
80
  .getSession) === null || _a === void 0 ? void 0 : _a.call(socialWalletConnector).then((session) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
79
- const address = yield socialWalletConnector.fetchPublicAddress();
80
- if (!address) {
81
- return;
81
+ /**
82
+ * If the user is already authenticated, that means that they are in the process
83
+ * of setting their social wallet as their primary wallet. At this point, they
84
+ * have successfully re-authenticated with the social provider. We can now finish
85
+ * the setPrimaryWallet flow
86
+ */
87
+ if (isAuthenticated) {
88
+ if (!socialAccount) {
89
+ throw new Error('Social account not found');
90
+ }
91
+ if (socialAccount.oauthAccountId === session.oauthId) {
92
+ // justification: socialAccount is defined if and only if wallet is also defined
93
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
94
+ setPrimaryWalletId(wallet.id);
95
+ setShowAuthFlow(false);
96
+ setShowDynamicUserProfile(true);
97
+ }
98
+ else {
99
+ yield socialWalletConnector.endSession();
100
+ setView('social-wrong-account');
101
+ }
102
+ }
103
+ else {
104
+ const address = yield socialWalletConnector.fetchPublicAddress();
105
+ walletUiUtils.disabledConfirmationOnce();
106
+ yield verifyWallet({
107
+ oauth: {
108
+ accessToken: session.accessToken,
109
+ didToken: session.didToken,
110
+ provider: providerFromParams,
111
+ },
112
+ /**
113
+ * justification: if the user just successfully authenticated their social,
114
+ * then the social connector must return an address
115
+ */
116
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
117
+ publicWalletAddress: address,
118
+ walletConnector: socialWalletConnector,
119
+ });
82
120
  }
83
- walletUiUtils.disabledConfirmationOnce();
84
- yield verifyWallet({
85
- oauth: {
86
- accessToken: session.accessToken,
87
- didToken: session.didToken,
88
- provider: providerFromParams,
89
- },
90
- publicWalletAddress: address,
91
- walletConnector: socialWalletConnector,
92
- });
93
121
  setSocialProvider(undefined);
94
122
  setRedirectStatus('success');
95
123
  })).catch((error) => {
@@ -97,18 +125,27 @@ const SocialRedirectContextProvider = ({ children, }) => {
97
125
  });
98
126
  }
99
127
  }, [
128
+ socialAccount,
129
+ authToken,
130
+ isAuthenticated,
100
131
  projectSettings,
132
+ sdkHasLoaded,
133
+ secondaryWallets,
134
+ setPrimaryWalletId,
101
135
  setSelectedWalletConnector,
102
136
  setShowAuthFlow,
137
+ setShowDynamicUserProfile,
103
138
  setView,
104
139
  socialWalletConnector,
105
140
  verifyWallet,
106
141
  walletUiUtils,
142
+ wallet,
107
143
  ]);
108
144
  return (jsxRuntime.jsx(SocialRedirectContext.Provider, Object.assign({ value: {
109
145
  enabledSocialProviders,
110
146
  redirectStatus,
111
147
  setSocialProvider,
148
+ socialAccount,
112
149
  socialProvider,
113
150
  socialWalletConnector,
114
151
  } }, { children: children })));
@@ -1,11 +1,13 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { SocialOAuthProvider } from '@dynamic-labs/types';
3
+ import { JwtVerifiedCredential } from '@dynamic-labs/sdk-api';
3
4
  import { WalletConnector } from '../../..';
4
5
  type SocialRedirectStatus = 'idle' | 'loading' | 'success' | 'error';
5
- type SocialContextReturnType = {
6
+ export type SocialContextReturnType = {
6
7
  enabledSocialProviders: SocialOAuthProvider[];
7
8
  redirectStatus: SocialRedirectStatus;
8
9
  setSocialProvider: (val: SocialOAuthProvider) => void;
10
+ socialAccount: JwtVerifiedCredential | undefined;
9
11
  socialProvider: SocialOAuthProvider | undefined;
10
12
  socialWalletConnector: WalletConnector | undefined;
11
13
  };
@@ -1,6 +1,6 @@
1
1
  import { __awaiter } from '../../../../_virtual/_tslib.js';
2
2
  import { jsx } from 'react/jsx-runtime';
3
- import { createContext, useContext, useState, useEffect } from 'react';
3
+ import { createContext, useContext, useState, useMemo, useEffect } from 'react';
4
4
  import { isSocialWalletConnector } from '@dynamic-labs/wallet-connector-core';
5
5
  import { useInternalDynamicContext } from '../DynamicContext/useInternalDynamicContext.js';
6
6
  import { useViewContext } from '../ViewContext/ViewContext.js';
@@ -13,6 +13,7 @@ import '../../utils/constants/colors.js';
13
13
  import 'ethers';
14
14
  import '../../shared/consts/index.js';
15
15
  import '@dynamic-labs/multi-wallet';
16
+ import { getReferencedAccount } from '../../utils/functions/getReferencedAccount/getReferencedAccount.js';
16
17
  import '@dynamic-labs/rpc-providers';
17
18
  import { useVerifyWallet } from '../../utils/hooks/useVerifyWallet/useVerifyWallet.js';
18
19
  import 'react-dom';
@@ -36,7 +37,7 @@ import '../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.js';
36
37
  const SocialRedirectContext = createContext(undefined);
37
38
  const SocialRedirectContextProvider = ({ children, }) => {
38
39
  var _a, _b;
39
- const { setShowAuthFlow, wallets, setSelectedWalletConnector, walletUiUtils, consumeNonce, displayTermsOfService, environmentId, projectSettings, setIsSingleWalletAccount, } = useInternalDynamicContext();
40
+ const { setShowAuthFlow, wallets, setSelectedWalletConnector, walletUiUtils, consumeNonce, displayTermsOfService, environmentId, projectSettings, setIsSingleWalletAccount, setShowDynamicUserProfile, isAuthenticated, setPrimaryWalletId, secondaryWallets, sdkHasLoaded, authToken, } = useInternalDynamicContext();
40
41
  const { setView } = useViewContext();
41
42
  const verifyWallet = useVerifyWallet({
42
43
  consumeNonce,
@@ -54,12 +55,11 @@ const SocialRedirectContextProvider = ({ children, }) => {
54
55
  .find(isSocialWalletConnector);
55
56
  const [redirectStatus, setRedirectStatus] = useState('idle');
56
57
  const [socialProvider, setSocialProvider] = useState();
58
+ const wallet = secondaryWallets.find((wallet) => wallet.connector.key === (socialWalletConnector === null || socialWalletConnector === void 0 ? void 0 : socialWalletConnector.key));
59
+ const socialAccount = useMemo(() => (wallet ? getReferencedAccount(authToken, wallet.id) : undefined), [authToken, wallet]);
57
60
  useEffect(() => {
58
61
  var _a;
59
- if (!projectSettings) {
60
- return;
61
- }
62
- if (!socialWalletConnector) {
62
+ if (!projectSettings || !socialWalletConnector || !sdkHasLoaded) {
63
63
  return;
64
64
  }
65
65
  const params = new URLSearchParams(window.location.search);
@@ -69,23 +69,51 @@ const SocialRedirectContextProvider = ({ children, }) => {
69
69
  setRedirectStatus('loading');
70
70
  setView('social-redirect-view');
71
71
  setShowAuthFlow(true);
72
- setSelectedWalletConnector(socialWalletConnector);
72
+ if (!isAuthenticated) {
73
+ setSelectedWalletConnector(socialWalletConnector);
74
+ }
73
75
  (_a = socialWalletConnector
74
76
  .getSession) === null || _a === void 0 ? void 0 : _a.call(socialWalletConnector).then((session) => __awaiter(void 0, void 0, void 0, function* () {
75
- const address = yield socialWalletConnector.fetchPublicAddress();
76
- if (!address) {
77
- return;
77
+ /**
78
+ * If the user is already authenticated, that means that they are in the process
79
+ * of setting their social wallet as their primary wallet. At this point, they
80
+ * have successfully re-authenticated with the social provider. We can now finish
81
+ * the setPrimaryWallet flow
82
+ */
83
+ if (isAuthenticated) {
84
+ if (!socialAccount) {
85
+ throw new Error('Social account not found');
86
+ }
87
+ if (socialAccount.oauthAccountId === session.oauthId) {
88
+ // justification: socialAccount is defined if and only if wallet is also defined
89
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
90
+ setPrimaryWalletId(wallet.id);
91
+ setShowAuthFlow(false);
92
+ setShowDynamicUserProfile(true);
93
+ }
94
+ else {
95
+ yield socialWalletConnector.endSession();
96
+ setView('social-wrong-account');
97
+ }
98
+ }
99
+ else {
100
+ const address = yield socialWalletConnector.fetchPublicAddress();
101
+ walletUiUtils.disabledConfirmationOnce();
102
+ yield verifyWallet({
103
+ oauth: {
104
+ accessToken: session.accessToken,
105
+ didToken: session.didToken,
106
+ provider: providerFromParams,
107
+ },
108
+ /**
109
+ * justification: if the user just successfully authenticated their social,
110
+ * then the social connector must return an address
111
+ */
112
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
113
+ publicWalletAddress: address,
114
+ walletConnector: socialWalletConnector,
115
+ });
78
116
  }
79
- walletUiUtils.disabledConfirmationOnce();
80
- yield verifyWallet({
81
- oauth: {
82
- accessToken: session.accessToken,
83
- didToken: session.didToken,
84
- provider: providerFromParams,
85
- },
86
- publicWalletAddress: address,
87
- walletConnector: socialWalletConnector,
88
- });
89
117
  setSocialProvider(undefined);
90
118
  setRedirectStatus('success');
91
119
  })).catch((error) => {
@@ -93,18 +121,27 @@ const SocialRedirectContextProvider = ({ children, }) => {
93
121
  });
94
122
  }
95
123
  }, [
124
+ socialAccount,
125
+ authToken,
126
+ isAuthenticated,
96
127
  projectSettings,
128
+ sdkHasLoaded,
129
+ secondaryWallets,
130
+ setPrimaryWalletId,
97
131
  setSelectedWalletConnector,
98
132
  setShowAuthFlow,
133
+ setShowDynamicUserProfile,
99
134
  setView,
100
135
  socialWalletConnector,
101
136
  verifyWallet,
102
137
  walletUiUtils,
138
+ wallet,
103
139
  ]);
104
140
  return (jsx(SocialRedirectContext.Provider, Object.assign({ value: {
105
141
  enabledSocialProviders,
106
142
  redirectStatus,
107
143
  setSocialProvider,
144
+ socialAccount,
108
145
  socialProvider,
109
146
  socialWalletConnector,
110
147
  } }, { children: children })));
@@ -1,5 +1,5 @@
1
1
  import { ReactNode, SetStateAction, Dispatch } from 'react';
2
- export type ViewType = 'captcha' | 'chainalysis-blocked-wallet' | 'collect-user-data' | 'collect-user-data-login-with-email' | 'login-with-email-or-wallet-full-wallet-list' | 'login-with-email-or-wallet' | 'login-with-email-verification' | 'network-not-supported' | 'network-not-supported-manual' | 'no-access' | 'no-qr-not-installed' | 'pending-connect' | 'pending-signature-without-back-button' | 'pending-signature' | 'qr-code' | 'update-email' | 'verify-email' | 'wallet-connect-mobile-wallets-list' | 'wallet-list' | 'wallet-sign' | 'wallet-used' | 'wait-for-email-confirmation-view' | 'email-wallet-otp-verification-view' | 'social-redirect-view';
2
+ export type ViewType = 'captcha' | 'chainalysis-blocked-wallet' | 'collect-user-data' | 'collect-user-data-login-with-email' | 'login-with-email-or-wallet-full-wallet-list' | 'login-with-email-or-wallet' | 'login-with-email-verification' | 'network-not-supported' | 'network-not-supported-manual' | 'no-access' | 'no-qr-not-installed' | 'pending-connect' | 'pending-signature-without-back-button' | 'pending-signature' | 'qr-code' | 'update-email' | 'verify-email' | 'wallet-connect-mobile-wallets-list' | 'wallet-list' | 'wallet-sign' | 'wallet-used' | 'wait-for-email-confirmation-view' | 'email-wallet-otp-verification-view' | 'social-redirect-view' | 'social-wrong-account';
3
3
  export interface ViewContextProps {
4
4
  setView: Dispatch<SetStateAction<ViewType>>;
5
5
  view: ViewType;
@@ -42,13 +42,21 @@ require('../../../components/SendBalanceForm/SendBalanceForm.cjs');
42
42
  var QrCodeContext = require('../../../context/QrCodeContext/QrCodeContext.cjs');
43
43
 
44
44
  const Header = ({ onClose: handleClose, heading, projectSettings, }) => {
45
- const { clearStatesOnBackClick, loginWithEmail } = useInternalDynamicContext.useInternalDynamicContext();
45
+ const { clearStatesOnBackClick, loginWithEmail, selectedWalletConnector } = useInternalDynamicContext.useInternalDynamicContext();
46
46
  const { showQrCodeMessage, setShowQrCodeImage, showQrCodeImage } = QrCodeContext.useQrCodeContext();
47
47
  const { view, setView } = ViewContext.useViewContext();
48
48
  const handleBackClick = React.useCallback(() => {
49
- clearStatesOnBackClick();
50
49
  setView(loginWithEmail ? 'login-with-email-or-wallet' : 'wallet-list');
51
- }, [clearStatesOnBackClick, loginWithEmail, setView]);
50
+ // on back button click in Coinbase wallet clearing state would kill connection and refresh the page
51
+ if ((selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.name) !== 'Coinbase') {
52
+ clearStatesOnBackClick();
53
+ }
54
+ }, [
55
+ clearStatesOnBackClick,
56
+ loginWithEmail,
57
+ selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.name,
58
+ setView,
59
+ ]);
52
60
  const positionAbsolute = view === 'login-with-email-verification';
53
61
  const showCloseButton = view !== 'login-with-email-or-wallet-full-wallet-list' &&
54
62
  view !== 'login-with-email-verification';
@@ -38,13 +38,21 @@ import '../../../components/SendBalanceForm/SendBalanceForm.js';
38
38
  import { useQrCodeContext } from '../../../context/QrCodeContext/QrCodeContext.js';
39
39
 
40
40
  const Header = ({ onClose: handleClose, heading, projectSettings, }) => {
41
- const { clearStatesOnBackClick, loginWithEmail } = useInternalDynamicContext();
41
+ const { clearStatesOnBackClick, loginWithEmail, selectedWalletConnector } = useInternalDynamicContext();
42
42
  const { showQrCodeMessage, setShowQrCodeImage, showQrCodeImage } = useQrCodeContext();
43
43
  const { view, setView } = useViewContext();
44
44
  const handleBackClick = useCallback(() => {
45
- clearStatesOnBackClick();
46
45
  setView(loginWithEmail ? 'login-with-email-or-wallet' : 'wallet-list');
47
- }, [clearStatesOnBackClick, loginWithEmail, setView]);
46
+ // on back button click in Coinbase wallet clearing state would kill connection and refresh the page
47
+ if ((selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.name) !== 'Coinbase') {
48
+ clearStatesOnBackClick();
49
+ }
50
+ }, [
51
+ clearStatesOnBackClick,
52
+ loginWithEmail,
53
+ selectedWalletConnector === null || selectedWalletConnector === void 0 ? void 0 : selectedWalletConnector.name,
54
+ setView,
55
+ ]);
48
56
  const positionAbsolute = view === 'login-with-email-verification';
49
57
  const showCloseButton = view !== 'login-with-email-or-wallet-full-wallet-list' &&
50
58
  view !== 'login-with-email-verification';