@b3dotfun/sdk 0.1.69-alpha.1 → 0.1.69-alpha.11
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/bsmnt.d.ts +0 -1
- package/dist/cjs/global-account/bsmnt.js +0 -6
- 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/global-account/react/utils/index.d.ts +0 -1
- package/dist/cjs/global-account/react/utils/index.js +0 -1
- 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/bsmnt.d.ts +0 -1
- package/dist/esm/global-account/bsmnt.js +0 -5
- 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/global-account/react/utils/index.d.ts +0 -1
- package/dist/esm/global-account/react/utils/index.js +0 -1
- 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/bsmnt.d.ts +0 -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/global-account/react/utils/index.d.ts +0 -1
- package/dist/types/shared/utils/session-duration.d.ts +15 -0
- package/package.json +2 -6
- 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/bsmnt.ts +0 -6
- 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/global-account/react/utils/index.ts +0 -1
- package/src/shared/utils/session-duration.ts +64 -0
- package/src/types/torph.d.ts +4 -0
- package/dist/cjs/global-account/react/components/AvatarCreator/AvatarCreator.d.ts +0 -6
- package/dist/cjs/global-account/react/components/AvatarCreator/AvatarCreator.js +0 -54
- package/dist/cjs/global-account/react/components/ProfileAvatar.d.ts +0 -0
- package/dist/cjs/global-account/react/components/ProfileAvatar.js +0 -127
- package/dist/cjs/global-account/react/hooks/useRPMToken.d.ts +0 -7
- package/dist/cjs/global-account/react/hooks/useRPMToken.js +0 -11
- package/dist/cjs/global-account/react/utils/updateAvatar.d.ts +0 -4
- package/dist/cjs/global-account/react/utils/updateAvatar.js +0 -54
- package/dist/esm/global-account/react/components/AvatarCreator/AvatarCreator.d.ts +0 -6
- package/dist/esm/global-account/react/components/AvatarCreator/AvatarCreator.js +0 -51
- package/dist/esm/global-account/react/components/ProfileAvatar.d.ts +0 -0
- package/dist/esm/global-account/react/components/ProfileAvatar.js +0 -127
- package/dist/esm/global-account/react/hooks/useRPMToken.d.ts +0 -7
- package/dist/esm/global-account/react/hooks/useRPMToken.js +0 -8
- package/dist/esm/global-account/react/utils/updateAvatar.d.ts +0 -4
- package/dist/esm/global-account/react/utils/updateAvatar.js +0 -18
- package/dist/types/global-account/react/components/AvatarCreator/AvatarCreator.d.ts +0 -6
- package/dist/types/global-account/react/components/ProfileAvatar.d.ts +0 -0
- package/dist/types/global-account/react/hooks/useRPMToken.d.ts +0 -7
- package/dist/types/global-account/react/utils/updateAvatar.d.ts +0 -4
- package/src/global-account/react/components/AvatarCreator/AvatarCreator.tsx +0 -90
- package/src/global-account/react/components/ProfileAvatar.tsx +0 -138
- package/src/global-account/react/hooks/useRPMToken.ts +0 -17
- package/src/global-account/react/utils/updateAvatar.ts +0 -21
|
@@ -6,7 +6,7 @@ import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
|
6
6
|
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
7
7
|
import { ConnectionOptions } from "@thirdweb-dev/wagmi-adapter";
|
|
8
8
|
import { getConnectors } from "@wagmi/core";
|
|
9
|
-
import { useCallback, useContext, useEffect, useRef } from "react";
|
|
9
|
+
import { useCallback, useContext, useEffect, useMemo, useRef } from "react";
|
|
10
10
|
import {
|
|
11
11
|
useActiveWallet,
|
|
12
12
|
useAutoConnect,
|
|
@@ -25,7 +25,7 @@ import { useUserQuery } from "./useUserQuery";
|
|
|
25
25
|
const debug = debugB3React("useAuthentication");
|
|
26
26
|
|
|
27
27
|
export function useAuthentication(partnerId: string, { skipAutoConnect = false }: { skipAutoConnect?: boolean } = {}) {
|
|
28
|
-
const { onConnectCallback, onLogoutCallback } = useContext(LocalSDKContext);
|
|
28
|
+
const { onConnectCallback, onLogoutCallback, disableBSMNTAuthentication } = useContext(LocalSDKContext);
|
|
29
29
|
const { disconnect } = useDisconnect();
|
|
30
30
|
const wallets = useConnectedWallets();
|
|
31
31
|
// Keep refs so logout() always disconnects current wallets, not stale closure values.
|
|
@@ -57,7 +57,7 @@ export function useAuthentication(partnerId: string, { skipAutoConnect = false }
|
|
|
57
57
|
const { authenticate } = useTWAuth();
|
|
58
58
|
const { user, setUser } = useUserQuery();
|
|
59
59
|
const useAutoConnectLoadingPrevious = useRef(false);
|
|
60
|
-
const wagmiConfig = createWagmiConfig({ partnerId });
|
|
60
|
+
const wagmiConfig = useMemo(() => createWagmiConfig({ partnerId }), [partnerId]);
|
|
61
61
|
const { connect } = useConnect();
|
|
62
62
|
const activeWagmiAccount = useAccount();
|
|
63
63
|
const { switchAccount } = useSwitchAccount();
|
|
@@ -113,9 +113,7 @@ export function useAuthentication(partnerId: string, { skipAutoConnect = false }
|
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
syncWagmiFunc();
|
|
116
|
-
|
|
117
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
118
|
-
}, [partnerId, wallets]);
|
|
116
|
+
}, [wagmiConfig, wallets, connect, switchAccount]);
|
|
119
117
|
|
|
120
118
|
useEffect(() => {
|
|
121
119
|
syncWagmi();
|
|
@@ -142,9 +140,11 @@ export function useAuthentication(partnerId: string, { skipAutoConnect = false }
|
|
|
142
140
|
setIsAuthenticating(false);
|
|
143
141
|
debug("Re-authenticated successfully", { userAuth });
|
|
144
142
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
143
|
+
if (!disableBSMNTAuthentication) {
|
|
144
|
+
// Authenticate on BSMNT with B3 JWT
|
|
145
|
+
const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
|
|
146
|
+
debug("@@b3Jwt", b3Jwt);
|
|
147
|
+
}
|
|
148
148
|
|
|
149
149
|
return userAuth;
|
|
150
150
|
} catch (error) {
|
|
@@ -156,14 +156,25 @@ export function useAuthentication(partnerId: string, { skipAutoConnect = false }
|
|
|
156
156
|
setIsAuthenticating(false);
|
|
157
157
|
debug("Fresh authentication successful", { userAuth });
|
|
158
158
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
if (!disableBSMNTAuthentication) {
|
|
160
|
+
// Authenticate on BSMNT with B3 JWT
|
|
161
|
+
const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
|
|
162
|
+
debug("@@b3Jwt", b3Jwt);
|
|
163
|
+
}
|
|
162
164
|
|
|
163
165
|
return userAuth;
|
|
164
166
|
}
|
|
165
167
|
},
|
|
166
|
-
[
|
|
168
|
+
[
|
|
169
|
+
activeWallet,
|
|
170
|
+
partnerId,
|
|
171
|
+
authenticate,
|
|
172
|
+
setIsAuthenticated,
|
|
173
|
+
setIsAuthenticating,
|
|
174
|
+
setUser,
|
|
175
|
+
setHasStartedConnecting,
|
|
176
|
+
disableBSMNTAuthentication,
|
|
177
|
+
],
|
|
167
178
|
);
|
|
168
179
|
|
|
169
180
|
const logout = useCallback(
|
|
@@ -4,7 +4,7 @@ import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
|
4
4
|
import { useCallback, useState } from "react";
|
|
5
5
|
import { Chain } from "thirdweb";
|
|
6
6
|
import { useConnect as useConnectTW } from "thirdweb/react";
|
|
7
|
-
import { ecosystemWallet, SingleStepAuthArgsType } from "thirdweb/wallets";
|
|
7
|
+
import { ecosystemWallet, MultiStepAuthArgsType, SingleStepAuthArgsType } from "thirdweb/wallets";
|
|
8
8
|
const debug = debugB3React("useConnect");
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -23,7 +23,7 @@ export function useConnect(partnerId: string, chain?: Chain) {
|
|
|
23
23
|
* It is used to connect to a wallet using the thirdweb client.
|
|
24
24
|
*/
|
|
25
25
|
const connectTw = useCallback(
|
|
26
|
-
async (strategyOptions?: SingleStepAuthArgsType) => {
|
|
26
|
+
async (strategyOptions?: MultiStepAuthArgsType | SingleStepAuthArgsType) => {
|
|
27
27
|
setIsLoading(true);
|
|
28
28
|
return await connect(async () => {
|
|
29
29
|
if (!strategyOptions) throw new Error("Strategy options are required");
|
|
@@ -12,7 +12,6 @@ import { useSearchParam } from "./useSearchParamsSSR";
|
|
|
12
12
|
* @deprecated Use useAuth() instead
|
|
13
13
|
*/
|
|
14
14
|
export function useTWAuth() {
|
|
15
|
-
console.warn("useTWAuth is deprecated. Please migrate to useAuth() for authentication.");
|
|
16
15
|
const referralCode = useSearchParam("referralCode");
|
|
17
16
|
|
|
18
17
|
const authenticate = useCallback(
|
|
@@ -451,6 +451,16 @@ export interface SendModalProps extends BaseModalProps {
|
|
|
451
451
|
onSuccess?: (txHash?: string) => void;
|
|
452
452
|
}
|
|
453
453
|
|
|
454
|
+
/**
|
|
455
|
+
* Props for the Session Duration modal
|
|
456
|
+
* Allows users to configure how long they stay signed in
|
|
457
|
+
*/
|
|
458
|
+
export interface SessionDurationModalProps extends BaseModalProps {
|
|
459
|
+
type: "sessionDuration";
|
|
460
|
+
partnerId: string;
|
|
461
|
+
chain: Chain;
|
|
462
|
+
}
|
|
463
|
+
|
|
454
464
|
/**
|
|
455
465
|
* Props for the Notifications modal
|
|
456
466
|
* Allows users to manage notification settings and channels
|
|
@@ -677,6 +687,7 @@ export type ModalContentType =
|
|
|
677
687
|
| DepositModalProps
|
|
678
688
|
| SendModalProps
|
|
679
689
|
| NotificationsModalProps
|
|
690
|
+
| SessionDurationModalProps
|
|
680
691
|
| AnySpendCollectorClubPurchaseProps
|
|
681
692
|
| AnySpendDepositModalProps
|
|
682
693
|
| AnySpendWorkflowTriggerModalProps
|
|
@@ -38,21 +38,3 @@ export function createWagmiConfig(options: CreateWagmiConfigOptions) {
|
|
|
38
38
|
connectors: finalConnectors,
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
/** Module-level cache — wagmi configs must not be recreated on every render. */
|
|
43
|
-
const wagmiConfigCache = new Map<string, ReturnType<typeof createWagmiConfig>>();
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Returns a cached wagmi config for the given partnerId.
|
|
47
|
-
* Use this instead of calling createWagmiConfig() directly inside React components or hooks
|
|
48
|
-
* to avoid registering duplicate EventEmitter listeners on every render.
|
|
49
|
-
*/
|
|
50
|
-
export function getCachedWagmiConfig(options: CreateWagmiConfigOptions) {
|
|
51
|
-
const key = options.partnerId;
|
|
52
|
-
let config = wagmiConfigCache.get(key);
|
|
53
|
-
if (!config) {
|
|
54
|
-
config = createWagmiConfig(options);
|
|
55
|
-
wagmiConfigCache.set(key, config);
|
|
56
|
-
}
|
|
57
|
-
return config;
|
|
58
|
-
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const STORAGE_KEY_PREFIX = "b3-session-duration";
|
|
2
|
+
const DEFAULT_DAYS = 7;
|
|
3
|
+
|
|
4
|
+
// 0 = session cookie (expires when browser closes)
|
|
5
|
+
export const SESSION_DURATION_OPTIONS = [0, 1, 7, 14, 30] as const;
|
|
6
|
+
export type SessionDurationDays = (typeof SESSION_DURATION_OPTIONS)[number];
|
|
7
|
+
|
|
8
|
+
function storageKey(partnerId?: string) {
|
|
9
|
+
return partnerId ? `${STORAGE_KEY_PREFIX}_${partnerId}` : STORAGE_KEY_PREFIX;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Read session duration for a specific partner.
|
|
14
|
+
*
|
|
15
|
+
* preferences shape: { [partnerId]: { sessionDuration: number }, sessionDuration?: number }
|
|
16
|
+
*
|
|
17
|
+
* Priority: user.preferences[partnerId].sessionDuration
|
|
18
|
+
* → user.preferences.sessionDuration (global fallback)
|
|
19
|
+
* → localStorage (per-partner) → localStorage (global) → default 7d
|
|
20
|
+
*/
|
|
21
|
+
export function getSessionDurationDays(userPreferences?: Record<string, any>, partnerId?: string): SessionDurationDays {
|
|
22
|
+
if (userPreferences) {
|
|
23
|
+
if (partnerId) {
|
|
24
|
+
const v = userPreferences[partnerId]?.sessionDuration;
|
|
25
|
+
if (SESSION_DURATION_OPTIONS.includes(v as SessionDurationDays)) return v as SessionDurationDays;
|
|
26
|
+
}
|
|
27
|
+
const v = userPreferences["sessionDuration"];
|
|
28
|
+
if (SESSION_DURATION_OPTIONS.includes(v as SessionDurationDays)) return v as SessionDurationDays;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
if (partnerId) {
|
|
32
|
+
const stored = localStorage.getItem(storageKey(partnerId));
|
|
33
|
+
if (stored !== null) {
|
|
34
|
+
const parsed = Number(stored);
|
|
35
|
+
if (SESSION_DURATION_OPTIONS.includes(parsed as SessionDurationDays)) return parsed as SessionDurationDays;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const stored = localStorage.getItem(STORAGE_KEY_PREFIX);
|
|
39
|
+
if (stored !== null) {
|
|
40
|
+
const parsed = Number(stored);
|
|
41
|
+
if (SESSION_DURATION_OPTIONS.includes(parsed as SessionDurationDays)) return parsed as SessionDurationDays;
|
|
42
|
+
}
|
|
43
|
+
} catch {
|
|
44
|
+
// localStorage unavailable (e.g. SSR)
|
|
45
|
+
}
|
|
46
|
+
return DEFAULT_DAYS;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const SESSION_DURATION_LABELS: Record<SessionDurationDays, string> = {
|
|
50
|
+
0: "Session only",
|
|
51
|
+
1: "1 day",
|
|
52
|
+
7: "7 days",
|
|
53
|
+
14: "14 days",
|
|
54
|
+
30: "30 days",
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** Cache the preference locally so it's available immediately on next login */
|
|
58
|
+
export function setSessionDurationDays(days: SessionDurationDays, partnerId?: string): void {
|
|
59
|
+
try {
|
|
60
|
+
localStorage.setItem(storageKey(partnerId), String(days));
|
|
61
|
+
} catch {
|
|
62
|
+
// ignore
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
"use client";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.AvatarCreator = AvatarCreator;
|
|
5
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
-
const react_1 = require("../../../../global-account/react");
|
|
7
|
-
const useRPMToken_1 = require("../../../../global-account/react/hooks/useRPMToken");
|
|
8
|
-
const updateAvatar_1 = require("../../../../global-account/react/utils/updateAvatar");
|
|
9
|
-
const cn_1 = require("../../../../shared/utils/cn");
|
|
10
|
-
const debug_1 = require("../../../../shared/utils/debug");
|
|
11
|
-
const react_avatar_creator_1 = require("@readyplayerme/react-avatar-creator");
|
|
12
|
-
const react_2 = require("react");
|
|
13
|
-
const react_3 = require("thirdweb/react");
|
|
14
|
-
const debug = (0, debug_1.debugB3React)("AvatarCreator");
|
|
15
|
-
const config = {
|
|
16
|
-
clearCache: true,
|
|
17
|
-
bodyType: "fullbody",
|
|
18
|
-
quickStart: true,
|
|
19
|
-
language: "en",
|
|
20
|
-
};
|
|
21
|
-
function AvatarCreator({ onSetAvatar, className }) {
|
|
22
|
-
const { token, refetch: refetchRPMToken } = (0, useRPMToken_1.useRPMToken)();
|
|
23
|
-
const [loading, setIsLoading] = (0, react_2.useState)(false);
|
|
24
|
-
const account = (0, react_3.useActiveAccount)();
|
|
25
|
-
const { data: profile, refetch: refreshProfile } = (0, react_1.useProfile)({
|
|
26
|
-
address: account?.address,
|
|
27
|
-
fresh: true,
|
|
28
|
-
});
|
|
29
|
-
const hasAvatar = profile?.avatar;
|
|
30
|
-
const handleOnAvatarExported = async (event) => {
|
|
31
|
-
setIsLoading(true);
|
|
32
|
-
debug("@@AvatarExportedEvent", event);
|
|
33
|
-
try {
|
|
34
|
-
const avatarUpload = await (0, updateAvatar_1.updateAvatar)(event.data.url);
|
|
35
|
-
debug("@@avatarUpload", avatarUpload);
|
|
36
|
-
await refreshProfile();
|
|
37
|
-
react_1.toast.success(hasAvatar ? "Nice look! Your avatar has been updated!" : "Looks great! Your avatar has been saved!");
|
|
38
|
-
onSetAvatar?.();
|
|
39
|
-
await refetchRPMToken(undefined);
|
|
40
|
-
}
|
|
41
|
-
catch (e) {
|
|
42
|
-
debug("@@error:AvatarCreator", e);
|
|
43
|
-
react_1.toast.error("Failed to update avatar. Please try again.");
|
|
44
|
-
}
|
|
45
|
-
setIsLoading(false);
|
|
46
|
-
};
|
|
47
|
-
if (loading) {
|
|
48
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: "flex h-[80vh] w-full flex-col items-center justify-center gap-4", children: [(0, jsx_runtime_1.jsx)("div", { className: "border-primary h-8 w-8 animate-spin rounded-full border-4 border-t-transparent" }), (0, jsx_runtime_1.jsx)("p", { className: "text-muted-foreground text-sm font-medium", children: "Saving your avatar" })] }));
|
|
49
|
-
}
|
|
50
|
-
if (!token) {
|
|
51
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: "flex h-[80vh] w-full flex-col items-center justify-center gap-4", children: [(0, jsx_runtime_1.jsx)("div", { className: "border-primary h-8 w-8 animate-spin rounded-full border-4 border-t-transparent" }), (0, jsx_runtime_1.jsx)("p", { className: "text-muted-foreground text-sm font-medium", children: "Loading avatar creator" })] }));
|
|
52
|
-
}
|
|
53
|
-
return ((0, jsx_runtime_1.jsx)("div", { className: (0, cn_1.cn)("h-[calc(90vh-2px)] w-full", className), children: (0, jsx_runtime_1.jsx)(react_avatar_creator_1.AvatarCreator, { className: "h-full w-full", subdomain: "b3", config: { ...config, token }, onAvatarExported: handleOnAvatarExported }) }));
|
|
54
|
-
}
|
|
File without changes
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// "use client";
|
|
3
|
-
// import { AnimatePresence, motion } from "motion/react";
|
|
4
|
-
// import { useEffect, useState } from "react";
|
|
5
|
-
// import ClientOnly from "./custom/ClientOnly";
|
|
6
|
-
// interface ProfileAvatarProps {
|
|
7
|
-
// avatarId: string;
|
|
8
|
-
// timestamp?: number;
|
|
9
|
-
// }
|
|
10
|
-
// // this function was taken from b3-shared
|
|
11
|
-
// function createUrlFromAvatarId(avatarId: string, extension: string = "png"): string {
|
|
12
|
-
// if (extension === "png") {
|
|
13
|
-
// return `https://avatars.basement.fun/${avatarId}.png`;
|
|
14
|
-
// }
|
|
15
|
-
// return `https://models.readyplayer.me/${avatarId}.${extension}`;
|
|
16
|
-
// }
|
|
17
|
-
// // Sub component for the avatar image
|
|
18
|
-
// const ProfileAvatar = ({ avatarId, timestamp }: ProfileAvatarProps) => {
|
|
19
|
-
// const [avatarLoading, setAvatarLoading] = useState(true);
|
|
20
|
-
// const [avatarError, setAvatarError] = useState(false);
|
|
21
|
-
// const [ReadyPlayerMeAvatar, setReadyPlayerMeAvatar] = useState<any>(null);
|
|
22
|
-
// const [Vector3, setVector3] = useState<any>(null);
|
|
23
|
-
// const [dependenciesLoaded, setDependenciesLoaded] = useState(false);
|
|
24
|
-
// // Dynamically import dependencies only when component is used
|
|
25
|
-
// useEffect(() => {
|
|
26
|
-
// let isMounted = true;
|
|
27
|
-
// const loadDependencies = async () => {
|
|
28
|
-
// try {
|
|
29
|
-
// const [visageModule, threeModule] = await Promise.all([
|
|
30
|
-
// // @ts-ignore - Optional peer dependency
|
|
31
|
-
// import("@readyplayerme/visage"),
|
|
32
|
-
// // @ts-ignore - Optional peer dependency
|
|
33
|
-
// import("three")
|
|
34
|
-
// ]);
|
|
35
|
-
// if (isMounted) {
|
|
36
|
-
// setReadyPlayerMeAvatar(() => visageModule.Avatar);
|
|
37
|
-
// setVector3(() => threeModule.Vector3);
|
|
38
|
-
// setDependenciesLoaded(true);
|
|
39
|
-
// }
|
|
40
|
-
// } catch (error) {
|
|
41
|
-
// console.warn("ProfileAvatar: 3D dependencies not available, falling back to 2D avatar:", error);
|
|
42
|
-
// if (isMounted) {
|
|
43
|
-
// setAvatarLoading(false);
|
|
44
|
-
// setDependenciesLoaded(false);
|
|
45
|
-
// }
|
|
46
|
-
// }
|
|
47
|
-
// };
|
|
48
|
-
// loadDependencies();
|
|
49
|
-
// return () => {
|
|
50
|
-
// isMounted = false;
|
|
51
|
-
// };
|
|
52
|
-
// }, []);
|
|
53
|
-
// if (!avatarId) {
|
|
54
|
-
// return (
|
|
55
|
-
// <div className="flex h-full w-full items-center justify-center">
|
|
56
|
-
// <p className="text-white/50">No avatar available</p>
|
|
57
|
-
// </div>
|
|
58
|
-
// );
|
|
59
|
-
// }
|
|
60
|
-
// return (
|
|
61
|
-
// <AnimatePresence mode="wait">
|
|
62
|
-
// {(avatarLoading || !dependenciesLoaded) && !avatarError && (
|
|
63
|
-
// <motion.img
|
|
64
|
-
// key="avatar-image"
|
|
65
|
-
// src={`https://models.readyplayer.me/${avatarId}.png?camera=fullbody&size=1024&expression=happy&t=${timestamp || ""}`}
|
|
66
|
-
// alt="avatar"
|
|
67
|
-
// className="absolute left-0 top-0 h-full w-full object-cover"
|
|
68
|
-
// initial={{ opacity: 0 }}
|
|
69
|
-
// animate={{ opacity: 1 }}
|
|
70
|
-
// exit={{ opacity: 0 }}
|
|
71
|
-
// transition={{ duration: 0.3, ease: "easeInOut" }}
|
|
72
|
-
// onError={() => setAvatarError(true)}
|
|
73
|
-
// />
|
|
74
|
-
// )}
|
|
75
|
-
// {dependenciesLoaded && (
|
|
76
|
-
// <ClientOnly>
|
|
77
|
-
// <motion.div
|
|
78
|
-
// key={`avatar-3d-${timestamp}`}
|
|
79
|
-
// className="absolute left-0 top-0 h-full w-full"
|
|
80
|
-
// initial={{ opacity: 0 }}
|
|
81
|
-
// animate={{ opacity: avatarLoading ? 0 : 1 }}
|
|
82
|
-
// exit={{ opacity: 0 }}
|
|
83
|
-
// transition={{ duration: 0.3, ease: "easeInOut" }}
|
|
84
|
-
// >
|
|
85
|
-
// {ReadyPlayerMeAvatar && Vector3 && (
|
|
86
|
-
// <ReadyPlayerMeAvatar
|
|
87
|
-
// animationSrc="https://readyplayerme-assets.s3.amazonaws.com/animations/visage/male-idle.glb"
|
|
88
|
-
// onLoadedAnimation={{
|
|
89
|
-
// src: "https://readyplayerme-assets.s3.amazonaws.com/animations/visage/male-spawn-animation.fbx",
|
|
90
|
-
// loop: 4
|
|
91
|
-
// }}
|
|
92
|
-
// modelSrc={createUrlFromAvatarId(avatarId, "glb")}
|
|
93
|
-
// idleRotation={true}
|
|
94
|
-
// headMovement={true}
|
|
95
|
-
// scale={0.9}
|
|
96
|
-
// keyLightColor="#bca1f4"
|
|
97
|
-
// keyLightIntensity={1}
|
|
98
|
-
// fillLightColor="#8d4cf6"
|
|
99
|
-
// fov={50}
|
|
100
|
-
// emotion={{
|
|
101
|
-
// browInnerUp: 0.3,
|
|
102
|
-
// browOuterUpLeft: 0.37,
|
|
103
|
-
// browOuterUpRight: 0.49,
|
|
104
|
-
// eyeSquintLeft: 0.4,
|
|
105
|
-
// eyeSquintRight: 0.2,
|
|
106
|
-
// mouthShrugUpper: 0.27,
|
|
107
|
-
// mouthSmileLeft: 0.37,
|
|
108
|
-
// mouthSmileRight: 0.36
|
|
109
|
-
// }}
|
|
110
|
-
// cameraZoomTarget={new Vector3(0, 0.1, 3.2)}
|
|
111
|
-
// cameraInitialDistance={3.2}
|
|
112
|
-
// cameraTarget={1.55}
|
|
113
|
-
// className="h-full w-full"
|
|
114
|
-
// onLoaded={() => {
|
|
115
|
-
// setAvatarLoading(false);
|
|
116
|
-
// setAvatarError(false);
|
|
117
|
-
// }}
|
|
118
|
-
// shadows
|
|
119
|
-
// />
|
|
120
|
-
// )}
|
|
121
|
-
// </motion.div>
|
|
122
|
-
// </ClientOnly>
|
|
123
|
-
// )}
|
|
124
|
-
// </AnimatePresence>
|
|
125
|
-
// );
|
|
126
|
-
// };
|
|
127
|
-
// export default ProfileAvatar;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
"use client";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.useRPMToken = useRPMToken;
|
|
5
|
-
const useQueryBSMNT_1 = require("../../../global-account/react/hooks/useQueryBSMNT");
|
|
6
|
-
function useRPMToken() {
|
|
7
|
-
const { data, runQuery: refetch, isLoading, error: isError, } = (0, useQueryBSMNT_1.useQueryBSMNT)("profiles", "getReadyPlayerMeToken", undefined, true);
|
|
8
|
-
const token = data?.token || "";
|
|
9
|
-
const accountId = data?.accountId || "";
|
|
10
|
-
return { token, accountId, refetch, isLoading, isError };
|
|
11
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.updateAvatar = updateAvatar;
|
|
37
|
-
const bsmnt_1 = __importStar(require("../../../global-account/bsmnt"));
|
|
38
|
-
const debug_1 = require("../../../shared/utils/debug");
|
|
39
|
-
const debug = (0, debug_1.debugB3React)("updateAvatar");
|
|
40
|
-
async function updateAvatar(avatar) {
|
|
41
|
-
try {
|
|
42
|
-
// Extract avatar ID from URL
|
|
43
|
-
const avatarID = (0, bsmnt_1.extractAvatarIdFromUrl)(avatar);
|
|
44
|
-
if (!avatarID) {
|
|
45
|
-
throw new Error("Invalid avatar URL");
|
|
46
|
-
}
|
|
47
|
-
// Set the avatar in the profiles service
|
|
48
|
-
return await bsmnt_1.default.service("profiles").setAvatar({ avatarUrl: String(avatar), avatarID: String(avatarID) }, {});
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
debug("Failed to update avatar:", error);
|
|
52
|
-
throw error; // Re-throw to handle in component
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { toast, useProfile } from "../../../../global-account/react/index.js";
|
|
4
|
-
import { useRPMToken } from "../../../../global-account/react/hooks/useRPMToken.js";
|
|
5
|
-
import { updateAvatar } from "../../../../global-account/react/utils/updateAvatar.js";
|
|
6
|
-
import { cn } from "../../../../shared/utils/cn.js";
|
|
7
|
-
import { debugB3React } from "../../../../shared/utils/debug.js";
|
|
8
|
-
import { AvatarCreator as AvatarCreatorRPM, } from "@readyplayerme/react-avatar-creator";
|
|
9
|
-
import { useState } from "react";
|
|
10
|
-
import { useActiveAccount } from "thirdweb/react";
|
|
11
|
-
const debug = debugB3React("AvatarCreator");
|
|
12
|
-
const config = {
|
|
13
|
-
clearCache: true,
|
|
14
|
-
bodyType: "fullbody",
|
|
15
|
-
quickStart: true,
|
|
16
|
-
language: "en",
|
|
17
|
-
};
|
|
18
|
-
export function AvatarCreator({ onSetAvatar, className }) {
|
|
19
|
-
const { token, refetch: refetchRPMToken } = useRPMToken();
|
|
20
|
-
const [loading, setIsLoading] = useState(false);
|
|
21
|
-
const account = useActiveAccount();
|
|
22
|
-
const { data: profile, refetch: refreshProfile } = useProfile({
|
|
23
|
-
address: account?.address,
|
|
24
|
-
fresh: true,
|
|
25
|
-
});
|
|
26
|
-
const hasAvatar = profile?.avatar;
|
|
27
|
-
const handleOnAvatarExported = async (event) => {
|
|
28
|
-
setIsLoading(true);
|
|
29
|
-
debug("@@AvatarExportedEvent", event);
|
|
30
|
-
try {
|
|
31
|
-
const avatarUpload = await updateAvatar(event.data.url);
|
|
32
|
-
debug("@@avatarUpload", avatarUpload);
|
|
33
|
-
await refreshProfile();
|
|
34
|
-
toast.success(hasAvatar ? "Nice look! Your avatar has been updated!" : "Looks great! Your avatar has been saved!");
|
|
35
|
-
onSetAvatar?.();
|
|
36
|
-
await refetchRPMToken(undefined);
|
|
37
|
-
}
|
|
38
|
-
catch (e) {
|
|
39
|
-
debug("@@error:AvatarCreator", e);
|
|
40
|
-
toast.error("Failed to update avatar. Please try again.");
|
|
41
|
-
}
|
|
42
|
-
setIsLoading(false);
|
|
43
|
-
};
|
|
44
|
-
if (loading) {
|
|
45
|
-
return (_jsxs("div", { className: "flex h-[80vh] w-full flex-col items-center justify-center gap-4", children: [_jsx("div", { className: "border-primary h-8 w-8 animate-spin rounded-full border-4 border-t-transparent" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: "Saving your avatar" })] }));
|
|
46
|
-
}
|
|
47
|
-
if (!token) {
|
|
48
|
-
return (_jsxs("div", { className: "flex h-[80vh] w-full flex-col items-center justify-center gap-4", children: [_jsx("div", { className: "border-primary h-8 w-8 animate-spin rounded-full border-4 border-t-transparent" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: "Loading avatar creator" })] }));
|
|
49
|
-
}
|
|
50
|
-
return (_jsx("div", { className: cn("h-[calc(90vh-2px)] w-full", className), children: _jsx(AvatarCreatorRPM, { className: "h-full w-full", subdomain: "b3", config: { ...config, token }, onAvatarExported: handleOnAvatarExported }) }));
|
|
51
|
-
}
|
|
File without changes
|