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