@b3dotfun/sdk 0.0.90-test.1 → 0.1.0-alpha.1

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 (52) hide show
  1. package/dist/cjs/anyspend/constants/rpc.d.ts +22 -0
  2. package/dist/cjs/anyspend/constants/rpc.js +38 -0
  3. package/dist/cjs/anyspend/utils/chain.d.ts +23 -0
  4. package/dist/cjs/anyspend/utils/chain.js +56 -12
  5. package/dist/cjs/global-account/react/components/B3Provider/B3ConfigProvider.d.ts +31 -0
  6. package/dist/cjs/global-account/react/components/B3Provider/B3ConfigProvider.js +37 -0
  7. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +2 -19
  8. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +4 -31
  9. package/dist/cjs/global-account/react/components/B3Provider/useB3.d.ts +1 -12
  10. package/dist/cjs/global-account/react/components/B3Provider/useB3Config.d.ts +1 -17
  11. package/dist/cjs/global-account/react/components/B3Provider/useB3Config.js +2 -21
  12. package/dist/cjs/global-account/react/hooks/useFirstEOA.d.ts +2 -2
  13. package/dist/cjs/global-account/react/hooks/useTokenBalancesByChain.js +3 -0
  14. package/dist/cjs/global-account/react/stores/index.d.ts +0 -1
  15. package/dist/cjs/global-account/react/stores/index.js +1 -3
  16. package/dist/esm/anyspend/constants/rpc.d.ts +22 -0
  17. package/dist/esm/anyspend/constants/rpc.js +35 -0
  18. package/dist/esm/anyspend/utils/chain.d.ts +23 -0
  19. package/dist/esm/anyspend/utils/chain.js +53 -12
  20. package/dist/esm/global-account/react/components/B3Provider/B3ConfigProvider.d.ts +31 -0
  21. package/dist/esm/global-account/react/components/B3Provider/B3ConfigProvider.js +33 -0
  22. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +2 -19
  23. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +3 -30
  24. package/dist/esm/global-account/react/components/B3Provider/useB3.d.ts +1 -12
  25. package/dist/esm/global-account/react/components/B3Provider/useB3Config.d.ts +1 -17
  26. package/dist/esm/global-account/react/components/B3Provider/useB3Config.js +1 -20
  27. package/dist/esm/global-account/react/hooks/useFirstEOA.d.ts +2 -2
  28. package/dist/esm/global-account/react/hooks/useTokenBalancesByChain.js +3 -0
  29. package/dist/esm/global-account/react/stores/index.d.ts +0 -1
  30. package/dist/esm/global-account/react/stores/index.js +0 -1
  31. package/dist/types/anyspend/constants/rpc.d.ts +22 -0
  32. package/dist/types/anyspend/utils/chain.d.ts +23 -0
  33. package/dist/types/global-account/react/components/B3Provider/B3ConfigProvider.d.ts +31 -0
  34. package/dist/types/global-account/react/components/B3Provider/useB3.d.ts +1 -12
  35. package/dist/types/global-account/react/components/B3Provider/useB3Config.d.ts +1 -17
  36. package/dist/types/global-account/react/hooks/useFirstEOA.d.ts +2 -2
  37. package/dist/types/global-account/react/stores/index.d.ts +0 -1
  38. package/package.json +1 -1
  39. package/src/anyspend/constants/rpc.ts +38 -0
  40. package/src/anyspend/utils/chain.ts +70 -36
  41. package/src/global-account/react/components/B3Provider/B3ConfigProvider.tsx +84 -0
  42. package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +28 -36
  43. package/src/global-account/react/components/B3Provider/B3Provider.tsx +21 -27
  44. package/src/global-account/react/components/B3Provider/useB3Config.ts +1 -21
  45. package/src/global-account/react/hooks/useTokenBalancesByChain.tsx +3 -0
  46. package/src/global-account/react/stores/index.ts +0 -1
  47. package/dist/cjs/global-account/react/stores/configStore.d.ts +0 -24
  48. package/dist/cjs/global-account/react/stores/configStore.js +0 -30
  49. package/dist/esm/global-account/react/stores/configStore.d.ts +0 -24
  50. package/dist/esm/global-account/react/stores/configStore.js +0 -27
  51. package/dist/types/global-account/react/stores/configStore.d.ts +0 -24
  52. package/src/global-account/react/stores/configStore.ts +0 -51
@@ -1,6 +1,29 @@
1
1
  import { components } from "../../anyspend/types/api";
2
2
  import { Account, Chain, PublicClient, Transport, WalletClient } from "viem";
3
3
  import { ChainType, IBaseChain, IEVMChain, IHyperliquidChain, ISolanaChain } from "../types/chain";
4
+ /**
5
+ * Set custom RPC URL overrides for specific chains.
6
+ * These overrides are used by chainIdToPublicClient and chainIdToWalletClient.
7
+ *
8
+ * @param overrides - A record mapping chain IDs to custom RPC URLs
9
+ *
10
+ * @example
11
+ * // Set once at app initialization using environment variables
12
+ * setChainRpcOverrides({
13
+ * 1: process.env.ETHEREUM_RPC_URL,
14
+ * 8453: process.env.BASE_RPC_URL,
15
+ * 42161: process.env.ARBITRUM_RPC_URL,
16
+ * });
17
+ */
18
+ export declare function setChainRpcOverrides(overrides: Record<number, string>): void;
19
+ /**
20
+ * Get the current RPC URL overrides.
21
+ */
22
+ export declare function getChainRpcOverrides(): Record<number, string>;
23
+ /**
24
+ * Clear all RPC URL overrides.
25
+ */
26
+ export declare function clearChainRpcOverrides(): void;
4
27
  export declare const hyperEVM: {
5
28
  blockExplorers: {
6
29
  readonly default: {
@@ -1,4 +1,5 @@
1
1
  import { RELAY_SOLANA_MAINNET_CHAIN_ID } from "../../anyspend/constants/index.js";
2
+ import { ABSTRACT_PUBLIC_RPC, ARBITRUM_PUBLIC_RPC, AVALANCHE_PUBLIC_RPC, B3_PUBLIC_RPC, BASE_PUBLIC_RPC, BSC_PUBLIC_RPC, ETHEREUM_PUBLIC_RPC, HYPEREVM_PUBLIC_RPC, OPTIMISM_PUBLIC_RPC, POLYGON_PUBLIC_RPC, } from "../../anyspend/constants/rpc.js";
2
3
  import invariant from "invariant";
3
4
  import { createPublicClient, createWalletClient, defineChain, http, parseEther, } from "viem";
4
5
  import { abstract, arbitrum, avalanche, b3, base, bsc, mainnet, optimism, polygon } from "viem/chains";
@@ -7,11 +8,45 @@ import { getAvaxToken, getBnbToken, getEthToken, getHyperEVMNativeToken, getHype
7
8
  function getCustomEvmChain(chain, rpcUrl) {
8
9
  return defineChain({ ...chain, rpcUrls: { default: { http: [rpcUrl] } } });
9
10
  }
11
+ /**
12
+ * Global RPC URL overrides for EVM chains.
13
+ * Use setChainRpcOverrides() to configure custom RPC endpoints.
14
+ */
15
+ let chainRpcOverrides = {};
16
+ /**
17
+ * Set custom RPC URL overrides for specific chains.
18
+ * These overrides are used by chainIdToPublicClient and chainIdToWalletClient.
19
+ *
20
+ * @param overrides - A record mapping chain IDs to custom RPC URLs
21
+ *
22
+ * @example
23
+ * // Set once at app initialization using environment variables
24
+ * setChainRpcOverrides({
25
+ * 1: process.env.ETHEREUM_RPC_URL,
26
+ * 8453: process.env.BASE_RPC_URL,
27
+ * 42161: process.env.ARBITRUM_RPC_URL,
28
+ * });
29
+ */
30
+ export function setChainRpcOverrides(overrides) {
31
+ chainRpcOverrides = { ...overrides };
32
+ }
33
+ /**
34
+ * Get the current RPC URL overrides.
35
+ */
36
+ export function getChainRpcOverrides() {
37
+ return { ...chainRpcOverrides };
38
+ }
39
+ /**
40
+ * Clear all RPC URL overrides.
41
+ */
42
+ export function clearChainRpcOverrides() {
43
+ chainRpcOverrides = {};
44
+ }
10
45
  export const hyperEVM = defineChain({
11
46
  id: HYPEREVM_CHAIN_ID,
12
47
  name: "HyperEVM",
13
48
  nativeCurrency: { name: "HyperEVM", symbol: "HYPE", decimals: 18 },
14
- rpcUrls: { default: { http: ["https://rpc.hyperliquid.xyz/evm"] } },
49
+ rpcUrls: { default: { http: [HYPEREVM_PUBLIC_RPC] } },
15
50
  blockExplorers: { default: { name: "HyperEVM Explorer", url: "https://hyperevmscan.io/" } },
16
51
  });
17
52
  // export const b4testnet = defineChain({
@@ -31,7 +66,7 @@ export const EVM_MAINNET = {
31
66
  canDepositNative: true,
32
67
  defaultToken: getEthToken(mainnet.id),
33
68
  nativeToken: getEthToken(mainnet.id),
34
- viem: getCustomEvmChain(mainnet, "https://quick-chaotic-film.quiknode.pro/39a7aae6a7078f9f36c435e6f34c071c641cf863/"),
69
+ viem: getCustomEvmChain(mainnet, ETHEREUM_PUBLIC_RPC),
35
70
  pollingInterval: 4000, // 4 seconds for Ethereum mainnet
36
71
  zapperEnum: "ETHEREUM_MAINNET",
37
72
  coingeckoName: "eth",
@@ -46,7 +81,7 @@ export const EVM_MAINNET = {
46
81
  canDepositNative: true,
47
82
  defaultToken: getEthToken(arbitrum.id),
48
83
  nativeToken: getEthToken(arbitrum.id),
49
- viem: getCustomEvmChain(arbitrum, "https://proportionate-twilight-patina.arbitrum-mainnet.quiknode.pro/60e4825626515233a0f566f5915601af6043127b/"),
84
+ viem: getCustomEvmChain(arbitrum, ARBITRUM_PUBLIC_RPC),
50
85
  pollingInterval: 500, // 500ms for Arbitrum's fast blocks
51
86
  zapperEnum: "ARBITRUM_MAINNET",
52
87
  coingeckoName: "arbitrum",
@@ -61,7 +96,7 @@ export const EVM_MAINNET = {
61
96
  canDepositNative: true,
62
97
  defaultToken: getEthToken(base.id),
63
98
  nativeToken: getEthToken(base.id),
64
- viem: getCustomEvmChain(base, "https://sly-indulgent-bird.base-mainnet.quiknode.pro/4e31fab6845eb29a2764723a43896999fe962e48/"),
99
+ viem: getCustomEvmChain(base, BASE_PUBLIC_RPC),
65
100
  pollingInterval: 1000, // 1 second for Base
66
101
  zapperEnum: "BASE_MAINNET",
67
102
  coingeckoName: "base",
@@ -76,7 +111,7 @@ export const EVM_MAINNET = {
76
111
  canDepositNative: true,
77
112
  defaultToken: getEthToken(optimism.id),
78
113
  nativeToken: getEthToken(optimism.id),
79
- viem: getCustomEvmChain(optimism, "https://black-cosmopolitan-hexagon.optimism.quiknode.pro/18382925841f9d09f9e76eef954bf189aa234523/"),
114
+ viem: getCustomEvmChain(optimism, OPTIMISM_PUBLIC_RPC),
80
115
  pollingInterval: 1000, // 1 second for Optimism
81
116
  zapperEnum: "OPTIMISM_MAINNET",
82
117
  coingeckoName: "optimism",
@@ -91,7 +126,7 @@ export const EVM_MAINNET = {
91
126
  canDepositNative: true,
92
127
  defaultToken: getPolToken(),
93
128
  nativeToken: getPolToken(),
94
- viem: getCustomEvmChain(polygon, "https://purple-young-field.matic.quiknode.pro/ca54f365c1a4c7f970223eb8087e0fc579feba12/"),
129
+ viem: getCustomEvmChain(polygon, POLYGON_PUBLIC_RPC),
95
130
  pollingInterval: 1000, // 1 second for Polygon
96
131
  zapperEnum: "POLYGON_MAINNET",
97
132
  coingeckoName: "polygon_pos",
@@ -106,7 +141,7 @@ export const EVM_MAINNET = {
106
141
  canDepositNative: true,
107
142
  defaultToken: getAvaxToken(),
108
143
  nativeToken: getAvaxToken(),
109
- viem: getCustomEvmChain(avalanche, "https://avalanche-c-chain-rpc.publicnode.com"),
144
+ viem: getCustomEvmChain(avalanche, AVALANCHE_PUBLIC_RPC),
110
145
  pollingInterval: 1000, // 1 second for Avalanche
111
146
  zapperEnum: "AVALANCHE_MAINNET",
112
147
  coingeckoName: "avax",
@@ -121,7 +156,7 @@ export const EVM_MAINNET = {
121
156
  canDepositNative: true,
122
157
  defaultToken: getBnbToken(),
123
158
  nativeToken: getBnbToken(),
124
- viem: getCustomEvmChain(bsc, "https://methodical-divine-flower.bsc.quiknode.pro/9fc7efd3c34cc016cceacc27ee95850629b7cd21/"),
159
+ viem: getCustomEvmChain(bsc, BSC_PUBLIC_RPC),
125
160
  pollingInterval: 1000, // 1 second for BSC
126
161
  zapperEnum: "BSC_MAINNET",
127
162
  coingeckoName: "bsc",
@@ -136,7 +171,7 @@ export const EVM_MAINNET = {
136
171
  canDepositNative: true,
137
172
  defaultToken: getEthToken(b3.id),
138
173
  nativeToken: getEthToken(b3.id),
139
- viem: getCustomEvmChain(b3, "https://late-dimensional-yard.b3-mainnet.quiknode.pro/461dbdbd44158cd7a7a764a58ffb01a67eef77f2/"),
174
+ viem: getCustomEvmChain(b3, B3_PUBLIC_RPC),
140
175
  pollingInterval: 1000, // 1 second for B3
141
176
  zapperEnum: "B3_MAINNET",
142
177
  coingeckoName: "b3",
@@ -151,7 +186,7 @@ export const EVM_MAINNET = {
151
186
  canDepositNative: true,
152
187
  defaultToken: getEthToken(abstract.id),
153
188
  nativeToken: getEthToken(abstract.id),
154
- viem: getCustomEvmChain(abstract, "https://cosmopolitan-nameless-mountain.abstract-mainnet.quiknode.pro/863853304b986b582bdacf625ce3350397c560f8/"),
189
+ viem: getCustomEvmChain(abstract, ABSTRACT_PUBLIC_RPC),
155
190
  pollingInterval: 3000, // 3 seconds for Abstract
156
191
  zapperEnum: "ABSTRACT_MAINNET",
157
192
  coingeckoName: "abstract",
@@ -266,16 +301,22 @@ export function getChainType(chainId) {
266
301
  }
267
302
  export function chainIdToPublicClient(chainId) {
268
303
  invariant(EVM_CHAINS[chainId], `Chain ${chainId} is not an EVM chain`);
304
+ // Use override RPC if configured, otherwise use the default chain RPC
305
+ const rpcOverride = chainRpcOverrides[chainId];
306
+ const chain = rpcOverride ? getCustomEvmChain(EVM_CHAINS[chainId].viem, rpcOverride) : EVM_CHAINS[chainId].viem;
269
307
  return createPublicClient({
270
- chain: EVM_CHAINS[chainId].viem,
308
+ chain,
271
309
  transport: http(),
272
310
  pollingInterval: EVM_CHAINS[chainId].pollingInterval,
273
311
  });
274
312
  }
275
313
  export function chainIdToWalletClient(chainId, account) {
276
314
  invariant(EVM_CHAINS[chainId], `Chain ${chainId} is not an EVM chain`);
315
+ // Use override RPC if configured, otherwise use the default chain RPC
316
+ const rpcOverride = chainRpcOverrides[chainId];
317
+ const chain = rpcOverride ? getCustomEvmChain(EVM_CHAINS[chainId].viem, rpcOverride) : EVM_CHAINS[chainId].viem;
277
318
  return createWalletClient({
278
- chain: EVM_CHAINS[chainId].viem,
319
+ chain,
279
320
  transport: http(),
280
321
  account,
281
322
  pollingInterval: EVM_CHAINS[chainId].pollingInterval,
@@ -0,0 +1,31 @@
1
+ import { CreateOnrampOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOnrampOrder";
2
+ import { CreateOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOrder";
3
+ import { PermissionsConfig } from "../../../../global-account/types/permissions";
4
+ import { Account } from "thirdweb/wallets";
5
+ import { ClientType } from "../../../client-manager";
6
+ export interface B3ConfigContextType {
7
+ accountOverride?: Account;
8
+ automaticallySetFirstEoa: boolean;
9
+ environment: "development" | "production";
10
+ defaultPermissions: PermissionsConfig;
11
+ theme: "light" | "dark";
12
+ clientType: ClientType;
13
+ partnerId: string;
14
+ stripePublishableKey?: string;
15
+ createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
16
+ enableTurnkey: boolean;
17
+ }
18
+ export declare function B3ConfigProvider({ children, accountOverride, environment, defaultPermissions, automaticallySetFirstEoa, theme, clientType, partnerId, stripePublishableKey, createClientReferenceId, enableTurnkey, }: {
19
+ children: React.ReactNode;
20
+ accountOverride?: Account;
21
+ environment?: "development" | "production";
22
+ defaultPermissions?: PermissionsConfig;
23
+ automaticallySetFirstEoa?: boolean;
24
+ theme?: "light" | "dark";
25
+ clientType?: ClientType;
26
+ partnerId: string;
27
+ stripePublishableKey?: string;
28
+ createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
29
+ enableTurnkey?: boolean;
30
+ }): import("react/jsx-runtime").JSX.Element;
31
+ export declare function useB3Config(): B3ConfigContextType;
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext } from "react";
3
+ /**
4
+ * Default permissions configuration for B3 provider
5
+ */
6
+ const DEFAULT_PERMISSIONS = {
7
+ approvedTargets: ["0xa8e42121e318e3D3BeD7f5969AF6D360045317DD"],
8
+ nativeTokenLimitPerTransaction: 0.1,
9
+ startDate: new Date(),
10
+ endDate: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365), // 1 year from now
11
+ };
12
+ const B3ConfigContext = createContext(null);
13
+ export function B3ConfigProvider({ children, accountOverride, environment = "development", defaultPermissions = DEFAULT_PERMISSIONS, automaticallySetFirstEoa = false, theme = "light", clientType = "rest", partnerId, stripePublishableKey, createClientReferenceId, enableTurnkey = false, }) {
14
+ return (_jsx(B3ConfigContext.Provider, { value: {
15
+ accountOverride,
16
+ environment,
17
+ defaultPermissions,
18
+ automaticallySetFirstEoa,
19
+ theme,
20
+ clientType,
21
+ partnerId,
22
+ stripePublishableKey,
23
+ createClientReferenceId,
24
+ enableTurnkey,
25
+ }, children: children }));
26
+ }
27
+ export function useB3Config() {
28
+ const context = useContext(B3ConfigContext);
29
+ if (!context) {
30
+ throw new Error("useB3Config must be used within a B3ConfigProvider");
31
+ }
32
+ return context;
33
+ }
@@ -8,10 +8,10 @@ import { useEffect, useMemo } from "react";
8
8
  import { ThirdwebProvider } from "thirdweb/react";
9
9
  import { WagmiProvider } from "wagmi";
10
10
  import { setClientType } from "../../../client-manager.js";
11
- import { useB3ConfigStore } from "../../stores/configStore.js";
12
11
  import { StyleRoot } from "../StyleRoot.js";
13
12
  import { setToastContext, ToastProvider, useToastContext } from "../Toast/index.js";
14
13
  import AuthenticationProvider from "./AuthenticationProvider.js";
14
+ import { B3ConfigProvider } from "./B3ConfigProvider.js";
15
15
  import { LocalSDKProvider } from "./LocalSDKProvider.js";
16
16
  // Create queryClient instance
17
17
  const queryClient = new QueryClient();
@@ -21,23 +21,6 @@ const queryClient = new QueryClient();
21
21
  export function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey,
22
22
  // deprecated since v0.0.87
23
23
  toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey, onConnect, connectors, overrideDefaultConnectors = false, createClientReferenceId, enableTurnkey = false, defaultPermissions, }) {
24
- const setConfig = useB3ConfigStore(state => state.setConfig);
25
- // Initialize config store on mount
26
- useEffect(() => {
27
- setConfig({
28
- accountOverride,
29
- environment: environment ?? "development",
30
- automaticallySetFirstEoa: !!automaticallySetFirstEoa,
31
- theme,
32
- clientType,
33
- partnerId,
34
- stripePublishableKey,
35
- createClientReferenceId,
36
- enableTurnkey,
37
- defaultPermissions,
38
- });
39
- // eslint-disable-next-line react-hooks/exhaustive-deps
40
- }, []);
41
24
  // Initialize Google Analytics on mount
42
25
  useEffect(() => {
43
26
  loadGA4Script();
@@ -47,7 +30,7 @@ toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey
47
30
  setClientType(clientType);
48
31
  }, [clientType]);
49
32
  const wagmiConfig = useMemo(() => createWagmiConfig({ partnerId, rpcUrls, connectors, overrideDefaultConnectors }), [partnerId, rpcUrls, connectors, overrideDefaultConnectors]);
50
- return (_jsx(ThirdwebProvider, { children: _jsx(WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(TooltipProvider, { children: _jsx(ToastProvider, { children: _jsxs(LocalSDKProvider, { onConnectCallback: onConnect, children: [_jsx(ToastContextConnector, {}), _jsxs(RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, _jsx(StyleRoot, { id: "b3-root" })] }), _jsx(AuthenticationProvider, { partnerId: partnerId, automaticallySetFirstEoa: !!automaticallySetFirstEoa })] }) }) }) }) }) }));
33
+ return (_jsx(ThirdwebProvider, { children: _jsx(WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(TooltipProvider, { children: _jsx(ToastProvider, { children: _jsx(LocalSDKProvider, { onConnectCallback: onConnect, children: _jsxs(B3ConfigProvider, { accountOverride: accountOverride, environment: environment, automaticallySetFirstEoa: !!automaticallySetFirstEoa, theme: theme, clientType: clientType, partnerId: partnerId, stripePublishableKey: stripePublishableKey, createClientReferenceId: createClientReferenceId, enableTurnkey: enableTurnkey, defaultPermissions: defaultPermissions, children: [_jsx(ToastContextConnector, {}), _jsxs(RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, _jsx(StyleRoot, { id: "b3-root" })] }), _jsx(AuthenticationProvider, { partnerId: partnerId, automaticallySetFirstEoa: !!automaticallySetFirstEoa })] }) }) }) }) }) }) }));
51
34
  }
52
35
  /**
53
36
  * Component to connect the toast context to the global toast API
@@ -1,11 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
3
- import { useEffect } from "react";
4
3
  import { ThirdwebProvider } from "thirdweb/react";
5
4
  import { WagmiProvider } from "wagmi";
6
- import { useB3ConfigStore } from "../../stores/configStore.js";
7
5
  import { createWagmiConfig } from "../../utils/createWagmiConfig.js";
8
6
  import AuthenticationProvider from "./AuthenticationProvider.js";
7
+ import { B3ConfigProvider } from "./B3ConfigProvider.js";
9
8
  import { LocalSDKProvider } from "./LocalSDKProvider.js";
10
9
  // Create queryClient instance
11
10
  const queryClient = new QueryClient();
@@ -13,38 +12,12 @@ const queryClient = new QueryClient();
13
12
  * Main B3Provider component
14
13
  */
15
14
  export function B3Provider({ theme = "light", children, accountOverride, environment, clientType = "socket", partnerId, rpcUrls, onConnect, defaultPermissions, }) {
16
- const setConfig = useB3ConfigStore(state => state.setConfig);
17
- // Initialize config store on mount - props are static and never change
18
- useEffect(() => {
19
- setConfig({
20
- accountOverride,
21
- environment: environment ?? "development",
22
- automaticallySetFirstEoa: false,
23
- theme,
24
- clientType,
25
- partnerId,
26
- defaultPermissions,
27
- });
28
- }, []); // eslint-disable-line react-hooks/exhaustive-deps
29
- return (_jsx(ThirdwebProvider, { children: _jsxs(LocalSDKProvider, { onConnectCallback: onConnect, children: [children, _jsx(AuthenticationProvider, { partnerId: partnerId, automaticallySetFirstEoa: false })] }) }));
15
+ return (_jsx(ThirdwebProvider, { children: _jsx(LocalSDKProvider, { onConnectCallback: onConnect, children: _jsxs(B3ConfigProvider, { accountOverride: accountOverride, environment: environment, automaticallySetFirstEoa: false, theme: theme, clientType: clientType, partnerId: partnerId, defaultPermissions: defaultPermissions, children: [children, _jsx(AuthenticationProvider, { partnerId: partnerId, automaticallySetFirstEoa: false })] }) }) }));
30
16
  }
31
17
  /**
32
18
  * Inner provider component for native
33
19
  */
34
20
  export function InnerProvider({ children, accountOverride, environment, defaultPermissions, theme = "light", clientType = "socket", partnerId, rpcUrls, }) {
35
- const setConfig = useB3ConfigStore(state => state.setConfig);
36
21
  const wagmiConfig = createWagmiConfig({ partnerId, rpcUrls });
37
- // Initialize config store on mount - props are static and never change
38
- useEffect(() => {
39
- setConfig({
40
- accountOverride,
41
- environment: environment ?? "development",
42
- automaticallySetFirstEoa: false,
43
- theme,
44
- clientType,
45
- partnerId,
46
- defaultPermissions,
47
- });
48
- }, []); // eslint-disable-line react-hooks/exhaustive-deps
49
- return (_jsx(WagmiProvider, { config: wagmiConfig, children: _jsx(QueryClientProvider, { client: queryClient, children: children }) }));
22
+ return (_jsx(WagmiProvider, { config: wagmiConfig, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(B3ConfigProvider, { accountOverride: accountOverride, environment: environment, automaticallySetFirstEoa: false, theme: theme, clientType: clientType, partnerId: partnerId, defaultPermissions: defaultPermissions, children: children }) }) }));
50
23
  }
@@ -2,15 +2,4 @@
2
2
  * Hook to access the B3 configuration
3
3
  * @deprecated This is just an alias for useB3Config. Use useB3Config directly instead.
4
4
  */
5
- export declare function useB3(): {
6
- automaticallySetFirstEoa: boolean;
7
- environment: "development" | "production";
8
- theme: "light" | "dark";
9
- clientType: import("../../../client-manager").ClientType;
10
- partnerId: string;
11
- createClientReferenceId: ((params: import("../../../../anyspend/react").CreateOrderParams | import("../../../../anyspend/react").CreateOnrampOrderParams) => Promise<string>) | undefined;
12
- enableTurnkey: boolean;
13
- stripePublishableKey: string | undefined;
14
- defaultPermissions: import("../../../types/permissions").PermissionsConfig;
15
- accountOverride: import("thirdweb/wallets").Account | undefined;
16
- };
5
+ export declare function useB3(): import("./B3ConfigProvider").B3ConfigContextType;
@@ -1,17 +1 @@
1
- /**
2
- * Hook to access B3 configuration
3
- * Returns all config values from the Zustand store
4
- * Since config is static (set once at initialization), destructuring is fine here
5
- */
6
- export declare const useB3Config: () => {
7
- automaticallySetFirstEoa: boolean;
8
- environment: "development" | "production";
9
- theme: "light" | "dark";
10
- clientType: import("../../../client-manager").ClientType;
11
- partnerId: string;
12
- createClientReferenceId: ((params: import("../../../../anyspend/react").CreateOrderParams | import("../../../../anyspend/react").CreateOnrampOrderParams) => Promise<string>) | undefined;
13
- enableTurnkey: boolean;
14
- stripePublishableKey: string | undefined;
15
- defaultPermissions: import("../../../types/permissions").PermissionsConfig;
16
- accountOverride: import("thirdweb/wallets").Account | undefined;
17
- };
1
+ export { useB3Config } from "./B3ConfigProvider";
@@ -1,20 +1 @@
1
- import { useB3ConfigStore } from "../../stores/configStore.js";
2
- /**
3
- * Hook to access B3 configuration
4
- * Returns all config values from the Zustand store
5
- * Since config is static (set once at initialization), destructuring is fine here
6
- */
7
- export const useB3Config = () => {
8
- return useB3ConfigStore(state => ({
9
- automaticallySetFirstEoa: state.automaticallySetFirstEoa,
10
- environment: state.environment,
11
- theme: state.theme,
12
- clientType: state.clientType,
13
- partnerId: state.partnerId,
14
- createClientReferenceId: state.createClientReferenceId,
15
- enableTurnkey: state.enableTurnkey,
16
- stripePublishableKey: state.stripePublishableKey,
17
- defaultPermissions: state.defaultPermissions,
18
- accountOverride: state.accountOverride,
19
- }));
20
- };
1
+ export { useB3Config } from "./B3ConfigProvider.js";
@@ -7455,12 +7455,12 @@ export declare function useFirstEOA(chain?: {
7455
7455
  [x: `bytes6[${string}]`]: undefined;
7456
7456
  [x: `bytes9[${string}]`]: undefined;
7457
7457
  [x: `bytes8[${string}]`]: undefined;
7458
+ [x: `bytes10[${string}]`]: undefined;
7458
7459
  [x: `bytes2[${string}]`]: undefined;
7459
7460
  [x: `bytes3[${string}]`]: undefined;
7460
7461
  [x: `bytes4[${string}]`]: undefined;
7461
7462
  [x: `bytes5[${string}]`]: undefined;
7462
7463
  [x: `bytes7[${string}]`]: undefined;
7463
- [x: `bytes10[${string}]`]: undefined;
7464
7464
  [x: `bytes11[${string}]`]: undefined;
7465
7465
  [x: `bytes12[${string}]`]: undefined;
7466
7466
  [x: `bytes13[${string}]`]: undefined;
@@ -7557,12 +7557,12 @@ export declare function useFirstEOA(chain?: {
7557
7557
  bytes6?: undefined;
7558
7558
  bytes9?: undefined;
7559
7559
  bytes8?: undefined;
7560
+ bytes10?: undefined;
7560
7561
  bytes2?: undefined;
7561
7562
  bytes3?: undefined;
7562
7563
  bytes4?: undefined;
7563
7564
  bytes5?: undefined;
7564
7565
  bytes7?: undefined;
7565
- bytes10?: undefined;
7566
7566
  bytes11?: undefined;
7567
7567
  bytes12?: undefined;
7568
7568
  bytes13?: undefined;
@@ -46,6 +46,9 @@ export function useTokenBalancesByChain({ address, chainsIds, enabled = true, })
46
46
  staleTime: 30000, // Consider data fresh for 30 seconds
47
47
  gcTime: 5 * 60 * 1000, // Keep in cache for 5 minutes
48
48
  retry: 2, // Limit retries on failure
49
+ // Enable structural sharing to prevent infinite loops
50
+ // This ensures we only get new references when data actually changes
51
+ structuralSharing: true,
49
52
  });
50
53
  return {
51
54
  nativeTokens: combinedData?.nativeTokens ?? [],
@@ -1,5 +1,4 @@
1
1
  export { useAuthStore } from "./useAuthStore";
2
- export { useB3ConfigStore } from "./configStore";
3
2
  export { useModalStore } from "./useModalStore";
4
3
  export { useRecentAddressesStore } from "./useRecentAddressesStore";
5
4
  export type { AnySpendBuySpinProps, AnySpendFundTournamentProps, AnySpendJoinTournamentProps, AnySpendModalProps, AnySpendNftProps, AnySpendOrderHistoryProps, AnySpendStakeB3Props, AnyspendOrderDetailsProps, ManageAccountModalProps, ModalContentType, RequestPermissionsModalProps, SignInWithB3ModalProps, } from "./useModalStore";
@@ -1,4 +1,3 @@
1
1
  export { useAuthStore } from "./useAuthStore.js";
2
- export { useB3ConfigStore } from "./configStore.js";
3
2
  export { useModalStore } from "./useModalStore.js";
4
3
  export { useRecentAddressesStore } from "./useRecentAddressesStore.js";
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Public RPC endpoints for EVM chains.
3
+ * These are free, public endpoints that can be used without API keys.
4
+ *
5
+ * Sources:
6
+ * - https://publicnode.com
7
+ * - https://chainlist.org
8
+ */
9
+ export declare const ETHEREUM_PUBLIC_RPC = "https://ethereum-rpc.publicnode.com";
10
+ export declare const ARBITRUM_PUBLIC_RPC = "https://arbitrum-one-rpc.publicnode.com";
11
+ export declare const BASE_PUBLIC_RPC = "https://base-rpc.publicnode.com";
12
+ export declare const OPTIMISM_PUBLIC_RPC = "https://optimism-rpc.publicnode.com";
13
+ export declare const POLYGON_PUBLIC_RPC = "https://polygon-bor-rpc.publicnode.com";
14
+ export declare const AVALANCHE_PUBLIC_RPC = "https://avalanche-c-chain-rpc.publicnode.com";
15
+ export declare const BSC_PUBLIC_RPC = "https://bsc-rpc.publicnode.com";
16
+ export declare const B3_PUBLIC_RPC = "https://mainnet-rpc.b3.fun/http";
17
+ export declare const ABSTRACT_PUBLIC_RPC = "https://api.mainnet.abs.xyz";
18
+ export declare const HYPEREVM_PUBLIC_RPC = "https://rpc.hyperliquid.xyz/evm";
19
+ /**
20
+ * Map of chain IDs to their default public RPC URLs.
21
+ */
22
+ export declare const PUBLIC_RPC_URLS: Record<number, string>;
@@ -1,6 +1,29 @@
1
1
  import { components } from "@b3dotfun/sdk/anyspend/types/api";
2
2
  import { Account, Chain, PublicClient, Transport, WalletClient } from "viem";
3
3
  import { ChainType, IBaseChain, IEVMChain, IHyperliquidChain, ISolanaChain } from "../types/chain";
4
+ /**
5
+ * Set custom RPC URL overrides for specific chains.
6
+ * These overrides are used by chainIdToPublicClient and chainIdToWalletClient.
7
+ *
8
+ * @param overrides - A record mapping chain IDs to custom RPC URLs
9
+ *
10
+ * @example
11
+ * // Set once at app initialization using environment variables
12
+ * setChainRpcOverrides({
13
+ * 1: process.env.ETHEREUM_RPC_URL,
14
+ * 8453: process.env.BASE_RPC_URL,
15
+ * 42161: process.env.ARBITRUM_RPC_URL,
16
+ * });
17
+ */
18
+ export declare function setChainRpcOverrides(overrides: Record<number, string>): void;
19
+ /**
20
+ * Get the current RPC URL overrides.
21
+ */
22
+ export declare function getChainRpcOverrides(): Record<number, string>;
23
+ /**
24
+ * Clear all RPC URL overrides.
25
+ */
26
+ export declare function clearChainRpcOverrides(): void;
4
27
  export declare const hyperEVM: {
5
28
  blockExplorers: {
6
29
  readonly default: {
@@ -0,0 +1,31 @@
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 { Account } from "thirdweb/wallets";
5
+ import { ClientType } from "../../../client-manager";
6
+ export interface B3ConfigContextType {
7
+ accountOverride?: Account;
8
+ automaticallySetFirstEoa: boolean;
9
+ environment: "development" | "production";
10
+ defaultPermissions: PermissionsConfig;
11
+ theme: "light" | "dark";
12
+ clientType: ClientType;
13
+ partnerId: string;
14
+ stripePublishableKey?: string;
15
+ createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
16
+ enableTurnkey: boolean;
17
+ }
18
+ export declare function B3ConfigProvider({ children, accountOverride, environment, defaultPermissions, automaticallySetFirstEoa, theme, clientType, partnerId, stripePublishableKey, createClientReferenceId, enableTurnkey, }: {
19
+ children: React.ReactNode;
20
+ accountOverride?: Account;
21
+ environment?: "development" | "production";
22
+ defaultPermissions?: PermissionsConfig;
23
+ automaticallySetFirstEoa?: boolean;
24
+ theme?: "light" | "dark";
25
+ clientType?: ClientType;
26
+ partnerId: string;
27
+ stripePublishableKey?: string;
28
+ createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
29
+ enableTurnkey?: boolean;
30
+ }): import("react/jsx-runtime").JSX.Element;
31
+ export declare function useB3Config(): B3ConfigContextType;
@@ -2,15 +2,4 @@
2
2
  * Hook to access the B3 configuration
3
3
  * @deprecated This is just an alias for useB3Config. Use useB3Config directly instead.
4
4
  */
5
- export declare function useB3(): {
6
- automaticallySetFirstEoa: boolean;
7
- environment: "development" | "production";
8
- theme: "light" | "dark";
9
- clientType: import("../../../client-manager").ClientType;
10
- partnerId: string;
11
- createClientReferenceId: ((params: import("../../../../anyspend/react").CreateOrderParams | import("../../../../anyspend/react").CreateOnrampOrderParams) => Promise<string>) | undefined;
12
- enableTurnkey: boolean;
13
- stripePublishableKey: string | undefined;
14
- defaultPermissions: import("../../../types/permissions").PermissionsConfig;
15
- accountOverride: import("thirdweb/wallets").Account | undefined;
16
- };
5
+ export declare function useB3(): import("./B3ConfigProvider").B3ConfigContextType;
@@ -1,17 +1 @@
1
- /**
2
- * Hook to access B3 configuration
3
- * Returns all config values from the Zustand store
4
- * Since config is static (set once at initialization), destructuring is fine here
5
- */
6
- export declare const useB3Config: () => {
7
- automaticallySetFirstEoa: boolean;
8
- environment: "development" | "production";
9
- theme: "light" | "dark";
10
- clientType: import("../../../client-manager").ClientType;
11
- partnerId: string;
12
- createClientReferenceId: ((params: import("../../../../anyspend/react").CreateOrderParams | import("../../../../anyspend/react").CreateOnrampOrderParams) => Promise<string>) | undefined;
13
- enableTurnkey: boolean;
14
- stripePublishableKey: string | undefined;
15
- defaultPermissions: import("../../../types/permissions").PermissionsConfig;
16
- accountOverride: import("thirdweb/wallets").Account | undefined;
17
- };
1
+ export { useB3Config } from "./B3ConfigProvider";
@@ -7455,12 +7455,12 @@ export declare function useFirstEOA(chain?: {
7455
7455
  [x: `bytes6[${string}]`]: undefined;
7456
7456
  [x: `bytes9[${string}]`]: undefined;
7457
7457
  [x: `bytes8[${string}]`]: undefined;
7458
+ [x: `bytes10[${string}]`]: undefined;
7458
7459
  [x: `bytes2[${string}]`]: undefined;
7459
7460
  [x: `bytes3[${string}]`]: undefined;
7460
7461
  [x: `bytes4[${string}]`]: undefined;
7461
7462
  [x: `bytes5[${string}]`]: undefined;
7462
7463
  [x: `bytes7[${string}]`]: undefined;
7463
- [x: `bytes10[${string}]`]: undefined;
7464
7464
  [x: `bytes11[${string}]`]: undefined;
7465
7465
  [x: `bytes12[${string}]`]: undefined;
7466
7466
  [x: `bytes13[${string}]`]: undefined;
@@ -7557,12 +7557,12 @@ export declare function useFirstEOA(chain?: {
7557
7557
  bytes6?: undefined;
7558
7558
  bytes9?: undefined;
7559
7559
  bytes8?: undefined;
7560
+ bytes10?: undefined;
7560
7561
  bytes2?: undefined;
7561
7562
  bytes3?: undefined;
7562
7563
  bytes4?: undefined;
7563
7564
  bytes5?: undefined;
7564
7565
  bytes7?: undefined;
7565
- bytes10?: undefined;
7566
7566
  bytes11?: undefined;
7567
7567
  bytes12?: undefined;
7568
7568
  bytes13?: undefined;
@@ -1,5 +1,4 @@
1
1
  export { useAuthStore } from "./useAuthStore";
2
- export { useB3ConfigStore } from "./configStore";
3
2
  export { useModalStore } from "./useModalStore";
4
3
  export { useRecentAddressesStore } from "./useRecentAddressesStore";
5
4
  export type { AnySpendBuySpinProps, AnySpendFundTournamentProps, AnySpendJoinTournamentProps, AnySpendModalProps, AnySpendNftProps, AnySpendOrderHistoryProps, AnySpendStakeB3Props, AnyspendOrderDetailsProps, ManageAccountModalProps, ModalContentType, RequestPermissionsModalProps, SignInWithB3ModalProps, } from "./useModalStore";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b3dotfun/sdk",
3
- "version": "0.0.90-test.1",
3
+ "version": "0.1.0-alpha.1",
4
4
  "source": "src/index.ts",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "react-native": "./dist/cjs/index.native.js",