@b3dotfun/sdk 0.0.58-alpha.2 → 0.0.58-alpha.3

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.
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.CryptoPaymentMethodType = void 0;
5
5
  exports.CryptoPaymentMethod = CryptoPaymentMethod;
6
6
  const jsx_runtime_1 = require("react/jsx-runtime");
7
+ const utils_1 = require("../../../../anyspend/utils");
7
8
  const react_1 = require("../../../../global-account/react");
8
9
  const cn_1 = require("../../../../shared/utils/cn");
9
10
  const formatAddress_1 = require("../../../../shared/utils/formatAddress");
@@ -32,6 +33,8 @@ function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentMethod,
32
33
  const [showWalletModal, setShowWalletModal] = (0, react_3.useState)(false);
33
34
  const setActiveWallet = (0, react_4.useSetActiveWallet)();
34
35
  const { data: eoaWalletInfo } = (0, react_4.useWalletInfo)(connectedEOAWallet?.id);
36
+ const activeWallet = (0, react_4.useActiveWallet)();
37
+ const setGlobalAccountWallet = (0, utils_1.useGlobalWalletState)(state => state.setGlobalAccountWallet);
35
38
  const isConnected = !!connectedEOAWallet;
36
39
  const globalAddress = connectedSmartWallet?.getAccount()?.address;
37
40
  // Helper function to check if two addresses are the same
@@ -173,6 +176,7 @@ function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentMethod,
173
176
  return ((0, jsx_runtime_1.jsxs)("div", { className: "crypto-payment-method mx-auto h-fit w-[460px] max-w-full", children: [(0, jsx_runtime_1.jsxs)("div", { className: (0, cn_1.cn)("relative flex flex-col gap-10"), children: [(0, jsx_runtime_1.jsx)("button", { onClick: onBack, className: "text-as-quaternary hover:text-as-primary absolute flex h-8 w-8 items-center justify-center rounded-lg transition-colors", children: (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronLeft, { className: "h-6 w-6" }) }), (0, jsx_runtime_1.jsx)("div", { className: "flex items-center justify-around gap-4", children: (0, jsx_runtime_1.jsx)("div", { className: "flex-1 text-center", children: (0, jsx_runtime_1.jsx)("h2", { className: "text-as-primary text-lg font-semibold", children: "Select a payment method" }) }) }), (0, jsx_runtime_1.jsxs)("div", { className: "crypto-payment-methods flex flex-col gap-4", children: [(shouldShowConnectedEOA || shouldShowWagmiWallet || globalAddress) && ((0, jsx_runtime_1.jsxs)("div", { className: "installed-wallets", children: [(0, jsx_runtime_1.jsx)("h3", { className: "text-as-primary/80 mb-3 text-sm font-medium", children: "Connected wallets" }), (0, jsx_runtime_1.jsxs)("div", { className: "space-y-2", children: [shouldShowConnectedEOA && ((0, jsx_runtime_1.jsx)("button", { onClick: () => {
174
177
  setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
175
178
  onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
179
+ setGlobalAccountWallet(activeWallet);
176
180
  setActiveWallet(connectedEOAWallet);
177
181
  sonner_1.toast.success(`Selected ${eoaWalletInfo?.name || connector?.name || "wallet"}`);
178
182
  }, className: (0, cn_1.cn)("crypto-payment-method-connect-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md", selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
@@ -0,0 +1,7 @@
1
+ import type { Wallet } from "thirdweb/wallets";
2
+ interface GlobalWalletState {
3
+ globalAccountWallet?: Wallet;
4
+ setGlobalAccountWallet: (account?: Wallet) => void;
5
+ }
6
+ export declare const useGlobalWalletState: import("zustand").UseBoundStore<import("zustand").StoreApi<GlobalWalletState>>;
7
+ export {};
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useGlobalWalletState = void 0;
4
+ const zustand_1 = require("zustand");
5
+ exports.useGlobalWalletState = (0, zustand_1.create)(set => ({
6
+ globalAccountWallet: undefined,
7
+ setGlobalAccountWallet: account => set({ globalAccountWallet: account }),
8
+ }));
@@ -1,3 +1,4 @@
1
+ export * from "./accountStore";
1
2
  export * from "./address";
2
3
  export * from "./chain";
3
4
  export * from "./format";
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./accountStore"), exports);
17
18
  __exportStar(require("./address"), exports);
18
19
  __exportStar(require("./chain"), exports);
19
20
  __exportStar(require("./format"), exports);
@@ -5,9 +5,11 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("../../../anyspend/react");
6
6
  const AnyspendDepositHype_1 = require("../../../anyspend/react/components/AnyspendDepositHype");
7
7
  const AnySpendStakeUpside_1 = require("../../../anyspend/react/components/AnySpendStakeUpside");
8
+ const utils_1 = require("../../../anyspend/utils");
8
9
  const react_2 = require("../../../global-account/react");
9
10
  const cn_1 = require("../../../shared/utils/cn");
10
11
  const debug_1 = require("../../../shared/utils/debug");
12
+ const react_3 = require("react");
11
13
  const AvatarEditor_1 = require("./AvatarEditor/AvatarEditor");
12
14
  const useB3_1 = require("./B3Provider/useB3");
13
15
  const LinkAccount_1 = require("./LinkAccount/LinkAccount");
@@ -16,11 +18,26 @@ const RequestPermissions_1 = require("./RequestPermissions/RequestPermissions");
16
18
  const SignInWithB3Flow_1 = require("./SignInWithB3/SignInWithB3Flow");
17
19
  const dialog_1 = require("./ui/dialog");
18
20
  const drawer_1 = require("./ui/drawer");
21
+ const react_4 = require("thirdweb/react");
19
22
  const debug = (0, debug_1.debugB3React)("B3DynamicModal");
20
23
  function B3DynamicModal() {
21
24
  const { isOpen, setB3ModalOpen, contentType, history, navigateBack } = (0, react_2.useModalStore)();
22
25
  const { theme } = (0, useB3_1.useB3)();
23
26
  const isMobile = (0, react_2.useIsMobile)();
27
+ const prevIsOpenRef = (0, react_3.useRef)(isOpen);
28
+ const globalAccountWallet = (0, utils_1.useGlobalWalletState)(state => state.globalAccountWallet);
29
+ const setGlobalAccountWallet = (0, utils_1.useGlobalWalletState)(state => state.setGlobalAccountWallet);
30
+ const setActiveWallet = (0, react_4.useSetActiveWallet)();
31
+ // anyspend cleanup global account chnages by setting account back
32
+ (0, react_3.useEffect)(() => {
33
+ if (prevIsOpenRef.current && !isOpen) {
34
+ if (globalAccountWallet) {
35
+ setActiveWallet(globalAccountWallet);
36
+ setGlobalAccountWallet(undefined);
37
+ }
38
+ }
39
+ prevIsOpenRef.current = isOpen;
40
+ }, [isOpen, globalAccountWallet, setActiveWallet, setGlobalAccountWallet]);
24
41
  // Define arrays for different modal type groups
25
42
  const fullWidthTypes = [
26
43
  "anySpend",
@@ -1,5 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useGlobalWalletState } from "../../../../anyspend/utils/index.js";
3
4
  import { useAccountWallet } from "../../../../global-account/react/index.js";
4
5
  import { cn } from "../../../../shared/utils/cn.js";
5
6
  import { shortenAddress } from "../../../../shared/utils/formatAddress.js";
@@ -9,7 +10,7 @@ import { ChevronLeft, ChevronRightCircle, Wallet, X, ZapIcon } from "lucide-reac
9
10
  import { useState } from "react";
10
11
  import { createPortal } from "react-dom";
11
12
  import { toast } from "sonner";
12
- import { useSetActiveWallet, useWalletInfo } from "thirdweb/react";
13
+ import { useActiveWallet, useSetActiveWallet, useWalletInfo } from "thirdweb/react";
13
14
  import { createWallet } from "thirdweb/wallets";
14
15
  import { useAccount, useConnect, useDisconnect, useWalletClient } from "wagmi";
15
16
  export var CryptoPaymentMethodType;
@@ -28,6 +29,8 @@ export function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentM
28
29
  const [showWalletModal, setShowWalletModal] = useState(false);
29
30
  const setActiveWallet = useSetActiveWallet();
30
31
  const { data: eoaWalletInfo } = useWalletInfo(connectedEOAWallet?.id);
32
+ const activeWallet = useActiveWallet();
33
+ const setGlobalAccountWallet = useGlobalWalletState(state => state.setGlobalAccountWallet);
31
34
  const isConnected = !!connectedEOAWallet;
32
35
  const globalAddress = connectedSmartWallet?.getAccount()?.address;
33
36
  // Helper function to check if two addresses are the same
@@ -169,6 +172,7 @@ export function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentM
169
172
  return (_jsxs("div", { className: "crypto-payment-method mx-auto h-fit w-[460px] max-w-full", children: [_jsxs("div", { className: cn("relative flex flex-col gap-10"), children: [_jsx("button", { onClick: onBack, className: "text-as-quaternary hover:text-as-primary absolute flex h-8 w-8 items-center justify-center rounded-lg transition-colors", children: _jsx(ChevronLeft, { className: "h-6 w-6" }) }), _jsx("div", { className: "flex items-center justify-around gap-4", children: _jsx("div", { className: "flex-1 text-center", children: _jsx("h2", { className: "text-as-primary text-lg font-semibold", children: "Select a payment method" }) }) }), _jsxs("div", { className: "crypto-payment-methods flex flex-col gap-4", children: [(shouldShowConnectedEOA || shouldShowWagmiWallet || globalAddress) && (_jsxs("div", { className: "installed-wallets", children: [_jsx("h3", { className: "text-as-primary/80 mb-3 text-sm font-medium", children: "Connected wallets" }), _jsxs("div", { className: "space-y-2", children: [shouldShowConnectedEOA && (_jsx("button", { onClick: () => {
170
173
  setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
171
174
  onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
175
+ setGlobalAccountWallet(activeWallet);
172
176
  setActiveWallet(connectedEOAWallet);
173
177
  toast.success(`Selected ${eoaWalletInfo?.name || connector?.name || "wallet"}`);
174
178
  }, className: cn("crypto-payment-method-connect-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md", selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
@@ -0,0 +1,7 @@
1
+ import type { Wallet } from "thirdweb/wallets";
2
+ interface GlobalWalletState {
3
+ globalAccountWallet?: Wallet;
4
+ setGlobalAccountWallet: (account?: Wallet) => void;
5
+ }
6
+ export declare const useGlobalWalletState: import("zustand").UseBoundStore<import("zustand").StoreApi<GlobalWalletState>>;
7
+ export {};
@@ -0,0 +1,5 @@
1
+ import { create } from "zustand";
2
+ export const useGlobalWalletState = create(set => ({
3
+ globalAccountWallet: undefined,
4
+ setGlobalAccountWallet: account => set({ globalAccountWallet: account }),
5
+ }));
@@ -1,3 +1,4 @@
1
+ export * from "./accountStore";
1
2
  export * from "./address";
2
3
  export * from "./chain";
3
4
  export * from "./format";
@@ -1,3 +1,4 @@
1
+ export * from "./accountStore.js";
1
2
  export * from "./address.js";
2
3
  export * from "./chain.js";
3
4
  export * from "./format.js";
@@ -2,9 +2,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { AnySpend, AnySpendBondKit, AnySpendBuySpin, AnySpendNFT, AnyspendSignatureMint, AnySpendStakeB3, AnySpendTournament, OrderHistory, } from "../../../anyspend/react/index.js";
3
3
  import { AnySpendDepositHype } from "../../../anyspend/react/components/AnyspendDepositHype.js";
4
4
  import { AnySpendStakeUpside } from "../../../anyspend/react/components/AnySpendStakeUpside.js";
5
+ import { useGlobalWalletState } from "../../../anyspend/utils/index.js";
5
6
  import { useIsMobile, useModalStore } from "../../../global-account/react/index.js";
6
7
  import { cn } from "../../../shared/utils/cn.js";
7
8
  import { debugB3React } from "../../../shared/utils/debug.js";
9
+ import { useEffect, useRef } from "react";
8
10
  import { AvatarEditor } from "./AvatarEditor/AvatarEditor.js";
9
11
  import { useB3 } from "./B3Provider/useB3.js";
10
12
  import { LinkAccount } from "./LinkAccount/LinkAccount.js";
@@ -13,11 +15,26 @@ import { RequestPermissions } from "./RequestPermissions/RequestPermissions.js";
13
15
  import { SignInWithB3Flow } from "./SignInWithB3/SignInWithB3Flow.js";
14
16
  import { Dialog, DialogContent, DialogDescription, DialogTitle } from "./ui/dialog.js";
15
17
  import { Drawer, DrawerContent, DrawerDescription, DrawerTitle } from "./ui/drawer.js";
18
+ import { useSetActiveWallet } from "thirdweb/react";
16
19
  const debug = debugB3React("B3DynamicModal");
17
20
  export function B3DynamicModal() {
18
21
  const { isOpen, setB3ModalOpen, contentType, history, navigateBack } = useModalStore();
19
22
  const { theme } = useB3();
20
23
  const isMobile = useIsMobile();
24
+ const prevIsOpenRef = useRef(isOpen);
25
+ const globalAccountWallet = useGlobalWalletState(state => state.globalAccountWallet);
26
+ const setGlobalAccountWallet = useGlobalWalletState(state => state.setGlobalAccountWallet);
27
+ const setActiveWallet = useSetActiveWallet();
28
+ // anyspend cleanup global account chnages by setting account back
29
+ useEffect(() => {
30
+ if (prevIsOpenRef.current && !isOpen) {
31
+ if (globalAccountWallet) {
32
+ setActiveWallet(globalAccountWallet);
33
+ setGlobalAccountWallet(undefined);
34
+ }
35
+ }
36
+ prevIsOpenRef.current = isOpen;
37
+ }, [isOpen, globalAccountWallet, setActiveWallet, setGlobalAccountWallet]);
21
38
  // Define arrays for different modal type groups
22
39
  const fullWidthTypes = [
23
40
  "anySpend",
@@ -0,0 +1,7 @@
1
+ import type { Wallet } from "thirdweb/wallets";
2
+ interface GlobalWalletState {
3
+ globalAccountWallet?: Wallet;
4
+ setGlobalAccountWallet: (account?: Wallet) => void;
5
+ }
6
+ export declare const useGlobalWalletState: import("zustand").UseBoundStore<import("zustand").StoreApi<GlobalWalletState>>;
7
+ export {};
@@ -1,3 +1,4 @@
1
+ export * from "./accountStore";
1
2
  export * from "./address";
2
3
  export * from "./chain";
3
4
  export * from "./format";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b3dotfun/sdk",
3
- "version": "0.0.58-alpha.2",
3
+ "version": "0.0.58-alpha.3",
4
4
  "source": "src/index.ts",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "react-native": "./dist/cjs/index.native.js",
@@ -1,5 +1,6 @@
1
1
  "use client";
2
2
 
3
+ import { useGlobalWalletState } from "@b3dotfun/sdk/anyspend/utils";
3
4
  import { useAccountWallet } from "@b3dotfun/sdk/global-account/react";
4
5
  import { cn } from "@b3dotfun/sdk/shared/utils/cn";
5
6
  import { shortenAddress } from "@b3dotfun/sdk/shared/utils/formatAddress";
@@ -9,7 +10,7 @@ import { ChevronLeft, ChevronRightCircle, Wallet, X, ZapIcon } from "lucide-reac
9
10
  import { useState } from "react";
10
11
  import { createPortal } from "react-dom";
11
12
  import { toast } from "sonner";
12
- import { useSetActiveWallet, useWalletInfo } from "thirdweb/react";
13
+ import { useActiveWallet, useSetActiveWallet, useWalletInfo } from "thirdweb/react";
13
14
  import { WalletId, createWallet } from "thirdweb/wallets";
14
15
  import { useAccount, useConnect, useDisconnect, useWalletClient } from "wagmi";
15
16
 
@@ -51,10 +52,12 @@ export function CryptoPaymentMethod({
51
52
  const { disconnect } = useDisconnect();
52
53
  const { data: walletClient } = useWalletClient();
53
54
  const [showWalletModal, setShowWalletModal] = useState(false);
54
-
55
55
  const setActiveWallet = useSetActiveWallet();
56
56
  const { data: eoaWalletInfo } = useWalletInfo(connectedEOAWallet?.id);
57
57
 
58
+ const activeWallet = useActiveWallet();
59
+ const setGlobalAccountWallet = useGlobalWalletState(state => state.setGlobalAccountWallet);
60
+
58
61
  const isConnected = !!connectedEOAWallet;
59
62
  const globalAddress = connectedSmartWallet?.getAccount()?.address;
60
63
 
@@ -233,6 +236,7 @@ export function CryptoPaymentMethod({
233
236
  onClick={() => {
234
237
  setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
235
238
  onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
239
+ setGlobalAccountWallet(activeWallet);
236
240
  setActiveWallet(connectedEOAWallet);
237
241
  toast.success(`Selected ${eoaWalletInfo?.name || connector?.name || "wallet"}`);
238
242
  }}
@@ -0,0 +1,12 @@
1
+ import type { Wallet } from "thirdweb/wallets";
2
+ import { create } from "zustand";
3
+
4
+ interface GlobalWalletState {
5
+ globalAccountWallet?: Wallet;
6
+ setGlobalAccountWallet: (account?: Wallet) => void;
7
+ }
8
+
9
+ export const useGlobalWalletState = create<GlobalWalletState>(set => ({
10
+ globalAccountWallet: undefined,
11
+ setGlobalAccountWallet: account => set({ globalAccountWallet: account }),
12
+ }));
@@ -1,3 +1,4 @@
1
+ export * from "./accountStore";
1
2
  export * from "./address";
2
3
  export * from "./chain";
3
4
  export * from "./format";
@@ -10,9 +10,11 @@ import {
10
10
  } from "@b3dotfun/sdk/anyspend/react";
11
11
  import { AnySpendDepositHype } from "@b3dotfun/sdk/anyspend/react/components/AnyspendDepositHype";
12
12
  import { AnySpendStakeUpside } from "@b3dotfun/sdk/anyspend/react/components/AnySpendStakeUpside";
13
+ import { useGlobalWalletState } from "@b3dotfun/sdk/anyspend/utils";
13
14
  import { useIsMobile, useModalStore } from "@b3dotfun/sdk/global-account/react";
14
15
  import { cn } from "@b3dotfun/sdk/shared/utils/cn";
15
16
  import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
17
+ import { useEffect, useRef } from "react";
16
18
  import { AvatarEditor } from "./AvatarEditor/AvatarEditor";
17
19
  import { useB3 } from "./B3Provider/useB3";
18
20
  import { LinkAccount } from "./LinkAccount/LinkAccount";
@@ -21,6 +23,7 @@ import { RequestPermissions } from "./RequestPermissions/RequestPermissions";
21
23
  import { SignInWithB3Flow } from "./SignInWithB3/SignInWithB3Flow";
22
24
  import { Dialog, DialogContent, DialogDescription, DialogTitle } from "./ui/dialog";
23
25
  import { Drawer, DrawerContent, DrawerDescription, DrawerTitle } from "./ui/drawer";
26
+ import { useSetActiveWallet } from "thirdweb/react";
24
27
 
25
28
  const debug = debugB3React("B3DynamicModal");
26
29
 
@@ -28,6 +31,23 @@ export function B3DynamicModal() {
28
31
  const { isOpen, setB3ModalOpen, contentType, history, navigateBack } = useModalStore();
29
32
  const { theme } = useB3();
30
33
  const isMobile = useIsMobile();
34
+ const prevIsOpenRef = useRef(isOpen);
35
+
36
+ const globalAccountWallet = useGlobalWalletState(state => state.globalAccountWallet);
37
+ const setGlobalAccountWallet = useGlobalWalletState(state => state.setGlobalAccountWallet);
38
+ const setActiveWallet = useSetActiveWallet();
39
+
40
+ // anyspend cleanup global account chnages by setting account back
41
+ useEffect(() => {
42
+ if (prevIsOpenRef.current && !isOpen) {
43
+ if (globalAccountWallet) {
44
+ setActiveWallet(globalAccountWallet);
45
+ setGlobalAccountWallet(undefined);
46
+ }
47
+ }
48
+
49
+ prevIsOpenRef.current = isOpen;
50
+ }, [isOpen, globalAccountWallet, setActiveWallet, setGlobalAccountWallet]);
31
51
 
32
52
  // Define arrays for different modal type groups
33
53
  const fullWidthTypes = [