@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.
Files changed (161) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpendStakeB3.js +1 -1
  2. package/dist/cjs/anyspend/react/components/AnySpendStakeB3ExactIn.js +1 -1
  3. package/dist/cjs/anyspend/react/components/checkout/CheckoutPaymentPanel.js +2 -4
  4. package/dist/cjs/anyspend/react/components/checkout/CheckoutSuccess.d.ts +2 -1
  5. package/dist/cjs/anyspend/react/components/checkout/CheckoutSuccess.js +5 -3
  6. package/dist/cjs/anyspend/react/components/checkout/FiatCheckoutPanel.js +1 -2
  7. package/dist/cjs/anyspend/react/components/checkout/KycGate.js +1 -2
  8. package/dist/cjs/anyspend/react/components/common/OrderDetails.js +5 -0
  9. package/dist/cjs/anyspend/react/components/common/OrderStatus.js +37 -6
  10. package/dist/cjs/anyspend/react/components/common/StepProgress.d.ts +2 -0
  11. package/dist/cjs/anyspend/react/components/common/StepProgress.js +7 -2
  12. package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +4 -6
  13. package/dist/cjs/anyspend/react/hooks/useKycStatus.d.ts +3 -1
  14. package/dist/cjs/anyspend/react/hooks/useKycStatus.js +11 -7
  15. package/dist/cjs/app.shared.js +9 -7
  16. package/dist/cjs/global-account/bsmnt.d.ts +0 -1
  17. package/dist/cjs/global-account/bsmnt.js +0 -6
  18. package/dist/cjs/global-account/react/components/B3DynamicModal.js +5 -2
  19. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +2 -1
  20. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +2 -2
  21. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +2 -1
  22. package/dist/cjs/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +3 -1
  23. package/dist/cjs/global-account/react/components/B3Provider/LocalSDKProvider.js +3 -1
  24. package/dist/cjs/global-account/react/components/ManageAccount/SessionDurationContent.d.ts +5 -0
  25. package/dist/cjs/global-account/react/components/ManageAccount/SessionDurationContent.js +57 -0
  26. package/dist/cjs/global-account/react/components/ManageAccount/SettingsContent.js +12 -29
  27. package/dist/cjs/global-account/react/components/SignInWithB3/components/AuthButton.js +10 -1
  28. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +96 -15
  29. package/dist/cjs/global-account/react/components/SignInWithB3/utils/signInUtils.d.ts +5 -3
  30. package/dist/cjs/global-account/react/components/SignInWithB3/utils/signInUtils.js +15 -2
  31. package/dist/cjs/global-account/react/components/Toast/ToastContext.d.ts +3 -0
  32. package/dist/cjs/global-account/react/components/Toast/ToastContext.js +30 -7
  33. package/dist/cjs/global-account/react/hooks/useAuth.js +26 -15
  34. package/dist/cjs/global-account/react/hooks/useAuthentication.js +23 -12
  35. package/dist/cjs/global-account/react/hooks/useConnect.d.ts +2 -2
  36. package/dist/cjs/global-account/react/hooks/useFirstEOA.d.ts +8 -8
  37. package/dist/cjs/global-account/react/hooks/useTWAuth.js +0 -1
  38. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +10 -1
  39. package/dist/cjs/global-account/react/utils/createWagmiConfig.d.ts +0 -18
  40. package/dist/cjs/global-account/react/utils/createWagmiConfig.js +0 -17
  41. package/dist/cjs/global-account/react/utils/index.d.ts +0 -1
  42. package/dist/cjs/global-account/react/utils/index.js +0 -1
  43. package/dist/cjs/shared/utils/session-duration.d.ts +15 -0
  44. package/dist/cjs/shared/utils/session-duration.js +69 -0
  45. package/dist/esm/anyspend/react/components/AnySpendStakeB3.js +2 -2
  46. package/dist/esm/anyspend/react/components/AnySpendStakeB3ExactIn.js +2 -2
  47. package/dist/esm/anyspend/react/components/checkout/CheckoutPaymentPanel.js +2 -4
  48. package/dist/esm/anyspend/react/components/checkout/CheckoutSuccess.d.ts +2 -1
  49. package/dist/esm/anyspend/react/components/checkout/CheckoutSuccess.js +5 -3
  50. package/dist/esm/anyspend/react/components/checkout/FiatCheckoutPanel.js +2 -3
  51. package/dist/esm/anyspend/react/components/checkout/KycGate.js +2 -3
  52. package/dist/esm/anyspend/react/components/common/OrderDetails.js +6 -1
  53. package/dist/esm/anyspend/react/components/common/OrderStatus.js +34 -3
  54. package/dist/esm/anyspend/react/components/common/StepProgress.d.ts +2 -0
  55. package/dist/esm/anyspend/react/components/common/StepProgress.js +4 -2
  56. package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +5 -7
  57. package/dist/esm/anyspend/react/hooks/useKycStatus.d.ts +3 -1
  58. package/dist/esm/anyspend/react/hooks/useKycStatus.js +9 -5
  59. package/dist/esm/app.shared.js +9 -7
  60. package/dist/esm/global-account/bsmnt.d.ts +0 -1
  61. package/dist/esm/global-account/bsmnt.js +0 -5
  62. package/dist/esm/global-account/react/components/B3DynamicModal.js +5 -2
  63. package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +2 -1
  64. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +2 -2
  65. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +2 -1
  66. package/dist/esm/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +3 -1
  67. package/dist/esm/global-account/react/components/B3Provider/LocalSDKProvider.js +3 -1
  68. package/dist/esm/global-account/react/components/ManageAccount/SessionDurationContent.d.ts +5 -0
  69. package/dist/esm/global-account/react/components/ManageAccount/SessionDurationContent.js +52 -0
  70. package/dist/esm/global-account/react/components/ManageAccount/SettingsContent.js +12 -29
  71. package/dist/esm/global-account/react/components/SignInWithB3/components/AuthButton.js +11 -2
  72. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +100 -19
  73. package/dist/esm/global-account/react/components/SignInWithB3/utils/signInUtils.d.ts +5 -3
  74. package/dist/esm/global-account/react/components/SignInWithB3/utils/signInUtils.js +14 -1
  75. package/dist/esm/global-account/react/components/Toast/ToastContext.d.ts +3 -0
  76. package/dist/esm/global-account/react/components/Toast/ToastContext.js +30 -7
  77. package/dist/esm/global-account/react/hooks/useAuth.js +28 -17
  78. package/dist/esm/global-account/react/hooks/useAuthentication.js +24 -13
  79. package/dist/esm/global-account/react/hooks/useConnect.d.ts +2 -2
  80. package/dist/esm/global-account/react/hooks/useFirstEOA.d.ts +8 -8
  81. package/dist/esm/global-account/react/hooks/useTWAuth.js +0 -1
  82. package/dist/esm/global-account/react/stores/useModalStore.d.ts +10 -1
  83. package/dist/esm/global-account/react/utils/createWagmiConfig.d.ts +0 -18
  84. package/dist/esm/global-account/react/utils/createWagmiConfig.js +0 -16
  85. package/dist/esm/global-account/react/utils/index.d.ts +0 -1
  86. package/dist/esm/global-account/react/utils/index.js +0 -1
  87. package/dist/esm/shared/utils/session-duration.d.ts +15 -0
  88. package/dist/esm/shared/utils/session-duration.js +64 -0
  89. package/dist/styles/index.css +1 -1
  90. package/dist/types/anyspend/react/components/checkout/CheckoutSuccess.d.ts +2 -1
  91. package/dist/types/anyspend/react/components/common/StepProgress.d.ts +2 -0
  92. package/dist/types/anyspend/react/hooks/useKycStatus.d.ts +3 -1
  93. package/dist/types/global-account/bsmnt.d.ts +0 -1
  94. package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +2 -1
  95. package/dist/types/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +3 -1
  96. package/dist/types/global-account/react/components/ManageAccount/SessionDurationContent.d.ts +5 -0
  97. package/dist/types/global-account/react/components/SignInWithB3/utils/signInUtils.d.ts +5 -3
  98. package/dist/types/global-account/react/components/Toast/ToastContext.d.ts +3 -0
  99. package/dist/types/global-account/react/hooks/useConnect.d.ts +2 -2
  100. package/dist/types/global-account/react/hooks/useFirstEOA.d.ts +8 -8
  101. package/dist/types/global-account/react/stores/useModalStore.d.ts +10 -1
  102. package/dist/types/global-account/react/utils/createWagmiConfig.d.ts +0 -18
  103. package/dist/types/global-account/react/utils/index.d.ts +0 -1
  104. package/dist/types/shared/utils/session-duration.d.ts +15 -0
  105. package/package.json +2 -6
  106. package/src/anyspend/react/components/AnySpendStakeB3.tsx +2 -2
  107. package/src/anyspend/react/components/AnySpendStakeB3ExactIn.tsx +2 -2
  108. package/src/anyspend/react/components/checkout/CheckoutPaymentPanel.tsx +2 -4
  109. package/src/anyspend/react/components/checkout/CheckoutSuccess.tsx +13 -3
  110. package/src/anyspend/react/components/checkout/FiatCheckoutPanel.tsx +9 -3
  111. package/src/anyspend/react/components/checkout/KycGate.tsx +8 -3
  112. package/src/anyspend/react/components/common/OrderDetails.tsx +8 -0
  113. package/src/anyspend/react/components/common/OrderStatus.tsx +38 -3
  114. package/src/anyspend/react/components/common/StepProgress.tsx +15 -5
  115. package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +5 -7
  116. package/src/anyspend/react/hooks/useKycStatus.ts +8 -5
  117. package/src/app.shared.ts +9 -8
  118. package/src/global-account/bsmnt.ts +0 -6
  119. package/src/global-account/react/components/B3DynamicModal.tsx +5 -2
  120. package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +2 -1
  121. package/src/global-account/react/components/B3Provider/B3Provider.tsx +7 -1
  122. package/src/global-account/react/components/B3Provider/LocalSDKProvider.tsx +5 -0
  123. package/src/global-account/react/components/ManageAccount/SessionDurationContent.tsx +107 -0
  124. package/src/global-account/react/components/ManageAccount/SettingsContent.tsx +28 -30
  125. package/src/global-account/react/components/SignInWithB3/components/AuthButton.tsx +21 -2
  126. package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +207 -54
  127. package/src/global-account/react/components/SignInWithB3/utils/signInUtils.ts +19 -3
  128. package/src/global-account/react/components/Toast/ToastContext.tsx +39 -7
  129. package/src/global-account/react/hooks/useAuth.ts +28 -17
  130. package/src/global-account/react/hooks/useAuthentication.ts +24 -13
  131. package/src/global-account/react/hooks/useConnect.tsx +2 -2
  132. package/src/global-account/react/hooks/useTWAuth.tsx +0 -1
  133. package/src/global-account/react/stores/useModalStore.ts +11 -0
  134. package/src/global-account/react/utils/createWagmiConfig.tsx +0 -18
  135. package/src/global-account/react/utils/index.ts +0 -1
  136. package/src/shared/utils/session-duration.ts +64 -0
  137. package/src/types/torph.d.ts +4 -0
  138. package/dist/cjs/global-account/react/components/AvatarCreator/AvatarCreator.d.ts +0 -6
  139. package/dist/cjs/global-account/react/components/AvatarCreator/AvatarCreator.js +0 -54
  140. package/dist/cjs/global-account/react/components/ProfileAvatar.d.ts +0 -0
  141. package/dist/cjs/global-account/react/components/ProfileAvatar.js +0 -127
  142. package/dist/cjs/global-account/react/hooks/useRPMToken.d.ts +0 -7
  143. package/dist/cjs/global-account/react/hooks/useRPMToken.js +0 -11
  144. package/dist/cjs/global-account/react/utils/updateAvatar.d.ts +0 -4
  145. package/dist/cjs/global-account/react/utils/updateAvatar.js +0 -54
  146. package/dist/esm/global-account/react/components/AvatarCreator/AvatarCreator.d.ts +0 -6
  147. package/dist/esm/global-account/react/components/AvatarCreator/AvatarCreator.js +0 -51
  148. package/dist/esm/global-account/react/components/ProfileAvatar.d.ts +0 -0
  149. package/dist/esm/global-account/react/components/ProfileAvatar.js +0 -127
  150. package/dist/esm/global-account/react/hooks/useRPMToken.d.ts +0 -7
  151. package/dist/esm/global-account/react/hooks/useRPMToken.js +0 -8
  152. package/dist/esm/global-account/react/utils/updateAvatar.d.ts +0 -4
  153. package/dist/esm/global-account/react/utils/updateAvatar.js +0 -18
  154. package/dist/types/global-account/react/components/AvatarCreator/AvatarCreator.d.ts +0 -6
  155. package/dist/types/global-account/react/components/ProfileAvatar.d.ts +0 -0
  156. package/dist/types/global-account/react/hooks/useRPMToken.d.ts +0 -7
  157. package/dist/types/global-account/react/utils/updateAvatar.d.ts +0 -4
  158. package/src/global-account/react/components/AvatarCreator/AvatarCreator.tsx +0 -90
  159. package/src/global-account/react/components/ProfileAvatar.tsx +0 -138
  160. package/src/global-account/react/hooks/useRPMToken.ts +0 -17
  161. 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
- // wagmi config shouldn't change
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
- // Authenticate on BSMNT with B3 JWT
146
- const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
147
- debug("@@b3Jwt", b3Jwt);
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
- // Authenticate on BSMNT with B3 JWT
160
- const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
161
- debug("@@b3Jwt", b3Jwt);
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
- [activeWallet, partnerId, authenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting],
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
- }
@@ -1,4 +1,3 @@
1
1
  export * from "./notificationsAPI";
2
2
  export * from "./profileDisplay";
3
3
  export * from "./toast";
4
- export * from "./updateAvatar";
@@ -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
+ }
@@ -0,0 +1,4 @@
1
+ declare module "torph/react" {
2
+ import type { JSX } from "react";
3
+ export function TextMorph(props: { children: string; className?: string }): JSX.Element;
4
+ }
@@ -1,6 +0,0 @@
1
- interface AvatarCreatorProps {
2
- onSetAvatar?: () => void;
3
- className?: string;
4
- }
5
- export declare function AvatarCreator({ onSetAvatar, className }: AvatarCreatorProps): import("react/jsx-runtime").JSX.Element;
6
- export {};
@@ -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
- }
@@ -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,7 +0,0 @@
1
- export declare function useRPMToken(): {
2
- token: string;
3
- accountId: string;
4
- refetch: (queryParams: undefined) => Promise<any>;
5
- isLoading: boolean;
6
- isError: Error | null;
7
- };
@@ -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,4 +0,0 @@
1
- export declare function updateAvatar(avatar: string): Promise<{
2
- success: boolean;
3
- error?: string;
4
- }>;
@@ -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,6 +0,0 @@
1
- interface AvatarCreatorProps {
2
- onSetAvatar?: () => void;
3
- className?: string;
4
- }
5
- export declare function AvatarCreator({ onSetAvatar, className }: AvatarCreatorProps): import("react/jsx-runtime").JSX.Element;
6
- export {};
@@ -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
- }