@b3dotfun/sdk 0.0.1-alpha.23 → 0.0.1-alpha.4

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 (87) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpend.d.ts +1 -2
  2. package/dist/cjs/anyspend/react/components/AnySpend.js +4 -4
  3. package/dist/cjs/anyspend/react/components/AnySpendBuySpin.d.ts +1 -2
  4. package/dist/cjs/anyspend/react/components/AnySpendBuySpin.js +51 -124
  5. package/dist/cjs/anyspend/utils/chain.js +0 -3
  6. package/dist/cjs/global-account/react/components/B3DynamicModal.js +2 -2
  7. package/dist/{esm/global-account/react/components/B3Provider → cjs/global-account/react/components}/B3Provider.d.ts +29 -3
  8. package/dist/cjs/global-account/react/components/{B3Provider/B3Provider.js → B3Provider.js} +34 -6
  9. package/dist/cjs/global-account/react/components/{B3Provider/B3Provider.native.d.ts → B3Provider.native.d.ts} +25 -2
  10. package/dist/cjs/global-account/react/components/{B3Provider/B3Provider.native.js → B3Provider.native.js} +28 -5
  11. package/dist/cjs/global-account/react/components/StyleRoot.js +2 -2
  12. package/dist/cjs/global-account/react/components/index.d.ts +6 -8
  13. package/dist/cjs/global-account/react/components/index.js +16 -18
  14. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +0 -2
  15. package/dist/cjs/global-account/types/chain-networks.d.ts +34 -34
  16. package/dist/cjs/global-account/types/feature-flags.d.ts +5 -5
  17. package/dist/cjs/shared/constants/chains/b3Chain.d.ts +1 -1
  18. package/dist/cjs/shared/constants/chains/supported.d.ts +3 -4
  19. package/dist/cjs/shared/constants/chains/supported.js +1 -3
  20. package/dist/cjs/shared/utils/chains.js +0 -4
  21. package/dist/esm/anyspend/react/components/AnySpend.d.ts +1 -2
  22. package/dist/esm/anyspend/react/components/AnySpend.js +4 -4
  23. package/dist/esm/anyspend/react/components/AnySpendBuySpin.d.ts +1 -2
  24. package/dist/esm/anyspend/react/components/AnySpendBuySpin.js +51 -124
  25. package/dist/esm/anyspend/utils/chain.js +0 -3
  26. package/dist/esm/global-account/react/components/B3DynamicModal.js +1 -1
  27. package/dist/{cjs/global-account/react/components/B3Provider → esm/global-account/react/components}/B3Provider.d.ts +29 -3
  28. package/dist/esm/global-account/react/components/{B3Provider/B3Provider.js → B3Provider.js} +32 -5
  29. package/dist/esm/global-account/react/components/{B3Provider/B3Provider.native.d.ts → B3Provider.native.d.ts} +25 -2
  30. package/dist/esm/global-account/react/components/{B3Provider/B3Provider.native.js → B3Provider.native.js} +26 -5
  31. package/dist/esm/global-account/react/components/StyleRoot.js +1 -1
  32. package/dist/esm/global-account/react/components/index.d.ts +6 -8
  33. package/dist/esm/global-account/react/components/index.js +5 -7
  34. package/dist/esm/global-account/react/stores/useModalStore.d.ts +0 -2
  35. package/dist/esm/global-account/types/chain-networks.d.ts +34 -34
  36. package/dist/esm/global-account/types/feature-flags.d.ts +5 -5
  37. package/dist/esm/shared/constants/chains/b3Chain.d.ts +1 -1
  38. package/dist/esm/shared/constants/chains/supported.d.ts +3 -4
  39. package/dist/esm/shared/constants/chains/supported.js +0 -2
  40. package/dist/esm/shared/utils/chains.js +0 -4
  41. package/dist/styles/index.css +1 -1
  42. package/dist/types/anyspend/react/components/AnySpend.d.ts +1 -2
  43. package/dist/types/anyspend/react/components/AnySpendBuySpin.d.ts +1 -2
  44. package/dist/types/global-account/react/components/{B3Provider/B3Provider.d.ts → B3Provider.d.ts} +28 -2
  45. package/dist/types/global-account/react/components/{B3Provider/B3Provider.native.d.ts → B3Provider.native.d.ts} +24 -1
  46. package/dist/types/global-account/react/components/index.d.ts +6 -8
  47. package/dist/types/global-account/react/stores/useModalStore.d.ts +0 -2
  48. package/dist/types/global-account/types/chain-networks.d.ts +34 -34
  49. package/dist/types/global-account/types/feature-flags.d.ts +5 -5
  50. package/dist/types/shared/constants/chains/b3Chain.d.ts +1 -1
  51. package/dist/types/shared/constants/chains/supported.d.ts +3 -4
  52. package/package.json +11 -25
  53. package/src/anyspend/react/components/AnySpend.tsx +5 -6
  54. package/src/anyspend/react/components/AnySpendBuySpin.tsx +180 -233
  55. package/src/anyspend/utils/chain.ts +0 -3
  56. package/src/global-account/react/components/B3DynamicModal.tsx +1 -1
  57. package/src/global-account/react/components/{B3Provider/B3Provider.native.tsx → B3Provider.native.tsx} +45 -4
  58. package/src/global-account/react/components/{B3Provider/B3Provider.tsx → B3Provider.tsx} +53 -4
  59. package/src/global-account/react/components/StyleRoot.tsx +1 -1
  60. package/src/global-account/react/components/index.ts +6 -8
  61. package/src/global-account/react/stores/useModalStore.ts +0 -2
  62. package/src/shared/constants/chains/supported.ts +0 -2
  63. package/src/shared/utils/chains.ts +1 -4
  64. package/dist/cjs/anyspend/index.native.d.ts +0 -13
  65. package/dist/cjs/anyspend/index.native.js +0 -35
  66. package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +0 -25
  67. package/dist/cjs/global-account/react/components/B3Provider/types.js +0 -20
  68. package/dist/cjs/global-account/react/components/B3Provider/useB3.d.ts +0 -5
  69. package/dist/cjs/global-account/react/components/B3Provider/useB3.js +0 -17
  70. package/dist/cjs/global-account/react/index.native.d.ts +0 -7
  71. package/dist/cjs/global-account/react/index.native.js +0 -21
  72. package/dist/esm/anyspend/index.native.d.ts +0 -13
  73. package/dist/esm/anyspend/index.native.js +0 -19
  74. package/dist/esm/global-account/react/components/B3Provider/types.d.ts +0 -25
  75. package/dist/esm/global-account/react/components/B3Provider/types.js +0 -17
  76. package/dist/esm/global-account/react/components/B3Provider/useB3.d.ts +0 -5
  77. package/dist/esm/global-account/react/components/B3Provider/useB3.js +0 -14
  78. package/dist/esm/global-account/react/index.native.d.ts +0 -7
  79. package/dist/esm/global-account/react/index.native.js +0 -11
  80. package/dist/types/anyspend/index.native.d.ts +0 -13
  81. package/dist/types/global-account/react/components/B3Provider/types.d.ts +0 -25
  82. package/dist/types/global-account/react/components/B3Provider/useB3.d.ts +0 -5
  83. package/dist/types/global-account/react/index.native.d.ts +0 -7
  84. package/src/anyspend/index.native.ts +0 -24
  85. package/src/global-account/react/components/B3Provider/types.ts +0 -40
  86. package/src/global-account/react/components/B3Provider/useB3.ts +0 -17
  87. package/src/global-account/react/index.native.ts +0 -14
@@ -11,7 +11,7 @@ export declare enum PanelView {
11
11
  LOADING = 3,
12
12
  FIAT_PAYMENT = 4
13
13
  }
14
- export declare function AnySpend({ destinationTokenAddress, destinationTokenChainId, isMainnet, mode, defaultActiveTab, loadOrder, hideTransactionHistoryButton, recipientAddress: recipientAddressFromProps }: {
14
+ export declare function AnySpend({ destinationTokenAddress, destinationTokenChainId, isMainnet, mode, defaultActiveTab, loadOrder, hideTransactionHistoryButton }: {
15
15
  destinationTokenAddress?: string;
16
16
  destinationTokenChainId?: number;
17
17
  isMainnet?: boolean;
@@ -19,5 +19,4 @@ export declare function AnySpend({ destinationTokenAddress, destinationTokenChai
19
19
  defaultActiveTab?: "crypto" | "fiat";
20
20
  loadOrder?: string;
21
21
  hideTransactionHistoryButton?: boolean;
22
- recipientAddress?: string;
23
22
  }): import("react/jsx-runtime").JSX.Element;
@@ -9,8 +9,8 @@ exports.AnySpend = AnySpend;
9
9
  const jsx_runtime_1 = require("react/jsx-runtime");
10
10
  const anyspend_1 = require("../../../anyspend");
11
11
  const react_1 = require("../../../global-account/react");
12
- const cn_1 = require("../../../shared/utils/cn");
13
12
  const formatAddress_1 = require("../../../shared/utils/formatAddress");
13
+ const cn_1 = require("../../../shared/utils/cn");
14
14
  const number_1 = require("../../../shared/utils/number");
15
15
  const framer_motion_1 = require("framer-motion");
16
16
  const invariant_1 = __importDefault(require("invariant"));
@@ -36,7 +36,7 @@ var PanelView;
36
36
  PanelView[PanelView["FIAT_PAYMENT"] = 4] = "FIAT_PAYMENT";
37
37
  })(PanelView || (exports.PanelView = PanelView = {}));
38
38
  const ANYSPEND_RECIPIENTS_KEY = "anyspend_recipients";
39
- function AnySpend({ destinationTokenAddress, destinationTokenChainId, isMainnet = true, mode = "modal", defaultActiveTab = "crypto", loadOrder, hideTransactionHistoryButton, recipientAddress: recipientAddressFromProps }) {
39
+ function AnySpend({ destinationTokenAddress, destinationTokenChainId, isMainnet = true, mode = "modal", defaultActiveTab = "crypto", loadOrder, hideTransactionHistoryButton }) {
40
40
  const searchParams = (0, react_1.useSearchParamsSSR)();
41
41
  const router = (0, react_1.useRouter)();
42
42
  // Determine if we're in "buy mode" based on whether destination token props are provided
@@ -279,8 +279,8 @@ function AnySpend({ destinationTokenAddress, destinationTokenChainId, isMainnet
279
279
  const { address: globalAddress, wallet: globalWallet } = (0, react_1.useAccountWallet)();
280
280
  // Set default recipient address when wallet changes
281
281
  (0, react_2.useEffect)(() => {
282
- setRecipientAddress(recipientAddressFromProps || globalAddress);
283
- }, [recipientAddressFromProps, globalAddress]);
282
+ setRecipientAddress(globalAddress);
283
+ }, [globalAddress]);
284
284
  // Get anyspend price
285
285
  const activeInputAmountInWei = isSrcInputDirty
286
286
  ? (0, viem_1.parseUnits)(srcAmount.replaceAll(",", ""), selectedSrcToken.decimals).toString()
@@ -1,10 +1,9 @@
1
- export declare function AnySpendBuySpin({ isMainnet, loadOrder, mode, spinwheelContractAddress, chainId, recipientAddress, prefillQuantity, onSuccess }: {
1
+ export declare function AnySpendBuySpin({ isMainnet, loadOrder, mode, spinwheelContractAddress, chainId, recipientAddress, onSuccess }: {
2
2
  isMainnet?: boolean;
3
3
  loadOrder?: string;
4
4
  mode?: "modal" | "page";
5
5
  spinwheelContractAddress: string;
6
6
  chainId: number;
7
7
  recipientAddress: string;
8
- prefillQuantity?: string;
9
8
  onSuccess?: (txHash?: string) => void;
10
9
  }): import("react/jsx-runtime").JSX.Element;
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.AnySpendBuySpin = AnySpendBuySpin;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const anyspend_1 = require("../../../anyspend");
9
- const supported_1 = require("../../../shared/constants/chains/supported");
10
9
  const EthIcon_1 = require("./icons/EthIcon");
11
10
  const SolIcon_1 = require("./icons/SolIcon");
12
11
  const USDCIcon_1 = require("./icons/USDCIcon");
@@ -18,6 +17,7 @@ const lucide_react_1 = require("lucide-react");
18
17
  const react_3 = require("react");
19
18
  const sonner_1 = require("sonner");
20
19
  const viem_1 = require("viem");
20
+ const chains_1 = require("viem/chains");
21
21
  const wagmi_1 = require("wagmi");
22
22
  const AnySpendCustom_1 = require("./AnySpendCustom");
23
23
  const SPIN_WHEEL_ABI = [
@@ -49,37 +49,8 @@ const SPIN_WHEEL_ABI = [
49
49
  outputs: [],
50
50
  stateMutability: "payable",
51
51
  type: "function"
52
- },
53
- {
54
- inputs: [],
55
- name: "getWheelInfo",
56
- outputs: [
57
- { internalType: "address", name: "creator_", type: "address" },
58
- { internalType: "uint256", name: "startTime_", type: "uint256" },
59
- { internalType: "uint256", name: "endTime_", type: "uint256" },
60
- { internalType: "uint256", name: "totalPrizesAvailable_", type: "uint256" },
61
- { internalType: "uint256", name: "prizesRequestedCount_", type: "uint256" },
62
- { internalType: "enum SpinWheelV2.WheelState", name: "state_", type: "uint8" }
63
- ],
64
- stateMutability: "view",
65
- type: "function"
66
52
  }
67
53
  ];
68
- function getWheelStatus(wheelInfo) {
69
- const now = BigInt(Math.floor(Date.now() / 1000));
70
- console.log("@@anyspend-buy-spin:now:", now);
71
- console.log("@@anyspend-buy-spin:wheelInfo:", wheelInfo);
72
- if (now < wheelInfo.startTime_) {
73
- return "not_started";
74
- }
75
- if (now > wheelInfo.endTime_) {
76
- return "ended";
77
- }
78
- if (wheelInfo.totalPrizesAvailable_ <= wheelInfo.prizesRequestedCount_) {
79
- return "sold_out";
80
- }
81
- return "active";
82
- }
83
54
  function generateEncodedDataForBuyEntriesAndSpin(user, quantity) {
84
55
  (0, invariant_1.default)(BigInt(quantity) > 0, "Quantity must be greater than zero");
85
56
  console.log("@@anyspend-buy-spin:encoded-data:", { user, quantity });
@@ -91,17 +62,16 @@ function generateEncodedDataForBuyEntriesAndSpin(user, quantity) {
91
62
  return encodedData;
92
63
  }
93
64
  const basePublicClient = (0, viem_1.createPublicClient)({
94
- chain: supported_1.baseMainnet,
65
+ chain: chains_1.base,
95
66
  transport: (0, viem_1.http)()
96
67
  });
97
- function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwheelContractAddress, chainId, recipientAddress, prefillQuantity, onSuccess }) {
68
+ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwheelContractAddress, chainId, recipientAddress, onSuccess }) {
98
69
  const hasMounted = (0, react_2.useHasMounted)();
99
70
  const { setB3ModalOpen } = (0, react_2.useModalStore)();
100
71
  // Payment config state
101
72
  const [paymentConfig, setPaymentConfig] = (0, react_3.useState)(null);
102
73
  const [isLoadingConfig, setIsLoadingConfig] = (0, react_3.useState)(true);
103
74
  const [configError, setConfigError] = (0, react_3.useState)("");
104
- const [wheelInfo, setWheelInfo] = (0, react_3.useState)(null);
105
75
  // Fetch B3 token balance
106
76
  const { formattedBalance: b3Balance, isLoading: isBalanceLoading, rawBalance: b3RawBalance } = (0, react_2.useTokenBalance)({
107
77
  token: anyspend_1.B3_TOKEN
@@ -113,29 +83,22 @@ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwhee
113
83
  // State for direct buying flow (when user has B3 tokens)
114
84
  const [isBuying, setIsBuying] = (0, react_3.useState)(false);
115
85
  const [buyingTxHash, setBuyingTxHash] = (0, react_3.useState)("");
116
- const { isLoading: isTxPending, isSuccess: isTxSuccess, isError: isTxError, error: txError } = (0, wagmi_1.useWaitForTransactionReceipt)({
86
+ const [showSuccessModal, setShowSuccessModal] = (0, react_3.useState)(false);
87
+ // Wait for transaction confirmation
88
+ const { isLoading: isTxPending, isSuccess: isTxSuccess } = (0, wagmi_1.useWaitForTransactionReceipt)({
117
89
  hash: buyingTxHash,
118
90
  query: {
119
91
  structuralSharing: false
120
92
  }
121
93
  });
122
- // Handle transaction status
94
+ // Show success modal when transaction is confirmed
123
95
  (0, react_3.useEffect)(() => {
124
- if (!buyingTxHash)
125
- return;
126
- if (isTxSuccess) {
127
- setB3ModalOpen(false);
128
- onSuccess?.(buyingTxHash);
129
- sonner_1.toast.success("Spin purchase transaction confirmed!");
130
- setIsBuying(false);
131
- }
132
- else if (isTxError) {
133
- console.error("@@anyspend-buy-spin:tx-error:", txError);
134
- sonner_1.toast.error("Transaction failed. Please try again.");
135
- setB3ModalOpen(false);
96
+ if (isTxSuccess && buyingTxHash) {
97
+ setShowAmountPrompt(false);
98
+ setShowSuccessModal(true);
136
99
  setIsBuying(false);
137
100
  }
138
- }, [isTxSuccess, isTxError, buyingTxHash, onSuccess, setB3ModalOpen, txError]);
101
+ }, [isTxSuccess, buyingTxHash]);
139
102
  // Spin quantity state
140
103
  const [userSpinQuantity, setUserSpinQuantity] = (0, react_3.useState)("");
141
104
  const [showAmountPrompt, setShowAmountPrompt] = (0, react_3.useState)(true);
@@ -143,17 +106,9 @@ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwhee
143
106
  const [validationError, setValidationError] = (0, react_3.useState)("");
144
107
  const [displayQuantity, setDisplayQuantity] = (0, react_3.useState)("");
145
108
  const [debouncedQuantity, setDebouncedQuantity] = (0, react_3.useState)("");
146
- const [debouncedUserSpinQuantity, setDebouncedUserSpinQuantity] = (0, react_3.useState)("");
147
- (0, react_3.useEffect)(() => {
148
- if (prefillQuantity && wheelInfo) {
149
- const remainingSpins = wheelInfo.totalPrizesAvailable_ - wheelInfo.prizesRequestedCount_;
150
- const adjustedQuantity = BigInt(prefillQuantity) > remainingSpins ? remainingSpins.toString() : prefillQuantity;
151
- validateAndSetQuantity(adjustedQuantity);
152
- }
153
- }, [prefillQuantity, wheelInfo]);
154
109
  // Calculate total cost
155
110
  const totalCost = paymentConfig && userSpinQuantity ? paymentConfig.pricePerEntry * BigInt(userSpinQuantity) : BigInt(0);
156
- // Fetch payment configuration and wheel info
111
+ // Fetch payment configuration
157
112
  const fetchPaymentConfig = (0, react_3.useCallback)(async () => {
158
113
  if (!basePublicClient || !spinwheelContractAddress)
159
114
  return;
@@ -161,7 +116,7 @@ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwhee
161
116
  setIsLoadingConfig(true);
162
117
  setConfigError("");
163
118
  console.log("@@anyspend-buy-spin:fetch-config:", { spinwheelContractAddress, chainId });
164
- const [config, entryModuleAddress, wheelInfo] = await Promise.all([
119
+ const [config, entryModuleAddress] = await Promise.all([
165
120
  basePublicClient.readContract({
166
121
  address: spinwheelContractAddress,
167
122
  abi: SPIN_WHEEL_ABI,
@@ -171,11 +126,6 @@ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwhee
171
126
  address: spinwheelContractAddress,
172
127
  abi: SPIN_WHEEL_ABI,
173
128
  functionName: "entryModule"
174
- }),
175
- basePublicClient.readContract({
176
- address: spinwheelContractAddress,
177
- abi: SPIN_WHEEL_ABI,
178
- functionName: "getWheelInfo"
179
129
  })
180
130
  ]);
181
131
  const paymentConfig = {
@@ -184,16 +134,13 @@ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwhee
184
134
  paymentRecipient: config[3],
185
135
  entryModule: entryModuleAddress
186
136
  };
187
- const wheelInfoData = {
188
- creator_: wheelInfo[0],
189
- startTime_: wheelInfo[1],
190
- endTime_: wheelInfo[2],
191
- totalPrizesAvailable_: wheelInfo[3],
192
- prizesRequestedCount_: wheelInfo[4],
193
- state_: wheelInfo[5]
194
- };
137
+ console.log("@@anyspend-buy-spin:config-fetched:", {
138
+ pricePerEntry: paymentConfig.pricePerEntry.toString(),
139
+ maxEntriesPerUser: paymentConfig.maxEntriesPerUser.toString(),
140
+ paymentRecipient: paymentConfig.paymentRecipient,
141
+ entryModule: paymentConfig.entryModule
142
+ });
195
143
  setPaymentConfig(paymentConfig);
196
- setWheelInfo(wheelInfoData);
197
144
  }
198
145
  catch (error) {
199
146
  console.error("@@anyspend-buy-spin:config-error:", error);
@@ -212,7 +159,6 @@ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwhee
212
159
  (0, react_3.useEffect)(() => {
213
160
  const timer = setTimeout(() => {
214
161
  setDebouncedQuantity(displayQuantity);
215
- setDebouncedUserSpinQuantity(userSpinQuantity);
216
162
  }, 500);
217
163
  return () => clearTimeout(timer);
218
164
  }, [displayQuantity, userSpinQuantity]);
@@ -238,19 +184,12 @@ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwhee
238
184
  return;
239
185
  }
240
186
  // Check maximum entries per user (0 means no limit)
241
- if (paymentConfig && paymentConfig.maxEntriesPerUser > 0n && BigInt(numValue) > paymentConfig.maxEntriesPerUser) {
187
+ if (paymentConfig && paymentConfig.maxEntriesPerUser > BigInt(0) && BigInt(numValue) > paymentConfig.maxEntriesPerUser) {
242
188
  setIsQuantityValid(false);
243
189
  setUserSpinQuantity("");
244
190
  setValidationError(`Maximum ${paymentConfig.maxEntriesPerUser.toString()} spins allowed`);
245
191
  return;
246
192
  }
247
- // Check if quantity exceeds remaining entries
248
- if (wheelInfo && BigInt(numValue) > wheelInfo.totalPrizesAvailable_ - wheelInfo.prizesRequestedCount_) {
249
- setIsQuantityValid(false);
250
- setUserSpinQuantity("");
251
- setValidationError(`Only ${(wheelInfo.totalPrizesAvailable_ - wheelInfo.prizesRequestedCount_).toString()} spins remaining`);
252
- return;
253
- }
254
193
  setUserSpinQuantity(value);
255
194
  setIsQuantityValid(true);
256
195
  setValidationError("");
@@ -300,7 +239,7 @@ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwhee
300
239
  catch (error) {
301
240
  console.error("@@anyspend-buy-spin:error:", error);
302
241
  sonner_1.toast.error("Spin purchase failed. Please try again.");
303
- setB3ModalOpen(false);
242
+ setShowSuccessModal(false);
304
243
  }
305
244
  finally {
306
245
  setIsBuying(false);
@@ -338,58 +277,46 @@ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwhee
338
277
  // Render quantity input prompt
339
278
  if (showAmountPrompt) {
340
279
  const pricePerEntry = (0, viem_1.formatUnits)(paymentConfig.pricePerEntry, 18);
341
- const remainingEntries = wheelInfo ? wheelInfo.totalPrizesAvailable_ - wheelInfo.prizesRequestedCount_ : 0n;
342
- const wheelStatus = wheelInfo ? getWheelStatus(wheelInfo) : null;
343
- const isSoldOut = wheelStatus === "sold_out";
344
- const isActive = wheelStatus === "active";
345
- const getStatusMessage = () => {
346
- if (!wheelInfo)
347
- return null;
348
- const formatDate = (timestamp) => {
349
- return new Date(Number(timestamp) * 1000).toLocaleString();
350
- };
351
- switch (wheelStatus) {
352
- case "not_started":
353
- return {
354
- title: "Spin Wheel Not Started",
355
- message: `Starts at ${formatDate(wheelInfo.startTime_)}`
356
- };
357
- case "ended":
358
- return {
359
- title: "Spin Wheel Ended",
360
- message: `Ended at ${formatDate(wheelInfo.endTime_)}`
361
- };
362
- case "sold_out":
363
- return {
364
- title: "All Spins Have Been Claimed",
365
- message: "Stay tuned for the next spin wheel event!"
366
- };
367
- default:
368
- return null;
369
- }
370
- };
371
- const statusInfo = getStatusMessage();
372
280
  return ((0, jsx_runtime_1.jsx)(react_1.StyleRoot, { children: (0, jsx_runtime_1.jsxs)("div", { className: "bg-b3-react-background flex w-full flex-col items-center", children: [(0, jsx_runtime_1.jsxs)("div", { className: "w-full px-4 pb-2 pt-4", children: [(0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { initial: false, animate: {
373
281
  opacity: hasMounted ? 1 : 0,
374
282
  y: hasMounted ? 0 : 20,
375
283
  filter: hasMounted ? "blur(0px)" : "blur(10px)"
376
- }, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, className: `flex justify-center ${isActive ? "mb-4" : ""}`, children: (0, jsx_runtime_1.jsx)("img", { alt: "B3 Token", loading: "lazy", width: "64", height: "64", decoding: "async", className: "rounded-full", src: "https://cdn.b3.fun/b3-coin-3d.png" }) }), (0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { initial: false, animate: {
284
+ }, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, className: "mb-4 flex justify-center", children: (0, jsx_runtime_1.jsx)("img", { alt: "B3 Token", loading: "lazy", width: "64", height: "64", decoding: "async", className: "rounded-full", src: "https://cdn.b3.fun/b3-coin-3d.png" }) }), (0, jsx_runtime_1.jsxs)(framer_motion_1.motion.div, { initial: false, animate: {
285
+ opacity: hasMounted ? 1 : 0,
286
+ y: hasMounted ? 0 : 20,
287
+ filter: hasMounted ? "blur(0px)" : "blur(10px)"
288
+ }, transition: { duration: 0.3, delay: 0.1, ease: "easeInOut" }, className: "text-center", children: [(0, jsx_runtime_1.jsx)("h2", { className: "font-sf-rounded text-as-primary mb-2 text-2xl font-bold", children: (() => {
289
+ const hasEnoughBalance = b3RawBalance && totalCost <= b3RawBalance;
290
+ return hasEnoughBalance || !debouncedQuantity ? "Buy Spins" : `Swap & Buy Spins`;
291
+ })() }), (0, jsx_runtime_1.jsx)("div", { className: "bg-as-on-surface-2/50 inline-flex items-center gap-2 rounded-full border border-white/10 px-3 py-1 backdrop-blur-sm", children: (0, jsx_runtime_1.jsxs)("p", { className: "text-as-primary/80 text-sm", children: [pricePerEntry, " $B3 per spin"] }) })] })] }), (0, jsx_runtime_1.jsxs)(framer_motion_1.motion.div, { initial: false, animate: {
292
+ opacity: hasMounted ? 1 : 0,
293
+ y: hasMounted ? 0 : 20,
294
+ filter: hasMounted ? "blur(0px)" : "blur(10px)"
295
+ }, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: "bg-b3-react-background w-full p-6", children: [(0, jsx_runtime_1.jsxs)("div", { className: "space-y-4", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("p", { className: "text-as-primary/70 text-sm font-medium", children: "Number of spins" }), (0, jsx_runtime_1.jsxs)("span", { className: "text-as-primary/50 flex items-center gap-1 text-sm", children: ["Available: ", isBalanceLoading ? (0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "h-3 w-3 animate-spin" }) : `${b3Balance} B3`] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "relative", children: [(0, jsx_runtime_1.jsx)(react_2.Input, { onFocus: onFocusQuantityInput, type: "text", placeholder: "1", value: displayQuantity, onChange: e => validateAndSetQuantity(e.target.value), className: `h-14 px-4 pr-20 text-lg ${!isQuantityValid && displayQuantity ? "border-as-red" : "border-b3-react-border"}` }), (0, jsx_runtime_1.jsx)("div", { className: "font-pack absolute right-4 top-1/2 -translate-y-1/2 text-lg font-medium text-blue-500/70", children: displayQuantity === "1" ? "Spin" : "Spins" })] }), !isQuantityValid && displayQuantity && (0, jsx_runtime_1.jsx)("p", { className: "text-as-red text-sm", children: validationError }), (0, jsx_runtime_1.jsx)("div", { className: "bg-as-on-surface-2/30 rounded-lg border border-white/10 p-4 backdrop-blur-sm", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-as-primary/70 text-sm font-medium", children: "Total Cost:" }), (0, jsx_runtime_1.jsx)("div", { className: "flex items-center gap-2", children: (0, jsx_runtime_1.jsxs)("span", { className: "text-as-primary text-lg font-bold", children: [displayQuantity && isQuantityValid ? (0, viem_1.formatUnits)(totalCost, 18) : "0", " B3"] }) })] }) })] }), (0, jsx_runtime_1.jsx)("div", { className: "mt-4", children: (() => {
296
+ const hasEnoughBalance = b3RawBalance && totalCost <= b3RawBalance;
297
+ if (!hasEnoughBalance && debouncedQuantity) {
298
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "bg-as-brand/10 flex flex-col items-center gap-2 rounded-lg p-4 pb-5", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-center gap-2", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-as-primary text-sm font-semibold", children: "Swap & buy from any token" }), (0, jsx_runtime_1.jsxs)(react_2.TextLoop, { children: [(0, jsx_runtime_1.jsx)(EthIcon_1.EthIcon, { className: "h-8 w-8" }), (0, jsx_runtime_1.jsx)(SolIcon_1.SolIcon, { className: "h-8 w-8" }), (0, jsx_runtime_1.jsx)(USDCIcon_1.UsdcIcon, { className: "h-8 w-8" })] }), (0, jsx_runtime_1.jsx)(lucide_react_1.ArrowRight, { className: "text-as-primary h-4 w-4" }), (0, jsx_runtime_1.jsx)("img", { src: "https://cdn.b3.fun/b3-coin-3d.png", className: "h-7 w-7", alt: "B3 Token" })] }), (0, jsx_runtime_1.jsx)("p", { className: "text-as-primary/50 text-sm font-medium", children: "No problem, we'll help you swap to B3 for your spins!" })] }));
299
+ }
300
+ })() }), (0, jsx_runtime_1.jsx)(react_2.Button, { onClick: confirmQuantity, disabled: !isQuantityValid || !displayQuantity || isBuying || isTxPending, className: "bg-as-brand hover:bg-as-brand/90 text-as-primary mt-4 h-14 w-full rounded-xl text-lg font-medium", children: isBuying ? "Buying..." : isTxPending ? "Confirming..." : "Continue" })] })] }) }));
301
+ }
302
+ // Success Modal for Direct Buying
303
+ if (showSuccessModal) {
304
+ return ((0, jsx_runtime_1.jsx)(react_1.StyleRoot, { children: (0, jsx_runtime_1.jsxs)("div", { className: "bg-b3-react-background flex w-full flex-col items-center", children: [(0, jsx_runtime_1.jsxs)("div", { className: "w-full p-4", children: [(0, jsx_runtime_1.jsxs)(framer_motion_1.motion.div, { initial: false, animate: {
305
+ opacity: hasMounted ? 1 : 0,
306
+ y: hasMounted ? 0 : 20,
307
+ filter: hasMounted ? "blur(0px)" : "blur(10px)"
308
+ }, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, className: "relative mx-auto mb-4 size-[120px]", children: [(0, jsx_runtime_1.jsx)("div", { className: "absolute inset-0 scale-95 rounded-[50%] bg-gradient-to-br from-green-500/30 to-blue-500/30 blur-xl" }), (0, jsx_runtime_1.jsxs)(react_2.GlareCardRounded, { className: "overflow-hidden rounded-full border-none bg-gradient-to-br from-green-500/10 to-blue-500/10 backdrop-blur-sm", children: [(0, jsx_runtime_1.jsx)("img", { alt: "B3 Token", loading: "lazy", width: "120", height: "120", decoding: "async", "data-nimg": "1", className: "size-full shrink-0 bg-transparent text-transparent", src: "https://cdn.b3.fun/b3-coin-3d.png" }), (0, jsx_runtime_1.jsx)("div", { className: "absolute inset-0 rounded-[50%] border border-white/20" })] })] }), (0, jsx_runtime_1.jsxs)(framer_motion_1.motion.div, { initial: false, animate: {
377
309
  opacity: hasMounted ? 1 : 0,
378
310
  y: hasMounted ? 0 : 20,
379
311
  filter: hasMounted ? "blur(0px)" : "blur(10px)"
380
- }, transition: { duration: 0.3, delay: 0.1, ease: "easeInOut" }, className: "text-center", children: isActive ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("h2", { className: "font-sf-rounded text-as-primary mb-4 text-2xl font-bold", children: (() => {
381
- const hasEnoughBalance = b3RawBalance && totalCost <= b3RawBalance;
382
- return hasEnoughBalance || !debouncedQuantity ? "Buy Spins" : `Swap & Buy Spins`;
383
- })() }), wheelInfo && ((0, jsx_runtime_1.jsxs)("div", { className: "inline-flex items-center gap-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "bg-as-brand/10 border-as-brand/10 inline-flex items-center rounded-full border px-3 py-1", children: (0, jsx_runtime_1.jsxs)("p", { className: "text-as-brand text-sm font-medium", children: [pricePerEntry, " $B3 per spin"] }) }), (0, jsx_runtime_1.jsx)("div", { className: "bg-as-brand/10 border-as-brand/10 inline-flex items-center rounded-full border px-3 py-1", children: (0, jsx_runtime_1.jsxs)("p", { className: "text-as-brand text-sm font-medium", children: [remainingEntries.toString(), " remaining"] }) })] }))] })) : (statusInfo && ((0, jsx_runtime_1.jsxs)("div", { className: "text-center", children: [(0, jsx_runtime_1.jsx)("p", { className: "text-as-primary text-lg font-semibold", children: statusInfo.title }), (0, jsx_runtime_1.jsx)("p", { className: "text-as-primary/70 mt-2 text-sm", children: statusInfo.message })] }))) })] }), (0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { initial: false, animate: {
312
+ }, transition: { duration: 0.3, delay: 0.1, ease: "easeInOut" }, className: "text-center", children: [(0, jsx_runtime_1.jsx)("h2", { className: "font-sf-rounded mb-3 bg-gradient-to-r from-green-400 to-blue-500 bg-clip-text text-3xl font-bold text-transparent", children: "\uD83C\uDF89 Purchase Complete!" }), (0, jsx_runtime_1.jsx)("div", { className: "bg-as-on-surface-2/50 inline-flex items-center gap-2 rounded-full border border-white/10 px-4 py-2 backdrop-blur-sm", children: (0, jsx_runtime_1.jsxs)("span", { className: "text-as-primary/80 text-sm font-medium", children: [userSpinQuantity, " Spin", userSpinQuantity !== "1" ? "s" : "", " \u2022 ", (0, viem_1.formatUnits)(totalCost, 18), " B3"] }) })] })] }), (0, jsx_runtime_1.jsxs)(framer_motion_1.motion.div, { initial: false, animate: {
384
313
  opacity: hasMounted ? 1 : 0,
385
314
  y: hasMounted ? 0 : 20,
386
315
  filter: hasMounted ? "blur(0px)" : "blur(10px)"
387
- }, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: "bg-b3-react-background w-full p-6", children: isActive ? ((0, jsx_runtime_1.jsxs)("div", { className: "space-y-4", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("p", { className: "text-as-primary/70 text-sm font-medium", children: "Number of spins" }), (0, jsx_runtime_1.jsxs)("span", { className: "text-as-primary/50 flex items-center gap-1 text-sm", children: ["Available: ", isBalanceLoading ? (0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "h-3 w-3 animate-spin" }) : `${b3Balance} B3`] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "relative", children: [(0, jsx_runtime_1.jsx)(react_2.Input, { onFocus: onFocusQuantityInput, type: "text", placeholder: "1", value: displayQuantity, onChange: e => validateAndSetQuantity(e.target.value), className: `h-14 px-4 pr-20 text-lg ${!isQuantityValid && displayQuantity ? "border-as-red" : "border-b3-react-border"}` }), (0, jsx_runtime_1.jsx)("div", { className: "font-pack absolute right-4 top-1/2 -translate-y-1/2 text-lg font-medium text-blue-500/70", children: displayQuantity === "1" ? "Spin" : "Spins" })] }), !isQuantityValid && displayQuantity && (0, jsx_runtime_1.jsx)("p", { className: "text-as-red text-sm", children: validationError }), (0, jsx_runtime_1.jsx)("div", { className: "bg-as-on-surface-2/30 rounded-lg border border-white/10 p-4 backdrop-blur-sm", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-as-primary/70 text-sm font-medium", children: "Total Cost:" }), (0, jsx_runtime_1.jsx)("div", { className: "flex items-center gap-2", children: (0, jsx_runtime_1.jsxs)("span", { className: "text-as-primary text-lg font-bold", children: [displayQuantity && isQuantityValid ? (0, viem_1.formatUnits)(totalCost, 18) : "0", " B3"] }) })] }) }), (0, jsx_runtime_1.jsx)("div", { className: "mt-4", children: (() => {
388
- const hasEnoughBalance = b3RawBalance && totalCost <= b3RawBalance;
389
- if (!hasEnoughBalance && debouncedQuantity) {
390
- return ((0, jsx_runtime_1.jsxs)("div", { className: "bg-as-brand/10 flex flex-col items-center gap-2 rounded-lg p-4 pb-5", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-center gap-2", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-as-primary text-sm font-semibold", children: "Swap & buy from any token" }), (0, jsx_runtime_1.jsxs)(react_2.TextLoop, { children: [(0, jsx_runtime_1.jsx)(EthIcon_1.EthIcon, { className: "h-8 w-8" }), (0, jsx_runtime_1.jsx)(SolIcon_1.SolIcon, { className: "h-8 w-8" }), (0, jsx_runtime_1.jsx)(USDCIcon_1.UsdcIcon, { className: "h-8 w-8" })] }), (0, jsx_runtime_1.jsx)(lucide_react_1.ArrowRight, { className: "text-as-primary h-4 w-4" }), (0, jsx_runtime_1.jsx)("img", { src: "https://cdn.b3.fun/b3-coin-3d.png", className: "h-7 w-7", alt: "B3 Token" })] }), (0, jsx_runtime_1.jsx)("p", { className: "text-as-primary/50 text-sm font-medium", children: "No problem, we'll help you swap to B3 for your spins!" })] }));
391
- }
392
- })() }), (0, jsx_runtime_1.jsx)(react_2.Button, { onClick: confirmQuantity, disabled: !isQuantityValid || !displayQuantity || isBuying || isTxPending, className: "bg-as-brand hover:bg-as-brand/90 text-as-primary mt-4 h-14 w-full rounded-xl text-lg font-medium", children: isBuying ? "Buying..." : isTxPending ? "Confirming..." : "Continue" })] })) : null })] }) }));
316
+ }, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: "bg-b3-react-background w-full p-6", children: [(0, jsx_runtime_1.jsx)("div", { className: "mb-6", children: (0, jsx_runtime_1.jsx)("a", { href: `https://basescan.org/tx/${buyingTxHash}`, target: "_blank", rel: "noopener noreferrer", className: "text-as-primary/70 hover:text-as-primary block break-all text-center font-mono text-sm underline transition-colors", children: "View transaction" }) }), (0, jsx_runtime_1.jsx)(react_2.Button, { onClick: () => {
317
+ setB3ModalOpen(false);
318
+ onSuccess?.(buyingTxHash);
319
+ }, className: "bg-as-brand hover:bg-as-brand/90 text-as-primary h-14 w-full rounded-xl text-lg font-medium", children: "Done" })] })] }) }));
393
320
  }
394
321
  // AnySpend flow for when user needs to swap to B3
395
322
  const encodedData = generateEncodedDataForBuyEntriesAndSpin(address || "", userSpinQuantity);
@@ -267,9 +267,6 @@ function getPaymentUrl(address, amount, currency) {
267
267
  return `ethereum:${address}`;
268
268
  }
269
269
  function getExplorerTxUrl(chainId, txHash) {
270
- if (chainId === chains_1.b3.id) {
271
- return "https://explorer.b3.fun/b3/tx/" + txHash;
272
- }
273
270
  if (exports.EVM_CHAINS[chainId]) {
274
271
  return exports.EVM_CHAINS[chainId].viem.blockExplorers?.default.url + "/tx/" + txHash;
275
272
  }
@@ -5,7 +5,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("../../../anyspend/react");
6
6
  const react_2 = require("../../../global-account/react");
7
7
  const debug_1 = require("../../../shared/utils/debug");
8
- const useB3_1 = require("./B3Provider/useB3");
8
+ const B3Provider_1 = require("./B3Provider");
9
9
  const ManageAccount_1 = require("./ManageAccount/ManageAccount");
10
10
  const RequestPermissions_1 = require("./RequestPermissions/RequestPermissions");
11
11
  const SignInWithB3Flow_1 = require("./SignInWithB3/SignInWithB3Flow");
@@ -15,7 +15,7 @@ const drawer_1 = require("./ui/drawer");
15
15
  const debug = (0, debug_1.debugB3React)("B3DynamicModal");
16
16
  function B3DynamicModal() {
17
17
  const { isOpen, setB3ModalOpen, contentType, history, navigateBack } = (0, react_2.useModalStore)();
18
- const { theme } = (0, useB3_1.useB3)();
18
+ const { theme } = (0, B3Provider_1.useB3)();
19
19
  const isMobile = (0, react_2.useIsMobile)();
20
20
  let contentClass = `b3-modal ${theme === "dark" ? "dark" : ""}`;
21
21
  let hideCloseButton = false;
@@ -1,8 +1,34 @@
1
- import { PermissionsConfig } from "../../../../global-account/types/permissions";
2
- import { Account } from "thirdweb/wallets";
1
+ import { User } from "../../../global-account/types/b3-api.types";
2
+ import { PermissionsConfig } from "../../../global-account/types/permissions";
3
+ import { Account, Wallet } from "thirdweb/wallets";
3
4
  import "@reservoir0x/relay-kit-ui/styles.css";
4
- import { B3ContextType } from "./types";
5
5
  export declare const wagmiConfig: import("wagmi").Config<readonly [import("viem").Chain, ...import("viem").Chain[]], any, readonly import("wagmi").CreateConnectorFn[]>;
6
+ /**
7
+ * Context type for B3Provider
8
+ */
9
+ export interface B3ContextType {
10
+ account?: Account;
11
+ automaticallySetFirstEoa: boolean;
12
+ user?: User;
13
+ setAccount: (account: Account) => void;
14
+ setWallet: (wallet: Wallet) => void;
15
+ wallet?: Wallet;
16
+ setUser: (user?: User) => void;
17
+ initialized: boolean;
18
+ ready: boolean;
19
+ environment?: "development" | "production";
20
+ defaultPermissions?: PermissionsConfig;
21
+ theme: "light" | "dark";
22
+ }
23
+ /**
24
+ * Context for B3 provider
25
+ */
26
+ export declare const B3Context: import("react").Context<B3ContextType>;
27
+ /**
28
+ * Hook to access the B3 context
29
+ * @throws Error if used outside a B3Provider
30
+ */
31
+ export declare function useB3(): B3ContextType;
6
32
  /**
7
33
  * Main B3Provider component
8
34
  */
@@ -1,19 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wagmiConfig = void 0;
3
+ exports.B3Context = exports.wagmiConfig = void 0;
4
+ exports.useB3 = useB3;
4
5
  exports.B3Provider = B3Provider;
5
6
  exports.InnerProvider = InnerProvider;
6
7
  const jsx_runtime_1 = require("react/jsx-runtime");
7
- const supported_1 = require("../../../../shared/constants/chains/supported");
8
+ const supported_1 = require("../../../shared/constants/chains/supported");
8
9
  const react_query_1 = require("@tanstack/react-query");
9
10
  const react_1 = require("react");
10
11
  const sonner_1 = require("sonner");
11
12
  const react_2 = require("thirdweb/react");
12
13
  const wagmi_1 = require("wagmi");
13
- const RelayKitProviderWrapper_1 = require("../RelayKitProviderWrapper");
14
- const StyleRoot_1 = require("../StyleRoot");
14
+ const RelayKitProviderWrapper_1 = require("./RelayKitProviderWrapper");
15
+ const StyleRoot_1 = require("./StyleRoot");
15
16
  require("@reservoir0x/relay-kit-ui/styles.css");
16
- const types_1 = require("./types");
17
17
  /**
18
18
  * Default permissions configuration for B3 provider
19
19
  */
@@ -27,6 +27,34 @@ exports.wagmiConfig = (0, wagmi_1.createConfig)({
27
27
  chains: [supported_1.supportedChains[0], ...supported_1.supportedChains.slice(1)],
28
28
  transports: Object.fromEntries(supported_1.supportedChains.map(chain => [chain.id, (0, wagmi_1.http)()]))
29
29
  });
30
+ /**
31
+ * Context for B3 provider
32
+ */
33
+ exports.B3Context = (0, react_1.createContext)({
34
+ account: undefined,
35
+ automaticallySetFirstEoa: false,
36
+ user: undefined,
37
+ setAccount: () => { },
38
+ setWallet: () => { },
39
+ wallet: undefined,
40
+ setUser: () => { },
41
+ initialized: false,
42
+ ready: false,
43
+ environment: "development",
44
+ theme: "light"
45
+ });
46
+ /**
47
+ * Hook to access the B3 context
48
+ * @throws Error if used outside a B3Provider
49
+ */
50
+ function useB3() {
51
+ const context = (0, react_1.useContext)(exports.B3Context);
52
+ if (!context.initialized) {
53
+ throw new Error("useB3 must be used within a B3Provider");
54
+ }
55
+ // Return a stable reference
56
+ return (0, react_1.useMemo)(() => context, [context]);
57
+ }
30
58
  // Create queryClient instance
31
59
  const queryClient = new react_query_1.QueryClient();
32
60
  /**
@@ -70,7 +98,7 @@ function InnerProvider({ children, accountOverride, environment, defaultPermissi
70
98
  }
71
99
  // eslint-disable-next-line react-hooks/exhaustive-deps
72
100
  }, [automaticallySetFirstEoa, wallets]);
73
- return ((0, jsx_runtime_1.jsx)(types_1.B3Context.Provider, { value: {
101
+ return ((0, jsx_runtime_1.jsx)(exports.B3Context.Provider, { value: {
74
102
  account: effectiveAccount,
75
103
  setAccount,
76
104
  setWallet,
@@ -1,6 +1,29 @@
1
- import { PermissionsConfig } from "../../../../global-account/types/permissions";
1
+ import { PermissionsConfig } from "../../../global-account/types/permissions";
2
2
  import { Account } from "thirdweb/wallets";
3
- import { B3ContextType } from "./types";
3
+ import { User } from "../../../global-account/types/b3-api.types";
4
+ /**
5
+ * Context type for B3Provider
6
+ */
7
+ export interface B3ContextType {
8
+ account?: Account;
9
+ user?: User;
10
+ setAccount: (account: Account) => void;
11
+ setUser: (user?: User) => void;
12
+ initialized: boolean;
13
+ ready: boolean;
14
+ environment?: "development" | "production";
15
+ defaultPermissions?: PermissionsConfig;
16
+ theme: "light" | "dark";
17
+ }
18
+ /**
19
+ * Context for B3 provider
20
+ */
21
+ export declare const B3Context: import("react").Context<B3ContextType>;
22
+ /**
23
+ * Hook to access the B3 context
24
+ * @throws Error if used outside a B3Provider
25
+ */
26
+ export declare function useB3(): B3ContextType;
4
27
  /**
5
28
  * Main B3Provider component
6
29
  */
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.B3Context = void 0;
4
+ exports.useB3 = useB3;
3
5
  exports.B3Provider = B3Provider;
4
6
  exports.InnerProvider = InnerProvider;
5
7
  const jsx_runtime_1 = require("react/jsx-runtime");
6
8
  const react_query_1 = require("@tanstack/react-query");
7
9
  const react_1 = require("react");
8
10
  const react_2 = require("thirdweb/react");
9
- const types_1 = require("./types");
10
11
  /**
11
12
  * Default permissions configuration for B3 provider
12
13
  */
@@ -16,6 +17,31 @@ const DEFAULT_PERMISSIONS = {
16
17
  startDate: new Date(),
17
18
  endDate: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365) // 1 year from now
18
19
  };
20
+ /**
21
+ * Context for B3 provider
22
+ */
23
+ exports.B3Context = (0, react_1.createContext)({
24
+ account: undefined,
25
+ user: undefined,
26
+ setAccount: () => { },
27
+ setUser: () => { },
28
+ initialized: false,
29
+ ready: false,
30
+ environment: "development",
31
+ theme: "light"
32
+ });
33
+ /**
34
+ * Hook to access the B3 context
35
+ * @throws Error if used outside a B3Provider
36
+ */
37
+ function useB3() {
38
+ const context = (0, react_1.useContext)(exports.B3Context);
39
+ if (!context.initialized) {
40
+ throw new Error("useB3 must be used within a B3Provider");
41
+ }
42
+ // Return a stable reference
43
+ return (0, react_1.useMemo)(() => context, [context]);
44
+ }
19
45
  // Create queryClient instance
20
46
  const queryClient = new react_query_1.QueryClient();
21
47
  /**
@@ -36,11 +62,8 @@ function InnerProvider({ children, accountOverride, environment, defaultPermissi
36
62
  const setAccount = (account) => {
37
63
  setManuallySetAccount(account);
38
64
  };
39
- return ((0, jsx_runtime_1.jsx)(types_1.B3Context.Provider, { value: {
65
+ return ((0, jsx_runtime_1.jsx)(exports.B3Context.Provider, { value: {
40
66
  account: effectiveAccount,
41
- automaticallySetFirstEoa: false,
42
- setWallet: () => { },
43
- wallet: undefined,
44
67
  setAccount,
45
68
  user,
46
69
  setUser,
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StyleRoot = StyleRoot;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
- const useB3_1 = require("./B3Provider/useB3");
5
+ const B3Provider_1 = require("./B3Provider");
6
6
  function StyleRoot({ children, id }) {
7
- const { theme: b3Theme } = (0, useB3_1.useB3)();
7
+ const { theme: b3Theme } = (0, B3Provider_1.useB3)();
8
8
  // eslint-disable-next-line tailwindcss/no-custom-classname
9
9
  return ((0, jsx_runtime_1.jsx)("div", { className: "b3-root", id: id, "data-theme": b3Theme, children: children }));
10
10
  }