@dynamic-labs/sdk-react-core 0.19.0-alpha.21 → 0.19.0-alpha.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -8
- package/src/lib/Main.cjs +3 -3
- package/src/lib/Main.js +3 -3
- package/src/lib/components/SignMessagePreview/SignMessagePreview.cjs +1 -1
- package/src/lib/components/SignMessagePreview/SignMessagePreview.js +1 -1
- package/src/lib/context/DynamicContext/DynamicContext.cjs +5 -8
- package/src/lib/context/DynamicContext/DynamicContext.js +5 -8
- package/src/lib/context/DynamicContext/types/index.d.ts +1 -1
- package/src/lib/utils/functions/getOauthLoginUrl/getOauthLoginUrl.cjs +25 -3
- package/src/lib/utils/functions/getOauthLoginUrl/getOauthLoginUrl.d.ts +1 -1
- package/src/lib/utils/functions/getOauthLoginUrl/getOauthLoginUrl.js +25 -3
- package/src/lib/utils/functions/getProviderByType/getProviderByType.cjs +7 -0
- package/src/lib/utils/functions/getProviderByType/getProviderByType.d.ts +2 -0
- package/src/lib/utils/functions/getProviderByType/getProviderByType.js +3 -0
- package/src/lib/utils/functions/getProviderByType/index.d.ts +1 -0
- package/src/lib/utils/functions/index.d.ts +1 -0
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.cjs +9 -9
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.d.ts +3 -3
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.js +9 -9
- package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.cjs +36 -12
- package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.js +36 -12
- package/src/lib/widgets/DynamicBridgeWidget/components/DynamicBridgeWalletCardBody/DynamicBridgeWalletCardBody.cjs +3 -3
- package/src/lib/widgets/DynamicBridgeWidget/components/DynamicBridgeWalletCardBody/DynamicBridgeWalletCardBody.d.ts +1 -1
- package/src/lib/widgets/DynamicBridgeWidget/components/DynamicBridgeWalletCardBody/DynamicBridgeWalletCardBody.js +3 -3
- package/src/lib/widgets/DynamicBridgeWidget/views/WalletsView/WalletsView.cjs +2 -2
- package/src/lib/widgets/DynamicBridgeWidget/views/WalletsView/WalletsView.js +2 -2
- package/src/lib/widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs +2 -4
- package/src/lib/widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.js +2 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
|
|
2
|
+
## [0.19.0-alpha.22](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.21...v0.19.0-alpha.22) (2023-10-23)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### ⚠ BREAKING CHANGES
|
|
6
|
+
|
|
7
|
+
* rename unlinkConnectedWallet to disconnectWallet (#3595)
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* rename unlinkConnectedWallet to disconnectWallet ([#3595](https://github.com/dynamic-labs/DynamicAuth/issues/3595)) ([ac4a59e](https://github.com/dynamic-labs/DynamicAuth/commit/ac4a59ee5e50814fdb4190f07f5905b0c1499c7d))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* add support for apple oauth ([#3568](https://github.com/dynamic-labs/DynamicAuth/issues/3568)) ([10455fd](https://github.com/dynamic-labs/DynamicAuth/commit/10455fd74f22c6a1d66409fc01650d6ec68c2156))
|
|
17
|
+
* only process oauth message coming from the expected origin ([#3653](https://github.com/dynamic-labs/DynamicAuth/issues/3653)) ([3bf48d4](https://github.com/dynamic-labs/DynamicAuth/commit/3bf48d4a61fa624c30ff11861e6f5db4c33ef5c3))
|
|
18
|
+
* **SignMessagePreview:** safely render message to sign ([#3655](https://github.com/dynamic-labs/DynamicAuth/issues/3655)) ([02b520a](https://github.com/dynamic-labs/DynamicAuth/commit/02b520a2ddb6ba4042bf630de4cf80259c4fac37))
|
|
19
|
+
|
|
2
20
|
## [0.19.0-alpha.21](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.20...v0.19.0-alpha.21) (2023-10-23)
|
|
3
21
|
|
|
4
22
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/sdk-react-core",
|
|
3
|
-
"version": "0.19.0-alpha.
|
|
3
|
+
"version": "0.19.0-alpha.22",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
"react-focus-lock": "2.9.2",
|
|
18
18
|
"react-i18next": "^13.2.0",
|
|
19
19
|
"yup": "0.32.11",
|
|
20
|
-
"@dynamic-labs/logger": "0.19.0-alpha.
|
|
21
|
-
"@dynamic-labs/multi-wallet": "0.19.0-alpha.
|
|
22
|
-
"@dynamic-labs/rpc-providers": "0.19.0-alpha.
|
|
23
|
-
"@dynamic-labs/types": "0.19.0-alpha.
|
|
24
|
-
"@dynamic-labs/utils": "0.19.0-alpha.
|
|
25
|
-
"@dynamic-labs/wallet-book": "0.19.0-alpha.
|
|
26
|
-
"@dynamic-labs/wallet-connector-core": "0.19.0-alpha.
|
|
20
|
+
"@dynamic-labs/logger": "0.19.0-alpha.22",
|
|
21
|
+
"@dynamic-labs/multi-wallet": "0.19.0-alpha.22",
|
|
22
|
+
"@dynamic-labs/rpc-providers": "0.19.0-alpha.22",
|
|
23
|
+
"@dynamic-labs/types": "0.19.0-alpha.22",
|
|
24
|
+
"@dynamic-labs/utils": "0.19.0-alpha.22",
|
|
25
|
+
"@dynamic-labs/wallet-book": "0.19.0-alpha.22",
|
|
26
|
+
"@dynamic-labs/wallet-connector-core": "0.19.0-alpha.22",
|
|
27
27
|
"eventemitter3": "5.0.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
package/src/lib/Main.cjs
CHANGED
|
@@ -68,7 +68,7 @@ const viewsToDisableCloseOnOverlayClick = [
|
|
|
68
68
|
'passkey-intro',
|
|
69
69
|
];
|
|
70
70
|
const Main = () => {
|
|
71
|
-
const { selectedWalletConnector, linkedWallets, isProjectSettingsLoading, projectSettings, setShowAuthFlow, showAuthFlow, wallets, clearStatesOnBackClick, user,
|
|
71
|
+
const { selectedWalletConnector, linkedWallets, isProjectSettingsLoading, projectSettings, setShowAuthFlow, showAuthFlow, wallets, clearStatesOnBackClick, user, disconnectWallet, authMode, connectedWallets, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
72
72
|
const { view, goToInitialView } = ViewContext.useViewContext();
|
|
73
73
|
const { setDeniedAddress, setDeniedOauthProvider } = AccessDeniedContext.useAccessDeniedContext();
|
|
74
74
|
const { setExistentAccountData } = AccountExistsContext.useAccountExistsContext();
|
|
@@ -105,7 +105,7 @@ const Main = () => {
|
|
|
105
105
|
network: yield walletByConnectorName.connector.getNetwork(),
|
|
106
106
|
walletConnector: walletByConnectorName.connector,
|
|
107
107
|
})) {
|
|
108
|
-
|
|
108
|
+
disconnectWallet(walletByConnectorName.id);
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
}
|
|
@@ -113,7 +113,7 @@ const Main = () => {
|
|
|
113
113
|
selectedWalletConnector,
|
|
114
114
|
authMode,
|
|
115
115
|
connectedWallets,
|
|
116
|
-
|
|
116
|
+
disconnectWallet,
|
|
117
117
|
user,
|
|
118
118
|
view,
|
|
119
119
|
]);
|
package/src/lib/Main.js
CHANGED
|
@@ -64,7 +64,7 @@ const viewsToDisableCloseOnOverlayClick = [
|
|
|
64
64
|
'passkey-intro',
|
|
65
65
|
];
|
|
66
66
|
const Main = () => {
|
|
67
|
-
const { selectedWalletConnector, linkedWallets, isProjectSettingsLoading, projectSettings, setShowAuthFlow, showAuthFlow, wallets, clearStatesOnBackClick, user,
|
|
67
|
+
const { selectedWalletConnector, linkedWallets, isProjectSettingsLoading, projectSettings, setShowAuthFlow, showAuthFlow, wallets, clearStatesOnBackClick, user, disconnectWallet, authMode, connectedWallets, } = useInternalDynamicContext();
|
|
68
68
|
const { view, goToInitialView } = useViewContext();
|
|
69
69
|
const { setDeniedAddress, setDeniedOauthProvider } = useAccessDeniedContext();
|
|
70
70
|
const { setExistentAccountData } = useAccountExistsContext();
|
|
@@ -101,7 +101,7 @@ const Main = () => {
|
|
|
101
101
|
network: yield walletByConnectorName.connector.getNetwork(),
|
|
102
102
|
walletConnector: walletByConnectorName.connector,
|
|
103
103
|
})) {
|
|
104
|
-
|
|
104
|
+
disconnectWallet(walletByConnectorName.id);
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
}
|
|
@@ -109,7 +109,7 @@ const Main = () => {
|
|
|
109
109
|
selectedWalletConnector,
|
|
110
110
|
authMode,
|
|
111
111
|
connectedWallets,
|
|
112
|
-
|
|
112
|
+
disconnectWallet,
|
|
113
113
|
user,
|
|
114
114
|
view,
|
|
115
115
|
]);
|
|
@@ -21,7 +21,7 @@ const SignMessagePreview = ({ message, }) => {
|
|
|
21
21
|
if (signTypedData) {
|
|
22
22
|
return (jsxRuntime.jsx(SignTypedDataPreview.SignTypedDataPreview, { currentType: signTypedData.primaryType, types: signTypedData.types, showTypeName: true, data: signTypedData.message }));
|
|
23
23
|
}
|
|
24
|
-
return (jsxRuntime.jsx(Typography.Typography, { color: 'primary', variant: 'body_normal', children: jsxRuntime.jsx("span", { style: { whiteSpace: 'pre-line' },
|
|
24
|
+
return (jsxRuntime.jsx(Typography.Typography, { color: 'primary', variant: 'body_normal', children: jsxRuntime.jsx("span", { style: { whiteSpace: 'pre-line' }, children: message }) }));
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
exports.SignMessagePreview = SignMessagePreview;
|
|
@@ -17,7 +17,7 @@ const SignMessagePreview = ({ message, }) => {
|
|
|
17
17
|
if (signTypedData) {
|
|
18
18
|
return (jsx(SignTypedDataPreview, { currentType: signTypedData.primaryType, types: signTypedData.types, showTypeName: true, data: signTypedData.message }));
|
|
19
19
|
}
|
|
20
|
-
return (jsx(Typography, { color: 'primary', variant: 'body_normal', children: jsx("span", { style: { whiteSpace: 'pre-line' },
|
|
20
|
+
return (jsx(Typography, { color: 'primary', variant: 'body_normal', children: jsx("span", { style: { whiteSpace: 'pre-line' }, children: message }) }));
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export { SignMessagePreview };
|
|
@@ -197,14 +197,14 @@ const DynamicContextProvider = ({ children, theme, settings, locale: locale$1, }
|
|
|
197
197
|
});
|
|
198
198
|
const [authMode, setAuthMode] = useLocalStorage.useLocalStorage(localStorage$1.AUTH_MODE, initialAuthenticationMode);
|
|
199
199
|
const { clearPrimaryWalletId, primaryWalletId, setPrimaryWalletId } = usePrimaryWalletId.usePrimaryWalletId(internalEventsRef.current);
|
|
200
|
-
const { connectWallet, removeConnectedWalletsInfo, connectedWalletsInfo, connectedWallet, getConnectedWalletById, connectedWallets,
|
|
200
|
+
const { connectWallet, removeConnectedWalletsInfo, connectedWalletsInfo, connectedWallet, getConnectedWalletById, connectedWallets, disconnectWallet, refreshConnectedWallet, } = useConnectWallet.useConnectWallet({
|
|
201
201
|
authMode,
|
|
202
202
|
clearPrimaryWalletId,
|
|
203
203
|
enableVisitTrackingOnConnectOnly,
|
|
204
204
|
environmentId,
|
|
205
205
|
isBridgeFlow,
|
|
206
206
|
onBeforeConnectSuccessConfirmation: eventsCallbacks === null || eventsCallbacks === void 0 ? void 0 : eventsCallbacks.onBeforeConnectSuccessConfirmation,
|
|
207
|
-
|
|
207
|
+
onDisconnect: (connectedWalletsInfo, wallet) => handleDisconnectWallet.handleDisconnectWallet({
|
|
208
208
|
connectedWalletsInfo,
|
|
209
209
|
eventsCallbacks,
|
|
210
210
|
setWalletsToConnectByChain,
|
|
@@ -485,15 +485,14 @@ const DynamicContextProvider = ({ children, theme, settings, locale: locale$1, }
|
|
|
485
485
|
decodedOnboardingOnlyToken: decodeJwt.decodeJwt(onboardingOnlyJwt),
|
|
486
486
|
defaultNumberOfWalletsToShow,
|
|
487
487
|
desktopUri,
|
|
488
|
+
disconnectWallet,
|
|
488
489
|
displaySiweStatement,
|
|
489
490
|
environmentId,
|
|
490
491
|
eventsCallbacks,
|
|
491
492
|
getConnectedWalletById,
|
|
492
493
|
getNameService,
|
|
493
494
|
handleLogOut,
|
|
494
|
-
handleUnlinkWallet: authMode === 'connect-only'
|
|
495
|
-
? unlinkConnectedWallet
|
|
496
|
-
: handleUnlinkWallet,
|
|
495
|
+
handleUnlinkWallet: authMode === 'connect-only' ? disconnectWallet : handleUnlinkWallet,
|
|
497
496
|
i18nSDKInstance,
|
|
498
497
|
internalEvents: internalEventsRef,
|
|
499
498
|
internalSetShowAuthFlow: setShowAuthFlow,
|
|
@@ -575,7 +574,6 @@ const DynamicContextProvider = ({ children, theme, settings, locale: locale$1, }
|
|
|
575
574
|
termsOfServiceUrl,
|
|
576
575
|
theme,
|
|
577
576
|
toolkitEnabled,
|
|
578
|
-
unlinkConnectedWallet,
|
|
579
577
|
user,
|
|
580
578
|
walletConnector: (_c = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector) !== null && _c !== void 0 ? _c : null,
|
|
581
579
|
walletUiUtils,
|
|
@@ -614,7 +612,7 @@ const DynamicContextProvider = ({ children, theme, settings, locale: locale$1, }
|
|
|
614
612
|
getConnectedWalletById,
|
|
615
613
|
getNameService,
|
|
616
614
|
handleLogOut,
|
|
617
|
-
|
|
615
|
+
disconnectWallet,
|
|
618
616
|
handleUnlinkWallet,
|
|
619
617
|
i18nSDKInstance,
|
|
620
618
|
isAuthenticated,
|
|
@@ -626,7 +624,6 @@ const DynamicContextProvider = ({ children, theme, settings, locale: locale$1, }
|
|
|
626
624
|
legacyIsVerifying,
|
|
627
625
|
linkedWallets,
|
|
628
626
|
loadingNetwork,
|
|
629
|
-
locale$1,
|
|
630
627
|
loginWithEmail,
|
|
631
628
|
multiWallet,
|
|
632
629
|
multiWalletWidgetState,
|
|
@@ -193,14 +193,14 @@ const DynamicContextProvider = ({ children, theme, settings, locale, }) => {
|
|
|
193
193
|
});
|
|
194
194
|
const [authMode, setAuthMode] = useLocalStorage(AUTH_MODE, initialAuthenticationMode);
|
|
195
195
|
const { clearPrimaryWalletId, primaryWalletId, setPrimaryWalletId } = usePrimaryWalletId(internalEventsRef.current);
|
|
196
|
-
const { connectWallet, removeConnectedWalletsInfo, connectedWalletsInfo, connectedWallet, getConnectedWalletById, connectedWallets,
|
|
196
|
+
const { connectWallet, removeConnectedWalletsInfo, connectedWalletsInfo, connectedWallet, getConnectedWalletById, connectedWallets, disconnectWallet, refreshConnectedWallet, } = useConnectWallet({
|
|
197
197
|
authMode,
|
|
198
198
|
clearPrimaryWalletId,
|
|
199
199
|
enableVisitTrackingOnConnectOnly,
|
|
200
200
|
environmentId,
|
|
201
201
|
isBridgeFlow,
|
|
202
202
|
onBeforeConnectSuccessConfirmation: eventsCallbacks === null || eventsCallbacks === void 0 ? void 0 : eventsCallbacks.onBeforeConnectSuccessConfirmation,
|
|
203
|
-
|
|
203
|
+
onDisconnect: (connectedWalletsInfo, wallet) => handleDisconnectWallet({
|
|
204
204
|
connectedWalletsInfo,
|
|
205
205
|
eventsCallbacks,
|
|
206
206
|
setWalletsToConnectByChain,
|
|
@@ -481,15 +481,14 @@ const DynamicContextProvider = ({ children, theme, settings, locale, }) => {
|
|
|
481
481
|
decodedOnboardingOnlyToken: decodeJwt(onboardingOnlyJwt),
|
|
482
482
|
defaultNumberOfWalletsToShow,
|
|
483
483
|
desktopUri,
|
|
484
|
+
disconnectWallet,
|
|
484
485
|
displaySiweStatement,
|
|
485
486
|
environmentId,
|
|
486
487
|
eventsCallbacks,
|
|
487
488
|
getConnectedWalletById,
|
|
488
489
|
getNameService,
|
|
489
490
|
handleLogOut,
|
|
490
|
-
handleUnlinkWallet: authMode === 'connect-only'
|
|
491
|
-
? unlinkConnectedWallet
|
|
492
|
-
: handleUnlinkWallet,
|
|
491
|
+
handleUnlinkWallet: authMode === 'connect-only' ? disconnectWallet : handleUnlinkWallet,
|
|
493
492
|
i18nSDKInstance,
|
|
494
493
|
internalEvents: internalEventsRef,
|
|
495
494
|
internalSetShowAuthFlow: setShowAuthFlow,
|
|
@@ -571,7 +570,6 @@ const DynamicContextProvider = ({ children, theme, settings, locale, }) => {
|
|
|
571
570
|
termsOfServiceUrl,
|
|
572
571
|
theme,
|
|
573
572
|
toolkitEnabled,
|
|
574
|
-
unlinkConnectedWallet,
|
|
575
573
|
user,
|
|
576
574
|
walletConnector: (_c = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector) !== null && _c !== void 0 ? _c : null,
|
|
577
575
|
walletUiUtils,
|
|
@@ -610,7 +608,7 @@ const DynamicContextProvider = ({ children, theme, settings, locale, }) => {
|
|
|
610
608
|
getConnectedWalletById,
|
|
611
609
|
getNameService,
|
|
612
610
|
handleLogOut,
|
|
613
|
-
|
|
611
|
+
disconnectWallet,
|
|
614
612
|
handleUnlinkWallet,
|
|
615
613
|
i18nSDKInstance,
|
|
616
614
|
isAuthenticated,
|
|
@@ -622,7 +620,6 @@ const DynamicContextProvider = ({ children, theme, settings, locale, }) => {
|
|
|
622
620
|
legacyIsVerifying,
|
|
623
621
|
linkedWallets,
|
|
624
622
|
loadingNetwork,
|
|
625
|
-
locale,
|
|
626
623
|
loginWithEmail,
|
|
627
624
|
multiWallet,
|
|
628
625
|
multiWalletWidgetState,
|
|
@@ -133,7 +133,7 @@ export interface IDynamicContext {
|
|
|
133
133
|
theme?: ThemeData | ThemeSetting;
|
|
134
134
|
toolkitEnabled?: boolean;
|
|
135
135
|
user: UserProfile | undefined;
|
|
136
|
-
|
|
136
|
+
disconnectWallet: (walletId: string) => void;
|
|
137
137
|
walletConnector: WalletConnector | null;
|
|
138
138
|
walletUiUtils: WalletUiUtils<WalletConnector>;
|
|
139
139
|
wallets: WalletOption[];
|
|
@@ -2,9 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var utils = require('@dynamic-labs/utils');
|
|
5
6
|
var stringifyURIQuery = require('../stringifyURIQuery/stringifyURIQuery.cjs');
|
|
7
|
+
var getProviderByType = require('../getProviderByType/getProviderByType.cjs');
|
|
6
8
|
|
|
7
9
|
const OAUTH_LOGIN_DATA = {
|
|
10
|
+
apple: {
|
|
11
|
+
customMobileUrl: true,
|
|
12
|
+
response_mode: 'form_post',
|
|
13
|
+
response_type: ['code', 'id_token'],
|
|
14
|
+
scope: ['name', 'email'],
|
|
15
|
+
url: 'https://appleid.apple.com/auth/authorize',
|
|
16
|
+
},
|
|
8
17
|
discord: {
|
|
9
18
|
scope: ['identify', 'email'],
|
|
10
19
|
url: 'https://discord.com/api/oauth2/authorize',
|
|
@@ -44,9 +53,15 @@ const getProviderData = (provider) => {
|
|
|
44
53
|
}
|
|
45
54
|
return null;
|
|
46
55
|
};
|
|
47
|
-
const
|
|
56
|
+
const getMobileOauthUrl = (provider, loginData) => {
|
|
57
|
+
if (!loginData.customMobileUrl || !utils.isMobile() || !provider.redirectUrl) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
return provider.redirectUrl.replace('redirect', 'authorizeHtml');
|
|
61
|
+
};
|
|
62
|
+
const getOauthLoginUrl = (providers, providerType) => {
|
|
48
63
|
var _a;
|
|
49
|
-
const provider =
|
|
64
|
+
const provider = getProviderByType.getProviderByType(providers, providerType);
|
|
50
65
|
if (!(provider === null || provider === void 0 ? void 0 : provider.clientId)) {
|
|
51
66
|
return '';
|
|
52
67
|
}
|
|
@@ -54,6 +69,7 @@ const getOauthLoginUrl = (providers, providerType, environmentId) => {
|
|
|
54
69
|
if (!loginData) {
|
|
55
70
|
return '';
|
|
56
71
|
}
|
|
72
|
+
const mobileUrl = getMobileOauthUrl(provider, loginData);
|
|
57
73
|
const baseProps = {
|
|
58
74
|
client_id: provider.clientId,
|
|
59
75
|
redirect_uri: (_a = provider.redirectUrl) !== null && _a !== void 0 ? _a : '',
|
|
@@ -65,8 +81,14 @@ const getOauthLoginUrl = (providers, providerType, environmentId) => {
|
|
|
65
81
|
if (loginData.prompt) {
|
|
66
82
|
baseProps.prompt = loginData.prompt.join(' ');
|
|
67
83
|
}
|
|
84
|
+
if (loginData.response_mode) {
|
|
85
|
+
baseProps.response_mode = loginData.response_mode;
|
|
86
|
+
}
|
|
87
|
+
if (loginData.response_type) {
|
|
88
|
+
baseProps.response_type = loginData.response_type.join(' ');
|
|
89
|
+
}
|
|
68
90
|
const params = stringifyURIQuery.stringifyURIQuery(baseProps);
|
|
69
|
-
return `${loginData.url}?${params}`;
|
|
91
|
+
return `${mobileUrl !== null && mobileUrl !== void 0 ? mobileUrl : loginData.url}?${params}`;
|
|
70
92
|
};
|
|
71
93
|
|
|
72
94
|
exports.getOauthLoginUrl = getOauthLoginUrl;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Provider, ProviderEnum } from '@dynamic-labs/sdk-api';
|
|
2
|
-
export declare const getOauthLoginUrl: (providers: Provider[], providerType: ProviderEnum
|
|
2
|
+
export declare const getOauthLoginUrl: (providers: Provider[], providerType: ProviderEnum) => string;
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import { isMobile } from '@dynamic-labs/utils';
|
|
1
2
|
import { stringifyURIQuery } from '../stringifyURIQuery/stringifyURIQuery.js';
|
|
3
|
+
import { getProviderByType } from '../getProviderByType/getProviderByType.js';
|
|
2
4
|
|
|
3
5
|
const OAUTH_LOGIN_DATA = {
|
|
6
|
+
apple: {
|
|
7
|
+
customMobileUrl: true,
|
|
8
|
+
response_mode: 'form_post',
|
|
9
|
+
response_type: ['code', 'id_token'],
|
|
10
|
+
scope: ['name', 'email'],
|
|
11
|
+
url: 'https://appleid.apple.com/auth/authorize',
|
|
12
|
+
},
|
|
4
13
|
discord: {
|
|
5
14
|
scope: ['identify', 'email'],
|
|
6
15
|
url: 'https://discord.com/api/oauth2/authorize',
|
|
@@ -40,9 +49,15 @@ const getProviderData = (provider) => {
|
|
|
40
49
|
}
|
|
41
50
|
return null;
|
|
42
51
|
};
|
|
43
|
-
const
|
|
52
|
+
const getMobileOauthUrl = (provider, loginData) => {
|
|
53
|
+
if (!loginData.customMobileUrl || !isMobile() || !provider.redirectUrl) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
return provider.redirectUrl.replace('redirect', 'authorizeHtml');
|
|
57
|
+
};
|
|
58
|
+
const getOauthLoginUrl = (providers, providerType) => {
|
|
44
59
|
var _a;
|
|
45
|
-
const provider = providers
|
|
60
|
+
const provider = getProviderByType(providers, providerType);
|
|
46
61
|
if (!(provider === null || provider === void 0 ? void 0 : provider.clientId)) {
|
|
47
62
|
return '';
|
|
48
63
|
}
|
|
@@ -50,6 +65,7 @@ const getOauthLoginUrl = (providers, providerType, environmentId) => {
|
|
|
50
65
|
if (!loginData) {
|
|
51
66
|
return '';
|
|
52
67
|
}
|
|
68
|
+
const mobileUrl = getMobileOauthUrl(provider, loginData);
|
|
53
69
|
const baseProps = {
|
|
54
70
|
client_id: provider.clientId,
|
|
55
71
|
redirect_uri: (_a = provider.redirectUrl) !== null && _a !== void 0 ? _a : '',
|
|
@@ -61,8 +77,14 @@ const getOauthLoginUrl = (providers, providerType, environmentId) => {
|
|
|
61
77
|
if (loginData.prompt) {
|
|
62
78
|
baseProps.prompt = loginData.prompt.join(' ');
|
|
63
79
|
}
|
|
80
|
+
if (loginData.response_mode) {
|
|
81
|
+
baseProps.response_mode = loginData.response_mode;
|
|
82
|
+
}
|
|
83
|
+
if (loginData.response_type) {
|
|
84
|
+
baseProps.response_type = loginData.response_type.join(' ');
|
|
85
|
+
}
|
|
64
86
|
const params = stringifyURIQuery(baseProps);
|
|
65
|
-
return `${loginData.url}?${params}`;
|
|
87
|
+
return `${mobileUrl !== null && mobileUrl !== void 0 ? mobileUrl : loginData.url}?${params}`;
|
|
66
88
|
};
|
|
67
89
|
|
|
68
90
|
export { getOauthLoginUrl };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getProviderByType } from './getProviderByType';
|
|
@@ -23,15 +23,15 @@ var api = require('../../../data/api.cjs');
|
|
|
23
23
|
require('@dynamic-labs/multi-wallet');
|
|
24
24
|
var shouldManuallyReconnectOnRefresh = require('../../functions/shouldManuallyReconnectOnRefresh/shouldManuallyReconnectOnRefresh.cjs');
|
|
25
25
|
|
|
26
|
-
const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingOnConnectOnly, environmentId, primaryWalletId, setPrimaryWalletId, wallets,
|
|
26
|
+
const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingOnConnectOnly, environmentId, primaryWalletId, setPrimaryWalletId, wallets, onDisconnect, onBeforeConnectSuccessConfirmation, setShowAuthFlow, isBridgeFlow, }) => {
|
|
27
27
|
const [connectedWalletsInfo, setConnectedWalletsInfo, removeConnectedWalletsInfo,] = useLocalStorage.useLocalStorage(localStorage.CONNECTED_WALLETS_INFO, []);
|
|
28
28
|
const [connectedWallets, setConnectedWallets] = React.useState([]);
|
|
29
|
-
const
|
|
29
|
+
const disconnectWallet = React.useCallback((walletId) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
30
30
|
const walletToDisconnect = connectedWallets.find((wallet) => wallet.id === walletId);
|
|
31
31
|
yield (walletToDisconnect === null || walletToDisconnect === void 0 ? void 0 : walletToDisconnect.connector.endSession());
|
|
32
32
|
const updatedConnectedWalletsInfo = connectedWalletsInfo.filter((wallet) => wallet.id !== walletId);
|
|
33
33
|
setConnectedWalletsInfo(updatedConnectedWalletsInfo);
|
|
34
|
-
|
|
34
|
+
onDisconnect(updatedConnectedWalletsInfo, walletToDisconnect);
|
|
35
35
|
if (walletId !== primaryWalletId) {
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
@@ -47,7 +47,7 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
47
47
|
connectedWallets,
|
|
48
48
|
connectedWalletsInfo,
|
|
49
49
|
isBridgeFlow,
|
|
50
|
-
|
|
50
|
+
onDisconnect,
|
|
51
51
|
primaryWalletId,
|
|
52
52
|
setConnectedWalletsInfo,
|
|
53
53
|
setPrimaryWalletId,
|
|
@@ -67,12 +67,12 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
67
67
|
if (!walletConnector) {
|
|
68
68
|
walletConnectorCore.logger.error('Could not find walletConnector: ' +
|
|
69
69
|
storedConnectedWalletInfo.walletConnectorKey);
|
|
70
|
-
yield
|
|
70
|
+
yield disconnectWallet(storedConnectedWalletInfo.id);
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
73
|
const [walletAddress] = yield walletConnector.getConnectedAccounts();
|
|
74
74
|
if (!walletAddress) {
|
|
75
|
-
yield
|
|
75
|
+
yield disconnectWallet(storedConnectedWalletInfo.id);
|
|
76
76
|
return null;
|
|
77
77
|
}
|
|
78
78
|
const walletNetwork = yield walletConnector.getNetwork();
|
|
@@ -88,7 +88,7 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
88
88
|
return walletObject;
|
|
89
89
|
})))).filter((wallet) => Boolean(wallet));
|
|
90
90
|
setConnectedWallets(updatedConnectedWallets);
|
|
91
|
-
}), [connectedWalletsInfo,
|
|
91
|
+
}), [connectedWalletsInfo, disconnectWallet, wallets]);
|
|
92
92
|
// Generate the connectedWallets list when connectedWalletsInfo (localStorage) or memoized wallet connector updates
|
|
93
93
|
React.useEffect(() => {
|
|
94
94
|
updateConnectedWalletsList();
|
|
@@ -140,7 +140,7 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
140
140
|
});
|
|
141
141
|
if (!shouldProceedWithConnection) {
|
|
142
142
|
walletConnectorCore.logger.info('Connection was not established because onBeforeConnectSuccessConfirmation returned false');
|
|
143
|
-
|
|
143
|
+
disconnectWallet(walletId);
|
|
144
144
|
setShowAuthFlow(false);
|
|
145
145
|
return;
|
|
146
146
|
}
|
|
@@ -210,10 +210,10 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
210
210
|
connectedWallet,
|
|
211
211
|
connectedWallets,
|
|
212
212
|
connectedWalletsInfo,
|
|
213
|
+
disconnectWallet,
|
|
213
214
|
getConnectedWalletById,
|
|
214
215
|
refreshConnectedWallet,
|
|
215
216
|
removeConnectedWalletsInfo,
|
|
216
|
-
unlinkConnectedWallet,
|
|
217
217
|
};
|
|
218
218
|
};
|
|
219
219
|
|
|
@@ -15,7 +15,7 @@ type Props = {
|
|
|
15
15
|
primaryWalletId: string | undefined;
|
|
16
16
|
setPrimaryWalletId: (walletId: string) => void;
|
|
17
17
|
wallets: WalletOption[];
|
|
18
|
-
|
|
18
|
+
onDisconnect: (connectedWalletsInfo: ConnectedWalletConnectorType[], wallet?: Wallet) => void;
|
|
19
19
|
onBeforeConnectSuccessConfirmation: OnBeforeConnectSuccessConfirmation | undefined;
|
|
20
20
|
setShowAuthFlow: Dispatch<SetStateAction<boolean>>;
|
|
21
21
|
isBridgeFlow: boolean;
|
|
@@ -28,7 +28,7 @@ type UseConnectWalletValue = {
|
|
|
28
28
|
getConnectedWalletById: (walletId: string) => Wallet | undefined;
|
|
29
29
|
refreshConnectedWallet: (walletId: string, walletConnector: WalletConnector) => Promise<void>;
|
|
30
30
|
removeConnectedWalletsInfo: () => void;
|
|
31
|
-
|
|
31
|
+
disconnectWallet: (walletId: string) => Promise<void>;
|
|
32
32
|
};
|
|
33
|
-
export declare const useConnectWallet: ({ authMode, clearPrimaryWalletId, enableVisitTrackingOnConnectOnly, environmentId, primaryWalletId, setPrimaryWalletId, wallets,
|
|
33
|
+
export declare const useConnectWallet: ({ authMode, clearPrimaryWalletId, enableVisitTrackingOnConnectOnly, environmentId, primaryWalletId, setPrimaryWalletId, wallets, onDisconnect, onBeforeConnectSuccessConfirmation, setShowAuthFlow, isBridgeFlow, }: Props) => UseConnectWalletValue;
|
|
34
34
|
export {};
|
|
@@ -19,15 +19,15 @@ import { createVisit } from '../../../data/api.js';
|
|
|
19
19
|
import '@dynamic-labs/multi-wallet';
|
|
20
20
|
import { shouldManuallyReconnectOnRefresh } from '../../functions/shouldManuallyReconnectOnRefresh/shouldManuallyReconnectOnRefresh.js';
|
|
21
21
|
|
|
22
|
-
const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingOnConnectOnly, environmentId, primaryWalletId, setPrimaryWalletId, wallets,
|
|
22
|
+
const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingOnConnectOnly, environmentId, primaryWalletId, setPrimaryWalletId, wallets, onDisconnect, onBeforeConnectSuccessConfirmation, setShowAuthFlow, isBridgeFlow, }) => {
|
|
23
23
|
const [connectedWalletsInfo, setConnectedWalletsInfo, removeConnectedWalletsInfo,] = useLocalStorage(CONNECTED_WALLETS_INFO, []);
|
|
24
24
|
const [connectedWallets, setConnectedWallets] = useState([]);
|
|
25
|
-
const
|
|
25
|
+
const disconnectWallet = useCallback((walletId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
26
|
const walletToDisconnect = connectedWallets.find((wallet) => wallet.id === walletId);
|
|
27
27
|
yield (walletToDisconnect === null || walletToDisconnect === void 0 ? void 0 : walletToDisconnect.connector.endSession());
|
|
28
28
|
const updatedConnectedWalletsInfo = connectedWalletsInfo.filter((wallet) => wallet.id !== walletId);
|
|
29
29
|
setConnectedWalletsInfo(updatedConnectedWalletsInfo);
|
|
30
|
-
|
|
30
|
+
onDisconnect(updatedConnectedWalletsInfo, walletToDisconnect);
|
|
31
31
|
if (walletId !== primaryWalletId) {
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
@@ -43,7 +43,7 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
43
43
|
connectedWallets,
|
|
44
44
|
connectedWalletsInfo,
|
|
45
45
|
isBridgeFlow,
|
|
46
|
-
|
|
46
|
+
onDisconnect,
|
|
47
47
|
primaryWalletId,
|
|
48
48
|
setConnectedWalletsInfo,
|
|
49
49
|
setPrimaryWalletId,
|
|
@@ -63,12 +63,12 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
63
63
|
if (!walletConnector) {
|
|
64
64
|
logger.error('Could not find walletConnector: ' +
|
|
65
65
|
storedConnectedWalletInfo.walletConnectorKey);
|
|
66
|
-
yield
|
|
66
|
+
yield disconnectWallet(storedConnectedWalletInfo.id);
|
|
67
67
|
return null;
|
|
68
68
|
}
|
|
69
69
|
const [walletAddress] = yield walletConnector.getConnectedAccounts();
|
|
70
70
|
if (!walletAddress) {
|
|
71
|
-
yield
|
|
71
|
+
yield disconnectWallet(storedConnectedWalletInfo.id);
|
|
72
72
|
return null;
|
|
73
73
|
}
|
|
74
74
|
const walletNetwork = yield walletConnector.getNetwork();
|
|
@@ -84,7 +84,7 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
84
84
|
return walletObject;
|
|
85
85
|
})))).filter((wallet) => Boolean(wallet));
|
|
86
86
|
setConnectedWallets(updatedConnectedWallets);
|
|
87
|
-
}), [connectedWalletsInfo,
|
|
87
|
+
}), [connectedWalletsInfo, disconnectWallet, wallets]);
|
|
88
88
|
// Generate the connectedWallets list when connectedWalletsInfo (localStorage) or memoized wallet connector updates
|
|
89
89
|
useEffect(() => {
|
|
90
90
|
updateConnectedWalletsList();
|
|
@@ -136,7 +136,7 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
136
136
|
});
|
|
137
137
|
if (!shouldProceedWithConnection) {
|
|
138
138
|
logger.info('Connection was not established because onBeforeConnectSuccessConfirmation returned false');
|
|
139
|
-
|
|
139
|
+
disconnectWallet(walletId);
|
|
140
140
|
setShowAuthFlow(false);
|
|
141
141
|
return;
|
|
142
142
|
}
|
|
@@ -206,10 +206,10 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
206
206
|
connectedWallet,
|
|
207
207
|
connectedWallets,
|
|
208
208
|
connectedWalletsInfo,
|
|
209
|
+
disconnectWallet,
|
|
209
210
|
getConnectedWalletById,
|
|
210
211
|
refreshConnectedWallet,
|
|
211
212
|
removeConnectedWalletsInfo,
|
|
212
|
-
unlinkConnectedWallet,
|
|
213
213
|
};
|
|
214
214
|
};
|
|
215
215
|
|
|
@@ -28,11 +28,13 @@ var stringifyURIQuery = require('../../functions/stringifyURIQuery/stringifyURIQ
|
|
|
28
28
|
var digestSHA256 = require('../../functions/digestSHA256/digestSHA256.cjs');
|
|
29
29
|
var encodeBase64URL = require('../../functions/encodeBase64URL/encodeBase64URL.cjs');
|
|
30
30
|
var getOauthLoginUrl = require('../../functions/getOauthLoginUrl/getOauthLoginUrl.cjs');
|
|
31
|
+
var getProviderByType = require('../../functions/getProviderByType/getProviderByType.cjs');
|
|
31
32
|
var useCreateUserProfileByJWTCallback = require('../useCreateUserProfileByJWTCallback/useCreateUserProfileByJWTCallback.cjs');
|
|
32
33
|
var ErrorContext = require('../../../context/ErrorContext/ErrorContext.cjs');
|
|
33
34
|
var useEmbeddedWallet = require('../useEmbeddedWallet/useEmbeddedWallet.cjs');
|
|
34
35
|
|
|
35
36
|
const socialProviders = [
|
|
37
|
+
'apple',
|
|
36
38
|
'discord',
|
|
37
39
|
'facebook',
|
|
38
40
|
'github',
|
|
@@ -182,19 +184,37 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, }) => {
|
|
|
182
184
|
providersWaitingOauthMessage.current = Object.assign(Object.assign({}, providersWaitingOauthMessage.current), { [provider]: false });
|
|
183
185
|
};
|
|
184
186
|
const handleAuthWindowMessage = (event) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
185
|
-
var _d;
|
|
187
|
+
var _d, _e;
|
|
186
188
|
const message = event.data;
|
|
187
189
|
const isAuthorizationMessage = (message === null || message === void 0 ? void 0 : message.type) === 'authorization_response';
|
|
188
190
|
if (isAuthorizationMessage) {
|
|
189
191
|
logger.logger.debug('Message received', { data: message });
|
|
190
192
|
}
|
|
191
|
-
const
|
|
193
|
+
const apiProvider = getProviderByType.getProviderByType((_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) !== null && _d !== void 0 ? _d : [], provider);
|
|
194
|
+
if (!(apiProvider === null || apiProvider === void 0 ? void 0 : apiProvider.redirectUrl)) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
let expectedOrigin = '';
|
|
198
|
+
try {
|
|
199
|
+
const redirectUri = new URL(apiProvider.redirectUrl);
|
|
200
|
+
expectedOrigin = redirectUri.origin;
|
|
201
|
+
}
|
|
202
|
+
catch (e) {
|
|
203
|
+
logger.logger.error('Failed to parse social provider redirect url', {
|
|
204
|
+
error: e,
|
|
205
|
+
});
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const isExpectedOrigin = event.origin === expectedOrigin;
|
|
209
|
+
const isValidMessage = isAuthorizationMessage &&
|
|
210
|
+
(message === null || message === void 0 ? void 0 : message.provider) === provider &&
|
|
211
|
+
isExpectedOrigin;
|
|
192
212
|
// don't process invalid messages for provider
|
|
193
213
|
if (!isValidMessage) {
|
|
194
214
|
return;
|
|
195
215
|
}
|
|
196
216
|
setIsProcessing(true);
|
|
197
|
-
if (!((
|
|
217
|
+
if (!((_e = providersWaitingOauthMessage.current) === null || _e === void 0 ? void 0 : _e[provider])) {
|
|
198
218
|
handleError(types.SocialOAuthErrorCode.SESSION_TIMEOUT, `Connecting ${provider} account session timeout.`);
|
|
199
219
|
return;
|
|
200
220
|
}
|
|
@@ -221,19 +241,23 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, }) => {
|
|
|
221
241
|
handleError(types.SocialOAuthErrorCode.NO_OAUTH_URL, `Failed to get login url to connect social account: ${provider}`);
|
|
222
242
|
return;
|
|
223
243
|
}
|
|
224
|
-
|
|
244
|
+
if (!((_c = providersWaitingOauthMessage.current) === null || _c === void 0 ? void 0 : _c[provider])) {
|
|
245
|
+
window.addEventListener('message', handleAuthWindowMessage);
|
|
246
|
+
providersWaitingOauthMessage.current = Object.assign(Object.assign({}, providersWaitingOauthMessage.current), { [provider]: true });
|
|
247
|
+
}
|
|
248
|
+
// add state param for all providers
|
|
249
|
+
const stateParam = stringifyURIQuery.stringifyURIQuery({
|
|
250
|
+
state,
|
|
251
|
+
});
|
|
252
|
+
let oauthLoginUrl = `${loginUrl}&${stateParam}`;
|
|
253
|
+
// only add pkce params for providers that support/require it
|
|
225
254
|
if (providersRequiringPkce.includes(provider)) {
|
|
226
255
|
const digest = yield digestSHA256.digestSHA256(verifier);
|
|
227
256
|
const pkceParams = stringifyURIQuery.stringifyURIQuery({
|
|
228
257
|
code_challenge: encodeBase64URL.encodeBase64URL(digest),
|
|
229
258
|
code_challenge_method: 'S256',
|
|
230
|
-
state: state,
|
|
231
259
|
});
|
|
232
|
-
oauthLoginUrl = `${
|
|
233
|
-
}
|
|
234
|
-
if (!((_c = providersWaitingOauthMessage.current) === null || _c === void 0 ? void 0 : _c[provider])) {
|
|
235
|
-
window.addEventListener('message', handleAuthWindowMessage);
|
|
236
|
-
providersWaitingOauthMessage.current = Object.assign(Object.assign({}, providersWaitingOauthMessage.current), { [provider]: true });
|
|
260
|
+
oauthLoginUrl = `${oauthLoginUrl}&${pkceParams}`;
|
|
237
261
|
}
|
|
238
262
|
authWindow === null || authWindow === void 0 ? void 0 : authWindow.location.assign(oauthLoginUrl);
|
|
239
263
|
if (!providersWithoutWindowOpenerRefence.includes(provider)) {
|
|
@@ -260,10 +284,10 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, }) => {
|
|
|
260
284
|
shouldPool.current = true;
|
|
261
285
|
poolOauthResult(provider, state);
|
|
262
286
|
authWindowInterval.current = setInterval(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
263
|
-
var
|
|
287
|
+
var _f;
|
|
264
288
|
shouldPool.current = false;
|
|
265
289
|
// clear all states/listeners, assuming user closed the window before completing oauth
|
|
266
|
-
if ((
|
|
290
|
+
if ((_f = providersWaitingOauthMessage.current) === null || _f === void 0 ? void 0 : _f[provider]) {
|
|
267
291
|
clearListeners();
|
|
268
292
|
handleError(types.SocialOAuthErrorCode.OAUTH_WINDOW_TIMEOUT, `Connecting ${provider} account window timeout.`);
|
|
269
293
|
}
|
|
@@ -24,11 +24,13 @@ import { stringifyURIQuery } from '../../functions/stringifyURIQuery/stringifyUR
|
|
|
24
24
|
import { digestSHA256 } from '../../functions/digestSHA256/digestSHA256.js';
|
|
25
25
|
import { encodeBase64URL } from '../../functions/encodeBase64URL/encodeBase64URL.js';
|
|
26
26
|
import { getOauthLoginUrl } from '../../functions/getOauthLoginUrl/getOauthLoginUrl.js';
|
|
27
|
+
import { getProviderByType } from '../../functions/getProviderByType/getProviderByType.js';
|
|
27
28
|
import { useCreateUserProfileByJWTCallback } from '../useCreateUserProfileByJWTCallback/useCreateUserProfileByJWTCallback.js';
|
|
28
29
|
import { useErrorContext } from '../../../context/ErrorContext/ErrorContext.js';
|
|
29
30
|
import { useEmbeddedWallet } from '../useEmbeddedWallet/useEmbeddedWallet.js';
|
|
30
31
|
|
|
31
32
|
const socialProviders = [
|
|
33
|
+
'apple',
|
|
32
34
|
'discord',
|
|
33
35
|
'facebook',
|
|
34
36
|
'github',
|
|
@@ -178,19 +180,37 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, }) => {
|
|
|
178
180
|
providersWaitingOauthMessage.current = Object.assign(Object.assign({}, providersWaitingOauthMessage.current), { [provider]: false });
|
|
179
181
|
};
|
|
180
182
|
const handleAuthWindowMessage = (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
181
|
-
var _d;
|
|
183
|
+
var _d, _e;
|
|
182
184
|
const message = event.data;
|
|
183
185
|
const isAuthorizationMessage = (message === null || message === void 0 ? void 0 : message.type) === 'authorization_response';
|
|
184
186
|
if (isAuthorizationMessage) {
|
|
185
187
|
logger.debug('Message received', { data: message });
|
|
186
188
|
}
|
|
187
|
-
const
|
|
189
|
+
const apiProvider = getProviderByType((_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) !== null && _d !== void 0 ? _d : [], provider);
|
|
190
|
+
if (!(apiProvider === null || apiProvider === void 0 ? void 0 : apiProvider.redirectUrl)) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
let expectedOrigin = '';
|
|
194
|
+
try {
|
|
195
|
+
const redirectUri = new URL(apiProvider.redirectUrl);
|
|
196
|
+
expectedOrigin = redirectUri.origin;
|
|
197
|
+
}
|
|
198
|
+
catch (e) {
|
|
199
|
+
logger.error('Failed to parse social provider redirect url', {
|
|
200
|
+
error: e,
|
|
201
|
+
});
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const isExpectedOrigin = event.origin === expectedOrigin;
|
|
205
|
+
const isValidMessage = isAuthorizationMessage &&
|
|
206
|
+
(message === null || message === void 0 ? void 0 : message.provider) === provider &&
|
|
207
|
+
isExpectedOrigin;
|
|
188
208
|
// don't process invalid messages for provider
|
|
189
209
|
if (!isValidMessage) {
|
|
190
210
|
return;
|
|
191
211
|
}
|
|
192
212
|
setIsProcessing(true);
|
|
193
|
-
if (!((
|
|
213
|
+
if (!((_e = providersWaitingOauthMessage.current) === null || _e === void 0 ? void 0 : _e[provider])) {
|
|
194
214
|
handleError(SocialOAuthErrorCode.SESSION_TIMEOUT, `Connecting ${provider} account session timeout.`);
|
|
195
215
|
return;
|
|
196
216
|
}
|
|
@@ -217,19 +237,23 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, }) => {
|
|
|
217
237
|
handleError(SocialOAuthErrorCode.NO_OAUTH_URL, `Failed to get login url to connect social account: ${provider}`);
|
|
218
238
|
return;
|
|
219
239
|
}
|
|
220
|
-
|
|
240
|
+
if (!((_c = providersWaitingOauthMessage.current) === null || _c === void 0 ? void 0 : _c[provider])) {
|
|
241
|
+
window.addEventListener('message', handleAuthWindowMessage);
|
|
242
|
+
providersWaitingOauthMessage.current = Object.assign(Object.assign({}, providersWaitingOauthMessage.current), { [provider]: true });
|
|
243
|
+
}
|
|
244
|
+
// add state param for all providers
|
|
245
|
+
const stateParam = stringifyURIQuery({
|
|
246
|
+
state,
|
|
247
|
+
});
|
|
248
|
+
let oauthLoginUrl = `${loginUrl}&${stateParam}`;
|
|
249
|
+
// only add pkce params for providers that support/require it
|
|
221
250
|
if (providersRequiringPkce.includes(provider)) {
|
|
222
251
|
const digest = yield digestSHA256(verifier);
|
|
223
252
|
const pkceParams = stringifyURIQuery({
|
|
224
253
|
code_challenge: encodeBase64URL(digest),
|
|
225
254
|
code_challenge_method: 'S256',
|
|
226
|
-
state: state,
|
|
227
255
|
});
|
|
228
|
-
oauthLoginUrl = `${
|
|
229
|
-
}
|
|
230
|
-
if (!((_c = providersWaitingOauthMessage.current) === null || _c === void 0 ? void 0 : _c[provider])) {
|
|
231
|
-
window.addEventListener('message', handleAuthWindowMessage);
|
|
232
|
-
providersWaitingOauthMessage.current = Object.assign(Object.assign({}, providersWaitingOauthMessage.current), { [provider]: true });
|
|
256
|
+
oauthLoginUrl = `${oauthLoginUrl}&${pkceParams}`;
|
|
233
257
|
}
|
|
234
258
|
authWindow === null || authWindow === void 0 ? void 0 : authWindow.location.assign(oauthLoginUrl);
|
|
235
259
|
if (!providersWithoutWindowOpenerRefence.includes(provider)) {
|
|
@@ -256,10 +280,10 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, }) => {
|
|
|
256
280
|
shouldPool.current = true;
|
|
257
281
|
poolOauthResult(provider, state);
|
|
258
282
|
authWindowInterval.current = setInterval(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
259
|
-
var
|
|
283
|
+
var _f;
|
|
260
284
|
shouldPool.current = false;
|
|
261
285
|
// clear all states/listeners, assuming user closed the window before completing oauth
|
|
262
|
-
if ((
|
|
286
|
+
if ((_f = providersWaitingOauthMessage.current) === null || _f === void 0 ? void 0 : _f[provider]) {
|
|
263
287
|
clearListeners();
|
|
264
288
|
handleError(SocialOAuthErrorCode.OAUTH_WINDOW_TIMEOUT, `Connecting ${provider} account window timeout.`);
|
|
265
289
|
}
|
|
@@ -59,7 +59,7 @@ var WalletInformationCard = require('../../../../components/WalletInformationCar
|
|
|
59
59
|
require('../../../../components/MenuList/Dropdown/Dropdown.cjs');
|
|
60
60
|
var useFetchNameService = require('../../../DynamicWidget/hooks/useFetchNameService/useFetchNameService.cjs');
|
|
61
61
|
|
|
62
|
-
const DynamicBridgeWalletCardBody = ({ walletAddress, walletBalance, walletKey,
|
|
62
|
+
const DynamicBridgeWalletCardBody = ({ walletAddress, walletBalance, walletKey, onDisconnectClick }) => {
|
|
63
63
|
const nameService = useFetchNameService.useFetchNameService(walletAddress);
|
|
64
64
|
const options = [
|
|
65
65
|
{
|
|
@@ -76,8 +76,8 @@ const DynamicBridgeWalletCardBody = ({ walletAddress, walletBalance, walletKey,
|
|
|
76
76
|
},
|
|
77
77
|
{
|
|
78
78
|
Icon: null,
|
|
79
|
-
callback: () =>
|
|
80
|
-
hide: !
|
|
79
|
+
callback: () => onDisconnectClick === null || onDisconnectClick === void 0 ? void 0 : onDisconnectClick(),
|
|
80
|
+
hide: !onDisconnectClick,
|
|
81
81
|
text: 'Disconnect',
|
|
82
82
|
},
|
|
83
83
|
];
|
|
@@ -3,6 +3,6 @@ export type DynamicBridgeWalletCardBodyProps = {
|
|
|
3
3
|
walletKey: string;
|
|
4
4
|
walletAddress: string;
|
|
5
5
|
walletBalance?: ReactElement;
|
|
6
|
-
|
|
6
|
+
onDisconnectClick?: () => void;
|
|
7
7
|
};
|
|
8
8
|
export declare const DynamicBridgeWalletCardBody: FC<DynamicBridgeWalletCardBodyProps>;
|
|
@@ -55,7 +55,7 @@ import { WalletInformationCard } from '../../../../components/WalletInformationC
|
|
|
55
55
|
import '../../../../components/MenuList/Dropdown/Dropdown.js';
|
|
56
56
|
import { useFetchNameService } from '../../../DynamicWidget/hooks/useFetchNameService/useFetchNameService.js';
|
|
57
57
|
|
|
58
|
-
const DynamicBridgeWalletCardBody = ({ walletAddress, walletBalance, walletKey,
|
|
58
|
+
const DynamicBridgeWalletCardBody = ({ walletAddress, walletBalance, walletKey, onDisconnectClick }) => {
|
|
59
59
|
const nameService = useFetchNameService(walletAddress);
|
|
60
60
|
const options = [
|
|
61
61
|
{
|
|
@@ -72,8 +72,8 @@ const DynamicBridgeWalletCardBody = ({ walletAddress, walletBalance, walletKey,
|
|
|
72
72
|
},
|
|
73
73
|
{
|
|
74
74
|
Icon: null,
|
|
75
|
-
callback: () =>
|
|
76
|
-
hide: !
|
|
75
|
+
callback: () => onDisconnectClick === null || onDisconnectClick === void 0 ? void 0 : onDisconnectClick(),
|
|
76
|
+
hide: !onDisconnectClick,
|
|
77
77
|
text: 'Disconnect',
|
|
78
78
|
},
|
|
79
79
|
];
|
|
@@ -64,7 +64,7 @@ var DynamicBridgeWalletCardBody = require('../../components/DynamicBridgeWalletC
|
|
|
64
64
|
var DynamicBridgeWidgetEmptyCard = require('../../components/DynamicBridgeWidgetEmptyCard/DynamicBridgeWidgetEmptyCard.cjs');
|
|
65
65
|
|
|
66
66
|
const WalletsView = () => {
|
|
67
|
-
const {
|
|
67
|
+
const { disconnectWallet, walletsByChain, connectedWallets } = useInternalDynamicContext.useInternalDynamicContext();
|
|
68
68
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: 'dynamic-bridge-widget-wallets-view', "data-testid": 'dynamic-bridge-wget-wallets-view', children: walletsByChain === null || walletsByChain === void 0 ? void 0 : walletsByChain.map(({ chain }) => {
|
|
69
69
|
const chainWallets = connectedWallets.filter(({ chain: walletChain }) => chain === walletChain);
|
|
70
70
|
// "Connect wallet" for empty chains
|
|
@@ -73,7 +73,7 @@ const WalletsView = () => {
|
|
|
73
73
|
const WalletIcon = getChainIcon.getChainIcon(chain);
|
|
74
74
|
const walletInfo = walletConnectorCore.getChainInfo(chain);
|
|
75
75
|
// Wallets info for chains with connected wallets
|
|
76
|
-
return chainWallets.map(({ connector, address, id }) => (jsxRuntime.jsx(DynamicBridgeWalletCard.DynamicBridgeWalletCard, { networkIcon: jsxRuntime.jsx(WalletIcon, {}), networkName: walletInfo === null || walletInfo === void 0 ? void 0 : walletInfo.displayName, children: jsxRuntime.jsx(DynamicBridgeWalletCardBody.DynamicBridgeWalletCardBody, { walletKey: connector.key, walletAddress: address, walletBalance: jsxRuntime.jsx(Balance.Balance, { address: address, connector: connector, network: chain }),
|
|
76
|
+
return chainWallets.map(({ connector, address, id }) => (jsxRuntime.jsx(DynamicBridgeWalletCard.DynamicBridgeWalletCard, { networkIcon: jsxRuntime.jsx(WalletIcon, {}), networkName: walletInfo === null || walletInfo === void 0 ? void 0 : walletInfo.displayName, children: jsxRuntime.jsx(DynamicBridgeWalletCardBody.DynamicBridgeWalletCardBody, { walletKey: connector.key, walletAddress: address, walletBalance: jsxRuntime.jsx(Balance.Balance, { address: address, connector: connector, network: chain }), onDisconnectClick: () => disconnectWallet(id) }) }, `${id}-${connector.name}`)));
|
|
77
77
|
}) }), jsxRuntime.jsx(DynamicWidgetFooter.DynamicWidgetFooter, { children: jsxRuntime.jsx(LogoutButton.LogoutButton, { buttonClassName: 'dynamic-bridge-widget-wallets-view__logout-button', isTextButton: true }) })] }));
|
|
78
78
|
};
|
|
79
79
|
|
|
@@ -60,7 +60,7 @@ import { DynamicBridgeWalletCardBody } from '../../components/DynamicBridgeWalle
|
|
|
60
60
|
import { DynamicBridgeWidgetEmptyCard } from '../../components/DynamicBridgeWidgetEmptyCard/DynamicBridgeWidgetEmptyCard.js';
|
|
61
61
|
|
|
62
62
|
const WalletsView = () => {
|
|
63
|
-
const {
|
|
63
|
+
const { disconnectWallet, walletsByChain, connectedWallets } = useInternalDynamicContext();
|
|
64
64
|
return (jsxs(Fragment, { children: [jsx("div", { className: 'dynamic-bridge-widget-wallets-view', "data-testid": 'dynamic-bridge-wget-wallets-view', children: walletsByChain === null || walletsByChain === void 0 ? void 0 : walletsByChain.map(({ chain }) => {
|
|
65
65
|
const chainWallets = connectedWallets.filter(({ chain: walletChain }) => chain === walletChain);
|
|
66
66
|
// "Connect wallet" for empty chains
|
|
@@ -69,7 +69,7 @@ const WalletsView = () => {
|
|
|
69
69
|
const WalletIcon = getChainIcon(chain);
|
|
70
70
|
const walletInfo = getChainInfo(chain);
|
|
71
71
|
// Wallets info for chains with connected wallets
|
|
72
|
-
return chainWallets.map(({ connector, address, id }) => (jsx(DynamicBridgeWalletCard, { networkIcon: jsx(WalletIcon, {}), networkName: walletInfo === null || walletInfo === void 0 ? void 0 : walletInfo.displayName, children: jsx(DynamicBridgeWalletCardBody, { walletKey: connector.key, walletAddress: address, walletBalance: jsx(Balance, { address: address, connector: connector, network: chain }),
|
|
72
|
+
return chainWallets.map(({ connector, address, id }) => (jsx(DynamicBridgeWalletCard, { networkIcon: jsx(WalletIcon, {}), networkName: walletInfo === null || walletInfo === void 0 ? void 0 : walletInfo.displayName, children: jsx(DynamicBridgeWalletCardBody, { walletKey: connector.key, walletAddress: address, walletBalance: jsx(Balance, { address: address, connector: connector, network: chain }), onDisconnectClick: () => disconnectWallet(id) }) }, `${id}-${connector.name}`)));
|
|
73
73
|
}) }), jsx(DynamicWidgetFooter, { children: jsx(LogoutButton, { buttonClassName: 'dynamic-bridge-widget-wallets-view__logout-button', isTextButton: true }) })] }));
|
|
74
74
|
};
|
|
75
75
|
|
|
@@ -27,15 +27,13 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
27
27
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
28
28
|
|
|
29
29
|
const SecondaryWallets = ({ hideUnlinkAction = false }) => {
|
|
30
|
-
const {
|
|
30
|
+
const { disconnectWallet, getConnectedWalletById, walletsByChain } = useInternalDynamicContext.useInternalDynamicContext();
|
|
31
31
|
const wallet = getConnectedWalletById('connect-wallet-1');
|
|
32
32
|
const NetworkIcon = wallet && getChainIcon.getChainIcon(wallet === null || wallet === void 0 ? void 0 : wallet.chain);
|
|
33
33
|
const networkInfo = wallet && walletConnectorCore.getChainInfo(wallet === null || wallet === void 0 ? void 0 : wallet.chain);
|
|
34
34
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!wallet && (jsxRuntime.jsx(DynamicBridgeWidgetEmptyCard.DynamicBridgeWidgetEmptyCard, { chain: walletsByChain === null || walletsByChain === void 0 ? void 0 : walletsByChain[1].chain })), wallet && NetworkIcon && (jsxRuntime.jsx(DynamicBridgeWalletCard.DynamicBridgeWalletCard, { networkIcon: jsxRuntime.jsx(NetworkIcon, {}), networkName: networkInfo === null || networkInfo === void 0 ? void 0 : networkInfo.displayName, children: jsxRuntime.jsx(DynamicBridgeWalletCardBody.DynamicBridgeWalletCardBody, { walletKey: wallet.connector.key, walletAddress: wallet.address, walletBalance:
|
|
35
35
|
// eslint-disable-next-line react/jsx-wrap-multilines
|
|
36
|
-
jsxRuntime.jsx(Balance.Balance, { address: wallet.address, connector: wallet.connector, network: wallet.chain }),
|
|
37
|
-
? () => unlinkConnectedWallet(wallet.id)
|
|
38
|
-
: undefined }, wallet.id) }))] }));
|
|
36
|
+
jsxRuntime.jsx(Balance.Balance, { address: wallet.address, connector: wallet.connector, network: wallet.chain }), onDisconnectClick: !hideUnlinkAction ? () => disconnectWallet(wallet.id) : undefined }, wallet.id) }))] }));
|
|
39
37
|
};
|
|
40
38
|
const MemoSecondaryWallets = React__default["default"].memo(SecondaryWallets);
|
|
41
39
|
|
|
@@ -19,15 +19,13 @@ import { useInternalDynamicContext } from '../../../../../../context/DynamicCont
|
|
|
19
19
|
import { DynamicBridgeWidgetEmptyCard } from '../../../../components/DynamicBridgeWidgetEmptyCard/DynamicBridgeWidgetEmptyCard.js';
|
|
20
20
|
|
|
21
21
|
const SecondaryWallets = ({ hideUnlinkAction = false }) => {
|
|
22
|
-
const {
|
|
22
|
+
const { disconnectWallet, getConnectedWalletById, walletsByChain } = useInternalDynamicContext();
|
|
23
23
|
const wallet = getConnectedWalletById('connect-wallet-1');
|
|
24
24
|
const NetworkIcon = wallet && getChainIcon(wallet === null || wallet === void 0 ? void 0 : wallet.chain);
|
|
25
25
|
const networkInfo = wallet && getChainInfo(wallet === null || wallet === void 0 ? void 0 : wallet.chain);
|
|
26
26
|
return (jsxs(Fragment, { children: [!wallet && (jsx(DynamicBridgeWidgetEmptyCard, { chain: walletsByChain === null || walletsByChain === void 0 ? void 0 : walletsByChain[1].chain })), wallet && NetworkIcon && (jsx(DynamicBridgeWalletCard, { networkIcon: jsx(NetworkIcon, {}), networkName: networkInfo === null || networkInfo === void 0 ? void 0 : networkInfo.displayName, children: jsx(DynamicBridgeWalletCardBody, { walletKey: wallet.connector.key, walletAddress: wallet.address, walletBalance:
|
|
27
27
|
// eslint-disable-next-line react/jsx-wrap-multilines
|
|
28
|
-
jsx(Balance, { address: wallet.address, connector: wallet.connector, network: wallet.chain }),
|
|
29
|
-
? () => unlinkConnectedWallet(wallet.id)
|
|
30
|
-
: undefined }, wallet.id) }))] }));
|
|
28
|
+
jsx(Balance, { address: wallet.address, connector: wallet.connector, network: wallet.chain }), onDisconnectClick: !hideUnlinkAction ? () => disconnectWallet(wallet.id) : undefined }, wallet.id) }))] }));
|
|
31
29
|
};
|
|
32
30
|
const MemoSecondaryWallets = React__default.memo(SecondaryWallets);
|
|
33
31
|
|