@b3dotfun/sdk 0.0.1-alpha.2 → 0.0.1-alpha.21

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 (115) hide show
  1. package/README.md +328 -230
  2. package/dist/cjs/anyspend/index.native.d.ts +13 -0
  3. package/dist/cjs/anyspend/index.native.js +35 -0
  4. package/dist/cjs/anyspend/react/components/AnySpend.d.ts +2 -1
  5. package/dist/cjs/anyspend/react/components/AnySpend.js +4 -4
  6. package/dist/cjs/anyspend/react/components/AnySpendBuySpin.d.ts +2 -1
  7. package/dist/cjs/anyspend/react/components/AnySpendBuySpin.js +123 -50
  8. package/dist/cjs/anyspend/react/components/common/OrderHistoryItem.js +5 -1
  9. package/dist/cjs/anyspend/react/components/common/TokenBalance.js +1 -1
  10. package/dist/cjs/anyspend/utils/chain.js +3 -0
  11. package/dist/cjs/global-account/react/components/B3DynamicModal.js +2 -2
  12. package/dist/cjs/global-account/react/components/{B3Provider.d.ts → B3Provider/B3Provider.d.ts} +3 -29
  13. package/dist/cjs/global-account/react/components/{B3Provider.js → B3Provider/B3Provider.js} +6 -34
  14. package/dist/cjs/global-account/react/components/{B3Provider.native.d.ts → B3Provider/B3Provider.native.d.ts} +2 -25
  15. package/dist/cjs/global-account/react/components/{B3Provider.native.js → B3Provider/B3Provider.native.js} +5 -28
  16. package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +25 -0
  17. package/dist/cjs/global-account/react/components/B3Provider/types.js +20 -0
  18. package/dist/cjs/global-account/react/components/B3Provider/useB3.d.ts +5 -0
  19. package/dist/cjs/global-account/react/components/B3Provider/useB3.js +17 -0
  20. package/dist/cjs/global-account/react/components/StyleRoot.js +2 -2
  21. package/dist/cjs/global-account/react/components/index.d.ts +8 -6
  22. package/dist/cjs/global-account/react/components/index.js +18 -16
  23. package/dist/cjs/global-account/react/hooks/index.d.ts +1 -1
  24. package/dist/cjs/global-account/react/hooks/index.js +2 -1
  25. package/dist/cjs/global-account/react/hooks/useBestTransactionPath.js +3 -3
  26. package/dist/cjs/global-account/react/hooks/useTokenBalance.js +1 -1
  27. package/dist/cjs/global-account/react/index.native.d.ts +7 -0
  28. package/dist/cjs/global-account/react/index.native.js +21 -0
  29. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +2 -0
  30. package/dist/cjs/global-account/types/chain-networks.d.ts +34 -34
  31. package/dist/cjs/global-account/types/feature-flags.d.ts +5 -5
  32. package/dist/cjs/shared/constants/chains/b3Chain.d.ts +1 -1
  33. package/dist/cjs/shared/constants/chains/supported.d.ts +8 -7
  34. package/dist/cjs/shared/constants/chains/supported.js +8 -1
  35. package/dist/cjs/shared/utils/chains.js +4 -0
  36. package/dist/cjs/shared/utils/number.js +1 -1
  37. package/dist/esm/anyspend/index.native.d.ts +13 -0
  38. package/dist/esm/anyspend/index.native.js +19 -0
  39. package/dist/esm/anyspend/react/components/AnySpend.d.ts +2 -1
  40. package/dist/esm/anyspend/react/components/AnySpend.js +4 -4
  41. package/dist/esm/anyspend/react/components/AnySpendBuySpin.d.ts +2 -1
  42. package/dist/esm/anyspend/react/components/AnySpendBuySpin.js +123 -50
  43. package/dist/esm/anyspend/react/components/common/OrderHistoryItem.js +5 -1
  44. package/dist/esm/anyspend/react/components/common/TokenBalance.js +1 -1
  45. package/dist/esm/anyspend/utils/chain.js +3 -0
  46. package/dist/esm/global-account/react/components/B3DynamicModal.js +1 -1
  47. package/dist/esm/global-account/react/components/{B3Provider.d.ts → B3Provider/B3Provider.d.ts} +3 -29
  48. package/dist/esm/global-account/react/components/{B3Provider.js → B3Provider/B3Provider.js} +5 -32
  49. package/dist/esm/global-account/react/components/{B3Provider.native.d.ts → B3Provider/B3Provider.native.d.ts} +2 -25
  50. package/dist/esm/global-account/react/components/{B3Provider.native.js → B3Provider/B3Provider.native.js} +5 -26
  51. package/dist/esm/global-account/react/components/B3Provider/types.d.ts +25 -0
  52. package/dist/esm/global-account/react/components/B3Provider/types.js +17 -0
  53. package/dist/esm/global-account/react/components/B3Provider/useB3.d.ts +5 -0
  54. package/dist/esm/global-account/react/components/B3Provider/useB3.js +14 -0
  55. package/dist/esm/global-account/react/components/StyleRoot.js +1 -1
  56. package/dist/esm/global-account/react/components/index.d.ts +8 -6
  57. package/dist/esm/global-account/react/components/index.js +7 -5
  58. package/dist/esm/global-account/react/hooks/index.d.ts +1 -1
  59. package/dist/esm/global-account/react/hooks/index.js +1 -1
  60. package/dist/esm/global-account/react/hooks/useBestTransactionPath.js +3 -3
  61. package/dist/esm/global-account/react/hooks/useTokenBalance.js +1 -1
  62. package/dist/esm/global-account/react/index.native.d.ts +7 -0
  63. package/dist/esm/global-account/react/index.native.js +11 -0
  64. package/dist/esm/global-account/react/stores/useModalStore.d.ts +2 -0
  65. package/dist/esm/global-account/types/chain-networks.d.ts +34 -34
  66. package/dist/esm/global-account/types/feature-flags.d.ts +5 -5
  67. package/dist/esm/shared/constants/chains/b3Chain.d.ts +1 -1
  68. package/dist/esm/shared/constants/chains/supported.d.ts +8 -7
  69. package/dist/esm/shared/constants/chains/supported.js +7 -0
  70. package/dist/esm/shared/utils/chains.js +4 -0
  71. package/dist/esm/shared/utils/number.js +1 -1
  72. package/dist/styles/index.css +1 -1
  73. package/dist/types/anyspend/index.native.d.ts +13 -0
  74. package/dist/types/anyspend/react/components/AnySpend.d.ts +2 -1
  75. package/dist/types/anyspend/react/components/AnySpendBuySpin.d.ts +2 -1
  76. package/dist/types/global-account/react/components/{B3Provider.d.ts → B3Provider/B3Provider.d.ts} +2 -28
  77. package/dist/types/global-account/react/components/{B3Provider.native.d.ts → B3Provider/B3Provider.native.d.ts} +1 -24
  78. package/dist/types/global-account/react/components/B3Provider/types.d.ts +25 -0
  79. package/dist/types/global-account/react/components/B3Provider/useB3.d.ts +5 -0
  80. package/dist/types/global-account/react/components/index.d.ts +8 -6
  81. package/dist/types/global-account/react/hooks/index.d.ts +1 -1
  82. package/dist/types/global-account/react/index.native.d.ts +7 -0
  83. package/dist/types/global-account/react/stores/useModalStore.d.ts +2 -0
  84. package/dist/types/global-account/types/chain-networks.d.ts +34 -34
  85. package/dist/types/global-account/types/feature-flags.d.ts +5 -5
  86. package/dist/types/shared/constants/chains/b3Chain.d.ts +1 -1
  87. package/dist/types/shared/constants/chains/supported.d.ts +8 -7
  88. package/package.json +26 -24
  89. package/src/anyspend/index.native.ts +24 -0
  90. package/src/anyspend/react/components/AnySpend.tsx +6 -5
  91. package/src/anyspend/react/components/AnySpendBuySpin.tsx +232 -179
  92. package/src/anyspend/react/components/common/OrderHistoryItem.tsx +5 -1
  93. package/src/anyspend/react/components/common/TokenBalance.tsx +1 -1
  94. package/src/anyspend/utils/chain.ts +3 -0
  95. package/src/global-account/react/components/B3DynamicModal.tsx +1 -1
  96. package/src/global-account/react/components/{B3Provider.native.tsx → B3Provider/B3Provider.native.tsx} +4 -45
  97. package/src/global-account/react/components/{B3Provider.tsx → B3Provider/B3Provider.tsx} +4 -53
  98. package/src/global-account/react/components/B3Provider/types.ts +40 -0
  99. package/src/global-account/react/components/B3Provider/useB3.ts +17 -0
  100. package/src/global-account/react/components/StyleRoot.tsx +1 -1
  101. package/src/global-account/react/components/index.ts +8 -6
  102. package/src/global-account/react/hooks/index.ts +1 -1
  103. package/src/global-account/react/hooks/useBestTransactionPath.tsx +3 -3
  104. package/src/global-account/react/hooks/useTokenBalance.tsx +1 -1
  105. package/src/global-account/react/index.native.ts +14 -0
  106. package/src/global-account/react/stores/useModalStore.ts +2 -0
  107. package/src/shared/constants/chains/supported.ts +12 -4
  108. package/src/shared/utils/chains.ts +4 -1
  109. package/src/shared/utils/number.ts +1 -1
  110. package/dist/cjs/styles/index.d.ts +0 -20
  111. package/dist/cjs/styles/index.js +0 -22
  112. package/dist/esm/styles/index.d.ts +0 -20
  113. package/dist/esm/styles/index.js +0 -20
  114. package/dist/types/styles/index.d.ts +0 -20
  115. package/src/styles/index.ts +0 -24
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // Export all hooks
18
+ __exportStar(require("./react/hooks"), exports);
19
+ // Providers
20
+ __exportStar(require("./react/providers/AnyspendProvider"), exports);
21
+ // Types
22
+ __exportStar(require("./types"), exports);
23
+ // Utils
24
+ __exportStar(require("./utils/address"), exports);
25
+ __exportStar(require("./utils/chain"), exports);
26
+ __exportStar(require("./utils/format"), exports);
27
+ __exportStar(require("./utils/json"), exports);
28
+ __exportStar(require("./utils/number"), exports);
29
+ __exportStar(require("./utils/string"), exports);
30
+ __exportStar(require("./utils/token"), exports);
31
+ // Constants
32
+ __exportStar(require("./constants"), exports);
33
+ // Abis
34
+ __exportStar(require("./abis/abi-usdc-base"), exports);
35
+ __exportStar(require("./abis/erc20-staking"), exports);
@@ -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 }: {
14
+ export declare function AnySpend({ destinationTokenAddress, destinationTokenChainId, isMainnet, mode, defaultActiveTab, loadOrder, hideTransactionHistoryButton, recipientAddress: recipientAddressFromProps }: {
15
15
  destinationTokenAddress?: string;
16
16
  destinationTokenChainId?: number;
17
17
  isMainnet?: boolean;
@@ -19,4 +19,5 @@ export declare function AnySpend({ destinationTokenAddress, destinationTokenChai
19
19
  defaultActiveTab?: "crypto" | "fiat";
20
20
  loadOrder?: string;
21
21
  hideTransactionHistoryButton?: boolean;
22
+ recipientAddress?: string;
22
23
  }): 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 formatAddress_1 = require("../../../shared/utils/formatAddress");
13
12
  const cn_1 = require("../../../shared/utils/cn");
13
+ const formatAddress_1 = require("../../../shared/utils/formatAddress");
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 }) {
39
+ function AnySpend({ destinationTokenAddress, destinationTokenChainId, isMainnet = true, mode = "modal", defaultActiveTab = "crypto", loadOrder, hideTransactionHistoryButton, recipientAddress: recipientAddressFromProps }) {
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(globalAddress);
283
- }, [globalAddress]);
282
+ setRecipientAddress(recipientAddressFromProps || globalAddress);
283
+ }, [recipientAddressFromProps, globalAddress]);
284
284
  // Get anyspend price
285
285
  const activeInputAmountInWei = isSrcInputDirty
286
286
  ? (0, viem_1.parseUnits)(srcAmount.replaceAll(",", ""), selectedSrcToken.decimals).toString()
@@ -1,9 +1,10 @@
1
- export declare function AnySpendBuySpin({ isMainnet, loadOrder, mode, spinwheelContractAddress, chainId, recipientAddress, onSuccess }: {
1
+ export declare function AnySpendBuySpin({ isMainnet, loadOrder, mode, spinwheelContractAddress, chainId, recipientAddress, prefillQuantity, 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;
8
9
  onSuccess?: (txHash?: string) => void;
9
10
  }): import("react/jsx-runtime").JSX.Element;
@@ -6,6 +6,7 @@ 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");
9
10
  const EthIcon_1 = require("./icons/EthIcon");
10
11
  const SolIcon_1 = require("./icons/SolIcon");
11
12
  const USDCIcon_1 = require("./icons/USDCIcon");
@@ -17,7 +18,6 @@ const lucide_react_1 = require("lucide-react");
17
18
  const react_3 = require("react");
18
19
  const sonner_1 = require("sonner");
19
20
  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,8 +49,37 @@ 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"
52
66
  }
53
67
  ];
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
+ }
54
83
  function generateEncodedDataForBuyEntriesAndSpin(user, quantity) {
55
84
  (0, invariant_1.default)(BigInt(quantity) > 0, "Quantity must be greater than zero");
56
85
  console.log("@@anyspend-buy-spin:encoded-data:", { user, quantity });
@@ -62,16 +91,17 @@ function generateEncodedDataForBuyEntriesAndSpin(user, quantity) {
62
91
  return encodedData;
63
92
  }
64
93
  const basePublicClient = (0, viem_1.createPublicClient)({
65
- chain: chains_1.base,
94
+ chain: supported_1.baseMainnet,
66
95
  transport: (0, viem_1.http)()
67
96
  });
68
- function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwheelContractAddress, chainId, recipientAddress, onSuccess }) {
97
+ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwheelContractAddress, chainId, recipientAddress, prefillQuantity, onSuccess }) {
69
98
  const hasMounted = (0, react_2.useHasMounted)();
70
99
  const { setB3ModalOpen } = (0, react_2.useModalStore)();
71
100
  // Payment config state
72
101
  const [paymentConfig, setPaymentConfig] = (0, react_3.useState)(null);
73
102
  const [isLoadingConfig, setIsLoadingConfig] = (0, react_3.useState)(true);
74
103
  const [configError, setConfigError] = (0, react_3.useState)("");
104
+ const [wheelInfo, setWheelInfo] = (0, react_3.useState)(null);
75
105
  // Fetch B3 token balance
76
106
  const { formattedBalance: b3Balance, isLoading: isBalanceLoading, rawBalance: b3RawBalance } = (0, react_2.useTokenBalance)({
77
107
  token: anyspend_1.B3_TOKEN
@@ -83,22 +113,29 @@ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwhee
83
113
  // State for direct buying flow (when user has B3 tokens)
84
114
  const [isBuying, setIsBuying] = (0, react_3.useState)(false);
85
115
  const [buyingTxHash, setBuyingTxHash] = (0, react_3.useState)("");
86
- const [showSuccessModal, setShowSuccessModal] = (0, react_3.useState)(false);
87
- // Wait for transaction confirmation
88
- const { isLoading: isTxPending, isSuccess: isTxSuccess } = (0, wagmi_1.useWaitForTransactionReceipt)({
116
+ const { isLoading: isTxPending, isSuccess: isTxSuccess, isError: isTxError, error: txError } = (0, wagmi_1.useWaitForTransactionReceipt)({
89
117
  hash: buyingTxHash,
90
118
  query: {
91
119
  structuralSharing: false
92
120
  }
93
121
  });
94
- // Show success modal when transaction is confirmed
122
+ // Handle transaction status
95
123
  (0, react_3.useEffect)(() => {
96
- if (isTxSuccess && buyingTxHash) {
97
- setShowAmountPrompt(false);
98
- setShowSuccessModal(true);
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);
99
136
  setIsBuying(false);
100
137
  }
101
- }, [isTxSuccess, buyingTxHash]);
138
+ }, [isTxSuccess, isTxError, buyingTxHash, onSuccess, setB3ModalOpen, txError]);
102
139
  // Spin quantity state
103
140
  const [userSpinQuantity, setUserSpinQuantity] = (0, react_3.useState)("");
104
141
  const [showAmountPrompt, setShowAmountPrompt] = (0, react_3.useState)(true);
@@ -106,9 +143,17 @@ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwhee
106
143
  const [validationError, setValidationError] = (0, react_3.useState)("");
107
144
  const [displayQuantity, setDisplayQuantity] = (0, react_3.useState)("");
108
145
  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]);
109
154
  // Calculate total cost
110
155
  const totalCost = paymentConfig && userSpinQuantity ? paymentConfig.pricePerEntry * BigInt(userSpinQuantity) : BigInt(0);
111
- // Fetch payment configuration
156
+ // Fetch payment configuration and wheel info
112
157
  const fetchPaymentConfig = (0, react_3.useCallback)(async () => {
113
158
  if (!basePublicClient || !spinwheelContractAddress)
114
159
  return;
@@ -116,7 +161,7 @@ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwhee
116
161
  setIsLoadingConfig(true);
117
162
  setConfigError("");
118
163
  console.log("@@anyspend-buy-spin:fetch-config:", { spinwheelContractAddress, chainId });
119
- const [config, entryModuleAddress] = await Promise.all([
164
+ const [config, entryModuleAddress, wheelInfo] = await Promise.all([
120
165
  basePublicClient.readContract({
121
166
  address: spinwheelContractAddress,
122
167
  abi: SPIN_WHEEL_ABI,
@@ -126,6 +171,11 @@ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwhee
126
171
  address: spinwheelContractAddress,
127
172
  abi: SPIN_WHEEL_ABI,
128
173
  functionName: "entryModule"
174
+ }),
175
+ basePublicClient.readContract({
176
+ address: spinwheelContractAddress,
177
+ abi: SPIN_WHEEL_ABI,
178
+ functionName: "getWheelInfo"
129
179
  })
130
180
  ]);
131
181
  const paymentConfig = {
@@ -134,13 +184,16 @@ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwhee
134
184
  paymentRecipient: config[3],
135
185
  entryModule: entryModuleAddress
136
186
  };
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
- });
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
+ };
143
195
  setPaymentConfig(paymentConfig);
196
+ setWheelInfo(wheelInfoData);
144
197
  }
145
198
  catch (error) {
146
199
  console.error("@@anyspend-buy-spin:config-error:", error);
@@ -159,6 +212,7 @@ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwhee
159
212
  (0, react_3.useEffect)(() => {
160
213
  const timer = setTimeout(() => {
161
214
  setDebouncedQuantity(displayQuantity);
215
+ setDebouncedUserSpinQuantity(userSpinQuantity);
162
216
  }, 500);
163
217
  return () => clearTimeout(timer);
164
218
  }, [displayQuantity, userSpinQuantity]);
@@ -190,6 +244,13 @@ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwhee
190
244
  setValidationError(`Maximum ${paymentConfig.maxEntriesPerUser.toString()} spins allowed`);
191
245
  return;
192
246
  }
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
+ }
193
254
  setUserSpinQuantity(value);
194
255
  setIsQuantityValid(true);
195
256
  setValidationError("");
@@ -239,7 +300,7 @@ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwhee
239
300
  catch (error) {
240
301
  console.error("@@anyspend-buy-spin:error:", error);
241
302
  sonner_1.toast.error("Spin purchase failed. Please try again.");
242
- setShowSuccessModal(false);
303
+ setB3ModalOpen(false);
243
304
  }
244
305
  finally {
245
306
  setIsBuying(false);
@@ -277,46 +338,58 @@ function AnySpendBuySpin({ isMainnet = true, loadOrder, mode = "modal", spinwhee
277
338
  // Render quantity input prompt
278
339
  if (showAmountPrompt) {
279
340
  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();
280
372
  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: {
281
373
  opacity: hasMounted ? 1 : 0,
282
374
  y: hasMounted ? 0 : 20,
283
375
  filter: hasMounted ? "blur(0px)" : "blur(10px)"
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: {
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: {
309
377
  opacity: hasMounted ? 1 : 0,
310
378
  y: hasMounted ? 0 : 20,
311
379
  filter: hasMounted ? "blur(0px)" : "blur(10px)"
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: {
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: {
313
384
  opacity: hasMounted ? 1 : 0,
314
385
  y: hasMounted ? 0 : 20,
315
386
  filter: hasMounted ? "blur(0px)" : "blur(10px)"
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" })] })] }) }));
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 })] }) }));
320
393
  }
321
394
  // AnySpend flow for when user needs to swap to B3
322
395
  const encodedData = generateEncodedDataForBuyEntriesAndSpin(address || "", userSpinQuantity);
@@ -32,5 +32,9 @@ function OrderHistoryItem({ order, onSelectOrder, mode }) {
32
32
  : order.payload.expectedDstAmount;
33
33
  const { text: orderStatusText, status: orderDisplayStatus } = (0, anyspend_1.getStatusDisplay)(order);
34
34
  const isSmallView = (0, react_1.useIsMobile)() || mode === "modal";
35
- return ((0, jsx_runtime_1.jsxs)("div", { className: (0, utils_1.cn)("bg-as-light-brand/20 rounded-lg border p-4", onSelectOrder && "hover:bg-as-light-brand/30 hover:border-as-brand cursor-pointer transition-colors"), onClick: () => onSelectOrder?.(order.id), children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)(react_1.Badge, { className: (0, utils_1.cn)("px-3 py-1 text-xs", orderDisplayStatus === "processing" && "bg-yellow-500/10 text-yellow-500", orderDisplayStatus === "success" && "bg-green-500/10 text-green-500", orderDisplayStatus === "failure" && "bg-red-500/10 text-red-500"), children: orderStatusText }), (0, jsx_runtime_1.jsx)("div", { className: "flex items-center gap-2", children: (0, jsx_runtime_1.jsx)("span", { className: "text-nano label-style text-as-primary/30", children: (0, jsx_runtime_1.jsx)(react_timeago_1.default, { date: new Date(order.createdAt) }) }) })] }), order.oneClickBuyUrl ? ((0, jsx_runtime_1.jsx)("div", { className: "mb-3 mt-4 flex items-center gap-1", children: (0, jsx_runtime_1.jsxs)("div", { className: "bg-b3-react-background flex flex-1 flex-col gap-1 rounded-lg border p-4 px-5", children: [(0, jsx_runtime_1.jsxs)("h3", { className: "text-as-primary/50 flex items-center gap-2 text-xl font-semibold", children: [(0, jsx_runtime_1.jsxs)("span", { children: ["Buy ", (0, jsx_runtime_1.jsxs)("span", { className: "text-as-primary", children: ["$", (0, number_1.formatTokenAmount)(BigInt(order.srcAmount), order.metadata.srcToken.decimals)] }), ` of`] }), (0, jsx_runtime_1.jsxs)("span", { className: "text-as-primary flex items-center gap-2", children: [nft ? ((0, jsx_runtime_1.jsx)("img", { src: nft.imageUrl, alt: nft.name, className: "h-6 w-6" })) : tournament ? ((0, jsx_runtime_1.jsx)("img", { src: tournament.imageUrl, alt: tournament.name, className: "h-6 w-6" })) : ((0, jsx_runtime_1.jsx)("img", { src: dstToken.metadata.logoURI, alt: dstToken.symbol, className: "h-6 w-6" })), nft ? nft.name : tournament ? tournament.name : dstToken.symbol] }), (0, jsx_runtime_1.jsxs)("span", { className: "flex items-center gap-2", children: [` on `, (0, jsx_runtime_1.jsxs)("span", { className: "text-as-primary flex items-center gap-2", children: [(0, jsx_runtime_1.jsx)("img", { src: anyspend_1.ALL_CHAINS[order.dstChain]?.logoUrl, alt: (0, anyspend_1.getChainName)(order.dstChain), className: "h-4" }), order.dstChain !== chains_1.b3.id && (0, anyspend_1.getChainName)(order.dstChain)] })] })] }), (0, jsx_runtime_1.jsxs)("p", { className: "label-style text-as-primary/30 mt-1 flex items-center gap-2 text-xs", children: ["Paying via", " ", (0, jsx_runtime_1.jsx)("img", { src: "https://cdn.b3.fun/coinbase-wordmark-blue.svg", alt: "Coinbase", className: "-mt-1 h-3" })] })] }) })) : ((0, jsx_runtime_1.jsxs)("div", { className: (0, utils_1.cn)("mb-3 mt-4 flex items-center gap-1", isSmallView && "flex-col"), children: [(0, jsx_runtime_1.jsxs)("div", { className: "bg-b3-react-background flex w-full flex-1 flex-col gap-1 overflow-hidden rounded-lg border p-4 px-5", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2", children: [(0, jsx_runtime_1.jsx)("img", { src: order.metadata.srcToken.metadata.logoURI, alt: order.metadata.srcToken.symbol, className: "h-6 w-6 rounded-full" }), (0, jsx_runtime_1.jsxs)("div", { className: "text-as-primary flex items-center gap-2 overflow-hidden text-ellipsis whitespace-nowrap text-xl font-semibold", children: [(0, number_1.formatTokenAmount)(BigInt(order.srcAmount), order.metadata.srcToken.decimals), " ", order.metadata.srcToken.symbol] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "label-style text-as-primary/50 flex items-center gap-2 text-sm", children: ["from", (0, jsx_runtime_1.jsx)("img", { src: anyspend_1.ALL_CHAINS[order.srcChain]?.logoUrl, alt: (0, anyspend_1.getChainName)(order.srcChain), className: (0, utils_1.cn)("h-4", order.srcChain !== chains_1.b3.id && "w-4 rounded-full", order.srcChain === chains_1.b3.id && "h-3") }), (0, anyspend_1.getChainName)(order.srcChain)] })] }), (0, jsx_runtime_1.jsx)("div", { className: (0, utils_1.cn)("h-8 w-8 shrink-0 -rotate-90 opacity-30", isSmallView && "rotate-0"), children: (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronDown, { className: "h-8 w-8" }) }), (0, jsx_runtime_1.jsxs)("div", { className: "bg-b3-react-background flex w-full flex-1 flex-col gap-1 overflow-hidden rounded-lg border p-4 px-5", children: [(0, jsx_runtime_1.jsx)("div", { className: "flex items-center gap-2", children: nft ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("img", { src: nft.imageUrl, alt: nft.name, className: "h-6 w-6 rounded-full" }), (0, jsx_runtime_1.jsx)("div", { className: "text-as-primary overflow-hidden text-ellipsis whitespace-nowrap text-xl font-semibold", children: nft.name })] })) : tournament ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("img", { src: tournament.imageUrl, alt: tournament.name, className: "h-6 w-6 rounded-full" }), (0, jsx_runtime_1.jsx)("div", { className: "text-as-primary overflow-hidden text-ellipsis whitespace-nowrap text-xl font-semibold", children: tournament.name })] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("img", { src: dstToken.metadata.logoURI, alt: dstToken.symbol, className: "h-6 w-6 rounded-full" }), (0, jsx_runtime_1.jsxs)("div", { className: "text-as-primary overflow-hidden text-ellipsis whitespace-nowrap text-xl font-semibold", children: [(0, number_1.formatTokenAmount)(actualDstAmount ? BigInt(actualDstAmount) : expectedDstAmount ? BigInt(expectedDstAmount) : 0n, dstToken.decimals), " ", dstToken.symbol] })] })) }), (0, jsx_runtime_1.jsxs)("div", { className: "label-style text-as-primary/50 flex items-center gap-2 text-sm", children: ["to", (0, jsx_runtime_1.jsx)("img", { src: anyspend_1.ALL_CHAINS[order.dstChain]?.logoUrl, alt: (0, anyspend_1.getChainName)(order.dstChain), className: (0, utils_1.cn)("h-4", order.dstChain !== chains_1.b3.id && "w-4 rounded-full", order.dstChain === chains_1.b3.id && "h-3") }), (0, anyspend_1.getChainName)(order.dstChain)] })] })] })), (0, jsx_runtime_1.jsx)("div", { className: "flex items-center justify-end", children: (0, jsx_runtime_1.jsxs)(react_1.Button, { variant: "link", size: "sm", className: "h-auto", onClick: () => onSelectOrder?.(order.id), children: [orderDisplayStatus === "processing" ? "Proceed with payment" : "Details", " ", (0, jsx_runtime_1.jsx)(lucide_react_1.ArrowRight, { className: "ml-2 h-3 w-3" })] }) })] }, `anyspend-${order.id}`));
35
+ return ((0, jsx_runtime_1.jsxs)("div", { className: (0, utils_1.cn)("bg-as-light-brand/20 rounded-lg border p-4", onSelectOrder && "hover:bg-as-light-brand/30 hover:border-as-brand cursor-pointer transition-colors"), onClick: () => onSelectOrder?.(order.id), children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)(react_1.Badge, { className: (0, utils_1.cn)("px-3 py-1 text-xs", orderDisplayStatus === "processing" && "bg-yellow-500/10 text-yellow-500", orderDisplayStatus === "success" && "bg-green-500/10 text-green-500", orderDisplayStatus === "failure" && "bg-red-500/10 text-red-500"), children: orderStatusText }), (0, jsx_runtime_1.jsx)("div", { className: "flex items-center gap-2", children: (0, jsx_runtime_1.jsx)("span", { className: "text-nano label-style text-as-primary/30", children: (0, jsx_runtime_1.jsx)(react_timeago_1.default, { date: new Date(order.createdAt) }) }) })] }), order.oneClickBuyUrl ? ((0, jsx_runtime_1.jsx)("div", { className: "mb-3 mt-4 flex items-center gap-1", children: (0, jsx_runtime_1.jsxs)("div", { className: "bg-b3-react-background flex flex-1 flex-col gap-1 rounded-lg border p-4 px-5", children: [(0, jsx_runtime_1.jsxs)("h3", { className: "text-as-primary/50 flex items-center gap-2 text-xl font-semibold", children: [(0, jsx_runtime_1.jsxs)("span", { children: ["Buy ", (0, jsx_runtime_1.jsxs)("span", { className: "text-as-primary", children: ["$", (0, number_1.formatTokenAmount)(BigInt(order.srcAmount), order.metadata.srcToken.decimals)] }), ` of`] }), (0, jsx_runtime_1.jsxs)("span", { className: "text-as-primary flex items-center gap-2", children: [nft ? ((0, jsx_runtime_1.jsx)("img", { src: nft.imageUrl, alt: nft.name, className: "h-6 w-6" })) : tournament ? ((0, jsx_runtime_1.jsx)("img", { src: tournament.imageUrl, alt: tournament.name, className: "h-6 w-6" })) : ((0, jsx_runtime_1.jsx)("img", { src: dstToken.metadata.logoURI, alt: dstToken.symbol, className: "h-6 w-6" })), nft ? nft.name : tournament ? tournament.name : dstToken.symbol] }), (0, jsx_runtime_1.jsxs)("span", { className: "flex items-center gap-2", children: [` on `, (0, jsx_runtime_1.jsxs)("span", { className: "text-as-primary flex items-center gap-2", children: [(0, jsx_runtime_1.jsx)("img", { src: anyspend_1.ALL_CHAINS[order.dstChain]?.logoUrl, alt: (0, anyspend_1.getChainName)(order.dstChain), className: "h-4" }), order.dstChain !== chains_1.b3.id && (0, anyspend_1.getChainName)(order.dstChain)] })] })] }), (0, jsx_runtime_1.jsxs)("p", { className: "label-style text-as-primary/30 mt-1 flex items-center gap-2 text-xs", children: ["Paying via", " ", (0, jsx_runtime_1.jsx)("img", { src: "https://cdn.b3.fun/coinbase-wordmark-blue.svg", alt: "Coinbase", className: "-mt-1 h-3" })] })] }) })) : ((0, jsx_runtime_1.jsxs)("div", { className: (0, utils_1.cn)("mb-3 mt-4 flex items-center gap-1", isSmallView && "flex-col"), children: [(0, jsx_runtime_1.jsxs)("div", { className: "bg-b3-react-background flex w-full flex-1 flex-col gap-1 overflow-hidden rounded-lg border p-4 px-5", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2", children: [(0, jsx_runtime_1.jsx)("img", { src: order.metadata.srcToken.metadata.logoURI, alt: order.metadata.srcToken.symbol, className: "h-6 w-6 rounded-full" }), (0, jsx_runtime_1.jsxs)("div", { className: "text-as-primary flex items-center gap-2 overflow-hidden text-ellipsis whitespace-nowrap text-xl font-semibold", children: [(0, number_1.formatTokenAmount)(BigInt(order.srcAmount), order.metadata.srcToken.decimals), " ", order.metadata.srcToken.symbol] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "label-style text-as-primary/50 flex items-center gap-2 text-sm", children: ["from", (0, jsx_runtime_1.jsx)("img", { src: anyspend_1.ALL_CHAINS[order.srcChain]?.logoUrl, alt: (0, anyspend_1.getChainName)(order.srcChain), className: (0, utils_1.cn)("h-4", order.srcChain !== chains_1.b3.id && "w-4 rounded-full", order.srcChain === chains_1.b3.id && "h-3") }), (0, anyspend_1.getChainName)(order.srcChain)] })] }), (0, jsx_runtime_1.jsx)("div", { className: (0, utils_1.cn)("h-8 w-8 shrink-0 -rotate-90 opacity-30", isSmallView && "rotate-0"), children: (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronDown, { className: "h-8 w-8" }) }), (0, jsx_runtime_1.jsxs)("div", { className: "bg-b3-react-background flex w-full flex-1 flex-col gap-1 overflow-hidden rounded-lg border p-4 px-5", children: [(0, jsx_runtime_1.jsx)("div", { className: "flex items-center gap-2", children: nft ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("img", { src: nft.imageUrl, alt: nft.name, className: "h-6 w-6 rounded-full" }), (0, jsx_runtime_1.jsx)("div", { className: "text-as-primary overflow-hidden text-ellipsis whitespace-nowrap text-xl font-semibold", children: nft.name })] })) : tournament ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("img", { src: tournament.imageUrl, alt: tournament.name, className: "h-6 w-6 rounded-full" }), (0, jsx_runtime_1.jsx)("div", { className: "text-as-primary overflow-hidden text-ellipsis whitespace-nowrap text-xl font-semibold", children: tournament.name })] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("img", { src: dstToken.metadata.logoURI, alt: dstToken.symbol, className: "h-6 w-6 rounded-full" }), (0, jsx_runtime_1.jsxs)("div", { className: "text-as-primary overflow-hidden text-ellipsis whitespace-nowrap text-xl font-semibold", children: [(0, number_1.formatTokenAmount)(actualDstAmount
36
+ ? BigInt(actualDstAmount)
37
+ : expectedDstAmount
38
+ ? BigInt(expectedDstAmount)
39
+ : BigInt(0), dstToken.decimals), " ", dstToken.symbol] })] })) }), (0, jsx_runtime_1.jsxs)("div", { className: "label-style text-as-primary/50 flex items-center gap-2 text-sm", children: ["to", (0, jsx_runtime_1.jsx)("img", { src: anyspend_1.ALL_CHAINS[order.dstChain]?.logoUrl, alt: (0, anyspend_1.getChainName)(order.dstChain), className: (0, utils_1.cn)("h-4", order.dstChain !== chains_1.b3.id && "w-4 rounded-full", order.dstChain === chains_1.b3.id && "h-3") }), (0, anyspend_1.getChainName)(order.dstChain)] })] })] })), (0, jsx_runtime_1.jsx)("div", { className: "flex items-center justify-end", children: (0, jsx_runtime_1.jsxs)(react_1.Button, { variant: "link", size: "sm", className: "h-auto", onClick: () => onSelectOrder?.(order.id), children: [orderDisplayStatus === "processing" ? "Proceed with payment" : "Details", " ", (0, jsx_runtime_1.jsx)(lucide_react_1.ArrowRight, { className: "ml-2 h-3 w-3" })] }) })] }, `anyspend-${order.id}`));
36
40
  }
@@ -14,7 +14,7 @@ function TokenBalance({ token, walletAddress, onChangeInput }) {
14
14
  return;
15
15
  // Calculate the amount based on percentage of balance
16
16
  // Multiply first, then divide to avoid BigInt truncation
17
- const amount = percentage === 100 ? rawBalance : (rawBalance * BigInt(percentage)) / 100n;
17
+ const amount = percentage === 100 ? rawBalance : (rawBalance * BigInt(percentage)) / BigInt(100);
18
18
  onChangeInput((0, viem_1.formatUnits)(amount, token.decimals));
19
19
  };
20
20
  return ((0, jsx_runtime_1.jsx)("div", { className: "flex h-7 items-center justify-end gap-1", children: !isLoading && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: "text-as-primary/50 inline-flex rounded-lg text-sm", children: rawBalance ? `Balance: ${formattedBalance}` : `Balance: 0` }), !!rawBalance && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("button", { onClick: () => handlePercentageClick(20), className: "text-as-primary/50 bg-as-on-surface-2 hover:bg-as-on-surface-3 inline-flex rounded-lg px-2 py-1 text-xs transition-colors sm:hidden", children: "20%" }), (0, jsx_runtime_1.jsx)("button", { onClick: () => handlePercentageClick(50), className: "text-as-primary/50 bg-as-on-surface-2 hover:bg-as-on-surface-3 inline-flex rounded-lg px-2 py-1 text-xs transition-colors", children: "50%" }), (0, jsx_runtime_1.jsx)("button", { onClick: () => handlePercentageClick(100), className: "text-as-primary/50 bg-as-on-surface-2 hover:bg-as-on-surface-3 inline-flex rounded-lg px-2 py-1 text-xs transition-colors", children: "MAX" })] }))] })) }, `balance-${token.address}-${token.chainId}`));
@@ -267,6 +267,9 @@ 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
+ }
270
273
  if (exports.EVM_CHAINS[chainId]) {
271
274
  return exports.EVM_CHAINS[chainId].viem.blockExplorers?.default.url + "/tx/" + txHash;
272
275
  }
@@ -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 B3Provider_1 = require("./B3Provider");
8
+ const useB3_1 = require("./B3Provider/useB3");
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, B3Provider_1.useB3)();
18
+ const { theme } = (0, useB3_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,34 +1,8 @@
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";
1
+ import { PermissionsConfig } from "../../../../global-account/types/permissions";
2
+ import { Account } from "thirdweb/wallets";
4
3
  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;
32
6
  /**
33
7
  * Main B3Provider component
34
8
  */
@@ -1,19 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.B3Context = exports.wagmiConfig = void 0;
4
- exports.useB3 = useB3;
3
+ exports.wagmiConfig = void 0;
5
4
  exports.B3Provider = B3Provider;
6
5
  exports.InnerProvider = InnerProvider;
7
6
  const jsx_runtime_1 = require("react/jsx-runtime");
8
- const supported_1 = require("../../../shared/constants/chains/supported");
7
+ const supported_1 = require("../../../../shared/constants/chains/supported");
9
8
  const react_query_1 = require("@tanstack/react-query");
10
9
  const react_1 = require("react");
11
10
  const sonner_1 = require("sonner");
12
11
  const react_2 = require("thirdweb/react");
13
12
  const wagmi_1 = require("wagmi");
14
- const RelayKitProviderWrapper_1 = require("./RelayKitProviderWrapper");
15
- const StyleRoot_1 = require("./StyleRoot");
13
+ const RelayKitProviderWrapper_1 = require("../RelayKitProviderWrapper");
14
+ const StyleRoot_1 = require("../StyleRoot");
16
15
  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,34 +27,6 @@ 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
- }
58
30
  // Create queryClient instance
59
31
  const queryClient = new react_query_1.QueryClient();
60
32
  /**
@@ -98,7 +70,7 @@ function InnerProvider({ children, accountOverride, environment, defaultPermissi
98
70
  }
99
71
  // eslint-disable-next-line react-hooks/exhaustive-deps
100
72
  }, [automaticallySetFirstEoa, wallets]);
101
- return ((0, jsx_runtime_1.jsx)(exports.B3Context.Provider, { value: {
73
+ return ((0, jsx_runtime_1.jsx)(types_1.B3Context.Provider, { value: {
102
74
  account: effectiveAccount,
103
75
  setAccount,
104
76
  setWallet,