@b3dotfun/sdk 0.0.88 → 0.0.89-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 (281) hide show
  1. package/dist/cjs/anyspend/constants/index.d.ts +2 -0
  2. package/dist/cjs/anyspend/constants/index.js +3 -1
  3. package/dist/cjs/anyspend/index.d.ts +2 -0
  4. package/dist/cjs/anyspend/index.js +3 -0
  5. package/dist/cjs/anyspend/react/components/AnySpend.d.ts +6 -0
  6. package/dist/cjs/anyspend/react/components/AnySpend.js +9 -6
  7. package/dist/cjs/anyspend/react/components/AnySpendCollectorClubPurchase.d.ts +5 -1
  8. package/dist/cjs/anyspend/react/components/AnySpendCollectorClubPurchase.js +2 -2
  9. package/dist/cjs/anyspend/react/components/AnySpendCustom.d.ts +1 -0
  10. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +3 -3
  11. package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.d.ts +6 -0
  12. package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +24 -20
  13. package/dist/cjs/anyspend/react/components/AnySpendDeposit.d.ts +7 -1
  14. package/dist/cjs/anyspend/react/components/AnySpendDeposit.js +3 -3
  15. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.d.ts +4 -0
  16. package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +14 -1
  17. package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.d.ts +3 -1
  18. package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.js +3 -2
  19. package/dist/cjs/anyspend/react/components/common/GasIndicator.d.ts +6 -0
  20. package/dist/cjs/anyspend/react/components/common/GasIndicator.js +34 -0
  21. package/dist/cjs/anyspend/react/components/common/OrderDetails.d.ts +4 -0
  22. package/dist/cjs/anyspend/react/components/common/OrderDetails.js +34 -6
  23. package/dist/cjs/anyspend/react/components/common/PanelOnramp.d.ts +3 -1
  24. package/dist/cjs/anyspend/react/components/common/PanelOnramp.js +3 -2
  25. package/dist/cjs/anyspend/react/components/common/PaymentStripeWeb2.js +3 -4
  26. package/dist/cjs/anyspend/react/hooks/index.d.ts +1 -0
  27. package/dist/cjs/anyspend/react/hooks/index.js +1 -0
  28. package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +1 -1
  29. package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOrder.js +1 -1
  30. package/dist/cjs/anyspend/react/hooks/useCreateDepositFirstOrder.js +1 -1
  31. package/dist/cjs/anyspend/react/hooks/useGasPrice.d.ts +37 -0
  32. package/dist/cjs/anyspend/react/hooks/useGasPrice.js +43 -0
  33. package/dist/cjs/anyspend/react/hooks/useValidatedClientReferenceId.js +1 -1
  34. package/dist/cjs/anyspend/services/gas.d.ts +21 -0
  35. package/dist/cjs/anyspend/services/gas.js +65 -0
  36. package/dist/cjs/anyspend/types/gas.d.ts +61 -0
  37. package/dist/cjs/anyspend/types/gas.js +2 -0
  38. package/dist/cjs/global-account/react/components/B3DynamicModal.js +2 -3
  39. package/dist/cjs/global-account/react/components/B3Provider/AuthenticationProvider.d.ts +5 -0
  40. package/dist/cjs/global-account/react/components/B3Provider/AuthenticationProvider.js +12 -0
  41. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +2 -18
  42. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +35 -52
  43. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.d.ts +5 -5
  44. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +38 -35
  45. package/dist/cjs/global-account/react/components/B3Provider/RelayKitProviderWrapper.js +3 -1
  46. package/dist/cjs/global-account/react/components/B3Provider/useB3.d.ts +14 -4
  47. package/dist/cjs/global-account/react/components/B3Provider/useB3.js +4 -11
  48. package/dist/cjs/global-account/react/components/B3Provider/useB3Account.js +5 -2
  49. package/dist/cjs/global-account/react/components/B3Provider/useB3Config.d.ts +10 -2
  50. package/dist/cjs/global-account/react/components/B3Provider/useB3Config.js +18 -17
  51. package/dist/cjs/global-account/react/components/ManageAccount/ProfileSection.js +1 -2
  52. package/dist/cjs/global-account/react/components/ManageAccount/channels/DiscordChannel.js +6 -6
  53. package/dist/cjs/global-account/react/components/ManageAccount/channels/EmailChannel.js +7 -7
  54. package/dist/cjs/global-account/react/components/ManageAccount/channels/PhoneChannel.js +7 -7
  55. package/dist/cjs/global-account/react/components/ManageAccount/channels/TelegramChannel.js +5 -5
  56. package/dist/cjs/global-account/react/components/RequestPermissions/RequestPermissions.js +8 -9
  57. package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +1 -1
  58. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +76 -20
  59. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +1 -1
  60. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +1 -1
  61. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +1 -1
  62. package/dist/cjs/global-account/react/components/StyleRoot.js +3 -3
  63. package/dist/cjs/global-account/react/components/TurnkeyAuthModal.js +3 -1
  64. package/dist/cjs/global-account/react/components/custom/ManageAccountButton.js +1 -2
  65. package/dist/cjs/global-account/react/components/index.d.ts +1 -2
  66. package/dist/cjs/global-account/react/components/index.js +3 -6
  67. package/dist/cjs/global-account/react/hooks/index.d.ts +2 -0
  68. package/dist/cjs/global-account/react/hooks/index.js +5 -1
  69. package/dist/cjs/global-account/react/hooks/useAuth.d.ts +76 -0
  70. package/dist/cjs/global-account/react/hooks/useAuth.js +337 -0
  71. package/dist/cjs/global-account/react/hooks/useClient.js +1 -1
  72. package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.js +1 -1
  73. package/dist/cjs/global-account/react/hooks/useNotifications.js +14 -14
  74. package/dist/cjs/global-account/react/hooks/useTWAuth.d.ts +3 -0
  75. package/dist/cjs/global-account/react/hooks/useTWAuth.js +8 -0
  76. package/dist/cjs/global-account/react/hooks/useTokenBalance.js +5 -5
  77. package/dist/cjs/global-account/react/hooks/useTokenBalancesByChain.js +4 -2
  78. package/dist/cjs/global-account/react/hooks/useTurnkeyAuth.js +50 -22
  79. package/dist/cjs/global-account/react/hooks/useUser.d.ts +60 -0
  80. package/dist/cjs/global-account/react/hooks/useUser.js +20 -0
  81. package/dist/cjs/global-account/react/hooks/useUserQuery.js +9 -35
  82. package/dist/cjs/global-account/react/index.native.d.ts +0 -2
  83. package/dist/cjs/global-account/react/index.native.js +1 -5
  84. package/dist/cjs/global-account/react/stores/configStore.d.ts +24 -0
  85. package/dist/cjs/global-account/react/stores/configStore.js +30 -0
  86. package/dist/cjs/global-account/react/stores/index.d.ts +1 -0
  87. package/dist/cjs/global-account/react/stores/index.js +3 -1
  88. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +10 -0
  89. package/dist/cjs/global-account/react/stores/userStore.d.ts +22 -0
  90. package/dist/cjs/global-account/react/stores/userStore.js +30 -0
  91. package/dist/esm/anyspend/constants/index.d.ts +2 -0
  92. package/dist/esm/anyspend/constants/index.js +2 -0
  93. package/dist/esm/anyspend/index.d.ts +2 -0
  94. package/dist/esm/anyspend/index.js +3 -0
  95. package/dist/esm/anyspend/react/components/AnySpend.d.ts +6 -0
  96. package/dist/esm/anyspend/react/components/AnySpend.js +11 -8
  97. package/dist/esm/anyspend/react/components/AnySpendCollectorClubPurchase.d.ts +5 -1
  98. package/dist/esm/anyspend/react/components/AnySpendCollectorClubPurchase.js +2 -2
  99. package/dist/esm/anyspend/react/components/AnySpendCustom.d.ts +1 -0
  100. package/dist/esm/anyspend/react/components/AnySpendCustom.js +3 -3
  101. package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.d.ts +6 -0
  102. package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +8 -4
  103. package/dist/esm/anyspend/react/components/AnySpendDeposit.d.ts +7 -1
  104. package/dist/esm/anyspend/react/components/AnySpendDeposit.js +3 -3
  105. package/dist/esm/anyspend/react/components/AnyspendDepositHype.d.ts +4 -0
  106. package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +14 -1
  107. package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.d.ts +3 -1
  108. package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.js +3 -2
  109. package/dist/esm/anyspend/react/components/common/GasIndicator.d.ts +6 -0
  110. package/dist/esm/anyspend/react/components/common/GasIndicator.js +31 -0
  111. package/dist/esm/anyspend/react/components/common/OrderDetails.d.ts +4 -0
  112. package/dist/esm/anyspend/react/components/common/OrderDetails.js +36 -8
  113. package/dist/esm/anyspend/react/components/common/PanelOnramp.d.ts +3 -1
  114. package/dist/esm/anyspend/react/components/common/PanelOnramp.js +3 -2
  115. package/dist/esm/anyspend/react/components/common/PaymentStripeWeb2.js +3 -4
  116. package/dist/esm/anyspend/react/hooks/index.d.ts +1 -0
  117. package/dist/esm/anyspend/react/hooks/index.js +1 -0
  118. package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +2 -2
  119. package/dist/esm/anyspend/react/hooks/useAnyspendCreateOrder.js +2 -2
  120. package/dist/esm/anyspend/react/hooks/useCreateDepositFirstOrder.js +2 -2
  121. package/dist/esm/anyspend/react/hooks/useGasPrice.d.ts +37 -0
  122. package/dist/esm/anyspend/react/hooks/useGasPrice.js +40 -0
  123. package/dist/esm/anyspend/react/hooks/useValidatedClientReferenceId.js +2 -2
  124. package/dist/esm/anyspend/services/gas.d.ts +21 -0
  125. package/dist/esm/anyspend/services/gas.js +59 -0
  126. package/dist/esm/anyspend/types/gas.d.ts +61 -0
  127. package/dist/esm/anyspend/types/gas.js +1 -0
  128. package/dist/esm/global-account/react/components/B3DynamicModal.js +3 -4
  129. package/dist/esm/global-account/react/components/B3Provider/AuthenticationProvider.d.ts +5 -0
  130. package/dist/esm/global-account/react/components/B3Provider/AuthenticationProvider.js +10 -0
  131. package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +2 -18
  132. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +34 -53
  133. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.d.ts +5 -5
  134. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +36 -36
  135. package/dist/esm/global-account/react/components/B3Provider/RelayKitProviderWrapper.js +3 -1
  136. package/dist/esm/global-account/react/components/B3Provider/useB3.d.ts +14 -4
  137. package/dist/esm/global-account/react/components/B3Provider/useB3.js +4 -11
  138. package/dist/esm/global-account/react/components/B3Provider/useB3Account.js +5 -2
  139. package/dist/esm/global-account/react/components/B3Provider/useB3Config.d.ts +10 -2
  140. package/dist/esm/global-account/react/components/B3Provider/useB3Config.js +18 -17
  141. package/dist/esm/global-account/react/components/ManageAccount/ProfileSection.js +2 -3
  142. package/dist/esm/global-account/react/components/ManageAccount/channels/DiscordChannel.js +2 -2
  143. package/dist/esm/global-account/react/components/ManageAccount/channels/EmailChannel.js +2 -2
  144. package/dist/esm/global-account/react/components/ManageAccount/channels/PhoneChannel.js +2 -2
  145. package/dist/esm/global-account/react/components/ManageAccount/channels/TelegramChannel.js +2 -2
  146. package/dist/esm/global-account/react/components/RequestPermissions/RequestPermissions.js +2 -3
  147. package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +2 -2
  148. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +76 -20
  149. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +2 -2
  150. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +2 -2
  151. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -2
  152. package/dist/esm/global-account/react/components/StyleRoot.js +3 -3
  153. package/dist/esm/global-account/react/components/TurnkeyAuthModal.js +5 -3
  154. package/dist/esm/global-account/react/components/custom/ManageAccountButton.js +2 -3
  155. package/dist/esm/global-account/react/components/index.d.ts +1 -2
  156. package/dist/esm/global-account/react/components/index.js +1 -2
  157. package/dist/esm/global-account/react/hooks/index.d.ts +2 -0
  158. package/dist/esm/global-account/react/hooks/index.js +2 -0
  159. package/dist/esm/global-account/react/hooks/useAuth.d.ts +76 -0
  160. package/dist/esm/global-account/react/hooks/useAuth.js +331 -0
  161. package/dist/esm/global-account/react/hooks/useClient.js +2 -2
  162. package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.js +2 -2
  163. package/dist/esm/global-account/react/hooks/useNotifications.js +2 -2
  164. package/dist/esm/global-account/react/hooks/useTWAuth.d.ts +3 -0
  165. package/dist/esm/global-account/react/hooks/useTWAuth.js +8 -0
  166. package/dist/esm/global-account/react/hooks/useTokenBalance.js +6 -6
  167. package/dist/esm/global-account/react/hooks/useTokenBalancesByChain.js +4 -2
  168. package/dist/esm/global-account/react/hooks/useTurnkeyAuth.js +50 -22
  169. package/dist/esm/global-account/react/hooks/useUser.d.ts +60 -0
  170. package/dist/esm/global-account/react/hooks/useUser.js +17 -0
  171. package/dist/esm/global-account/react/hooks/useUserQuery.js +1 -27
  172. package/dist/esm/global-account/react/index.native.d.ts +0 -2
  173. package/dist/esm/global-account/react/index.native.js +0 -2
  174. package/dist/esm/global-account/react/stores/configStore.d.ts +24 -0
  175. package/dist/esm/global-account/react/stores/configStore.js +27 -0
  176. package/dist/esm/global-account/react/stores/index.d.ts +1 -0
  177. package/dist/esm/global-account/react/stores/index.js +1 -0
  178. package/dist/esm/global-account/react/stores/useModalStore.d.ts +10 -0
  179. package/dist/esm/global-account/react/stores/userStore.d.ts +22 -0
  180. package/dist/esm/global-account/react/stores/userStore.js +27 -0
  181. package/dist/styles/index.css +1 -1
  182. package/dist/types/anyspend/constants/index.d.ts +2 -0
  183. package/dist/types/anyspend/index.d.ts +2 -0
  184. package/dist/types/anyspend/react/components/AnySpend.d.ts +6 -0
  185. package/dist/types/anyspend/react/components/AnySpendCollectorClubPurchase.d.ts +5 -1
  186. package/dist/types/anyspend/react/components/AnySpendCustom.d.ts +1 -0
  187. package/dist/types/anyspend/react/components/AnySpendCustomExactIn.d.ts +6 -0
  188. package/dist/types/anyspend/react/components/AnySpendDeposit.d.ts +7 -1
  189. package/dist/types/anyspend/react/components/AnyspendDepositHype.d.ts +4 -0
  190. package/dist/types/anyspend/react/components/common/CryptoReceiveSection.d.ts +3 -1
  191. package/dist/types/anyspend/react/components/common/GasIndicator.d.ts +6 -0
  192. package/dist/types/anyspend/react/components/common/OrderDetails.d.ts +4 -0
  193. package/dist/types/anyspend/react/components/common/PanelOnramp.d.ts +3 -1
  194. package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
  195. package/dist/types/anyspend/react/hooks/useGasPrice.d.ts +37 -0
  196. package/dist/types/anyspend/services/gas.d.ts +21 -0
  197. package/dist/types/anyspend/types/gas.d.ts +61 -0
  198. package/dist/types/global-account/react/components/B3Provider/AuthenticationProvider.d.ts +5 -0
  199. package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +2 -18
  200. package/dist/types/global-account/react/components/B3Provider/B3Provider.native.d.ts +5 -5
  201. package/dist/types/global-account/react/components/B3Provider/useB3.d.ts +14 -4
  202. package/dist/types/global-account/react/components/B3Provider/useB3Config.d.ts +10 -2
  203. package/dist/types/global-account/react/components/index.d.ts +1 -2
  204. package/dist/types/global-account/react/hooks/index.d.ts +2 -0
  205. package/dist/types/global-account/react/hooks/useAuth.d.ts +76 -0
  206. package/dist/types/global-account/react/hooks/useTWAuth.d.ts +3 -0
  207. package/dist/types/global-account/react/hooks/useUser.d.ts +60 -0
  208. package/dist/types/global-account/react/index.native.d.ts +0 -2
  209. package/dist/types/global-account/react/stores/configStore.d.ts +24 -0
  210. package/dist/types/global-account/react/stores/index.d.ts +1 -0
  211. package/dist/types/global-account/react/stores/useModalStore.d.ts +10 -0
  212. package/dist/types/global-account/react/stores/userStore.d.ts +22 -0
  213. package/package.json +1 -1
  214. package/src/anyspend/constants/index.ts +3 -0
  215. package/src/anyspend/index.ts +4 -0
  216. package/src/anyspend/react/components/AnySpend.tsx +28 -2
  217. package/src/anyspend/react/components/AnySpendCollectorClubPurchase.tsx +6 -0
  218. package/src/anyspend/react/components/AnySpendCustom.tsx +52 -47
  219. package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +23 -0
  220. package/src/anyspend/react/components/AnySpendDeposit.tsx +27 -18
  221. package/src/anyspend/react/components/AnyspendDepositHype.tsx +4 -0
  222. package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +15 -1
  223. package/src/anyspend/react/components/common/CryptoReceiveSection.tsx +5 -1
  224. package/src/anyspend/react/components/common/GasIndicator.tsx +59 -0
  225. package/src/anyspend/react/components/common/OrderDetails.tsx +60 -42
  226. package/src/anyspend/react/components/common/PanelOnramp.tsx +5 -1
  227. package/src/anyspend/react/components/common/PaymentStripeWeb2.tsx +3 -4
  228. package/src/anyspend/react/hooks/index.ts +1 -0
  229. package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +2 -2
  230. package/src/anyspend/react/hooks/useAnyspendCreateOrder.ts +2 -2
  231. package/src/anyspend/react/hooks/useCreateDepositFirstOrder.ts +2 -2
  232. package/src/anyspend/react/hooks/useGasPrice.ts +70 -0
  233. package/src/anyspend/react/hooks/useValidatedClientReferenceId.ts +2 -2
  234. package/src/anyspend/services/gas.test.ts +31 -0
  235. package/src/anyspend/services/gas.ts +73 -0
  236. package/src/anyspend/types/gas.ts +66 -0
  237. package/src/global-account/react/components/B3DynamicModal.tsx +3 -4
  238. package/src/global-account/react/components/B3Provider/AuthenticationProvider.tsx +19 -0
  239. package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +43 -54
  240. package/src/global-account/react/components/B3Provider/B3Provider.tsx +44 -106
  241. package/src/global-account/react/components/B3Provider/RelayKitProviderWrapper.tsx +4 -1
  242. package/src/global-account/react/components/B3Provider/useB3.ts +4 -13
  243. package/src/global-account/react/components/B3Provider/useB3Account.ts +6 -2
  244. package/src/global-account/react/components/B3Provider/useB3Config.ts +18 -31
  245. package/src/global-account/react/components/ManageAccount/ProfileSection.tsx +2 -4
  246. package/src/global-account/react/components/ManageAccount/channels/DiscordChannel.tsx +2 -2
  247. package/src/global-account/react/components/ManageAccount/channels/EmailChannel.tsx +2 -2
  248. package/src/global-account/react/components/ManageAccount/channels/PhoneChannel.tsx +2 -2
  249. package/src/global-account/react/components/ManageAccount/channels/TelegramChannel.tsx +2 -2
  250. package/src/global-account/react/components/RequestPermissions/RequestPermissions.tsx +4 -4
  251. package/src/global-account/react/components/SignInWithB3/SignIn.tsx +2 -2
  252. package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +168 -100
  253. package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +2 -2
  254. package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +2 -2
  255. package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +2 -2
  256. package/src/global-account/react/components/StyleRoot.tsx +3 -3
  257. package/src/global-account/react/components/TurnkeyAuthModal.tsx +7 -4
  258. package/src/global-account/react/components/custom/ManageAccountButton.tsx +2 -3
  259. package/src/global-account/react/components/index.ts +1 -2
  260. package/src/global-account/react/hooks/index.ts +2 -0
  261. package/src/global-account/react/hooks/useAuth.ts +379 -0
  262. package/src/global-account/react/hooks/useClient.ts +2 -2
  263. package/src/global-account/react/hooks/useHandleConnectWithPrivy.tsx +2 -2
  264. package/src/global-account/react/hooks/useNotifications.ts +2 -2
  265. package/src/global-account/react/hooks/useTWAuth.tsx +10 -0
  266. package/src/global-account/react/hooks/useTokenBalance.tsx +8 -7
  267. package/src/global-account/react/hooks/useTokenBalancesByChain.tsx +4 -2
  268. package/src/global-account/react/hooks/useTurnkeyAuth.ts +54 -23
  269. package/src/global-account/react/hooks/useUser.ts +20 -0
  270. package/src/global-account/react/hooks/useUserQuery.ts +1 -40
  271. package/src/global-account/react/index.native.ts +0 -2
  272. package/src/global-account/react/stores/configStore.ts +51 -0
  273. package/src/global-account/react/stores/index.ts +1 -0
  274. package/src/global-account/react/stores/useModalStore.ts +10 -0
  275. package/src/global-account/react/stores/userStore.ts +41 -0
  276. package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +0 -27
  277. package/dist/cjs/global-account/react/components/B3Provider/types.js +0 -24
  278. package/dist/esm/global-account/react/components/B3Provider/types.d.ts +0 -27
  279. package/dist/esm/global-account/react/components/B3Provider/types.js +0 -21
  280. package/dist/types/global-account/react/components/B3Provider/types.d.ts +0 -27
  281. package/src/global-account/react/components/B3Provider/types.ts +0 -50
@@ -0,0 +1,379 @@
1
+ import app from "@b3dotfun/sdk/global-account/app";
2
+ import { authenticateWithB3JWT } from "@b3dotfun/sdk/global-account/bsmnt";
3
+ import { useAuthStore, useB3Config } from "@b3dotfun/sdk/global-account/react";
4
+ import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
5
+ import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
6
+ import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
7
+ import { ConnectionOptions } from "@thirdweb-dev/wagmi-adapter";
8
+ import { getConnectors } from "@wagmi/core";
9
+ import { useCallback, useContext, useEffect, useRef } from "react";
10
+ import {
11
+ useActiveWallet,
12
+ useAutoConnect,
13
+ useConnectedWallets,
14
+ useDisconnect,
15
+ useSetActiveWallet,
16
+ } from "thirdweb/react";
17
+ import { Wallet, ecosystemWallet } from "thirdweb/wallets";
18
+ import { preAuthenticate } from "thirdweb/wallets/in-app";
19
+ import { useAccount, useConnect, useSwitchAccount } from "wagmi";
20
+ import { LocalSDKContext } from "../components/B3Provider/LocalSDKProvider";
21
+ import { createWagmiConfig } from "../utils/createWagmiConfig";
22
+ import { useSearchParam } from "./useSearchParamsSSR";
23
+ import { useUserQuery } from "./useUserQuery";
24
+
25
+ const debug = debugB3React("useAuth");
26
+
27
+ /**
28
+ * Unified authentication hook that uses Turnkey for authentication
29
+ * This replaces the previous Thirdweb-based authentication
30
+ *
31
+ * This hook provides 1:1 feature parity with useAuthentication.ts
32
+ */
33
+ export function useAuth() {
34
+ const { onConnectCallback } = useContext(LocalSDKContext);
35
+ const { disconnect } = useDisconnect();
36
+ const wallets = useConnectedWallets();
37
+ const activeWallet = useActiveWallet();
38
+ const isAuthenticated = useAuthStore(state => state.isAuthenticated);
39
+ const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
40
+ const setIsConnected = useAuthStore(state => state.setIsConnected);
41
+ const isConnecting = useAuthStore(state => state.isConnecting);
42
+ const isConnected = useAuthStore(state => state.isConnected);
43
+ const isAuthenticating = useAuthStore(state => state.isAuthenticating);
44
+ const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
45
+ const setHasStartedConnecting = useAuthStore(state => state.setHasStartedConnecting);
46
+ const setActiveWallet = useSetActiveWallet();
47
+ const hasStartedConnecting = useAuthStore(state => state.hasStartedConnecting);
48
+ const useAutoConnectLoadingPrevious = useRef(false);
49
+ const referralCode = useSearchParam("referralCode");
50
+ const { partnerId } = useB3Config();
51
+ const wagmiConfig = createWagmiConfig({ partnerId });
52
+ const { connect } = useConnect();
53
+ const activeWagmiAccount = useAccount();
54
+ const { switchAccount } = useSwitchAccount();
55
+ const { user, setUser } = useUserQuery();
56
+ debug("@@activeWagmiAccount", activeWagmiAccount);
57
+
58
+ const wallet = ecosystemWallet(ecosystemWalletId, {
59
+ partnerId: partnerId,
60
+ });
61
+
62
+ /**
63
+ * Re-authenticate using existing session
64
+ * Also updates user state and authenticates with BSMNT
65
+ */
66
+ const reAuthenticate = useCallback(async () => {
67
+ debug("Re-authenticating...");
68
+ try {
69
+ const response = await app.reAuthenticate();
70
+ debug("Re-authentication successful", response);
71
+
72
+ // Update user state if user data exists
73
+ if (response.user) {
74
+ setUser(response.user);
75
+ debug("User state updated", response.user);
76
+ }
77
+
78
+ // Authenticate with BSMNT
79
+ try {
80
+ const b3Jwt = await authenticateWithB3JWT(response.accessToken);
81
+ debug("BSMNT re-authentication successful", b3Jwt);
82
+ } catch (bsmntError) {
83
+ // BSMNT authentication failure shouldn't block the main auth flow
84
+ debug("BSMNT re-authentication failed (non-critical)", bsmntError);
85
+ }
86
+
87
+ return response;
88
+ } catch (err: any) {
89
+ debug("Re-authentication failed", err);
90
+ throw err;
91
+ }
92
+ }, [setUser]);
93
+
94
+ const syncWagmi = useCallback(async () => {
95
+ function syncWagmiFunc() {
96
+ const connectors = getConnectors(wagmiConfig);
97
+ debug("@@syncWagmi", {
98
+ connectors,
99
+ wallets,
100
+ });
101
+
102
+ // For each that matchs a TW wallet on wallets, connect to the wagmi connector
103
+ // or, since ecosystem wallets is separate, connect those via in-app-wallet from wagmi
104
+ connectors.forEach(async connector => {
105
+ const twWallet = wallets.find(wallet => wallet.id === connector.id || connector.id === "in-app-wallet");
106
+
107
+ // If no TW wallet, do not prompt the user to connect
108
+ if (!twWallet) {
109
+ return;
110
+ }
111
+
112
+ // Metamask will prompt to connect, we can just switch accounts here.
113
+ if (connector.id === "io.metamask") {
114
+ return switchAccount({ connector });
115
+ }
116
+
117
+ if (
118
+ // If it's not an in-app wallet or it is the ecosystem wallet, connect
119
+ connector.id !== "in-app-wallet" ||
120
+ (connector.id === "in-app-wallet" && twWallet.id === ecosystemWalletId)
121
+ ) {
122
+ try {
123
+ const options = {
124
+ wallet: twWallet, // the connected wallet
125
+ } satisfies ConnectionOptions;
126
+ debug("@@syncWagmi:connecting", { twWallet, connector });
127
+ connect({
128
+ connector,
129
+ ...options,
130
+ });
131
+ } catch (error) {
132
+ console.error("@@syncWagmi:error", error);
133
+ }
134
+ } else {
135
+ debug("@@syncWagmi:not-connecting", connector);
136
+ }
137
+ });
138
+ }
139
+ syncWagmiFunc();
140
+ // wagmi config shouldn't change
141
+ // eslint-disable-next-line react-hooks/exhaustive-deps
142
+ }, [partnerId, wallets]);
143
+
144
+ useEffect(() => {
145
+ syncWagmi();
146
+ }, [wallets, syncWagmi]);
147
+
148
+ /**
149
+ * Authenticate user using Turnkey
150
+ * Note: This no longer requires a wallet for authentication.
151
+ * Wallets are still used for signing transactions, but authentication is done via Turnkey email OTP.
152
+ *
153
+ * For backward compatibility, this function still accepts a wallet parameter,
154
+ * but it's not used for authentication anymore.
155
+ */
156
+ const authenticateUser = useCallback(async () => {
157
+ setHasStartedConnecting(true);
158
+
159
+ // Try to re-authenticate first
160
+ try {
161
+ const userAuth = await reAuthenticate();
162
+ setUser(userAuth.user);
163
+ setIsAuthenticated(true);
164
+ setIsAuthenticating(false);
165
+ debug("Re-authenticated successfully", { userAuth });
166
+
167
+ // Authenticate on BSMNT with B3 JWT
168
+ const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
169
+ debug("@@b3Jwt", b3Jwt);
170
+
171
+ return userAuth;
172
+ } catch (error) {
173
+ // If re-authentication fails, user needs to authenticate via Turnkey
174
+ // This should be handled by the Turnkey auth modal/flow
175
+ debug("Re-authentication failed. User needs to authenticate via Turnkey.", error);
176
+ setIsAuthenticated(false);
177
+ setIsAuthenticating(false);
178
+ throw new Error("Authentication required. Please authenticate via Turnkey.");
179
+ }
180
+ }, [reAuthenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting]);
181
+
182
+ /**
183
+ * Authenticate with Turnkey using email OTP
184
+ * This is the primary authentication method, replacing Thirdweb wallet-based auth
185
+ *
186
+ * This function:
187
+ * 1. Authenticates with FeathersJS (persists session via cookies)
188
+ * 2. Sets user state in the user store (persists to localStorage)
189
+ * 3. Authenticates with BSMNT for basement integration
190
+ */
191
+ const authenticate = useCallback(
192
+ async (turnkeySessionJwt: string, partnerId: string) => {
193
+ if (!turnkeySessionJwt) {
194
+ throw new Error("Turnkey session JWT is required");
195
+ }
196
+
197
+ debug("Authenticating with Turnkey JWT", { referralCode, partnerId });
198
+
199
+ try {
200
+ // Step 1: Authenticate with FeathersJS (session persisted via cookies)
201
+ const response = await app.authenticate({
202
+ strategy: "turnkey-jwt",
203
+ accessToken: turnkeySessionJwt,
204
+ referralCode,
205
+ partnerId: partnerId,
206
+ } as any);
207
+
208
+ debug("Authentication successful", response);
209
+
210
+ // Step 2: Set user state (persists to localStorage via Zustand)
211
+ if (response.user) {
212
+ setUser(response.user);
213
+ debug("User state updated", response.user);
214
+ }
215
+
216
+ // Step 3: Authenticate with BSMNT for basement integration
217
+ try {
218
+ const b3Jwt = await authenticateWithB3JWT(response.accessToken);
219
+ debug("BSMNT authentication successful", b3Jwt);
220
+ } catch (bsmntError) {
221
+ // BSMNT authentication failure shouldn't block the main auth flow
222
+ debug("BSMNT authentication failed (non-critical)", bsmntError);
223
+ }
224
+
225
+ return response;
226
+ } catch (err: any) {
227
+ debug("Authentication failed", err);
228
+ throw err;
229
+ }
230
+ },
231
+ [referralCode, setUser],
232
+ );
233
+
234
+ /**
235
+ * Handle wallet connection
236
+ * Note: With Turnkey migration, wallet connection is primarily for signing transactions,
237
+ * not for authentication. Authentication should be done separately via Turnkey email OTP.
238
+ */
239
+ /**
240
+ * Handle wallet connection
241
+ * Note: With Turnkey migration, wallet connection is primarily for signing transactions,
242
+ * not for authentication. Authentication should be done separately via Turnkey email OTP.
243
+ */
244
+ const onConnect = useCallback(
245
+ async (_walleAutoConnectedWith: Wallet, allConnectedWallets: Wallet[]) => {
246
+ debug("@@useAuth:onConnect", { _walleAutoConnectedWith, allConnectedWallets });
247
+
248
+ const wallet = allConnectedWallets.find(wallet => wallet.id.startsWith("ecosystem."));
249
+
250
+ if (!wallet) {
251
+ throw new Error("No smart wallet found during auto-connect");
252
+ }
253
+
254
+ debug("@@useAuth:onConnect", { wallet });
255
+
256
+ try {
257
+ setHasStartedConnecting(true);
258
+ setIsConnected(true);
259
+ setIsAuthenticating(true);
260
+ await setActiveWallet(wallet);
261
+
262
+ // Try to authenticate user (will use re-authenticate if session exists)
263
+ // If no session exists, authentication will need to happen via Turnkey flow
264
+ try {
265
+ const userAuth = await authenticateUser();
266
+
267
+ if (userAuth && onConnectCallback) {
268
+ await onConnectCallback(wallet, userAuth.accessToken);
269
+ }
270
+ } catch (authError) {
271
+ // Authentication failed - this is expected if user hasn't authenticated via Turnkey yet
272
+ // The Turnkey auth modal should handle this
273
+ debug("@@useAuth:onConnect:authFailed", { authError });
274
+ // Don't set isAuthenticated to false here - let the Turnkey flow handle it
275
+ }
276
+ } catch (error) {
277
+ debug("@@useAuth:onConnect:failed", { error });
278
+ setIsAuthenticated(false);
279
+ setUser(undefined);
280
+ } finally {
281
+ setIsAuthenticating(false);
282
+ }
283
+
284
+ debug({
285
+ isAuthenticated,
286
+ isAuthenticating,
287
+ isConnected,
288
+ });
289
+ },
290
+ [
291
+ onConnectCallback,
292
+ authenticateUser,
293
+ isAuthenticated,
294
+ isAuthenticating,
295
+ isConnected,
296
+ setActiveWallet,
297
+ setHasStartedConnecting,
298
+ setIsAuthenticated,
299
+ setIsAuthenticating,
300
+ setIsConnected,
301
+ setUser,
302
+ ],
303
+ );
304
+
305
+ const logout = useCallback(
306
+ async (callback?: () => void) => {
307
+ if (activeWallet) {
308
+ debug("@@logout:activeWallet", activeWallet);
309
+ disconnect(activeWallet);
310
+ debug("@@logout:activeWallet", activeWallet);
311
+ }
312
+
313
+ // Log out of each wallet
314
+ wallets.forEach(wallet => {
315
+ console.log("@@logging out", wallet);
316
+ disconnect(wallet);
317
+ });
318
+
319
+ // Delete localStorage thirdweb:connected-wallet-ids
320
+ // https://npc-labs.slack.com/archives/C070E6HNG85/p1750185115273099
321
+ if (typeof localStorage !== "undefined") {
322
+ localStorage.removeItem("thirdweb:connected-wallet-ids");
323
+ localStorage.removeItem("wagmi.store");
324
+ localStorage.removeItem("lastAuthProvider");
325
+ localStorage.removeItem("b3-user");
326
+ }
327
+
328
+ app.logout();
329
+ debug("@@logout:loggedOut");
330
+
331
+ setIsAuthenticated(false);
332
+ setIsConnected(false);
333
+ setUser();
334
+ callback?.();
335
+ },
336
+ [activeWallet, disconnect, wallets, setIsAuthenticated, setUser, setIsConnected],
337
+ );
338
+
339
+ const { isLoading: useAutoConnectLoading } = useAutoConnect({
340
+ client,
341
+ wallets: [wallet],
342
+ onConnect,
343
+ onTimeout: () => {
344
+ logout().catch(error => {
345
+ debug("@@useAuth:logout on timeout failed", { error });
346
+ });
347
+ },
348
+ });
349
+
350
+ /**
351
+ * useAutoConnectLoading starts as false
352
+ */
353
+ useEffect(() => {
354
+ if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
355
+ setIsAuthenticating(false);
356
+ }
357
+ useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
358
+ }, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating]);
359
+
360
+ const isReady = isAuthenticated && !isAuthenticating;
361
+
362
+ return {
363
+ authenticate,
364
+ reAuthenticate,
365
+ logout,
366
+ isAuthenticated,
367
+ isReady,
368
+ isConnecting,
369
+ isConnected,
370
+ wallet,
371
+ preAuthenticate,
372
+ connect: onConnect,
373
+ isAuthenticating,
374
+ onConnect,
375
+ user,
376
+ refetchUser: authenticateUser,
377
+ setUser,
378
+ };
379
+ }
@@ -1,4 +1,4 @@
1
- import { useB3 } from "@b3dotfun/sdk/global-account/react";
1
+ import { useB3Config } from "@b3dotfun/sdk/global-account/react";
2
2
  import { useCallback } from "react";
3
3
  import {
4
4
  ClientType,
@@ -13,7 +13,7 @@ import {
13
13
  * Hook to access the current FeathersJS client and client management utilities
14
14
  */
15
15
  export function useClient() {
16
- const { clientType } = useB3();
16
+ const { clientType } = useB3Config();
17
17
 
18
18
  const getCurrentClient = useCallback(() => {
19
19
  return getClient();
@@ -1,4 +1,4 @@
1
- import { useB3, useConnect } from "@b3dotfun/sdk/global-account/react";
1
+ import { useB3Config, useConnect } from "@b3dotfun/sdk/global-account/react";
2
2
  import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
3
3
  import { useIdentityToken, usePrivy } from "@privy-io/react-auth";
4
4
  import { useCallback, useRef, useState } from "react";
@@ -11,7 +11,7 @@ const debug = debugB3React("@@b3:useHandleConnectWithPrivy");
11
11
  * Currently, this is for the basement-privy strategy
12
12
  */
13
13
  export function useHandleConnectWithPrivy(chain?: Chain, onSuccess?: (account: Account) => void) {
14
- const { partnerId } = useB3();
14
+ const { partnerId } = useB3Config();
15
15
  if (!chain) {
16
16
  throw new Error("Chain is required");
17
17
  }
@@ -1,7 +1,7 @@
1
+ import { useB3Config } from "@b3dotfun/sdk/global-account/react";
1
2
  import { getAuthToken } from "@b3dotfun/sdk/shared/utils/auth-token";
2
3
  import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
3
4
  import { useCallback, useEffect, useState } from "react";
4
- import { useB3 } from "../components";
5
5
  import { notificationsAPI, UserData } from "../utils/notificationsAPI";
6
6
  import { useUserQuery } from "./useUserQuery";
7
7
 
@@ -56,7 +56,7 @@ export interface UseNotificationsReturn {
56
56
  */
57
57
  export function useNotifications(): UseNotificationsReturn {
58
58
  const { user } = useUserQuery();
59
- const { partnerId } = useB3();
59
+ const { partnerId } = useB3Config();
60
60
  const [userData, setUserData] = useState<UserData | null>(null);
61
61
  const [loading, setLoading] = useState(true);
62
62
  const [error, setError] = useState<string | null>(null);
@@ -1,10 +1,20 @@
1
+ /**
2
+ * @deprecated This hook is deprecated. Use useAuth() with Turnkey authentication instead.
3
+ * This file is kept for backward compatibility but should not be used in new code.
4
+ */
1
5
  import app from "@b3dotfun/sdk/global-account/app";
2
6
  import debug from "@b3dotfun/sdk/shared/utils/debug";
3
7
  import { useCallback } from "react";
4
8
  import { Wallet } from "thirdweb/wallets";
5
9
  import { useSearchParam } from "./useSearchParamsSSR";
6
10
 
11
+ /**
12
+ * @deprecated Use useAuth() with Turnkey authentication instead
13
+ */
7
14
  export function useTWAuth() {
15
+ console.warn(
16
+ "useTWAuth is deprecated. Please migrate to useAuth() with Turnkey authentication. See useTurnkeyAuth.ts for the new implementation.",
17
+ );
8
18
  const referralCode = useSearchParam("referralCode");
9
19
 
10
20
  const authenticate = useCallback(
@@ -1,12 +1,12 @@
1
1
  "use client";
2
2
 
3
3
  import { isNativeToken } from "@b3dotfun/sdk/anyspend";
4
- import { useB3, useAccountWallet } from "@b3dotfun/sdk/global-account/react";
4
+ import { components } from "@b3dotfun/sdk/anyspend/types/api";
5
+ import { useAccountWallet, useAuthStore } from "@b3dotfun/sdk/global-account/react";
5
6
  import { formatTokenAmount } from "@b3dotfun/sdk/shared/utils/number";
6
7
  import { getERC20Balances, getNativeTokenBalance } from "@b3dotfun/sdk/shared/utils/thirdweb-insights";
7
8
  import { useQuery } from "@tanstack/react-query";
8
9
  import { useEffect } from "react";
9
- import { components } from "@b3dotfun/sdk/anyspend/types/api";
10
10
 
11
11
  interface UseTokenBalanceProps {
12
12
  token: components["schemas"]["Token"];
@@ -20,7 +20,8 @@ export interface TokenBalanceResult {
20
20
  }
21
21
 
22
22
  export function useTokenBalance({ token, address }: UseTokenBalanceProps): TokenBalanceResult {
23
- const { ready } = useB3();
23
+ const isAuthenticated = useAuthStore(state => state.isAuthenticated);
24
+
24
25
  const account = useAccountWallet();
25
26
 
26
27
  const effectiveAddress = address || account?.address;
@@ -60,7 +61,7 @@ export function useTokenBalance({ token, address }: UseTokenBalanceProps): Token
60
61
  }
61
62
  return { formatted: "0", raw: null };
62
63
  },
63
- enabled: ready && !!effectiveAddress,
64
+ enabled: isAuthenticated && !!effectiveAddress,
64
65
  staleTime: 30000,
65
66
  gcTime: 5 * 60 * 1000,
66
67
  retry: 2,
@@ -69,13 +70,13 @@ export function useTokenBalance({ token, address }: UseTokenBalanceProps): Token
69
70
 
70
71
  // Force a refetch when the wallet or token changes
71
72
  useEffect(() => {
72
- if (ready && effectiveAddress) {
73
+ if (isAuthenticated && effectiveAddress) {
73
74
  refetch();
74
75
  }
75
- }, [ready, effectiveAddress, token.address, token.chainId, token.symbol, refetch]);
76
+ }, [isAuthenticated, effectiveAddress, token.address, token.chainId, token.symbol, refetch]);
76
77
 
77
78
  // Determine if we're actually loading
78
- const isActuallyLoading = !ready || !effectiveAddress || isLoading || (isFetching && !tokenBalance);
79
+ const isActuallyLoading = !isAuthenticated || !effectiveAddress || isLoading || (isFetching && !tokenBalance);
79
80
 
80
81
  return {
81
82
  rawBalance: tokenBalance?.raw || BigInt(0),
@@ -6,8 +6,8 @@ import { useQuery } from "@tanstack/react-query";
6
6
  import { viemToThirdwebChain } from "@b3dotfun/sdk/shared/constants/chains/b3Chain";
7
7
  import { getChainById } from "@b3dotfun/sdk/shared/utils/chains";
8
8
  import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
9
- import { getWalletBalance } from "thirdweb/wallets";
10
9
  import invariant from "invariant";
10
+ import { getWalletBalance } from "thirdweb/wallets";
11
11
 
12
12
  type GetWalletBalanceResult = {
13
13
  value: bigint;
@@ -83,7 +83,9 @@ export function useTokenBalancesByChain({
83
83
  staleTime: 30000, // Consider data fresh for 30 seconds
84
84
  gcTime: 5 * 60 * 1000, // Keep in cache for 5 minutes
85
85
  retry: 2, // Limit retries on failure
86
- structuralSharing: false,
86
+ // Enable structural sharing to prevent infinite loops
87
+ // This ensures we only get new references when data actually changes
88
+ structuralSharing: true,
87
89
  });
88
90
 
89
91
  return {
@@ -4,7 +4,7 @@ import { useCallback, useState } from "react";
4
4
  import app from "../../app";
5
5
  import { useB3Config } from "../components";
6
6
  import { useAuthStore } from "../stores";
7
- import { useAuthentication } from "./useAuthentication";
7
+ import { useAuth } from "./useAuth";
8
8
 
9
9
  const debug = debugB3React("useTurnkeyAuth");
10
10
 
@@ -34,12 +34,15 @@ export function useTurnkeyAuth(): UseTurnkeyAuthReturn {
34
34
  const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
35
35
  const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
36
36
  const { partnerId } = useB3Config();
37
- const { user } = useAuthentication(partnerId);
37
+ const { authenticate } = useAuth();
38
38
 
39
39
  /**
40
40
  * Step 1: Initiate login with email
41
- * - Calls backend to create sub-org (if needed) and send OTP
41
+ * - Calls backend turnkey-jwt strategy (init action) to create sub-org (if needed) and send OTP
42
42
  * - Returns otpId to use in verification step
43
+ *
44
+ * Note: Uses the turnkey-jwt authentication strategy, not the service directly.
45
+ * The turnkey-jwt strategy handles both OTP flow (init/verify) and final authentication.
43
46
  */
44
47
  const initiateLogin = useCallback(
45
48
  async (email: string): Promise<TurnkeyAuthInitResponse> => {
@@ -48,20 +51,44 @@ export function useTurnkeyAuth(): UseTurnkeyAuthReturn {
48
51
  setIsAuthenticating(true);
49
52
 
50
53
  try {
51
- if (!user?.userId) {
52
- throw new Error("User ID is required to initiate Turnkey login.");
53
- }
54
54
  debug(`Initiating login for: ${email}`);
55
55
 
56
- // Call FeathersJS service to initialize OTP
57
- const data: TurnkeyAuthInitResponse = await app.service("turnkey-auth").init({ email, userId: user.userId });
56
+ // Use authentication service with turnkey-jwt strategy (init action)
57
+ // userId is resolved from authentication context on the backend (params.user.userId)
58
+ // Backend will get userId from _params.user?.userId if authenticated, or handle unauthenticated case
59
+ // So we only need to send email
60
+ debug(`Calling app.authenticate with turnkey-jwt strategy (init action)`, { email });
61
+
62
+ const response = await app.authenticate({
63
+ strategy: "turnkey-jwt",
64
+ action: "init",
65
+ email,
66
+ } as any);
67
+
68
+ // The strategy returns the TurnkeyAuthInitResponse directly
69
+ const data = response as unknown as TurnkeyAuthInitResponse;
58
70
 
59
71
  debug(`OTP initialized successfully. OtpId: ${data.otpId}`);
60
72
 
61
73
  return data;
62
74
  } catch (err: any) {
63
75
  debug("Error initiating login:", err);
64
- const errorMessage = err.message || "Failed to send OTP email. Please try again.";
76
+
77
+ // Provide more detailed error information
78
+ let errorMessage = "Failed to send OTP email. Please try again.";
79
+
80
+ if (err.message) {
81
+ errorMessage = err.message;
82
+ } else if (err.name === "TypeError" && err.message?.includes("fetch")) {
83
+ errorMessage = "Network error: Unable to reach the server. Please check your connection and try again.";
84
+ } else if (err.code === "ECONNREFUSED" || err.code === "ENOTFOUND") {
85
+ errorMessage = "Connection error: Unable to reach the server. Please check your internet connection.";
86
+ } else if (err.response) {
87
+ // FeathersJS error response
88
+ errorMessage = err.response.message || err.message || errorMessage;
89
+ debug("FeathersJS error response:", err.response);
90
+ }
91
+
65
92
  setError(errorMessage);
66
93
  throw err;
67
94
  } finally {
@@ -69,13 +96,13 @@ export function useTurnkeyAuth(): UseTurnkeyAuthReturn {
69
96
  setIsAuthenticating(false);
70
97
  }
71
98
  },
72
- [user, setIsAuthenticating],
99
+ [setIsAuthenticating],
73
100
  );
74
101
 
75
102
  /**
76
103
  * Step 2: Verify OTP and authenticate
77
- * - Verifies OTP with backend
78
- * - Gets Turnkey session JWT
104
+ * - Verifies OTP with backend via turnkey-jwt strategy (verify action)
105
+ * - Gets Turnkey session JWT from the verify response
79
106
  * - Authenticates with b3-api using "turnkey-jwt" strategy
80
107
  * - JWT automatically stored in cookies by SDK
81
108
  */
@@ -86,22 +113,26 @@ export function useTurnkeyAuth(): UseTurnkeyAuthReturn {
86
113
  setIsAuthenticating(true);
87
114
 
88
115
  try {
89
- debug(`Verifying OTP...`, { userId: user?.userId });
116
+ debug(`Verifying OTP...`, { otpId });
90
117
 
91
- // Step 1: Verify OTP and get Turnkey session JWT
92
- const { turnkeySessionJwt }: TurnkeyVerifyResponse = await app.service("turnkey-auth").verify({
118
+ // Step 1: Verify OTP with backend using turnkey-jwt strategy (verify action)
119
+ // This returns the Turnkey session JWT
120
+ const response = await app.authenticate({
121
+ strategy: "turnkey-jwt",
122
+ action: "verify",
93
123
  otpId,
94
124
  otpCode,
95
- });
125
+ } as any);
96
126
 
97
- debug(`OTP verified! Authenticating with b3-api...`);
127
+ // The strategy returns the TurnkeyAuthVerifyResponse directly
128
+ const verifyResult = response as unknown as TurnkeyVerifyResponse;
129
+ const { turnkeySessionJwt } = verifyResult;
130
+
131
+ debug(`OTP verified! Got Turnkey session JWT. Authenticating with b3-api...`);
98
132
 
99
133
  // Step 2: Authenticate with b3-api using Turnkey JWT
100
- // The SDK will automatically store the b3-api JWT in cookies
101
- const authResult = await app.authenticate({
102
- strategy: "turnkey-jwt",
103
- accessToken: turnkeySessionJwt,
104
- } as any);
134
+ // Use the unified useAuth hook for authentication with "turnkey-jwt" strategy
135
+ const authResult = await authenticate(turnkeySessionJwt, partnerId || "");
105
136
 
106
137
  debug(`Successfully authenticated with b3-api!`, authResult);
107
138
 
@@ -123,7 +154,7 @@ export function useTurnkeyAuth(): UseTurnkeyAuthReturn {
123
154
  setIsAuthenticating(false);
124
155
  }
125
156
  },
126
- [user, setIsAuthenticating, setIsAuthenticated],
157
+ [partnerId, setIsAuthenticating, setIsAuthenticated, authenticate],
127
158
  );
128
159
 
129
160
  const clearError = useCallback(() => {
@@ -0,0 +1,20 @@
1
+ import { useAuthStore } from "@b3dotfun/sdk/global-account/react";
2
+ import { useUserStore } from "../stores/userStore";
3
+
4
+ /**
5
+ * Preferred Hook to get the user data
6
+ */
7
+ export function useUser() {
8
+ const user = useUserStore(state => state.user);
9
+
10
+ const isConnecting = useAuthStore(state => state.isConnecting);
11
+ const isConnected = useAuthStore(state => state.isConnected);
12
+ const isAuthenticating = useAuthStore(state => state.isAuthenticating);
13
+
14
+ return {
15
+ user,
16
+ isConnecting,
17
+ isConnected,
18
+ isAuthenticating,
19
+ };
20
+ }