@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
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { formatUnits } from "viem";
|
|
3
|
+
import { useBalance } from "wagmi";
|
|
4
|
+
import { isNativeToken } from "../../utils";
|
|
5
|
+
|
|
6
|
+
export interface TransferResult {
|
|
7
|
+
amount: string;
|
|
8
|
+
formattedAmount: string;
|
|
9
|
+
txHash?: string;
|
|
10
|
+
timestamp: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface UseWatchTransferProps {
|
|
14
|
+
/** Address to watch for incoming transfers */
|
|
15
|
+
address: string;
|
|
16
|
+
/** Chain ID to watch on */
|
|
17
|
+
chainId: number;
|
|
18
|
+
/** Token address (use zero address for native token) */
|
|
19
|
+
tokenAddress: string;
|
|
20
|
+
/** Token decimals */
|
|
21
|
+
tokenDecimals: number;
|
|
22
|
+
/** Whether watching is enabled */
|
|
23
|
+
enabled?: boolean;
|
|
24
|
+
/** Callback when a transfer is detected */
|
|
25
|
+
onTransferDetected?: (result: TransferResult) => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Hook to watch for incoming transfers to an address by monitoring balance changes.
|
|
30
|
+
* When a transfer is detected (balance increases), it captures the amount and notifies.
|
|
31
|
+
*/
|
|
32
|
+
export function useWatchTransfer({
|
|
33
|
+
address,
|
|
34
|
+
chainId,
|
|
35
|
+
tokenAddress,
|
|
36
|
+
tokenDecimals,
|
|
37
|
+
enabled = true,
|
|
38
|
+
onTransferDetected,
|
|
39
|
+
}: UseWatchTransferProps) {
|
|
40
|
+
const [transferResult, setTransferResult] = useState<TransferResult | null>(null);
|
|
41
|
+
const [isWatching, setIsWatching] = useState(false);
|
|
42
|
+
const initialBalanceRef = useRef<bigint | null>(null);
|
|
43
|
+
const transferDetectedRef = useRef(false);
|
|
44
|
+
|
|
45
|
+
const isNative = isNativeToken(tokenAddress);
|
|
46
|
+
// Get current balance
|
|
47
|
+
const { data: balanceData, refetch: refetchBalance } = useBalance({
|
|
48
|
+
address: address as `0x${string}`,
|
|
49
|
+
chainId,
|
|
50
|
+
token: isNative ? undefined : (tokenAddress as `0x${string}`),
|
|
51
|
+
query: {
|
|
52
|
+
enabled: enabled && !!address,
|
|
53
|
+
refetchInterval: 3000,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Initialize or update the initial balance
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (balanceData && initialBalanceRef.current === null && enabled) {
|
|
60
|
+
initialBalanceRef.current = balanceData.value;
|
|
61
|
+
setIsWatching(true);
|
|
62
|
+
}
|
|
63
|
+
}, [balanceData, enabled]);
|
|
64
|
+
|
|
65
|
+
// Check for balance increase (transfer detected)
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (!enabled || transferDetectedRef.current || initialBalanceRef.current === null || !balanceData) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const currentBalance = balanceData.value;
|
|
72
|
+
const initialBalance = initialBalanceRef.current;
|
|
73
|
+
|
|
74
|
+
if (currentBalance > initialBalance) {
|
|
75
|
+
const transferAmount = currentBalance - initialBalance;
|
|
76
|
+
const formattedAmount = formatUnits(transferAmount, tokenDecimals);
|
|
77
|
+
|
|
78
|
+
const result: TransferResult = {
|
|
79
|
+
amount: transferAmount.toString(),
|
|
80
|
+
formattedAmount,
|
|
81
|
+
timestamp: Date.now(),
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
transferDetectedRef.current = true;
|
|
85
|
+
setTransferResult(result);
|
|
86
|
+
setIsWatching(false);
|
|
87
|
+
onTransferDetected?.(result);
|
|
88
|
+
}
|
|
89
|
+
}, [balanceData, enabled, tokenDecimals, onTransferDetected]);
|
|
90
|
+
|
|
91
|
+
// Reset function to start watching again
|
|
92
|
+
const reset = useCallback(() => {
|
|
93
|
+
transferDetectedRef.current = false;
|
|
94
|
+
initialBalanceRef.current = null;
|
|
95
|
+
setTransferResult(null);
|
|
96
|
+
setIsWatching(false);
|
|
97
|
+
}, []);
|
|
98
|
+
|
|
99
|
+
return useMemo(
|
|
100
|
+
() => ({
|
|
101
|
+
/** Whether currently watching for transfers */
|
|
102
|
+
isWatching,
|
|
103
|
+
/** The detected transfer result, if any */
|
|
104
|
+
transferResult,
|
|
105
|
+
/** Whether a transfer has been detected */
|
|
106
|
+
hasTransfer: transferResult !== null,
|
|
107
|
+
/** Reset and start watching again */
|
|
108
|
+
reset,
|
|
109
|
+
/** Manually refetch balance */
|
|
110
|
+
refetchBalance,
|
|
111
|
+
}),
|
|
112
|
+
[isWatching, transferResult, reset, refetchBalance],
|
|
113
|
+
);
|
|
114
|
+
}
|
|
@@ -38,3 +38,16 @@ export function eqci(a: string | null | undefined, b: string | null | undefined)
|
|
|
38
38
|
if (!a || !b) return false;
|
|
39
39
|
return a.toLowerCase() === b.toLowerCase();
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Check if source and destination represent the same token on the same chain.
|
|
44
|
+
* When true, this is a pure transfer (no swap/bridge needed).
|
|
45
|
+
*/
|
|
46
|
+
export function isSameChainAndToken(
|
|
47
|
+
sourceChainId: number,
|
|
48
|
+
sourceTokenAddress: string,
|
|
49
|
+
destinationChainId: number,
|
|
50
|
+
destinationTokenAddress: string,
|
|
51
|
+
): boolean {
|
|
52
|
+
return sourceChainId === destinationChainId && eqci(sourceTokenAddress, destinationTokenAddress);
|
|
53
|
+
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
IPFSMediaRenderer,
|
|
7
7
|
toast,
|
|
8
8
|
useAuthentication,
|
|
9
|
-
|
|
9
|
+
useB3Config,
|
|
10
10
|
useProfile,
|
|
11
11
|
} from "@b3dotfun/sdk/global-account/react";
|
|
12
12
|
import { validateImageUrl } from "@b3dotfun/sdk/global-account/react/utils/profileDisplay";
|
|
@@ -57,7 +57,7 @@ export function AvatarEditor({ onSetAvatar, className }: AvatarEditorProps) {
|
|
|
57
57
|
const [zoom, setZoom] = useState(1);
|
|
58
58
|
const [croppedAreaPixels, setCroppedAreaPixels] = useState<Area | null>(null);
|
|
59
59
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
60
|
-
const { partnerId } =
|
|
60
|
+
const { partnerId } = useB3Config();
|
|
61
61
|
const { user, setUser } = useAuthentication(partnerId);
|
|
62
62
|
const setB3ModalContentType = useModalStore(state => state.setB3ModalContentType);
|
|
63
63
|
const contentType = useModalStore(state => state.contentType);
|
|
@@ -10,11 +10,12 @@ import {
|
|
|
10
10
|
AnySpendTournament,
|
|
11
11
|
OrderHistory,
|
|
12
12
|
} from "@b3dotfun/sdk/anyspend/react";
|
|
13
|
+
import { AnySpendDeposit } from "@b3dotfun/sdk/anyspend/react/components/AnySpendDeposit";
|
|
13
14
|
import { AnySpendDepositHype } from "@b3dotfun/sdk/anyspend/react/components/AnyspendDepositHype";
|
|
14
15
|
import { AnySpendDepositUpside } from "@b3dotfun/sdk/anyspend/react/components/AnySpendDepositUpside";
|
|
15
16
|
import { AnySpendStakeUpside } from "@b3dotfun/sdk/anyspend/react/components/AnySpendStakeUpside";
|
|
16
17
|
import { AnySpendStakeUpsideExactIn } from "@b3dotfun/sdk/anyspend/react/components/AnySpendStakeUpsideExactIn";
|
|
17
|
-
import {
|
|
18
|
+
import { useB3Config, useIsMobile, useModalStore } from "@b3dotfun/sdk/global-account/react";
|
|
18
19
|
import { cn } from "@b3dotfun/sdk/shared/utils/cn";
|
|
19
20
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
20
21
|
import { AnimatePresence, motion } from "framer-motion";
|
|
@@ -39,7 +40,7 @@ export function B3DynamicModal() {
|
|
|
39
40
|
const setB3ModalOpen = useModalStore(state => state.setB3ModalOpen);
|
|
40
41
|
const contentType = useModalStore(state => state.contentType);
|
|
41
42
|
const navigateBack = useModalStore(state => state.navigateBack);
|
|
42
|
-
const { theme } =
|
|
43
|
+
const { theme } = useB3Config();
|
|
43
44
|
const isMobile = useIsMobile();
|
|
44
45
|
const { toasts, removeToast } = useToastContext();
|
|
45
46
|
|
|
@@ -65,6 +66,7 @@ export function B3DynamicModal() {
|
|
|
65
66
|
"deposit",
|
|
66
67
|
"send",
|
|
67
68
|
"notifications",
|
|
69
|
+
"anySpendDeposit",
|
|
68
70
|
];
|
|
69
71
|
|
|
70
72
|
const freestyleTypes = [
|
|
@@ -153,6 +155,8 @@ export function B3DynamicModal() {
|
|
|
153
155
|
return <AnySpendDepositHype {...contentType} mode="modal" />;
|
|
154
156
|
case "anySpendCollectorClubPurchase":
|
|
155
157
|
return <AnySpendCollectorClubPurchase {...contentType} mode="modal" />;
|
|
158
|
+
case "anySpendDeposit":
|
|
159
|
+
return <AnySpendDeposit {...contentType} mode="modal" />;
|
|
156
160
|
case "avatarEditor":
|
|
157
161
|
return <AvatarEditor onSetAvatar={contentType.onSuccess} />;
|
|
158
162
|
case "deposit":
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useAuthentication } from "../../hooks";
|
|
2
|
+
import { useAutoSelectWallet } from "../../hooks/useAutoSelectWallet";
|
|
3
|
+
|
|
4
|
+
const AuthenticationProvider = ({
|
|
5
|
+
partnerId,
|
|
6
|
+
automaticallySetFirstEoa,
|
|
7
|
+
}: {
|
|
8
|
+
partnerId: string;
|
|
9
|
+
automaticallySetFirstEoa: boolean;
|
|
10
|
+
}) => {
|
|
11
|
+
useAuthentication(partnerId);
|
|
12
|
+
useAutoSelectWallet({
|
|
13
|
+
enabled: automaticallySetFirstEoa,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return null;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default AuthenticationProvider;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { CreateOnrampOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOnrampOrder";
|
|
2
|
+
import { CreateOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOrder";
|
|
3
|
+
import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
|
|
4
|
+
import { createContext, useContext } from "react";
|
|
5
|
+
import { Account } from "thirdweb/wallets";
|
|
6
|
+
import { ClientType } from "../../../client-manager";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Default permissions configuration for B3 provider
|
|
10
|
+
*/
|
|
11
|
+
const DEFAULT_PERMISSIONS: PermissionsConfig = {
|
|
12
|
+
approvedTargets: ["0xa8e42121e318e3D3BeD7f5969AF6D360045317DD"],
|
|
13
|
+
nativeTokenLimitPerTransaction: 0.1,
|
|
14
|
+
startDate: new Date(),
|
|
15
|
+
endDate: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365), // 1 year from now
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export interface B3ConfigContextType {
|
|
19
|
+
accountOverride?: Account;
|
|
20
|
+
automaticallySetFirstEoa: boolean;
|
|
21
|
+
environment: "development" | "production";
|
|
22
|
+
defaultPermissions: PermissionsConfig;
|
|
23
|
+
theme: "light" | "dark";
|
|
24
|
+
clientType: ClientType;
|
|
25
|
+
partnerId: string;
|
|
26
|
+
stripePublishableKey?: string;
|
|
27
|
+
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
28
|
+
enableTurnkey: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const B3ConfigContext = createContext<B3ConfigContextType | null>(null);
|
|
32
|
+
|
|
33
|
+
export function B3ConfigProvider({
|
|
34
|
+
children,
|
|
35
|
+
accountOverride,
|
|
36
|
+
environment = "development",
|
|
37
|
+
defaultPermissions = DEFAULT_PERMISSIONS,
|
|
38
|
+
automaticallySetFirstEoa = false,
|
|
39
|
+
theme = "light",
|
|
40
|
+
clientType = "rest",
|
|
41
|
+
partnerId,
|
|
42
|
+
stripePublishableKey,
|
|
43
|
+
createClientReferenceId,
|
|
44
|
+
enableTurnkey = false,
|
|
45
|
+
}: {
|
|
46
|
+
children: React.ReactNode;
|
|
47
|
+
accountOverride?: Account;
|
|
48
|
+
environment?: "development" | "production";
|
|
49
|
+
defaultPermissions?: PermissionsConfig;
|
|
50
|
+
automaticallySetFirstEoa?: boolean;
|
|
51
|
+
theme?: "light" | "dark";
|
|
52
|
+
clientType?: ClientType;
|
|
53
|
+
partnerId: string;
|
|
54
|
+
stripePublishableKey?: string;
|
|
55
|
+
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
56
|
+
enableTurnkey?: boolean;
|
|
57
|
+
}) {
|
|
58
|
+
return (
|
|
59
|
+
<B3ConfigContext.Provider
|
|
60
|
+
value={{
|
|
61
|
+
accountOverride,
|
|
62
|
+
environment,
|
|
63
|
+
defaultPermissions,
|
|
64
|
+
automaticallySetFirstEoa,
|
|
65
|
+
theme,
|
|
66
|
+
clientType,
|
|
67
|
+
partnerId,
|
|
68
|
+
stripePublishableKey,
|
|
69
|
+
createClientReferenceId,
|
|
70
|
+
enableTurnkey,
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
{children}
|
|
74
|
+
</B3ConfigContext.Provider>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function useB3Config(): B3ConfigContextType {
|
|
79
|
+
const context = useContext(B3ConfigContext);
|
|
80
|
+
if (!context) {
|
|
81
|
+
throw new Error("useB3Config must be used within a B3ConfigProvider");
|
|
82
|
+
}
|
|
83
|
+
return context;
|
|
84
|
+
}
|
|
@@ -1,78 +1,73 @@
|
|
|
1
1
|
import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
|
|
2
2
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
3
|
-
import { ThirdwebProvider
|
|
3
|
+
import { ThirdwebProvider } from "thirdweb/react";
|
|
4
4
|
import { Account, Wallet } from "thirdweb/wallets";
|
|
5
5
|
|
|
6
6
|
import { ClientType } from "../../../client-manager";
|
|
7
7
|
|
|
8
8
|
import { WagmiProvider } from "wagmi";
|
|
9
9
|
import { createWagmiConfig } from "../../utils/createWagmiConfig";
|
|
10
|
+
import AuthenticationProvider from "./AuthenticationProvider";
|
|
11
|
+
import { B3ConfigProvider } from "./B3ConfigProvider";
|
|
10
12
|
import { LocalSDKProvider } from "./LocalSDKProvider";
|
|
11
|
-
import { B3Context, B3ContextType } from "./types";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Default permissions configuration for B3 provider
|
|
15
|
-
*/
|
|
16
|
-
const DEFAULT_PERMISSIONS = {
|
|
17
|
-
approvedTargets: ["0xa8e42121e318e3D3BeD7f5969AF6D360045317DD"], // Example contract
|
|
18
|
-
nativeTokenLimitPerTransaction: 0.1, // in ETH
|
|
19
|
-
startDate: new Date(),
|
|
20
|
-
endDate: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365), // 1 year from now
|
|
21
|
-
};
|
|
22
13
|
|
|
23
14
|
// Create queryClient instance
|
|
24
15
|
const queryClient = new QueryClient();
|
|
25
16
|
|
|
26
17
|
/**
|
|
27
|
-
* Main B3Provider component
|
|
18
|
+
* Main B3Provider component
|
|
28
19
|
*/
|
|
29
20
|
export function B3Provider({
|
|
30
|
-
theme,
|
|
21
|
+
theme = "light",
|
|
31
22
|
children,
|
|
32
23
|
accountOverride,
|
|
33
24
|
environment,
|
|
34
|
-
clientType,
|
|
25
|
+
clientType = "socket",
|
|
35
26
|
partnerId,
|
|
36
27
|
rpcUrls,
|
|
37
28
|
onConnect,
|
|
29
|
+
defaultPermissions,
|
|
38
30
|
}: {
|
|
39
31
|
theme: "light" | "dark";
|
|
40
32
|
children: React.ReactNode;
|
|
41
33
|
accountOverride?: Account;
|
|
42
|
-
environment
|
|
34
|
+
environment?: "development" | "production";
|
|
43
35
|
clientType?: ClientType;
|
|
44
36
|
partnerId: string;
|
|
45
37
|
rpcUrls?: Record<number, string>;
|
|
46
38
|
onConnect?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
39
|
+
defaultPermissions?: PermissionsConfig;
|
|
47
40
|
}) {
|
|
48
41
|
return (
|
|
49
42
|
<ThirdwebProvider>
|
|
50
43
|
<LocalSDKProvider onConnectCallback={onConnect}>
|
|
51
|
-
<
|
|
44
|
+
<B3ConfigProvider
|
|
52
45
|
accountOverride={accountOverride}
|
|
53
46
|
environment={environment}
|
|
47
|
+
automaticallySetFirstEoa={false}
|
|
54
48
|
theme={theme}
|
|
55
49
|
clientType={clientType}
|
|
56
50
|
partnerId={partnerId}
|
|
57
|
-
|
|
51
|
+
defaultPermissions={defaultPermissions}
|
|
58
52
|
>
|
|
59
53
|
{/* <RelayKitProviderWrapper> */}
|
|
60
54
|
{children}
|
|
55
|
+
<AuthenticationProvider partnerId={partnerId} automaticallySetFirstEoa={false} />
|
|
61
56
|
{/* </RelayKitProviderWrapper> */}
|
|
62
|
-
</
|
|
57
|
+
</B3ConfigProvider>
|
|
63
58
|
</LocalSDKProvider>
|
|
64
59
|
</ThirdwebProvider>
|
|
65
60
|
);
|
|
66
61
|
}
|
|
67
62
|
|
|
68
63
|
/**
|
|
69
|
-
* Inner provider component
|
|
64
|
+
* Inner provider component for native
|
|
70
65
|
*/
|
|
71
66
|
export function InnerProvider({
|
|
72
67
|
children,
|
|
73
68
|
accountOverride,
|
|
74
69
|
environment,
|
|
75
|
-
defaultPermissions
|
|
70
|
+
defaultPermissions,
|
|
76
71
|
theme = "light",
|
|
77
72
|
clientType = "socket",
|
|
78
73
|
partnerId,
|
|
@@ -80,43 +75,29 @@ export function InnerProvider({
|
|
|
80
75
|
}: {
|
|
81
76
|
children: React.ReactNode;
|
|
82
77
|
accountOverride?: Account;
|
|
83
|
-
environment
|
|
78
|
+
environment?: "development" | "production";
|
|
84
79
|
defaultPermissions?: PermissionsConfig;
|
|
85
80
|
theme: "light" | "dark";
|
|
86
81
|
clientType?: ClientType;
|
|
87
82
|
partnerId: string;
|
|
88
83
|
rpcUrls?: Record<number, string>;
|
|
89
84
|
}) {
|
|
90
|
-
const activeAccount = useActiveAccount();
|
|
91
|
-
//const { user, setUser, refetchUser } = useAuthentication(partnerId);
|
|
92
85
|
const wagmiConfig = createWagmiConfig({ partnerId, rpcUrls });
|
|
93
86
|
|
|
94
|
-
// Use given accountOverride or activeAccount from thirdweb
|
|
95
|
-
const effectiveAccount = accountOverride || activeAccount;
|
|
96
|
-
|
|
97
87
|
return (
|
|
98
88
|
<WagmiProvider config={wagmiConfig}>
|
|
99
89
|
<QueryClientProvider client={queryClient}>
|
|
100
|
-
<
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
initialized: true,
|
|
109
|
-
ready: !!effectiveAccount,
|
|
110
|
-
environment,
|
|
111
|
-
defaultPermissions,
|
|
112
|
-
theme,
|
|
113
|
-
clientType,
|
|
114
|
-
partnerId,
|
|
115
|
-
//refetchUser,
|
|
116
|
-
}}
|
|
90
|
+
<B3ConfigProvider
|
|
91
|
+
accountOverride={accountOverride}
|
|
92
|
+
environment={environment}
|
|
93
|
+
automaticallySetFirstEoa={false}
|
|
94
|
+
theme={theme}
|
|
95
|
+
clientType={clientType}
|
|
96
|
+
partnerId={partnerId}
|
|
97
|
+
defaultPermissions={defaultPermissions}
|
|
117
98
|
>
|
|
118
99
|
{children}
|
|
119
|
-
</
|
|
100
|
+
</B3ConfigProvider>
|
|
120
101
|
</QueryClientProvider>
|
|
121
102
|
</WagmiProvider>
|
|
122
103
|
);
|
|
@@ -1,36 +1,21 @@
|
|
|
1
1
|
import { CreateOnrampOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOnrampOrder";
|
|
2
2
|
import { CreateOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOrder";
|
|
3
|
-
import {
|
|
4
|
-
RelayKitProviderWrapper,
|
|
5
|
-
TooltipProvider,
|
|
6
|
-
useAuthentication,
|
|
7
|
-
useAuthStore,
|
|
8
|
-
} from "@b3dotfun/sdk/global-account/react";
|
|
9
|
-
import { useAutoSelectWallet } from "@b3dotfun/sdk/global-account/react/hooks/useAutoSelectWallet";
|
|
3
|
+
import { RelayKitProviderWrapper, TooltipProvider } from "@b3dotfun/sdk/global-account/react";
|
|
10
4
|
import { createWagmiConfig } from "@b3dotfun/sdk/global-account/react/utils/createWagmiConfig";
|
|
11
5
|
import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
|
|
12
6
|
import { loadGA4Script } from "@b3dotfun/sdk/global-account/utils/analytics";
|
|
13
7
|
import "@relayprotocol/relay-kit-ui/styles.css";
|
|
14
8
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
15
9
|
import { useEffect, useMemo } from "react";
|
|
16
|
-
import { ThirdwebProvider
|
|
10
|
+
import { ThirdwebProvider } from "thirdweb/react";
|
|
17
11
|
import { Account, Wallet } from "thirdweb/wallets";
|
|
18
12
|
import { CreateConnectorFn, WagmiProvider } from "wagmi";
|
|
19
13
|
import { ClientType, setClientType } from "../../../client-manager";
|
|
20
14
|
import { StyleRoot } from "../StyleRoot";
|
|
21
15
|
import { setToastContext, ToastProvider, useToastContext } from "../Toast/index";
|
|
16
|
+
import AuthenticationProvider from "./AuthenticationProvider";
|
|
17
|
+
import { B3ConfigProvider } from "./B3ConfigProvider";
|
|
22
18
|
import { LocalSDKProvider } from "./LocalSDKProvider";
|
|
23
|
-
import { B3Context, B3ContextType } from "./types";
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Default permissions configuration for B3 provider
|
|
27
|
-
*/
|
|
28
|
-
const DEFAULT_PERMISSIONS = {
|
|
29
|
-
approvedTargets: ["0xa8e42121e318e3D3BeD7f5969AF6D360045317DD"], // Example contract
|
|
30
|
-
nativeTokenLimitPerTransaction: 0.1, // in ETH
|
|
31
|
-
startDate: new Date(),
|
|
32
|
-
endDate: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365), // 1 year from now
|
|
33
|
-
};
|
|
34
19
|
|
|
35
20
|
// Create queryClient instance
|
|
36
21
|
const queryClient = new QueryClient();
|
|
@@ -52,15 +37,17 @@ export function B3Provider({
|
|
|
52
37
|
partnerId,
|
|
53
38
|
stripePublishableKey,
|
|
54
39
|
onConnect,
|
|
40
|
+
onLogout,
|
|
55
41
|
connectors,
|
|
56
42
|
overrideDefaultConnectors = false,
|
|
57
43
|
createClientReferenceId,
|
|
58
44
|
enableTurnkey = false,
|
|
45
|
+
defaultPermissions,
|
|
59
46
|
}: {
|
|
60
47
|
theme: "light" | "dark";
|
|
61
48
|
children: React.ReactNode;
|
|
62
49
|
accountOverride?: Account;
|
|
63
|
-
environment
|
|
50
|
+
environment?: "development" | "production";
|
|
64
51
|
automaticallySetFirstEoa?: boolean;
|
|
65
52
|
simDuneApiKey?: string;
|
|
66
53
|
toaster?: {
|
|
@@ -73,10 +60,12 @@ export function B3Provider({
|
|
|
73
60
|
/** Partner-specific Stripe publishable key. If not provided, uses default B3 Stripe account. */
|
|
74
61
|
stripePublishableKey?: string;
|
|
75
62
|
onConnect?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
63
|
+
onLogout?: () => void | Promise<void>;
|
|
76
64
|
connectors?: CreateConnectorFn[];
|
|
77
65
|
overrideDefaultConnectors?: boolean;
|
|
78
66
|
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
79
67
|
enableTurnkey?: boolean;
|
|
68
|
+
defaultPermissions?: PermissionsConfig;
|
|
80
69
|
}) {
|
|
81
70
|
// Initialize Google Analytics on mount
|
|
82
71
|
useEffect(() => {
|
|
@@ -99,17 +88,18 @@ export function B3Provider({
|
|
|
99
88
|
<QueryClientProvider client={queryClient}>
|
|
100
89
|
<TooltipProvider>
|
|
101
90
|
<ToastProvider>
|
|
102
|
-
<LocalSDKProvider onConnectCallback={onConnect}>
|
|
103
|
-
<
|
|
91
|
+
<LocalSDKProvider onConnectCallback={onConnect} onLogoutCallback={onLogout}>
|
|
92
|
+
<B3ConfigProvider
|
|
104
93
|
accountOverride={accountOverride}
|
|
105
94
|
environment={environment}
|
|
106
|
-
theme={theme}
|
|
107
95
|
automaticallySetFirstEoa={!!automaticallySetFirstEoa}
|
|
96
|
+
theme={theme}
|
|
108
97
|
clientType={clientType}
|
|
109
98
|
partnerId={partnerId}
|
|
110
99
|
stripePublishableKey={stripePublishableKey}
|
|
111
100
|
createClientReferenceId={createClientReferenceId}
|
|
112
101
|
enableTurnkey={enableTurnkey}
|
|
102
|
+
defaultPermissions={defaultPermissions}
|
|
113
103
|
>
|
|
114
104
|
<ToastContextConnector />
|
|
115
105
|
<RelayKitProviderWrapper simDuneApiKey={simDuneApiKey}>
|
|
@@ -117,7 +107,8 @@ export function B3Provider({
|
|
|
117
107
|
{/* For the modal https://github.com/b3-fun/b3/blob/main/packages/sdk/src/global-account/react/components/ui/dialog.tsx#L46 */}
|
|
118
108
|
<StyleRoot id="b3-root" />
|
|
119
109
|
</RelayKitProviderWrapper>
|
|
120
|
-
|
|
110
|
+
<AuthenticationProvider partnerId={partnerId} automaticallySetFirstEoa={!!automaticallySetFirstEoa} />
|
|
111
|
+
</B3ConfigProvider>
|
|
121
112
|
</LocalSDKProvider>
|
|
122
113
|
</ToastProvider>
|
|
123
114
|
</TooltipProvider>
|
|
@@ -127,85 +118,6 @@ export function B3Provider({
|
|
|
127
118
|
);
|
|
128
119
|
}
|
|
129
120
|
|
|
130
|
-
/**
|
|
131
|
-
* Inner provider component that provides the actual B3Context
|
|
132
|
-
*/
|
|
133
|
-
export function InnerProvider({
|
|
134
|
-
children,
|
|
135
|
-
accountOverride,
|
|
136
|
-
environment,
|
|
137
|
-
defaultPermissions = DEFAULT_PERMISSIONS,
|
|
138
|
-
automaticallySetFirstEoa,
|
|
139
|
-
theme = "light",
|
|
140
|
-
clientType = "socket",
|
|
141
|
-
partnerId,
|
|
142
|
-
stripePublishableKey,
|
|
143
|
-
createClientReferenceId,
|
|
144
|
-
enableTurnkey,
|
|
145
|
-
}: {
|
|
146
|
-
children: React.ReactNode;
|
|
147
|
-
accountOverride?: Account;
|
|
148
|
-
environment: B3ContextType["environment"];
|
|
149
|
-
defaultPermissions?: PermissionsConfig;
|
|
150
|
-
automaticallySetFirstEoa: boolean;
|
|
151
|
-
theme: "light" | "dark";
|
|
152
|
-
clientType?: ClientType;
|
|
153
|
-
partnerId: string;
|
|
154
|
-
stripePublishableKey?: string;
|
|
155
|
-
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
156
|
-
enableTurnkey?: boolean;
|
|
157
|
-
}) {
|
|
158
|
-
const activeAccount = useActiveAccount();
|
|
159
|
-
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
160
|
-
//const isConnected = useAuthStore(state => state.isConnected);
|
|
161
|
-
//const justCompletedLogin = useAuthStore(state => state.justCompletedLogin);
|
|
162
|
-
|
|
163
|
-
// Note: This fixes a bug where useAuthentication is no longer rendered on every page, as of this PR https://github.com/b3-fun/b3/pull/385/files#diff-3ef996931b8fc8e49021ba1b42ddaa97535214681610dc5fdacf63542e261af7
|
|
164
|
-
// The above PR removes useAuthentication from the overall B3Provider. useAuthentication should be everywhere the provider is, since it sets the overall auth state
|
|
165
|
-
// By just calling it manually, we fix that issue
|
|
166
|
-
// As a follow up, we should fix the SDK directly
|
|
167
|
-
useAuthentication(partnerId);
|
|
168
|
-
|
|
169
|
-
// Use given accountOverride or activeAccount from thirdweb
|
|
170
|
-
// WOJ: why if isAuthenticated is false, we don't use activeAccount, which should be undefined?
|
|
171
|
-
// skip isAuthenticated check ?
|
|
172
|
-
const effectiveAccount = isAuthenticated ? accountOverride || activeAccount : undefined;
|
|
173
|
-
|
|
174
|
-
// Wrapper to set active wallet via thirdweb
|
|
175
|
-
// Note: `wallet` in context is deprecated - use useActiveWallet() from thirdweb/react instead
|
|
176
|
-
|
|
177
|
-
// Auto-select first EOA wallet when enabled
|
|
178
|
-
useAutoSelectWallet({
|
|
179
|
-
enabled: automaticallySetFirstEoa,
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
return (
|
|
183
|
-
<B3Context.Provider
|
|
184
|
-
value={{
|
|
185
|
-
account: effectiveAccount,
|
|
186
|
-
// setWallet,
|
|
187
|
-
//wallet: undefined, // Deprecated: use useActiveWallet() from thirdweb/react instead
|
|
188
|
-
//user,
|
|
189
|
-
//setUser,
|
|
190
|
-
//refetchUser,
|
|
191
|
-
initialized: true,
|
|
192
|
-
ready: !!effectiveAccount,
|
|
193
|
-
automaticallySetFirstEoa,
|
|
194
|
-
environment,
|
|
195
|
-
defaultPermissions,
|
|
196
|
-
theme,
|
|
197
|
-
clientType,
|
|
198
|
-
partnerId: partnerId,
|
|
199
|
-
stripePublishableKey,
|
|
200
|
-
createClientReferenceId,
|
|
201
|
-
enableTurnkey,
|
|
202
|
-
}}
|
|
203
|
-
>
|
|
204
|
-
{children}
|
|
205
|
-
</B3Context.Provider>
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
121
|
/**
|
|
210
122
|
* Component to connect the toast context to the global toast API
|
|
211
123
|
*/
|
|
@@ -7,10 +7,12 @@ import { Wallet } from "thirdweb/wallets";
|
|
|
7
7
|
*/
|
|
8
8
|
export interface LocalSDKContextType {
|
|
9
9
|
onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
10
|
+
onLogoutCallback?: () => void | Promise<void>;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export const LocalSDKContext = createContext<LocalSDKContextType>({
|
|
13
14
|
onConnectCallback: undefined,
|
|
15
|
+
onLogoutCallback: undefined,
|
|
14
16
|
});
|
|
15
17
|
|
|
16
18
|
/**
|
|
@@ -19,14 +21,17 @@ export const LocalSDKContext = createContext<LocalSDKContextType>({
|
|
|
19
21
|
export function LocalSDKProvider({
|
|
20
22
|
children,
|
|
21
23
|
onConnectCallback,
|
|
24
|
+
onLogoutCallback,
|
|
22
25
|
}: {
|
|
23
26
|
children: React.ReactNode;
|
|
24
27
|
onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
28
|
+
onLogoutCallback?: () => void | Promise<void>;
|
|
25
29
|
}) {
|
|
26
30
|
return (
|
|
27
31
|
<LocalSDKContext.Provider
|
|
28
32
|
value={{
|
|
29
33
|
onConnectCallback,
|
|
34
|
+
onLogoutCallback,
|
|
30
35
|
}}
|
|
31
36
|
>
|
|
32
37
|
{children}
|