@b3dotfun/sdk 0.1.69-alpha.1 → 0.1.69-alpha.10
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/dist/cjs/anyspend/react/components/AnySpendStakeB3.js +1 -1
- package/dist/cjs/anyspend/react/components/AnySpendStakeB3ExactIn.js +1 -1
- package/dist/cjs/anyspend/react/components/checkout/CheckoutPaymentPanel.js +2 -4
- package/dist/cjs/anyspend/react/components/checkout/CheckoutSuccess.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/checkout/CheckoutSuccess.js +5 -3
- package/dist/cjs/anyspend/react/components/checkout/FiatCheckoutPanel.js +1 -2
- package/dist/cjs/anyspend/react/components/checkout/KycGate.js +1 -2
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +5 -0
- package/dist/cjs/anyspend/react/components/common/OrderStatus.js +37 -6
- package/dist/cjs/anyspend/react/components/common/StepProgress.d.ts +2 -0
- package/dist/cjs/anyspend/react/components/common/StepProgress.js +7 -2
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +4 -6
- package/dist/cjs/anyspend/react/hooks/useKycStatus.d.ts +3 -1
- package/dist/cjs/anyspend/react/hooks/useKycStatus.js +11 -7
- package/dist/cjs/app.shared.js +9 -7
- package/dist/cjs/global-account/react/components/B3DynamicModal.js +5 -2
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +2 -1
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +2 -2
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +2 -1
- package/dist/cjs/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +3 -1
- package/dist/cjs/global-account/react/components/B3Provider/LocalSDKProvider.js +3 -1
- package/dist/cjs/global-account/react/components/ManageAccount/SessionDurationContent.d.ts +5 -0
- package/dist/cjs/global-account/react/components/ManageAccount/SessionDurationContent.js +57 -0
- package/dist/cjs/global-account/react/components/ManageAccount/SettingsContent.js +12 -29
- package/dist/cjs/global-account/react/components/SignInWithB3/components/AuthButton.js +10 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +96 -15
- package/dist/cjs/global-account/react/components/SignInWithB3/utils/signInUtils.d.ts +5 -3
- package/dist/cjs/global-account/react/components/SignInWithB3/utils/signInUtils.js +15 -2
- package/dist/cjs/global-account/react/components/Toast/ToastContext.d.ts +3 -0
- package/dist/cjs/global-account/react/components/Toast/ToastContext.js +30 -7
- package/dist/cjs/global-account/react/hooks/useAuth.js +26 -15
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +23 -12
- package/dist/cjs/global-account/react/hooks/useConnect.d.ts +2 -2
- package/dist/cjs/global-account/react/hooks/useFirstEOA.d.ts +8 -8
- package/dist/cjs/global-account/react/hooks/useTWAuth.js +0 -1
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +10 -1
- package/dist/cjs/global-account/react/utils/createWagmiConfig.d.ts +0 -18
- package/dist/cjs/global-account/react/utils/createWagmiConfig.js +0 -17
- package/dist/cjs/shared/utils/session-duration.d.ts +15 -0
- package/dist/cjs/shared/utils/session-duration.js +69 -0
- package/dist/esm/anyspend/react/components/AnySpendStakeB3.js +2 -2
- package/dist/esm/anyspend/react/components/AnySpendStakeB3ExactIn.js +2 -2
- package/dist/esm/anyspend/react/components/checkout/CheckoutPaymentPanel.js +2 -4
- package/dist/esm/anyspend/react/components/checkout/CheckoutSuccess.d.ts +2 -1
- package/dist/esm/anyspend/react/components/checkout/CheckoutSuccess.js +5 -3
- package/dist/esm/anyspend/react/components/checkout/FiatCheckoutPanel.js +2 -3
- package/dist/esm/anyspend/react/components/checkout/KycGate.js +2 -3
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +6 -1
- package/dist/esm/anyspend/react/components/common/OrderStatus.js +34 -3
- package/dist/esm/anyspend/react/components/common/StepProgress.d.ts +2 -0
- package/dist/esm/anyspend/react/components/common/StepProgress.js +4 -2
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +5 -7
- package/dist/esm/anyspend/react/hooks/useKycStatus.d.ts +3 -1
- package/dist/esm/anyspend/react/hooks/useKycStatus.js +9 -5
- package/dist/esm/app.shared.js +9 -7
- package/dist/esm/global-account/react/components/B3DynamicModal.js +5 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +2 -1
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +2 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +2 -1
- package/dist/esm/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +3 -1
- package/dist/esm/global-account/react/components/B3Provider/LocalSDKProvider.js +3 -1
- package/dist/esm/global-account/react/components/ManageAccount/SessionDurationContent.d.ts +5 -0
- package/dist/esm/global-account/react/components/ManageAccount/SessionDurationContent.js +52 -0
- package/dist/esm/global-account/react/components/ManageAccount/SettingsContent.js +12 -29
- package/dist/esm/global-account/react/components/SignInWithB3/components/AuthButton.js +11 -2
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +100 -19
- package/dist/esm/global-account/react/components/SignInWithB3/utils/signInUtils.d.ts +5 -3
- package/dist/esm/global-account/react/components/SignInWithB3/utils/signInUtils.js +14 -1
- package/dist/esm/global-account/react/components/Toast/ToastContext.d.ts +3 -0
- package/dist/esm/global-account/react/components/Toast/ToastContext.js +30 -7
- package/dist/esm/global-account/react/hooks/useAuth.js +28 -17
- package/dist/esm/global-account/react/hooks/useAuthentication.js +24 -13
- package/dist/esm/global-account/react/hooks/useConnect.d.ts +2 -2
- package/dist/esm/global-account/react/hooks/useFirstEOA.d.ts +8 -8
- package/dist/esm/global-account/react/hooks/useTWAuth.js +0 -1
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +10 -1
- package/dist/esm/global-account/react/utils/createWagmiConfig.d.ts +0 -18
- package/dist/esm/global-account/react/utils/createWagmiConfig.js +0 -16
- package/dist/esm/shared/utils/session-duration.d.ts +15 -0
- package/dist/esm/shared/utils/session-duration.js +64 -0
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/components/checkout/CheckoutSuccess.d.ts +2 -1
- package/dist/types/anyspend/react/components/common/StepProgress.d.ts +2 -0
- package/dist/types/anyspend/react/hooks/useKycStatus.d.ts +3 -1
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +2 -1
- package/dist/types/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +3 -1
- package/dist/types/global-account/react/components/ManageAccount/SessionDurationContent.d.ts +5 -0
- package/dist/types/global-account/react/components/SignInWithB3/utils/signInUtils.d.ts +5 -3
- package/dist/types/global-account/react/components/Toast/ToastContext.d.ts +3 -0
- package/dist/types/global-account/react/hooks/useConnect.d.ts +2 -2
- package/dist/types/global-account/react/hooks/useFirstEOA.d.ts +8 -8
- package/dist/types/global-account/react/stores/useModalStore.d.ts +10 -1
- package/dist/types/global-account/react/utils/createWagmiConfig.d.ts +0 -18
- package/dist/types/shared/utils/session-duration.d.ts +15 -0
- package/package.json +2 -1
- package/src/anyspend/react/components/AnySpendStakeB3.tsx +2 -2
- package/src/anyspend/react/components/AnySpendStakeB3ExactIn.tsx +2 -2
- package/src/anyspend/react/components/checkout/CheckoutPaymentPanel.tsx +2 -4
- package/src/anyspend/react/components/checkout/CheckoutSuccess.tsx +13 -3
- package/src/anyspend/react/components/checkout/FiatCheckoutPanel.tsx +9 -3
- package/src/anyspend/react/components/checkout/KycGate.tsx +8 -3
- package/src/anyspend/react/components/common/OrderDetails.tsx +8 -0
- package/src/anyspend/react/components/common/OrderStatus.tsx +38 -3
- package/src/anyspend/react/components/common/StepProgress.tsx +15 -5
- package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +5 -7
- package/src/anyspend/react/hooks/useKycStatus.ts +8 -5
- package/src/app.shared.ts +9 -8
- package/src/global-account/react/components/B3DynamicModal.tsx +5 -2
- package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +2 -1
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +7 -1
- package/src/global-account/react/components/B3Provider/LocalSDKProvider.tsx +5 -0
- package/src/global-account/react/components/ManageAccount/SessionDurationContent.tsx +107 -0
- package/src/global-account/react/components/ManageAccount/SettingsContent.tsx +28 -30
- package/src/global-account/react/components/SignInWithB3/components/AuthButton.tsx +21 -2
- package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +207 -54
- package/src/global-account/react/components/SignInWithB3/utils/signInUtils.ts +19 -3
- package/src/global-account/react/components/Toast/ToastContext.tsx +39 -7
- package/src/global-account/react/hooks/useAuth.ts +28 -17
- package/src/global-account/react/hooks/useAuthentication.ts +24 -13
- package/src/global-account/react/hooks/useConnect.tsx +2 -2
- package/src/global-account/react/hooks/useTWAuth.tsx +0 -1
- package/src/global-account/react/stores/useModalStore.ts +11 -0
- package/src/global-account/react/utils/createWagmiConfig.tsx +0 -18
- package/src/shared/utils/session-duration.ts +64 -0
- package/src/types/torph.d.ts +4 -0
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
7
|
const react_1 = require("../../../../global-account/react");
|
|
8
8
|
const thirdweb_1 = require("../../../../shared/utils/thirdweb");
|
|
9
|
+
const session_duration_1 = require("../../../../shared/utils/session-duration");
|
|
9
10
|
const lucide_react_1 = require("lucide-react");
|
|
10
11
|
const react_2 = require("react");
|
|
11
12
|
const react_3 = require("thirdweb/react");
|
|
@@ -16,47 +17,29 @@ const SettingsProfileCard_1 = __importDefault(require("./SettingsProfileCard"));
|
|
|
16
17
|
const SettingsContent = ({ partnerId, onLogout, chain, }) => {
|
|
17
18
|
const setB3ModalContentType = (0, react_1.useModalStore)(state => state.setB3ModalContentType);
|
|
18
19
|
const setB3ModalOpen = (0, react_1.useModalStore)(state => state.setB3ModalOpen);
|
|
19
|
-
const { logout } = (0, react_1.useAuthentication)(partnerId);
|
|
20
|
+
const { logout, user } = (0, react_1.useAuthentication)(partnerId);
|
|
20
21
|
const [logoutLoading, setLogoutLoading] = (0, react_2.useState)(false);
|
|
22
|
+
const sessionDays = (0, session_duration_1.getSessionDurationDays)(user?.preferences, partnerId);
|
|
21
23
|
const { data: profilesRaw = [] } = (0, react_3.useProfiles)({ client: thirdweb_1.client });
|
|
22
24
|
const profiles = profilesRaw.filter((profile) => !["custom_auth_endpoint"].includes(profile.type));
|
|
23
25
|
const handleNavigate = (type) => {
|
|
24
26
|
if (type === "home") {
|
|
25
|
-
setB3ModalContentType({
|
|
26
|
-
type: "manageAccount",
|
|
27
|
-
chain,
|
|
28
|
-
partnerId,
|
|
29
|
-
onLogout,
|
|
30
|
-
activeTab: "home",
|
|
31
|
-
});
|
|
27
|
+
setB3ModalContentType({ type: "manageAccount", chain, partnerId, onLogout, activeTab: "home" });
|
|
32
28
|
}
|
|
33
29
|
else if (type === "swap") {
|
|
34
|
-
setB3ModalContentType({
|
|
35
|
-
type: "manageAccount",
|
|
36
|
-
chain,
|
|
37
|
-
partnerId,
|
|
38
|
-
onLogout,
|
|
39
|
-
activeTab: "tokens",
|
|
40
|
-
});
|
|
30
|
+
setB3ModalContentType({ type: "manageAccount", chain, partnerId, onLogout, activeTab: "tokens" });
|
|
41
31
|
}
|
|
42
32
|
else if (type === "linkAccount") {
|
|
43
|
-
setB3ModalContentType({
|
|
44
|
-
type: "linkAccount",
|
|
45
|
-
chain,
|
|
46
|
-
partnerId,
|
|
47
|
-
});
|
|
33
|
+
setB3ModalContentType({ type: "linkAccount", chain, partnerId });
|
|
48
34
|
}
|
|
49
35
|
else if (type === "notifications") {
|
|
50
|
-
setB3ModalContentType({
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
36
|
+
setB3ModalContentType({ type: "notifications", chain, partnerId });
|
|
37
|
+
}
|
|
38
|
+
else if (type === "sessionDuration") {
|
|
39
|
+
setB3ModalContentType({ type: "sessionDuration", chain, partnerId });
|
|
55
40
|
}
|
|
56
41
|
else {
|
|
57
|
-
setB3ModalContentType({
|
|
58
|
-
type: "avatarEditor",
|
|
59
|
-
});
|
|
42
|
+
setB3ModalContentType({ type: "avatarEditor" });
|
|
60
43
|
}
|
|
61
44
|
setB3ModalOpen(true);
|
|
62
45
|
};
|
|
@@ -67,7 +50,7 @@ const SettingsContent = ({ partnerId, onLogout, chain, }) => {
|
|
|
67
50
|
setB3ModalOpen(false);
|
|
68
51
|
setLogoutLoading(false);
|
|
69
52
|
};
|
|
70
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: "flex h-[470px] flex-col", children: [(0, jsx_runtime_1.jsx)(ModalHeader_1.default, { showBackButton: false, showCloseButton: false, title: "Settings" }), (0, jsx_runtime_1.jsx)("div", { className: "p-5", children: (0, jsx_runtime_1.jsx)("div", { className: "b3-modal-settings-profile-card dark:border-b3-line dark:bg-b3-background flex items-center rounded-xl border border-[#e4e4e7] bg-[#f4f4f5] p-4", children: (0, jsx_runtime_1.jsx)(SettingsProfileCard_1.default, {}) }) }), (0, jsx_runtime_1.jsxs)("div", { className: "space-y-3 px-5", children: [(0, jsx_runtime_1.jsx)(SettingsMenuItem_1.default, { icon: (0, jsx_runtime_1.jsx)("svg", { width: "40", height: "40", viewBox: "0 0 40 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: (0, jsx_runtime_1.jsx)("path", { d: "M0 12C0 5.37258 5.37258 0 12 0H28C34.6274 0 40 5.37258 40 12V28C40 34.6274 34.6274 40 28 40H12C5.37258 40 0 34.6274 0 28V12Z", fill: "#F4F4F5" }) }), title: "Linked Accounts", subtitle: `${profiles.length} connected account${profiles.length > 1 ? "s" : ""}`, onClick: () => handleNavigate("linkAccount") }), (0, jsx_runtime_1.jsx)(SettingsMenuItem_1.default, { icon: (0, jsx_runtime_1.jsx)("svg", { width: "40", height: "40", viewBox: "0 0 40 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: (0, jsx_runtime_1.jsx)("path", { d: "M0 12C0 5.37258 5.37258 0 12 0H28C34.6274 0 40 5.37258 40 12V28C40 34.6274 34.6274 40 28 40H12C5.37258 40 0 34.6274 0 28V12Z", fill: "#F4F4F5" }) }), title: "Notifications", subtitle: "Manage your notifications", onClick: () => handleNavigate("notifications") })] }), (0, jsx_runtime_1.jsx)("div", { className: "mt-auto px-5 pb-5", children: (0, jsx_runtime_1.jsxs)("button", { className: "b3-modal-sign-out-button border-b3-line hover:bg-b3-line bg-b3-background dark:bg-b3-background dark:border-b3-line dark:hover:bg-b3-line/80 flex w-full items-center justify-center gap-1.5 rounded-xl border border-solid p-3 transition-colors", onClick: onLogoutEnhanced, disabled: logoutLoading, style: {
|
|
53
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "flex h-[470px] flex-col", children: [(0, jsx_runtime_1.jsx)(ModalHeader_1.default, { showBackButton: false, showCloseButton: false, title: "Settings" }), (0, jsx_runtime_1.jsx)("div", { className: "p-5", children: (0, jsx_runtime_1.jsx)("div", { className: "b3-modal-settings-profile-card dark:border-b3-line dark:bg-b3-background flex items-center rounded-xl border border-[#e4e4e7] bg-[#f4f4f5] p-4", children: (0, jsx_runtime_1.jsx)(SettingsProfileCard_1.default, {}) }) }), (0, jsx_runtime_1.jsxs)("div", { className: "space-y-3 px-5", children: [(0, jsx_runtime_1.jsx)(SettingsMenuItem_1.default, { icon: (0, jsx_runtime_1.jsx)("svg", { width: "40", height: "40", viewBox: "0 0 40 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: (0, jsx_runtime_1.jsx)("path", { d: "M0 12C0 5.37258 5.37258 0 12 0H28C34.6274 0 40 5.37258 40 12V28C40 34.6274 34.6274 40 28 40H12C5.37258 40 0 34.6274 0 28V12Z", fill: "#F4F4F5" }) }), title: "Linked Accounts", subtitle: `${profiles.length} connected account${profiles.length > 1 ? "s" : ""}`, onClick: () => handleNavigate("linkAccount") }), (0, jsx_runtime_1.jsx)(SettingsMenuItem_1.default, { icon: (0, jsx_runtime_1.jsx)("svg", { width: "40", height: "40", viewBox: "0 0 40 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: (0, jsx_runtime_1.jsx)("path", { d: "M0 12C0 5.37258 5.37258 0 12 0H28C34.6274 0 40 5.37258 40 12V28C40 34.6274 34.6274 40 28 40H12C5.37258 40 0 34.6274 0 28V12Z", fill: "#F4F4F5" }) }), title: "Notifications", subtitle: "Manage your notifications", onClick: () => handleNavigate("notifications") }), (0, jsx_runtime_1.jsx)(SettingsMenuItem_1.default, { icon: (0, jsx_runtime_1.jsx)("svg", { width: "40", height: "40", viewBox: "0 0 40 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: (0, jsx_runtime_1.jsx)("path", { d: "M0 12C0 5.37258 5.37258 0 12 0H28C34.6274 0 40 5.37258 40 12V28C40 34.6274 34.6274 40 28 40H12C5.37258 40 0 34.6274 0 28V12Z", fill: "#F4F4F5" }) }), title: "Stay signed in", subtitle: session_duration_1.SESSION_DURATION_LABELS[sessionDays] ?? `${sessionDays} days`, onClick: () => handleNavigate("sessionDuration") })] }), (0, jsx_runtime_1.jsx)("div", { className: "mt-auto px-5 pb-5", children: (0, jsx_runtime_1.jsxs)("button", { type: "button", className: "b3-modal-sign-out-button border-b3-line hover:bg-b3-line bg-b3-background dark:bg-b3-background dark:border-b3-line dark:hover:bg-b3-line/80 flex w-full items-center justify-center gap-1.5 rounded-xl border border-solid p-3 transition-colors", onClick: onLogoutEnhanced, disabled: logoutLoading, style: {
|
|
71
54
|
boxShadow: "inset 0px 0px 0px 1px rgba(10,13,18,0.18), inset 0px -2px 0px 0px rgba(10,13,18,0.05)",
|
|
72
55
|
}, children: [logoutLoading ? ((0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "text-b3-grey animate-spin", size: 20 })) : ((0, jsx_runtime_1.jsx)(SignOutIcon_1.default, { size: 20, className: "text-b3-grey", color: "currentColor" })), (0, jsx_runtime_1.jsx)("p", { className: "text-b3-grey dark:text-b3-foreground-muted font-neue-montreal-semibold text-base", children: "Sign out" })] }) })] }));
|
|
73
56
|
};
|
|
@@ -3,7 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AuthButton = AuthButton;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const Button_1 = require("../../custom/Button");
|
|
6
|
+
const lucide_react_1 = require("lucide-react");
|
|
6
7
|
const signInUtils_1 = require("../utils/signInUtils");
|
|
8
|
+
const fallbackIcons = {
|
|
9
|
+
github: lucide_react_1.Github,
|
|
10
|
+
email: lucide_react_1.Mail,
|
|
11
|
+
};
|
|
7
12
|
function AuthButton({ strategy, onClick, isLoading, }) {
|
|
8
|
-
|
|
13
|
+
const strategyIcon = signInUtils_1.strategyIcons[strategy];
|
|
14
|
+
const strategyLabel = signInUtils_1.strategyLabels[strategy] || strategy;
|
|
15
|
+
const FallbackIcon = fallbackIcons[strategy];
|
|
16
|
+
const buttonLabel = `Sign in with ${strategyLabel}`;
|
|
17
|
+
return ((0, jsx_runtime_1.jsx)(Button_1.Button, { onClick: onClick, disabled: isLoading, "aria-label": buttonLabel, title: buttonLabel, className: "flex w-full items-center justify-center bg-gray-100 px-2 py-3 hover:bg-gray-200 dark:bg-gray-800 dark:hover:bg-gray-700", children: strategyIcon ? ((0, jsx_runtime_1.jsx)("img", { src: strategyIcon, alt: `${strategyLabel} icon`, className: "h-9 w-9" })) : FallbackIcon ? ((0, jsx_runtime_1.jsx)(FallbackIcon, { className: "h-9 w-9 text-gray-900 dark:text-gray-100" })) : ((0, jsx_runtime_1.jsx)("span", { className: "text-sm font-semibold text-gray-900 dark:text-gray-100", children: strategyLabel.charAt(0) })) }, strategy));
|
|
9
18
|
}
|
|
@@ -3,39 +3,53 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.LoginStepCustom = LoginStepCustom;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("../../../../../global-account/react");
|
|
6
|
+
const constants_1 = require("../../../../../shared/constants");
|
|
6
7
|
const debug_1 = require("../../../../../shared/utils/debug");
|
|
7
8
|
const thirdweb_1 = require("../../../../../shared/utils/thirdweb");
|
|
8
9
|
const react_2 = require("react");
|
|
9
10
|
const react_3 = require("thirdweb/react");
|
|
10
11
|
const wallets_1 = require("thirdweb/wallets");
|
|
11
12
|
const debug = (0, debug_1.debugB3React)("LoginStepCustom");
|
|
13
|
+
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
12
14
|
function LoginStepCustom({ onSuccess, onError, chain, strategies, maxInitialWallets = 2, automaticallySetFirstEoa, }) {
|
|
13
15
|
const { partnerId } = (0, react_1.useB3Config)();
|
|
14
16
|
const [isLoading, setIsLoading] = (0, react_2.useState)(false);
|
|
15
17
|
const [showAllWallets, setShowAllWallets] = (0, react_2.useState)(false);
|
|
18
|
+
const [showEmailFlow, setShowEmailFlow] = (0, react_2.useState)(false);
|
|
19
|
+
const [email, setEmail] = (0, react_2.useState)("");
|
|
20
|
+
const [verificationCode, setVerificationCode] = (0, react_2.useState)("");
|
|
21
|
+
const [emailCodeSent, setEmailCodeSent] = (0, react_2.useState)(false);
|
|
22
|
+
const [emailError, setEmailError] = (0, react_2.useState)(null);
|
|
16
23
|
const { connect } = (0, react_1.useConnect)(partnerId, chain);
|
|
17
24
|
const setIsAuthenticating = (0, react_1.useAuthStore)(state => state.setIsAuthenticating);
|
|
18
|
-
const
|
|
19
|
-
const { logout } = (0, react_1.useAuthentication)(partnerId, { skipAutoConnect: true });
|
|
25
|
+
const { connect: onAuthConnect, logout } = (0, react_1.useAuthentication)(partnerId, { skipAutoConnect: true });
|
|
20
26
|
const { connect: connectTW } = (0, react_3.useConnect)();
|
|
27
|
+
const connectedWallets = (0, react_3.useConnectedWallets)();
|
|
21
28
|
// Split strategies into auth and wallet types
|
|
22
29
|
const authStrategies = strategies.filter(s => !(0, react_1.isWalletType)(s));
|
|
23
30
|
const walletStrategies = strategies.filter(react_1.isWalletType);
|
|
24
31
|
const initialWallets = walletStrategies.slice(0, maxInitialWallets);
|
|
25
32
|
const additionalWallets = walletStrategies.slice(maxInitialWallets);
|
|
26
|
-
const
|
|
33
|
+
const authGridColumns = Math.max(1, Math.min(authStrategies.length, 4));
|
|
34
|
+
const resetEmailFlow = () => {
|
|
35
|
+
setShowEmailFlow(false);
|
|
36
|
+
setEmailCodeSent(false);
|
|
37
|
+
setVerificationCode("");
|
|
38
|
+
setEmailError(null);
|
|
39
|
+
};
|
|
40
|
+
const connectWithOptions = async (strategy, options) => {
|
|
27
41
|
try {
|
|
28
42
|
setIsLoading(true);
|
|
29
43
|
debug("setIsAuthenticating:true:3");
|
|
30
44
|
setIsAuthenticating(true);
|
|
31
|
-
const options = (0, react_1.getConnectOptionsFromStrategy)(strategy);
|
|
32
45
|
let connectResult;
|
|
33
|
-
if (automaticallySetFirstEoa) {
|
|
34
|
-
|
|
46
|
+
if (automaticallySetFirstEoa && (0, react_1.isWalletType)(strategy) && options.strategy === "wallet") {
|
|
47
|
+
const walletId = options.wallet?.id;
|
|
48
|
+
if (!walletId) {
|
|
35
49
|
throw new Error("Wallet ID is required");
|
|
36
50
|
}
|
|
37
51
|
connectResult = await connectTW(async () => {
|
|
38
|
-
const wallet = (0, wallets_1.createWallet)(
|
|
52
|
+
const wallet = (0, wallets_1.createWallet)(walletId);
|
|
39
53
|
await wallet.connect({
|
|
40
54
|
client: thirdweb_1.client,
|
|
41
55
|
});
|
|
@@ -43,20 +57,27 @@ function LoginStepCustom({ onSuccess, onError, chain, strategies, maxInitialWall
|
|
|
43
57
|
});
|
|
44
58
|
}
|
|
45
59
|
else {
|
|
46
|
-
// @ts-expect-error we have custom strategies too and we also get things like "apple" isn't assignable to "wallet"
|
|
47
60
|
connectResult = await connect(options);
|
|
48
61
|
}
|
|
49
62
|
const account = connectResult?.getAccount();
|
|
50
63
|
debug("@@connectResult", { connectResult, account, options });
|
|
51
|
-
if (!account)
|
|
64
|
+
if (!account || !connectResult)
|
|
52
65
|
throw new Error("Failed to connect");
|
|
66
|
+
const allConnectedWallets = connectedWallets.length > 0 && connectedWallets.some(wallet => wallet.id === connectResult.id)
|
|
67
|
+
? connectedWallets
|
|
68
|
+
: [connectResult, ...connectedWallets.filter(wallet => wallet.id !== connectResult.id)];
|
|
69
|
+
await onAuthConnect(connectResult, allConnectedWallets);
|
|
53
70
|
await onSuccess(account);
|
|
54
|
-
|
|
71
|
+
if (strategy === "email") {
|
|
72
|
+
resetEmailFlow();
|
|
73
|
+
}
|
|
55
74
|
}
|
|
56
75
|
catch (error) {
|
|
76
|
+
if (strategy === "email") {
|
|
77
|
+
setEmailError(error instanceof Error ? error.message : "Failed to sign in with email");
|
|
78
|
+
}
|
|
57
79
|
await onError?.(error);
|
|
58
80
|
await logout();
|
|
59
|
-
setIsAuthenticated(false);
|
|
60
81
|
}
|
|
61
82
|
finally {
|
|
62
83
|
setIsLoading(false);
|
|
@@ -64,8 +85,68 @@ function LoginStepCustom({ onSuccess, onError, chain, strategies, maxInitialWall
|
|
|
64
85
|
setIsAuthenticating(false);
|
|
65
86
|
}
|
|
66
87
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
88
|
+
const handleConnect = async (strategy) => {
|
|
89
|
+
if (strategy === "email") {
|
|
90
|
+
setShowEmailFlow(true);
|
|
91
|
+
setEmailCodeSent(false);
|
|
92
|
+
setVerificationCode("");
|
|
93
|
+
setEmailError(null);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const options = (0, react_1.getConnectOptionsFromStrategy)(strategy);
|
|
97
|
+
await connectWithOptions(strategy, options);
|
|
98
|
+
};
|
|
99
|
+
const handleSendEmailCode = async () => {
|
|
100
|
+
const normalizedEmail = email.trim().toLowerCase();
|
|
101
|
+
if (!normalizedEmail) {
|
|
102
|
+
setEmailError("Please enter your email address");
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (!EMAIL_REGEX.test(normalizedEmail)) {
|
|
106
|
+
setEmailError("Please enter a valid email address");
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
setIsLoading(true);
|
|
111
|
+
setEmailError(null);
|
|
112
|
+
await (0, wallets_1.preAuthenticate)({
|
|
113
|
+
client: thirdweb_1.client,
|
|
114
|
+
strategy: "email",
|
|
115
|
+
email: normalizedEmail,
|
|
116
|
+
ecosystem: {
|
|
117
|
+
id: constants_1.ecosystemWalletId,
|
|
118
|
+
partnerId,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
setEmail(normalizedEmail);
|
|
122
|
+
setEmailCodeSent(true);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
setEmailError(error instanceof Error ? error.message : "Failed to send verification code");
|
|
126
|
+
await onError?.(error);
|
|
127
|
+
}
|
|
128
|
+
finally {
|
|
129
|
+
setIsLoading(false);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
const handleEmailLogin = async () => {
|
|
133
|
+
const normalizedEmail = email.trim().toLowerCase();
|
|
134
|
+
const normalizedCode = verificationCode.trim();
|
|
135
|
+
if (!EMAIL_REGEX.test(normalizedEmail)) {
|
|
136
|
+
setEmailError("Please enter a valid email address");
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (!normalizedCode) {
|
|
140
|
+
setEmailError("Please enter your verification code");
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
await connectWithOptions("email", {
|
|
144
|
+
strategy: "email",
|
|
145
|
+
email: normalizedEmail,
|
|
146
|
+
verificationCode: normalizedCode,
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
return ((0, jsx_runtime_1.jsx)(react_1.LoginStepContainer, { partnerId: partnerId, children: showEmailFlow ? ((0, jsx_runtime_1.jsxs)("div", { className: "mb-6 w-full space-y-3 px-3", children: [(0, jsx_runtime_1.jsx)("p", { className: "text-center text-sm font-medium text-gray-900 dark:text-gray-100", children: "Sign in with email" }), (0, jsx_runtime_1.jsx)(react_1.Input, { type: "email", placeholder: "you@example.com", value: email, onChange: event => setEmail(event.target.value), disabled: isLoading || emailCodeSent }), emailCodeSent && ((0, jsx_runtime_1.jsx)(react_1.Input, { type: "text", placeholder: "Enter verification code", value: verificationCode, onChange: event => setVerificationCode(event.target.value), disabled: isLoading })), emailError && (0, jsx_runtime_1.jsx)("p", { className: "text-sm text-red-500", children: emailError }), (0, jsx_runtime_1.jsx)(react_1.Button, { onClick: emailCodeSent ? handleEmailLogin : handleSendEmailCode, disabled: isLoading, className: "w-full", children: isLoading ? "Loading..." : emailCodeSent ? "Verify code" : "Send code" }), emailCodeSent && ((0, jsx_runtime_1.jsx)(react_1.Button, { variant: "outline", onClick: handleSendEmailCode, disabled: isLoading, className: "w-full", children: "Resend code" })), (0, jsx_runtime_1.jsx)(react_1.Button, { variant: "outline", onClick: resetEmailFlow, disabled: isLoading, className: "w-full", children: "Back" })] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [authStrategies.length > 0 && ((0, jsx_runtime_1.jsx)("div", { className: `mb-6 grid w-full gap-4 px-3 ${authStrategies.length > 4 ? "grid-cols-4" : ""}`, style: authStrategies.length <= 4
|
|
150
|
+
? { gridTemplateColumns: `repeat(${authGridColumns}, minmax(0, 1fr))` }
|
|
151
|
+
: undefined, children: authStrategies.map(strategy => ((0, jsx_runtime_1.jsx)(react_1.AuthButton, { strategy: strategy, onClick: () => handleConnect(strategy), isLoading: isLoading }, strategy))) })), (0, jsx_runtime_1.jsx)("div", { className: "mb-4 w-full space-y-2", children: initialWallets.map(walletId => ((0, jsx_runtime_1.jsx)(react_1.WalletRow, { walletId: walletId, onClick: () => handleConnect(walletId), isLoading: isLoading }, walletId))) }), additionalWallets.length > 0 && ((0, jsx_runtime_1.jsxs)("div", { className: "w-full", children: [(0, jsx_runtime_1.jsx)(react_1.Button, { onClick: () => setShowAllWallets(!showAllWallets), className: "mb-2 w-full bg-transparent text-gray-600 hover:bg-gray-100", children: showAllWallets ? "Show less" : "More options" }), showAllWallets && ((0, jsx_runtime_1.jsx)("div", { className: "max-h-60 space-y-2 overflow-y-auto", children: additionalWallets.map(walletId => ((0, jsx_runtime_1.jsx)(react_1.WalletRow, { walletId: walletId, onClick: () => handleConnect(walletId), isLoading: isLoading }, walletId))) }))] }))] })) }));
|
|
71
152
|
}
|
|
@@ -3,15 +3,17 @@ import { SingleStepAuthArgsType, Wallet } from "thirdweb/wallets";
|
|
|
3
3
|
type WalletType = Wallet["id"];
|
|
4
4
|
type StrategyType = SingleStepAuthArgsType["strategy"];
|
|
5
5
|
type CustomStrategyType = "basement" | "privy";
|
|
6
|
-
type AllowedStrategies = StrategyType | WalletType | CustomStrategyType;
|
|
7
|
-
|
|
6
|
+
type AllowedStrategies = StrategyType | WalletType | CustomStrategyType | "email";
|
|
7
|
+
type NonWalletStrategyType = Exclude<AllowedStrategies, WalletType>;
|
|
8
|
+
export declare const allowedStrategies: readonly ["apple", "google", "github", "x", "discord", "email", "guest", "walletConnect", "io.metamask", "com.coinbase.wallet", "basement", "privy"];
|
|
8
9
|
export type AllowedStrategy = (typeof allowedStrategies)[number];
|
|
9
10
|
export declare function isWalletType(strategy: AllowedStrategies): strategy is WalletType;
|
|
10
|
-
export declare function isStrategyType(strategy: AllowedStrategies): strategy is
|
|
11
|
+
export declare function isStrategyType(strategy: AllowedStrategies): strategy is NonWalletStrategyType;
|
|
11
12
|
export declare function getConnectOptionsFromStrategy(strategy: AllowedStrategy): {
|
|
12
13
|
strategy: StrategyType;
|
|
13
14
|
wallet?: Wallet;
|
|
14
15
|
chain?: Chain;
|
|
15
16
|
};
|
|
16
17
|
export declare const strategyIcons: Record<string, string>;
|
|
18
|
+
export declare const strategyLabels: Record<string, string>;
|
|
17
19
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.strategyIcons = exports.allowedStrategies = void 0;
|
|
3
|
+
exports.strategyLabels = exports.strategyIcons = exports.allowedStrategies = void 0;
|
|
4
4
|
exports.isWalletType = isWalletType;
|
|
5
5
|
exports.isStrategyType = isStrategyType;
|
|
6
6
|
exports.getConnectOptionsFromStrategy = getConnectOptionsFromStrategy;
|
|
@@ -11,9 +11,10 @@ exports.allowedStrategies = [
|
|
|
11
11
|
// Auth strategies
|
|
12
12
|
"apple",
|
|
13
13
|
"google",
|
|
14
|
+
"github",
|
|
14
15
|
"x",
|
|
15
16
|
"discord",
|
|
16
|
-
|
|
17
|
+
"email",
|
|
17
18
|
"guest",
|
|
18
19
|
// Wallet IDs
|
|
19
20
|
"walletConnect",
|
|
@@ -35,6 +36,9 @@ function getConnectOptionsFromStrategy(strategy) {
|
|
|
35
36
|
if (!exports.allowedStrategies.includes(strategy)) {
|
|
36
37
|
throw new Error(`Invalid strategy: ${strategy}`);
|
|
37
38
|
}
|
|
39
|
+
if (strategy === "email") {
|
|
40
|
+
throw new Error("Email strategy requires OTP flow and cannot be connected in a single step");
|
|
41
|
+
}
|
|
38
42
|
if (isWalletType(strategy)) {
|
|
39
43
|
return { strategy: "wallet", wallet: (0, wallets_1.createWallet)(strategy) };
|
|
40
44
|
}
|
|
@@ -51,6 +55,15 @@ exports.strategyIcons = {
|
|
|
51
55
|
guest: "https://cdn.b3.fun/incognito.svg",
|
|
52
56
|
// Add more strategies as needed
|
|
53
57
|
};
|
|
58
|
+
exports.strategyLabels = {
|
|
59
|
+
google: "Google",
|
|
60
|
+
x: "X",
|
|
61
|
+
discord: "Discord",
|
|
62
|
+
apple: "Apple",
|
|
63
|
+
guest: "Guest",
|
|
64
|
+
github: "GitHub",
|
|
65
|
+
email: "Email",
|
|
66
|
+
};
|
|
54
67
|
// Test it
|
|
55
68
|
// console.log(getConnectOptionsFromStrategy("io.metamask"));
|
|
56
69
|
// console.log(getConnectOptionsFromStrategy("google"));
|
|
@@ -11,6 +11,9 @@ interface ToastContextType {
|
|
|
11
11
|
addToast: (type: ToastType, message: string, duration?: number) => string;
|
|
12
12
|
removeToast: (id: string) => void;
|
|
13
13
|
clearAll: () => void;
|
|
14
|
+
headerMode: boolean;
|
|
15
|
+
setHeaderMode: (enabled: boolean) => void;
|
|
16
|
+
latestToast: ToastItem | null;
|
|
14
17
|
}
|
|
15
18
|
export declare function ToastProvider({ children }: {
|
|
16
19
|
children: React.ReactNode;
|
|
@@ -8,6 +8,9 @@ const ToastContext = (0, react_1.createContext)(undefined);
|
|
|
8
8
|
let globalToastCounter = 0;
|
|
9
9
|
function ToastProvider({ children }) {
|
|
10
10
|
const [toasts, setToasts] = (0, react_1.useState)([]);
|
|
11
|
+
const [headerMode, setHeaderMode] = (0, react_1.useState)(false);
|
|
12
|
+
const headerModeRef = (0, react_1.useRef)(false);
|
|
13
|
+
const [latestToast, setLatestToast] = (0, react_1.useState)(null);
|
|
11
14
|
const timeoutsRef = (0, react_1.useRef)(new Map());
|
|
12
15
|
const removeToast = (0, react_1.useCallback)((id) => {
|
|
13
16
|
setToasts(prev => prev.filter(toast => toast.id !== id));
|
|
@@ -26,12 +29,23 @@ function ToastProvider({ children }) {
|
|
|
26
29
|
duration,
|
|
27
30
|
createdAt: Date.now(),
|
|
28
31
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
if (headerModeRef.current) {
|
|
33
|
+
setLatestToast(newToast);
|
|
34
|
+
if (duration > 0) {
|
|
35
|
+
const timeout = setTimeout(() => {
|
|
36
|
+
setLatestToast(null);
|
|
37
|
+
}, duration);
|
|
38
|
+
timeoutsRef.current.set(id, timeout);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
setToasts(prev => [...prev, newToast]);
|
|
43
|
+
if (duration > 0) {
|
|
44
|
+
const timeout = setTimeout(() => {
|
|
45
|
+
removeToast(id);
|
|
46
|
+
}, duration);
|
|
47
|
+
timeoutsRef.current.set(id, timeout);
|
|
48
|
+
}
|
|
35
49
|
}
|
|
36
50
|
return id;
|
|
37
51
|
}, [removeToast]);
|
|
@@ -40,6 +54,15 @@ function ToastProvider({ children }) {
|
|
|
40
54
|
timeoutsRef.current.clear();
|
|
41
55
|
setToasts([]);
|
|
42
56
|
}, []);
|
|
57
|
+
const setHeaderModeCallback = (0, react_1.useCallback)((enabled) => {
|
|
58
|
+
setHeaderMode(enabled);
|
|
59
|
+
headerModeRef.current = enabled;
|
|
60
|
+
if (!enabled) {
|
|
61
|
+
setLatestToast(null);
|
|
62
|
+
timeoutsRef.current.forEach(timeout => clearTimeout(timeout));
|
|
63
|
+
timeoutsRef.current.clear();
|
|
64
|
+
}
|
|
65
|
+
}, []);
|
|
43
66
|
// Cleanup on unmount
|
|
44
67
|
(0, react_1.useEffect)(() => {
|
|
45
68
|
const timeouts = timeoutsRef.current;
|
|
@@ -48,7 +71,7 @@ function ToastProvider({ children }) {
|
|
|
48
71
|
timeouts.clear();
|
|
49
72
|
};
|
|
50
73
|
}, []);
|
|
51
|
-
return (0, jsx_runtime_1.jsx)(ToastContext.Provider, { value: { toasts, addToast, removeToast, clearAll }, children: children });
|
|
74
|
+
return ((0, jsx_runtime_1.jsx)(ToastContext.Provider, { value: { toasts, addToast, removeToast, clearAll, headerMode, setHeaderMode: setHeaderModeCallback, latestToast }, children: children }));
|
|
52
75
|
}
|
|
53
76
|
function useToastContext() {
|
|
54
77
|
const context = (0, react_1.useContext)(ToastContext);
|
|
@@ -27,7 +27,7 @@ const debug = (0, debug_1.debugB3React)("useAuth");
|
|
|
27
27
|
* This hook provides 1:1 feature parity with useAuthentication.ts
|
|
28
28
|
*/
|
|
29
29
|
function useAuth() {
|
|
30
|
-
const { onConnectCallback } = (0, react_2.useContext)(LocalSDKProvider_1.LocalSDKContext);
|
|
30
|
+
const { onConnectCallback, disableBSMNTAuthentication } = (0, react_2.useContext)(LocalSDKProvider_1.LocalSDKContext);
|
|
31
31
|
const { disconnect } = (0, react_3.useDisconnect)();
|
|
32
32
|
const wallets = (0, react_3.useConnectedWallets)();
|
|
33
33
|
const activeWallet = (0, react_3.useActiveWallet)();
|
|
@@ -44,7 +44,7 @@ function useAuth() {
|
|
|
44
44
|
const useAutoConnectLoadingPrevious = (0, react_2.useRef)(false);
|
|
45
45
|
const referralCode = (0, useSearchParamsSSR_1.useSearchParam)("referralCode");
|
|
46
46
|
const { partnerId } = (0, react_1.useB3Config)();
|
|
47
|
-
const wagmiConfig = (0, createWagmiConfig_1.
|
|
47
|
+
const wagmiConfig = (0, react_2.useMemo)(() => (0, createWagmiConfig_1.createWagmiConfig)({ partnerId }), [partnerId]);
|
|
48
48
|
const { connect } = (0, wagmi_1.useConnect)();
|
|
49
49
|
const activeWagmiAccount = (0, wagmi_1.useAccount)();
|
|
50
50
|
const { switchAccount } = (0, wagmi_1.useSwitchAccount)();
|
|
@@ -69,8 +69,10 @@ function useAuth() {
|
|
|
69
69
|
}
|
|
70
70
|
// Authenticate with BSMNT
|
|
71
71
|
try {
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
if (!disableBSMNTAuthentication) {
|
|
73
|
+
const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(response.accessToken);
|
|
74
|
+
debug("BSMNT re-authentication successful", b3Jwt);
|
|
75
|
+
}
|
|
74
76
|
}
|
|
75
77
|
catch (bsmntError) {
|
|
76
78
|
// BSMNT authentication failure shouldn't block the main auth flow
|
|
@@ -82,7 +84,7 @@ function useAuth() {
|
|
|
82
84
|
debug("Re-authentication failed", err);
|
|
83
85
|
throw err;
|
|
84
86
|
}
|
|
85
|
-
}, [setUser]);
|
|
87
|
+
}, [setUser, disableBSMNTAuthentication]);
|
|
86
88
|
const syncWagmi = (0, react_2.useCallback)(async () => {
|
|
87
89
|
function syncWagmiFunc() {
|
|
88
90
|
const connectors = (0, core_1.getConnectors)(wagmiConfig);
|
|
@@ -126,9 +128,7 @@ function useAuth() {
|
|
|
126
128
|
});
|
|
127
129
|
}
|
|
128
130
|
syncWagmiFunc();
|
|
129
|
-
|
|
130
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
131
|
-
}, [partnerId, wallets]);
|
|
131
|
+
}, [wagmiConfig, wallets, connect, switchAccount]);
|
|
132
132
|
(0, react_2.useEffect)(() => {
|
|
133
133
|
syncWagmi();
|
|
134
134
|
}, [wallets, syncWagmi]);
|
|
@@ -145,9 +145,11 @@ function useAuth() {
|
|
|
145
145
|
setIsAuthenticated(true);
|
|
146
146
|
setIsAuthenticating(false);
|
|
147
147
|
debug("Re-authenticated successfully", { userAuth });
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
if (!disableBSMNTAuthentication) {
|
|
149
|
+
// Authenticate on BSMNT with B3 JWT
|
|
150
|
+
const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
|
|
151
|
+
debug("@@b3Jwt", b3Jwt);
|
|
152
|
+
}
|
|
151
153
|
return userAuth;
|
|
152
154
|
}
|
|
153
155
|
catch (error) {
|
|
@@ -157,7 +159,14 @@ function useAuth() {
|
|
|
157
159
|
setIsAuthenticating(false);
|
|
158
160
|
throw new Error("Authentication required. Please authenticate.");
|
|
159
161
|
}
|
|
160
|
-
}, [
|
|
162
|
+
}, [
|
|
163
|
+
reAuthenticate,
|
|
164
|
+
setIsAuthenticated,
|
|
165
|
+
setIsAuthenticating,
|
|
166
|
+
setUser,
|
|
167
|
+
setHasStartedConnecting,
|
|
168
|
+
disableBSMNTAuthentication,
|
|
169
|
+
]);
|
|
161
170
|
/**
|
|
162
171
|
* Authenticate with B3
|
|
163
172
|
*
|
|
@@ -187,8 +196,10 @@ function useAuth() {
|
|
|
187
196
|
}
|
|
188
197
|
// Step 3: Authenticate with BSMNT for basement integration
|
|
189
198
|
try {
|
|
190
|
-
|
|
191
|
-
|
|
199
|
+
if (!disableBSMNTAuthentication) {
|
|
200
|
+
const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(response.accessToken);
|
|
201
|
+
debug("BSMNT authentication successful", b3Jwt);
|
|
202
|
+
}
|
|
192
203
|
}
|
|
193
204
|
catch (bsmntError) {
|
|
194
205
|
// BSMNT authentication failure shouldn't block the main auth flow
|
|
@@ -200,7 +211,7 @@ function useAuth() {
|
|
|
200
211
|
debug("Authentication failed", err);
|
|
201
212
|
throw err;
|
|
202
213
|
}
|
|
203
|
-
}, [referralCode, setUser]);
|
|
214
|
+
}, [referralCode, setUser, disableBSMNTAuthentication]);
|
|
204
215
|
/**
|
|
205
216
|
* Handle wallet connection
|
|
206
217
|
*/
|
|
@@ -22,7 +22,7 @@ const useTWAuth_1 = require("./useTWAuth");
|
|
|
22
22
|
const useUserQuery_1 = require("./useUserQuery");
|
|
23
23
|
const debug = (0, debug_1.debugB3React)("useAuthentication");
|
|
24
24
|
function useAuthentication(partnerId, { skipAutoConnect = false } = {}) {
|
|
25
|
-
const { onConnectCallback, onLogoutCallback } = (0, react_2.useContext)(LocalSDKProvider_1.LocalSDKContext);
|
|
25
|
+
const { onConnectCallback, onLogoutCallback, disableBSMNTAuthentication } = (0, react_2.useContext)(LocalSDKProvider_1.LocalSDKContext);
|
|
26
26
|
const { disconnect } = (0, react_3.useDisconnect)();
|
|
27
27
|
const wallets = (0, react_3.useConnectedWallets)();
|
|
28
28
|
// Keep refs so logout() always disconnects current wallets, not stale closure values.
|
|
@@ -54,7 +54,7 @@ function useAuthentication(partnerId, { skipAutoConnect = false } = {}) {
|
|
|
54
54
|
const { authenticate } = (0, useTWAuth_1.useTWAuth)();
|
|
55
55
|
const { user, setUser } = (0, useUserQuery_1.useUserQuery)();
|
|
56
56
|
const useAutoConnectLoadingPrevious = (0, react_2.useRef)(false);
|
|
57
|
-
const wagmiConfig = (0, createWagmiConfig_1.createWagmiConfig)({ partnerId });
|
|
57
|
+
const wagmiConfig = (0, react_2.useMemo)(() => (0, createWagmiConfig_1.createWagmiConfig)({ partnerId }), [partnerId]);
|
|
58
58
|
const { connect } = (0, wagmi_1.useConnect)();
|
|
59
59
|
const activeWagmiAccount = (0, wagmi_1.useAccount)();
|
|
60
60
|
const { switchAccount } = (0, wagmi_1.useSwitchAccount)();
|
|
@@ -105,9 +105,7 @@ function useAuthentication(partnerId, { skipAutoConnect = false } = {}) {
|
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
syncWagmiFunc();
|
|
108
|
-
|
|
109
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
110
|
-
}, [partnerId, wallets]);
|
|
108
|
+
}, [wagmiConfig, wallets, connect, switchAccount]);
|
|
111
109
|
(0, react_2.useEffect)(() => {
|
|
112
110
|
syncWagmi();
|
|
113
111
|
}, [wallets, syncWagmi]);
|
|
@@ -127,9 +125,11 @@ function useAuthentication(partnerId, { skipAutoConnect = false } = {}) {
|
|
|
127
125
|
setIsAuthenticated(true);
|
|
128
126
|
setIsAuthenticating(false);
|
|
129
127
|
debug("Re-authenticated successfully", { userAuth });
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
if (!disableBSMNTAuthentication) {
|
|
129
|
+
// Authenticate on BSMNT with B3 JWT
|
|
130
|
+
const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
|
|
131
|
+
debug("@@b3Jwt", b3Jwt);
|
|
132
|
+
}
|
|
133
133
|
return userAuth;
|
|
134
134
|
}
|
|
135
135
|
catch (error) {
|
|
@@ -140,12 +140,23 @@ function useAuthentication(partnerId, { skipAutoConnect = false } = {}) {
|
|
|
140
140
|
setIsAuthenticated(true);
|
|
141
141
|
setIsAuthenticating(false);
|
|
142
142
|
debug("Fresh authentication successful", { userAuth });
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
if (!disableBSMNTAuthentication) {
|
|
144
|
+
// Authenticate on BSMNT with B3 JWT
|
|
145
|
+
const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
|
|
146
|
+
debug("@@b3Jwt", b3Jwt);
|
|
147
|
+
}
|
|
146
148
|
return userAuth;
|
|
147
149
|
}
|
|
148
|
-
}, [
|
|
150
|
+
}, [
|
|
151
|
+
activeWallet,
|
|
152
|
+
partnerId,
|
|
153
|
+
authenticate,
|
|
154
|
+
setIsAuthenticated,
|
|
155
|
+
setIsAuthenticating,
|
|
156
|
+
setUser,
|
|
157
|
+
setHasStartedConnecting,
|
|
158
|
+
disableBSMNTAuthentication,
|
|
159
|
+
]);
|
|
149
160
|
const logout = (0, react_2.useCallback)(async (callback) => {
|
|
150
161
|
// Disconnect ecosystem/smart wallets from the connected wallets list.
|
|
151
162
|
// EOA wallets (MetaMask, Coinbase Wallet) are left in the list so they can
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Chain } from "thirdweb";
|
|
2
|
-
import { SingleStepAuthArgsType } from "thirdweb/wallets";
|
|
2
|
+
import { MultiStepAuthArgsType, SingleStepAuthArgsType } from "thirdweb/wallets";
|
|
3
3
|
/**
|
|
4
4
|
* This hook is used to connect to a wallet using the thirdweb client.
|
|
5
5
|
*/
|
|
6
6
|
export declare function useConnect(partnerId: string, chain?: Chain): {
|
|
7
|
-
connect: (strategyOptions?: SingleStepAuthArgsType) => Promise<import("thirdweb/wallets").Wallet | null>;
|
|
7
|
+
connect: (strategyOptions?: MultiStepAuthArgsType | SingleStepAuthArgsType) => Promise<import("thirdweb/wallets").Wallet | null>;
|
|
8
8
|
isLoading: boolean;
|
|
9
9
|
};
|