@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
|
@@ -5,6 +5,7 @@ import { Account, Wallet } from "thirdweb/wallets";
|
|
|
5
5
|
|
|
6
6
|
import { ClientType } from "../../../client-manager";
|
|
7
7
|
|
|
8
|
+
import { useMemo } from "react";
|
|
8
9
|
import { WagmiProvider } from "wagmi";
|
|
9
10
|
import { createWagmiConfig } from "../../utils/createWagmiConfig";
|
|
10
11
|
import AuthenticationProvider from "./AuthenticationProvider";
|
|
@@ -82,7 +83,7 @@ export function InnerProvider({
|
|
|
82
83
|
partnerId: string;
|
|
83
84
|
rpcUrls?: Record<number, string>;
|
|
84
85
|
}) {
|
|
85
|
-
const wagmiConfig = createWagmiConfig({ partnerId, rpcUrls });
|
|
86
|
+
const wagmiConfig = useMemo(() => createWagmiConfig({ partnerId, rpcUrls }), [partnerId, rpcUrls]);
|
|
86
87
|
|
|
87
88
|
return (
|
|
88
89
|
<WagmiProvider config={wagmiConfig}>
|
|
@@ -43,6 +43,7 @@ export function B3Provider({
|
|
|
43
43
|
overrideDefaultConnectors = false,
|
|
44
44
|
createClientReferenceId,
|
|
45
45
|
defaultPermissions,
|
|
46
|
+
disableBSMNTAuthentication = false,
|
|
46
47
|
}: {
|
|
47
48
|
theme: "light" | "dark";
|
|
48
49
|
children: React.ReactNode;
|
|
@@ -67,6 +68,7 @@ export function B3Provider({
|
|
|
67
68
|
overrideDefaultConnectors?: boolean;
|
|
68
69
|
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
69
70
|
defaultPermissions?: PermissionsConfig;
|
|
71
|
+
disableBSMNTAuthentication?: boolean;
|
|
70
72
|
}) {
|
|
71
73
|
// Initialize Google Analytics on mount
|
|
72
74
|
useEffect(() => {
|
|
@@ -89,7 +91,11 @@ export function B3Provider({
|
|
|
89
91
|
<QueryClientProvider client={queryClient}>
|
|
90
92
|
<TooltipProvider>
|
|
91
93
|
<ToastProvider>
|
|
92
|
-
<LocalSDKProvider
|
|
94
|
+
<LocalSDKProvider
|
|
95
|
+
onConnectCallback={onConnect}
|
|
96
|
+
onLogoutCallback={onLogout}
|
|
97
|
+
disableBSMNTAuthentication={disableBSMNTAuthentication}
|
|
98
|
+
>
|
|
93
99
|
<B3ConfigProvider
|
|
94
100
|
accountOverride={accountOverride}
|
|
95
101
|
environment={environment}
|
|
@@ -8,11 +8,13 @@ import { Wallet } from "thirdweb/wallets";
|
|
|
8
8
|
export interface LocalSDKContextType {
|
|
9
9
|
onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
10
10
|
onLogoutCallback?: () => void | Promise<void>;
|
|
11
|
+
disableBSMNTAuthentication?: boolean;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export const LocalSDKContext = createContext<LocalSDKContextType>({
|
|
14
15
|
onConnectCallback: undefined,
|
|
15
16
|
onLogoutCallback: undefined,
|
|
17
|
+
disableBSMNTAuthentication: false,
|
|
16
18
|
});
|
|
17
19
|
|
|
18
20
|
/**
|
|
@@ -22,16 +24,19 @@ export function LocalSDKProvider({
|
|
|
22
24
|
children,
|
|
23
25
|
onConnectCallback,
|
|
24
26
|
onLogoutCallback,
|
|
27
|
+
disableBSMNTAuthentication,
|
|
25
28
|
}: {
|
|
26
29
|
children: React.ReactNode;
|
|
27
30
|
onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
28
31
|
onLogoutCallback?: () => void | Promise<void>;
|
|
32
|
+
disableBSMNTAuthentication?: boolean;
|
|
29
33
|
}) {
|
|
30
34
|
return (
|
|
31
35
|
<LocalSDKContext.Provider
|
|
32
36
|
value={{
|
|
33
37
|
onConnectCallback,
|
|
34
38
|
onLogoutCallback,
|
|
39
|
+
disableBSMNTAuthentication,
|
|
35
40
|
}}
|
|
36
41
|
>
|
|
37
42
|
{children}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import app from "@b3dotfun/sdk/global-account/app";
|
|
2
|
+
import { useAuthentication, useModalStore } from "@b3dotfun/sdk/global-account/react";
|
|
3
|
+
import {
|
|
4
|
+
getSessionDurationDays,
|
|
5
|
+
SESSION_DURATION_LABELS,
|
|
6
|
+
SESSION_DURATION_OPTIONS,
|
|
7
|
+
SessionDurationDays,
|
|
8
|
+
setSessionDurationDays,
|
|
9
|
+
} from "@b3dotfun/sdk/shared/utils/session-duration";
|
|
10
|
+
import { useState } from "react";
|
|
11
|
+
import ModalHeader from "../ModalHeader/ModalHeader";
|
|
12
|
+
|
|
13
|
+
interface SessionDurationContentProps {
|
|
14
|
+
partnerId: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const DESCRIPTIONS: Record<SessionDurationDays, string> = {
|
|
18
|
+
0: "Sign out when browser closes",
|
|
19
|
+
1: "Stay signed in for 1 day",
|
|
20
|
+
7: "Stay signed in for 7 days",
|
|
21
|
+
14: "Stay signed in for 2 weeks",
|
|
22
|
+
30: "Stay signed in for 30 days",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const SessionDurationContent = ({ partnerId }: SessionDurationContentProps) => {
|
|
26
|
+
const { user, setUser } = useAuthentication(partnerId);
|
|
27
|
+
const navigateBack = useModalStore(state => state.navigateBack);
|
|
28
|
+
const [sessionDays, setSessionDays] = useState<SessionDurationDays>(() =>
|
|
29
|
+
getSessionDurationDays(user?.preferences, partnerId),
|
|
30
|
+
);
|
|
31
|
+
const [saving, setSaving] = useState(false);
|
|
32
|
+
|
|
33
|
+
const handleSelect = async (days: SessionDurationDays) => {
|
|
34
|
+
const previous = sessionDays;
|
|
35
|
+
setSessionDurationDays(days, partnerId);
|
|
36
|
+
setSessionDays(days);
|
|
37
|
+
if (user?.userId) {
|
|
38
|
+
setSaving(true);
|
|
39
|
+
try {
|
|
40
|
+
const updated = await app.service("users").patch(user.userId, {
|
|
41
|
+
preferences: {
|
|
42
|
+
...user.preferences,
|
|
43
|
+
[partnerId]: {
|
|
44
|
+
...((((user.preferences as Record<string, unknown>) ?? {})[partnerId] as Record<string, unknown>) ?? {}),
|
|
45
|
+
sessionDuration: days,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
setUser(updated);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error("Failed to save session duration preference:", error);
|
|
52
|
+
// Revert optimistic update so UI stays consistent with server state
|
|
53
|
+
setSessionDays(previous);
|
|
54
|
+
setSessionDurationDays(previous, partnerId);
|
|
55
|
+
} finally {
|
|
56
|
+
setSaving(false);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<div className="flex h-[470px] flex-col">
|
|
63
|
+
<ModalHeader showBackButton={true} showCloseButton={false} title="Stay signed in" handleBack={navigateBack} />
|
|
64
|
+
|
|
65
|
+
<div className="flex flex-col gap-2 p-5">
|
|
66
|
+
{SESSION_DURATION_OPTIONS.map(days => (
|
|
67
|
+
<button
|
|
68
|
+
type="button"
|
|
69
|
+
key={days}
|
|
70
|
+
onClick={() => handleSelect(days)}
|
|
71
|
+
disabled={saving}
|
|
72
|
+
className={`flex items-center justify-between rounded-xl border px-4 py-3 transition-colors ${
|
|
73
|
+
sessionDays === days
|
|
74
|
+
? "border-[#3f3f46] bg-[#f4f4f5] dark:border-white dark:bg-white/10"
|
|
75
|
+
: "border-[#e4e4e7] bg-transparent hover:bg-[#f4f4f5] dark:border-white/10 dark:hover:bg-white/5"
|
|
76
|
+
}`}
|
|
77
|
+
>
|
|
78
|
+
<div className="flex flex-col items-start gap-0.5">
|
|
79
|
+
<span className="font-neue-montreal-semibold text-[14px] leading-none tracking-[-0.28px] text-[#3f3f46] dark:text-white">
|
|
80
|
+
{SESSION_DURATION_LABELS[days]}
|
|
81
|
+
</span>
|
|
82
|
+
<span className="font-neue-montreal-medium text-[13px] leading-none tracking-[-0.26px] text-[#70707b] dark:text-white/50">
|
|
83
|
+
{DESCRIPTIONS[days]}
|
|
84
|
+
</span>
|
|
85
|
+
</div>
|
|
86
|
+
{sessionDays === days && (
|
|
87
|
+
<div className="flex size-5 items-center justify-center rounded-full bg-[#3f3f46] dark:bg-white">
|
|
88
|
+
<svg width="10" height="8" viewBox="0 0 10 8" fill="none">
|
|
89
|
+
<path
|
|
90
|
+
d="M1 4L3.5 6.5L9 1"
|
|
91
|
+
stroke="white"
|
|
92
|
+
strokeWidth="1.5"
|
|
93
|
+
strokeLinecap="round"
|
|
94
|
+
strokeLinejoin="round"
|
|
95
|
+
className="dark:stroke-[#3f3f46]"
|
|
96
|
+
/>
|
|
97
|
+
</svg>
|
|
98
|
+
</div>
|
|
99
|
+
)}
|
|
100
|
+
</button>
|
|
101
|
+
))}
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export default SessionDurationContent;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useAuthentication, useModalStore } from "@b3dotfun/sdk/global-account/react";
|
|
2
2
|
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
3
|
+
import { getSessionDurationDays, SESSION_DURATION_LABELS } from "@b3dotfun/sdk/shared/utils/session-duration";
|
|
3
4
|
import { Loader2 } from "lucide-react";
|
|
4
5
|
import { useState } from "react";
|
|
5
6
|
import { Chain } from "thirdweb";
|
|
@@ -20,46 +21,29 @@ const SettingsContent = ({
|
|
|
20
21
|
}) => {
|
|
21
22
|
const setB3ModalContentType = useModalStore(state => state.setB3ModalContentType);
|
|
22
23
|
const setB3ModalOpen = useModalStore(state => state.setB3ModalOpen);
|
|
23
|
-
const { logout } = useAuthentication(partnerId);
|
|
24
|
+
const { logout, user } = useAuthentication(partnerId);
|
|
24
25
|
const [logoutLoading, setLogoutLoading] = useState(false);
|
|
25
26
|
|
|
26
|
-
const
|
|
27
|
+
const sessionDays = getSessionDurationDays(user?.preferences, partnerId);
|
|
27
28
|
|
|
29
|
+
const { data: profilesRaw = [] } = useProfiles({ client });
|
|
28
30
|
const profiles = profilesRaw.filter((profile: any) => !["custom_auth_endpoint"].includes(profile.type));
|
|
29
31
|
|
|
30
|
-
const handleNavigate = (
|
|
32
|
+
const handleNavigate = (
|
|
33
|
+
type: "home" | "swap" | "linkAccount" | "avatarEditor" | "notifications" | "sessionDuration",
|
|
34
|
+
) => {
|
|
31
35
|
if (type === "home") {
|
|
32
|
-
setB3ModalContentType({
|
|
33
|
-
type: "manageAccount",
|
|
34
|
-
chain,
|
|
35
|
-
partnerId,
|
|
36
|
-
onLogout,
|
|
37
|
-
activeTab: "home",
|
|
38
|
-
});
|
|
36
|
+
setB3ModalContentType({ type: "manageAccount", chain, partnerId, onLogout, activeTab: "home" });
|
|
39
37
|
} else if (type === "swap") {
|
|
40
|
-
setB3ModalContentType({
|
|
41
|
-
type: "manageAccount",
|
|
42
|
-
chain,
|
|
43
|
-
partnerId,
|
|
44
|
-
onLogout,
|
|
45
|
-
activeTab: "tokens",
|
|
46
|
-
});
|
|
38
|
+
setB3ModalContentType({ type: "manageAccount", chain, partnerId, onLogout, activeTab: "tokens" });
|
|
47
39
|
} else if (type === "linkAccount") {
|
|
48
|
-
setB3ModalContentType({
|
|
49
|
-
type: "linkAccount",
|
|
50
|
-
chain,
|
|
51
|
-
partnerId,
|
|
52
|
-
});
|
|
40
|
+
setB3ModalContentType({ type: "linkAccount", chain, partnerId });
|
|
53
41
|
} else if (type === "notifications") {
|
|
54
|
-
setB3ModalContentType({
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
partnerId,
|
|
58
|
-
});
|
|
42
|
+
setB3ModalContentType({ type: "notifications", chain, partnerId });
|
|
43
|
+
} else if (type === "sessionDuration") {
|
|
44
|
+
setB3ModalContentType({ type: "sessionDuration", chain, partnerId });
|
|
59
45
|
} else {
|
|
60
|
-
setB3ModalContentType({
|
|
61
|
-
type: "avatarEditor",
|
|
62
|
-
});
|
|
46
|
+
setB3ModalContentType({ type: "avatarEditor" });
|
|
63
47
|
}
|
|
64
48
|
setB3ModalOpen(true);
|
|
65
49
|
};
|
|
@@ -111,11 +95,25 @@ const SettingsContent = ({
|
|
|
111
95
|
subtitle="Manage your notifications"
|
|
112
96
|
onClick={() => handleNavigate("notifications")}
|
|
113
97
|
/>
|
|
98
|
+
<SettingsMenuItem
|
|
99
|
+
icon={
|
|
100
|
+
<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
101
|
+
<path
|
|
102
|
+
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"
|
|
103
|
+
fill="#F4F4F5"
|
|
104
|
+
/>
|
|
105
|
+
</svg>
|
|
106
|
+
}
|
|
107
|
+
title="Stay signed in"
|
|
108
|
+
subtitle={SESSION_DURATION_LABELS[sessionDays] ?? `${sessionDays} days`}
|
|
109
|
+
onClick={() => handleNavigate("sessionDuration")}
|
|
110
|
+
/>
|
|
114
111
|
</div>
|
|
115
112
|
|
|
116
113
|
{/* Logout Section */}
|
|
117
114
|
<div className="mt-auto px-5 pb-5">
|
|
118
115
|
<button
|
|
116
|
+
type="button"
|
|
119
117
|
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"
|
|
120
118
|
onClick={onLogoutEnhanced}
|
|
121
119
|
disabled={logoutLoading}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { Button } from "../../custom/Button";
|
|
2
|
-
import {
|
|
2
|
+
import { Github, Mail } from "lucide-react";
|
|
3
|
+
import { strategyIcons, strategyLabels } from "../utils/signInUtils";
|
|
4
|
+
|
|
5
|
+
const fallbackIcons = {
|
|
6
|
+
github: Github,
|
|
7
|
+
email: Mail,
|
|
8
|
+
} as const;
|
|
3
9
|
|
|
4
10
|
export function AuthButton({
|
|
5
11
|
strategy,
|
|
@@ -10,14 +16,27 @@ export function AuthButton({
|
|
|
10
16
|
onClick: () => void;
|
|
11
17
|
isLoading: boolean;
|
|
12
18
|
}) {
|
|
19
|
+
const strategyIcon = strategyIcons[strategy];
|
|
20
|
+
const strategyLabel = strategyLabels[strategy] || strategy;
|
|
21
|
+
const FallbackIcon = fallbackIcons[strategy as keyof typeof fallbackIcons];
|
|
22
|
+
const buttonLabel = `Sign in with ${strategyLabel}`;
|
|
23
|
+
|
|
13
24
|
return (
|
|
14
25
|
<Button
|
|
15
26
|
key={strategy}
|
|
16
27
|
onClick={onClick}
|
|
17
28
|
disabled={isLoading}
|
|
29
|
+
aria-label={buttonLabel}
|
|
30
|
+
title={buttonLabel}
|
|
18
31
|
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"
|
|
19
32
|
>
|
|
20
|
-
|
|
33
|
+
{strategyIcon ? (
|
|
34
|
+
<img src={strategyIcon} alt={`${strategyLabel} icon`} className="h-9 w-9" />
|
|
35
|
+
) : FallbackIcon ? (
|
|
36
|
+
<FallbackIcon className="h-9 w-9 text-gray-900 dark:text-gray-100" />
|
|
37
|
+
) : (
|
|
38
|
+
<span className="text-sm font-semibold text-gray-900 dark:text-gray-100">{strategyLabel.charAt(0)}</span>
|
|
39
|
+
)}
|
|
21
40
|
</Button>
|
|
22
41
|
);
|
|
23
42
|
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
AuthButton,
|
|
4
4
|
Button,
|
|
5
5
|
getConnectOptionsFromStrategy,
|
|
6
|
+
Input,
|
|
6
7
|
isWalletType,
|
|
7
8
|
LoginStepContainer,
|
|
8
9
|
useAuthentication,
|
|
@@ -11,12 +12,21 @@ import {
|
|
|
11
12
|
useConnect,
|
|
12
13
|
WalletRow,
|
|
13
14
|
} from "@b3dotfun/sdk/global-account/react";
|
|
15
|
+
import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
|
|
14
16
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
15
17
|
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
16
18
|
import { useState } from "react";
|
|
17
19
|
import { Chain } from "thirdweb";
|
|
18
|
-
import { useConnect as useConnectTW } from "thirdweb/react";
|
|
19
|
-
import {
|
|
20
|
+
import { useConnectedWallets, useConnect as useConnectTW } from "thirdweb/react";
|
|
21
|
+
import {
|
|
22
|
+
Account,
|
|
23
|
+
createWallet,
|
|
24
|
+
MultiStepAuthArgsType,
|
|
25
|
+
preAuthenticate,
|
|
26
|
+
SingleStepAuthArgsType,
|
|
27
|
+
Wallet,
|
|
28
|
+
WalletId,
|
|
29
|
+
} from "thirdweb/wallets";
|
|
20
30
|
|
|
21
31
|
interface LoginStepCustomProps {
|
|
22
32
|
automaticallySetFirstEoa: boolean;
|
|
@@ -28,6 +38,7 @@ interface LoginStepCustomProps {
|
|
|
28
38
|
}
|
|
29
39
|
|
|
30
40
|
const debug = debugB3React("LoginStepCustom");
|
|
41
|
+
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
31
42
|
|
|
32
43
|
export function LoginStepCustom({
|
|
33
44
|
onSuccess,
|
|
@@ -40,32 +51,49 @@ export function LoginStepCustom({
|
|
|
40
51
|
const { partnerId } = useB3Config();
|
|
41
52
|
const [isLoading, setIsLoading] = useState(false);
|
|
42
53
|
const [showAllWallets, setShowAllWallets] = useState(false);
|
|
54
|
+
const [showEmailFlow, setShowEmailFlow] = useState(false);
|
|
55
|
+
const [email, setEmail] = useState("");
|
|
56
|
+
const [verificationCode, setVerificationCode] = useState("");
|
|
57
|
+
const [emailCodeSent, setEmailCodeSent] = useState(false);
|
|
58
|
+
const [emailError, setEmailError] = useState<string | null>(null);
|
|
43
59
|
const { connect } = useConnect(partnerId, chain);
|
|
44
60
|
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
45
|
-
const
|
|
46
|
-
const { logout } = useAuthentication(partnerId, { skipAutoConnect: true });
|
|
61
|
+
const { connect: onAuthConnect, logout } = useAuthentication(partnerId, { skipAutoConnect: true });
|
|
47
62
|
const { connect: connectTW } = useConnectTW();
|
|
63
|
+
const connectedWallets = useConnectedWallets();
|
|
48
64
|
|
|
49
65
|
// Split strategies into auth and wallet types
|
|
50
66
|
const authStrategies = strategies.filter(s => !isWalletType(s));
|
|
51
67
|
const walletStrategies = strategies.filter(isWalletType);
|
|
52
68
|
const initialWallets = walletStrategies.slice(0, maxInitialWallets);
|
|
53
69
|
const additionalWallets = walletStrategies.slice(maxInitialWallets);
|
|
70
|
+
const authGridColumns = Math.max(1, Math.min(authStrategies.length, 4));
|
|
54
71
|
|
|
55
|
-
const
|
|
72
|
+
const resetEmailFlow = () => {
|
|
73
|
+
setShowEmailFlow(false);
|
|
74
|
+
setEmailCodeSent(false);
|
|
75
|
+
setVerificationCode("");
|
|
76
|
+
setEmailError(null);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const connectWithOptions = async (
|
|
80
|
+
strategy: AllowedStrategy,
|
|
81
|
+
options: MultiStepAuthArgsType | SingleStepAuthArgsType,
|
|
82
|
+
) => {
|
|
56
83
|
try {
|
|
57
84
|
setIsLoading(true);
|
|
58
85
|
debug("setIsAuthenticating:true:3");
|
|
59
86
|
setIsAuthenticating(true);
|
|
60
|
-
const options = getConnectOptionsFromStrategy(strategy);
|
|
61
87
|
let connectResult: Wallet | null;
|
|
62
88
|
|
|
63
|
-
if (automaticallySetFirstEoa) {
|
|
64
|
-
|
|
89
|
+
if (automaticallySetFirstEoa && isWalletType(strategy) && options.strategy === "wallet") {
|
|
90
|
+
const walletId = options.wallet?.id as WalletId | undefined;
|
|
91
|
+
if (!walletId) {
|
|
65
92
|
throw new Error("Wallet ID is required");
|
|
66
93
|
}
|
|
94
|
+
|
|
67
95
|
connectResult = await connectTW(async () => {
|
|
68
|
-
const wallet = createWallet(
|
|
96
|
+
const wallet = createWallet(walletId);
|
|
69
97
|
await wallet.connect({
|
|
70
98
|
client,
|
|
71
99
|
});
|
|
@@ -73,19 +101,27 @@ export function LoginStepCustom({
|
|
|
73
101
|
return wallet;
|
|
74
102
|
});
|
|
75
103
|
} else {
|
|
76
|
-
// @ts-expect-error we have custom strategies too and we also get things like "apple" isn't assignable to "wallet"
|
|
77
104
|
connectResult = await connect(options);
|
|
78
105
|
}
|
|
79
106
|
|
|
80
107
|
const account = connectResult?.getAccount();
|
|
81
108
|
debug("@@connectResult", { connectResult, account, options });
|
|
82
|
-
if (!account) throw new Error("Failed to connect");
|
|
109
|
+
if (!account || !connectResult) throw new Error("Failed to connect");
|
|
110
|
+
const allConnectedWallets =
|
|
111
|
+
connectedWallets.length > 0 && connectedWallets.some(wallet => wallet.id === connectResult.id)
|
|
112
|
+
? connectedWallets
|
|
113
|
+
: [connectResult, ...connectedWallets.filter(wallet => wallet.id !== connectResult.id)];
|
|
114
|
+
await onAuthConnect(connectResult, allConnectedWallets);
|
|
83
115
|
await onSuccess(account);
|
|
84
|
-
|
|
116
|
+
if (strategy === "email") {
|
|
117
|
+
resetEmailFlow();
|
|
118
|
+
}
|
|
85
119
|
} catch (error) {
|
|
120
|
+
if (strategy === "email") {
|
|
121
|
+
setEmailError(error instanceof Error ? error.message : "Failed to sign in with email");
|
|
122
|
+
}
|
|
86
123
|
await onError?.(error as Error);
|
|
87
124
|
await logout();
|
|
88
|
-
setIsAuthenticated(false);
|
|
89
125
|
} finally {
|
|
90
126
|
setIsLoading(false);
|
|
91
127
|
debug("setIsAuthenticating:false:3");
|
|
@@ -93,60 +129,177 @@ export function LoginStepCustom({
|
|
|
93
129
|
}
|
|
94
130
|
};
|
|
95
131
|
|
|
132
|
+
const handleConnect = async (strategy: AllowedStrategy) => {
|
|
133
|
+
if (strategy === "email") {
|
|
134
|
+
setShowEmailFlow(true);
|
|
135
|
+
setEmailCodeSent(false);
|
|
136
|
+
setVerificationCode("");
|
|
137
|
+
setEmailError(null);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const options = getConnectOptionsFromStrategy(strategy);
|
|
142
|
+
await connectWithOptions(strategy, options as SingleStepAuthArgsType);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const handleSendEmailCode = async () => {
|
|
146
|
+
const normalizedEmail = email.trim().toLowerCase();
|
|
147
|
+
if (!normalizedEmail) {
|
|
148
|
+
setEmailError("Please enter your email address");
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (!EMAIL_REGEX.test(normalizedEmail)) {
|
|
153
|
+
setEmailError("Please enter a valid email address");
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
setIsLoading(true);
|
|
159
|
+
setEmailError(null);
|
|
160
|
+
await preAuthenticate({
|
|
161
|
+
client,
|
|
162
|
+
strategy: "email",
|
|
163
|
+
email: normalizedEmail,
|
|
164
|
+
ecosystem: {
|
|
165
|
+
id: ecosystemWalletId,
|
|
166
|
+
partnerId,
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
setEmail(normalizedEmail);
|
|
170
|
+
setEmailCodeSent(true);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
setEmailError(error instanceof Error ? error.message : "Failed to send verification code");
|
|
173
|
+
await onError?.(error as Error);
|
|
174
|
+
} finally {
|
|
175
|
+
setIsLoading(false);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const handleEmailLogin = async () => {
|
|
180
|
+
const normalizedEmail = email.trim().toLowerCase();
|
|
181
|
+
const normalizedCode = verificationCode.trim();
|
|
182
|
+
|
|
183
|
+
if (!EMAIL_REGEX.test(normalizedEmail)) {
|
|
184
|
+
setEmailError("Please enter a valid email address");
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (!normalizedCode) {
|
|
189
|
+
setEmailError("Please enter your verification code");
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
await connectWithOptions("email", {
|
|
194
|
+
strategy: "email",
|
|
195
|
+
email: normalizedEmail,
|
|
196
|
+
verificationCode: normalizedCode,
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
|
|
96
200
|
return (
|
|
97
201
|
<LoginStepContainer partnerId={partnerId}>
|
|
98
|
-
{
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
onClick={() => handleConnect(strategy)}
|
|
108
|
-
isLoading={isLoading}
|
|
109
|
-
/>
|
|
110
|
-
);
|
|
111
|
-
})}
|
|
112
|
-
</div>
|
|
113
|
-
)}
|
|
114
|
-
|
|
115
|
-
{/* Initial Wallet List */}
|
|
116
|
-
<div className="mb-4 w-full space-y-2">
|
|
117
|
-
{initialWallets.map(walletId => (
|
|
118
|
-
<WalletRow
|
|
119
|
-
key={walletId}
|
|
120
|
-
walletId={walletId as WalletId}
|
|
121
|
-
onClick={() => handleConnect(walletId)}
|
|
122
|
-
isLoading={isLoading}
|
|
202
|
+
{showEmailFlow ? (
|
|
203
|
+
<div className="mb-6 w-full space-y-3 px-3">
|
|
204
|
+
<p className="text-center text-sm font-medium text-gray-900 dark:text-gray-100">Sign in with email</p>
|
|
205
|
+
<Input
|
|
206
|
+
type="email"
|
|
207
|
+
placeholder="you@example.com"
|
|
208
|
+
value={email}
|
|
209
|
+
onChange={event => setEmail(event.target.value)}
|
|
210
|
+
disabled={isLoading || emailCodeSent}
|
|
123
211
|
/>
|
|
124
|
-
))}
|
|
125
|
-
</div>
|
|
126
212
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
213
|
+
{emailCodeSent && (
|
|
214
|
+
<Input
|
|
215
|
+
type="text"
|
|
216
|
+
placeholder="Enter verification code"
|
|
217
|
+
value={verificationCode}
|
|
218
|
+
onChange={event => setVerificationCode(event.target.value)}
|
|
219
|
+
disabled={isLoading}
|
|
220
|
+
/>
|
|
221
|
+
)}
|
|
222
|
+
|
|
223
|
+
{emailError && <p className="text-sm text-red-500">{emailError}</p>}
|
|
224
|
+
|
|
130
225
|
<Button
|
|
131
|
-
onClick={
|
|
132
|
-
|
|
226
|
+
onClick={emailCodeSent ? handleEmailLogin : handleSendEmailCode}
|
|
227
|
+
disabled={isLoading}
|
|
228
|
+
className="w-full"
|
|
133
229
|
>
|
|
134
|
-
{
|
|
230
|
+
{isLoading ? "Loading..." : emailCodeSent ? "Verify code" : "Send code"}
|
|
135
231
|
</Button>
|
|
136
232
|
|
|
137
|
-
{
|
|
138
|
-
<
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
233
|
+
{emailCodeSent && (
|
|
234
|
+
<Button variant="outline" onClick={handleSendEmailCode} disabled={isLoading} className="w-full">
|
|
235
|
+
Resend code
|
|
236
|
+
</Button>
|
|
237
|
+
)}
|
|
238
|
+
|
|
239
|
+
<Button variant="outline" onClick={resetEmailFlow} disabled={isLoading} className="w-full">
|
|
240
|
+
Back
|
|
241
|
+
</Button>
|
|
242
|
+
</div>
|
|
243
|
+
) : (
|
|
244
|
+
<>
|
|
245
|
+
{/* Auth Strategies */}
|
|
246
|
+
{authStrategies.length > 0 && (
|
|
247
|
+
<div
|
|
248
|
+
className={`mb-6 grid w-full gap-4 px-3 ${authStrategies.length > 4 ? "grid-cols-4" : ""}`}
|
|
249
|
+
style={
|
|
250
|
+
authStrategies.length <= 4
|
|
251
|
+
? { gridTemplateColumns: `repeat(${authGridColumns}, minmax(0, 1fr))` }
|
|
252
|
+
: undefined
|
|
253
|
+
}
|
|
254
|
+
>
|
|
255
|
+
{authStrategies.map(strategy => (
|
|
256
|
+
<AuthButton
|
|
257
|
+
key={strategy}
|
|
258
|
+
strategy={strategy}
|
|
259
|
+
onClick={() => handleConnect(strategy)}
|
|
144
260
|
isLoading={isLoading}
|
|
145
261
|
/>
|
|
146
262
|
))}
|
|
147
263
|
</div>
|
|
148
264
|
)}
|
|
149
|
-
|
|
265
|
+
|
|
266
|
+
{/* Initial Wallet List */}
|
|
267
|
+
<div className="mb-4 w-full space-y-2">
|
|
268
|
+
{initialWallets.map(walletId => (
|
|
269
|
+
<WalletRow
|
|
270
|
+
key={walletId}
|
|
271
|
+
walletId={walletId as WalletId}
|
|
272
|
+
onClick={() => handleConnect(walletId)}
|
|
273
|
+
isLoading={isLoading}
|
|
274
|
+
/>
|
|
275
|
+
))}
|
|
276
|
+
</div>
|
|
277
|
+
|
|
278
|
+
{/* Additional Wallets Section */}
|
|
279
|
+
{additionalWallets.length > 0 && (
|
|
280
|
+
<div className="w-full">
|
|
281
|
+
<Button
|
|
282
|
+
onClick={() => setShowAllWallets(!showAllWallets)}
|
|
283
|
+
className="mb-2 w-full bg-transparent text-gray-600 hover:bg-gray-100"
|
|
284
|
+
>
|
|
285
|
+
{showAllWallets ? "Show less" : "More options"}
|
|
286
|
+
</Button>
|
|
287
|
+
|
|
288
|
+
{showAllWallets && (
|
|
289
|
+
<div className="max-h-60 space-y-2 overflow-y-auto">
|
|
290
|
+
{additionalWallets.map(walletId => (
|
|
291
|
+
<WalletRow
|
|
292
|
+
key={walletId}
|
|
293
|
+
walletId={walletId as WalletId}
|
|
294
|
+
onClick={() => handleConnect(walletId)}
|
|
295
|
+
isLoading={isLoading}
|
|
296
|
+
/>
|
|
297
|
+
))}
|
|
298
|
+
</div>
|
|
299
|
+
)}
|
|
300
|
+
</div>
|
|
301
|
+
)}
|
|
302
|
+
</>
|
|
150
303
|
)}
|
|
151
304
|
</LoginStepContainer>
|
|
152
305
|
);
|