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