@b3dotfun/sdk 0.0.40 → 0.0.41-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 (227) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpend.d.ts +11 -1
  2. package/dist/cjs/anyspend/react/components/AnySpend.js +17 -4
  3. package/dist/cjs/anyspend/react/components/AnySpendBondKit.js +0 -1
  4. package/dist/cjs/anyspend/react/components/AnySpendBuySpin.js +0 -1
  5. package/dist/cjs/anyspend/react/components/AnySpendCustom.d.ts +1 -0
  6. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +33 -11
  7. package/dist/cjs/anyspend/react/components/AnySpendNFT.d.ts +2 -1
  8. package/dist/cjs/anyspend/react/components/AnySpendNFT.js +2 -2
  9. package/dist/cjs/anyspend/react/components/AnySpendStakeB3.js +0 -1
  10. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.d.ts +8 -0
  11. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +6 -3
  12. package/dist/cjs/anyspend/react/components/AnyspendSignatureMint.js +1 -2
  13. package/dist/cjs/anyspend/react/components/common/ConnectWalletPayment.js +5 -3
  14. package/dist/cjs/anyspend/react/components/common/CryptoPaySection.d.ts +4 -1
  15. package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +9 -9
  16. package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +80 -10
  17. package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.d.ts +2 -1
  18. package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.js +40 -37
  19. package/dist/cjs/anyspend/react/components/common/OrderDetails.js +8 -11
  20. package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.d.ts +4 -1
  21. package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +23 -9
  22. package/dist/cjs/anyspend/react/components/common/PanelOnramp.d.ts +4 -1
  23. package/dist/cjs/anyspend/react/components/common/PanelOnramp.js +10 -6
  24. package/dist/cjs/anyspend/react/components/common/PointsBadge.d.ts +7 -0
  25. package/dist/cjs/anyspend/react/components/common/PointsBadge.js +7 -0
  26. package/dist/cjs/anyspend/react/components/common/PointsDetailPanel.d.ts +6 -0
  27. package/dist/cjs/anyspend/react/components/common/PointsDetailPanel.js +14 -0
  28. package/dist/cjs/anyspend/react/contexts/FeatureFlagsContext.d.ts +11 -0
  29. package/dist/cjs/anyspend/react/contexts/FeatureFlagsContext.js +21 -0
  30. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +4 -1
  31. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +18 -8
  32. package/dist/cjs/anyspend/react/providers/AnyspendProvider.d.ts +5 -2
  33. package/dist/cjs/anyspend/react/providers/AnyspendProvider.js +5 -3
  34. package/dist/cjs/anyspend/react/providers/index.d.ts +1 -0
  35. package/dist/cjs/anyspend/react/providers/index.js +3 -0
  36. package/dist/cjs/anyspend/services/anyspend.d.ts +1 -1
  37. package/dist/cjs/anyspend/services/anyspend.js +2 -0
  38. package/dist/cjs/anyspend/types/api.d.ts +51 -1
  39. package/dist/cjs/anyspend/utils/chain.js +1 -1
  40. package/dist/cjs/anyspend/utils/orderPayload.js +3 -0
  41. package/dist/cjs/bondkit/bondkitToken.d.ts +37 -2
  42. package/dist/cjs/bondkit/bondkitToken.js +268 -2
  43. package/dist/cjs/bondkit/bondkitTokenFactory.d.ts +1 -1
  44. package/dist/cjs/bondkit/bondkitTokenFactory.js +2 -2
  45. package/dist/cjs/bondkit/components/TradingView.js +3 -4
  46. package/dist/cjs/bondkit/config.d.ts +1 -1
  47. package/dist/cjs/bondkit/config.js +5 -2
  48. package/dist/cjs/bondkit/constants.d.ts +4 -0
  49. package/dist/cjs/bondkit/constants.js +6 -1
  50. package/dist/cjs/bondkit/index.d.ts +1 -0
  51. package/dist/cjs/bondkit/index.js +4 -1
  52. package/dist/cjs/bondkit/swapService.d.ts +43 -0
  53. package/dist/cjs/bondkit/swapService.js +376 -0
  54. package/dist/cjs/bondkit/types.d.ts +10 -4
  55. package/dist/cjs/bondkit/types.js +4 -5
  56. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +4 -3
  57. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +41 -9
  58. package/dist/cjs/global-account/react/components/LinkAccount/LinkAccount.js +63 -3
  59. package/dist/cjs/global-account/react/components/ManageAccount/ManageAccount.js +35 -2
  60. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +4 -3
  61. package/dist/cjs/global-account/react/hooks/index.d.ts +1 -0
  62. package/dist/cjs/global-account/react/hooks/index.js +3 -1
  63. package/dist/cjs/global-account/react/hooks/useAccountAssets.js +5 -2
  64. package/dist/cjs/global-account/react/hooks/useAuthentication.js +2 -3
  65. package/dist/cjs/global-account/react/hooks/useGlobalAccount.d.ts +6 -0
  66. package/dist/cjs/global-account/react/hooks/useGlobalAccount.js +32 -0
  67. package/dist/cjs/global-account/react/hooks/useQueryB3.js +5 -2
  68. package/dist/cjs/global-account/react/hooks/useQueryBSMNT.js +5 -2
  69. package/dist/cjs/global-account/react/hooks/useSimBalance.js +2 -2
  70. package/dist/cjs/global-account/react/hooks/useTokenBalancesByChain.js +7 -1
  71. package/dist/cjs/global-account/react/hooks/useTokenFromUrl.js +2 -2
  72. package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +28 -24
  73. package/dist/cjs/shared/utils/fetchBalances.d.ts +1 -1
  74. package/dist/esm/anyspend/react/components/AnySpend.d.ts +11 -1
  75. package/dist/esm/anyspend/react/components/AnySpend.js +17 -4
  76. package/dist/esm/anyspend/react/components/AnySpendBondKit.js +0 -1
  77. package/dist/esm/anyspend/react/components/AnySpendBuySpin.js +0 -1
  78. package/dist/esm/anyspend/react/components/AnySpendCustom.d.ts +1 -0
  79. package/dist/esm/anyspend/react/components/AnySpendCustom.js +33 -11
  80. package/dist/esm/anyspend/react/components/AnySpendNFT.d.ts +2 -1
  81. package/dist/esm/anyspend/react/components/AnySpendNFT.js +2 -2
  82. package/dist/esm/anyspend/react/components/AnySpendStakeB3.js +0 -1
  83. package/dist/esm/anyspend/react/components/AnyspendDepositHype.d.ts +8 -0
  84. package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +6 -3
  85. package/dist/esm/anyspend/react/components/AnyspendSignatureMint.js +1 -2
  86. package/dist/esm/anyspend/react/components/common/ConnectWalletPayment.js +6 -4
  87. package/dist/esm/anyspend/react/components/common/CryptoPaySection.d.ts +4 -1
  88. package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +9 -9
  89. package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +80 -10
  90. package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.d.ts +2 -1
  91. package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.js +40 -37
  92. package/dist/esm/anyspend/react/components/common/OrderDetails.js +8 -11
  93. package/dist/esm/anyspend/react/components/common/OrderTokenAmount.d.ts +4 -1
  94. package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +23 -9
  95. package/dist/esm/anyspend/react/components/common/PanelOnramp.d.ts +4 -1
  96. package/dist/esm/anyspend/react/components/common/PanelOnramp.js +10 -6
  97. package/dist/esm/anyspend/react/components/common/PointsBadge.d.ts +7 -0
  98. package/dist/esm/anyspend/react/components/common/PointsBadge.js +4 -0
  99. package/dist/esm/anyspend/react/components/common/PointsDetailPanel.d.ts +6 -0
  100. package/dist/esm/anyspend/react/components/common/PointsDetailPanel.js +8 -0
  101. package/dist/esm/anyspend/react/contexts/FeatureFlagsContext.d.ts +11 -0
  102. package/dist/esm/anyspend/react/contexts/FeatureFlagsContext.js +17 -0
  103. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +4 -1
  104. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +18 -8
  105. package/dist/esm/anyspend/react/providers/AnyspendProvider.d.ts +5 -2
  106. package/dist/esm/anyspend/react/providers/AnyspendProvider.js +5 -3
  107. package/dist/esm/anyspend/react/providers/index.d.ts +1 -0
  108. package/dist/esm/anyspend/react/providers/index.js +1 -0
  109. package/dist/esm/anyspend/services/anyspend.d.ts +1 -1
  110. package/dist/esm/anyspend/services/anyspend.js +2 -0
  111. package/dist/esm/anyspend/types/api.d.ts +51 -1
  112. package/dist/esm/anyspend/utils/chain.js +1 -1
  113. package/dist/esm/anyspend/utils/orderPayload.js +3 -0
  114. package/dist/esm/bondkit/bondkitToken.d.ts +37 -2
  115. package/dist/esm/bondkit/bondkitToken.js +268 -2
  116. package/dist/esm/bondkit/bondkitTokenFactory.d.ts +1 -1
  117. package/dist/esm/bondkit/bondkitTokenFactory.js +2 -2
  118. package/dist/esm/bondkit/components/TradingView.js +3 -4
  119. package/dist/esm/bondkit/config.d.ts +1 -1
  120. package/dist/esm/bondkit/config.js +5 -2
  121. package/dist/esm/bondkit/constants.d.ts +4 -0
  122. package/dist/esm/bondkit/constants.js +5 -0
  123. package/dist/esm/bondkit/index.d.ts +1 -0
  124. package/dist/esm/bondkit/index.js +2 -0
  125. package/dist/esm/bondkit/swapService.d.ts +43 -0
  126. package/dist/esm/bondkit/swapService.js +372 -0
  127. package/dist/esm/bondkit/types.d.ts +10 -4
  128. package/dist/esm/bondkit/types.js +4 -5
  129. package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +4 -3
  130. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +42 -9
  131. package/dist/esm/global-account/react/components/LinkAccount/LinkAccount.js +65 -5
  132. package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +35 -2
  133. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +3 -2
  134. package/dist/esm/global-account/react/hooks/index.d.ts +1 -0
  135. package/dist/esm/global-account/react/hooks/index.js +1 -0
  136. package/dist/esm/global-account/react/hooks/useAccountAssets.js +2 -2
  137. package/dist/esm/global-account/react/hooks/useAuthentication.js +2 -3
  138. package/dist/esm/global-account/react/hooks/useGlobalAccount.d.ts +6 -0
  139. package/dist/esm/global-account/react/hooks/useGlobalAccount.js +29 -0
  140. package/dist/esm/global-account/react/hooks/useQueryB3.js +5 -2
  141. package/dist/esm/global-account/react/hooks/useQueryBSMNT.js +5 -2
  142. package/dist/esm/global-account/react/hooks/useSimBalance.js +2 -2
  143. package/dist/esm/global-account/react/hooks/useTokenBalancesByChain.js +4 -1
  144. package/dist/esm/global-account/react/hooks/useTokenFromUrl.js +2 -2
  145. package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +29 -25
  146. package/dist/esm/shared/utils/fetchBalances.d.ts +1 -1
  147. package/dist/styles/index.css +1 -1
  148. package/dist/types/anyspend/react/components/AnySpend.d.ts +11 -1
  149. package/dist/types/anyspend/react/components/AnySpendCustom.d.ts +1 -0
  150. package/dist/types/anyspend/react/components/AnySpendNFT.d.ts +2 -1
  151. package/dist/types/anyspend/react/components/AnyspendDepositHype.d.ts +8 -0
  152. package/dist/types/anyspend/react/components/common/CryptoPaySection.d.ts +4 -1
  153. package/dist/types/anyspend/react/components/common/CryptoReceiveSection.d.ts +2 -1
  154. package/dist/types/anyspend/react/components/common/OrderTokenAmount.d.ts +4 -1
  155. package/dist/types/anyspend/react/components/common/PanelOnramp.d.ts +4 -1
  156. package/dist/types/anyspend/react/components/common/PointsBadge.d.ts +7 -0
  157. package/dist/types/anyspend/react/components/common/PointsDetailPanel.d.ts +6 -0
  158. package/dist/types/anyspend/react/contexts/FeatureFlagsContext.d.ts +11 -0
  159. package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +4 -1
  160. package/dist/types/anyspend/react/providers/AnyspendProvider.d.ts +5 -2
  161. package/dist/types/anyspend/react/providers/index.d.ts +1 -0
  162. package/dist/types/anyspend/services/anyspend.d.ts +1 -1
  163. package/dist/types/anyspend/types/api.d.ts +51 -1
  164. package/dist/types/bondkit/bondkitToken.d.ts +37 -2
  165. package/dist/types/bondkit/bondkitTokenFactory.d.ts +1 -1
  166. package/dist/types/bondkit/config.d.ts +1 -1
  167. package/dist/types/bondkit/constants.d.ts +4 -0
  168. package/dist/types/bondkit/index.d.ts +1 -0
  169. package/dist/types/bondkit/swapService.d.ts +43 -0
  170. package/dist/types/bondkit/types.d.ts +10 -4
  171. package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +4 -3
  172. package/dist/types/global-account/react/hooks/index.d.ts +1 -0
  173. package/dist/types/global-account/react/hooks/useGlobalAccount.d.ts +6 -0
  174. package/dist/types/shared/utils/fetchBalances.d.ts +1 -1
  175. package/package.json +6 -5
  176. package/src/anyspend/react/components/AnySpend.tsx +37 -1
  177. package/src/anyspend/react/components/AnySpendBondKit.tsx +0 -1
  178. package/src/anyspend/react/components/AnySpendBuySpin.tsx +0 -1
  179. package/src/anyspend/react/components/AnySpendCustom.tsx +63 -13
  180. package/src/anyspend/react/components/AnySpendNFT.tsx +3 -0
  181. package/src/anyspend/react/components/AnySpendStakeB3.tsx +0 -1
  182. package/src/anyspend/react/components/AnyspendDepositHype.tsx +22 -0
  183. package/src/anyspend/react/components/AnyspendSignatureMint.tsx +1 -2
  184. package/src/anyspend/react/components/common/ConnectWalletPayment.tsx +7 -4
  185. package/src/anyspend/react/components/common/CryptoPaySection.tsx +13 -8
  186. package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +170 -44
  187. package/src/anyspend/react/components/common/CryptoReceiveSection.tsx +61 -45
  188. package/src/anyspend/react/components/common/OrderDetails.tsx +10 -14
  189. package/src/anyspend/react/components/common/OrderTokenAmount.tsx +28 -8
  190. package/src/anyspend/react/components/common/PanelOnramp.tsx +28 -15
  191. package/src/anyspend/react/components/common/PointsBadge.tsx +20 -0
  192. package/src/anyspend/react/components/common/PointsDetailPanel.tsx +55 -0
  193. package/src/anyspend/react/contexts/FeatureFlagsContext.tsx +34 -0
  194. package/src/anyspend/react/hooks/useAnyspendFlow.ts +18 -8
  195. package/src/anyspend/react/hooks/useAnyspendOrderAndTransactions.ts +1 -1
  196. package/src/anyspend/react/hooks/useCoinbaseOnrampOptions.ts +1 -1
  197. package/src/anyspend/react/providers/AnyspendProvider.tsx +11 -6
  198. package/src/anyspend/react/providers/index.ts +1 -0
  199. package/src/anyspend/services/anyspend.ts +3 -1
  200. package/src/anyspend/types/api.ts +51 -1
  201. package/src/anyspend/types/api_req_res.ts +6 -10
  202. package/src/anyspend/utils/chain.ts +1 -1
  203. package/src/anyspend/utils/orderPayload.ts +3 -0
  204. package/src/bondkit/bondkitToken.ts +323 -3
  205. package/src/bondkit/bondkitTokenFactory.ts +2 -2
  206. package/src/bondkit/components/TradingView.tsx +3 -5
  207. package/src/bondkit/config.ts +5 -2
  208. package/src/bondkit/constants.ts +7 -0
  209. package/src/bondkit/index.ts +3 -0
  210. package/src/bondkit/swapService.ts +464 -0
  211. package/src/bondkit/types.ts +12 -5
  212. package/src/global-account/react/components/B3Provider/B3Provider.tsx +55 -15
  213. package/src/global-account/react/components/LinkAccount/LinkAccount.tsx +106 -32
  214. package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +60 -5
  215. package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +4 -2
  216. package/src/global-account/react/hooks/index.ts +1 -0
  217. package/src/global-account/react/hooks/useAccountAssets.ts +4 -3
  218. package/src/global-account/react/hooks/useAuthentication.ts +2 -3
  219. package/src/global-account/react/hooks/useGlobalAccount.tsx +36 -0
  220. package/src/global-account/react/hooks/useOneBalance.tsx +1 -1
  221. package/src/global-account/react/hooks/useQueryB3.ts +22 -15
  222. package/src/global-account/react/hooks/useQueryBSMNT.ts +22 -15
  223. package/src/global-account/react/hooks/useSimBalance.ts +2 -2
  224. package/src/global-account/react/hooks/useTokenBalancesByChain.tsx +4 -1
  225. package/src/global-account/react/hooks/useTokenFromUrl.tsx +2 -2
  226. package/src/global-account/react/hooks/useUnifiedChainSwitchAndExecute.ts +30 -26
  227. package/src/shared/utils/fetchBalances.ts +1 -1
@@ -0,0 +1,372 @@
1
+ import { createPublicClient, encodeAbiParameters, formatUnits, getContract, http, parseAbiParameters, parseUnits, } from "viem";
2
+ import { base } from "viem/chains";
3
+ import { BaseMainnetRpcUrl, Permit2Address, QuoterAddress, UniversalRouterAddress } from "./constants.js";
4
+ // Minimal ABIs needed for swap functionality
5
+ const UNIVERSAL_ROUTER_ABI = [
6
+ {
7
+ inputs: [
8
+ { name: "commands", type: "bytes" },
9
+ { name: "inputs", type: "bytes[]" },
10
+ { name: "deadline", type: "uint256" },
11
+ ],
12
+ name: "execute",
13
+ outputs: [],
14
+ stateMutability: "payable",
15
+ type: "function",
16
+ },
17
+ ];
18
+ const QUOTER_ABI = [
19
+ {
20
+ inputs: [
21
+ {
22
+ components: [
23
+ {
24
+ components: [
25
+ { internalType: "Currency", name: "currency0", type: "address" },
26
+ { internalType: "Currency", name: "currency1", type: "address" },
27
+ { internalType: "uint24", name: "fee", type: "uint24" },
28
+ { internalType: "int24", name: "tickSpacing", type: "int24" },
29
+ { internalType: "contract IHooks", name: "hooks", type: "address" },
30
+ ],
31
+ internalType: "struct PoolKey",
32
+ name: "poolKey",
33
+ type: "tuple",
34
+ },
35
+ { internalType: "bool", name: "zeroForOne", type: "bool" },
36
+ { internalType: "uint128", name: "exactAmount", type: "uint128" },
37
+ { internalType: "bytes", name: "hookData", type: "bytes" },
38
+ ],
39
+ internalType: "struct IV4Quoter.QuoteExactSingleParams",
40
+ name: "params",
41
+ type: "tuple",
42
+ },
43
+ ],
44
+ name: "quoteExactInputSingle",
45
+ outputs: [
46
+ { internalType: "uint256", name: "amountOut", type: "uint256" },
47
+ { internalType: "uint256", name: "gasEstimate", type: "uint256" },
48
+ ],
49
+ stateMutability: "nonpayable",
50
+ type: "function",
51
+ },
52
+ ];
53
+ const ERC20_ABI = [
54
+ {
55
+ inputs: [
56
+ { name: "spender", type: "address" },
57
+ { name: "amount", type: "uint256" },
58
+ ],
59
+ name: "approve",
60
+ outputs: [{ name: "", type: "bool" }],
61
+ stateMutability: "nonpayable",
62
+ type: "function",
63
+ },
64
+ {
65
+ inputs: [
66
+ { name: "owner", type: "address" },
67
+ { name: "spender", type: "address" },
68
+ ],
69
+ name: "allowance",
70
+ outputs: [{ name: "", type: "uint256" }],
71
+ stateMutability: "view",
72
+ type: "function",
73
+ },
74
+ ];
75
+ const PERMIT2_ABI = [
76
+ {
77
+ inputs: [
78
+ { name: "token", type: "address" },
79
+ { name: "spender", type: "address" },
80
+ { name: "amount", type: "uint160" },
81
+ { name: "expiration", type: "uint48" },
82
+ ],
83
+ name: "approve",
84
+ outputs: [],
85
+ stateMutability: "nonpayable",
86
+ type: "function",
87
+ },
88
+ {
89
+ inputs: [
90
+ { name: "owner", type: "address" },
91
+ { name: "token", type: "address" },
92
+ { name: "spender", type: "address" },
93
+ ],
94
+ name: "allowance",
95
+ outputs: [
96
+ { name: "amount", type: "uint160" },
97
+ { name: "expiration", type: "uint48" },
98
+ { name: "nonce", type: "uint48" },
99
+ ],
100
+ stateMutability: "view",
101
+ type: "function",
102
+ },
103
+ ];
104
+ const TOKEN_V4_CONFIG_ABI = [
105
+ {
106
+ inputs: [],
107
+ name: "v4Hook",
108
+ outputs: [{ internalType: "address", name: "", type: "address" }],
109
+ stateMutability: "view",
110
+ type: "function",
111
+ },
112
+ {
113
+ inputs: [],
114
+ name: "v4PoolFee",
115
+ outputs: [{ internalType: "uint24", name: "", type: "uint24" }],
116
+ stateMutability: "view",
117
+ type: "function",
118
+ },
119
+ {
120
+ inputs: [],
121
+ name: "v4TickSpacing",
122
+ outputs: [{ internalType: "int24", name: "", type: "int24" }],
123
+ stateMutability: "view",
124
+ type: "function",
125
+ },
126
+ ];
127
+ // Command and action constants
128
+ const COMMANDS = {
129
+ V4_SWAP: "0x10",
130
+ };
131
+ const V4_ACTIONS = {
132
+ SWAP_EXACT_IN_SINGLE: 6,
133
+ TAKE_ALL: 15,
134
+ SETTLE_ALL: 12,
135
+ };
136
+ /**
137
+ * Internal swap service for handling Uniswap V4 swaps between trading token and bondkit token
138
+ */
139
+ export class BondkitSwapService {
140
+ constructor(bondkitTokenAddress) {
141
+ this.v4Config = null;
142
+ this.configInitialized = false;
143
+ this.bondkitTokenAddress = bondkitTokenAddress;
144
+ this.publicClient = createPublicClient({
145
+ chain: base,
146
+ transport: http(BaseMainnetRpcUrl),
147
+ });
148
+ }
149
+ /**
150
+ * Initialize V4 pool configuration from bondkit token contract
151
+ */
152
+ async initializeV4Config() {
153
+ if (this.configInitialized) {
154
+ return;
155
+ }
156
+ try {
157
+ const tokenContract = getContract({
158
+ address: this.bondkitTokenAddress,
159
+ abi: TOKEN_V4_CONFIG_ABI,
160
+ client: this.publicClient,
161
+ });
162
+ const [hook, fee, tickSpacing] = await Promise.all([
163
+ tokenContract.read.v4Hook(),
164
+ tokenContract.read.v4PoolFee(),
165
+ tokenContract.read.v4TickSpacing(),
166
+ ]);
167
+ this.v4Config = {
168
+ hook: hook,
169
+ fee: Number(fee),
170
+ tickSpacing: Number(tickSpacing),
171
+ };
172
+ this.configInitialized = true;
173
+ }
174
+ catch (error) {
175
+ console.warn("Failed to initialize V4 configuration:", error);
176
+ // Use fallback configuration
177
+ this.v4Config = {
178
+ hook: "0xB36f4A2FB18b745ef8eD31452781a463d2B3f0cC",
179
+ fee: 30000,
180
+ tickSpacing: 60,
181
+ };
182
+ this.configInitialized = true;
183
+ }
184
+ }
185
+ /**
186
+ * Get V4 pool configuration
187
+ */
188
+ async getV4Config() {
189
+ await this.initializeV4Config();
190
+ if (!this.v4Config) {
191
+ throw new Error("Failed to initialize V4 configuration");
192
+ }
193
+ return this.v4Config;
194
+ }
195
+ /**
196
+ * Handle token approvals for swap
197
+ */
198
+ async handleTokenApprovals(tokenAddress, amountIn, walletClient, deadline) {
199
+ // Skip approvals for ETH
200
+ if (tokenAddress === "0x0000000000000000000000000000000000000000") {
201
+ return;
202
+ }
203
+ const userAddress = walletClient.account?.address;
204
+ if (!userAddress) {
205
+ throw new Error("No user address found");
206
+ }
207
+ const erc20Contract = getContract({
208
+ address: tokenAddress,
209
+ abi: ERC20_ABI,
210
+ client: walletClient,
211
+ });
212
+ const permit2Contract = getContract({
213
+ address: Permit2Address,
214
+ abi: PERMIT2_ABI,
215
+ client: walletClient,
216
+ });
217
+ // Check ERC20 allowance to Permit2
218
+ const currentAllowance = (await erc20Contract.read.allowance([userAddress, Permit2Address]));
219
+ const requiredAmount = BigInt(amountIn);
220
+ if (currentAllowance < requiredAmount) {
221
+ await erc20Contract.write.approve([Permit2Address, BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")], {
222
+ account: userAddress,
223
+ chain: base,
224
+ });
225
+ }
226
+ // Check Permit2 allowance for Universal Router
227
+ const permit2Allowance = (await permit2Contract.read.allowance([
228
+ userAddress,
229
+ tokenAddress,
230
+ UniversalRouterAddress,
231
+ ]));
232
+ const [currentPermit2Amount, expiration] = permit2Allowance;
233
+ const currentTime = Math.floor(Date.now() / 1000);
234
+ const isExpired = expiration <= currentTime;
235
+ if (currentPermit2Amount < requiredAmount || isExpired) {
236
+ await permit2Contract.write.approve([tokenAddress, UniversalRouterAddress, BigInt("0xffffffffffffffffffffffffffffffffffffff"), Number(deadline)], {
237
+ account: userAddress,
238
+ chain: base,
239
+ });
240
+ }
241
+ }
242
+ /**
243
+ * Get swap quote
244
+ */
245
+ async getSwapQuote(params) {
246
+ try {
247
+ const { tokenIn, tokenOut, amountIn, tokenInDecimals, tokenOutDecimals, slippageTolerance } = params;
248
+ const v4Config = await this.getV4Config();
249
+ const amountInWei = parseUnits(amountIn, tokenInDecimals);
250
+ // Determine token order for pool
251
+ const currency0 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenIn : tokenOut;
252
+ const currency1 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenOut : tokenIn;
253
+ const zeroForOne = tokenIn.toLowerCase() === currency0.toLowerCase();
254
+ const poolKey = {
255
+ currency0: currency0,
256
+ currency1: currency1,
257
+ fee: v4Config.fee,
258
+ tickSpacing: v4Config.tickSpacing,
259
+ hooks: v4Config.hook,
260
+ };
261
+ const quoteParams = {
262
+ poolKey,
263
+ zeroForOne,
264
+ exactAmount: BigInt(amountInWei.toString()),
265
+ hookData: "0x",
266
+ };
267
+ const { result } = await this.publicClient.simulateContract({
268
+ address: QuoterAddress,
269
+ abi: QUOTER_ABI,
270
+ functionName: "quoteExactInputSingle",
271
+ args: [quoteParams],
272
+ });
273
+ const [amountOut] = result;
274
+ const amountOutRaw = formatUnits(amountOut, tokenOutDecimals);
275
+ const amountOutFormatted = parseFloat(amountOutRaw).toFixed(Math.min(6, tokenOutDecimals));
276
+ // Calculate minimum amount out with slippage
277
+ const slippageMultiplier = (100 - slippageTolerance) / 100;
278
+ const amountOutMinRaw = parseFloat(amountOutFormatted) * slippageMultiplier;
279
+ const amountOutMin = amountOutMinRaw.toFixed(tokenOutDecimals);
280
+ // Simple execution price calculation
281
+ const rate = parseFloat(amountOutFormatted) / parseFloat(amountIn);
282
+ const executionPrice = `1 = ${rate.toFixed(6)}`;
283
+ return {
284
+ amountOut: amountOutFormatted,
285
+ amountOutMin,
286
+ priceImpact: "0.0", // Simplified
287
+ executionPrice,
288
+ fee: (v4Config.fee / 10000).toString(),
289
+ };
290
+ }
291
+ catch (error) {
292
+ console.warn("Error getting swap quote:", error);
293
+ return null;
294
+ }
295
+ }
296
+ /**
297
+ * Execute swap transaction
298
+ */
299
+ async executeSwap(params, walletClient) {
300
+ try {
301
+ const { tokenIn, tokenOut, amountIn, tokenInDecimals, tokenOutDecimals, deadline } = params;
302
+ const swapDeadline = deadline || Math.floor(Date.now() / 1000) + 3600;
303
+ if (!walletClient.account) {
304
+ throw new Error("Wallet client must have an account");
305
+ }
306
+ const amountInWei = parseUnits(amountIn, tokenInDecimals);
307
+ // Handle token approvals
308
+ await this.handleTokenApprovals(tokenIn, amountInWei.toString(), walletClient, swapDeadline);
309
+ // Get quote for minimum amount out
310
+ const quote = await this.getSwapQuote(params);
311
+ if (!quote) {
312
+ throw new Error("Unable to get swap quote");
313
+ }
314
+ const amountOutMinimum = parseUnits(quote.amountOutMin, tokenOutDecimals);
315
+ const v4Config = await this.getV4Config();
316
+ // Determine token order
317
+ const currency0 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenIn : tokenOut;
318
+ const currency1 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenOut : tokenIn;
319
+ const zeroForOne = tokenIn.toLowerCase() === currency0.toLowerCase();
320
+ const poolKey = [currency0, currency1, v4Config.fee, v4Config.tickSpacing, v4Config.hook];
321
+ // Encode V4 actions
322
+ const actions = [
323
+ {
324
+ type: V4_ACTIONS.SWAP_EXACT_IN_SINGLE,
325
+ params: [poolKey, zeroForOne, amountInWei, amountOutMinimum, "0x"],
326
+ },
327
+ {
328
+ type: V4_ACTIONS.TAKE_ALL,
329
+ params: [(zeroForOne ? currency1 : currency0), BigInt(0)],
330
+ },
331
+ {
332
+ type: V4_ACTIONS.SETTLE_ALL,
333
+ params: [(zeroForOne ? currency0 : currency1), amountInWei],
334
+ },
335
+ ];
336
+ // Encode actions
337
+ const actionTypes = actions.map(action => action.type);
338
+ const actionsBytes = ("0x" + actionTypes.map(type => type.toString(16).padStart(2, "0")).join(""));
339
+ const actionParams = actions.map(action => {
340
+ switch (action.type) {
341
+ case V4_ACTIONS.SWAP_EXACT_IN_SINGLE:
342
+ return encodeAbiParameters(parseAbiParameters("((address,address,uint24,int24,address),bool,uint128,uint128,bytes)"), [action.params]);
343
+ case V4_ACTIONS.TAKE_ALL:
344
+ return encodeAbiParameters(parseAbiParameters("address,uint256"), action.params);
345
+ case V4_ACTIONS.SETTLE_ALL:
346
+ return encodeAbiParameters(parseAbiParameters("address,uint256"), action.params);
347
+ default:
348
+ return "0x00";
349
+ }
350
+ });
351
+ const v4SwapInput = encodeAbiParameters(parseAbiParameters("bytes,bytes[]"), [actionsBytes, actionParams]);
352
+ const commands = COMMANDS.V4_SWAP;
353
+ const inputs = [v4SwapInput];
354
+ // Execute swap
355
+ const universalRouter = getContract({
356
+ address: UniversalRouterAddress,
357
+ abi: UNIVERSAL_ROUTER_ABI,
358
+ client: walletClient,
359
+ });
360
+ const txHash = await universalRouter.write.execute([commands, inputs, BigInt(swapDeadline)], {
361
+ account: walletClient.account,
362
+ chain: base,
363
+ value: tokenIn === "0x0000000000000000000000000000000000000000" ? amountInWei : BigInt(0),
364
+ });
365
+ return txHash;
366
+ }
367
+ catch (error) {
368
+ console.warn("Error executing swap:", error);
369
+ return null;
370
+ }
371
+ }
372
+ }
@@ -49,10 +49,9 @@ export type DexMigrationEventArgs = {
49
49
  ethForFeeRecipient: bigint;
50
50
  };
51
51
  export declare enum TokenStatus {
52
- Inactive = 0,// Assuming mapping from ABI, verify actual enum values if specified elsewhere
53
- BondingPhase = 1,
54
- DexPhase = 2,
55
- Migrated = 3
52
+ Uninitialized = 0,
53
+ Bonding = 1,
54
+ Dex = 2
56
55
  }
57
56
  export interface GetTransactionHistoryOptions {
58
57
  userAddress?: Address;
@@ -80,3 +79,10 @@ export interface TransactionResponse {
80
79
  skip: number;
81
80
  data: Transaction[];
82
81
  }
82
+ export interface SwapQuote {
83
+ amountOut: string;
84
+ amountOutMin: string;
85
+ priceImpact: string;
86
+ executionPrice: string;
87
+ fee: string;
88
+ }
@@ -1,8 +1,7 @@
1
- // Enum for Status (used in BondkitToken ABI)
1
+ // Enum for Status (matches contract Status enum exactly)
2
2
  export var TokenStatus;
3
3
  (function (TokenStatus) {
4
- TokenStatus[TokenStatus["Inactive"] = 0] = "Inactive";
5
- TokenStatus[TokenStatus["BondingPhase"] = 1] = "BondingPhase";
6
- TokenStatus[TokenStatus["DexPhase"] = 2] = "DexPhase";
7
- TokenStatus[TokenStatus["Migrated"] = 3] = "Migrated";
4
+ TokenStatus[TokenStatus["Uninitialized"] = 0] = "Uninitialized";
5
+ TokenStatus[TokenStatus["Bonding"] = 1] = "Bonding";
6
+ TokenStatus[TokenStatus["Dex"] = 2] = "Dex";
8
7
  })(TokenStatus || (TokenStatus = {}));
@@ -1,13 +1,12 @@
1
1
  import { PermissionsConfig } from "../../../../global-account/types/permissions";
2
+ import "@reservoir0x/relay-kit-ui/styles.css";
2
3
  import { Account } from "thirdweb/wallets";
3
4
  import { ClientType } from "../../../client-manager";
4
5
  import { B3ContextType } from "./types";
5
- import "@reservoir0x/relay-kit-ui/styles.css";
6
- export declare const wagmiConfig: import("wagmi").Config<readonly [import("viem").Chain, ...import("viem").Chain[]], any, readonly import("wagmi").CreateConnectorFn[]>;
7
6
  /**
8
7
  * Main B3Provider component
9
8
  */
10
- export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType, }: {
9
+ export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType, rpcUrls, partnerId, }: {
11
10
  theme: "light" | "dark";
12
11
  children: React.ReactNode;
13
12
  accountOverride?: Account;
@@ -19,6 +18,8 @@ export declare function B3Provider({ theme, children, accountOverride, environme
19
18
  style?: React.CSSProperties;
20
19
  };
21
20
  clientType?: ClientType;
21
+ rpcUrls?: Record<number, string>;
22
+ partnerId?: string;
22
23
  }): import("react/jsx-runtime").JSX.Element;
23
24
  /**
24
25
  * Inner provider component that provides the actual B3Context
@@ -1,16 +1,21 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { RelayKitProviderWrapper, TooltipProvider, useAuthStore } from "../../../../global-account/react/index.js";
3
3
  import { loadGA4Script } from "../../../../global-account/utils/analytics.js";
4
+ import { ecosystemWalletId } from "../../../../shared/constants/index.js";
4
5
  import { supportedChains } from "../../../../shared/constants/chains/supported.js";
6
+ import { debugB3React } from "../../../../shared/utils/debug.js";
7
+ import { client } from "../../../../shared/utils/thirdweb.js";
8
+ import "@reservoir0x/relay-kit-ui/styles.css";
5
9
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
6
- import { useCallback, useEffect, useState } from "react";
10
+ import { inAppWalletConnector } from "@thirdweb-dev/wagmi-adapter";
11
+ import { useCallback, useEffect, useMemo, useState } from "react";
7
12
  import { Toaster } from "sonner";
8
13
  import { getLastAuthProvider, ThirdwebProvider, useActiveAccount, useConnectedWallets, useSetActiveWallet, } from "thirdweb/react";
9
14
  import { createConfig, http, WagmiProvider } from "wagmi";
10
15
  import { setClientType } from "../../../client-manager.js";
11
16
  import { StyleRoot } from "../StyleRoot.js";
12
17
  import { B3Context } from "./types.js";
13
- import "@reservoir0x/relay-kit-ui/styles.css";
18
+ const debug = debugB3React("B3Provider");
14
19
  /**
15
20
  * Default permissions configuration for B3 provider
16
21
  */
@@ -20,16 +25,12 @@ const DEFAULT_PERMISSIONS = {
20
25
  startDate: new Date(),
21
26
  endDate: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365), // 1 year from now
22
27
  };
23
- export const wagmiConfig = createConfig({
24
- chains: [supportedChains[0], ...supportedChains.slice(1)],
25
- transports: Object.fromEntries(supportedChains.map(chain => [chain.id, http()])),
26
- });
27
28
  // Create queryClient instance
28
29
  const queryClient = new QueryClient();
29
30
  /**
30
31
  * Main B3Provider component
31
32
  */
32
- export function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType = "rest", }) {
33
+ export function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType = "rest", rpcUrls, partnerId, }) {
33
34
  // Initialize Google Analytics on mount
34
35
  useEffect(() => {
35
36
  loadGA4Script();
@@ -38,7 +39,38 @@ export function B3Provider({ theme = "light", children, accountOverride, environ
38
39
  useEffect(() => {
39
40
  setClientType(clientType);
40
41
  }, [clientType]);
41
- return (_jsx(WagmiProvider, { config: wagmiConfig, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(ThirdwebProvider, { children: _jsx(TooltipProvider, { children: _jsx(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, automaticallySetFirstEoa: !!automaticallySetFirstEoa, clientType: clientType, children: _jsxs(RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, _jsx(StyleRoot, { id: "b3-root" }), _jsx(Toaster, { theme: theme, position: toaster?.position, style: toaster?.style })] }) }) }) }) }) }));
42
+ const ecocystemConfig = useMemo(() => {
43
+ if (!partnerId)
44
+ return undefined;
45
+ return {
46
+ ecosystemId: ecosystemWalletId,
47
+ partnerId: partnerId,
48
+ client,
49
+ };
50
+ }, [partnerId]);
51
+ // Stringify rpcUrls for stable comparison to prevent wagmiConfig recreation
52
+ // when parent component passes new object references with same content
53
+ const rpcUrlsString = useMemo(() => (rpcUrls ? JSON.stringify(rpcUrls) : undefined), [rpcUrls]);
54
+ /**
55
+ * Creates wagmi config with optional custom RPC URLs
56
+ * @param rpcUrls - Optional mapping of chain IDs to RPC URLs
57
+ */
58
+ const wagmiConfig = useMemo(() => {
59
+ const parsedRpcUrls = rpcUrlsString ? JSON.parse(rpcUrlsString) : undefined;
60
+ return createConfig({
61
+ chains: [supportedChains[0], ...supportedChains.slice(1)],
62
+ transports: Object.fromEntries(supportedChains.map(chain => [chain.id, http(parsedRpcUrls?.[chain.id])])),
63
+ connectors: [
64
+ inAppWalletConnector({
65
+ ...(ecocystemConfig || {}),
66
+ client,
67
+ }),
68
+ // injected(),
69
+ // coinbaseWallet({ appName: "HypeDuel" }),
70
+ ],
71
+ });
72
+ }, [ecocystemConfig, rpcUrlsString]);
73
+ return (_jsx(ThirdwebProvider, { children: _jsx(WagmiProvider, { config: wagmiConfig, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(TooltipProvider, { children: _jsx(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, automaticallySetFirstEoa: !!automaticallySetFirstEoa, clientType: clientType, children: _jsxs(RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, _jsx(StyleRoot, { id: "b3-root" }), _jsx(Toaster, { theme: theme, position: toaster?.position, style: toaster?.style })] }) }) }) }) }) }));
42
74
  }
43
75
  /**
44
76
  * Inner provider component that provides the actual B3Context
@@ -49,6 +81,7 @@ export function InnerProvider({ children, accountOverride, environment, defaultP
49
81
  const wallets = useConnectedWallets();
50
82
  const setActiveWallet = useSetActiveWallet();
51
83
  const isAuthenticated = useAuthStore(state => state.isAuthenticated);
84
+ debug("@@wallets", wallets);
52
85
  const [user, setUser] = useState(() => {
53
86
  // Try to restore user from localStorage on initialization
54
87
  if (typeof window !== "undefined") {
@@ -79,7 +112,7 @@ export function InnerProvider({ children, accountOverride, environment, defaultP
79
112
  const setWallet = useCallback((wallet) => {
80
113
  setManuallySelectedWallet(wallet);
81
114
  const account = wallet.getAccount();
82
- console.log("@@gio:setWallet", wallet.id, account?.address);
115
+ debug("@@setWallet", wallet.id, account?.address);
83
116
  setActiveWallet(wallet);
84
117
  }, [setManuallySelectedWallet, setActiveWallet]);
85
118
  useEffect(() => {
@@ -1,12 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import app from "../../../../global-account/app.js";
3
3
  import { ecosystemWalletId } from "../../../../shared/constants/index.js";
4
+ import { thirdwebB3Mainnet } from "../../../../shared/constants/chains/b3Chain.js";
4
5
  import { client } from "../../../../shared/utils/thirdweb.js";
5
- import { Loader2, Mail, Phone } from "lucide-react";
6
+ import { Loader2, Mail, Phone, WalletIcon } from "lucide-react";
6
7
  import { useCallback, useEffect, useState } from "react";
7
8
  import { toast } from "sonner";
8
9
  import { useLinkProfile, useProfiles } from "thirdweb/react";
9
- import { preAuthenticate } from "thirdweb/wallets";
10
+ import { createWallet, preAuthenticate } from "thirdweb/wallets";
11
+ import { WalletRow } from "../../index.js";
10
12
  import { useModalStore } from "../../stores/useModalStore.js";
11
13
  import { getProfileDisplayInfo } from "../../utils/profileDisplay.js";
12
14
  import { useB3 } from "../B3Provider/useB3.js";
@@ -30,6 +32,38 @@ const AUTH_METHODS = [
30
32
  icon: _jsx(FarcasterIcon, { className: "size-6" }),
31
33
  },
32
34
  ];
35
+ const WALLET_METHODS = [
36
+ {
37
+ id: "wallet",
38
+ label: "Wallet",
39
+ enabled: true,
40
+ icon: _jsx(WalletIcon, { className: "size-6" }),
41
+ walletType: "com.coinbase.wallet",
42
+ },
43
+ { id: "wallet", label: "Wallet", enabled: true, icon: _jsx(WalletIcon, { className: "size-6" }), walletType: "io.metamask" },
44
+ {
45
+ id: "wallet",
46
+ label: "Wallet",
47
+ enabled: true,
48
+ icon: _jsx(WalletIcon, { className: "size-6" }),
49
+ walletType: "me.rainbow",
50
+ },
51
+ {
52
+ id: "wallet",
53
+ label: "Wallet",
54
+ enabled: true,
55
+ icon: _jsx(WalletIcon, { className: "size-6" }),
56
+ walletType: "app.phantom",
57
+ },
58
+ { id: "wallet", label: "Wallet", enabled: true, icon: _jsx(WalletIcon, { className: "size-6" }), walletType: "io.rabby" },
59
+ {
60
+ id: "wallet",
61
+ label: "Wallet",
62
+ enabled: true,
63
+ icon: _jsx(WalletIcon, { className: "size-6" }),
64
+ walletType: "walletConnect",
65
+ },
66
+ ];
33
67
  export function LinkAccount({ onSuccess: onSuccessCallback, onError, onClose, chain, partnerId, className, }) {
34
68
  const { isLinking, linkingMethod, setLinkingState, navigateBack, setB3ModalContentType } = useModalStore();
35
69
  const [selectedMethod, setSelectedMethod] = useState(null);
@@ -41,12 +75,12 @@ export function LinkAccount({ onSuccess: onSuccessCallback, onError, onClose, ch
41
75
  const { data: profilesRaw = [] } = useProfiles({ client });
42
76
  // Get connected auth methods
43
77
  const connectedAuthMethods = profilesRaw
44
- .filter((profile) => !["custom_auth_endpoint", "siwe"].includes(profile.type))
78
+ .filter((profile) => !["custom_auth_endpoint"].includes(profile.type))
45
79
  .map((profile) => profile.type);
46
80
  // Filter available auth methods
47
81
  const availableAuthMethods = AUTH_METHODS.filter(method => !connectedAuthMethods.includes(method.id) && method.enabled);
48
82
  const profiles = profilesRaw
49
- .filter((profile) => !["custom_auth_endpoint", "siwe"].includes(profile.type))
83
+ .filter((profile) => !["custom_auth_endpoint"].includes(profile.type))
50
84
  .map((profile) => ({
51
85
  ...getProfileDisplayInfo(profile),
52
86
  originalProfile: profile,
@@ -176,6 +210,26 @@ export function LinkAccount({ onSuccess: onSuccessCallback, onError, onClose, ch
176
210
  onError?.(error);
177
211
  }
178
212
  };
213
+ const handleLinkWallet = async (walletType) => {
214
+ setLinkingState(true, "wallet");
215
+ console.log("selectedMethod", walletType);
216
+ try {
217
+ if (!walletType) {
218
+ throw new Error("Wallet type not found");
219
+ }
220
+ await linkProfile({
221
+ client,
222
+ strategy: "wallet",
223
+ wallet: createWallet(walletType),
224
+ chain: thirdwebB3Mainnet,
225
+ }, mutationOptions);
226
+ }
227
+ catch (error) {
228
+ console.error("Error linking account:", error);
229
+ setError(error instanceof Error ? error.message : "Failed to link account");
230
+ onError?.(error);
231
+ }
232
+ };
179
233
  const handleSocialLink = async (strategy) => {
180
234
  try {
181
235
  console.log("handleSocialLink", strategy);
@@ -256,5 +310,11 @@ export function LinkAccount({ onSuccess: onSuccessCallback, onError, onClose, ch
256
310
  else {
257
311
  handleSocialLink(method.id);
258
312
  }
259
- }, disabled: linkingMethod === method.id, children: isLinking && linkingMethod === method.id ? (_jsx(Loader2, { className: "h-5 w-5 animate-spin" })) : (_jsxs("div", { className: "b3-link-account-method-content flex items-center gap-4", children: [_jsx("div", { className: "b3-link-account-method-icon flex items-center justify-center rounded-full", children: method.icon }), _jsx("span", { className: "b3-link-account-method-label font-medium", children: method.label })] })) }, method.id))), availableAuthMethods.length === 0 && (_jsx("div", { className: "text-b3-foreground-muted py-8 text-center", children: "All available authentication methods have been connected" }))] })) : (_jsxs("div", { className: "b3-link-account-form space-y-4", children: [selectedMethod === "email" && (_jsxs("div", { className: "space-y-2", children: [_jsx("label", { className: "text-b3-grey font-neue-montreal-medium text-sm", children: "Email Address" }), _jsx("input", { type: "email", placeholder: "Enter your email", className: "bg-b3-line text-b3-grey font-neue-montreal-medium focus:ring-b3-primary-blue/20 w-full rounded-xl p-4 focus:outline-none focus:ring-2", value: email, onChange: e => setEmail(e.target.value), disabled: otpSent || (isLinking && linkingMethod === "email") })] })), selectedMethod === "phone" && (_jsxs("div", { className: "space-y-2", children: [_jsx("label", { className: "text-b3-grey font-neue-montreal-medium text-sm", children: "Phone Number" }), _jsx("input", { type: "tel", placeholder: "Enter your phone number", className: "bg-b3-line text-b3-grey font-neue-montreal-medium focus:ring-b3-primary-blue/20 w-full rounded-xl p-4 focus:outline-none focus:ring-2", value: phone, onChange: e => setPhone(e.target.value), disabled: otpSent || (isLinking && linkingMethod === "phone") }), _jsx("p", { className: "text-b3-foreground-muted font-neue-montreal-medium text-sm", children: "Include country code (e.g., +1 for US)" })] })), error && _jsx("div", { className: "text-b3-negative font-neue-montreal-medium py-2 text-sm", children: error }), otpSent ? (_jsxs("div", { className: "space-y-4", children: [_jsxs("div", { className: "space-y-2", children: [_jsx("label", { className: "text-b3-grey font-neue-montreal-medium text-sm", children: "Verification Code" }), _jsx("input", { type: "text", placeholder: "Enter verification code", className: "bg-b3-line text-b3-grey font-neue-montreal-medium focus:ring-b3-primary-blue/20 w-full rounded-xl p-4 focus:outline-none focus:ring-2", value: otp, onChange: e => setOtp(e.target.value) })] }), _jsx(Button, { className: "bg-b3-primary-blue hover:bg-b3-primary-blue/90 font-neue-montreal-semibold h-12 w-full text-white", onClick: handleLinkAccount, children: "Link Account" })] })) : (_jsx(Button, { className: "bg-b3-primary-blue hover:bg-b3-primary-blue/90 font-neue-montreal-semibold h-12 w-full text-white", onClick: handleSendOTP, disabled: (!email && !phone) || (isLinking && linkingMethod === selectedMethod), children: isLinking && linkingMethod === selectedMethod ? (_jsx(Loader2, { className: "animate-spin" })) : ("Send Verification Code") }))] }))] }));
313
+ }, disabled: linkingMethod === method.id, children: isLinking && linkingMethod === method.id ? (_jsx(Loader2, { className: "h-5 w-5 animate-spin" })) : (_jsxs("div", { className: "b3-link-account-method-content flex items-center gap-4", children: [_jsx("div", { className: "b3-link-account-method-icon flex items-center justify-center rounded-full", children: method.icon }), _jsx("span", { className: "b3-link-account-method-label font-medium", children: method.label })] })) }, method.id))), WALLET_METHODS.map(method => {
314
+ if (!method.walletType) {
315
+ return null;
316
+ }
317
+ return (_jsx(WalletRow, { walletId: method.walletType, onClick: () => handleLinkWallet(method.walletType), isLoading: isLinking }, method.walletType));
318
+ }), availableAuthMethods.length === 0 && (_jsx("div", { className: "text-b3-foreground-muted py-8 text-center", children: "All available authentication methods have been connected" }))] })) : (_jsxs("div", { className: "b3-link-account-form space-y-4", children: [selectedMethod === "email" && (_jsxs("div", { className: "space-y-2", children: [_jsx("label", { className: "text-b3-grey font-neue-montreal-medium text-sm", children: "Email Address" }), _jsx("input", { type: "email", placeholder: "Enter your email", className: "bg-b3-line text-b3-grey font-neue-montreal-medium focus:ring-b3-primary-blue/20 w-full rounded-xl p-4 focus:outline-none focus:ring-2", value: email, onChange: e => setEmail(e.target.value), disabled: otpSent || (isLinking && linkingMethod === "email") })] })), selectedMethod === "phone" && (_jsxs("div", { className: "space-y-2", children: [_jsx("label", { className: "text-b3-grey font-neue-montreal-medium text-sm", children: "Phone Number" }), _jsx("input", { type: "tel", placeholder: "Enter your phone number", className: "bg-b3-line text-b3-grey font-neue-montreal-medium focus:ring-b3-primary-blue/20 w-full rounded-xl p-4 focus:outline-none focus:ring-2", value: phone, onChange: e => setPhone(e.target.value), disabled: otpSent || (isLinking && linkingMethod === "phone") }), _jsx("p", { className: "text-b3-foreground-muted font-neue-montreal-medium text-sm", children: "Include country code (e.g., +1 for US)" })] })), error && _jsx("div", { className: "text-b3-negative font-neue-montreal-medium py-2 text-sm", children: error }), (selectedMethod === "email" || selectedMethod === "phone") &&
319
+ (otpSent ? (_jsxs("div", { className: "space-y-4", children: [_jsxs("div", { className: "space-y-2", children: [_jsx("label", { className: "text-b3-grey font-neue-montreal-medium text-sm", children: "Verification Code" }), _jsx("input", { type: "text", placeholder: "Enter verification code", className: "bg-b3-line text-b3-grey font-neue-montreal-medium focus:ring-b3-primary-blue/20 w-full rounded-xl p-4 focus:outline-none focus:ring-2", value: otp, onChange: e => setOtp(e.target.value) })] }), _jsx(Button, { className: "bg-b3-primary-blue hover:bg-b3-primary-blue/90 font-neue-montreal-semibold h-12 w-full text-white", onClick: handleLinkAccount, children: "Link Account" })] })) : (_jsx(Button, { className: "bg-b3-primary-blue hover:bg-b3-primary-blue/90 font-neue-montreal-semibold h-12 w-full text-white", onClick: handleSendOTP, disabled: (!email && !phone) || (isLinking && linkingMethod === selectedMethod), children: isLinking && linkingMethod === selectedMethod ? (_jsx(Loader2, { className: "animate-spin" })) : ("Send Verification Code") })))] }))] }));
260
320
  }