@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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod";
|
|
2
|
+
interface DirectTransferParams {
|
|
3
|
+
chainId: number;
|
|
4
|
+
tokenAddress: string;
|
|
5
|
+
recipientAddress: string;
|
|
6
|
+
amount: bigint;
|
|
7
|
+
method: CryptoPaymentMethodType;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Hook for executing direct token transfers (same chain, same token)
|
|
11
|
+
* bypassing the swap backend.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useDirectTransfer(): {
|
|
14
|
+
executeDirectTransfer: ({ chainId, tokenAddress, recipientAddress, amount, method, }: DirectTransferParams) => Promise<string | undefined>;
|
|
15
|
+
isTransferring: boolean;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useUnifiedChainSwitchAndExecute } from "../../../global-account/react/index.js";
|
|
2
|
+
import { isNativeToken } from "../../../anyspend/utils/token.js";
|
|
3
|
+
import { encodeFunctionData, erc20Abi } from "viem";
|
|
4
|
+
import { useCallback } from "react";
|
|
5
|
+
import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod.js";
|
|
6
|
+
/**
|
|
7
|
+
* Hook for executing direct token transfers (same chain, same token)
|
|
8
|
+
* bypassing the swap backend.
|
|
9
|
+
*/
|
|
10
|
+
export function useDirectTransfer() {
|
|
11
|
+
const { switchChainAndExecute, switchChainAndExecuteWithEOA, isSwitchingOrExecuting } = useUnifiedChainSwitchAndExecute();
|
|
12
|
+
const executeDirectTransfer = useCallback(async ({ chainId, tokenAddress, recipientAddress, amount, method, }) => {
|
|
13
|
+
const isNative = isNativeToken(tokenAddress);
|
|
14
|
+
// Choose the correct execution function based on payment method
|
|
15
|
+
const execute = method === CryptoPaymentMethodType.CONNECT_WALLET ? switchChainAndExecuteWithEOA : switchChainAndExecute;
|
|
16
|
+
let txHash;
|
|
17
|
+
if (isNative) {
|
|
18
|
+
// Native token transfer (ETH, etc.)
|
|
19
|
+
txHash = await execute(chainId, {
|
|
20
|
+
to: recipientAddress,
|
|
21
|
+
value: amount,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
// ERC20 token transfer
|
|
26
|
+
const transferData = encodeFunctionData({
|
|
27
|
+
abi: erc20Abi,
|
|
28
|
+
functionName: "transfer",
|
|
29
|
+
args: [recipientAddress, amount],
|
|
30
|
+
});
|
|
31
|
+
txHash = await execute(chainId, {
|
|
32
|
+
to: tokenAddress,
|
|
33
|
+
data: transferData,
|
|
34
|
+
value: BigInt(0),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return txHash;
|
|
38
|
+
}, [switchChainAndExecute, switchChainAndExecuteWithEOA]);
|
|
39
|
+
return {
|
|
40
|
+
executeDirectTransfer,
|
|
41
|
+
isTransferring: isSwitchingOrExecuting,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -35,7 +35,7 @@ export function useRecipientAddressState({ recipientAddressFromProps, walletAddr
|
|
|
35
35
|
// selectedRecipientAddress: explicitly selected by user (undefined means no explicit selection)
|
|
36
36
|
const [selectedRecipientAddress, setSelectedRecipientAddress] = useState(undefined);
|
|
37
37
|
// The effective recipient address, derived on each render, respecting priority.
|
|
38
|
-
const effectiveRecipientAddress =
|
|
38
|
+
const effectiveRecipientAddress = selectedRecipientAddress || recipientAddressFromProps || walletAddress || globalAddress;
|
|
39
39
|
// Helper function to reset user's manual selection.
|
|
40
40
|
const resetRecipientAddress = () => {
|
|
41
41
|
setSelectedRecipientAddress(undefined);
|
|
@@ -3,7 +3,11 @@ export const getStatusDisplay = (order) => {
|
|
|
3
3
|
const srcToken = order.metadata?.srcToken;
|
|
4
4
|
const dstToken = order.metadata?.dstToken;
|
|
5
5
|
const formattedSrcAmount = srcToken ? formatTokenAmount(BigInt(order.srcAmount), srcToken.decimals) : undefined;
|
|
6
|
-
|
|
6
|
+
// For custom orders, use payload.amount as fallback if actualDstAmount is not available
|
|
7
|
+
const actualDstAmount = order.settlement?.actualDstAmount ||
|
|
8
|
+
(order.type === "custom" || order.type === "custom_exact_in" || order.type === "deposit_first"
|
|
9
|
+
? order.payload.amount?.toString()
|
|
10
|
+
: undefined);
|
|
7
11
|
const formattedActualDstAmount = actualDstAmount && dstToken ? formatTokenAmount(BigInt(actualDstAmount), dstToken.decimals) : undefined;
|
|
8
12
|
switch (order.status) {
|
|
9
13
|
case "scanning_deposit_transaction": {
|
|
@@ -40,6 +44,7 @@ export const getStatusDisplay = (order) => {
|
|
|
40
44
|
};
|
|
41
45
|
case "executed": {
|
|
42
46
|
const receivedText = formattedActualDstAmount && dstToken ? `Received ${formattedActualDstAmount} ${dstToken.symbol}` : undefined;
|
|
47
|
+
const actionText = order.metadata?.action || "Order";
|
|
43
48
|
const { text, description } = order.type === "swap"
|
|
44
49
|
? { text: receivedText || "Swap Complete", description: "Your swap has been completed successfully." }
|
|
45
50
|
: order.type === "mint_nft"
|
|
@@ -48,7 +53,12 @@ export const getStatusDisplay = (order) => {
|
|
|
48
53
|
? { text: "Tournament Joined", description: "You have joined the tournament" }
|
|
49
54
|
: order.type === "fund_tournament"
|
|
50
55
|
? { text: "Tournament Funded", description: "You have funded the tournament" }
|
|
51
|
-
:
|
|
56
|
+
: order.type === "custom" || order.type === "custom_exact_in"
|
|
57
|
+
? {
|
|
58
|
+
text: receivedText || `${actionText} Complete`,
|
|
59
|
+
description: "Your order has been completed successfully.",
|
|
60
|
+
}
|
|
61
|
+
: { text: receivedText || "Order Complete", description: "Your order has been completed" };
|
|
52
62
|
return { text, status: "success", description };
|
|
53
63
|
}
|
|
54
64
|
case "refunding":
|
|
@@ -19,7 +19,6 @@ import { RequestPermissions } from "./RequestPermissions/RequestPermissions.js";
|
|
|
19
19
|
import { Send } from "./Send/Send.js";
|
|
20
20
|
import { SignInWithB3Flow } from "./SignInWithB3/SignInWithB3Flow.js";
|
|
21
21
|
import { ToastContainer, useToastContext } from "./Toast/index.js";
|
|
22
|
-
import { TurnkeyAuthModal } from "./TurnkeyAuthModal.js";
|
|
23
22
|
import { Dialog, DialogContent, DialogDescription, DialogTitle } from "./ui/dialog.js";
|
|
24
23
|
import { Drawer, DrawerContent, DrawerDescription, DrawerTitle } from "./ui/drawer.js";
|
|
25
24
|
const debug = debugB3React("B3DynamicModal");
|
|
@@ -44,7 +43,6 @@ export function B3DynamicModal() {
|
|
|
44
43
|
"anySpendBuySpin",
|
|
45
44
|
"anySpendOrderHistory",
|
|
46
45
|
"signInWithB3",
|
|
47
|
-
"turnkeyAuth",
|
|
48
46
|
"anySpendSignatureMint",
|
|
49
47
|
"anySpendBondKit",
|
|
50
48
|
"linkAccount",
|
|
@@ -74,7 +72,7 @@ export function B3DynamicModal() {
|
|
|
74
72
|
const hideCloseButton = true;
|
|
75
73
|
// Build content class using cn utility
|
|
76
74
|
// eslint-disable-next-line tailwindcss/no-custom-classname
|
|
77
|
-
const contentClass = cn("b3-modal", theme === "dark" && "dark", fullWidthTypes.includes(contentType?.type) && "w-full", isFreestyleType && "b3-modal-freestyle", contentType?.type === "signInWithB3" && "p-0", contentType?.type === "
|
|
75
|
+
const contentClass = cn("b3-modal", theme === "dark" && "dark", fullWidthTypes.includes(contentType?.type) && "w-full", isFreestyleType && "b3-modal-freestyle", contentType?.type === "signInWithB3" && "p-0", contentType?.type === "anySpend" && "md:p-0", contentType?.type === "send" && "p-0", contentType?.type === "manageAccount" && " md:p-0 md:pt-2", contentType?.type === "linkAccount" && "md:p-0");
|
|
78
76
|
debug("contentType", contentType);
|
|
79
77
|
const renderContent = () => {
|
|
80
78
|
if (!contentType)
|
|
@@ -82,8 +80,6 @@ export function B3DynamicModal() {
|
|
|
82
80
|
switch (contentType.type) {
|
|
83
81
|
case "signInWithB3":
|
|
84
82
|
return _jsx(SignInWithB3Flow, { ...contentType });
|
|
85
|
-
case "turnkeyAuth":
|
|
86
|
-
return _jsx(TurnkeyAuthModal, { ...contentType });
|
|
87
83
|
case "requestPermissions":
|
|
88
84
|
return _jsx(RequestPermissions, { ...contentType });
|
|
89
85
|
case "manageAccount":
|
|
@@ -13,9 +13,8 @@ export interface B3ConfigContextType {
|
|
|
13
13
|
partnerId: string;
|
|
14
14
|
stripePublishableKey?: string;
|
|
15
15
|
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
16
|
-
enableTurnkey: boolean;
|
|
17
16
|
}
|
|
18
|
-
export declare function B3ConfigProvider({ children, accountOverride, environment, defaultPermissions, automaticallySetFirstEoa, theme, clientType, partnerId, stripePublishableKey, createClientReferenceId,
|
|
17
|
+
export declare function B3ConfigProvider({ children, accountOverride, environment, defaultPermissions, automaticallySetFirstEoa, theme, clientType, partnerId, stripePublishableKey, createClientReferenceId, }: {
|
|
19
18
|
children: React.ReactNode;
|
|
20
19
|
accountOverride?: Account;
|
|
21
20
|
environment?: "development" | "production";
|
|
@@ -26,6 +25,5 @@ export declare function B3ConfigProvider({ children, accountOverride, environmen
|
|
|
26
25
|
partnerId: string;
|
|
27
26
|
stripePublishableKey?: string;
|
|
28
27
|
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
29
|
-
enableTurnkey?: boolean;
|
|
30
28
|
}): import("react/jsx-runtime").JSX.Element;
|
|
31
29
|
export declare function useB3Config(): B3ConfigContextType;
|
|
@@ -10,7 +10,7 @@ const DEFAULT_PERMISSIONS = {
|
|
|
10
10
|
endDate: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365), // 1 year from now
|
|
11
11
|
};
|
|
12
12
|
const B3ConfigContext = createContext(null);
|
|
13
|
-
export function B3ConfigProvider({ children, accountOverride, environment = "development", defaultPermissions = DEFAULT_PERMISSIONS, automaticallySetFirstEoa = false, theme = "light", clientType = "rest", partnerId, stripePublishableKey, createClientReferenceId,
|
|
13
|
+
export function B3ConfigProvider({ children, accountOverride, environment = "development", defaultPermissions = DEFAULT_PERMISSIONS, automaticallySetFirstEoa = false, theme = "light", clientType = "rest", partnerId, stripePublishableKey, createClientReferenceId, }) {
|
|
14
14
|
return (_jsx(B3ConfigContext.Provider, { value: {
|
|
15
15
|
accountOverride,
|
|
16
16
|
environment,
|
|
@@ -21,7 +21,6 @@ export function B3ConfigProvider({ children, accountOverride, environment = "dev
|
|
|
21
21
|
partnerId,
|
|
22
22
|
stripePublishableKey,
|
|
23
23
|
createClientReferenceId,
|
|
24
|
-
enableTurnkey,
|
|
25
24
|
}, children: children }));
|
|
26
25
|
}
|
|
27
26
|
export function useB3Config() {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Users } from "@b3dotfun/b3-api";
|
|
2
1
|
import { CreateOnrampOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOnrampOrder";
|
|
3
2
|
import { CreateOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOrder";
|
|
4
3
|
import { PermissionsConfig } from "../../../../global-account/types/permissions";
|
|
@@ -9,7 +8,7 @@ import { ClientType } from "../../../client-manager";
|
|
|
9
8
|
/**
|
|
10
9
|
* Main B3Provider component
|
|
11
10
|
*/
|
|
12
|
-
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster: _toaster, clientType, rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors, createClientReferenceId,
|
|
11
|
+
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster: _toaster, clientType, rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors, createClientReferenceId, defaultPermissions, }: {
|
|
13
12
|
theme: "light" | "dark";
|
|
14
13
|
children: React.ReactNode;
|
|
15
14
|
accountOverride?: Account;
|
|
@@ -30,7 +29,5 @@ export declare function B3Provider({ theme, children, accountOverride, environme
|
|
|
30
29
|
connectors?: CreateConnectorFn[];
|
|
31
30
|
overrideDefaultConnectors?: boolean;
|
|
32
31
|
createClientReferenceId?: (params: CreateOrderParams | CreateOnrampOrderParams) => Promise<string>;
|
|
33
|
-
enableTurnkey?: boolean;
|
|
34
32
|
defaultPermissions?: PermissionsConfig;
|
|
35
|
-
onTurnkeyConnect?: (user: Users) => void | Promise<void>;
|
|
36
33
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -20,7 +20,7 @@ const queryClient = new QueryClient();
|
|
|
20
20
|
*/
|
|
21
21
|
export function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey,
|
|
22
22
|
// deprecated since v0.0.87
|
|
23
|
-
toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors = false, createClientReferenceId,
|
|
23
|
+
toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors = false, createClientReferenceId, defaultPermissions, }) {
|
|
24
24
|
// Initialize Google Analytics on mount
|
|
25
25
|
useEffect(() => {
|
|
26
26
|
loadGA4Script();
|
|
@@ -30,7 +30,7 @@ toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey
|
|
|
30
30
|
setClientType(clientType);
|
|
31
31
|
}, [clientType]);
|
|
32
32
|
const wagmiConfig = useMemo(() => createWagmiConfig({ partnerId, rpcUrls, connectors, overrideDefaultConnectors }), [partnerId, rpcUrls, connectors, overrideDefaultConnectors]);
|
|
33
|
-
return (_jsx(ThirdwebProvider, { children: _jsx(WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(TooltipProvider, { children: _jsx(ToastProvider, { children: _jsx(LocalSDKProvider, { onConnectCallback: onConnect, onLogoutCallback: onLogout,
|
|
33
|
+
return (_jsx(ThirdwebProvider, { children: _jsx(WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(TooltipProvider, { children: _jsx(ToastProvider, { children: _jsx(LocalSDKProvider, { onConnectCallback: onConnect, onLogoutCallback: onLogout, children: _jsxs(B3ConfigProvider, { accountOverride: accountOverride, environment: environment, automaticallySetFirstEoa: !!automaticallySetFirstEoa, theme: theme, clientType: clientType, partnerId: partnerId, stripePublishableKey: stripePublishableKey, createClientReferenceId: createClientReferenceId, defaultPermissions: defaultPermissions, children: [_jsx(ToastContextConnector, {}), _jsxs(RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, _jsx(StyleRoot, { id: "b3-root" })] }), _jsx(AuthenticationProvider, { partnerId: partnerId, automaticallySetFirstEoa: !!automaticallySetFirstEoa })] }) }) }) }) }) }) }));
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Component to connect the toast context to the global toast API
|
|
@@ -4,7 +4,7 @@ import { ClientType } from "../../../client-manager";
|
|
|
4
4
|
/**
|
|
5
5
|
* Main B3Provider component
|
|
6
6
|
*/
|
|
7
|
-
export declare function B3Provider({ theme, children, accountOverride, environment, clientType, partnerId, rpcUrls, onConnect, defaultPermissions, }: {
|
|
7
|
+
export declare function B3Provider({ theme, children, accountOverride, environment, clientType, partnerId, rpcUrls: _rpcUrls, onConnect, defaultPermissions, }: {
|
|
8
8
|
theme: "light" | "dark";
|
|
9
9
|
children: React.ReactNode;
|
|
10
10
|
accountOverride?: Account;
|
|
@@ -11,7 +11,7 @@ const queryClient = new QueryClient();
|
|
|
11
11
|
/**
|
|
12
12
|
* Main B3Provider component
|
|
13
13
|
*/
|
|
14
|
-
export function B3Provider({ theme = "light", children, accountOverride, environment, clientType = "socket", partnerId, rpcUrls, onConnect, defaultPermissions, }) {
|
|
14
|
+
export function B3Provider({ theme = "light", children, accountOverride, environment, clientType = "socket", partnerId, rpcUrls: _rpcUrls, onConnect, defaultPermissions, }) {
|
|
15
15
|
return (_jsx(ThirdwebProvider, { children: _jsx(LocalSDKProvider, { onConnectCallback: onConnect, children: _jsxs(B3ConfigProvider, { accountOverride: accountOverride, environment: environment, automaticallySetFirstEoa: false, theme: theme, clientType: clientType, partnerId: partnerId, defaultPermissions: defaultPermissions, children: [children, _jsx(AuthenticationProvider, { partnerId: partnerId, automaticallySetFirstEoa: false })] }) }) }));
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Users } from "@b3dotfun/b3-api";
|
|
2
1
|
import { Wallet } from "thirdweb/wallets";
|
|
3
2
|
/**
|
|
4
3
|
* Local SDK Context for internal SDK state (like authentication callbacks)
|
|
@@ -7,15 +6,13 @@ import { Wallet } from "thirdweb/wallets";
|
|
|
7
6
|
export interface LocalSDKContextType {
|
|
8
7
|
onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
9
8
|
onLogoutCallback?: () => void | Promise<void>;
|
|
10
|
-
onTurnkeyConnect?: (user: Users) => void | Promise<void>;
|
|
11
9
|
}
|
|
12
10
|
export declare const LocalSDKContext: import("react").Context<LocalSDKContextType>;
|
|
13
11
|
/**
|
|
14
12
|
* Local SDK Provider that wraps the app and provides internal SDK state
|
|
15
13
|
*/
|
|
16
|
-
export declare function LocalSDKProvider({ children, onConnectCallback, onLogoutCallback,
|
|
14
|
+
export declare function LocalSDKProvider({ children, onConnectCallback, onLogoutCallback, }: {
|
|
17
15
|
children: React.ReactNode;
|
|
18
16
|
onConnectCallback?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
|
|
19
17
|
onLogoutCallback?: () => void | Promise<void>;
|
|
20
|
-
onTurnkeyConnect?: (user: Users) => void | Promise<void>;
|
|
21
18
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -3,15 +3,13 @@ import { createContext } from "react";
|
|
|
3
3
|
export const LocalSDKContext = createContext({
|
|
4
4
|
onConnectCallback: undefined,
|
|
5
5
|
onLogoutCallback: undefined,
|
|
6
|
-
onTurnkeyConnect: undefined,
|
|
7
6
|
});
|
|
8
7
|
/**
|
|
9
8
|
* Local SDK Provider that wraps the app and provides internal SDK state
|
|
10
9
|
*/
|
|
11
|
-
export function LocalSDKProvider({ children, onConnectCallback, onLogoutCallback,
|
|
10
|
+
export function LocalSDKProvider({ children, onConnectCallback, onLogoutCallback, }) {
|
|
12
11
|
return (_jsx(LocalSDKContext.Provider, { value: {
|
|
13
12
|
onConnectCallback,
|
|
14
13
|
onLogoutCallback,
|
|
15
|
-
onTurnkeyConnect,
|
|
16
14
|
}, children: children }));
|
|
17
15
|
}
|
|
@@ -11,8 +11,6 @@ export function RelayKitProviderWrapper({ children, simDuneApiKey, }) {
|
|
|
11
11
|
};
|
|
12
12
|
fetchChains();
|
|
13
13
|
}, []);
|
|
14
|
-
const isTurnkeyPrimary = process.env.NEXT_PUBLIC_TURNKEY_PRIMARY === "true";
|
|
15
|
-
const appName = isTurnkeyPrimary ? "Smart Wallet" : "AnySpend";
|
|
16
14
|
return (_jsx(RelayKitProvider, { options: {
|
|
17
15
|
baseApiUrl: MAINNET_RELAY_API,
|
|
18
16
|
source: "anyspend",
|
|
@@ -22,7 +20,7 @@ export function RelayKitProviderWrapper({ children, simDuneApiKey, }) {
|
|
|
22
20
|
},
|
|
23
21
|
chains: relayChains,
|
|
24
22
|
privateChainIds: undefined,
|
|
25
|
-
appName,
|
|
23
|
+
appName: "AnySpend",
|
|
26
24
|
useGasFeeEstimations: true,
|
|
27
25
|
}, children: _jsx(_Fragment, { children: children }) }));
|
|
28
26
|
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useModalStore } from "../../../../global-account/react/index.js";
|
|
2
|
+
import { useAuthentication, useModalStore } from "../../../../global-account/react/index.js";
|
|
3
3
|
import { client } from "../../../../shared/utils/thirdweb.js";
|
|
4
|
+
import { Loader2 } from "lucide-react";
|
|
5
|
+
import { useState } from "react";
|
|
4
6
|
import { useProfiles } from "thirdweb/react";
|
|
7
|
+
import SignOutIcon from "../icons/SignOutIcon.js";
|
|
5
8
|
import ModalHeader from "../ModalHeader/ModalHeader.js";
|
|
6
9
|
import SettingsMenuItem from "./SettingsMenuItem.js";
|
|
7
10
|
import SettingsProfileCard from "./SettingsProfileCard.js";
|
|
8
11
|
const SettingsContent = ({ partnerId, onLogout, chain, }) => {
|
|
9
12
|
const setB3ModalContentType = useModalStore(state => state.setB3ModalContentType);
|
|
10
13
|
const setB3ModalOpen = useModalStore(state => state.setB3ModalOpen);
|
|
14
|
+
const { logout } = useAuthentication(partnerId);
|
|
15
|
+
const [logoutLoading, setLogoutLoading] = useState(false);
|
|
11
16
|
const { data: profilesRaw = [] } = useProfiles({ client });
|
|
12
17
|
const profiles = profilesRaw.filter((profile) => !["custom_auth_endpoint"].includes(profile.type));
|
|
13
18
|
const handleNavigate = (type) => {
|
|
@@ -50,6 +55,15 @@ const SettingsContent = ({ partnerId, onLogout, chain, }) => {
|
|
|
50
55
|
}
|
|
51
56
|
setB3ModalOpen(true);
|
|
52
57
|
};
|
|
53
|
-
|
|
58
|
+
const onLogoutEnhanced = async () => {
|
|
59
|
+
setLogoutLoading(true);
|
|
60
|
+
await logout();
|
|
61
|
+
onLogout?.();
|
|
62
|
+
setB3ModalOpen(false);
|
|
63
|
+
setLogoutLoading(false);
|
|
64
|
+
};
|
|
65
|
+
return (_jsxs("div", { className: "flex h-[470px] flex-col", children: [_jsx(ModalHeader, { showBackButton: false, showCloseButton: false, title: "Settings" }), _jsx("div", { className: "p-5", children: _jsx("div", { className: "b3-modal-settings-profile-card dark:border-b3-line dark:bg-b3-background flex items-center rounded-xl border border-[#e4e4e7] bg-[#f4f4f5] p-4", children: _jsx(SettingsProfileCard, {}) }) }), _jsxs("div", { className: "space-y-3 px-5", children: [_jsx(SettingsMenuItem, { icon: _jsx("svg", { width: "40", height: "40", viewBox: "0 0 40 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { d: "M0 12C0 5.37258 5.37258 0 12 0H28C34.6274 0 40 5.37258 40 12V28C40 34.6274 34.6274 40 28 40H12C5.37258 40 0 34.6274 0 28V12Z", fill: "#F4F4F5" }) }), title: "Linked Accounts", subtitle: `${profiles.length} connected account${profiles.length > 1 ? "s" : ""}`, onClick: () => handleNavigate("linkAccount") }), _jsx(SettingsMenuItem, { icon: _jsx("svg", { width: "40", height: "40", viewBox: "0 0 40 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { d: "M0 12C0 5.37258 5.37258 0 12 0H28C34.6274 0 40 5.37258 40 12V28C40 34.6274 34.6274 40 28 40H12C5.37258 40 0 34.6274 0 28V12Z", fill: "#F4F4F5" }) }), title: "Notifications", subtitle: "Manage your notifications", onClick: () => handleNavigate("notifications") })] }), _jsx("div", { className: "mt-auto px-5 pb-5", children: _jsxs("button", { className: "b3-modal-sign-out-button border-b3-line hover:bg-b3-line bg-b3-background dark:bg-b3-background dark:border-b3-line dark:hover:bg-b3-line/80 flex w-full items-center justify-center gap-1.5 rounded-xl border border-solid p-3 transition-colors", onClick: onLogoutEnhanced, disabled: logoutLoading, style: {
|
|
66
|
+
boxShadow: "inset 0px 0px 0px 1px rgba(10,13,18,0.18), inset 0px -2px 0px 0px rgba(10,13,18,0.05)",
|
|
67
|
+
}, children: [logoutLoading ? (_jsx(Loader2, { className: "text-b3-grey animate-spin", size: 20 })) : (_jsx(SignOutIcon, { size: 20, className: "text-b3-grey", color: "currentColor" })), _jsx("p", { className: "text-b3-grey dark:text-b3-foreground-muted font-neue-montreal-semibold text-base", children: "Sign out" })] }) })] }));
|
|
54
68
|
};
|
|
55
69
|
export default SettingsContent;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Loading, useAuthentication, useAuthStore, useB3Config, useGetAllTWSigners, useModalStore, } from "../../../../global-account/react/index.js";
|
|
3
3
|
import { debugB3React } from "../../../../shared/utils/debug.js";
|
|
4
|
-
import { useCallback,
|
|
4
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
5
5
|
import { useActiveAccount } from "thirdweb/react";
|
|
6
|
-
import { LocalSDKContext } from "../B3Provider/LocalSDKProvider.js";
|
|
7
|
-
import { TurnkeyAuthModal } from "../TurnkeyAuthModal.js";
|
|
8
6
|
import { SignInWithB3Privy } from "./SignInWithB3Privy.js";
|
|
9
7
|
import { LoginStep, LoginStepContainer } from "./steps/LoginStep.js";
|
|
10
8
|
import { LoginStepCustom } from "./steps/LoginStepCustom.js";
|
|
@@ -15,9 +13,8 @@ const MAX_REFETCH_ATTEMPTS = 20;
|
|
|
15
13
|
* Handles different login providers, authentication steps, and session key management
|
|
16
14
|
*/
|
|
17
15
|
export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onError, chain, sessionKeyAddress, partnerId, closeAfterLogin = false, source = "signInWithB3Button", signersEnabled = false, }) {
|
|
18
|
-
const { automaticallySetFirstEoa
|
|
19
|
-
const { user,
|
|
20
|
-
const { onTurnkeyConnect } = useContext(LocalSDKContext);
|
|
16
|
+
const { automaticallySetFirstEoa } = useB3Config();
|
|
17
|
+
const { user, logout } = useAuthentication(partnerId);
|
|
21
18
|
// FIXME Logout before login to ensure a clean state
|
|
22
19
|
const hasLoggedOutRef = useRef(false);
|
|
23
20
|
useEffect(() => {
|
|
@@ -35,13 +32,10 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
35
32
|
const account = useActiveAccount();
|
|
36
33
|
const isAuthenticating = useAuthStore(state => state.isAuthenticating);
|
|
37
34
|
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
38
|
-
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
39
35
|
const isConnected = useAuthStore(state => state.isConnected);
|
|
40
|
-
const setIsConnected = useAuthStore(state => state.setIsConnected);
|
|
41
36
|
const setJustCompletedLogin = useAuthStore(state => state.setJustCompletedLogin);
|
|
42
37
|
const [refetchCount, setRefetchCount] = useState(0);
|
|
43
38
|
const [refetchError, setRefetchError] = useState(null);
|
|
44
|
-
const [turnkeyAuthCompleted, setTurnkeyAuthCompleted] = useState(false);
|
|
45
39
|
const { data: signers, refetch: refetchSigners, isFetching: isFetchingSigners, } = useGetAllTWSigners({
|
|
46
40
|
chain,
|
|
47
41
|
accountAddress: account?.address,
|
|
@@ -74,8 +68,8 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
74
68
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
75
69
|
}, [refetchCount, refetchSigners, onError, refetchQueued]);
|
|
76
70
|
// Extract the completion flow logic to be reused
|
|
77
|
-
const
|
|
78
|
-
debug("Running post-
|
|
71
|
+
const handlePostAuthFlow = useCallback(() => {
|
|
72
|
+
debug("Running post-authentication flow logic");
|
|
79
73
|
// Check if we already have a signer for this partner
|
|
80
74
|
const hasExistingSigner = signers?.some(signer => signer.partner.id === partnerId);
|
|
81
75
|
if (hasExistingSigner) {
|
|
@@ -132,56 +126,6 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
132
126
|
handleRefetchSigners,
|
|
133
127
|
setSessionKeyAdded,
|
|
134
128
|
]);
|
|
135
|
-
// Define handleTurnkeySuccess before the useEffect that uses it
|
|
136
|
-
const handleTurnkeySuccess = useCallback(async (user) => {
|
|
137
|
-
debug("Turnkey authentication successful - setting completed flag", { user, onTurnkeyConnect });
|
|
138
|
-
// Call the onTurnkeyConnect callback
|
|
139
|
-
onTurnkeyConnect?.(user);
|
|
140
|
-
// Set completed flag FIRST before any async operations
|
|
141
|
-
setTurnkeyAuthCompleted(true);
|
|
142
|
-
// Refetch user to update the user state with Turnkey ID
|
|
143
|
-
debug("Refetching user after Turnkey success...");
|
|
144
|
-
// TODO: See why sometimes this fails with "No wallet found during auto-connect"
|
|
145
|
-
await refetchUser();
|
|
146
|
-
debug("User refetched successfully");
|
|
147
|
-
// Set authentication and connection state so UI updates properly
|
|
148
|
-
setIsAuthenticated(true);
|
|
149
|
-
setIsConnected(true);
|
|
150
|
-
setJustCompletedLogin(true);
|
|
151
|
-
// After user data is refreshed, close Turnkey modal and go back to sign-in flow
|
|
152
|
-
debug("Switching back to signInWithB3 modal");
|
|
153
|
-
setB3ModalContentType({
|
|
154
|
-
type: "signInWithB3",
|
|
155
|
-
strategies,
|
|
156
|
-
onLoginSuccess,
|
|
157
|
-
onSessionKeySuccess,
|
|
158
|
-
onError,
|
|
159
|
-
chain,
|
|
160
|
-
sessionKeyAddress,
|
|
161
|
-
partnerId,
|
|
162
|
-
closeAfterLogin,
|
|
163
|
-
source,
|
|
164
|
-
signersEnabled,
|
|
165
|
-
});
|
|
166
|
-
// The useEffect will re-run with updated user data to complete the sign-in process
|
|
167
|
-
}, [
|
|
168
|
-
onTurnkeyConnect,
|
|
169
|
-
refetchUser,
|
|
170
|
-
strategies,
|
|
171
|
-
onLoginSuccess,
|
|
172
|
-
onSessionKeySuccess,
|
|
173
|
-
onError,
|
|
174
|
-
chain,
|
|
175
|
-
sessionKeyAddress,
|
|
176
|
-
partnerId,
|
|
177
|
-
closeAfterLogin,
|
|
178
|
-
source,
|
|
179
|
-
signersEnabled,
|
|
180
|
-
setB3ModalContentType,
|
|
181
|
-
setIsAuthenticated,
|
|
182
|
-
setIsConnected,
|
|
183
|
-
setJustCompletedLogin,
|
|
184
|
-
]);
|
|
185
129
|
// Handle post-login flow after signers are loaded
|
|
186
130
|
useEffect(() => {
|
|
187
131
|
debug("@@SignInWithB3Flow:useEffect", {
|
|
@@ -194,49 +138,11 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
194
138
|
});
|
|
195
139
|
if (isConnected && isAuthenticated && user) {
|
|
196
140
|
// Mark that login just completed BEFORE opening manage account or closing modal
|
|
197
|
-
// This allows Turnkey modal to show (if enableTurnkey is true)
|
|
198
141
|
if (closeAfterLogin) {
|
|
199
142
|
setJustCompletedLogin(true);
|
|
200
143
|
}
|
|
201
|
-
//
|
|
202
|
-
|
|
203
|
-
// - enableTurnkey={true} is set on B3Provider
|
|
204
|
-
// - NEXT_PUBLIC_TURNKEY_PRIMARY is NOT set to true (otherwise Turnkey shows as primary)
|
|
205
|
-
// - User just logged in AND hasn't completed Turnkey auth in this session
|
|
206
|
-
// For new users (!turnkeyId): Show email form
|
|
207
|
-
// For returning users (turnkeyId && turnkeyEmail): Auto-skip to OTP
|
|
208
|
-
// Also check that we're not already showing the Turnkey modal
|
|
209
|
-
const hasTurnkeyId = user?.partnerIds?.turnkeyId;
|
|
210
|
-
const hasTurnkeyEmail = !!user?.email;
|
|
211
|
-
const isTurnkeyModalCurrentlyOpen = contentType?.type === "turnkeyAuth";
|
|
212
|
-
const isTurnkeyPrimary = process.env.NEXT_PUBLIC_TURNKEY_PRIMARY === "true";
|
|
213
|
-
const shouldShowTurnkeyModal = enableTurnkey &&
|
|
214
|
-
!isTurnkeyPrimary &&
|
|
215
|
-
user &&
|
|
216
|
-
!turnkeyAuthCompleted &&
|
|
217
|
-
!isTurnkeyModalCurrentlyOpen &&
|
|
218
|
-
(!hasTurnkeyId || (hasTurnkeyId && hasTurnkeyEmail));
|
|
219
|
-
if (shouldShowTurnkeyModal) {
|
|
220
|
-
// Extract email from user object - check partnerIds.turnkeyEmail first, then twProfiles, then user.email
|
|
221
|
-
const email = user?.email || user?.twProfiles?.find((profile) => profile.details?.email)?.details?.email;
|
|
222
|
-
// Open Turnkey modal through the modal store
|
|
223
|
-
setB3ModalContentType({
|
|
224
|
-
type: "turnkeyAuth",
|
|
225
|
-
onSuccess: handleTurnkeySuccess,
|
|
226
|
-
onClose: () => {
|
|
227
|
-
// After closing Turnkey modal, continue with the rest of the flow
|
|
228
|
-
setTurnkeyAuthCompleted(true);
|
|
229
|
-
debug("Turnkey modal closed, running post-Turnkey flow");
|
|
230
|
-
handlePostTurnkeyFlow();
|
|
231
|
-
},
|
|
232
|
-
initialEmail: email,
|
|
233
|
-
skipToOtp: !!(hasTurnkeyId && hasTurnkeyEmail),
|
|
234
|
-
closable: false, // Turnkey modal cannot be closed until auth is complete
|
|
235
|
-
});
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
// Normal flow continues after Turnkey auth is complete (or if not needed)
|
|
239
|
-
handlePostTurnkeyFlow();
|
|
144
|
+
// Normal flow continues
|
|
145
|
+
handlePostAuthFlow();
|
|
240
146
|
}
|
|
241
147
|
},
|
|
242
148
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -257,11 +163,8 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
257
163
|
isAuthenticated,
|
|
258
164
|
isOpen,
|
|
259
165
|
user,
|
|
260
|
-
enableTurnkey,
|
|
261
|
-
turnkeyAuthCompleted,
|
|
262
|
-
// handleTurnkeySuccess, // This is causing infinite loops
|
|
263
166
|
contentType,
|
|
264
|
-
|
|
167
|
+
handlePostAuthFlow,
|
|
265
168
|
]);
|
|
266
169
|
debug("render", {
|
|
267
170
|
step,
|
|
@@ -325,58 +228,22 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
325
228
|
content = (_jsx(LoginStepContainer, { partnerId: partnerId, children: _jsx("div", { className: "p-4 text-center text-red-500", children: refetchError }) }));
|
|
326
229
|
}
|
|
327
230
|
else if (step === "login") {
|
|
328
|
-
//
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const shouldShowTurnkeyFirst = isTurnkeyPrimary && !turnkeyAuthCompleted;
|
|
332
|
-
if (shouldShowTurnkeyFirst) {
|
|
333
|
-
// Don't show loading spinner for Turnkey - let the modal handle its own loading state
|
|
334
|
-
// This prevents the infinite loop where isAuthenticating causes the modal to be replaced
|
|
335
|
-
debug("Showing Turnkey as primary authentication option", {
|
|
336
|
-
isTurnkeyPrimary,
|
|
337
|
-
turnkeyAuthCompleted,
|
|
338
|
-
isAuthenticated,
|
|
339
|
-
});
|
|
340
|
-
// Show Turnkey authentication as primary option
|
|
341
|
-
content = (_jsx(LoginStepContainer, { partnerId: partnerId, children: _jsx(TurnkeyAuthModal, { onSuccess: async (authenticatedUser) => {
|
|
342
|
-
debug("Turnkey authentication successful in primary flow", { authenticatedUser });
|
|
343
|
-
setTurnkeyAuthCompleted(true);
|
|
344
|
-
// User is now authenticated via Turnkey
|
|
345
|
-
// Set both isAuthenticated and isConnected to true so UI updates properly
|
|
346
|
-
// Wallet connection is optional and can happen later for signing transactions
|
|
347
|
-
setIsAuthenticated(true);
|
|
348
|
-
setIsConnected(true);
|
|
349
|
-
setJustCompletedLogin(true);
|
|
350
|
-
// Call the login success callback
|
|
351
|
-
onLoginSuccess?.({});
|
|
352
|
-
// Call the onTurnkeyConnect callback
|
|
353
|
-
onTurnkeyConnect?.(authenticatedUser);
|
|
354
|
-
// After Turnkey auth, refetch user to get the full user object
|
|
355
|
-
// TODO: See why sometimes this fails with "No wallet found during auto-connect"
|
|
356
|
-
await refetchUser();
|
|
357
|
-
}, onClose: () => {
|
|
358
|
-
// If user closes Turnkey modal, they can still use wallet connection as fallback
|
|
359
|
-
setTurnkeyAuthCompleted(true);
|
|
360
|
-
}, initialEmail: "", skipToOtp: false }) }));
|
|
231
|
+
// Show loading spinner
|
|
232
|
+
if (isAuthenticating || (isFetchingSigners && step === "login") || source === "requestPermissions") {
|
|
233
|
+
content = (_jsx(LoginStepContainer, { partnerId: partnerId, children: _jsx("div", { className: "my-8 flex min-h-[350px] items-center justify-center", children: _jsx(Loading, { variant: "white", size: "lg" }) }) }));
|
|
361
234
|
}
|
|
362
235
|
else {
|
|
363
|
-
//
|
|
364
|
-
if (
|
|
365
|
-
content =
|
|
236
|
+
// Custom strategy
|
|
237
|
+
if (strategies?.[0] === "privy") {
|
|
238
|
+
content = _jsx(SignInWithB3Privy, { onSuccess: handleLoginSuccess, chain: chain });
|
|
239
|
+
}
|
|
240
|
+
else if (strategies) {
|
|
241
|
+
// Strategies are explicitly provided
|
|
242
|
+
content = (_jsx(LoginStepCustom, { strategies: strategies, chain: chain, onSuccess: handleLoginSuccess, onError: onError, automaticallySetFirstEoa: !!automaticallySetFirstEoa }));
|
|
366
243
|
}
|
|
367
244
|
else {
|
|
368
|
-
//
|
|
369
|
-
|
|
370
|
-
content = _jsx(SignInWithB3Privy, { onSuccess: handleLoginSuccess, chain: chain });
|
|
371
|
-
}
|
|
372
|
-
else if (strategies) {
|
|
373
|
-
// Strategies are explicitly provided
|
|
374
|
-
content = (_jsx(LoginStepCustom, { strategies: strategies, chain: chain, onSuccess: handleLoginSuccess, onError: onError, automaticallySetFirstEoa: !!automaticallySetFirstEoa }));
|
|
375
|
-
}
|
|
376
|
-
else {
|
|
377
|
-
// Default to handle all strategies we support
|
|
378
|
-
content = _jsx(LoginStep, { chain: chain, onSuccess: handleLoginSuccess, onError: onError });
|
|
379
|
-
}
|
|
245
|
+
// Default to handle all strategies we support
|
|
246
|
+
content = _jsx(LoginStep, { chain: chain, onSuccess: handleLoginSuccess, onError: onError });
|
|
380
247
|
}
|
|
381
248
|
}
|
|
382
249
|
}
|
|
@@ -13,7 +13,6 @@ export { SignInWithB3Flow } from "./SignInWithB3/SignInWithB3Flow";
|
|
|
13
13
|
export { SignInWithB3Privy } from "./SignInWithB3/SignInWithB3Privy";
|
|
14
14
|
export { LoginStepContainer } from "./SignInWithB3/steps/LoginStep";
|
|
15
15
|
export { getConnectOptionsFromStrategy, isWalletType, type AllowedStrategy } from "./SignInWithB3/utils/signInUtils";
|
|
16
|
-
export { TurnkeyAuthModal } from "./TurnkeyAuthModal";
|
|
17
16
|
export { ManageAccount } from "./ManageAccount/ManageAccount";
|
|
18
17
|
export { Deposit } from "./Deposit/Deposit";
|
|
19
18
|
export { Send } from "./Send/Send";
|
|
@@ -16,8 +16,6 @@ export { SignInWithB3Flow } from "./SignInWithB3/SignInWithB3Flow.js";
|
|
|
16
16
|
export { SignInWithB3Privy } from "./SignInWithB3/SignInWithB3Privy.js";
|
|
17
17
|
export { LoginStepContainer } from "./SignInWithB3/steps/LoginStep.js";
|
|
18
18
|
export { getConnectOptionsFromStrategy, isWalletType } from "./SignInWithB3/utils/signInUtils.js";
|
|
19
|
-
// Turnkey Components
|
|
20
|
-
export { TurnkeyAuthModal } from "./TurnkeyAuthModal.js";
|
|
21
19
|
// ManageAccount Components
|
|
22
20
|
export { ManageAccount } from "./ManageAccount/ManageAccount.js";
|
|
23
21
|
// Deposit Components
|
|
@@ -41,7 +41,6 @@ export { useTokenFromUrl } from "./useTokenFromUrl";
|
|
|
41
41
|
export { useTokenPrice } from "./useTokenPrice";
|
|
42
42
|
export { useTokenPriceWithFallback } from "./useTokenPriceWithFallback";
|
|
43
43
|
export { useTokensFromAddress } from "./useTokensFromAddress";
|
|
44
|
-
export { useTurnkeyAuth } from "./useTurnkeyAuth";
|
|
45
44
|
export { useUnifiedChainSwitchAndExecute } from "./useUnifiedChainSwitchAndExecute";
|
|
46
45
|
export { useURLParams } from "./useURLParams";
|
|
47
46
|
export { useUser } from "./useUser";
|
|
@@ -41,7 +41,6 @@ export { useTokenFromUrl } from "./useTokenFromUrl.js";
|
|
|
41
41
|
export { useTokenPrice } from "./useTokenPrice.js";
|
|
42
42
|
export { useTokenPriceWithFallback } from "./useTokenPriceWithFallback.js";
|
|
43
43
|
export { useTokensFromAddress } from "./useTokensFromAddress.js";
|
|
44
|
-
export { useTurnkeyAuth } from "./useTurnkeyAuth.js";
|
|
45
44
|
export { useUnifiedChainSwitchAndExecute } from "./useUnifiedChainSwitchAndExecute.js";
|
|
46
45
|
export { useURLParams } from "./useURLParams.js";
|
|
47
46
|
export { useUser } from "./useUser.js";
|