@b3dotfun/sdk 0.1.2 → 0.1.5
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/react/components/AnySpend.d.ts +7 -1
- package/dist/cjs/anyspend/react/components/AnySpend.js +66 -15
- package/dist/cjs/anyspend/react/components/AnySpendCollectorClubPurchase.d.ts +6 -2
- package/dist/cjs/anyspend/react/components/AnySpendCollectorClubPurchase.js +4 -4
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.d.ts +6 -0
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +185 -50
- package/dist/cjs/anyspend/react/components/AnySpendDeposit.d.ts +6 -1
- package/dist/cjs/anyspend/react/components/AnySpendDeposit.js +19 -4
- package/dist/cjs/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/AnySpendStakeUpsideExactIn.js +2 -2
- package/dist/cjs/anyspend/react/components/QRDeposit.d.ts +4 -1
- package/dist/cjs/anyspend/react/components/QRDeposit.js +12 -4
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.d.ts +3 -1
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +7 -5
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.d.ts +3 -1
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +4 -3
- package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.d.ts +3 -1
- package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.js +7 -6
- package/dist/cjs/anyspend/react/components/common/FeeDetailPanel.d.ts +3 -1
- package/dist/cjs/anyspend/react/components/common/FeeDetailPanel.js +15 -6
- package/dist/cjs/anyspend/react/components/common/FiatPaymentMethod.d.ts +3 -1
- package/dist/cjs/anyspend/react/components/common/FiatPaymentMethod.js +10 -6
- package/dist/cjs/anyspend/react/components/common/OrderDetails.d.ts +3 -0
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +11 -10
- package/dist/cjs/anyspend/react/components/common/OrderDetailsCollapsible.d.ts +2 -0
- package/dist/cjs/anyspend/react/components/common/OrderDetailsCollapsible.js +9 -9
- package/dist/cjs/anyspend/react/components/common/OrderHistory.js +2 -1
- package/dist/cjs/anyspend/react/components/common/PanelOnramp.d.ts +3 -1
- package/dist/cjs/anyspend/react/components/common/PanelOnramp.js +2 -2
- package/dist/cjs/anyspend/react/components/common/PanelOnrampPayment.d.ts +2 -0
- package/dist/cjs/anyspend/react/components/common/PanelOnrampPayment.js +20 -7
- package/dist/cjs/anyspend/react/components/common/PointsDetailPanel.d.ts +3 -1
- package/dist/cjs/anyspend/react/components/common/PointsDetailPanel.js +3 -2
- package/dist/cjs/anyspend/react/components/common/RecipientSelection.d.ts +6 -1
- package/dist/cjs/anyspend/react/components/common/RecipientSelection.js +5 -2
- package/dist/cjs/anyspend/react/components/common/TabSection.d.ts +3 -1
- package/dist/cjs/anyspend/react/components/common/TabSection.js +16 -7
- package/dist/cjs/anyspend/react/components/common/TransferCryptoDetails.d.ts +2 -0
- package/dist/cjs/anyspend/react/components/common/TransferCryptoDetails.js +3 -2
- package/dist/cjs/anyspend/react/components/common/WarningText.d.ts +8 -7
- package/dist/cjs/anyspend/react/components/common/WarningText.js +5 -6
- package/dist/cjs/anyspend/react/components/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/components/types/classes.d.ts +390 -0
- package/dist/cjs/anyspend/react/components/types/classes.js +6 -0
- 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/useAnyspendFlow.d.ts +22 -2
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +119 -15
- package/dist/cjs/anyspend/react/hooks/useDirectTransfer.d.ts +17 -0
- package/dist/cjs/anyspend/react/hooks/useDirectTransfer.js +46 -0
- package/dist/cjs/anyspend/react/hooks/useRecipientAddressState.js +1 -1
- package/dist/cjs/anyspend/utils/format.js +12 -2
- package/dist/cjs/global-account/react/components/B3DynamicModal.js +1 -5
- package/dist/cjs/global-account/react/components/B3Provider/B3ConfigProvider.d.ts +1 -3
- package/dist/cjs/global-account/react/components/B3Provider/B3ConfigProvider.js +1 -2
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +1 -4
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +2 -2
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.d.ts +1 -1
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +1 -1
- package/dist/cjs/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +1 -4
- package/dist/cjs/global-account/react/components/B3Provider/LocalSDKProvider.js +1 -3
- package/dist/cjs/global-account/react/components/B3Provider/RelayKitProviderWrapper.js +1 -3
- package/dist/cjs/global-account/react/components/ManageAccount/SettingsContent.js +17 -3
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +19 -152
- package/dist/cjs/global-account/react/components/index.d.ts +0 -1
- package/dist/cjs/global-account/react/components/index.js +3 -6
- package/dist/cjs/global-account/react/hooks/index.d.ts +0 -1
- package/dist/cjs/global-account/react/hooks/index.js +2 -4
- package/dist/cjs/global-account/react/hooks/useAuth.d.ts +2 -3
- package/dist/cjs/global-account/react/hooks/useAuth.js +14 -31
- package/dist/cjs/global-account/react/hooks/useTWAuth.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/useTWAuth.js +3 -3
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +8 -19
- package/dist/esm/anyspend/react/components/AnySpend.d.ts +7 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +68 -17
- package/dist/esm/anyspend/react/components/AnySpendCollectorClubPurchase.d.ts +6 -2
- package/dist/esm/anyspend/react/components/AnySpendCollectorClubPurchase.js +4 -4
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.d.ts +6 -0
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +189 -54
- package/dist/esm/anyspend/react/components/AnySpendDeposit.d.ts +6 -1
- package/dist/esm/anyspend/react/components/AnySpendDeposit.js +19 -4
- package/dist/esm/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +2 -1
- package/dist/esm/anyspend/react/components/AnySpendStakeUpsideExactIn.js +2 -2
- package/dist/esm/anyspend/react/components/QRDeposit.d.ts +4 -1
- package/dist/esm/anyspend/react/components/QRDeposit.js +12 -4
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.d.ts +3 -1
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +7 -5
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.d.ts +3 -1
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +4 -3
- package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.d.ts +3 -1
- package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.js +7 -6
- package/dist/esm/anyspend/react/components/common/FeeDetailPanel.d.ts +3 -1
- package/dist/esm/anyspend/react/components/common/FeeDetailPanel.js +15 -6
- package/dist/esm/anyspend/react/components/common/FiatPaymentMethod.d.ts +3 -1
- package/dist/esm/anyspend/react/components/common/FiatPaymentMethod.js +10 -6
- package/dist/esm/anyspend/react/components/common/OrderDetails.d.ts +3 -0
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +11 -10
- package/dist/esm/anyspend/react/components/common/OrderDetailsCollapsible.d.ts +2 -0
- package/dist/esm/anyspend/react/components/common/OrderDetailsCollapsible.js +9 -9
- package/dist/esm/anyspend/react/components/common/OrderHistory.js +2 -1
- package/dist/esm/anyspend/react/components/common/PanelOnramp.d.ts +3 -1
- package/dist/esm/anyspend/react/components/common/PanelOnramp.js +2 -2
- package/dist/esm/anyspend/react/components/common/PanelOnrampPayment.d.ts +2 -0
- package/dist/esm/anyspend/react/components/common/PanelOnrampPayment.js +20 -7
- package/dist/esm/anyspend/react/components/common/PointsDetailPanel.d.ts +3 -1
- package/dist/esm/anyspend/react/components/common/PointsDetailPanel.js +3 -2
- package/dist/esm/anyspend/react/components/common/RecipientSelection.d.ts +6 -1
- package/dist/esm/anyspend/react/components/common/RecipientSelection.js +5 -2
- package/dist/esm/anyspend/react/components/common/TabSection.d.ts +3 -1
- package/dist/esm/anyspend/react/components/common/TabSection.js +16 -7
- package/dist/esm/anyspend/react/components/common/TransferCryptoDetails.d.ts +2 -0
- package/dist/esm/anyspend/react/components/common/TransferCryptoDetails.js +3 -2
- package/dist/esm/anyspend/react/components/common/WarningText.d.ts +8 -7
- package/dist/esm/anyspend/react/components/common/WarningText.js +5 -6
- package/dist/esm/anyspend/react/components/index.d.ts +1 -0
- package/dist/esm/anyspend/react/components/types/classes.d.ts +390 -0
- package/dist/esm/anyspend/react/components/types/classes.js +5 -0
- 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/useAnyspendFlow.d.ts +22 -2
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +119 -16
- package/dist/esm/anyspend/react/hooks/useDirectTransfer.d.ts +17 -0
- package/dist/esm/anyspend/react/hooks/useDirectTransfer.js +43 -0
- package/dist/esm/anyspend/react/hooks/useRecipientAddressState.js +1 -1
- package/dist/esm/anyspend/utils/format.js +12 -2
- package/dist/esm/global-account/react/components/B3DynamicModal.js +1 -5
- package/dist/esm/global-account/react/components/B3Provider/B3ConfigProvider.d.ts +1 -3
- package/dist/esm/global-account/react/components/B3Provider/B3ConfigProvider.js +1 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +1 -4
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +2 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.d.ts +1 -1
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +1 -1
- package/dist/esm/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +1 -4
- package/dist/esm/global-account/react/components/B3Provider/LocalSDKProvider.js +1 -3
- package/dist/esm/global-account/react/components/B3Provider/RelayKitProviderWrapper.js +1 -3
- package/dist/esm/global-account/react/components/ManageAccount/SettingsContent.js +16 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +20 -153
- package/dist/esm/global-account/react/components/index.d.ts +0 -1
- package/dist/esm/global-account/react/components/index.js +0 -2
- package/dist/esm/global-account/react/hooks/index.d.ts +0 -1
- package/dist/esm/global-account/react/hooks/index.js +0 -1
- package/dist/esm/global-account/react/hooks/useAuth.d.ts +2 -3
- package/dist/esm/global-account/react/hooks/useAuth.js +14 -31
- package/dist/esm/global-account/react/hooks/useTWAuth.d.ts +1 -1
- package/dist/esm/global-account/react/hooks/useTWAuth.js +3 -3
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +8 -19
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/components/AnySpend.d.ts +7 -1
- package/dist/types/anyspend/react/components/AnySpendCollectorClubPurchase.d.ts +6 -2
- package/dist/types/anyspend/react/components/AnySpendCustomExactIn.d.ts +6 -0
- package/dist/types/anyspend/react/components/AnySpendDeposit.d.ts +6 -1
- package/dist/types/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +2 -1
- package/dist/types/anyspend/react/components/QRDeposit.d.ts +4 -1
- package/dist/types/anyspend/react/components/common/CryptoPaySection.d.ts +3 -1
- package/dist/types/anyspend/react/components/common/CryptoPaymentMethod.d.ts +3 -1
- package/dist/types/anyspend/react/components/common/CryptoReceiveSection.d.ts +3 -1
- package/dist/types/anyspend/react/components/common/FeeDetailPanel.d.ts +3 -1
- package/dist/types/anyspend/react/components/common/FiatPaymentMethod.d.ts +3 -1
- package/dist/types/anyspend/react/components/common/OrderDetails.d.ts +3 -0
- package/dist/types/anyspend/react/components/common/OrderDetailsCollapsible.d.ts +2 -0
- package/dist/types/anyspend/react/components/common/PanelOnramp.d.ts +3 -1
- package/dist/types/anyspend/react/components/common/PanelOnrampPayment.d.ts +2 -0
- package/dist/types/anyspend/react/components/common/PointsDetailPanel.d.ts +3 -1
- package/dist/types/anyspend/react/components/common/RecipientSelection.d.ts +6 -1
- package/dist/types/anyspend/react/components/common/TabSection.d.ts +3 -1
- package/dist/types/anyspend/react/components/common/TransferCryptoDetails.d.ts +2 -0
- package/dist/types/anyspend/react/components/common/WarningText.d.ts +8 -7
- package/dist/types/anyspend/react/components/index.d.ts +1 -0
- package/dist/types/anyspend/react/components/types/classes.d.ts +390 -0
- package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +22 -2
- package/dist/types/anyspend/react/hooks/useDirectTransfer.d.ts +17 -0
- package/dist/types/global-account/react/components/B3Provider/B3ConfigProvider.d.ts +1 -3
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +1 -4
- package/dist/types/global-account/react/components/B3Provider/B3Provider.native.d.ts +1 -1
- package/dist/types/global-account/react/components/B3Provider/LocalSDKProvider.d.ts +1 -4
- package/dist/types/global-account/react/components/index.d.ts +0 -1
- package/dist/types/global-account/react/hooks/index.d.ts +0 -1
- package/dist/types/global-account/react/hooks/useAuth.d.ts +2 -3
- package/dist/types/global-account/react/hooks/useTWAuth.d.ts +1 -1
- package/dist/types/global-account/react/stores/useModalStore.d.ts +8 -19
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +164 -36
- package/src/anyspend/react/components/AnySpendCollectorClubPurchase.tsx +11 -6
- package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +278 -69
- package/src/anyspend/react/components/AnySpendDeposit.tsx +176 -52
- package/src/anyspend/react/components/AnySpendStakeUpsideExactIn.tsx +3 -0
- package/src/anyspend/react/components/QRDeposit.tsx +91 -35
- package/src/anyspend/react/components/common/CryptoPaySection.tsx +31 -19
- package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +14 -4
- package/src/anyspend/react/components/common/CryptoReceiveSection.tsx +43 -23
- package/src/anyspend/react/components/common/FeeDetailPanel.tsx +53 -32
- package/src/anyspend/react/components/common/FiatPaymentMethod.tsx +26 -13
- package/src/anyspend/react/components/common/OrderDetails.tsx +20 -9
- package/src/anyspend/react/components/common/OrderDetailsCollapsible.tsx +12 -7
- package/src/anyspend/react/components/common/OrderHistory.tsx +2 -1
- package/src/anyspend/react/components/common/PanelOnramp.tsx +4 -1
- package/src/anyspend/react/components/common/PanelOnrampPayment.tsx +118 -40
- package/src/anyspend/react/components/common/PointsDetailPanel.tsx +28 -14
- package/src/anyspend/react/components/common/RecipientSelection.tsx +20 -5
- package/src/anyspend/react/components/common/TabSection.tsx +21 -12
- package/src/anyspend/react/components/common/TransferCryptoDetails.tsx +12 -4
- package/src/anyspend/react/components/common/WarningText.tsx +10 -10
- package/src/anyspend/react/components/index.ts +16 -0
- package/src/anyspend/react/components/types/classes.ts +476 -0
- package/src/anyspend/react/hooks/index.ts +1 -0
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +141 -17
- package/src/anyspend/react/hooks/useDirectTransfer.ts +67 -0
- package/src/anyspend/react/hooks/useRecipientAddressState.ts +1 -1
- package/src/anyspend/utils/format.ts +13 -2
- package/src/global-account/react/components/B3DynamicModal.tsx +0 -5
- package/src/global-account/react/components/B3Provider/B3ConfigProvider.tsx +0 -4
- package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +1 -1
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +1 -11
- package/src/global-account/react/components/B3Provider/LocalSDKProvider.tsx +0 -6
- package/src/global-account/react/components/B3Provider/RelayKitProviderWrapper.tsx +1 -4
- package/src/global-account/react/components/ManageAccount/SettingsContent.tsx +33 -1
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +27 -184
- package/src/global-account/react/components/index.ts +0 -3
- package/src/global-account/react/hooks/index.ts +0 -1
- package/src/global-account/react/hooks/useAuth.ts +14 -31
- package/src/global-account/react/hooks/useTWAuth.tsx +3 -5
- package/src/global-account/react/stores/useModalStore.ts +7 -20
- package/dist/cjs/global-account/react/components/TurnkeyAuthModal.d.ts +0 -8
- package/dist/cjs/global-account/react/components/TurnkeyAuthModal.js +0 -86
- package/dist/cjs/global-account/react/hooks/useTurnkeyAuth.d.ts +0 -20
- package/dist/cjs/global-account/react/hooks/useTurnkeyAuth.js +0 -142
- package/dist/esm/global-account/react/components/TurnkeyAuthModal.d.ts +0 -8
- package/dist/esm/global-account/react/components/TurnkeyAuthModal.js +0 -83
- package/dist/esm/global-account/react/hooks/useTurnkeyAuth.d.ts +0 -20
- package/dist/esm/global-account/react/hooks/useTurnkeyAuth.js +0 -136
- package/dist/types/global-account/react/components/TurnkeyAuthModal.d.ts +0 -8
- package/dist/types/global-account/react/hooks/useTurnkeyAuth.d.ts +0 -20
- package/src/global-account/react/components/TurnkeyAuthModal.tsx +0 -243
- package/src/global-account/react/hooks/useTurnkeyAuth.ts +0 -171
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Users } from "@b3dotfun/b3-api";
|
|
2
1
|
import {
|
|
3
2
|
Loading,
|
|
4
3
|
SignInWithB3ModalProps,
|
|
@@ -9,11 +8,9 @@ import {
|
|
|
9
8
|
useModalStore,
|
|
10
9
|
} from "@b3dotfun/sdk/global-account/react";
|
|
11
10
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
12
|
-
import { useCallback,
|
|
11
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
13
12
|
import { useActiveAccount } from "thirdweb/react";
|
|
14
13
|
import { Account } from "thirdweb/wallets";
|
|
15
|
-
import { LocalSDKContext } from "../B3Provider/LocalSDKProvider";
|
|
16
|
-
import { TurnkeyAuthModal } from "../TurnkeyAuthModal";
|
|
17
14
|
import { SignInWithB3Privy } from "./SignInWithB3Privy";
|
|
18
15
|
import { LoginStep, LoginStepContainer } from "./steps/LoginStep";
|
|
19
16
|
import { LoginStepCustom } from "./steps/LoginStepCustom";
|
|
@@ -37,9 +34,8 @@ export function SignInWithB3Flow({
|
|
|
37
34
|
source = "signInWithB3Button",
|
|
38
35
|
signersEnabled = false,
|
|
39
36
|
}: SignInWithB3ModalProps) {
|
|
40
|
-
const { automaticallySetFirstEoa
|
|
41
|
-
const { user,
|
|
42
|
-
const { onTurnkeyConnect } = useContext(LocalSDKContext);
|
|
37
|
+
const { automaticallySetFirstEoa } = useB3Config();
|
|
38
|
+
const { user, logout } = useAuthentication(partnerId);
|
|
43
39
|
|
|
44
40
|
// FIXME Logout before login to ensure a clean state
|
|
45
41
|
const hasLoggedOutRef = useRef(false);
|
|
@@ -58,13 +54,10 @@ export function SignInWithB3Flow({
|
|
|
58
54
|
const account = useActiveAccount();
|
|
59
55
|
const isAuthenticating = useAuthStore(state => state.isAuthenticating);
|
|
60
56
|
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
61
|
-
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
62
57
|
const isConnected = useAuthStore(state => state.isConnected);
|
|
63
|
-
const setIsConnected = useAuthStore(state => state.setIsConnected);
|
|
64
58
|
const setJustCompletedLogin = useAuthStore(state => state.setJustCompletedLogin);
|
|
65
59
|
const [refetchCount, setRefetchCount] = useState(0);
|
|
66
60
|
const [refetchError, setRefetchError] = useState<string | null>(null);
|
|
67
|
-
const [turnkeyAuthCompleted, setTurnkeyAuthCompleted] = useState(false);
|
|
68
61
|
const {
|
|
69
62
|
data: signers,
|
|
70
63
|
refetch: refetchSigners,
|
|
@@ -107,8 +100,8 @@ export function SignInWithB3Flow({
|
|
|
107
100
|
}, [refetchCount, refetchSigners, onError, refetchQueued]);
|
|
108
101
|
|
|
109
102
|
// Extract the completion flow logic to be reused
|
|
110
|
-
const
|
|
111
|
-
debug("Running post-
|
|
103
|
+
const handlePostAuthFlow = useCallback(() => {
|
|
104
|
+
debug("Running post-authentication flow logic");
|
|
112
105
|
|
|
113
106
|
// Check if we already have a signer for this partner
|
|
114
107
|
const hasExistingSigner = signers?.some(signer => signer.partner.id === partnerId);
|
|
@@ -163,65 +156,6 @@ export function SignInWithB3Flow({
|
|
|
163
156
|
setSessionKeyAdded,
|
|
164
157
|
]);
|
|
165
158
|
|
|
166
|
-
// Define handleTurnkeySuccess before the useEffect that uses it
|
|
167
|
-
const handleTurnkeySuccess = useCallback(
|
|
168
|
-
async (user: any) => {
|
|
169
|
-
debug("Turnkey authentication successful - setting completed flag", { user, onTurnkeyConnect });
|
|
170
|
-
|
|
171
|
-
// Call the onTurnkeyConnect callback
|
|
172
|
-
onTurnkeyConnect?.(user);
|
|
173
|
-
|
|
174
|
-
// Set completed flag FIRST before any async operations
|
|
175
|
-
setTurnkeyAuthCompleted(true);
|
|
176
|
-
|
|
177
|
-
// Refetch user to update the user state with Turnkey ID
|
|
178
|
-
debug("Refetching user after Turnkey success...");
|
|
179
|
-
// TODO: See why sometimes this fails with "No wallet found during auto-connect"
|
|
180
|
-
await refetchUser();
|
|
181
|
-
debug("User refetched successfully");
|
|
182
|
-
|
|
183
|
-
// Set authentication and connection state so UI updates properly
|
|
184
|
-
setIsAuthenticated(true);
|
|
185
|
-
setIsConnected(true);
|
|
186
|
-
setJustCompletedLogin(true);
|
|
187
|
-
|
|
188
|
-
// After user data is refreshed, close Turnkey modal and go back to sign-in flow
|
|
189
|
-
debug("Switching back to signInWithB3 modal");
|
|
190
|
-
setB3ModalContentType({
|
|
191
|
-
type: "signInWithB3",
|
|
192
|
-
strategies,
|
|
193
|
-
onLoginSuccess,
|
|
194
|
-
onSessionKeySuccess,
|
|
195
|
-
onError,
|
|
196
|
-
chain,
|
|
197
|
-
sessionKeyAddress,
|
|
198
|
-
partnerId,
|
|
199
|
-
closeAfterLogin,
|
|
200
|
-
source,
|
|
201
|
-
signersEnabled,
|
|
202
|
-
});
|
|
203
|
-
// The useEffect will re-run with updated user data to complete the sign-in process
|
|
204
|
-
},
|
|
205
|
-
[
|
|
206
|
-
onTurnkeyConnect,
|
|
207
|
-
refetchUser,
|
|
208
|
-
strategies,
|
|
209
|
-
onLoginSuccess,
|
|
210
|
-
onSessionKeySuccess,
|
|
211
|
-
onError,
|
|
212
|
-
chain,
|
|
213
|
-
sessionKeyAddress,
|
|
214
|
-
partnerId,
|
|
215
|
-
closeAfterLogin,
|
|
216
|
-
source,
|
|
217
|
-
signersEnabled,
|
|
218
|
-
setB3ModalContentType,
|
|
219
|
-
setIsAuthenticated,
|
|
220
|
-
setIsConnected,
|
|
221
|
-
setJustCompletedLogin,
|
|
222
|
-
],
|
|
223
|
-
);
|
|
224
|
-
|
|
225
159
|
// Handle post-login flow after signers are loaded
|
|
226
160
|
useEffect(
|
|
227
161
|
() => {
|
|
@@ -236,54 +170,12 @@ export function SignInWithB3Flow({
|
|
|
236
170
|
|
|
237
171
|
if (isConnected && isAuthenticated && user) {
|
|
238
172
|
// Mark that login just completed BEFORE opening manage account or closing modal
|
|
239
|
-
// This allows Turnkey modal to show (if enableTurnkey is true)
|
|
240
173
|
if (closeAfterLogin) {
|
|
241
174
|
setJustCompletedLogin(true);
|
|
242
175
|
}
|
|
243
176
|
|
|
244
|
-
//
|
|
245
|
-
|
|
246
|
-
// - enableTurnkey={true} is set on B3Provider
|
|
247
|
-
// - NEXT_PUBLIC_TURNKEY_PRIMARY is NOT set to true (otherwise Turnkey shows as primary)
|
|
248
|
-
// - User just logged in AND hasn't completed Turnkey auth in this session
|
|
249
|
-
// For new users (!turnkeyId): Show email form
|
|
250
|
-
// For returning users (turnkeyId && turnkeyEmail): Auto-skip to OTP
|
|
251
|
-
// Also check that we're not already showing the Turnkey modal
|
|
252
|
-
const hasTurnkeyId = user?.partnerIds?.turnkeyId;
|
|
253
|
-
const hasTurnkeyEmail = !!user?.email;
|
|
254
|
-
const isTurnkeyModalCurrentlyOpen = contentType?.type === "turnkeyAuth";
|
|
255
|
-
const isTurnkeyPrimary = process.env.NEXT_PUBLIC_TURNKEY_PRIMARY === "true";
|
|
256
|
-
const shouldShowTurnkeyModal =
|
|
257
|
-
enableTurnkey &&
|
|
258
|
-
!isTurnkeyPrimary &&
|
|
259
|
-
user &&
|
|
260
|
-
!turnkeyAuthCompleted &&
|
|
261
|
-
!isTurnkeyModalCurrentlyOpen &&
|
|
262
|
-
(!hasTurnkeyId || (hasTurnkeyId && hasTurnkeyEmail));
|
|
263
|
-
|
|
264
|
-
if (shouldShowTurnkeyModal) {
|
|
265
|
-
// Extract email from user object - check partnerIds.turnkeyEmail first, then twProfiles, then user.email
|
|
266
|
-
const email = user?.email || user?.twProfiles?.find((profile: any) => profile.details?.email)?.details?.email;
|
|
267
|
-
|
|
268
|
-
// Open Turnkey modal through the modal store
|
|
269
|
-
setB3ModalContentType({
|
|
270
|
-
type: "turnkeyAuth",
|
|
271
|
-
onSuccess: handleTurnkeySuccess,
|
|
272
|
-
onClose: () => {
|
|
273
|
-
// After closing Turnkey modal, continue with the rest of the flow
|
|
274
|
-
setTurnkeyAuthCompleted(true);
|
|
275
|
-
debug("Turnkey modal closed, running post-Turnkey flow");
|
|
276
|
-
handlePostTurnkeyFlow();
|
|
277
|
-
},
|
|
278
|
-
initialEmail: email,
|
|
279
|
-
skipToOtp: !!(hasTurnkeyId && hasTurnkeyEmail),
|
|
280
|
-
closable: false, // Turnkey modal cannot be closed until auth is complete
|
|
281
|
-
});
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// Normal flow continues after Turnkey auth is complete (or if not needed)
|
|
286
|
-
handlePostTurnkeyFlow();
|
|
177
|
+
// Normal flow continues
|
|
178
|
+
handlePostAuthFlow();
|
|
287
179
|
}
|
|
288
180
|
},
|
|
289
181
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -304,11 +196,8 @@ export function SignInWithB3Flow({
|
|
|
304
196
|
isAuthenticated,
|
|
305
197
|
isOpen,
|
|
306
198
|
user,
|
|
307
|
-
enableTurnkey,
|
|
308
|
-
turnkeyAuthCompleted,
|
|
309
|
-
// handleTurnkeySuccess, // This is causing infinite loops
|
|
310
199
|
contentType,
|
|
311
|
-
|
|
200
|
+
handlePostAuthFlow,
|
|
312
201
|
],
|
|
313
202
|
);
|
|
314
203
|
|
|
@@ -386,79 +275,33 @@ export function SignInWithB3Flow({
|
|
|
386
275
|
</LoginStepContainer>
|
|
387
276
|
);
|
|
388
277
|
} else if (step === "login") {
|
|
389
|
-
//
|
|
390
|
-
|
|
391
|
-
const isTurnkeyPrimary = process.env.NEXT_PUBLIC_TURNKEY_PRIMARY === "true";
|
|
392
|
-
const shouldShowTurnkeyFirst = isTurnkeyPrimary && !turnkeyAuthCompleted;
|
|
393
|
-
|
|
394
|
-
if (shouldShowTurnkeyFirst) {
|
|
395
|
-
// Don't show loading spinner for Turnkey - let the modal handle its own loading state
|
|
396
|
-
// This prevents the infinite loop where isAuthenticating causes the modal to be replaced
|
|
397
|
-
debug("Showing Turnkey as primary authentication option", {
|
|
398
|
-
isTurnkeyPrimary,
|
|
399
|
-
turnkeyAuthCompleted,
|
|
400
|
-
isAuthenticated,
|
|
401
|
-
});
|
|
402
|
-
// Show Turnkey authentication as primary option
|
|
278
|
+
// Show loading spinner
|
|
279
|
+
if (isAuthenticating || (isFetchingSigners && step === "login") || source === "requestPermissions") {
|
|
403
280
|
content = (
|
|
404
281
|
<LoginStepContainer partnerId={partnerId}>
|
|
405
|
-
<
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
setTurnkeyAuthCompleted(true);
|
|
409
|
-
// User is now authenticated via Turnkey
|
|
410
|
-
// Set both isAuthenticated and isConnected to true so UI updates properly
|
|
411
|
-
// Wallet connection is optional and can happen later for signing transactions
|
|
412
|
-
setIsAuthenticated(true);
|
|
413
|
-
setIsConnected(true);
|
|
414
|
-
setJustCompletedLogin(true);
|
|
415
|
-
// Call the login success callback
|
|
416
|
-
onLoginSuccess?.({} as Account);
|
|
417
|
-
// Call the onTurnkeyConnect callback
|
|
418
|
-
onTurnkeyConnect?.(authenticatedUser);
|
|
419
|
-
|
|
420
|
-
// After Turnkey auth, refetch user to get the full user object
|
|
421
|
-
// TODO: See why sometimes this fails with "No wallet found during auto-connect"
|
|
422
|
-
await refetchUser();
|
|
423
|
-
}}
|
|
424
|
-
onClose={() => {
|
|
425
|
-
// If user closes Turnkey modal, they can still use wallet connection as fallback
|
|
426
|
-
setTurnkeyAuthCompleted(true);
|
|
427
|
-
}}
|
|
428
|
-
initialEmail=""
|
|
429
|
-
skipToOtp={false}
|
|
430
|
-
/>
|
|
282
|
+
<div className="my-8 flex min-h-[350px] items-center justify-center">
|
|
283
|
+
<Loading variant="white" size="lg" />
|
|
284
|
+
</div>
|
|
431
285
|
</LoginStepContainer>
|
|
432
286
|
);
|
|
433
287
|
} else {
|
|
434
|
-
//
|
|
435
|
-
if (
|
|
288
|
+
// Custom strategy
|
|
289
|
+
if (strategies?.[0] === "privy") {
|
|
290
|
+
content = <SignInWithB3Privy onSuccess={handleLoginSuccess} chain={chain} />;
|
|
291
|
+
} else if (strategies) {
|
|
292
|
+
// Strategies are explicitly provided
|
|
436
293
|
content = (
|
|
437
|
-
<
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
294
|
+
<LoginStepCustom
|
|
295
|
+
strategies={strategies}
|
|
296
|
+
chain={chain}
|
|
297
|
+
onSuccess={handleLoginSuccess}
|
|
298
|
+
onError={onError}
|
|
299
|
+
automaticallySetFirstEoa={!!automaticallySetFirstEoa}
|
|
300
|
+
/>
|
|
442
301
|
);
|
|
443
302
|
} else {
|
|
444
|
-
//
|
|
445
|
-
|
|
446
|
-
content = <SignInWithB3Privy onSuccess={handleLoginSuccess} chain={chain} />;
|
|
447
|
-
} else if (strategies) {
|
|
448
|
-
// Strategies are explicitly provided
|
|
449
|
-
content = (
|
|
450
|
-
<LoginStepCustom
|
|
451
|
-
strategies={strategies}
|
|
452
|
-
chain={chain}
|
|
453
|
-
onSuccess={handleLoginSuccess}
|
|
454
|
-
onError={onError}
|
|
455
|
-
automaticallySetFirstEoa={!!automaticallySetFirstEoa}
|
|
456
|
-
/>
|
|
457
|
-
);
|
|
458
|
-
} else {
|
|
459
|
-
// Default to handle all strategies we support
|
|
460
|
-
content = <LoginStep chain={chain} onSuccess={handleLoginSuccess} onError={onError} />;
|
|
461
|
-
}
|
|
303
|
+
// Default to handle all strategies we support
|
|
304
|
+
content = <LoginStep chain={chain} onSuccess={handleLoginSuccess} onError={onError} />;
|
|
462
305
|
}
|
|
463
306
|
}
|
|
464
307
|
}
|
|
@@ -18,9 +18,6 @@ export { SignInWithB3Privy } from "./SignInWithB3/SignInWithB3Privy";
|
|
|
18
18
|
export { LoginStepContainer } from "./SignInWithB3/steps/LoginStep";
|
|
19
19
|
export { getConnectOptionsFromStrategy, isWalletType, type AllowedStrategy } from "./SignInWithB3/utils/signInUtils";
|
|
20
20
|
|
|
21
|
-
// Turnkey Components
|
|
22
|
-
export { TurnkeyAuthModal } from "./TurnkeyAuthModal";
|
|
23
|
-
|
|
24
21
|
// ManageAccount Components
|
|
25
22
|
export { ManageAccount } from "./ManageAccount/ManageAccount";
|
|
26
23
|
|
|
@@ -50,7 +50,6 @@ export { useTokenFromUrl } from "./useTokenFromUrl";
|
|
|
50
50
|
export { useTokenPrice } from "./useTokenPrice";
|
|
51
51
|
export { useTokenPriceWithFallback } from "./useTokenPriceWithFallback";
|
|
52
52
|
export { useTokensFromAddress } from "./useTokensFromAddress";
|
|
53
|
-
export { useTurnkeyAuth } from "./useTurnkeyAuth";
|
|
54
53
|
export { useUnifiedChainSwitchAndExecute } from "./useUnifiedChainSwitchAndExecute";
|
|
55
54
|
export { useURLParams } from "./useURLParams";
|
|
56
55
|
export { useUser } from "./useUser";
|
|
@@ -25,8 +25,7 @@ import { useUserQuery } from "./useUserQuery";
|
|
|
25
25
|
const debug = debugB3React("useAuth");
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* Unified authentication hook
|
|
29
|
-
* This replaces the previous Thirdweb-based authentication
|
|
28
|
+
* Unified authentication hook for B3
|
|
30
29
|
*
|
|
31
30
|
* This hook provides 1:1 feature parity with useAuthentication.ts
|
|
32
31
|
*/
|
|
@@ -146,12 +145,8 @@ export function useAuth() {
|
|
|
146
145
|
}, [wallets, syncWagmi]);
|
|
147
146
|
|
|
148
147
|
/**
|
|
149
|
-
* Authenticate user
|
|
150
|
-
*
|
|
151
|
-
* Wallets are still used for signing transactions, but authentication is done via Turnkey email OTP.
|
|
152
|
-
*
|
|
153
|
-
* For backward compatibility, this function still accepts a wallet parameter,
|
|
154
|
-
* but it's not used for authentication anymore.
|
|
148
|
+
* Authenticate user
|
|
149
|
+
* Attempts to re-authenticate using existing session
|
|
155
150
|
*/
|
|
156
151
|
const authenticateUser = useCallback(async () => {
|
|
157
152
|
setHasStartedConnecting(true);
|
|
@@ -170,18 +165,16 @@ export function useAuth() {
|
|
|
170
165
|
|
|
171
166
|
return userAuth;
|
|
172
167
|
} catch (error) {
|
|
173
|
-
// If re-authentication fails, user needs to authenticate
|
|
174
|
-
|
|
175
|
-
debug("Re-authentication failed. User needs to authenticate via Turnkey.", error);
|
|
168
|
+
// If re-authentication fails, user needs to authenticate
|
|
169
|
+
debug("Re-authentication failed. User needs to authenticate.", error);
|
|
176
170
|
setIsAuthenticated(false);
|
|
177
171
|
setIsAuthenticating(false);
|
|
178
|
-
throw new Error("Authentication required. Please authenticate
|
|
172
|
+
throw new Error("Authentication required. Please authenticate.");
|
|
179
173
|
}
|
|
180
174
|
}, [reAuthenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting]);
|
|
181
175
|
|
|
182
176
|
/**
|
|
183
|
-
* Authenticate with
|
|
184
|
-
* This is the primary authentication method, replacing Thirdweb wallet-based auth
|
|
177
|
+
* Authenticate with B3
|
|
185
178
|
*
|
|
186
179
|
* This function:
|
|
187
180
|
* 1. Authenticates with FeathersJS (persists session via cookies)
|
|
@@ -189,18 +182,18 @@ export function useAuth() {
|
|
|
189
182
|
* 3. Authenticates with BSMNT for basement integration
|
|
190
183
|
*/
|
|
191
184
|
const authenticate = useCallback(
|
|
192
|
-
async (
|
|
193
|
-
if (!
|
|
194
|
-
throw new Error("
|
|
185
|
+
async (accessToken: string, partnerId: string, strategy = "thirdweb-jwt") => {
|
|
186
|
+
if (!accessToken) {
|
|
187
|
+
throw new Error("Access token is required");
|
|
195
188
|
}
|
|
196
189
|
|
|
197
|
-
debug("Authenticating with
|
|
190
|
+
debug("Authenticating with B3", { referralCode, partnerId, strategy });
|
|
198
191
|
|
|
199
192
|
try {
|
|
200
193
|
// Step 1: Authenticate with FeathersJS (session persisted via cookies)
|
|
201
194
|
const response = await app.authenticate({
|
|
202
|
-
strategy
|
|
203
|
-
accessToken
|
|
195
|
+
strategy,
|
|
196
|
+
accessToken,
|
|
204
197
|
referralCode,
|
|
205
198
|
partnerId: partnerId,
|
|
206
199
|
} as any);
|
|
@@ -233,13 +226,6 @@ export function useAuth() {
|
|
|
233
226
|
|
|
234
227
|
/**
|
|
235
228
|
* Handle wallet connection
|
|
236
|
-
* Note: With Turnkey migration, wallet connection is primarily for signing transactions,
|
|
237
|
-
* not for authentication. Authentication should be done separately via Turnkey email OTP.
|
|
238
|
-
*/
|
|
239
|
-
/**
|
|
240
|
-
* Handle wallet connection
|
|
241
|
-
* Note: With Turnkey migration, wallet connection is primarily for signing transactions,
|
|
242
|
-
* not for authentication. Authentication should be done separately via Turnkey email OTP.
|
|
243
229
|
*/
|
|
244
230
|
const onConnect = useCallback(
|
|
245
231
|
async (_walleAutoConnectedWith: Wallet, allConnectedWallets: Wallet[]) => {
|
|
@@ -260,7 +246,6 @@ export function useAuth() {
|
|
|
260
246
|
await setActiveWallet(wallet);
|
|
261
247
|
|
|
262
248
|
// Try to authenticate user (will use re-authenticate if session exists)
|
|
263
|
-
// If no session exists, authentication will need to happen via Turnkey flow
|
|
264
249
|
try {
|
|
265
250
|
const userAuth = await authenticateUser();
|
|
266
251
|
|
|
@@ -268,10 +253,8 @@ export function useAuth() {
|
|
|
268
253
|
await onConnectCallback(wallet, userAuth.accessToken);
|
|
269
254
|
}
|
|
270
255
|
} catch (authError) {
|
|
271
|
-
// Authentication failed -
|
|
272
|
-
// The Turnkey auth modal should handle this
|
|
256
|
+
// Authentication failed - user needs to authenticate
|
|
273
257
|
debug("@@useAuth:onConnect:authFailed", { authError });
|
|
274
|
-
// Don't set isAuthenticated to false here - let the Turnkey flow handle it
|
|
275
258
|
}
|
|
276
259
|
} catch (error) {
|
|
277
260
|
debug("@@useAuth:onConnect:failed", { error });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @deprecated This hook is deprecated. Use useAuth()
|
|
2
|
+
* @deprecated This hook is deprecated. Use useAuth() instead.
|
|
3
3
|
* This file is kept for backward compatibility but should not be used in new code.
|
|
4
4
|
*/
|
|
5
5
|
import app from "@b3dotfun/sdk/global-account/app";
|
|
@@ -9,12 +9,10 @@ import { Wallet } from "thirdweb/wallets";
|
|
|
9
9
|
import { useSearchParam } from "./useSearchParamsSSR";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* @deprecated Use useAuth()
|
|
12
|
+
* @deprecated Use useAuth() instead
|
|
13
13
|
*/
|
|
14
14
|
export function useTWAuth() {
|
|
15
|
-
console.warn(
|
|
16
|
-
"useTWAuth is deprecated. Please migrate to useAuth() with Turnkey authentication. See useTurnkeyAuth.ts for the new implementation.",
|
|
17
|
-
);
|
|
15
|
+
console.warn("useTWAuth is deprecated. Please migrate to useAuth() for authentication.");
|
|
18
16
|
const referralCode = useSearchParam("referralCode");
|
|
19
17
|
|
|
20
18
|
const authenticate = useCallback(
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AnySpendAllClasses } from "@b3dotfun/sdk/anyspend/react";
|
|
1
2
|
import { components } from "@b3dotfun/sdk/anyspend/types/api";
|
|
2
3
|
import { GenerateSigMintResponse } from "@b3dotfun/sdk/anyspend/types/signatureMint";
|
|
3
4
|
import { AllowedStrategy } from "@b3dotfun/sdk/global-account/react";
|
|
@@ -45,25 +46,6 @@ export interface SignInWithB3ModalProps extends BaseModalProps {
|
|
|
45
46
|
signersEnabled?: boolean;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
/**
|
|
49
|
-
* Props for the Turnkey Authentication modal
|
|
50
|
-
* Handles Turnkey email/OTP authentication flow
|
|
51
|
-
*/
|
|
52
|
-
export interface TurnkeyAuthModalProps extends BaseModalProps {
|
|
53
|
-
/** Modal type identifier */
|
|
54
|
-
type: "turnkeyAuth";
|
|
55
|
-
/** Callback function called when authentication is successful */
|
|
56
|
-
onSuccess: (_user: any) => void;
|
|
57
|
-
/** Callback function called when modal is closed */
|
|
58
|
-
onClose: () => void;
|
|
59
|
-
/** Initial email to pre-fill */
|
|
60
|
-
initialEmail?: string;
|
|
61
|
-
/** Whether to skip directly to OTP step */
|
|
62
|
-
skipToOtp?: boolean;
|
|
63
|
-
/** Whether the modal can be closed - defaults to false for Turnkey */
|
|
64
|
-
closable?: boolean;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
49
|
/**
|
|
68
50
|
* Props for the Request Permissions modal
|
|
69
51
|
* Used to request permission for session keys to interact with contracts
|
|
@@ -322,6 +304,8 @@ export interface AnySpendDepositUpsideProps extends BaseModalProps {
|
|
|
322
304
|
depositContractAddress: string;
|
|
323
305
|
/** Token to deposit */
|
|
324
306
|
token: components["schemas"]["Token"];
|
|
307
|
+
/** The exact amount of destination tokens to receive, in wei. This will pre-fill the output amount and switch to an exact output swap. */
|
|
308
|
+
destinationTokenAmount?: string;
|
|
325
309
|
/** Callback function called when the deposit is successful */
|
|
326
310
|
onSuccess?: () => void;
|
|
327
311
|
}
|
|
@@ -568,6 +552,10 @@ export interface AnySpendDepositModalProps extends BaseModalProps {
|
|
|
568
552
|
returnHomeLabel?: string;
|
|
569
553
|
/** Whether the deposit requires a custom function (uses AnySpendCustomExactIn). Defaults to false. */
|
|
570
554
|
isCustomDeposit?: boolean;
|
|
555
|
+
/** Custom class names for styling specific elements */
|
|
556
|
+
classes?: AnySpendAllClasses;
|
|
557
|
+
/** Whether to allow direct transfer without swap */
|
|
558
|
+
allowDirectTransfer?: boolean;
|
|
571
559
|
}
|
|
572
560
|
|
|
573
561
|
/**
|
|
@@ -575,7 +563,6 @@ export interface AnySpendDepositModalProps extends BaseModalProps {
|
|
|
575
563
|
*/
|
|
576
564
|
export type ModalContentType =
|
|
577
565
|
| SignInWithB3ModalProps
|
|
578
|
-
| TurnkeyAuthModalProps
|
|
579
566
|
| RequestPermissionsModalProps
|
|
580
567
|
| ManageAccountModalProps
|
|
581
568
|
| AnySpendModalProps
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
interface TurnkeyAuthModalProps {
|
|
2
|
-
onClose: () => void;
|
|
3
|
-
onSuccess: (_user: any) => void;
|
|
4
|
-
initialEmail?: string;
|
|
5
|
-
skipToOtp?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export declare function TurnkeyAuthModal({ onClose, onSuccess, initialEmail, skipToOtp }: TurnkeyAuthModalProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
-
export {};
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TurnkeyAuthModal = TurnkeyAuthModal;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
const useTurnkeyAuth_1 = require("../hooks/useTurnkeyAuth");
|
|
7
|
-
function TurnkeyAuthModal({ onClose, onSuccess, initialEmail = "", skipToOtp = false }) {
|
|
8
|
-
const [step, setStep] = (0, react_1.useState)(skipToOtp ? "otp" : "email");
|
|
9
|
-
const [email, setEmail] = (0, react_1.useState)(initialEmail);
|
|
10
|
-
const [otpCode, setOtpCode] = (0, react_1.useState)("");
|
|
11
|
-
const [otpId, setOtpId] = (0, react_1.useState)("");
|
|
12
|
-
const autoSubmitTriggeredRef = (0, react_1.useRef)(false);
|
|
13
|
-
const { initiateLogin, verifyOtp, isLoading, error, clearError } = (0, useTurnkeyAuth_1.useTurnkeyAuth)();
|
|
14
|
-
// Update email when initialEmail changes
|
|
15
|
-
(0, react_1.useEffect)(() => {
|
|
16
|
-
if (initialEmail && initialEmail !== email) {
|
|
17
|
-
setEmail(initialEmail);
|
|
18
|
-
}
|
|
19
|
-
}, [initialEmail, email]);
|
|
20
|
-
// Auto-submit email form if skipToOtp is true - triggers on mount when skipToOtp=true
|
|
21
|
-
(0, react_1.useEffect)(() => {
|
|
22
|
-
if (skipToOtp && email && step === "otp" && !otpId && !isLoading && !autoSubmitTriggeredRef.current) {
|
|
23
|
-
autoSubmitTriggeredRef.current = true;
|
|
24
|
-
// Call initiateLogin directly to get OTP
|
|
25
|
-
initiateLogin(email)
|
|
26
|
-
.then(result => {
|
|
27
|
-
setOtpId(result.otpId);
|
|
28
|
-
})
|
|
29
|
-
.catch(err => {
|
|
30
|
-
console.error("Failed to initiate login:", err);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
34
|
-
}, [skipToOtp, email, step, otpId, isLoading]);
|
|
35
|
-
const handleEmailSubmit = async (e) => {
|
|
36
|
-
e.preventDefault();
|
|
37
|
-
try {
|
|
38
|
-
const result = await initiateLogin(email);
|
|
39
|
-
setOtpId(result.otpId);
|
|
40
|
-
setStep("otp");
|
|
41
|
-
}
|
|
42
|
-
catch (err) {
|
|
43
|
-
// Error is handled by the hook
|
|
44
|
-
console.error("Failed to initiate login:", err);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const handleOtpSubmit = async (e) => {
|
|
48
|
-
e.preventDefault();
|
|
49
|
-
try {
|
|
50
|
-
const result = await verifyOtp(otpId, otpCode);
|
|
51
|
-
setStep("success");
|
|
52
|
-
// Auto-close after success and notify parent
|
|
53
|
-
setTimeout(() => {
|
|
54
|
-
onSuccess(result.user);
|
|
55
|
-
handleClose();
|
|
56
|
-
}, 1500);
|
|
57
|
-
}
|
|
58
|
-
catch (err) {
|
|
59
|
-
// Error is handled by the hook
|
|
60
|
-
console.error("Failed to verify OTP:", err);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
const handleClose = () => {
|
|
64
|
-
// Reset state
|
|
65
|
-
setStep("email");
|
|
66
|
-
setEmail("");
|
|
67
|
-
setOtpCode("");
|
|
68
|
-
setOtpId("");
|
|
69
|
-
autoSubmitTriggeredRef.current = false;
|
|
70
|
-
clearError();
|
|
71
|
-
onClose();
|
|
72
|
-
};
|
|
73
|
-
const handleResendOtp = async () => {
|
|
74
|
-
try {
|
|
75
|
-
const result = await initiateLogin(email);
|
|
76
|
-
setOtpId(result.otpId);
|
|
77
|
-
clearError();
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
console.error("Failed to resend OTP:", err);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
const isTurnkeyPrimary = process.env.NEXT_PUBLIC_TURNKEY_PRIMARY === "true";
|
|
84
|
-
const walletBrand = isTurnkeyPrimary ? "Smart Wallet" : "AnySpend Wallet";
|
|
85
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: "font-neue-montreal p-8", children: [step === "email" && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("h2", { className: "mb-6 text-center text-2xl font-bold text-gray-900 dark:text-white", children: ["Setup your ", walletBrand] }), (0, jsx_runtime_1.jsxs)("div", { className: "mb-6 space-y-3 text-center text-sm text-gray-600 dark:text-gray-400", children: [(0, jsx_runtime_1.jsxs)("p", { children: [isTurnkeyPrimary ? "We use a secure," : "AnySpend uses a secure,", (0, jsx_runtime_1.jsx)("br", {}), "embedded wallet to fund your workflows."] }), (0, jsx_runtime_1.jsxs)("p", { children: ["Please provide an email address to secure", (0, jsx_runtime_1.jsx)("br", {}), "your wallet."] })] }), (0, jsx_runtime_1.jsxs)("form", { onSubmit: handleEmailSubmit, className: "space-y-4", children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("input", { type: "email", placeholder: "email", value: email, onChange: e => setEmail(e.target.value), required: true, disabled: isLoading, className: "w-full rounded-lg border border-gray-300 px-4 py-3 text-center text-gray-900 placeholder-gray-400 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20 disabled:cursor-not-allowed disabled:bg-gray-50 dark:border-gray-700 dark:bg-gray-800 dark:text-white dark:placeholder-gray-500" }) }), error && ((0, jsx_runtime_1.jsx)("div", { className: "rounded-md bg-red-50 p-3 text-sm text-red-800 dark:bg-red-900/20 dark:text-red-400", children: error })), (0, jsx_runtime_1.jsx)("button", { type: "submit", disabled: isLoading || !email, className: "w-full rounded-lg bg-blue-600 px-6 py-3 font-semibold text-white transition-all duration-200 hover:bg-blue-700 disabled:cursor-not-allowed disabled:bg-gray-300 dark:disabled:bg-gray-700", children: isLoading ? ((0, jsx_runtime_1.jsxs)("span", { className: "flex items-center justify-center gap-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "h-4 w-4 animate-spin rounded-full border-2 border-white border-t-transparent" }), "Sending..."] })) : ("Continue") })] })] })), step === "otp" && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("h2", { className: "mb-4 text-center text-2xl font-bold text-gray-900 dark:text-white", children: "2FA Security" }), (0, jsx_runtime_1.jsx)("div", { className: "mb-6 space-y-3 text-center text-sm text-gray-600 dark:text-gray-400", children: (0, jsx_runtime_1.jsxs)("p", { children: [isTurnkeyPrimary ? "We use a secure," : "AnySpend uses a secure,", (0, jsx_runtime_1.jsx)("br", {}), "embedded wallet to fund your workflows.", (0, jsx_runtime_1.jsx)("br", {}), "Please provide 2FA code sent to your email."] }) }), (0, jsx_runtime_1.jsxs)("form", { onSubmit: handleOtpSubmit, className: "space-y-4", children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("input", { type: "text", placeholder: "Enter code", value: otpCode, onChange: e => setOtpCode(e.target.value.toUpperCase()), required: true, disabled: isLoading, autoFocus: true, className: "w-full rounded-lg border border-gray-300 px-4 py-3 text-center font-mono text-lg uppercase tracking-wider text-gray-900 placeholder-gray-400 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20 disabled:cursor-not-allowed disabled:bg-gray-50 dark:border-gray-700 dark:bg-gray-800 dark:text-white dark:placeholder-gray-500", maxLength: 20 }) }), error && ((0, jsx_runtime_1.jsx)("div", { className: "rounded-md bg-red-50 p-3 text-sm text-red-800 dark:bg-red-900/20 dark:text-red-400", children: error })), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col gap-2", children: [(0, jsx_runtime_1.jsx)("button", { type: "submit", disabled: isLoading || !otpCode, className: "w-full rounded-lg bg-blue-600 px-6 py-3 font-semibold text-white transition-all duration-200 hover:bg-blue-700 disabled:cursor-not-allowed disabled:bg-gray-300 dark:disabled:bg-gray-700", children: isLoading ? ((0, jsx_runtime_1.jsxs)("span", { className: "flex items-center justify-center gap-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "h-4 w-4 animate-spin rounded-full border-2 border-white border-t-transparent" }), "Verifying..."] })) : ("Confirm") }), (0, jsx_runtime_1.jsx)("button", { type: "button", onClick: handleResendOtp, disabled: isLoading, className: "text-sm text-blue-600 hover:text-blue-700 hover:underline disabled:cursor-not-allowed disabled:text-gray-400 dark:text-blue-400 dark:hover:text-blue-300", children: "Resend code" })] })] })] })), step === "success" && ((0, jsx_runtime_1.jsxs)("div", { className: "text-center", children: [(0, jsx_runtime_1.jsx)("div", { className: "mb-6 flex items-center justify-center", children: (0, jsx_runtime_1.jsx)("div", { className: "flex h-16 w-16 items-center justify-center rounded-full bg-green-100 dark:bg-green-900/20", children: (0, jsx_runtime_1.jsx)("svg", { className: "h-8 w-8 text-green-600 dark:text-green-400", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: (0, jsx_runtime_1.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M5 13l4 4L19 7" }) }) }) }), (0, jsx_runtime_1.jsx)("h2", { className: "mb-2 text-2xl font-bold text-gray-900 dark:text-white", children: "Successfully Authenticated!" }), (0, jsx_runtime_1.jsx)("p", { className: "text-sm text-gray-600 dark:text-gray-400", children: "Redirecting..." })] }))] }));
|
|
86
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { TurnkeyAuthInitResponse } from "@b3dotfun/b3-api";
|
|
2
|
-
interface UseTurnkeyAuthReturn {
|
|
3
|
-
initiateLogin: (_email: string) => Promise<TurnkeyAuthInitResponse>;
|
|
4
|
-
verifyOtp: (_otpId: string, _otpCode: string) => Promise<{
|
|
5
|
-
user: any;
|
|
6
|
-
}>;
|
|
7
|
-
isLoading: boolean;
|
|
8
|
-
error: string | null;
|
|
9
|
-
clearError: () => void;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Hook for Turnkey email-based OTP authentication
|
|
13
|
-
*
|
|
14
|
-
* Usage:
|
|
15
|
-
* 1. Call initiateLogin(email) → User receives OTP email
|
|
16
|
-
* 2. Call verifyOtp(...) → Verifies OTP and authenticates with b3-api
|
|
17
|
-
* 3. User is authenticated, JWT stored in cookies automatically
|
|
18
|
-
*/
|
|
19
|
-
export declare function useTurnkeyAuth(): UseTurnkeyAuthReturn;
|
|
20
|
-
export {};
|