@b3dotfun/sdk 0.1.0-alpha.2 → 0.1.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/common/GasIndicator.d.ts +1 -1
- package/dist/cjs/anyspend/react/components/common/GasIndicator.js +16 -6
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +30 -2
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +31 -4
- package/dist/cjs/global-account/react/components/B3Provider/useB3.d.ts +12 -1
- package/dist/cjs/global-account/react/components/B3Provider/useB3Config.d.ts +17 -1
- package/dist/cjs/global-account/react/components/B3Provider/useB3Config.js +21 -2
- package/dist/cjs/global-account/react/stores/configStore.d.ts +24 -0
- package/dist/cjs/global-account/react/stores/configStore.js +30 -0
- package/dist/cjs/global-account/react/stores/index.d.ts +1 -0
- package/dist/cjs/global-account/react/stores/index.js +3 -1
- package/dist/esm/anyspend/react/components/common/GasIndicator.d.ts +1 -1
- package/dist/esm/anyspend/react/components/common/GasIndicator.js +17 -7
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +30 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +30 -3
- package/dist/esm/global-account/react/components/B3Provider/useB3.d.ts +12 -1
- package/dist/esm/global-account/react/components/B3Provider/useB3Config.d.ts +17 -1
- package/dist/esm/global-account/react/components/B3Provider/useB3Config.js +20 -1
- package/dist/esm/global-account/react/stores/configStore.d.ts +24 -0
- package/dist/esm/global-account/react/stores/configStore.js +27 -0
- package/dist/esm/global-account/react/stores/index.d.ts +1 -0
- package/dist/esm/global-account/react/stores/index.js +1 -0
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/components/common/GasIndicator.d.ts +1 -1
- package/dist/types/global-account/react/components/B3Provider/useB3.d.ts +12 -1
- package/dist/types/global-account/react/components/B3Provider/useB3Config.d.ts +17 -1
- package/dist/types/global-account/react/stores/configStore.d.ts +24 -0
- package/dist/types/global-account/react/stores/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/anyspend/react/components/common/GasIndicator.tsx +30 -11
- package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +36 -28
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +38 -21
- package/src/global-account/react/components/B3Provider/useB3Config.ts +21 -1
- package/src/global-account/react/stores/configStore.ts +51 -0
- package/src/global-account/react/stores/index.ts +1 -0
- package/dist/cjs/global-account/react/components/B3Provider/B3ConfigProvider.d.ts +0 -31
- package/dist/cjs/global-account/react/components/B3Provider/B3ConfigProvider.js +0 -37
- package/dist/esm/global-account/react/components/B3Provider/B3ConfigProvider.d.ts +0 -31
- package/dist/esm/global-account/react/components/B3Provider/B3ConfigProvider.js +0 -33
- package/dist/types/global-account/react/components/B3Provider/B3ConfigProvider.d.ts +0 -31
- package/src/global-account/react/components/B3Provider/B3ConfigProvider.tsx +0 -84
|
@@ -3,4 +3,4 @@ export interface GasIndicatorProps {
|
|
|
3
3
|
gasPrice: GasPriceData;
|
|
4
4
|
className?: string;
|
|
5
5
|
}
|
|
6
|
-
export declare function GasIndicator({ gasPrice, className }: GasIndicatorProps): import("react/jsx-runtime").JSX.Element
|
|
6
|
+
export declare function GasIndicator({ gasPrice, className }: GasIndicatorProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -5,7 +5,21 @@ exports.GasIndicator = GasIndicator;
|
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
6
|
const cn_1 = require("../../../../shared/utils/cn");
|
|
7
7
|
const react_1 = require("motion/react");
|
|
8
|
-
|
|
8
|
+
const LEVEL_LABELS = {
|
|
9
|
+
low: "Low",
|
|
10
|
+
normal: "Normal",
|
|
11
|
+
elevated: "Elevated",
|
|
12
|
+
high: "High",
|
|
13
|
+
spike: "Spike",
|
|
14
|
+
};
|
|
15
|
+
const LEVEL_STYLES = {
|
|
16
|
+
low: "bg-green-500/20 text-green-500",
|
|
17
|
+
normal: "bg-as-surface-tertiary text-as-secondary",
|
|
18
|
+
elevated: "bg-yellow-500/20 text-yellow-600",
|
|
19
|
+
high: "bg-orange-500/20 text-orange-500",
|
|
20
|
+
spike: "bg-red-500/20 text-red-500",
|
|
21
|
+
};
|
|
22
|
+
function formatGasPrice(gweiString) {
|
|
9
23
|
const gwei = parseFloat(gweiString);
|
|
10
24
|
if (gwei < 0.001)
|
|
11
25
|
return "<0.001";
|
|
@@ -16,9 +30,5 @@ function formatGwei(gweiString) {
|
|
|
16
30
|
return gwei.toFixed(1);
|
|
17
31
|
}
|
|
18
32
|
function GasIndicator({ gasPrice, className }) {
|
|
19
|
-
|
|
20
|
-
if (!["high", "spike"].includes(gasPrice.level)) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
return ((0, jsx_runtime_1.jsxs)(react_1.motion.div, { initial: { opacity: 0, y: 10 }, animate: { opacity: 1, y: 0 }, transition: { duration: 0.2 }, className: (0, cn_1.cn)("flex flex-col gap-1 rounded-lg bg-orange-500/10 px-3 py-2", className), children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-xs font-medium text-orange-500", children: "Gas is high - transaction may fail or cost more" }), (0, jsx_runtime_1.jsxs)("span", { className: "text-xs font-medium text-orange-500", children: [formatGwei(gasPrice.gasPriceGwei), " Gwei"] })] }), (0, jsx_runtime_1.jsx)("span", { className: "text-as-secondary text-xs", children: "Consider swapping later for better rates" })] }));
|
|
33
|
+
return ((0, jsx_runtime_1.jsxs)(react_1.motion.div, { initial: { opacity: 0, y: 10 }, animate: { opacity: 1, y: 0 }, transition: { duration: 0.2 }, className: (0, cn_1.cn)("flex items-center justify-between rounded-lg px-3 py-2", gasPrice.isSpike ? "bg-yellow-500/10" : "bg-as-surface-secondary", className), children: [(0, jsx_runtime_1.jsx)("div", { className: "flex items-center gap-2", children: (0, jsx_runtime_1.jsxs)("span", { className: "text-as-secondary text-xs", children: ["Gas on ", gasPrice.chainName] }) }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2", children: [(0, jsx_runtime_1.jsx)("span", { className: (0, cn_1.cn)("rounded px-1.5 py-0.5 text-xs font-medium", LEVEL_STYLES[gasPrice.level]), children: LEVEL_LABELS[gasPrice.level] }), (0, jsx_runtime_1.jsxs)("span", { className: "text-as-primary text-xs font-medium", children: [formatGasPrice(gasPrice.gasPriceGwei), " Gwei"] })] })] }));
|
|
24
34
|
}
|
|
@@ -14,10 +14,10 @@ const react_2 = require("react");
|
|
|
14
14
|
const react_3 = require("thirdweb/react");
|
|
15
15
|
const wagmi_1 = require("wagmi");
|
|
16
16
|
const client_manager_1 = require("../../../client-manager");
|
|
17
|
+
const configStore_1 = require("../../stores/configStore");
|
|
17
18
|
const StyleRoot_1 = require("../StyleRoot");
|
|
18
19
|
const index_1 = require("../Toast/index");
|
|
19
20
|
const AuthenticationProvider_1 = __importDefault(require("./AuthenticationProvider"));
|
|
20
|
-
const B3ConfigProvider_1 = require("./B3ConfigProvider");
|
|
21
21
|
const LocalSDKProvider_1 = require("./LocalSDKProvider");
|
|
22
22
|
// Create queryClient instance
|
|
23
23
|
const queryClient = new react_query_1.QueryClient();
|
|
@@ -27,6 +27,34 @@ const queryClient = new react_query_1.QueryClient();
|
|
|
27
27
|
function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey,
|
|
28
28
|
// deprecated since v0.0.87
|
|
29
29
|
toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey, onConnect, connectors, overrideDefaultConnectors = false, createClientReferenceId, enableTurnkey = false, defaultPermissions, }) {
|
|
30
|
+
const setConfig = (0, configStore_1.useB3ConfigStore)(state => state.setConfig);
|
|
31
|
+
// Initialize config store on mount
|
|
32
|
+
(0, react_2.useEffect)(() => {
|
|
33
|
+
setConfig({
|
|
34
|
+
accountOverride,
|
|
35
|
+
environment: environment ?? "development",
|
|
36
|
+
automaticallySetFirstEoa: !!automaticallySetFirstEoa,
|
|
37
|
+
theme,
|
|
38
|
+
clientType,
|
|
39
|
+
partnerId,
|
|
40
|
+
stripePublishableKey,
|
|
41
|
+
createClientReferenceId,
|
|
42
|
+
enableTurnkey,
|
|
43
|
+
defaultPermissions,
|
|
44
|
+
});
|
|
45
|
+
}, [
|
|
46
|
+
accountOverride,
|
|
47
|
+
environment,
|
|
48
|
+
automaticallySetFirstEoa,
|
|
49
|
+
theme,
|
|
50
|
+
clientType,
|
|
51
|
+
partnerId,
|
|
52
|
+
stripePublishableKey,
|
|
53
|
+
createClientReferenceId,
|
|
54
|
+
enableTurnkey,
|
|
55
|
+
defaultPermissions,
|
|
56
|
+
setConfig,
|
|
57
|
+
]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
30
58
|
// Initialize Google Analytics on mount
|
|
31
59
|
(0, react_2.useEffect)(() => {
|
|
32
60
|
(0, analytics_1.loadGA4Script)();
|
|
@@ -36,7 +64,7 @@ toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey
|
|
|
36
64
|
(0, client_manager_1.setClientType)(clientType);
|
|
37
65
|
}, [clientType]);
|
|
38
66
|
const wagmiConfig = (0, react_2.useMemo)(() => (0, createWagmiConfig_1.createWagmiConfig)({ partnerId, rpcUrls, connectors, overrideDefaultConnectors }), [partnerId, rpcUrls, connectors, overrideDefaultConnectors]);
|
|
39
|
-
return ((0, jsx_runtime_1.jsx)(react_3.ThirdwebProvider, { children: (0, jsx_runtime_1.jsx)(wagmi_1.WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: (0, jsx_runtime_1.jsx)(react_1.TooltipProvider, { children: (0, jsx_runtime_1.jsx)(index_1.ToastProvider, { children: (0, jsx_runtime_1.
|
|
67
|
+
return ((0, jsx_runtime_1.jsx)(react_3.ThirdwebProvider, { children: (0, jsx_runtime_1.jsx)(wagmi_1.WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: (0, jsx_runtime_1.jsx)(react_1.TooltipProvider, { children: (0, jsx_runtime_1.jsx)(index_1.ToastProvider, { children: (0, jsx_runtime_1.jsxs)(LocalSDKProvider_1.LocalSDKProvider, { onConnectCallback: onConnect, children: [(0, jsx_runtime_1.jsx)(ToastContextConnector, {}), (0, jsx_runtime_1.jsxs)(react_1.RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, (0, jsx_runtime_1.jsx)(StyleRoot_1.StyleRoot, { id: "b3-root" })] }), (0, jsx_runtime_1.jsx)(AuthenticationProvider_1.default, { partnerId: partnerId, automaticallySetFirstEoa: !!automaticallySetFirstEoa })] }) }) }) }) }) }));
|
|
40
68
|
}
|
|
41
69
|
/**
|
|
42
70
|
* Component to connect the toast context to the global toast API
|
|
@@ -7,11 +7,12 @@ exports.B3Provider = B3Provider;
|
|
|
7
7
|
exports.InnerProvider = InnerProvider;
|
|
8
8
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
9
|
const react_query_1 = require("@tanstack/react-query");
|
|
10
|
-
const react_1 = require("
|
|
10
|
+
const react_1 = require("react");
|
|
11
|
+
const react_2 = require("thirdweb/react");
|
|
11
12
|
const wagmi_1 = require("wagmi");
|
|
13
|
+
const configStore_1 = require("../../stores/configStore");
|
|
12
14
|
const createWagmiConfig_1 = require("../../utils/createWagmiConfig");
|
|
13
15
|
const AuthenticationProvider_1 = __importDefault(require("./AuthenticationProvider"));
|
|
14
|
-
const B3ConfigProvider_1 = require("./B3ConfigProvider");
|
|
15
16
|
const LocalSDKProvider_1 = require("./LocalSDKProvider");
|
|
16
17
|
// Create queryClient instance
|
|
17
18
|
const queryClient = new react_query_1.QueryClient();
|
|
@@ -19,12 +20,38 @@ const queryClient = new react_query_1.QueryClient();
|
|
|
19
20
|
* Main B3Provider component
|
|
20
21
|
*/
|
|
21
22
|
function B3Provider({ theme = "light", children, accountOverride, environment, clientType = "socket", partnerId, rpcUrls, onConnect, defaultPermissions, }) {
|
|
22
|
-
|
|
23
|
+
const setConfig = (0, configStore_1.useB3ConfigStore)(state => state.setConfig);
|
|
24
|
+
// Initialize config store on mount - props are static and never change
|
|
25
|
+
(0, react_1.useEffect)(() => {
|
|
26
|
+
setConfig({
|
|
27
|
+
accountOverride,
|
|
28
|
+
environment: environment ?? "development",
|
|
29
|
+
automaticallySetFirstEoa: false,
|
|
30
|
+
theme,
|
|
31
|
+
clientType,
|
|
32
|
+
partnerId,
|
|
33
|
+
defaultPermissions,
|
|
34
|
+
});
|
|
35
|
+
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
36
|
+
return ((0, jsx_runtime_1.jsx)(react_2.ThirdwebProvider, { children: (0, jsx_runtime_1.jsxs)(LocalSDKProvider_1.LocalSDKProvider, { onConnectCallback: onConnect, children: [children, (0, jsx_runtime_1.jsx)(AuthenticationProvider_1.default, { partnerId: partnerId, automaticallySetFirstEoa: false })] }) }));
|
|
23
37
|
}
|
|
24
38
|
/**
|
|
25
39
|
* Inner provider component for native
|
|
26
40
|
*/
|
|
27
41
|
function InnerProvider({ children, accountOverride, environment, defaultPermissions, theme = "light", clientType = "socket", partnerId, rpcUrls, }) {
|
|
42
|
+
const setConfig = (0, configStore_1.useB3ConfigStore)(state => state.setConfig);
|
|
28
43
|
const wagmiConfig = (0, createWagmiConfig_1.createWagmiConfig)({ partnerId, rpcUrls });
|
|
29
|
-
|
|
44
|
+
// Initialize config store on mount - props are static and never change
|
|
45
|
+
(0, react_1.useEffect)(() => {
|
|
46
|
+
setConfig({
|
|
47
|
+
accountOverride,
|
|
48
|
+
environment: environment ?? "development",
|
|
49
|
+
automaticallySetFirstEoa: false,
|
|
50
|
+
theme,
|
|
51
|
+
clientType,
|
|
52
|
+
partnerId,
|
|
53
|
+
defaultPermissions,
|
|
54
|
+
});
|
|
55
|
+
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
56
|
+
return ((0, jsx_runtime_1.jsx)(wagmi_1.WagmiProvider, { config: wagmiConfig, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: children }) }));
|
|
30
57
|
}
|
|
@@ -2,4 +2,15 @@
|
|
|
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():
|
|
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
|
+
};
|
|
@@ -1 +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,5 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useB3Config = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const configStore_1 = require("../../stores/configStore");
|
|
5
|
+
/**
|
|
6
|
+
* Hook to access B3 configuration
|
|
7
|
+
* Returns all config values from the Zustand store
|
|
8
|
+
* Since config is static (set once at initialization), destructuring is fine here
|
|
9
|
+
*/
|
|
10
|
+
const useB3Config = () => {
|
|
11
|
+
return (0, configStore_1.useB3ConfigStore)(state => ({
|
|
12
|
+
automaticallySetFirstEoa: state.automaticallySetFirstEoa,
|
|
13
|
+
environment: state.environment,
|
|
14
|
+
theme: state.theme,
|
|
15
|
+
clientType: state.clientType,
|
|
16
|
+
partnerId: state.partnerId,
|
|
17
|
+
createClientReferenceId: state.createClientReferenceId,
|
|
18
|
+
enableTurnkey: state.enableTurnkey,
|
|
19
|
+
stripePublishableKey: state.stripePublishableKey,
|
|
20
|
+
defaultPermissions: state.defaultPermissions,
|
|
21
|
+
accountOverride: state.accountOverride,
|
|
22
|
+
}));
|
|
23
|
+
};
|
|
24
|
+
exports.useB3Config = useB3Config;
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
interface ConfigStore {
|
|
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
|
+
setConfig: (config: Partial<Omit<ConfigStore, "setConfig">>) => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Zustand store for B3 configuration
|
|
21
|
+
* NOT persisted - these are developer-set configuration values
|
|
22
|
+
*/
|
|
23
|
+
export declare const useB3ConfigStore: import("zustand").UseBoundStore<import("zustand").StoreApi<ConfigStore>>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useB3ConfigStore = void 0;
|
|
4
|
+
const zustand_1 = require("zustand");
|
|
5
|
+
/**
|
|
6
|
+
* Default permissions configuration for B3 provider
|
|
7
|
+
*/
|
|
8
|
+
const DEFAULT_PERMISSIONS = {
|
|
9
|
+
approvedTargets: ["0xa8e42121e318e3D3BeD7f5969AF6D360045317DD"],
|
|
10
|
+
nativeTokenLimitPerTransaction: 0.1,
|
|
11
|
+
startDate: new Date(),
|
|
12
|
+
endDate: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365), // 1 year from now
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Zustand store for B3 configuration
|
|
16
|
+
* NOT persisted - these are developer-set configuration values
|
|
17
|
+
*/
|
|
18
|
+
exports.useB3ConfigStore = (0, zustand_1.create)(set => ({
|
|
19
|
+
accountOverride: undefined,
|
|
20
|
+
automaticallySetFirstEoa: false,
|
|
21
|
+
environment: "development",
|
|
22
|
+
defaultPermissions: DEFAULT_PERMISSIONS,
|
|
23
|
+
theme: "light",
|
|
24
|
+
clientType: "rest",
|
|
25
|
+
partnerId: "",
|
|
26
|
+
stripePublishableKey: undefined,
|
|
27
|
+
createClientReferenceId: undefined,
|
|
28
|
+
enableTurnkey: false,
|
|
29
|
+
setConfig: config => set(state => ({ ...state, ...config })),
|
|
30
|
+
}));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { useAuthStore } from "./useAuthStore";
|
|
2
|
+
export { useB3ConfigStore } from "./configStore";
|
|
2
3
|
export { useModalStore } from "./useModalStore";
|
|
3
4
|
export { useRecentAddressesStore } from "./useRecentAddressesStore";
|
|
4
5
|
export type { AnySpendBuySpinProps, AnySpendFundTournamentProps, AnySpendJoinTournamentProps, AnySpendModalProps, AnySpendNftProps, AnySpendOrderHistoryProps, AnySpendStakeB3Props, AnyspendOrderDetailsProps, ManageAccountModalProps, ModalContentType, RequestPermissionsModalProps, SignInWithB3ModalProps, } from "./useModalStore";
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useRecentAddressesStore = exports.useModalStore = exports.useAuthStore = void 0;
|
|
3
|
+
exports.useRecentAddressesStore = exports.useModalStore = exports.useB3ConfigStore = exports.useAuthStore = void 0;
|
|
4
4
|
var useAuthStore_1 = require("./useAuthStore");
|
|
5
5
|
Object.defineProperty(exports, "useAuthStore", { enumerable: true, get: function () { return useAuthStore_1.useAuthStore; } });
|
|
6
|
+
var configStore_1 = require("./configStore");
|
|
7
|
+
Object.defineProperty(exports, "useB3ConfigStore", { enumerable: true, get: function () { return configStore_1.useB3ConfigStore; } });
|
|
6
8
|
var useModalStore_1 = require("./useModalStore");
|
|
7
9
|
Object.defineProperty(exports, "useModalStore", { enumerable: true, get: function () { return useModalStore_1.useModalStore; } });
|
|
8
10
|
var useRecentAddressesStore_1 = require("./useRecentAddressesStore");
|
|
@@ -3,4 +3,4 @@ export interface GasIndicatorProps {
|
|
|
3
3
|
gasPrice: GasPriceData;
|
|
4
4
|
className?: string;
|
|
5
5
|
}
|
|
6
|
-
export declare function GasIndicator({ gasPrice, className }: GasIndicatorProps): import("react/jsx-runtime").JSX.Element
|
|
6
|
+
export declare function GasIndicator({ gasPrice, className }: GasIndicatorProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { cn } from "../../../../shared/utils/cn.js";
|
|
4
4
|
import { motion } from "motion/react";
|
|
5
|
-
|
|
5
|
+
const LEVEL_LABELS = {
|
|
6
|
+
low: "Low",
|
|
7
|
+
normal: "Normal",
|
|
8
|
+
elevated: "Elevated",
|
|
9
|
+
high: "High",
|
|
10
|
+
spike: "Spike",
|
|
11
|
+
};
|
|
12
|
+
const LEVEL_STYLES = {
|
|
13
|
+
low: "bg-green-500/20 text-green-500",
|
|
14
|
+
normal: "bg-as-surface-tertiary text-as-secondary",
|
|
15
|
+
elevated: "bg-yellow-500/20 text-yellow-600",
|
|
16
|
+
high: "bg-orange-500/20 text-orange-500",
|
|
17
|
+
spike: "bg-red-500/20 text-red-500",
|
|
18
|
+
};
|
|
19
|
+
function formatGasPrice(gweiString) {
|
|
6
20
|
const gwei = parseFloat(gweiString);
|
|
7
21
|
if (gwei < 0.001)
|
|
8
22
|
return "<0.001";
|
|
@@ -13,9 +27,5 @@ function formatGwei(gweiString) {
|
|
|
13
27
|
return gwei.toFixed(1);
|
|
14
28
|
}
|
|
15
29
|
export function GasIndicator({ gasPrice, className }) {
|
|
16
|
-
|
|
17
|
-
if (!["high", "spike"].includes(gasPrice.level)) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
return (_jsxs(motion.div, { initial: { opacity: 0, y: 10 }, animate: { opacity: 1, y: 0 }, transition: { duration: 0.2 }, className: cn("flex flex-col gap-1 rounded-lg bg-orange-500/10 px-3 py-2", className), children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("span", { className: "text-xs font-medium text-orange-500", children: "Gas is high - transaction may fail or cost more" }), _jsxs("span", { className: "text-xs font-medium text-orange-500", children: [formatGwei(gasPrice.gasPriceGwei), " Gwei"] })] }), _jsx("span", { className: "text-as-secondary text-xs", children: "Consider swapping later for better rates" })] }));
|
|
30
|
+
return (_jsxs(motion.div, { initial: { opacity: 0, y: 10 }, animate: { opacity: 1, y: 0 }, transition: { duration: 0.2 }, className: cn("flex items-center justify-between rounded-lg px-3 py-2", gasPrice.isSpike ? "bg-yellow-500/10" : "bg-as-surface-secondary", className), children: [_jsx("div", { className: "flex items-center gap-2", children: _jsxs("span", { className: "text-as-secondary text-xs", children: ["Gas on ", gasPrice.chainName] }) }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: cn("rounded px-1.5 py-0.5 text-xs font-medium", LEVEL_STYLES[gasPrice.level]), children: LEVEL_LABELS[gasPrice.level] }), _jsxs("span", { className: "text-as-primary text-xs font-medium", children: [formatGasPrice(gasPrice.gasPriceGwei), " Gwei"] })] })] }));
|
|
21
31
|
}
|
|
@@ -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";
|
|
11
12
|
import { StyleRoot } from "../StyleRoot.js";
|
|
12
13
|
import { setToastContext, ToastProvider, useToastContext } from "../Toast/index.js";
|
|
13
14
|
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,6 +21,34 @@ 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
|
+
}, [
|
|
40
|
+
accountOverride,
|
|
41
|
+
environment,
|
|
42
|
+
automaticallySetFirstEoa,
|
|
43
|
+
theme,
|
|
44
|
+
clientType,
|
|
45
|
+
partnerId,
|
|
46
|
+
stripePublishableKey,
|
|
47
|
+
createClientReferenceId,
|
|
48
|
+
enableTurnkey,
|
|
49
|
+
defaultPermissions,
|
|
50
|
+
setConfig,
|
|
51
|
+
]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
24
52
|
// Initialize Google Analytics on mount
|
|
25
53
|
useEffect(() => {
|
|
26
54
|
loadGA4Script();
|
|
@@ -30,7 +58,7 @@ toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey
|
|
|
30
58
|
setClientType(clientType);
|
|
31
59
|
}, [clientType]);
|
|
32
60
|
const wagmiConfig = useMemo(() => createWagmiConfig({ partnerId, rpcUrls, connectors, overrideDefaultConnectors }), [partnerId, rpcUrls, connectors, overrideDefaultConnectors]);
|
|
33
|
-
return (_jsx(ThirdwebProvider, { children: _jsx(WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(TooltipProvider, { children: _jsx(ToastProvider, { children:
|
|
61
|
+
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 })] }) }) }) }) }) }));
|
|
34
62
|
}
|
|
35
63
|
/**
|
|
36
64
|
* Component to connect the toast context to the global toast API
|
|
@@ -1,10 +1,11 @@
|
|
|
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";
|
|
3
4
|
import { ThirdwebProvider } from "thirdweb/react";
|
|
4
5
|
import { WagmiProvider } from "wagmi";
|
|
6
|
+
import { useB3ConfigStore } from "../../stores/configStore.js";
|
|
5
7
|
import { createWagmiConfig } from "../../utils/createWagmiConfig.js";
|
|
6
8
|
import AuthenticationProvider from "./AuthenticationProvider.js";
|
|
7
|
-
import { B3ConfigProvider } from "./B3ConfigProvider.js";
|
|
8
9
|
import { LocalSDKProvider } from "./LocalSDKProvider.js";
|
|
9
10
|
// Create queryClient instance
|
|
10
11
|
const queryClient = new QueryClient();
|
|
@@ -12,12 +13,38 @@ const queryClient = new QueryClient();
|
|
|
12
13
|
* Main B3Provider component
|
|
13
14
|
*/
|
|
14
15
|
export function B3Provider({ theme = "light", children, accountOverride, environment, clientType = "socket", partnerId, rpcUrls, onConnect, defaultPermissions, }) {
|
|
15
|
-
|
|
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 })] }) }));
|
|
16
30
|
}
|
|
17
31
|
/**
|
|
18
32
|
* Inner provider component for native
|
|
19
33
|
*/
|
|
20
34
|
export function InnerProvider({ children, accountOverride, environment, defaultPermissions, theme = "light", clientType = "socket", partnerId, rpcUrls, }) {
|
|
35
|
+
const setConfig = useB3ConfigStore(state => state.setConfig);
|
|
21
36
|
const wagmiConfig = createWagmiConfig({ partnerId, rpcUrls });
|
|
22
|
-
|
|
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 }) }));
|
|
23
50
|
}
|
|
@@ -2,4 +2,15 @@
|
|
|
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():
|
|
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
|
+
};
|
|
@@ -1 +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 +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
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
interface ConfigStore {
|
|
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
|
+
setConfig: (config: Partial<Omit<ConfigStore, "setConfig">>) => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Zustand store for B3 configuration
|
|
21
|
+
* NOT persisted - these are developer-set configuration values
|
|
22
|
+
*/
|
|
23
|
+
export declare const useB3ConfigStore: import("zustand").UseBoundStore<import("zustand").StoreApi<ConfigStore>>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
/**
|
|
3
|
+
* Default permissions configuration for B3 provider
|
|
4
|
+
*/
|
|
5
|
+
const DEFAULT_PERMISSIONS = {
|
|
6
|
+
approvedTargets: ["0xa8e42121e318e3D3BeD7f5969AF6D360045317DD"],
|
|
7
|
+
nativeTokenLimitPerTransaction: 0.1,
|
|
8
|
+
startDate: new Date(),
|
|
9
|
+
endDate: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365), // 1 year from now
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Zustand store for B3 configuration
|
|
13
|
+
* NOT persisted - these are developer-set configuration values
|
|
14
|
+
*/
|
|
15
|
+
export const useB3ConfigStore = create(set => ({
|
|
16
|
+
accountOverride: undefined,
|
|
17
|
+
automaticallySetFirstEoa: false,
|
|
18
|
+
environment: "development",
|
|
19
|
+
defaultPermissions: DEFAULT_PERMISSIONS,
|
|
20
|
+
theme: "light",
|
|
21
|
+
clientType: "rest",
|
|
22
|
+
partnerId: "",
|
|
23
|
+
stripePublishableKey: undefined,
|
|
24
|
+
createClientReferenceId: undefined,
|
|
25
|
+
enableTurnkey: false,
|
|
26
|
+
setConfig: config => set(state => ({ ...state, ...config })),
|
|
27
|
+
}));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { useAuthStore } from "./useAuthStore";
|
|
2
|
+
export { useB3ConfigStore } from "./configStore";
|
|
2
3
|
export { useModalStore } from "./useModalStore";
|
|
3
4
|
export { useRecentAddressesStore } from "./useRecentAddressesStore";
|
|
4
5
|
export type { AnySpendBuySpinProps, AnySpendFundTournamentProps, AnySpendJoinTournamentProps, AnySpendModalProps, AnySpendNftProps, AnySpendOrderHistoryProps, AnySpendStakeB3Props, AnyspendOrderDetailsProps, ManageAccountModalProps, ModalContentType, RequestPermissionsModalProps, SignInWithB3ModalProps, } from "./useModalStore";
|