@b3dotfun/sdk 0.0.62 → 0.0.63-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpend.js +61 -23
  2. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +3 -0
  3. package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.d.ts +34 -0
  4. package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +275 -0
  5. package/dist/cjs/anyspend/react/components/AnySpendStakeB3.js +5 -4
  6. package/dist/cjs/anyspend/react/components/AnySpendStakeB3ExactIn.d.ts +9 -0
  7. package/dist/cjs/anyspend/react/components/AnySpendStakeB3ExactIn.js +288 -0
  8. package/dist/cjs/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +11 -0
  9. package/dist/cjs/anyspend/react/components/AnySpendStakeUpsideExactIn.js +33 -0
  10. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +4 -4
  11. package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +4 -6
  12. package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +9 -17
  13. package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.d.ts +6 -1
  14. package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.js +11 -1
  15. package/dist/cjs/anyspend/react/components/common/OrderDetails.js +66 -147
  16. package/dist/cjs/anyspend/react/components/common/OrderDetailsCollapsible.js +2 -3
  17. package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.d.ts +2 -1
  18. package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +39 -15
  19. package/dist/cjs/anyspend/react/components/common/PaySection.js +1 -1
  20. package/dist/cjs/anyspend/react/components/common/TokenBalance.js +1 -1
  21. package/dist/cjs/anyspend/react/components/index.d.ts +5 -1
  22. package/dist/cjs/anyspend/react/components/index.js +11 -3
  23. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +25 -3
  24. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +42 -19
  25. package/dist/cjs/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +116 -0
  26. package/dist/cjs/anyspend/react/hooks/useAnyspendQuote.js +1 -1
  27. package/dist/cjs/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +26 -0
  28. package/dist/cjs/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.js +56 -0
  29. package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +10 -0
  30. package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +73 -0
  31. package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +14 -0
  32. package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.js +57 -0
  33. package/dist/cjs/anyspend/react/hooks/usePhantomTransfer.d.ts +36 -0
  34. package/dist/cjs/anyspend/react/hooks/usePhantomTransfer.js +211 -0
  35. package/dist/cjs/anyspend/types/api.d.ts +665 -3
  36. package/dist/cjs/anyspend/utils/orderPayload.js +4 -0
  37. package/dist/cjs/global-account/react/components/B3DynamicModal.js +10 -1
  38. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +3 -1
  39. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +2 -2
  40. package/dist/cjs/global-account/react/hooks/index.d.ts +2 -1
  41. package/dist/cjs/global-account/react/hooks/index.js +5 -3
  42. package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +2 -2
  43. package/dist/cjs/global-account/react/hooks/useAuthentication.js +7 -2
  44. package/dist/cjs/global-account/react/hooks/useSimBalance.d.ts +1 -1
  45. package/dist/cjs/global-account/react/hooks/useSimBalance.js +6 -5
  46. package/dist/cjs/global-account/react/hooks/useTokenBalanceDirect.d.ts +12 -0
  47. package/dist/cjs/global-account/react/hooks/useTokenBalanceDirect.js +62 -0
  48. package/dist/cjs/global-account/react/hooks/useTokenFromUrl.js +4 -3
  49. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +31 -1
  50. package/dist/esm/anyspend/react/components/AnySpend.js +62 -24
  51. package/dist/esm/anyspend/react/components/AnySpendCustom.js +3 -0
  52. package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.d.ts +34 -0
  53. package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +269 -0
  54. package/dist/esm/anyspend/react/components/AnySpendStakeB3.js +7 -6
  55. package/dist/esm/anyspend/react/components/AnySpendStakeB3ExactIn.d.ts +9 -0
  56. package/dist/esm/anyspend/react/components/AnySpendStakeB3ExactIn.js +285 -0
  57. package/dist/esm/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +11 -0
  58. package/dist/esm/anyspend/react/components/AnySpendStakeUpsideExactIn.js +30 -0
  59. package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +4 -4
  60. package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +5 -7
  61. package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +9 -17
  62. package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.d.ts +6 -1
  63. package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.js +11 -1
  64. package/dist/esm/anyspend/react/components/common/OrderDetails.js +67 -148
  65. package/dist/esm/anyspend/react/components/common/OrderDetailsCollapsible.js +2 -3
  66. package/dist/esm/anyspend/react/components/common/OrderTokenAmount.d.ts +2 -1
  67. package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +40 -16
  68. package/dist/esm/anyspend/react/components/common/PaySection.js +1 -1
  69. package/dist/esm/anyspend/react/components/common/TokenBalance.js +2 -2
  70. package/dist/esm/anyspend/react/components/index.d.ts +5 -1
  71. package/dist/esm/anyspend/react/components/index.js +5 -1
  72. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +25 -3
  73. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +42 -19
  74. package/dist/esm/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +116 -0
  75. package/dist/esm/anyspend/react/hooks/useAnyspendQuote.js +1 -1
  76. package/dist/esm/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +26 -0
  77. package/dist/esm/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.js +53 -0
  78. package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +10 -0
  79. package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +70 -0
  80. package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +14 -0
  81. package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.js +54 -0
  82. package/dist/esm/anyspend/react/hooks/usePhantomTransfer.d.ts +36 -0
  83. package/dist/esm/anyspend/react/hooks/usePhantomTransfer.js +208 -0
  84. package/dist/esm/anyspend/types/api.d.ts +665 -3
  85. package/dist/esm/anyspend/utils/orderPayload.js +4 -0
  86. package/dist/esm/global-account/react/components/B3DynamicModal.js +11 -2
  87. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +3 -1
  88. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +2 -2
  89. package/dist/esm/global-account/react/hooks/index.d.ts +2 -1
  90. package/dist/esm/global-account/react/hooks/index.js +2 -1
  91. package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +2 -2
  92. package/dist/esm/global-account/react/hooks/useAuthentication.js +7 -2
  93. package/dist/esm/global-account/react/hooks/useSimBalance.d.ts +1 -1
  94. package/dist/esm/global-account/react/hooks/useSimBalance.js +6 -5
  95. package/dist/esm/global-account/react/hooks/useTokenBalanceDirect.d.ts +12 -0
  96. package/dist/esm/global-account/react/hooks/useTokenBalanceDirect.js +59 -0
  97. package/dist/esm/global-account/react/hooks/useTokenFromUrl.js +4 -3
  98. package/dist/esm/global-account/react/stores/useModalStore.d.ts +31 -1
  99. package/dist/types/anyspend/react/components/AnySpendCustomExactIn.d.ts +34 -0
  100. package/dist/types/anyspend/react/components/AnySpendStakeB3ExactIn.d.ts +9 -0
  101. package/dist/types/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +11 -0
  102. package/dist/types/anyspend/react/components/common/CryptoReceiveSection.d.ts +6 -1
  103. package/dist/types/anyspend/react/components/common/OrderTokenAmount.d.ts +2 -1
  104. package/dist/types/anyspend/react/components/index.d.ts +5 -1
  105. package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +25 -3
  106. package/dist/types/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +116 -0
  107. package/dist/types/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +26 -0
  108. package/dist/types/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +10 -0
  109. package/dist/types/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +14 -0
  110. package/dist/types/anyspend/react/hooks/usePhantomTransfer.d.ts +36 -0
  111. package/dist/types/anyspend/types/api.d.ts +665 -3
  112. package/dist/types/global-account/react/hooks/index.d.ts +2 -1
  113. package/dist/types/global-account/react/hooks/useAuthentication.d.ts +2 -2
  114. package/dist/types/global-account/react/hooks/useSimBalance.d.ts +1 -1
  115. package/dist/types/global-account/react/hooks/useTokenBalanceDirect.d.ts +12 -0
  116. package/dist/types/global-account/react/stores/useModalStore.d.ts +31 -1
  117. package/package.json +3 -2
  118. package/src/anyspend/react/components/AnySpend.tsx +73 -22
  119. package/src/anyspend/react/components/AnySpendCustom.tsx +4 -0
  120. package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +595 -0
  121. package/src/anyspend/react/components/AnySpendStakeB3.tsx +8 -11
  122. package/src/anyspend/react/components/AnySpendStakeB3ExactIn.tsx +522 -0
  123. package/src/anyspend/react/components/AnySpendStakeUpsideExactIn.tsx +73 -0
  124. package/src/anyspend/react/components/AnyspendDepositHype.tsx +7 -3
  125. package/src/anyspend/react/components/common/CryptoPaySection.tsx +5 -7
  126. package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +9 -18
  127. package/src/anyspend/react/components/common/CryptoReceiveSection.tsx +22 -0
  128. package/src/anyspend/react/components/common/OrderDetails.tsx +76 -190
  129. package/src/anyspend/react/components/common/OrderDetailsCollapsible.tsx +2 -3
  130. package/src/anyspend/react/components/common/OrderTokenAmount.tsx +48 -17
  131. package/src/anyspend/react/components/common/PaySection.tsx +1 -0
  132. package/src/anyspend/react/components/common/TokenBalance.tsx +2 -2
  133. package/src/anyspend/react/components/index.ts +5 -1
  134. package/src/anyspend/react/hooks/useAnyspendFlow.ts +51 -18
  135. package/src/anyspend/react/hooks/useAnyspendQuote.ts +1 -1
  136. package/src/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.ts +72 -0
  137. package/src/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.ts +80 -0
  138. package/src/anyspend/react/hooks/useConnectedWalletDisplay.ts +69 -0
  139. package/src/anyspend/react/hooks/usePhantomTransfer.ts +301 -0
  140. package/src/anyspend/types/api.ts +669 -1
  141. package/src/anyspend/utils/orderPayload.ts +5 -1
  142. package/src/global-account/react/components/B3DynamicModal.tsx +11 -1
  143. package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +3 -1
  144. package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +2 -2
  145. package/src/global-account/react/hooks/index.ts +2 -1
  146. package/src/global-account/react/hooks/useAuthentication.ts +10 -2
  147. package/src/global-account/react/hooks/useSimBalance.ts +6 -5
  148. package/src/global-account/react/hooks/useTokenBalanceDirect.tsx +84 -0
  149. package/src/global-account/react/hooks/useTokenFromUrl.tsx +6 -5
  150. package/src/global-account/react/stores/useModalStore.ts +34 -0
@@ -1,5 +1,5 @@
1
- import { normalizeAddress } from "@b3dotfun/sdk/anyspend/utils";
2
1
  import { components } from "@b3dotfun/sdk/anyspend/types/api";
2
+ import { normalizeAddress } from "@b3dotfun/sdk/anyspend/utils";
3
3
 
4
4
  export type OrderParams = {
5
5
  orderType: components["schemas"]["Order"]["type"];
@@ -48,6 +48,8 @@ export const buildPayload = (orderType: components["schemas"]["Order"]["type"],
48
48
  };
49
49
  case "custom":
50
50
  return { ...payload };
51
+ case "custom_exact_in":
52
+ return { ...payload, expectedDstAmount };
51
53
  case "hype_duel":
52
54
  return {
53
55
  expectedDstAmount,
@@ -73,6 +75,8 @@ export const buildMetadata = (orderType: components["schemas"]["Order"]["type"],
73
75
  return { ...baseMetadata, tournament };
74
76
  case "custom":
75
77
  return { ...baseMetadata, action: payload.action };
78
+ case "custom_exact_in":
79
+ return { ...baseMetadata, action: payload.action };
76
80
  case "hype_duel":
77
81
  return { ...baseMetadata };
78
82
  default:
@@ -5,16 +5,19 @@ import {
5
5
  AnySpendNFT,
6
6
  AnyspendSignatureMint,
7
7
  AnySpendStakeB3,
8
+ AnySpendStakeB3ExactIn,
8
9
  AnySpendTournament,
9
10
  OrderHistory,
10
11
  } from "@b3dotfun/sdk/anyspend/react";
11
12
  import { AnySpendDepositHype } from "@b3dotfun/sdk/anyspend/react/components/AnyspendDepositHype";
12
13
  import { AnySpendStakeUpside } from "@b3dotfun/sdk/anyspend/react/components/AnySpendStakeUpside";
14
+ import { AnySpendStakeUpsideExactIn } from "@b3dotfun/sdk/anyspend/react/components/AnySpendStakeUpsideExactIn";
13
15
  import { useGlobalWalletState } from "@b3dotfun/sdk/anyspend/utils";
14
16
  import { useIsMobile, useModalStore } from "@b3dotfun/sdk/global-account/react";
15
17
  import { cn } from "@b3dotfun/sdk/shared/utils/cn";
16
18
  import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
17
19
  import { useEffect, useRef } from "react";
20
+ import { useSetActiveWallet } from "thirdweb/react";
18
21
  import { AvatarEditor } from "./AvatarEditor/AvatarEditor";
19
22
  import { useB3 } from "./B3Provider/useB3";
20
23
  import { LinkAccount } from "./LinkAccount/LinkAccount";
@@ -23,7 +26,6 @@ import { RequestPermissions } from "./RequestPermissions/RequestPermissions";
23
26
  import { SignInWithB3Flow } from "./SignInWithB3/SignInWithB3Flow";
24
27
  import { Dialog, DialogContent, DialogDescription, DialogTitle } from "./ui/dialog";
25
28
  import { Drawer, DrawerContent, DrawerDescription, DrawerTitle } from "./ui/drawer";
26
- import { useSetActiveWallet } from "thirdweb/react";
27
29
 
28
30
  const debug = debugB3React("B3DynamicModal");
29
31
 
@@ -56,7 +58,9 @@ export function B3DynamicModal() {
56
58
  "anySpendJoinTournament",
57
59
  "anySpendFundTournament",
58
60
  "anySpendStakeB3",
61
+ "anySpendStakeB3ExactIn",
59
62
  "anySpendStakeUpside",
63
+ "anySpendStakeUpsideExactIn",
60
64
  "anySpendBuySpin",
61
65
  "anySpendOrderHistory",
62
66
  "signInWithB3",
@@ -71,7 +75,9 @@ export function B3DynamicModal() {
71
75
  "anySpendJoinTournament",
72
76
  "anySpendFundTournament",
73
77
  "anySpendStakeB3",
78
+ "anySpendStakeB3ExactIn",
74
79
  "anySpendStakeUpside",
80
+ "anySpendStakeUpsideExactIn",
75
81
  "anySpendBuySpin",
76
82
  "anySpendSignatureMint",
77
83
  "anySpendBondKit",
@@ -120,8 +126,12 @@ export function B3DynamicModal() {
120
126
  return <OrderHistory onBack={() => {}} mode="modal" />;
121
127
  case "anySpendStakeB3":
122
128
  return <AnySpendStakeB3 {...contentType} mode="modal" />;
129
+ case "anySpendStakeB3ExactIn":
130
+ return <AnySpendStakeB3ExactIn {...contentType} mode="modal" />;
123
131
  case "anySpendStakeUpside":
124
132
  return <AnySpendStakeUpside {...contentType} mode="modal" />;
133
+ case "anySpendStakeUpsideExactIn":
134
+ return <AnySpendStakeUpsideExactIn {...contentType} mode="modal" />;
125
135
  case "anySpendBuySpin":
126
136
  return <AnySpendBuySpin {...contentType} mode="modal" />;
127
137
  case "anySpendSignatureMint":
@@ -39,6 +39,7 @@ export function SignInWithB3Flow({
39
39
  const { setB3ModalContentType, setB3ModalOpen, isOpen } = useModalStore();
40
40
  const account = useActiveAccount();
41
41
  const isAuthenticating = useAuthStore(state => state.isAuthenticating);
42
+ const isAuthenticated = useAuthStore(state => state.isAuthenticated);
42
43
  const isConnected = useAuthStore(state => state.isConnected);
43
44
  const [refetchCount, setRefetchCount] = useState(0);
44
45
  const [refetchError, setRefetchError] = useState<string | null>(null);
@@ -92,7 +93,7 @@ export function SignInWithB3Flow({
92
93
  source,
93
94
  });
94
95
 
95
- if (isConnected) {
96
+ if (isConnected && isAuthenticated) {
96
97
  // Check if we already have a signer for this partner
97
98
  const hasExistingSigner = signers?.some(signer => signer.partner.id === partnerId);
98
99
  if (hasExistingSigner) {
@@ -139,6 +140,7 @@ export function SignInWithB3Flow({
139
140
  signersEnabled,
140
141
  isConnected,
141
142
  isAuthenticating,
143
+ isAuthenticated,
142
144
  isOpen,
143
145
  ]);
144
146
 
@@ -86,8 +86,8 @@ export function LoginStep({ onSuccess, chain }: LoginStepProps) {
86
86
  titleIcon: "https://cdn.b3.fun/b3_logo.svg",
87
87
  }}
88
88
  className="b3-login-step"
89
- onConnect={async wallet => {
90
- await onConnect(wallet);
89
+ onConnect={async (wallet, allConnectedWallets) => {
90
+ await onConnect(wallet, allConnectedWallets);
91
91
  const account = wallet.getAccount();
92
92
  if (!account) throw new Error("No account found");
93
93
  await onSuccess(account);
@@ -38,11 +38,12 @@ export { useSearchParamsSSR } from "./useSearchParamsSSR";
38
38
  export { useSimBalance } from "./useSimBalance";
39
39
  export { useSiwe } from "./useSiwe";
40
40
  export { useTokenBalance } from "./useTokenBalance";
41
+ export { useTokenBalanceDirect } from "./useTokenBalanceDirect";
41
42
  export { useTokenBalancesByChain } from "./useTokenBalancesByChain";
42
43
  export { useTokenData } from "./useTokenData";
43
44
  export { useTokenFromUrl } from "./useTokenFromUrl";
44
45
  export { useTokenPrice } from "./useTokenPrice";
45
46
  export { useTokenPriceWithFallback } from "./useTokenPriceWithFallback";
46
47
  export { useTokensFromAddress } from "./useTokensFromAddress";
47
- export { useUnifiedChainSwitchAndExecute } from "./useUnifiedChainSwitchAndExecute";
48
48
  export { useURLParams } from "./useURLParams";
49
+ export { useUnifiedChainSwitchAndExecute } from "./useUnifiedChainSwitchAndExecute";
@@ -164,7 +164,15 @@ export function useAuthentication(partnerId: string) {
164
164
  );
165
165
 
166
166
  const onConnect = useCallback(
167
- async (wallet: Wallet) => {
167
+ async (_walleAutoConnectedWith: Wallet, allConnectedWallets: Wallet[]) => {
168
+ debug("@@useAuthentication:onConnect", { _walleAutoConnectedWith, allConnectedWallets });
169
+
170
+ const wallet = allConnectedWallets.find(wallet => wallet.id.startsWith("ecosystem."));
171
+
172
+ if (!wallet) {
173
+ throw new Error("No smart wallet found during auto-connect");
174
+ }
175
+
168
176
  debug("@@useAuthentication:onConnect", { wallet });
169
177
 
170
178
  try {
@@ -243,7 +251,7 @@ export function useAuthentication(partnerId: string) {
243
251
  const { isLoading: useAutoConnectLoading } = useAutoConnect({
244
252
  client,
245
253
  wallets: [wallet],
246
- onConnect: onConnect,
254
+ onConnect,
247
255
  });
248
256
 
249
257
  /**
@@ -26,10 +26,11 @@ export interface SimBalanceResponse {
26
26
  balances: SimBalanceItem[];
27
27
  }
28
28
 
29
- async function fetchSimBalance(address: string): Promise<SimBalanceResponse> {
29
+ async function fetchSimBalance(address: string, chainIdsParam: number[]): Promise<SimBalanceResponse> {
30
30
  if (!address) throw new Error("Address is required");
31
31
 
32
- let url = `https://simdune-api.sean-430.workers.dev/?url=https://api.sim.dune.com/v1/evm/balances/${address}?metadata=logo&chain_ids=mainnet`;
32
+ const chainIds = chainIdsParam.length === 0 ? "mainnet" : chainIdsParam.join(",");
33
+ let url = `https://simdune-api.sean-430.workers.dev/?url=https://api.sim.dune.com/v1/evm/balances/${address}?metadata=logo&chain_ids=${chainIds}`;
33
34
  if (process.env.NEXT_PUBLIC_LOCAL_KEY) {
34
35
  url += `&localkey=${process.env.NEXT_PUBLIC_LOCAL_KEY}`;
35
36
  }
@@ -44,12 +45,12 @@ async function fetchSimBalance(address: string): Promise<SimBalanceResponse> {
44
45
  return balanceData;
45
46
  }
46
47
 
47
- export function useSimBalance(address?: string) {
48
+ export function useSimBalance(address?: string, chainIdsParam?: number[]) {
48
49
  return useQuery({
49
- queryKey: ["simBalance", address],
50
+ queryKey: ["simBalance", address, chainIdsParam],
50
51
  queryFn: () => {
51
52
  if (!address) throw new Error("Address is required");
52
- return fetchSimBalance(address);
53
+ return fetchSimBalance(address, chainIdsParam || []);
53
54
  },
54
55
  enabled: Boolean(address),
55
56
  });
@@ -0,0 +1,84 @@
1
+ "use client";
2
+
3
+ import { isNativeToken } from "@b3dotfun/sdk/anyspend";
4
+ import { components } from "@b3dotfun/sdk/anyspend/types/api";
5
+ import { useAccountWallet } from "@b3dotfun/sdk/global-account/react";
6
+ import { formatTokenAmount } from "@b3dotfun/sdk/shared/utils/number";
7
+ import { getERC20Balances, getNativeTokenBalance } from "@b3dotfun/sdk/shared/utils/thirdweb-insights";
8
+ import { useQuery } from "@tanstack/react-query";
9
+ import { useEffect } from "react";
10
+
11
+ interface UseTokenBalanceProps {
12
+ token: components["schemas"]["Token"];
13
+ address?: string;
14
+ }
15
+
16
+ export interface TokenBalanceResult {
17
+ rawBalance: bigint | null;
18
+ formattedBalance: string;
19
+ isLoading: boolean;
20
+ }
21
+
22
+ export function useTokenBalanceDirect({ token, address }: UseTokenBalanceProps): TokenBalanceResult {
23
+ const account = useAccountWallet();
24
+
25
+ const effectiveAddress = address || account?.address;
26
+
27
+ const {
28
+ data: tokenBalance,
29
+ isLoading,
30
+ isFetching,
31
+ refetch,
32
+ } = useQuery({
33
+ queryKey: ["tokenBalance", effectiveAddress, token.chainId, token.address],
34
+ queryFn: async (): Promise<{ formatted: string; raw: bigint | null }> => {
35
+ if (!effectiveAddress) return { formatted: "0", raw: null };
36
+
37
+ if (isNativeToken(token.address)) {
38
+ const nativeToken = await getNativeTokenBalance(effectiveAddress, token.chainId);
39
+ if (nativeToken && nativeToken.balance) {
40
+ const rawBalance = nativeToken.balance;
41
+ return {
42
+ formatted: formatTokenAmount(BigInt(rawBalance), Number(nativeToken.decimals || 18)),
43
+ raw: BigInt(rawBalance),
44
+ };
45
+ }
46
+ return { formatted: "0", raw: null };
47
+ }
48
+
49
+ const response = await getERC20Balances(effectiveAddress, {
50
+ chainIds: [token.chainId],
51
+ includeSpam: false,
52
+ });
53
+ const tokenBalance = response.data?.find(t => t.token_address === token.address);
54
+ if (tokenBalance?.balance) {
55
+ return {
56
+ formatted: formatTokenAmount(BigInt(tokenBalance.balance), Number(tokenBalance.decimals || 18)),
57
+ raw: BigInt(tokenBalance.balance),
58
+ };
59
+ }
60
+ return { formatted: "0", raw: null };
61
+ },
62
+ enabled: !!effectiveAddress,
63
+ staleTime: 30000,
64
+ gcTime: 5 * 60 * 1000,
65
+ retry: 2,
66
+ structuralSharing: false,
67
+ });
68
+
69
+ // Force a refetch when the wallet or token changes
70
+ useEffect(() => {
71
+ if (effectiveAddress) {
72
+ refetch();
73
+ }
74
+ }, [effectiveAddress, token.address, token.chainId, token.symbol, refetch]);
75
+
76
+ // Determine if we're actually loading
77
+ const isActuallyLoading = !effectiveAddress || isLoading || (isFetching && !tokenBalance);
78
+
79
+ return {
80
+ rawBalance: tokenBalance?.raw || BigInt(0),
81
+ formattedBalance: tokenBalance?.formatted || "0",
82
+ isLoading: isActuallyLoading,
83
+ };
84
+ }
@@ -1,9 +1,9 @@
1
1
  "use client";
2
2
 
3
+ import { components } from "@b3dotfun/sdk/anyspend/types/api";
3
4
  import { getCoingeckoChainInfo } from "@b3dotfun/sdk/shared/constants/chains/supported";
4
5
  import { useSearchParams } from "@b3dotfun/sdk/shared/react/hooks";
5
6
  import { useQuery } from "@tanstack/react-query";
6
- import { components } from "@b3dotfun/sdk/anyspend/types/api";
7
7
 
8
8
  interface UseTokenFromUrlOptions {
9
9
  /**
@@ -59,14 +59,15 @@ export function useTokenFromUrl({ defaultToken, prefix }: UseTokenFromUrlOptions
59
59
  const currencyParam = searchParams.get(`${prefix}Currency`);
60
60
  const chainIdParam = searchParams.get(`${prefix}ChainId`);
61
61
 
62
+ // Determine network based on chainId
63
+ const chainInfo = chainIdParam ? getCoingeckoChainInfo(Number(chainIdParam)) : null;
64
+ const network = chainInfo?.coingecko_id || "";
65
+
62
66
  // Determine if we should fetch token info
63
67
  const shouldFetchToken = Boolean(
64
- currencyParam && chainIdParam && currencyParam.toLowerCase() !== defaultToken.address.toLowerCase(),
68
+ currencyParam && chainIdParam && chainInfo && currencyParam.toLowerCase() !== defaultToken.address.toLowerCase(),
65
69
  );
66
70
 
67
- // Determine network based on chainId
68
- const network = chainIdParam ? getCoingeckoChainInfo(Number(chainIdParam)).coingecko_id : "";
69
-
70
71
  const { data: tokenInfo, isError } = useQuery({
71
72
  queryKey: ["tokenInfo", network, currencyParam],
72
73
  queryFn: () => fetchTokenInfo(network, currencyParam || ""),
@@ -223,6 +223,21 @@ export interface AnySpendStakeB3Props extends BaseModalProps {
223
223
  onSuccess?: () => void;
224
224
  }
225
225
 
226
+ /**
227
+ * Props for the AnySpend Stake B3 (Custom Exact In) modal
228
+ * Handles B3 token staking operations using the custom exact in flow
229
+ */
230
+ export interface AnySpendStakeB3ExactInProps extends BaseModalProps {
231
+ /** Modal type identifier */
232
+ type: "anySpendStakeB3ExactIn";
233
+ /** Recipient address to stake B3 for */
234
+ recipientAddress: string;
235
+ /** Stake amount */
236
+ stakeAmount?: string;
237
+ /** Callback function called when the stake is successful */
238
+ onSuccess?: () => void;
239
+ }
240
+
226
241
  /**
227
242
  * Props for the AnySpend Stake Contract modal
228
243
  * Handles token staking operations to a given contract
@@ -244,6 +259,23 @@ export interface AnySpendStakeUpsideProps extends BaseModalProps {
244
259
  onSuccess?: () => void;
245
260
  }
246
261
 
262
+ /**
263
+ * Props for the AnySpend Stake Upside (Exact In) modal
264
+ * Handles token staking operations using the custom exact in flow
265
+ */
266
+ export interface AnySpendStakeUpsideExactInProps extends BaseModalProps {
267
+ /** Modal type identifier */
268
+ type: "anySpendStakeUpsideExactIn";
269
+ /** Recipient address to stake tokens for */
270
+ recipientAddress: string;
271
+ /** Staking contract address */
272
+ stakingContractAddress: string;
273
+ /** Token to stake */
274
+ token: components["schemas"]["Token"];
275
+ /** Callback function called when the stake is successful */
276
+ onSuccess?: () => void;
277
+ }
278
+
247
279
  /**
248
280
  * Props for the AnySpend Buy Spin modal
249
281
  * Handles spin wheel entry purchases
@@ -355,7 +387,9 @@ export type ModalContentType =
355
387
  | AnySpendFundTournamentProps
356
388
  | AnySpendOrderHistoryProps
357
389
  | AnySpendStakeB3Props
390
+ | AnySpendStakeB3ExactInProps
358
391
  | AnySpendStakeUpsideProps
392
+ | AnySpendStakeUpsideExactInProps
359
393
  | AnySpendBuySpinProps
360
394
  | AnySpendSignatureMintProps
361
395
  | AnySpendBondKitProps