@b3dotfun/sdk 0.1.69-alpha.11 → 0.1.69-alpha.13

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 (59) hide show
  1. package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckout.d.ts +3 -1
  2. package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckout.js +5 -1
  3. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +4 -1
  4. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +8 -12
  5. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +6 -9
  6. package/dist/cjs/global-account/react/utils/createWagmiConfig.d.ts +4 -13
  7. package/dist/cjs/global-account/react/utils/createWagmiConfig.js +5 -7
  8. package/dist/cjs/wallet/react/components/ConnectWallet.d.ts +11 -0
  9. package/dist/cjs/wallet/react/components/ConnectWallet.js +467 -0
  10. package/dist/cjs/wallet/react/components/WalletProvider.d.ts +35 -0
  11. package/dist/cjs/wallet/react/components/WalletProvider.js +20 -0
  12. package/dist/cjs/wallet/react/hooks/useWalletDisconnect.d.ts +13 -0
  13. package/dist/cjs/wallet/react/hooks/useWalletDisconnect.js +22 -0
  14. package/dist/cjs/wallet/react/hooks/useWalletState.d.ts +31 -0
  15. package/dist/cjs/wallet/react/hooks/useWalletState.js +63 -0
  16. package/dist/cjs/wallet/react/index.d.ts +5 -0
  17. package/dist/cjs/wallet/react/index.js +16 -0
  18. package/dist/cjs/wallet/utils/createWalletConfig.d.ts +21 -0
  19. package/dist/cjs/wallet/utils/createWalletConfig.js +24 -0
  20. package/dist/esm/anyspend/react/components/checkout/AnySpendCheckout.d.ts +3 -1
  21. package/dist/esm/anyspend/react/components/checkout/AnySpendCheckout.js +5 -1
  22. package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +4 -1
  23. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +3 -7
  24. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +2 -5
  25. package/dist/esm/global-account/react/utils/createWagmiConfig.d.ts +4 -13
  26. package/dist/esm/global-account/react/utils/createWagmiConfig.js +5 -7
  27. package/dist/esm/wallet/react/components/ConnectWallet.d.ts +11 -0
  28. package/dist/esm/wallet/react/components/ConnectWallet.js +431 -0
  29. package/dist/esm/wallet/react/components/WalletProvider.d.ts +35 -0
  30. package/dist/esm/wallet/react/components/WalletProvider.js +17 -0
  31. package/dist/esm/wallet/react/hooks/useWalletDisconnect.d.ts +13 -0
  32. package/dist/esm/wallet/react/hooks/useWalletDisconnect.js +19 -0
  33. package/dist/esm/wallet/react/hooks/useWalletState.d.ts +31 -0
  34. package/dist/esm/wallet/react/hooks/useWalletState.js +60 -0
  35. package/dist/esm/wallet/react/index.d.ts +5 -0
  36. package/dist/esm/wallet/react/index.js +8 -0
  37. package/dist/esm/wallet/utils/createWalletConfig.d.ts +21 -0
  38. package/dist/esm/wallet/utils/createWalletConfig.js +21 -0
  39. package/dist/types/anyspend/react/components/checkout/AnySpendCheckout.d.ts +3 -1
  40. package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +4 -1
  41. package/dist/types/global-account/react/utils/createWagmiConfig.d.ts +4 -13
  42. package/dist/types/wallet/react/components/ConnectWallet.d.ts +11 -0
  43. package/dist/types/wallet/react/components/WalletProvider.d.ts +35 -0
  44. package/dist/types/wallet/react/hooks/useWalletDisconnect.d.ts +13 -0
  45. package/dist/types/wallet/react/hooks/useWalletState.d.ts +31 -0
  46. package/dist/types/wallet/react/index.d.ts +5 -0
  47. package/dist/types/wallet/utils/createWalletConfig.d.ts +21 -0
  48. package/package.json +12 -1
  49. package/src/anyspend/react/components/checkout/AnySpendCheckout.tsx +6 -0
  50. package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +14 -20
  51. package/src/global-account/react/components/B3Provider/B3Provider.tsx +41 -45
  52. package/src/global-account/react/utils/createWagmiConfig.tsx +6 -7
  53. package/src/wallet/__tests__/createWalletConfig.test.ts +39 -0
  54. package/src/wallet/react/components/ConnectWallet.tsx +665 -0
  55. package/src/wallet/react/components/WalletProvider.tsx +64 -0
  56. package/src/wallet/react/hooks/useWalletDisconnect.ts +22 -0
  57. package/src/wallet/react/hooks/useWalletState.ts +93 -0
  58. package/src/wallet/react/index.ts +10 -0
  59. package/src/wallet/utils/createWalletConfig.ts +39 -0
@@ -0,0 +1,21 @@
1
+ import { supportedChains } from "../../shared/constants/chains/supported.js";
2
+ import { http } from "viem";
3
+ import { createConfig } from "wagmi";
4
+ import { coinbaseWallet, injected } from "wagmi/connectors";
5
+ /** Default connectors: injected (MetaMask, Rabby, Brave, etc.) + Coinbase Wallet. */
6
+ const DEFAULT_CONNECTORS = [injected(), coinbaseWallet({ appName: "B3" })];
7
+ /**
8
+ * Creates a generic wagmi config with sensible defaults.
9
+ * No ecosystem wallet, no B3-specific concerns.
10
+ */
11
+ export function createWalletConfig(options = {}) {
12
+ const { chains = supportedChains, connectors = DEFAULT_CONNECTORS, rpcUrls } = options;
13
+ if (chains.length === 0) {
14
+ throw new Error("createWalletConfig: at least one chain must be provided");
15
+ }
16
+ return createConfig({
17
+ chains: [chains[0], ...chains.slice(1)],
18
+ transports: Object.fromEntries(chains.map(chain => [chain.id, http(rpcUrls?.[chain.id])])),
19
+ connectors,
20
+ });
21
+ }
@@ -121,5 +121,7 @@ export interface AnySpendCheckoutProps {
121
121
  feeOnTop?: boolean;
122
122
  /** When true, identity verification (KYC) is required before card payment. Defaults to false. */
123
123
  kycEnabled?: boolean;
124
+ /** Extra metadata included under the 'callbackMetadata' key in the order's callbackMetadata (e.g. workflowId, orgId from checkout session) */
125
+ callbackMetadata?: Record<string, unknown>;
124
126
  }
125
- export declare function AnySpendCheckout({ mode, recipientAddress, destinationTokenAddress, destinationTokenChainId, items, totalAmount: totalAmountOverride, organizationName, organizationLogo, themeColor, buttonText, checkoutSessionId, onSuccess, onError, returnUrl, returnLabel, classes, footer, defaultPaymentMethod, senderAddress, slots, content, theme, showPoints, showOrderId, shipping: shippingProp, tax, discount: discountProp, summaryLines, formSchema, formComponent, onFormSubmit, shippingOptions, collectShippingAddress, onShippingChange: onShippingChangeProp, enableDiscountCode, onDiscountApplied: onDiscountAppliedProp, validateDiscount, variablePricing, feeOnTop, kycEnabled, }: AnySpendCheckoutProps): import("react/jsx-runtime").JSX.Element;
127
+ export declare function AnySpendCheckout({ mode, recipientAddress, destinationTokenAddress, destinationTokenChainId, items, totalAmount: totalAmountOverride, organizationName, organizationLogo, themeColor, buttonText, checkoutSessionId, onSuccess, onError, returnUrl, returnLabel, classes, footer, defaultPaymentMethod, senderAddress, slots, content, theme, showPoints, showOrderId, shipping: shippingProp, tax, discount: discountProp, summaryLines, formSchema, formComponent, onFormSubmit, shippingOptions, collectShippingAddress, onShippingChange: onShippingChangeProp, enableDiscountCode, onDiscountApplied: onDiscountAppliedProp, validateDiscount, variablePricing, feeOnTop, kycEnabled, callbackMetadata: callbackMetadataProp, }: AnySpendCheckoutProps): import("react/jsx-runtime").JSX.Element;
@@ -2,13 +2,14 @@ import { CreateOnrampOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useA
2
2
  import { CreateOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOrder";
3
3
  import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
4
4
  import "@relayprotocol/relay-kit-ui/styles.css";
5
+ import { QueryClient } from "@tanstack/react-query";
5
6
  import { Account, EIP1193, Wallet } from "thirdweb/wallets";
6
7
  import { CreateConnectorFn } from "wagmi";
7
8
  import { ClientType } from "../../../client-manager";
8
9
  /**
9
10
  * Main B3Provider component
10
11
  */
11
- export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, defaultEoaProvider, simDuneApiKey, toaster: _toaster, clientType, rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors, createClientReferenceId, defaultPermissions, disableBSMNTAuthentication, }: {
12
+ export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, defaultEoaProvider, simDuneApiKey, toaster: _toaster, clientType, rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors, createClientReferenceId, defaultPermissions, disableBSMNTAuthentication, queryClient, }: {
12
13
  theme: "light" | "dark";
13
14
  children: React.ReactNode;
14
15
  accountOverride?: Account;
@@ -33,4 +34,6 @@ export declare function B3Provider({ theme, children, accountOverride, environme
33
34
  createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
34
35
  defaultPermissions?: PermissionsConfig;
35
36
  disableBSMNTAuthentication?: boolean;
37
+ /** Provide your own QueryClient for React Query. If omitted, WalletProvider creates one internally. */
38
+ queryClient?: QueryClient;
36
39
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,4 @@
1
- import { type CreateConnectorFn } from "wagmi";
1
+ import type { CreateConnectorFn } from "wagmi";
2
2
  export interface CreateWagmiConfigOptions {
3
3
  partnerId: string;
4
4
  rpcUrls?: Record<number, string>;
@@ -6,7 +6,8 @@ export interface CreateWagmiConfigOptions {
6
6
  overrideDefaultConnectors?: boolean;
7
7
  }
8
8
  /**
9
- * Creates a wagmi config with optional custom RPC URLs and connectors
9
+ * Creates a wagmi config with the B3 ecosystem wallet connector.
10
+ * Delegates to createWalletConfig and adds the ecosystem connector on top.
10
11
  * @param options.partnerId - Partner ID for the ecosystem wallet
11
12
  * @param options.rpcUrls - Optional mapping of chain IDs to RPC URLs
12
13
  * @param options.connectors - Additional connectors to include
@@ -14,14 +15,4 @@ export interface CreateWagmiConfigOptions {
14
15
  */
15
16
  export declare function createWagmiConfig(options: CreateWagmiConfigOptions): import("wagmi").Config<readonly [import("viem").Chain, ...import("viem").Chain[]], {
16
17
  [k: string]: import("viem").HttpTransport<undefined, false>;
17
- }, (CreateConnectorFn | CreateConnectorFn<import("thirdweb/dist/types/adapters/eip1193").EIP1193Provider | undefined, {
18
- connect<withCapabilities extends boolean = false>(parameters?: import("@thirdweb-dev/wagmi-adapter").ConnectionOptions<withCapabilities> | undefined): Promise<{
19
- accounts: withCapabilities extends true ? readonly {
20
- address: `0x${string}`;
21
- capabilities: Record<string, unknown>;
22
- }[] : readonly `0x${string}`[];
23
- chainId: number;
24
- }>;
25
- }, {
26
- "thirdweb:lastChainId": number;
27
- }>)[]>;
18
+ }, CreateConnectorFn[]>;
@@ -0,0 +1,11 @@
1
+ export interface ConnectWalletProps {
2
+ /** Theme for the modal and button. Defaults to "light". */
3
+ theme?: "light" | "dark";
4
+ /** Label for the connect button. Defaults to "Connect Wallet". */
5
+ buttonLabel?: string;
6
+ }
7
+ /**
8
+ * Drop-in wallet connection component styled to match the B3 design system.
9
+ * Uses inline styles — works in any app without tailwind configuration.
10
+ */
11
+ export declare function ConnectWallet({ theme: themeProp, buttonLabel }: ConnectWalletProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,35 @@
1
+ import { QueryClient } from "@tanstack/react-query";
2
+ import { type Config, type CreateConnectorFn } from "wagmi";
3
+ import type { Chain } from "viem";
4
+ export interface WalletProviderProps {
5
+ children: React.ReactNode;
6
+ /**
7
+ * Chains to support. Defaults to SDK's supportedChains.
8
+ * Must be memoized or defined outside the component — inline arrays cause the
9
+ * wagmi config to rebuild on every render, losing wallet connection state.
10
+ */
11
+ chains?: Chain[];
12
+ /**
13
+ * Wagmi connectors. Must be memoized or defined outside the component — inline
14
+ * arrays cause the wagmi config to rebuild on every render, losing wallet connection state.
15
+ */
16
+ connectors?: CreateConnectorFn[];
17
+ /**
18
+ * Optional RPC URL overrides per chain ID.
19
+ * Must be memoized or defined outside the component — inline objects cause the
20
+ * wagmi config to rebuild on every render, losing wallet connection state.
21
+ */
22
+ rpcUrls?: Record<number, string>;
23
+ /** Escape hatch: pass a fully custom wagmi config. Overrides chains/connectors/rpcUrls. */
24
+ wagmiConfig?: Config;
25
+ /** Provide your own QueryClient for React Query. Defaults to an internal instance. */
26
+ queryClient?: QueryClient;
27
+ /** Whether to auto-reconnect the last wallet on mount. Defaults to false. */
28
+ reconnectOnMount?: boolean;
29
+ }
30
+ /**
31
+ * Standalone wallet connection provider.
32
+ * Wraps ThirdwebProvider, WagmiProvider, and QueryClientProvider.
33
+ * Use wagmi hooks (useAccount, useConnect, useDisconnect) directly inside.
34
+ */
35
+ export declare function WalletProvider({ children, chains, connectors, rpcUrls, wagmiConfig: wagmiConfigProp, queryClient: queryClientProp, reconnectOnMount, }: WalletProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Disconnect the current wallet via wagmi.
3
+ * Consumers should use this instead of wagmi's useDisconnect directly
4
+ * to ensure a consistent disconnect API across the wallet module.
5
+ *
6
+ * Note: this only disconnects the wagmi layer. When used inside B3Provider,
7
+ * the thirdweb auth session is managed separately by B3Provider's own logout
8
+ * flow (useAuthentication). ConnectWallet is intended for standalone
9
+ * WalletProvider usage where thirdweb auth is not involved.
10
+ */
11
+ export declare function useWalletDisconnect(): {
12
+ disconnect: () => void;
13
+ };
@@ -0,0 +1,31 @@
1
+ import type { Chain } from "viem";
2
+ import type { Connector } from "wagmi";
3
+ export interface WalletConnector {
4
+ /** Display name of the wallet */
5
+ name: string;
6
+ /** Unique identifier for this connector instance */
7
+ uid: string;
8
+ /** Whether the wallet extension/app is detected in the browser */
9
+ isInstalled: boolean;
10
+ /** Connect using this connector. Returns a promise that resolves on success or rejects on failure/rejection. */
11
+ connect: () => Promise<void>;
12
+ /** Raw wagmi connector for advanced use */
13
+ connector: Connector;
14
+ }
15
+ export interface WalletState {
16
+ /** Connected wallet address, or undefined if not connected */
17
+ address: string | undefined;
18
+ /** Whether a wallet is currently connected */
19
+ isConnected: boolean;
20
+ /** Current chain the wallet is connected to */
21
+ chain: Chain | undefined;
22
+ /** Whether a connection attempt is in progress */
23
+ isPending: boolean;
24
+ /** Available wallet connectors, deduplicated by name */
25
+ connectors: WalletConnector[];
26
+ }
27
+ /**
28
+ * Unified wallet state from both thirdweb and wagmi layers.
29
+ * Provides available connectors with install status and connect functions.
30
+ */
31
+ export declare function useWalletState(): WalletState;
@@ -0,0 +1,5 @@
1
+ export { WalletProvider, type WalletProviderProps } from "./components/WalletProvider";
2
+ export { createWalletConfig, type CreateWalletConfigOptions } from "../utils/createWalletConfig";
3
+ export { useWalletDisconnect } from "./hooks/useWalletDisconnect";
4
+ export { useWalletState, type WalletConnector, type WalletState } from "./hooks/useWalletState";
5
+ export { ConnectWallet, type ConnectWalletProps } from "./components/ConnectWallet";
@@ -0,0 +1,21 @@
1
+ import { type CreateConnectorFn } from "wagmi";
2
+ import type { Chain } from "viem";
3
+ export interface CreateWalletConfigOptions {
4
+ /** Chains to support. Defaults to SDK's supportedChains. Must be non-empty. */
5
+ chains?: Chain[];
6
+ /**
7
+ * Wagmi connectors. Defaults to injected + Coinbase Wallet.
8
+ * Must be memoized if passed to WalletProvider — inline arrays
9
+ * will cause the config to rebuild on every render, losing wallet connection state.
10
+ */
11
+ connectors?: CreateConnectorFn[];
12
+ /** Optional RPC URL overrides per chain ID. */
13
+ rpcUrls?: Record<number, string>;
14
+ }
15
+ /**
16
+ * Creates a generic wagmi config with sensible defaults.
17
+ * No ecosystem wallet, no B3-specific concerns.
18
+ */
19
+ export declare function createWalletConfig(options?: CreateWalletConfigOptions): import("wagmi").Config<readonly [Chain, ...Chain[]], {
20
+ [k: string]: import("viem").HttpTransport<undefined, false>;
21
+ }, CreateConnectorFn[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b3dotfun/sdk",
3
- "version": "0.1.69-alpha.11",
3
+ "version": "0.1.69-alpha.13",
4
4
  "source": "src/index.ts",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "react-native": "./dist/cjs/index.native.js",
@@ -205,6 +205,16 @@
205
205
  "import": "./dist/esm/notifications/types/index.js",
206
206
  "require": "./dist/cjs/notifications/types/index.js"
207
207
  },
208
+ "./wallet/react": {
209
+ "types": "./dist/types/wallet/react/index.d.ts",
210
+ "import": "./dist/esm/wallet/react/index.js",
211
+ "require": "./dist/cjs/wallet/react/index.js"
212
+ },
213
+ "./wallet/utils/*": {
214
+ "types": "./dist/types/wallet/utils/*.d.ts",
215
+ "import": "./dist/esm/wallet/utils/*.js",
216
+ "require": "./dist/cjs/wallet/utils/*.js"
217
+ },
208
218
  "./shared/utils": {
209
219
  "types": "./dist/types/shared/utils/index.d.ts",
210
220
  "import": "./dist/esm/shared/utils/index.js",
@@ -375,6 +385,7 @@
375
385
  "thirdweb": "5.116.1",
376
386
  "tsc-alias": "^1.8.16",
377
387
  "tsc-watch": "^7.1.1",
388
+ "vite-tsconfig-paths": "^6.1.1",
378
389
  "vitest": "^3.2.4"
379
390
  },
380
391
  "typesVersions": {
@@ -138,6 +138,8 @@ export interface AnySpendCheckoutProps {
138
138
  feeOnTop?: boolean;
139
139
  /** When true, identity verification (KYC) is required before card payment. Defaults to false. */
140
140
  kycEnabled?: boolean;
141
+ /** Extra metadata included under the 'callbackMetadata' key in the order's callbackMetadata (e.g. workflowId, orgId from checkout session) */
142
+ callbackMetadata?: Record<string, unknown>;
141
143
  }
142
144
 
143
145
  const emptyAddress: AddressData = { street: "", city: "", state: "", zip: "", country: "" };
@@ -187,6 +189,7 @@ export function AnySpendCheckout({
187
189
  variablePricing,
188
190
  feeOnTop,
189
191
  kycEnabled = false,
192
+ callbackMetadata: callbackMetadataProp,
190
193
  }: AnySpendCheckoutProps) {
191
194
  // ===== Variable pricing state =====
192
195
  const [variablePricingAmount, setVariablePricingAmount] = useState<string>("0");
@@ -342,8 +345,11 @@ export function AnySpendCheckout({
342
345
  if (isVariablePricingActive && variablePricingAmount !== "0") {
343
346
  meta.variablePricingAmount = variablePricingAmount;
344
347
  }
348
+ // Namespace caller-supplied metadata to avoid collisions with internal keys
349
+ if (callbackMetadataProp) meta.callbackMetadata = callbackMetadataProp;
345
350
  return Object.keys(meta).length > 0 ? meta : undefined;
346
351
  }, [
352
+ callbackMetadataProp,
347
353
  formData,
348
354
  selectedShipping,
349
355
  shippingAddress,
@@ -1,20 +1,16 @@
1
1
  import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
2
- import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
2
+ import { WalletProvider } from "@b3dotfun/sdk/wallet/react";
3
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 { useMemo } from "react";
9
- import { WagmiProvider } from "wagmi";
10
9
  import { createWagmiConfig } from "../../utils/createWagmiConfig";
11
10
  import AuthenticationProvider from "./AuthenticationProvider";
12
11
  import { B3ConfigProvider } from "./B3ConfigProvider";
13
12
  import { LocalSDKProvider } from "./LocalSDKProvider";
14
13
 
15
- // Create queryClient instance
16
- const queryClient = new QueryClient();
17
-
18
14
  /**
19
15
  * Main B3Provider component
20
16
  */
@@ -86,20 +82,18 @@ export function InnerProvider({
86
82
  const wagmiConfig = useMemo(() => createWagmiConfig({ partnerId, rpcUrls }), [partnerId, rpcUrls]);
87
83
 
88
84
  return (
89
- <WagmiProvider config={wagmiConfig}>
90
- <QueryClientProvider client={queryClient}>
91
- <B3ConfigProvider
92
- accountOverride={accountOverride}
93
- environment={environment}
94
- automaticallySetFirstEoa={false}
95
- theme={theme}
96
- clientType={clientType}
97
- partnerId={partnerId}
98
- defaultPermissions={defaultPermissions}
99
- >
100
- {children}
101
- </B3ConfigProvider>
102
- </QueryClientProvider>
103
- </WagmiProvider>
85
+ <WalletProvider wagmiConfig={wagmiConfig}>
86
+ <B3ConfigProvider
87
+ accountOverride={accountOverride}
88
+ environment={environment}
89
+ automaticallySetFirstEoa={false}
90
+ theme={theme}
91
+ clientType={clientType}
92
+ partnerId={partnerId}
93
+ defaultPermissions={defaultPermissions}
94
+ >
95
+ {children}
96
+ </B3ConfigProvider>
97
+ </WalletProvider>
104
98
  );
105
99
  }
@@ -4,12 +4,12 @@ import { RelayKitProviderWrapper, TooltipProvider } from "@b3dotfun/sdk/global-a
4
4
  import { createWagmiConfig } from "@b3dotfun/sdk/global-account/react/utils/createWagmiConfig";
5
5
  import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
6
6
  import { loadGA4Script } from "@b3dotfun/sdk/global-account/utils/analytics";
7
+ import { WalletProvider } from "@b3dotfun/sdk/wallet/react";
7
8
  import "@relayprotocol/relay-kit-ui/styles.css";
8
- import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
9
+ import { QueryClient } from "@tanstack/react-query";
9
10
  import { useEffect, useMemo } from "react";
10
- import { ThirdwebProvider } from "thirdweb/react";
11
11
  import { Account, EIP1193, Wallet } from "thirdweb/wallets";
12
- import { CreateConnectorFn, WagmiProvider } from "wagmi";
12
+ import { CreateConnectorFn } from "wagmi";
13
13
  import { ClientType, setClientType } from "../../../client-manager";
14
14
  import { StyleRoot } from "../StyleRoot";
15
15
  import { setToastContext, ToastProvider, useToastContext } from "../Toast/index";
@@ -17,9 +17,6 @@ import AuthenticationProvider from "./AuthenticationProvider";
17
17
  import { B3ConfigProvider } from "./B3ConfigProvider";
18
18
  import { LocalSDKProvider } from "./LocalSDKProvider";
19
19
 
20
- // Create queryClient instance
21
- const queryClient = new QueryClient();
22
-
23
20
  /**
24
21
  * Main B3Provider component
25
22
  */
@@ -44,6 +41,7 @@ export function B3Provider({
44
41
  createClientReferenceId,
45
42
  defaultPermissions,
46
43
  disableBSMNTAuthentication = false,
44
+ queryClient,
47
45
  }: {
48
46
  theme: "light" | "dark";
49
47
  children: React.ReactNode;
@@ -69,6 +67,8 @@ export function B3Provider({
69
67
  createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
70
68
  defaultPermissions?: PermissionsConfig;
71
69
  disableBSMNTAuthentication?: boolean;
70
+ /** Provide your own QueryClient for React Query. If omitted, WalletProvider creates one internally. */
71
+ queryClient?: QueryClient;
72
72
  }) {
73
73
  // Initialize Google Analytics on mount
74
74
  useEffect(() => {
@@ -86,45 +86,41 @@ export function B3Provider({
86
86
  );
87
87
 
88
88
  return (
89
- <ThirdwebProvider>
90
- <WagmiProvider config={wagmiConfig} reconnectOnMount={false}>
91
- <QueryClientProvider client={queryClient}>
92
- <TooltipProvider>
93
- <ToastProvider>
94
- <LocalSDKProvider
95
- onConnectCallback={onConnect}
96
- onLogoutCallback={onLogout}
97
- disableBSMNTAuthentication={disableBSMNTAuthentication}
98
- >
99
- <B3ConfigProvider
100
- accountOverride={accountOverride}
101
- environment={environment}
102
- automaticallySetFirstEoa={!!automaticallySetFirstEoa}
103
- theme={theme}
104
- clientType={clientType}
105
- partnerId={partnerId}
106
- stripePublishableKey={stripePublishableKey}
107
- createClientReferenceId={createClientReferenceId}
108
- defaultPermissions={defaultPermissions}
109
- >
110
- <ToastContextConnector />
111
- <RelayKitProviderWrapper simDuneApiKey={simDuneApiKey}>
112
- {children}
113
- {/* For the modal https://github.com/b3-fun/b3/blob/main/packages/sdk/src/global-account/react/components/ui/dialog.tsx#L46 */}
114
- <StyleRoot id="b3-root" />
115
- </RelayKitProviderWrapper>
116
- <AuthenticationProvider
117
- partnerId={partnerId}
118
- automaticallySetFirstEoa={!!automaticallySetFirstEoa}
119
- defaultEoaProvider={defaultEoaProvider}
120
- />
121
- </B3ConfigProvider>
122
- </LocalSDKProvider>
123
- </ToastProvider>
124
- </TooltipProvider>
125
- </QueryClientProvider>
126
- </WagmiProvider>
127
- </ThirdwebProvider>
89
+ <WalletProvider wagmiConfig={wagmiConfig} queryClient={queryClient}>
90
+ <TooltipProvider>
91
+ <ToastProvider>
92
+ <LocalSDKProvider
93
+ onConnectCallback={onConnect}
94
+ onLogoutCallback={onLogout}
95
+ disableBSMNTAuthentication={disableBSMNTAuthentication}
96
+ >
97
+ <B3ConfigProvider
98
+ accountOverride={accountOverride}
99
+ environment={environment}
100
+ automaticallySetFirstEoa={!!automaticallySetFirstEoa}
101
+ theme={theme}
102
+ clientType={clientType}
103
+ partnerId={partnerId}
104
+ stripePublishableKey={stripePublishableKey}
105
+ createClientReferenceId={createClientReferenceId}
106
+ defaultPermissions={defaultPermissions}
107
+ >
108
+ <ToastContextConnector />
109
+ <RelayKitProviderWrapper simDuneApiKey={simDuneApiKey}>
110
+ {children}
111
+ {/* For the modal https://github.com/b3-fun/b3/blob/main/packages/sdk/src/global-account/react/components/ui/dialog.tsx#L46 */}
112
+ <StyleRoot id="b3-root" />
113
+ </RelayKitProviderWrapper>
114
+ <AuthenticationProvider
115
+ partnerId={partnerId}
116
+ automaticallySetFirstEoa={!!automaticallySetFirstEoa}
117
+ defaultEoaProvider={defaultEoaProvider}
118
+ />
119
+ </B3ConfigProvider>
120
+ </LocalSDKProvider>
121
+ </ToastProvider>
122
+ </TooltipProvider>
123
+ </WalletProvider>
128
124
  );
129
125
  }
130
126
 
@@ -1,9 +1,8 @@
1
+ import { createWalletConfig } from "@b3dotfun/sdk/wallet/utils/createWalletConfig";
1
2
  import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
2
- import { supportedChains } from "@b3dotfun/sdk/shared/constants/chains/supported";
3
3
  import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
4
4
  import { inAppWalletConnector } from "@thirdweb-dev/wagmi-adapter";
5
- import { http } from "viem";
6
- import { createConfig, type CreateConnectorFn } from "wagmi";
5
+ import type { CreateConnectorFn } from "wagmi";
7
6
 
8
7
  export interface CreateWagmiConfigOptions {
9
8
  partnerId: string;
@@ -13,7 +12,8 @@ export interface CreateWagmiConfigOptions {
13
12
  }
14
13
 
15
14
  /**
16
- * Creates a wagmi config with optional custom RPC URLs and connectors
15
+ * Creates a wagmi config with the B3 ecosystem wallet connector.
16
+ * Delegates to createWalletConfig and adds the ecosystem connector on top.
17
17
  * @param options.partnerId - Partner ID for the ecosystem wallet
18
18
  * @param options.rpcUrls - Optional mapping of chain IDs to RPC URLs
19
19
  * @param options.connectors - Additional connectors to include
@@ -32,9 +32,8 @@ export function createWagmiConfig(options: CreateWagmiConfigOptions) {
32
32
 
33
33
  const finalConnectors = overrideDefaultConnectors ? connectors : [...defaultConnectors, ...connectors];
34
34
 
35
- return createConfig({
36
- chains: [supportedChains[0], ...supportedChains.slice(1)],
37
- transports: Object.fromEntries(supportedChains.map(chain => [chain.id, http(rpcUrls?.[chain.id])])),
35
+ return createWalletConfig({
38
36
  connectors: finalConnectors,
37
+ rpcUrls,
39
38
  });
40
39
  }
@@ -0,0 +1,39 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { createWalletConfig } from "../utils/createWalletConfig";
3
+ import { base, optimism } from "viem/chains";
4
+
5
+ describe("createWalletConfig", () => {
6
+ it("should create a config with default chains when no options provided", () => {
7
+ const config = createWalletConfig();
8
+ // Should not throw — uses supportedChains as default
9
+ expect(config).toBeDefined();
10
+ expect(config.chains).toBeDefined();
11
+ expect(config.chains.length).toBeGreaterThan(0);
12
+ });
13
+
14
+ it("should create a config with custom chains", () => {
15
+ const config = createWalletConfig({ chains: [base, optimism] });
16
+ expect(config.chains).toHaveLength(2);
17
+ expect(config.chains[0].id).toBe(base.id);
18
+ expect(config.chains[1].id).toBe(optimism.id);
19
+ });
20
+
21
+ it("should throw if chains array is empty", () => {
22
+ expect(() => createWalletConfig({ chains: [] })).toThrow("createWalletConfig: at least one chain must be provided");
23
+ });
24
+
25
+ it("should accept custom RPC URLs", () => {
26
+ const config = createWalletConfig({
27
+ chains: [base],
28
+ rpcUrls: { [base.id]: "https://custom-rpc.example.com" },
29
+ });
30
+ expect(config).toBeDefined();
31
+ // Config is created without error; transport internals are opaque
32
+ });
33
+
34
+ it("should accept connectors", () => {
35
+ // Pass an empty array (valid) — connector instantiation requires browser env
36
+ const config = createWalletConfig({ chains: [base], connectors: [] });
37
+ expect(config).toBeDefined();
38
+ });
39
+ });