@b3dotfun/sdk 0.1.1-test.0 → 0.1.2-test.0
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/AnySpend.js +2 -2
- package/dist/cjs/anyspend/react/components/AnySpendDeposit.d.ts +15 -10
- package/dist/cjs/anyspend/react/components/AnySpendDeposit.js +22 -14
- package/dist/cjs/anyspend/react/components/QRDeposit.js +31 -5
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +9 -2
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +1 -1
- package/dist/cjs/anyspend/react/components/common/PaymentStripeWeb2.js +1 -1
- package/dist/cjs/anyspend/react/components/common/TransferResultScreen.d.ts +22 -0
- package/dist/cjs/anyspend/react/components/common/TransferResultScreen.js +25 -0
- package/dist/cjs/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/hooks/index.js +1 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +1 -1
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOrder.js +1 -1
- package/dist/cjs/anyspend/react/hooks/useCreateDepositFirstOrder.js +1 -1
- package/dist/cjs/anyspend/react/hooks/useValidatedClientReferenceId.js +1 -1
- package/dist/cjs/anyspend/react/hooks/useWatchTransfer.d.ts +41 -0
- package/dist/cjs/anyspend/react/hooks/useWatchTransfer.js +75 -0
- package/dist/cjs/anyspend/utils/address.d.ts +5 -0
- package/dist/cjs/anyspend/utils/address.js +8 -0
- package/dist/cjs/global-account/react/components/AvatarEditor/AvatarEditor.js +1 -1
- package/dist/cjs/global-account/react/components/B3DynamicModal.js +5 -1
- package/dist/cjs/global-account/react/components/B3Provider/AuthenticationProvider.d.ts +5 -0
- package/dist/cjs/global-account/react/components/B3Provider/AuthenticationProvider.js +12 -0
- package/dist/cjs/global-account/react/components/B3Provider/B3ConfigProvider.d.ts +31 -0
- package/dist/cjs/global-account/react/components/B3Provider/B3ConfigProvider.js +37 -0
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +3 -18
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +7 -57
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -6
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +11 -35
- 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/B3Provider/useB3.d.ts +3 -3
- package/dist/cjs/global-account/react/components/B3Provider/useB3.js +4 -10
- package/dist/cjs/global-account/react/components/B3Provider/useB3Account.js +5 -2
- package/dist/cjs/global-account/react/components/B3Provider/useB3Config.d.ts +1 -9
- package/dist/cjs/global-account/react/components/B3Provider/useB3Config.js +2 -20
- package/dist/cjs/global-account/react/components/ManageAccount/ProfileSection.js +1 -2
- package/dist/cjs/global-account/react/components/ManageAccount/SettingsProfileCard.js +1 -1
- package/dist/cjs/global-account/react/components/ManageAccount/channels/DiscordChannel.js +1 -1
- package/dist/cjs/global-account/react/components/ManageAccount/channels/EmailChannel.js +1 -1
- package/dist/cjs/global-account/react/components/ManageAccount/channels/PhoneChannel.js +1 -1
- package/dist/cjs/global-account/react/components/ManageAccount/channels/TelegramChannel.js +1 -1
- package/dist/cjs/global-account/react/components/RequestPermissions/RequestPermissions.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +4 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +1 -1
- package/dist/cjs/global-account/react/components/SingleUserSearchSelector/SingleUserSearchSelector.d.ts +64 -0
- package/dist/cjs/global-account/react/components/SingleUserSearchSelector/SingleUserSearchSelector.js +163 -0
- package/dist/cjs/global-account/react/components/SingleUserSearchSelector/index.d.ts +2 -0
- package/dist/cjs/global-account/react/components/SingleUserSearchSelector/index.js +5 -0
- package/dist/cjs/global-account/react/components/StyleRoot.js +2 -2
- package/dist/cjs/global-account/react/components/WalletImage/WalletImage.d.ts +1 -1
- package/dist/cjs/global-account/react/components/custom/ManageAccountButton.js +1 -2
- package/dist/cjs/global-account/react/components/index.d.ts +3 -2
- package/dist/cjs/global-account/react/components/index.js +6 -6
- package/dist/cjs/global-account/react/hooks/index.d.ts +1 -0
- package/dist/cjs/global-account/react/hooks/index.js +3 -1
- package/dist/cjs/global-account/react/hooks/useAuth.d.ts +2 -2
- package/dist/cjs/global-account/react/hooks/useAuth.js +2 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +6 -3
- package/dist/cjs/global-account/react/hooks/useClient.js +1 -1
- package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.js +1 -1
- package/dist/cjs/global-account/react/hooks/useNotifications.js +1 -1
- package/dist/cjs/global-account/react/hooks/useProfile.js +4 -23
- package/dist/cjs/global-account/react/hooks/useTokenBalance.js +5 -5
- package/dist/cjs/global-account/react/hooks/useTurnkeyAuth.js +1 -1
- package/dist/cjs/global-account/react/hooks/useUser.d.ts +60 -0
- package/dist/cjs/global-account/react/hooks/useUser.js +20 -0
- package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +6 -7
- package/dist/cjs/global-account/react/hooks/useUserQuery.js +64 -39
- package/dist/cjs/global-account/react/index.native.d.ts +0 -2
- package/dist/cjs/global-account/react/index.native.js +1 -5
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +66 -1
- package/dist/cjs/global-account/react/stores/useModalStore.js +3 -0
- package/dist/cjs/global-account/react/stores/userStore.d.ts +22 -0
- package/dist/cjs/global-account/react/stores/userStore.js +30 -0
- package/dist/cjs/global-account/react/utils/profileApi.d.ts +13 -0
- package/dist/cjs/global-account/react/utils/profileApi.js +29 -0
- package/dist/esm/anyspend/react/components/AnySpend.js +3 -3
- package/dist/esm/anyspend/react/components/AnySpendDeposit.d.ts +15 -10
- package/dist/esm/anyspend/react/components/AnySpendDeposit.js +23 -15
- package/dist/esm/anyspend/react/components/QRDeposit.js +32 -6
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +10 -3
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +2 -2
- package/dist/esm/anyspend/react/components/common/PaymentStripeWeb2.js +2 -2
- package/dist/esm/anyspend/react/components/common/TransferResultScreen.d.ts +22 -0
- package/dist/esm/anyspend/react/components/common/TransferResultScreen.js +22 -0
- package/dist/esm/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/esm/anyspend/react/hooks/index.js +1 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +2 -2
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOrder.js +2 -2
- package/dist/esm/anyspend/react/hooks/useCreateDepositFirstOrder.js +2 -2
- package/dist/esm/anyspend/react/hooks/useValidatedClientReferenceId.js +2 -2
- package/dist/esm/anyspend/react/hooks/useWatchTransfer.d.ts +41 -0
- package/dist/esm/anyspend/react/hooks/useWatchTransfer.js +72 -0
- package/dist/esm/anyspend/utils/address.d.ts +5 -0
- package/dist/esm/anyspend/utils/address.js +7 -0
- package/dist/esm/global-account/react/components/AvatarEditor/AvatarEditor.js +2 -2
- package/dist/esm/global-account/react/components/B3DynamicModal.js +6 -2
- package/dist/esm/global-account/react/components/B3Provider/AuthenticationProvider.d.ts +5 -0
- package/dist/esm/global-account/react/components/B3Provider/AuthenticationProvider.js +10 -0
- package/dist/esm/global-account/react/components/B3Provider/B3ConfigProvider.d.ts +31 -0
- package/dist/esm/global-account/react/components/B3Provider/B3ConfigProvider.js +33 -0
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +3 -18
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +6 -58
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -6
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +10 -37
- 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/B3Provider/useB3.d.ts +3 -3
- package/dist/esm/global-account/react/components/B3Provider/useB3.js +4 -10
- package/dist/esm/global-account/react/components/B3Provider/useB3Account.js +5 -2
- package/dist/esm/global-account/react/components/B3Provider/useB3Config.d.ts +1 -9
- package/dist/esm/global-account/react/components/B3Provider/useB3Config.js +1 -19
- package/dist/esm/global-account/react/components/ManageAccount/ProfileSection.js +2 -3
- package/dist/esm/global-account/react/components/ManageAccount/SettingsProfileCard.js +2 -2
- package/dist/esm/global-account/react/components/ManageAccount/channels/DiscordChannel.js +2 -2
- package/dist/esm/global-account/react/components/ManageAccount/channels/EmailChannel.js +2 -2
- package/dist/esm/global-account/react/components/ManageAccount/channels/PhoneChannel.js +2 -2
- package/dist/esm/global-account/react/components/ManageAccount/channels/TelegramChannel.js +2 -2
- package/dist/esm/global-account/react/components/RequestPermissions/RequestPermissions.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +5 -3
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -2
- package/dist/esm/global-account/react/components/SingleUserSearchSelector/SingleUserSearchSelector.d.ts +64 -0
- package/dist/esm/global-account/react/components/SingleUserSearchSelector/SingleUserSearchSelector.js +160 -0
- package/dist/esm/global-account/react/components/SingleUserSearchSelector/index.d.ts +2 -0
- package/dist/esm/global-account/react/components/SingleUserSearchSelector/index.js +1 -0
- package/dist/esm/global-account/react/components/StyleRoot.js +2 -2
- package/dist/esm/global-account/react/components/WalletImage/WalletImage.d.ts +1 -1
- package/dist/esm/global-account/react/components/custom/ManageAccountButton.js +2 -3
- package/dist/esm/global-account/react/components/index.d.ts +3 -2
- package/dist/esm/global-account/react/components/index.js +3 -2
- package/dist/esm/global-account/react/hooks/index.d.ts +1 -0
- package/dist/esm/global-account/react/hooks/index.js +1 -0
- package/dist/esm/global-account/react/hooks/useAuth.d.ts +2 -2
- package/dist/esm/global-account/react/hooks/useAuth.js +3 -3
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.js +6 -3
- package/dist/esm/global-account/react/hooks/useClient.js +2 -2
- package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.js +2 -2
- package/dist/esm/global-account/react/hooks/useNotifications.js +2 -2
- package/dist/esm/global-account/react/hooks/useProfile.js +1 -20
- package/dist/esm/global-account/react/hooks/useTokenBalance.js +6 -6
- package/dist/esm/global-account/react/hooks/useTurnkeyAuth.js +2 -2
- package/dist/esm/global-account/react/hooks/useUser.d.ts +60 -0
- package/dist/esm/global-account/react/hooks/useUser.js +17 -0
- package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +6 -7
- package/dist/esm/global-account/react/hooks/useUserQuery.js +63 -37
- package/dist/esm/global-account/react/index.native.d.ts +0 -2
- package/dist/esm/global-account/react/index.native.js +0 -2
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +66 -1
- package/dist/esm/global-account/react/stores/useModalStore.js +3 -0
- package/dist/esm/global-account/react/stores/userStore.d.ts +22 -0
- package/dist/esm/global-account/react/stores/userStore.js +27 -0
- package/dist/esm/global-account/react/utils/profileApi.d.ts +13 -0
- package/dist/esm/global-account/react/utils/profileApi.js +25 -0
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/components/AnySpendDeposit.d.ts +15 -10
- package/dist/types/anyspend/react/components/common/TransferResultScreen.d.ts +22 -0
- package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useWatchTransfer.d.ts +41 -0
- package/dist/types/anyspend/utils/address.d.ts +5 -0
- package/dist/types/global-account/react/components/B3Provider/AuthenticationProvider.d.ts +5 -0
- package/dist/types/global-account/react/components/B3Provider/B3ConfigProvider.d.ts +31 -0
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +3 -18
- package/dist/types/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -6
- package/dist/types/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +3 -1
- package/dist/types/global-account/react/components/B3Provider/useB3.d.ts +3 -3
- package/dist/types/global-account/react/components/B3Provider/useB3Config.d.ts +1 -9
- package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
- package/dist/types/global-account/react/components/SingleUserSearchSelector/SingleUserSearchSelector.d.ts +64 -0
- package/dist/types/global-account/react/components/SingleUserSearchSelector/index.d.ts +2 -0
- package/dist/types/global-account/react/components/WalletImage/WalletImage.d.ts +1 -1
- package/dist/types/global-account/react/components/index.d.ts +3 -2
- package/dist/types/global-account/react/hooks/index.d.ts +1 -0
- package/dist/types/global-account/react/hooks/useAuth.d.ts +2 -2
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/types/global-account/react/hooks/useUser.d.ts +60 -0
- package/dist/types/global-account/react/hooks/useUserQuery.d.ts +6 -7
- package/dist/types/global-account/react/index.native.d.ts +0 -2
- package/dist/types/global-account/react/stores/useModalStore.d.ts +66 -1
- package/dist/types/global-account/react/stores/userStore.d.ts +22 -0
- package/dist/types/global-account/react/utils/profileApi.d.ts +13 -0
- package/package.json +6 -1
- package/src/anyspend/react/components/AnySpend.tsx +3 -2
- package/src/anyspend/react/components/AnySpendDeposit.tsx +60 -42
- package/src/anyspend/react/components/QRDeposit.tsx +57 -5
- package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +13 -3
- package/src/anyspend/react/components/common/OrderDetails.tsx +2 -2
- package/src/anyspend/react/components/common/PaymentStripeWeb2.tsx +2 -2
- package/src/anyspend/react/components/common/TransferResultScreen.tsx +107 -0
- package/src/anyspend/react/hooks/index.ts +1 -0
- package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +2 -2
- package/src/anyspend/react/hooks/useAnyspendCreateOrder.ts +2 -2
- package/src/anyspend/react/hooks/useCreateDepositFirstOrder.ts +2 -2
- package/src/anyspend/react/hooks/useValidatedClientReferenceId.ts +2 -2
- package/src/anyspend/react/hooks/useWatchTransfer.ts +114 -0
- package/src/anyspend/utils/address.ts +13 -0
- package/src/global-account/react/components/AvatarEditor/AvatarEditor.tsx +2 -2
- package/src/global-account/react/components/B3DynamicModal.tsx +6 -2
- package/src/global-account/react/components/B3Provider/AuthenticationProvider.tsx +19 -0
- package/src/global-account/react/components/B3Provider/B3ConfigProvider.tsx +84 -0
- package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +26 -45
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +15 -103
- package/src/global-account/react/components/B3Provider/LocalSDKProvider.tsx +5 -0
- package/src/global-account/react/components/B3Provider/useB3.ts +4 -12
- package/src/global-account/react/components/B3Provider/useB3Account.ts +6 -2
- package/src/global-account/react/components/B3Provider/useB3Config.ts +1 -34
- package/src/global-account/react/components/ManageAccount/ProfileSection.tsx +2 -4
- package/src/global-account/react/components/ManageAccount/SettingsProfileCard.tsx +2 -2
- package/src/global-account/react/components/ManageAccount/channels/DiscordChannel.tsx +2 -2
- package/src/global-account/react/components/ManageAccount/channels/EmailChannel.tsx +2 -2
- package/src/global-account/react/components/ManageAccount/channels/PhoneChannel.tsx +2 -2
- package/src/global-account/react/components/ManageAccount/channels/TelegramChannel.tsx +2 -2
- package/src/global-account/react/components/RequestPermissions/RequestPermissions.tsx +2 -2
- package/src/global-account/react/components/SignInWithB3/SignIn.tsx +2 -2
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +7 -3
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +2 -2
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +2 -2
- package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +2 -2
- package/src/global-account/react/components/SingleUserSearchSelector/README.md +266 -0
- package/src/global-account/react/components/SingleUserSearchSelector/SingleUserSearchSelector.tsx +330 -0
- package/src/global-account/react/components/SingleUserSearchSelector/index.ts +2 -0
- package/src/global-account/react/components/StyleRoot.tsx +2 -2
- package/src/global-account/react/components/custom/ManageAccountButton.tsx +2 -3
- package/src/global-account/react/components/index.ts +8 -2
- package/src/global-account/react/hooks/index.ts +1 -0
- package/src/global-account/react/hooks/useAuth.ts +3 -3
- package/src/global-account/react/hooks/useAuthentication.ts +7 -3
- package/src/global-account/react/hooks/useClient.ts +2 -2
- package/src/global-account/react/hooks/useHandleConnectWithPrivy.tsx +2 -2
- package/src/global-account/react/hooks/useNotifications.ts +2 -2
- package/src/global-account/react/hooks/useProfile.ts +1 -32
- package/src/global-account/react/hooks/useTokenBalance.tsx +8 -7
- package/src/global-account/react/hooks/useTurnkeyAuth.ts +2 -2
- package/src/global-account/react/hooks/useUser.ts +20 -0
- package/src/global-account/react/hooks/useUserQuery.ts +64 -51
- package/src/global-account/react/index.native.ts +0 -2
- package/src/global-account/react/stores/useModalStore.ts +70 -1
- package/src/global-account/react/stores/userStore.ts +41 -0
- package/src/global-account/react/utils/profileApi.ts +38 -0
- package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +0 -27
- package/dist/cjs/global-account/react/components/B3Provider/types.js +0 -24
- package/dist/esm/global-account/react/components/B3Provider/types.d.ts +0 -27
- package/dist/esm/global-account/react/components/B3Provider/types.js +0 -21
- package/dist/types/global-account/react/components/B3Provider/types.d.ts +0 -27
- package/src/global-account/react/components/B3Provider/types.ts +0 -50
package/src/global-account/react/components/SingleUserSearchSelector/SingleUserSearchSelector.tsx
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { cn } from "@b3dotfun/sdk/shared/utils";
|
|
4
|
+
import { Search, X } from "lucide-react";
|
|
5
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
6
|
+
import type { CombinedProfile, Profile } from "../../hooks/useProfile";
|
|
7
|
+
import { fetchProfile as fetchProfileApi } from "../../utils/profileApi";
|
|
8
|
+
import { IPFSMediaRenderer } from "../IPFSMediaRenderer/IPFSMediaRenderer";
|
|
9
|
+
import { Input } from "../ui/input";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Profile type filter options for SingleUserSearchSelector
|
|
13
|
+
* - b3-ens: B3 ENS profiles
|
|
14
|
+
* - thirdweb-${string}: Thirdweb profiles (e.g., thirdweb-email, thirdweb-wallet)
|
|
15
|
+
* - ens-data: ENS data profiles
|
|
16
|
+
* - global-account: Global account profiles
|
|
17
|
+
*/
|
|
18
|
+
export type ProfileTypeFilter = "b3-ens" | `thirdweb-${string}` | "ens-data" | "global-account";
|
|
19
|
+
|
|
20
|
+
export interface SingleUserSearchSelectorProps {
|
|
21
|
+
/**
|
|
22
|
+
* Callback function when a user is selected
|
|
23
|
+
* Returns the complete profile data including all profile types
|
|
24
|
+
*/
|
|
25
|
+
onSelectUser: (profile: CombinedProfile) => void;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Optional: Filter results to only show profiles that include specific types
|
|
29
|
+
* If provided, only profiles containing at least one of these types will be shown
|
|
30
|
+
*/
|
|
31
|
+
profileTypeFilter?: ProfileTypeFilter[];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Optional: Custom placeholder text for the search input
|
|
35
|
+
*/
|
|
36
|
+
placeholder?: string;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Optional: Custom class name for the container
|
|
40
|
+
*/
|
|
41
|
+
className?: string;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Optional: Show clear button when there's input
|
|
45
|
+
*/
|
|
46
|
+
showClearButton?: boolean;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Optional: Show profile type badges in the result
|
|
50
|
+
*/
|
|
51
|
+
showBadges?: boolean;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Optional: Minimum characters before triggering search
|
|
55
|
+
*/
|
|
56
|
+
minSearchLength?: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* SingleUserSearchSelector Component
|
|
61
|
+
*
|
|
62
|
+
* A specialized component for searching and selecting a single user profile.
|
|
63
|
+
* This component is designed specifically for single-user selection scenarios,
|
|
64
|
+
* not for multi-user or general profile browsing.
|
|
65
|
+
*
|
|
66
|
+
* Features:
|
|
67
|
+
* - Search by address or name
|
|
68
|
+
* - Filter results by profile type (b3-ens, thirdweb-*, ens-data, global-account)
|
|
69
|
+
* - Shows a single result in a dropdown
|
|
70
|
+
* - Callback with complete profile data on selection
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```tsx
|
|
74
|
+
* <SingleUserSearchSelector
|
|
75
|
+
* onSelectUser={(profile) => console.log('Selected:', profile)}
|
|
76
|
+
* profileTypeFilter={['b3-ens', 'global-account']}
|
|
77
|
+
* placeholder="Search by address or name..."
|
|
78
|
+
* />
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export function SingleUserSearchSelector({
|
|
82
|
+
onSelectUser,
|
|
83
|
+
profileTypeFilter,
|
|
84
|
+
placeholder = "Search by address, name, or ID...",
|
|
85
|
+
className,
|
|
86
|
+
showClearButton = true,
|
|
87
|
+
showBadges = false,
|
|
88
|
+
minSearchLength = 3,
|
|
89
|
+
}: SingleUserSearchSelectorProps) {
|
|
90
|
+
const [searchQuery, setSearchQuery] = useState("");
|
|
91
|
+
const [isSearching, setIsSearching] = useState(false);
|
|
92
|
+
const [searchResult, setSearchResult] = useState<CombinedProfile | null>(null);
|
|
93
|
+
const [error, setError] = useState<string | null>(null);
|
|
94
|
+
const [showDropdown, setShowDropdown] = useState(false);
|
|
95
|
+
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
96
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
97
|
+
const searchTimeoutRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
98
|
+
|
|
99
|
+
// Fetch profile from API using shared utility
|
|
100
|
+
const fetchProfile = useCallback(
|
|
101
|
+
async (query: string): Promise<CombinedProfile | null> => {
|
|
102
|
+
if (!query || query.length < minSearchLength) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
// Determine if query is an address (starts with 0x) or a name
|
|
108
|
+
const params = query.startsWith("0x") ? { address: query } : { name: query };
|
|
109
|
+
|
|
110
|
+
const profile = await fetchProfileApi(params);
|
|
111
|
+
return profile;
|
|
112
|
+
} catch (err) {
|
|
113
|
+
// Return null for 404s (user not found)
|
|
114
|
+
if (err instanceof Error && err.message.includes("404")) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
console.error("Error fetching profile:", err);
|
|
118
|
+
throw err;
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
[minSearchLength],
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
// Filter profile by type
|
|
125
|
+
const filterProfileByType = useCallback(
|
|
126
|
+
(profile: CombinedProfile): boolean => {
|
|
127
|
+
if (!profileTypeFilter || profileTypeFilter.length === 0) {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Check if any of the profile's types match the filter
|
|
132
|
+
return profile.profiles.some(p => {
|
|
133
|
+
return profileTypeFilter.some(filter => {
|
|
134
|
+
// Handle thirdweb-* wildcard matching
|
|
135
|
+
if (filter.startsWith("thirdweb-")) {
|
|
136
|
+
return p.type.startsWith("thirdweb-");
|
|
137
|
+
}
|
|
138
|
+
return p.type === filter;
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
[profileTypeFilter],
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
// Handle search with debouncing
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
if (searchTimeoutRef.current) {
|
|
148
|
+
clearTimeout(searchTimeoutRef.current);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (!searchQuery || searchQuery.length < minSearchLength) {
|
|
152
|
+
setSearchResult(null);
|
|
153
|
+
setShowDropdown(false);
|
|
154
|
+
setError(null);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
setIsSearching(true);
|
|
159
|
+
setError(null);
|
|
160
|
+
|
|
161
|
+
searchTimeoutRef.current = setTimeout(async () => {
|
|
162
|
+
try {
|
|
163
|
+
const result = await fetchProfile(searchQuery);
|
|
164
|
+
|
|
165
|
+
if (result) {
|
|
166
|
+
// Apply profile type filter
|
|
167
|
+
if (filterProfileByType(result)) {
|
|
168
|
+
setSearchResult(result);
|
|
169
|
+
setShowDropdown(true);
|
|
170
|
+
setError(null); // Clear any previous errors
|
|
171
|
+
} else {
|
|
172
|
+
setSearchResult(null);
|
|
173
|
+
setShowDropdown(false);
|
|
174
|
+
setError("No matching profile types found");
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
setSearchResult(null);
|
|
178
|
+
setShowDropdown(false);
|
|
179
|
+
setError("No user found");
|
|
180
|
+
}
|
|
181
|
+
} catch (err) {
|
|
182
|
+
setError(err instanceof Error ? err.message : "Failed to search");
|
|
183
|
+
setSearchResult(null);
|
|
184
|
+
setShowDropdown(false);
|
|
185
|
+
} finally {
|
|
186
|
+
setIsSearching(false);
|
|
187
|
+
}
|
|
188
|
+
}, 500); // 500ms debounce
|
|
189
|
+
|
|
190
|
+
return () => {
|
|
191
|
+
if (searchTimeoutRef.current) {
|
|
192
|
+
clearTimeout(searchTimeoutRef.current);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}, [searchQuery, fetchProfile, filterProfileByType, minSearchLength]);
|
|
196
|
+
|
|
197
|
+
// Handle click outside to close dropdown
|
|
198
|
+
useEffect(() => {
|
|
199
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
200
|
+
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
|
|
201
|
+
setShowDropdown(false);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
206
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
207
|
+
}, []);
|
|
208
|
+
|
|
209
|
+
// Handle user selection
|
|
210
|
+
const handleSelectUser = useCallback(
|
|
211
|
+
(profile: CombinedProfile) => {
|
|
212
|
+
onSelectUser(profile);
|
|
213
|
+
setShowDropdown(false);
|
|
214
|
+
setSearchQuery("");
|
|
215
|
+
setSearchResult(null);
|
|
216
|
+
},
|
|
217
|
+
[onSelectUser],
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
// Handle clear search
|
|
221
|
+
const handleClear = useCallback(() => {
|
|
222
|
+
setSearchQuery("");
|
|
223
|
+
setSearchResult(null);
|
|
224
|
+
setShowDropdown(false);
|
|
225
|
+
setError(null);
|
|
226
|
+
inputRef.current?.focus();
|
|
227
|
+
}, []);
|
|
228
|
+
|
|
229
|
+
// Get display name for profile
|
|
230
|
+
const getDisplayName = (profile: CombinedProfile): string => {
|
|
231
|
+
return profile.displayName || profile.name || profile.address || "Unknown";
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// Get profile type badges
|
|
235
|
+
const getProfileTypeBadges = (profiles: Profile[]): string[] => {
|
|
236
|
+
return profiles.map(p => p.type);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
return (
|
|
240
|
+
<div className={cn("single-user-search-selector b3-root relative w-full", className)} ref={dropdownRef}>
|
|
241
|
+
{/* Search Input */}
|
|
242
|
+
<div className="single-user-search-input-wrapper relative flex items-center">
|
|
243
|
+
<Search
|
|
244
|
+
className="single-user-search-icon pointer-events-none absolute text-gray-400"
|
|
245
|
+
style={{ left: "12px", width: "16px", height: "16px" }}
|
|
246
|
+
/>
|
|
247
|
+
<Input
|
|
248
|
+
ref={inputRef}
|
|
249
|
+
type="text"
|
|
250
|
+
value={searchQuery}
|
|
251
|
+
onChange={e => setSearchQuery(e.target.value)}
|
|
252
|
+
placeholder={placeholder}
|
|
253
|
+
className={cn("single-user-search-input w-full border-gray-300 focus:border-blue-500 focus:ring-blue-500")}
|
|
254
|
+
style={{ paddingLeft: "44px", paddingRight: "44px" }}
|
|
255
|
+
/>
|
|
256
|
+
{showClearButton && searchQuery && (
|
|
257
|
+
<button
|
|
258
|
+
onClick={handleClear}
|
|
259
|
+
className="single-user-search-clear-button absolute text-gray-400 transition-colors hover:text-gray-600"
|
|
260
|
+
style={{ right: "12px" }}
|
|
261
|
+
type="button"
|
|
262
|
+
>
|
|
263
|
+
<X style={{ width: "16px", height: "16px" }} />
|
|
264
|
+
</button>
|
|
265
|
+
)}
|
|
266
|
+
</div>
|
|
267
|
+
|
|
268
|
+
{/* Loading State */}
|
|
269
|
+
{isSearching && <div className="single-user-search-loading mt-2 text-sm text-gray-500">Searching...</div>}
|
|
270
|
+
|
|
271
|
+
{/* Error State */}
|
|
272
|
+
{error && !isSearching && <div className="single-user-search-error mt-2 text-sm text-red-500">{error}</div>}
|
|
273
|
+
|
|
274
|
+
{/* Dropdown with Search Result */}
|
|
275
|
+
{showDropdown && searchResult && !isSearching && (
|
|
276
|
+
<div className="single-user-search-dropdown absolute z-50 mt-2 w-full rounded-lg border border-gray-200 bg-white shadow-lg">
|
|
277
|
+
<button
|
|
278
|
+
onClick={() => handleSelectUser(searchResult)}
|
|
279
|
+
className="single-user-search-result-button w-full px-4 py-3 text-left transition-colors hover:bg-gray-50"
|
|
280
|
+
type="button"
|
|
281
|
+
>
|
|
282
|
+
<div className="flex items-start gap-3">
|
|
283
|
+
{/* Avatar */}
|
|
284
|
+
<div className="single-user-search-result-avatar h-11 w-11 shrink-0">
|
|
285
|
+
<IPFSMediaRenderer
|
|
286
|
+
src={searchResult.avatar}
|
|
287
|
+
alt={getDisplayName(searchResult)}
|
|
288
|
+
className="h-full w-full rounded-full object-cover"
|
|
289
|
+
/>
|
|
290
|
+
</div>
|
|
291
|
+
|
|
292
|
+
{/* Profile Info */}
|
|
293
|
+
<div className="single-user-search-result-info min-w-0 flex-1 pt-0.5">
|
|
294
|
+
<div className="single-user-search-result-name text-base font-semibold text-gray-900">
|
|
295
|
+
{getDisplayName(searchResult)}
|
|
296
|
+
</div>
|
|
297
|
+
|
|
298
|
+
{searchResult.address && (
|
|
299
|
+
<div className="single-user-search-result-address mt-1 font-mono text-xs text-gray-500">
|
|
300
|
+
{searchResult.address.slice(0, 6)}...{searchResult.address.slice(-4)}
|
|
301
|
+
</div>
|
|
302
|
+
)}
|
|
303
|
+
|
|
304
|
+
{searchResult.bio && (
|
|
305
|
+
<div className="single-user-search-result-bio mt-1.5 line-clamp-2 text-sm text-gray-600">
|
|
306
|
+
{searchResult.bio}
|
|
307
|
+
</div>
|
|
308
|
+
)}
|
|
309
|
+
|
|
310
|
+
{/* Profile Type Badges */}
|
|
311
|
+
{showBadges && (
|
|
312
|
+
<div className="single-user-search-result-badges mt-2 flex flex-wrap gap-1.5">
|
|
313
|
+
{getProfileTypeBadges(searchResult.profiles).map((type, index) => (
|
|
314
|
+
<span
|
|
315
|
+
key={`${type}-${index}`}
|
|
316
|
+
className="single-user-search-result-badge inline-flex items-center rounded-full bg-blue-100 px-2.5 py-0.5 text-xs font-medium text-blue-800"
|
|
317
|
+
>
|
|
318
|
+
{type}
|
|
319
|
+
</span>
|
|
320
|
+
))}
|
|
321
|
+
</div>
|
|
322
|
+
)}
|
|
323
|
+
</div>
|
|
324
|
+
</div>
|
|
325
|
+
</button>
|
|
326
|
+
</div>
|
|
327
|
+
)}
|
|
328
|
+
</div>
|
|
329
|
+
);
|
|
330
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { PropsWithChildren } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { useB3Config } from "./B3Provider/useB3Config";
|
|
3
3
|
|
|
4
4
|
export function StyleRoot({ children, id }: PropsWithChildren<{ id?: string }>) {
|
|
5
|
-
const { theme } =
|
|
5
|
+
const { theme } = useB3Config();
|
|
6
6
|
|
|
7
7
|
return (
|
|
8
8
|
<div className="b3-root" id={id} data-theme={theme}>
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { Button, StyleRoot,
|
|
1
|
+
import { Button, StyleRoot, useModalStore, useUser } from "@b3dotfun/sdk/global-account/react";
|
|
2
2
|
import { cn } from "@b3dotfun/sdk/shared/utils";
|
|
3
3
|
import { SignInWithB3Props } from "../SignInWithB3/SignInWithB3";
|
|
4
4
|
|
|
5
5
|
export function ManageAccountButton(props: SignInWithB3Props & { className?: string }) {
|
|
6
|
-
const { partnerId } = useB3();
|
|
7
6
|
const { setB3ModalOpen, setB3ModalContentType } = useModalStore();
|
|
8
|
-
const { isConnected } =
|
|
7
|
+
const { isConnected } = useUser();
|
|
9
8
|
|
|
10
9
|
const handleClickManageAccount = () => {
|
|
11
10
|
setB3ModalContentType({
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// TODO woj: Barrel file for all components, this might be reason of bundle size issues
|
|
2
2
|
// Core Components
|
|
3
3
|
export { B3DynamicModal } from "./B3DynamicModal";
|
|
4
|
-
export { B3Provider
|
|
4
|
+
export { B3Provider } from "./B3Provider/B3Provider";
|
|
5
5
|
export { RelayKitProviderWrapper } from "./B3Provider/RelayKitProviderWrapper";
|
|
6
|
-
export { B3Context, type B3ContextType } from "./B3Provider/types";
|
|
7
6
|
export { useB3 } from "./B3Provider/useB3";
|
|
8
7
|
export { useB3Account } from "./B3Provider/useB3Account";
|
|
9
8
|
export { useB3Config } from "./B3Provider/useB3Config";
|
|
@@ -50,6 +49,13 @@ export { SendETHButton } from "./SendETHButton/SendETHButton";
|
|
|
50
49
|
// SendERC20Button Components
|
|
51
50
|
export { SendERC20Button } from "./SendERC20Button/SendERC20Button";
|
|
52
51
|
|
|
52
|
+
// SingleUserSearchSelector Components
|
|
53
|
+
export { SingleUserSearchSelector } from "./SingleUserSearchSelector/SingleUserSearchSelector";
|
|
54
|
+
export type {
|
|
55
|
+
ProfileTypeFilter,
|
|
56
|
+
SingleUserSearchSelectorProps,
|
|
57
|
+
} from "./SingleUserSearchSelector/SingleUserSearchSelector";
|
|
58
|
+
|
|
53
59
|
// Custom Components
|
|
54
60
|
export { Button as CustomButton, buttonVariants as customButtonVariants } from "./custom/Button";
|
|
55
61
|
export { ClientOnly } from "./custom/ClientOnly";
|
|
@@ -53,3 +53,4 @@ export { useTokensFromAddress } from "./useTokensFromAddress";
|
|
|
53
53
|
export { useTurnkeyAuth } from "./useTurnkeyAuth";
|
|
54
54
|
export { useUnifiedChainSwitchAndExecute } from "./useUnifiedChainSwitchAndExecute";
|
|
55
55
|
export { useURLParams } from "./useURLParams";
|
|
56
|
+
export { useUser } from "./useUser";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import app from "@b3dotfun/sdk/global-account/app";
|
|
2
2
|
import { authenticateWithB3JWT } from "@b3dotfun/sdk/global-account/bsmnt";
|
|
3
|
-
import { useAuthStore,
|
|
3
|
+
import { useAuthStore, useB3Config } from "@b3dotfun/sdk/global-account/react";
|
|
4
4
|
import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
|
|
5
5
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
6
6
|
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
@@ -47,7 +47,7 @@ export function useAuth() {
|
|
|
47
47
|
const hasStartedConnecting = useAuthStore(state => state.hasStartedConnecting);
|
|
48
48
|
const useAutoConnectLoadingPrevious = useRef(false);
|
|
49
49
|
const referralCode = useSearchParam("referralCode");
|
|
50
|
-
const { partnerId } =
|
|
50
|
+
const { partnerId } = useB3Config();
|
|
51
51
|
const wagmiConfig = createWagmiConfig({ partnerId });
|
|
52
52
|
const { connect } = useConnect();
|
|
53
53
|
const activeWagmiAccount = useAccount();
|
|
@@ -330,7 +330,7 @@ export function useAuth() {
|
|
|
330
330
|
|
|
331
331
|
setIsAuthenticated(false);
|
|
332
332
|
setIsConnected(false);
|
|
333
|
-
setUser(
|
|
333
|
+
setUser();
|
|
334
334
|
callback?.();
|
|
335
335
|
},
|
|
336
336
|
[activeWallet, disconnect, wallets, setIsAuthenticated, setUser, setIsConnected],
|
|
@@ -25,7 +25,7 @@ import { useUserQuery } from "./useUserQuery";
|
|
|
25
25
|
const debug = debugB3React("useAuthentication");
|
|
26
26
|
|
|
27
27
|
export function useAuthentication(partnerId: string) {
|
|
28
|
-
const { onConnectCallback } = useContext(LocalSDKContext);
|
|
28
|
+
const { onConnectCallback, onLogoutCallback } = useContext(LocalSDKContext);
|
|
29
29
|
const { disconnect } = useDisconnect();
|
|
30
30
|
const wallets = useConnectedWallets();
|
|
31
31
|
const activeWallet = useActiveWallet();
|
|
@@ -179,10 +179,14 @@ export function useAuthentication(partnerId: string) {
|
|
|
179
179
|
|
|
180
180
|
setIsAuthenticated(false);
|
|
181
181
|
setIsConnected(false);
|
|
182
|
-
setUser(
|
|
182
|
+
setUser();
|
|
183
183
|
callback?.();
|
|
184
|
+
|
|
185
|
+
if (onLogoutCallback) {
|
|
186
|
+
await onLogoutCallback();
|
|
187
|
+
}
|
|
184
188
|
},
|
|
185
|
-
[activeWallet, disconnect, wallets, setIsAuthenticated, setUser, setIsConnected],
|
|
189
|
+
[activeWallet, disconnect, wallets, setIsAuthenticated, setUser, setIsConnected, onLogoutCallback],
|
|
186
190
|
);
|
|
187
191
|
|
|
188
192
|
const onConnect = useCallback(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useB3Config } from "@b3dotfun/sdk/global-account/react";
|
|
2
2
|
import { useCallback } from "react";
|
|
3
3
|
import {
|
|
4
4
|
ClientType,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
* Hook to access the current FeathersJS client and client management utilities
|
|
14
14
|
*/
|
|
15
15
|
export function useClient() {
|
|
16
|
-
const { clientType } =
|
|
16
|
+
const { clientType } = useB3Config();
|
|
17
17
|
|
|
18
18
|
const getCurrentClient = useCallback(() => {
|
|
19
19
|
return getClient();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useB3Config, useConnect } from "@b3dotfun/sdk/global-account/react";
|
|
2
2
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
3
3
|
import { useIdentityToken, usePrivy } from "@privy-io/react-auth";
|
|
4
4
|
import { useCallback, useRef, useState } from "react";
|
|
@@ -11,7 +11,7 @@ const debug = debugB3React("@@b3:useHandleConnectWithPrivy");
|
|
|
11
11
|
* Currently, this is for the basement-privy strategy
|
|
12
12
|
*/
|
|
13
13
|
export function useHandleConnectWithPrivy(chain?: Chain, onSuccess?: (account: Account) => void) {
|
|
14
|
-
const { partnerId } =
|
|
14
|
+
const { partnerId } = useB3Config();
|
|
15
15
|
if (!chain) {
|
|
16
16
|
throw new Error("Chain is required");
|
|
17
17
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useB3Config } from "@b3dotfun/sdk/global-account/react";
|
|
2
2
|
import { getAuthToken } from "@b3dotfun/sdk/shared/utils/auth-token";
|
|
3
3
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
4
4
|
import { useCallback, useEffect, useState } from "react";
|
|
@@ -56,7 +56,7 @@ export interface UseNotificationsReturn {
|
|
|
56
56
|
*/
|
|
57
57
|
export function useNotifications(): UseNotificationsReturn {
|
|
58
58
|
const { user } = useUserQuery();
|
|
59
|
-
const { partnerId } =
|
|
59
|
+
const { partnerId } = useB3Config();
|
|
60
60
|
const [userData, setUserData] = useState<UserData | null>(null);
|
|
61
61
|
const [loading, setLoading] = useState(true);
|
|
62
62
|
const [error, setError] = useState<string | null>(null);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useQuery } from "@tanstack/react-query";
|
|
2
|
+
import { fetchProfile, PROFILES_API_URL } from "../utils/profileApi";
|
|
2
3
|
|
|
3
4
|
// TypeScript interface for profile data
|
|
4
5
|
export interface Profile {
|
|
@@ -37,38 +38,6 @@ export interface DisplayNameRequestBody {
|
|
|
37
38
|
timestamp: number;
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
const PROFILES_API_URL = "https://profiles.b3.fun";
|
|
41
|
-
|
|
42
|
-
async function fetchProfile({
|
|
43
|
-
address,
|
|
44
|
-
name,
|
|
45
|
-
b3GlobalId,
|
|
46
|
-
fresh = false,
|
|
47
|
-
}: {
|
|
48
|
-
address?: string;
|
|
49
|
-
name?: string;
|
|
50
|
-
b3GlobalId?: string;
|
|
51
|
-
fresh?: boolean;
|
|
52
|
-
}): Promise<CombinedProfile> {
|
|
53
|
-
if (!address && !name && !b3GlobalId) {
|
|
54
|
-
throw new Error("Either address or name or b3GlobalId must be provided");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const params = new URLSearchParams();
|
|
58
|
-
if (address) params.append("address", address);
|
|
59
|
-
if (name) params.append("name", name);
|
|
60
|
-
if (b3GlobalId) params.append("b3GlobalId", b3GlobalId);
|
|
61
|
-
if (fresh) params.append("fresh", "true");
|
|
62
|
-
|
|
63
|
-
const response = await fetch(`${PROFILES_API_URL}?${params.toString()}`);
|
|
64
|
-
|
|
65
|
-
if (!response.ok) {
|
|
66
|
-
throw new Error(`Failed to fetch profile: ${response.statusText}`);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return response.json();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
41
|
async function setProfilePreference({
|
|
73
42
|
key,
|
|
74
43
|
preferredType,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { isNativeToken } from "@b3dotfun/sdk/anyspend";
|
|
4
|
-
import {
|
|
4
|
+
import { components } from "@b3dotfun/sdk/anyspend/types/api";
|
|
5
|
+
import { useAccountWallet, useAuthStore } from "@b3dotfun/sdk/global-account/react";
|
|
5
6
|
import { formatTokenAmount } from "@b3dotfun/sdk/shared/utils/number";
|
|
6
7
|
import { getERC20Balances, getNativeTokenBalance } from "@b3dotfun/sdk/shared/utils/thirdweb-insights";
|
|
7
8
|
import { useQuery } from "@tanstack/react-query";
|
|
8
9
|
import { useEffect } from "react";
|
|
9
|
-
import { components } from "@b3dotfun/sdk/anyspend/types/api";
|
|
10
10
|
|
|
11
11
|
interface UseTokenBalanceProps {
|
|
12
12
|
token: components["schemas"]["Token"];
|
|
@@ -20,7 +20,8 @@ export interface TokenBalanceResult {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function useTokenBalance({ token, address }: UseTokenBalanceProps): TokenBalanceResult {
|
|
23
|
-
const
|
|
23
|
+
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
24
|
+
|
|
24
25
|
const account = useAccountWallet();
|
|
25
26
|
|
|
26
27
|
const effectiveAddress = address || account?.address;
|
|
@@ -60,7 +61,7 @@ export function useTokenBalance({ token, address }: UseTokenBalanceProps): Token
|
|
|
60
61
|
}
|
|
61
62
|
return { formatted: "0", raw: null };
|
|
62
63
|
},
|
|
63
|
-
enabled:
|
|
64
|
+
enabled: isAuthenticated && !!effectiveAddress,
|
|
64
65
|
staleTime: 30000,
|
|
65
66
|
gcTime: 5 * 60 * 1000,
|
|
66
67
|
retry: 2,
|
|
@@ -69,13 +70,13 @@ export function useTokenBalance({ token, address }: UseTokenBalanceProps): Token
|
|
|
69
70
|
|
|
70
71
|
// Force a refetch when the wallet or token changes
|
|
71
72
|
useEffect(() => {
|
|
72
|
-
if (
|
|
73
|
+
if (isAuthenticated && effectiveAddress) {
|
|
73
74
|
refetch();
|
|
74
75
|
}
|
|
75
|
-
}, [
|
|
76
|
+
}, [isAuthenticated, effectiveAddress, token.address, token.chainId, token.symbol, refetch]);
|
|
76
77
|
|
|
77
78
|
// Determine if we're actually loading
|
|
78
|
-
const isActuallyLoading = !
|
|
79
|
+
const isActuallyLoading = !isAuthenticated || !effectiveAddress || isLoading || (isFetching && !tokenBalance);
|
|
79
80
|
|
|
80
81
|
return {
|
|
81
82
|
rawBalance: tokenBalance?.raw || BigInt(0),
|
|
@@ -2,7 +2,7 @@ import { TurnkeyAuthInitResponse } from "@b3dotfun/b3-api";
|
|
|
2
2
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
3
3
|
import { useCallback, useState } from "react";
|
|
4
4
|
import app from "../../app";
|
|
5
|
-
import {
|
|
5
|
+
import { useB3Config } from "../components";
|
|
6
6
|
import { useAuthStore } from "../stores";
|
|
7
7
|
import { useAuth } from "./useAuth";
|
|
8
8
|
|
|
@@ -33,7 +33,7 @@ export function useTurnkeyAuth(): UseTurnkeyAuthReturn {
|
|
|
33
33
|
const [error, setError] = useState<string | null>(null);
|
|
34
34
|
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
35
35
|
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
36
|
-
const { partnerId } =
|
|
36
|
+
const { partnerId } = useB3Config();
|
|
37
37
|
const { authenticate } = useAuth();
|
|
38
38
|
|
|
39
39
|
/**
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useAuthStore } from "@b3dotfun/sdk/global-account/react";
|
|
2
|
+
import { useUserStore } from "../stores/userStore";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Preferred Hook to get the user data
|
|
6
|
+
*/
|
|
7
|
+
export function useUser() {
|
|
8
|
+
const user = useUserStore(state => state.user);
|
|
9
|
+
|
|
10
|
+
const isConnecting = useAuthStore(state => state.isConnecting);
|
|
11
|
+
const isConnected = useAuthStore(state => state.isConnected);
|
|
12
|
+
const isAuthenticating = useAuthStore(state => state.isAuthenticating);
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
user,
|
|
16
|
+
isConnecting,
|
|
17
|
+
isConnected,
|
|
18
|
+
isAuthenticating,
|
|
19
|
+
};
|
|
20
|
+
}
|