@b3dotfun/sdk 0.0.61-test.1 → 0.0.62-alpha.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.
Files changed (44) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpendStakeB3.js +13 -2
  2. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.d.ts +1 -0
  3. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +17 -1
  4. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +4 -1
  5. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +3 -3
  6. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +2 -2
  7. package/dist/cjs/global-account/react/hooks/index.d.ts +1 -0
  8. package/dist/cjs/global-account/react/hooks/index.js +3 -1
  9. package/dist/cjs/global-account/react/hooks/useAuthentication.js +2 -2
  10. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +2 -0
  11. package/dist/cjs/global-account/react/utils/createWagmiConfig.d.ts +27 -0
  12. package/dist/cjs/global-account/react/utils/createWagmiConfig.js +32 -0
  13. package/dist/esm/anyspend/react/components/AnySpendStakeB3.js +13 -2
  14. package/dist/esm/anyspend/react/components/AnyspendDepositHype.d.ts +1 -0
  15. package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +19 -3
  16. package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +4 -1
  17. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +3 -3
  18. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +2 -2
  19. package/dist/esm/global-account/react/hooks/index.d.ts +1 -0
  20. package/dist/esm/global-account/react/hooks/index.js +1 -0
  21. package/dist/esm/global-account/react/hooks/useAuthentication.js +2 -2
  22. package/dist/esm/global-account/react/stores/useModalStore.d.ts +2 -0
  23. package/dist/esm/global-account/react/utils/createWagmiConfig.d.ts +27 -0
  24. package/dist/esm/global-account/react/utils/createWagmiConfig.js +29 -0
  25. package/dist/types/anyspend/react/components/AnyspendDepositHype.d.ts +1 -0
  26. package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +4 -1
  27. package/dist/types/global-account/react/hooks/index.d.ts +1 -0
  28. package/dist/types/global-account/react/stores/useModalStore.d.ts +2 -0
  29. package/dist/types/global-account/react/utils/createWagmiConfig.d.ts +27 -0
  30. package/package.json +1 -2
  31. package/src/anyspend/react/components/AnySpendStakeB3.tsx +15 -2
  32. package/src/anyspend/react/components/AnyspendDepositHype.tsx +22 -2
  33. package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +2 -2
  34. package/src/global-account/react/components/B3Provider/B3Provider.tsx +7 -3
  35. package/src/global-account/react/hooks/index.ts +1 -0
  36. package/src/global-account/react/hooks/useAuthentication.ts +2 -2
  37. package/src/global-account/react/stores/useModalStore.ts +2 -0
  38. package/src/global-account/react/utils/createWagmiConfig.tsx +40 -0
  39. package/dist/cjs/global-account/react/hooks/useWagmiConfig.d.ts +0 -453
  40. package/dist/cjs/global-account/react/hooks/useWagmiConfig.js +0 -44
  41. package/dist/esm/global-account/react/hooks/useWagmiConfig.d.ts +0 -453
  42. package/dist/esm/global-account/react/hooks/useWagmiConfig.js +0 -41
  43. package/dist/types/global-account/react/hooks/useWagmiConfig.d.ts +0 -453
  44. package/src/global-account/react/hooks/useWagmiConfig.tsx +0 -46
@@ -207,13 +207,26 @@ export function AnySpendStakeB3({
207
207
  args: [ERC20Staking as `0x${string}`, BigInt(userStakeAmount)],
208
208
  });
209
209
 
210
- await switchChainAndExecute(base.id, {
210
+ const approvalHash = await switchChainAndExecute(base.id, {
211
211
  to: B3_TOKEN.address as `0x${string}`,
212
212
  data: approvalData,
213
213
  value: BigInt(0),
214
214
  });
215
215
 
216
- toast.info("Approval confirmed. Proceeding with stake...");
216
+ if (!approvalHash) {
217
+ toast.error("Approval failed. Please try again.");
218
+ return;
219
+ }
220
+
221
+ const approvalReceipt = await basePublicClient.waitForTransactionReceipt({
222
+ hash: approvalHash as `0x${string}`,
223
+ confirmations: 1,
224
+ });
225
+
226
+ if (approvalReceipt?.status !== "success") {
227
+ toast.error("Approval failed. Please try again.");
228
+ return;
229
+ }
217
230
  }
218
231
 
219
232
  // Execute the stake
@@ -1,10 +1,10 @@
1
1
  import { B3_TOKEN } from "@b3dotfun/sdk/anyspend";
2
2
  import { components } from "@b3dotfun/sdk/anyspend/types/api";
3
- import { Button, ShinyButton, StyleRoot, TransitionPanel } from "@b3dotfun/sdk/global-account/react";
3
+ import { Button, ShinyButton, StyleRoot, TransitionPanel, useAccountWallet } from "@b3dotfun/sdk/global-account/react";
4
4
  import { cn } from "@b3dotfun/sdk/shared/utils/cn";
5
5
  import invariant from "invariant";
6
6
  import { motion } from "motion/react";
7
- import { useMemo } from "react";
7
+ import { useEffect, useMemo, useRef } from "react";
8
8
  import { toast } from "sonner";
9
9
  import { base } from "viem/chains";
10
10
  import { PanelView, useAnyspendFlow } from "../hooks/useAnyspendFlow";
@@ -17,9 +17,11 @@ import { FiatPaymentMethod, FiatPaymentMethodComponent } from "./common/FiatPaym
17
17
  import { OrderDetails } from "./common/OrderDetails";
18
18
  import { PointsDetailPanel } from "./common/PointsDetailPanel";
19
19
  import { RecipientSelection } from "./common/RecipientSelection";
20
+ import { useActiveWallet, useSetActiveWallet } from "thirdweb/react";
20
21
 
21
22
  import { ArrowDown, Loader2 } from "lucide-react";
22
23
  import { PanelOnramp } from "./common/PanelOnramp";
24
+ import { useGlobalWalletState } from "../../utils";
23
25
 
24
26
  const SLIPPAGE_PERCENT = 3;
25
27
 
@@ -43,6 +45,7 @@ export interface AnySpendDepositHypeProps {
43
45
  */
44
46
  onTokenSelect?: (token: components["schemas"]["Token"], event: { preventDefault: () => void }) => void;
45
47
  customUsdInputValues?: string[];
48
+ preferEoa?: boolean;
46
49
  }
47
50
 
48
51
  export function AnySpendDepositHype(props: AnySpendDepositHypeProps) {
@@ -66,6 +69,7 @@ function AnySpendDepositHypeInner({
66
69
  mainFooter,
67
70
  onTokenSelect,
68
71
  customUsdInputValues,
72
+ preferEoa,
69
73
  }: AnySpendDepositHypeProps) {
70
74
  // Use shared flow hook
71
75
  const {
@@ -113,6 +117,22 @@ function AnySpendDepositHypeInner({
113
117
  disableUrlParamManagement: true,
114
118
  });
115
119
 
120
+ const { connectedEOAWallet: connectedEOAWallet } = useAccountWallet();
121
+ const setActiveWallet = useSetActiveWallet();
122
+ const activeWallet = useActiveWallet();
123
+ const setGlobalAccountWallet = useGlobalWalletState(state => state.setGlobalAccountWallet);
124
+ const appliedPreferEoa = useRef(false);
125
+
126
+ useEffect(() => {
127
+ if (preferEoa && !appliedPreferEoa.current) {
128
+ if (connectedEOAWallet) {
129
+ appliedPreferEoa.current = true;
130
+ setGlobalAccountWallet(activeWallet);
131
+ setActiveWallet(connectedEOAWallet);
132
+ }
133
+ }
134
+ }, [preferEoa, connectedEOAWallet, setActiveWallet, activeWallet, setGlobalAccountWallet]);
135
+
116
136
  // Button state logic
117
137
  const btnInfo: { text: string; disable: boolean; error: boolean; loading: boolean } = useMemo(() => {
118
138
  if (activeInputAmountInWei === "0") return { text: "Enter an amount", disable: true, error: false, loading: false };
@@ -7,7 +7,7 @@ import { ClientType } from "../../../client-manager";
7
7
 
8
8
  import { WagmiProvider } from "wagmi";
9
9
  import { useAuthentication } from "../../hooks/useAuthentication";
10
- import { useWagmiConfig } from "../../hooks/useWagmiConfig";
10
+ import { createWagmiConfig } from "../../utils/createWagmiConfig";
11
11
  import { LocalSDKProvider } from "./LocalSDKProvider";
12
12
  import { B3Context, B3ContextType } from "./types";
13
13
 
@@ -90,7 +90,7 @@ export function InnerProvider({
90
90
  }) {
91
91
  const activeAccount = useActiveAccount();
92
92
  const { user, setUser, refetchUser } = useAuthentication(partnerId);
93
- const wagmiConfig = useWagmiConfig(partnerId, rpcUrls);
93
+ const wagmiConfig = createWagmiConfig({ partnerId, rpcUrls });
94
94
 
95
95
  // Use given accountOverride or activeAccount from thirdweb
96
96
  const effectiveAccount = accountOverride || activeAccount;
@@ -4,7 +4,7 @@ import {
4
4
  useAuthentication,
5
5
  useAuthStore,
6
6
  } from "@b3dotfun/sdk/global-account/react";
7
- import { useWagmiConfig } from "@b3dotfun/sdk/global-account/react/hooks/useWagmiConfig";
7
+ import { createWagmiConfig } from "@b3dotfun/sdk/global-account/react/utils/createWagmiConfig";
8
8
  import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
9
9
  import { loadGA4Script } from "@b3dotfun/sdk/global-account/utils/analytics";
10
10
  import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
@@ -20,7 +20,7 @@ import {
20
20
  useSetActiveWallet,
21
21
  } from "thirdweb/react";
22
22
  import { Account, Wallet } from "thirdweb/wallets";
23
- import { WagmiProvider } from "wagmi";
23
+ import { CreateConnectorFn, WagmiProvider } from "wagmi";
24
24
  import { ClientType, setClientType } from "../../../client-manager";
25
25
  import { StyleRoot } from "../StyleRoot";
26
26
  import { LocalSDKProvider } from "./LocalSDKProvider";
@@ -56,6 +56,8 @@ export function B3Provider({
56
56
  rpcUrls,
57
57
  partnerId,
58
58
  onConnect,
59
+ connectors,
60
+ overrideDefaultConnectors = false,
59
61
  }: {
60
62
  theme: "light" | "dark";
61
63
  children: React.ReactNode;
@@ -71,6 +73,8 @@ export function B3Provider({
71
73
  rpcUrls?: Record<number, string>;
72
74
  partnerId: string;
73
75
  onConnect?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
76
+ connectors?: CreateConnectorFn[];
77
+ overrideDefaultConnectors?: boolean;
74
78
  }) {
75
79
  // Initialize Google Analytics on mount
76
80
  useEffect(() => {
@@ -81,7 +85,7 @@ export function B3Provider({
81
85
  useEffect(() => {
82
86
  setClientType(clientType);
83
87
  }, [clientType]);
84
- const wagmiConfig = useWagmiConfig(partnerId, rpcUrls);
88
+ const wagmiConfig = createWagmiConfig({ partnerId, rpcUrls, connectors, overrideDefaultConnectors });
85
89
 
86
90
  return (
87
91
  <ThirdwebProvider>
@@ -1,3 +1,4 @@
1
+ export { createWagmiConfig, type CreateWagmiConfigOptions } from "../utils/createWagmiConfig";
1
2
  export { useAccountAssets } from "./useAccountAssets";
2
3
  export { useAccountWallet } from "./useAccountWallet";
3
4
  export { useAddTWSessionKey } from "./useAddTWSessionKey";
@@ -18,9 +18,9 @@ import { Wallet, ecosystemWallet } from "thirdweb/wallets";
18
18
  import { preAuthenticate } from "thirdweb/wallets/in-app";
19
19
  import { useAccount, useConnect, useSwitchAccount } from "wagmi";
20
20
  import { LocalSDKContext } from "../components/B3Provider/LocalSDKProvider";
21
+ import { createWagmiConfig } from "../utils/createWagmiConfig";
21
22
  import { useTWAuth } from "./useTWAuth";
22
23
  import { useUserQuery } from "./useUserQuery";
23
- import { useWagmiConfig } from "./useWagmiConfig";
24
24
 
25
25
  const debug = debugB3React("useAuthentication");
26
26
 
@@ -42,7 +42,7 @@ export function useAuthentication(partnerId: string) {
42
42
  const { authenticate } = useTWAuth();
43
43
  const { user, setUser } = useUserQuery();
44
44
  const useAutoConnectLoadingPrevious = useRef(false);
45
- const wagmiConfig = useWagmiConfig(partnerId);
45
+ const wagmiConfig = createWagmiConfig({ partnerId });
46
46
  const { connect } = useConnect();
47
47
  const activeWagmiAccount = useAccount();
48
48
  const { switchAccount } = useSwitchAccount();
@@ -330,6 +330,8 @@ export interface AnySpendDepositHypeProps extends BaseModalProps {
330
330
  onSuccess?: (amount?: string) => void;
331
331
  /** Custom USD input values for quick amount buttons in fiat onramp */
332
332
  customUsdInputValues?: string[];
333
+ /** prefer eoa wallet */
334
+ preferEoa?: boolean;
333
335
  }
334
336
 
335
337
  export interface AvatarEditorModalProps extends BaseModalProps {
@@ -0,0 +1,40 @@
1
+ import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
2
+ import { supportedChains } from "@b3dotfun/sdk/shared/constants/chains/supported";
3
+ import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
4
+ import { inAppWalletConnector } from "@thirdweb-dev/wagmi-adapter";
5
+ import { http } from "viem";
6
+ import { createConfig, type CreateConnectorFn } from "wagmi";
7
+
8
+ export interface CreateWagmiConfigOptions {
9
+ partnerId: string;
10
+ rpcUrls?: Record<number, string>;
11
+ connectors?: CreateConnectorFn[];
12
+ overrideDefaultConnectors?: boolean;
13
+ }
14
+
15
+ /**
16
+ * Creates a wagmi config with optional custom RPC URLs and connectors
17
+ * @param options.partnerId - Partner ID for the ecosystem wallet
18
+ * @param options.rpcUrls - Optional mapping of chain IDs to RPC URLs
19
+ * @param options.connectors - Additional connectors to include
20
+ * @param options.overrideDefaultConnectors - If true, only use provided connectors (ignores defaults)
21
+ */
22
+ export function createWagmiConfig(options: CreateWagmiConfigOptions) {
23
+ const { partnerId, rpcUrls, connectors = [], overrideDefaultConnectors = false } = options;
24
+
25
+ const defaultConnectors = [
26
+ inAppWalletConnector({
27
+ ecosystemId: ecosystemWalletId,
28
+ partnerId,
29
+ client,
30
+ }),
31
+ ];
32
+
33
+ const finalConnectors = overrideDefaultConnectors ? connectors : [...defaultConnectors, ...connectors];
34
+
35
+ return createConfig({
36
+ chains: [supportedChains[0], ...supportedChains.slice(1)],
37
+ transports: Object.fromEntries(supportedChains.map(chain => [chain.id, http(rpcUrls?.[chain.id])])),
38
+ connectors: finalConnectors,
39
+ });
40
+ }