@b3dotfun/sdk 0.0.83-alpha.2 → 0.0.83-alpha.4
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/AnySpendCustom.js +3 -2
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +2 -4
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethodDisplay.js +28 -0
- package/dist/cjs/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
- package/dist/cjs/anyspend/react/hooks/useConnectedUserProfile.js +5 -8
- package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
- package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.js +2 -12
- package/dist/cjs/anyspend/react/hooks/useHyperliquidTransfer.js +1 -1
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +3 -2
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +4 -6
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethodDisplay.js +25 -0
- package/dist/esm/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
- package/dist/esm/anyspend/react/hooks/useConnectedUserProfile.js +6 -9
- package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
- package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.js +2 -12
- package/dist/esm/anyspend/react/hooks/useHyperliquidTransfer.js +1 -1
- package/dist/types/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
- package/dist/types/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
- package/dist/types/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpendCustom.tsx +7 -23
- package/src/anyspend/react/components/common/CryptoPaySection.tsx +7 -30
- package/src/anyspend/react/components/common/CryptoPaymentMethodDisplay.tsx +64 -0
- package/src/anyspend/react/hooks/useConnectedUserProfile.ts +7 -10
- package/src/anyspend/react/hooks/useConnectedWalletDisplay.ts +2 -15
- package/src/anyspend/react/hooks/useHyperliquidTransfer.ts +1 -1
|
@@ -56,6 +56,7 @@ const useCryptoPaymentMethodState_1 = require("../hooks/useCryptoPaymentMethodSt
|
|
|
56
56
|
const useRecipientAddressState_1 = require("../hooks/useRecipientAddressState");
|
|
57
57
|
const AnySpendFingerprintWrapper_1 = require("./AnySpendFingerprintWrapper");
|
|
58
58
|
const CryptoPaymentMethod_1 = require("./common/CryptoPaymentMethod");
|
|
59
|
+
const CryptoPaymentMethodDisplay_1 = require("./common/CryptoPaymentMethodDisplay");
|
|
59
60
|
const FeeBreakDown_1 = require("./common/FeeBreakDown");
|
|
60
61
|
const FiatPaymentMethod_1 = require("./common/FiatPaymentMethod");
|
|
61
62
|
const OrderDetails_1 = require("./common/OrderDetails");
|
|
@@ -337,7 +338,7 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
|
|
|
337
338
|
},
|
|
338
339
|
});
|
|
339
340
|
const isCreatingOrder = isCreatingRegularOrder || isCreatingOnrampOrder;
|
|
340
|
-
const { address: connectedAddress, name: connectedName } = (0, react_1.useConnectedUserProfile)();
|
|
341
|
+
const { address: connectedAddress, name: connectedName } = (0, react_1.useConnectedUserProfile)(effectiveCryptoPaymentMethod);
|
|
341
342
|
const recipientProfile = (0, react_2.useProfile)({ address: recipientAddress });
|
|
342
343
|
const recipientName = recipientProfile.data?.name;
|
|
343
344
|
const handleCreateOrder = async (recipientAddress, onramp) => {
|
|
@@ -559,7 +560,7 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
|
|
|
559
560
|
opacity: hasMounted ? 1 : 0,
|
|
560
561
|
y: hasMounted ? 0 : 20,
|
|
561
562
|
filter: hasMounted ? "blur(0px)" : "blur(10px)",
|
|
562
|
-
}, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, className: "relative flex w-full items-center justify-between", children: [(0, jsx_runtime_1.jsx)("div", { className: "text-as-tertiarry flex h-7 items-center text-sm", children: "Pay" }), (0, jsx_runtime_1.jsx)("button", { className: "text-as-tertiarry flex flex-wrap items-center justify-end gap-2 text-sm transition-colors hover:text-blue-700", onClick: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), children:
|
|
563
|
+
}, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, className: "relative flex w-full items-center justify-between", children: [(0, jsx_runtime_1.jsx)("div", { className: "text-as-tertiarry flex h-7 items-center text-sm", children: "Pay" }), (0, jsx_runtime_1.jsx)("button", { className: "text-as-tertiarry flex flex-wrap items-center justify-end gap-2 text-sm transition-colors hover:text-blue-700", onClick: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), children: (0, jsx_runtime_1.jsx)(CryptoPaymentMethodDisplay_1.CryptoPaymentMethodDisplay, { paymentMethod: effectiveCryptoPaymentMethod, connectedAddress: connectedAddress, connectedName: connectedName }) })] }), (0, jsx_runtime_1.jsx)("div", { className: "divider w-full" }), recipientSection, (0, jsx_runtime_1.jsx)("div", { className: "divider w-full" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col gap-4", children: [(0, jsx_runtime_1.jsxs)(react_4.motion.div, { initial: false, animate: {
|
|
563
564
|
opacity: hasMounted ? 1 : 0,
|
|
564
565
|
y: hasMounted ? 0 : 20,
|
|
565
566
|
filter: hasMounted ? "blur(0px)" : "blur(10px)",
|
|
@@ -3,14 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CryptoPaySection = CryptoPaySection;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("../../../../global-account/react");
|
|
6
|
-
const utils_1 = require("../../../../shared/utils");
|
|
7
|
-
const formatAddress_1 = require("../../../../shared/utils/formatAddress");
|
|
8
6
|
const number_1 = require("../../../../shared/utils/number");
|
|
9
7
|
const lucide_react_1 = require("lucide-react");
|
|
10
8
|
const react_2 = require("motion/react");
|
|
11
9
|
const react_3 = require("react");
|
|
12
10
|
const useConnectedWalletDisplay_1 = require("../../hooks/useConnectedWalletDisplay");
|
|
13
|
-
const
|
|
11
|
+
const CryptoPaymentMethodDisplay_1 = require("./CryptoPaymentMethodDisplay");
|
|
14
12
|
const OrderTokenAmount_1 = require("./OrderTokenAmount");
|
|
15
13
|
const TokenBalance_1 = require("./TokenBalance");
|
|
16
14
|
function CryptoPaySection({ selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, isSrcInputDirty, setIsSrcInputDirty, selectedCryptoPaymentMethod, onSelectCryptoPaymentMethod, anyspendQuote, onTokenSelect, onShowFeeDetail, }) {
|
|
@@ -43,7 +41,7 @@ function CryptoPaySection({ selectedSrcChainId, setSelectedSrcChainId, selectedS
|
|
|
43
41
|
(0, react_3.useEffect)(() => {
|
|
44
42
|
appliedSrcMetadataRef.current = false;
|
|
45
43
|
}, [selectedSrcToken.address, selectedSrcToken.chainId]);
|
|
46
|
-
return ((0, jsx_runtime_1.jsxs)(react_2.motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, className: "pay-section bg-as-surface-secondary border-as-border-secondary relative flex w-full flex-col gap-2 rounded-2xl border p-4 sm:p-6", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsxs)("div", { className: "text-as-primary/50 flex h-7 items-center gap-1.5 text-sm", children: ["Pay", !isSrcInputDirty && anyspendQuote?.data?.fee && onShowFeeDetail && ((0, jsx_runtime_1.jsx)("button", { onClick: onShowFeeDetail, className: "text-as-primary/40 hover:text-as-primary/60 transition-colors", children: (0, jsx_runtime_1.jsx)(lucide_react_1.Info, { className: "h-4 w-4" }) }))] }), (0, jsx_runtime_1.jsx)("button", { className: "text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors focus:!outline-none", onClick: onSelectCryptoPaymentMethod, children:
|
|
44
|
+
return ((0, jsx_runtime_1.jsxs)(react_2.motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, className: "pay-section bg-as-surface-secondary border-as-border-secondary relative flex w-full flex-col gap-2 rounded-2xl border p-4 sm:p-6", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsxs)("div", { className: "text-as-primary/50 flex h-7 items-center gap-1.5 text-sm", children: ["Pay", !isSrcInputDirty && anyspendQuote?.data?.fee && onShowFeeDetail && ((0, jsx_runtime_1.jsx)("button", { onClick: onShowFeeDetail, className: "text-as-primary/40 hover:text-as-primary/60 transition-colors", children: (0, jsx_runtime_1.jsx)(lucide_react_1.Info, { className: "h-4 w-4" }) }))] }), (0, jsx_runtime_1.jsx)("button", { className: "text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors focus:!outline-none", onClick: onSelectCryptoPaymentMethod, children: (0, jsx_runtime_1.jsx)(CryptoPaymentMethodDisplay_1.CryptoPaymentMethodDisplay, { paymentMethod: selectedCryptoPaymentMethod, connectedAddress: walletAddress, connectedName: connectedName }) })] }), (0, jsx_runtime_1.jsx)(OrderTokenAmount_1.OrderTokenAmount, { address: walletAddress, walletAddress: walletAddress, context: "from", inputValue: srcAmount, onChangeInput: value => {
|
|
47
45
|
setIsSrcInputDirty(true);
|
|
48
46
|
setSrcAmount(value);
|
|
49
47
|
}, chainId: selectedSrcChainId, setChainId: setSelectedSrcChainId, token: selectedSrcToken, setToken: setSelectedSrcToken, onTokenSelect: onTokenSelect }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("div", { className: "text-as-primary/50 flex h-5 items-center text-sm", children: (0, number_1.formatDisplayNumber)(anyspendQuote?.data?.currencyIn?.amountUsd, {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CryptoPaymentMethodType } from "./CryptoPaymentMethod";
|
|
2
|
+
interface CryptoPaymentMethodDisplayProps {
|
|
3
|
+
paymentMethod: CryptoPaymentMethodType;
|
|
4
|
+
connectedAddress?: string | null;
|
|
5
|
+
connectedName?: string | null;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Displays the selected crypto payment method with appropriate label
|
|
9
|
+
* - CONNECT_WALLET: Shows wallet address/name or "Connect wallet"
|
|
10
|
+
* - GLOBAL_WALLET: Shows "Global Account"
|
|
11
|
+
* - TRANSFER_CRYPTO: Shows "Transfer crypto"
|
|
12
|
+
* - NONE: Shows "Select payment method"
|
|
13
|
+
*/
|
|
14
|
+
export declare function CryptoPaymentMethodDisplay({ paymentMethod, connectedAddress, connectedName, }: CryptoPaymentMethodDisplayProps): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CryptoPaymentMethodDisplay = CryptoPaymentMethodDisplay;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const utils_1 = require("../../../../shared/utils");
|
|
6
|
+
const formatAddress_1 = require("../../../../shared/utils/formatAddress");
|
|
7
|
+
const lucide_react_1 = require("lucide-react");
|
|
8
|
+
const CryptoPaymentMethod_1 = require("./CryptoPaymentMethod");
|
|
9
|
+
/**
|
|
10
|
+
* Displays the selected crypto payment method with appropriate label
|
|
11
|
+
* - CONNECT_WALLET: Shows wallet address/name or "Connect wallet"
|
|
12
|
+
* - GLOBAL_WALLET: Shows "Global Account"
|
|
13
|
+
* - TRANSFER_CRYPTO: Shows "Transfer crypto"
|
|
14
|
+
* - NONE: Shows "Select payment method"
|
|
15
|
+
*/
|
|
16
|
+
function CryptoPaymentMethodDisplay({ paymentMethod, connectedAddress, connectedName, }) {
|
|
17
|
+
if (paymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
18
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [connectedAddress ? ((0, jsx_runtime_1.jsx)("span", { className: "text-as-tertiarry whitespace-nowrap", children: connectedName ? (0, utils_1.formatUsername)(connectedName) : (0, formatAddress_1.shortenAddress)(connectedAddress) })) : ((0, jsx_runtime_1.jsx)("span", { className: "whitespace-nowrap", children: "Connect wallet" })), (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "h-4 w-4 shrink-0" })] }));
|
|
19
|
+
}
|
|
20
|
+
if (paymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.GLOBAL_WALLET) {
|
|
21
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { className: "whitespace-nowrap", children: "Global Account" }), (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "h-4 w-4 shrink-0" })] }));
|
|
22
|
+
}
|
|
23
|
+
if (paymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.TRANSFER_CRYPTO) {
|
|
24
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { className: "whitespace-nowrap", children: "Transfer crypto" }), (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "h-4 w-4 shrink-0" })] }));
|
|
25
|
+
}
|
|
26
|
+
// NONE or any other case
|
|
27
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { className: "whitespace-nowrap", children: "Select payment method" }), (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "h-4 w-4 shrink-0" })] }));
|
|
28
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod";
|
|
1
2
|
/**
|
|
2
3
|
* Hook that provides connected user's address, profile, and cleaned display name
|
|
3
4
|
* Combines logic for getting connected address from either global account or thirdweb wallets
|
|
4
5
|
*/
|
|
5
|
-
export declare function useConnectedUserProfile(): {
|
|
6
|
+
export declare function useConnectedUserProfile(selectedCryptoPaymentMethod?: CryptoPaymentMethodType): {
|
|
6
7
|
address: string | undefined;
|
|
7
8
|
profile: import("@tanstack/react-query").UseQueryResult<import("../../../global-account/react").CombinedProfile, Error>;
|
|
8
9
|
name: string | null | undefined;
|
|
@@ -2,20 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useConnectedUserProfile = useConnectedUserProfile;
|
|
4
4
|
const react_1 = require("../../../global-account/react");
|
|
5
|
-
const
|
|
5
|
+
const useConnectedWalletDisplay_1 = require("./useConnectedWalletDisplay");
|
|
6
6
|
/**
|
|
7
7
|
* Hook that provides connected user's address, profile, and cleaned display name
|
|
8
8
|
* Combines logic for getting connected address from either global account or thirdweb wallets
|
|
9
9
|
*/
|
|
10
|
-
function useConnectedUserProfile() {
|
|
11
|
-
const {
|
|
12
|
-
const connectedWallets = (0, react_2.useConnectedWallets)();
|
|
13
|
-
// Get connected address from global account or first connected wallet
|
|
14
|
-
const connectedAddress = globalAddress || connectedWallets?.[0]?.getAccount()?.address;
|
|
10
|
+
function useConnectedUserProfile(selectedCryptoPaymentMethod) {
|
|
11
|
+
const { walletAddress } = (0, useConnectedWalletDisplay_1.useConnectedWalletDisplay)(selectedCryptoPaymentMethod);
|
|
15
12
|
// Fetch profile data for the connected address with cleaned name
|
|
16
|
-
const connectedProfile = (0, react_1.useProfile)({ address:
|
|
13
|
+
const connectedProfile = (0, react_1.useProfile)({ address: walletAddress });
|
|
17
14
|
return {
|
|
18
|
-
address:
|
|
15
|
+
address: walletAddress,
|
|
19
16
|
profile: connectedProfile,
|
|
20
17
|
name: connectedProfile.data?.name,
|
|
21
18
|
isLoading: connectedProfile.isLoading,
|
|
@@ -2,8 +2,6 @@ import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMetho
|
|
|
2
2
|
interface UseConnectedWalletDisplayResult {
|
|
3
3
|
walletAddress: string | undefined;
|
|
4
4
|
shouldShowConnectedEOA: boolean;
|
|
5
|
-
shouldShowWagmiWallet: boolean;
|
|
6
|
-
isWalletDuplicated: boolean;
|
|
7
5
|
suggestedPaymentMethod: CryptoPaymentMethodType;
|
|
8
6
|
}
|
|
9
7
|
/**
|
|
@@ -12,23 +12,15 @@ function useConnectedWalletDisplay(selectedCryptoPaymentMethod) {
|
|
|
12
12
|
const { connectedEOAWallet, connectedSmartWallet } = (0, react_1.useAccountWallet)();
|
|
13
13
|
const { address: wagmiAddress } = (0, wagmi_1.useAccount)();
|
|
14
14
|
const globalWalletAddress = connectedSmartWallet?.getAccount()?.address;
|
|
15
|
-
// Helper function to check if two addresses are the same
|
|
16
|
-
const isSameAddress = (addr1, addr2) => {
|
|
17
|
-
if (!addr1 || !addr2)
|
|
18
|
-
return false;
|
|
19
|
-
return addr1.toLowerCase() === addr2.toLowerCase();
|
|
20
|
-
};
|
|
21
15
|
// Check if connectedEOAWallet and wagmi wallet represent the same wallet
|
|
22
16
|
const connectedEOAAddress = connectedEOAWallet?.getAccount()?.address;
|
|
23
|
-
const isWalletDuplicated = isSameAddress(connectedEOAAddress, wagmiAddress) || isSameAddress(globalWalletAddress, wagmiAddress);
|
|
24
17
|
// Determine which wallet to show (prefer connectedEOAWallet if both exist and are the same)
|
|
25
18
|
const shouldShowConnectedEOA = !!connectedEOAWallet;
|
|
26
19
|
// this is disabled because we don't want to display In-App Wallet as a payment method
|
|
27
|
-
const shouldShowWagmiWallet = false; // wagmiWalletIsConnected && (!isWalletDuplicated || !connectedEOAWallet);
|
|
28
20
|
// Determine which address to use based on payment method
|
|
29
21
|
let walletAddress;
|
|
30
22
|
if (selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.GLOBAL_WALLET) {
|
|
31
|
-
walletAddress =
|
|
23
|
+
walletAddress = globalWalletAddress;
|
|
32
24
|
}
|
|
33
25
|
else if (selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
34
26
|
// Prefer connectedEOAWallet, fallback to wagmi wallet
|
|
@@ -45,15 +37,13 @@ function useConnectedWalletDisplay(selectedCryptoPaymentMethod) {
|
|
|
45
37
|
// If there's a connected EOA or wagmi wallet, suggest CONNECT_WALLET
|
|
46
38
|
suggestedPaymentMethod = CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET;
|
|
47
39
|
}
|
|
48
|
-
else if (
|
|
40
|
+
else if (globalWalletAddress) {
|
|
49
41
|
// If only global wallet is available, suggest that
|
|
50
42
|
suggestedPaymentMethod = CryptoPaymentMethod_1.CryptoPaymentMethodType.GLOBAL_WALLET;
|
|
51
43
|
}
|
|
52
44
|
return {
|
|
53
45
|
walletAddress,
|
|
54
46
|
shouldShowConnectedEOA,
|
|
55
|
-
shouldShowWagmiWallet,
|
|
56
|
-
isWalletDuplicated,
|
|
57
47
|
suggestedPaymentMethod,
|
|
58
48
|
};
|
|
59
49
|
}
|
|
@@ -17,6 +17,7 @@ import { useCryptoPaymentMethodState } from "../hooks/useCryptoPaymentMethodStat
|
|
|
17
17
|
import { useRecipientAddressState } from "../hooks/useRecipientAddressState.js";
|
|
18
18
|
import { AnySpendFingerprintWrapper, getFingerprintConfig } from "./AnySpendFingerprintWrapper.js";
|
|
19
19
|
import { CryptoPaymentMethod, CryptoPaymentMethodType } from "./common/CryptoPaymentMethod.js";
|
|
20
|
+
import { CryptoPaymentMethodDisplay } from "./common/CryptoPaymentMethodDisplay.js";
|
|
20
21
|
import { FeeBreakDown } from "./common/FeeBreakDown.js";
|
|
21
22
|
import { FIAT_PAYMENT_METHOD_DISPLAY, FiatPaymentMethod, FiatPaymentMethodComponent } from "./common/FiatPaymentMethod.js";
|
|
22
23
|
import { OrderDetails } from "./common/OrderDetails.js";
|
|
@@ -298,7 +299,7 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
|
|
|
298
299
|
},
|
|
299
300
|
});
|
|
300
301
|
const isCreatingOrder = isCreatingRegularOrder || isCreatingOnrampOrder;
|
|
301
|
-
const { address: connectedAddress, name: connectedName } = useConnectedUserProfile();
|
|
302
|
+
const { address: connectedAddress, name: connectedName } = useConnectedUserProfile(effectiveCryptoPaymentMethod);
|
|
302
303
|
const recipientProfile = useProfile({ address: recipientAddress });
|
|
303
304
|
const recipientName = recipientProfile.data?.name;
|
|
304
305
|
const handleCreateOrder = async (recipientAddress, onramp) => {
|
|
@@ -520,7 +521,7 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
|
|
|
520
521
|
opacity: hasMounted ? 1 : 0,
|
|
521
522
|
y: hasMounted ? 0 : 20,
|
|
522
523
|
filter: hasMounted ? "blur(0px)" : "blur(10px)",
|
|
523
|
-
}, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, className: "relative flex w-full items-center justify-between", children: [_jsx("div", { className: "text-as-tertiarry flex h-7 items-center text-sm", children: "Pay" }), _jsx("button", { className: "text-as-tertiarry flex flex-wrap items-center justify-end gap-2 text-sm transition-colors hover:text-blue-700", onClick: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), children:
|
|
524
|
+
}, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, className: "relative flex w-full items-center justify-between", children: [_jsx("div", { className: "text-as-tertiarry flex h-7 items-center text-sm", children: "Pay" }), _jsx("button", { className: "text-as-tertiarry flex flex-wrap items-center justify-end gap-2 text-sm transition-colors hover:text-blue-700", onClick: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), children: _jsx(CryptoPaymentMethodDisplay, { paymentMethod: effectiveCryptoPaymentMethod, connectedAddress: connectedAddress, connectedName: connectedName }) })] }), _jsx("div", { className: "divider w-full" }), recipientSection, _jsx("div", { className: "divider w-full" }), _jsxs("div", { className: "flex flex-col gap-4", children: [_jsxs(motion.div, { initial: false, animate: {
|
|
524
525
|
opacity: hasMounted ? 1 : 0,
|
|
525
526
|
y: hasMounted ? 0 : 20,
|
|
526
527
|
filter: hasMounted ? "blur(0px)" : "blur(10px)",
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useProfile, useTokenData } from "../../../../global-account/react/index.js";
|
|
3
|
-
import { formatUsername } from "../../../../shared/utils/index.js";
|
|
4
|
-
import { shortenAddress } from "../../../../shared/utils/formatAddress.js";
|
|
5
3
|
import { formatDisplayNumber } from "../../../../shared/utils/number.js";
|
|
6
|
-
import {
|
|
4
|
+
import { Info } from "lucide-react";
|
|
7
5
|
import { motion } from "motion/react";
|
|
8
6
|
import { useEffect, useRef } from "react";
|
|
9
7
|
import { useConnectedWalletDisplay } from "../../hooks/useConnectedWalletDisplay.js";
|
|
10
|
-
import {
|
|
8
|
+
import { CryptoPaymentMethodDisplay } from "./CryptoPaymentMethodDisplay.js";
|
|
11
9
|
import { OrderTokenAmount } from "./OrderTokenAmount.js";
|
|
12
10
|
import { TokenBalance } from "./TokenBalance.js";
|
|
13
11
|
export function CryptoPaySection({ selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, isSrcInputDirty, setIsSrcInputDirty, selectedCryptoPaymentMethod, onSelectCryptoPaymentMethod, anyspendQuote, onTokenSelect, onShowFeeDetail, }) {
|
|
@@ -40,7 +38,7 @@ export function CryptoPaySection({ selectedSrcChainId, setSelectedSrcChainId, se
|
|
|
40
38
|
useEffect(() => {
|
|
41
39
|
appliedSrcMetadataRef.current = false;
|
|
42
40
|
}, [selectedSrcToken.address, selectedSrcToken.chainId]);
|
|
43
|
-
return (_jsxs(motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, className: "pay-section bg-as-surface-secondary border-as-border-secondary relative flex w-full flex-col gap-2 rounded-2xl border p-4 sm:p-6", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "text-as-primary/50 flex h-7 items-center gap-1.5 text-sm", children: ["Pay", !isSrcInputDirty && anyspendQuote?.data?.fee && onShowFeeDetail && (_jsx("button", { onClick: onShowFeeDetail, className: "text-as-primary/40 hover:text-as-primary/60 transition-colors", children: _jsx(Info, { className: "h-4 w-4" }) }))] }), _jsx("button", { className: "text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors focus:!outline-none", onClick: onSelectCryptoPaymentMethod, children:
|
|
41
|
+
return (_jsxs(motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, className: "pay-section bg-as-surface-secondary border-as-border-secondary relative flex w-full flex-col gap-2 rounded-2xl border p-4 sm:p-6", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "text-as-primary/50 flex h-7 items-center gap-1.5 text-sm", children: ["Pay", !isSrcInputDirty && anyspendQuote?.data?.fee && onShowFeeDetail && (_jsx("button", { onClick: onShowFeeDetail, className: "text-as-primary/40 hover:text-as-primary/60 transition-colors", children: _jsx(Info, { className: "h-4 w-4" }) }))] }), _jsx("button", { className: "text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors focus:!outline-none", onClick: onSelectCryptoPaymentMethod, children: _jsx(CryptoPaymentMethodDisplay, { paymentMethod: selectedCryptoPaymentMethod, connectedAddress: walletAddress, connectedName: connectedName }) })] }), _jsx(OrderTokenAmount, { address: walletAddress, walletAddress: walletAddress, context: "from", inputValue: srcAmount, onChangeInput: value => {
|
|
44
42
|
setIsSrcInputDirty(true);
|
|
45
43
|
setSrcAmount(value);
|
|
46
44
|
}, chainId: selectedSrcChainId, setChainId: setSelectedSrcChainId, token: selectedSrcToken, setToken: setSelectedSrcToken, onTokenSelect: onTokenSelect }), _jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-as-primary/50 flex h-5 items-center text-sm", children: formatDisplayNumber(anyspendQuote?.data?.currencyIn?.amountUsd, {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CryptoPaymentMethodType } from "./CryptoPaymentMethod";
|
|
2
|
+
interface CryptoPaymentMethodDisplayProps {
|
|
3
|
+
paymentMethod: CryptoPaymentMethodType;
|
|
4
|
+
connectedAddress?: string | null;
|
|
5
|
+
connectedName?: string | null;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Displays the selected crypto payment method with appropriate label
|
|
9
|
+
* - CONNECT_WALLET: Shows wallet address/name or "Connect wallet"
|
|
10
|
+
* - GLOBAL_WALLET: Shows "Global Account"
|
|
11
|
+
* - TRANSFER_CRYPTO: Shows "Transfer crypto"
|
|
12
|
+
* - NONE: Shows "Select payment method"
|
|
13
|
+
*/
|
|
14
|
+
export declare function CryptoPaymentMethodDisplay({ paymentMethod, connectedAddress, connectedName, }: CryptoPaymentMethodDisplayProps): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { formatUsername } from "../../../../shared/utils/index.js";
|
|
3
|
+
import { shortenAddress } from "../../../../shared/utils/formatAddress.js";
|
|
4
|
+
import { ChevronRight } from "lucide-react";
|
|
5
|
+
import { CryptoPaymentMethodType } from "./CryptoPaymentMethod.js";
|
|
6
|
+
/**
|
|
7
|
+
* Displays the selected crypto payment method with appropriate label
|
|
8
|
+
* - CONNECT_WALLET: Shows wallet address/name or "Connect wallet"
|
|
9
|
+
* - GLOBAL_WALLET: Shows "Global Account"
|
|
10
|
+
* - TRANSFER_CRYPTO: Shows "Transfer crypto"
|
|
11
|
+
* - NONE: Shows "Select payment method"
|
|
12
|
+
*/
|
|
13
|
+
export function CryptoPaymentMethodDisplay({ paymentMethod, connectedAddress, connectedName, }) {
|
|
14
|
+
if (paymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
15
|
+
return (_jsxs(_Fragment, { children: [connectedAddress ? (_jsx("span", { className: "text-as-tertiarry whitespace-nowrap", children: connectedName ? formatUsername(connectedName) : shortenAddress(connectedAddress) })) : (_jsx("span", { className: "whitespace-nowrap", children: "Connect wallet" })), _jsx(ChevronRight, { className: "h-4 w-4 shrink-0" })] }));
|
|
16
|
+
}
|
|
17
|
+
if (paymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET) {
|
|
18
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { className: "whitespace-nowrap", children: "Global Account" }), _jsx(ChevronRight, { className: "h-4 w-4 shrink-0" })] }));
|
|
19
|
+
}
|
|
20
|
+
if (paymentMethod === CryptoPaymentMethodType.TRANSFER_CRYPTO) {
|
|
21
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { className: "whitespace-nowrap", children: "Transfer crypto" }), _jsx(ChevronRight, { className: "h-4 w-4 shrink-0" })] }));
|
|
22
|
+
}
|
|
23
|
+
// NONE or any other case
|
|
24
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { className: "whitespace-nowrap", children: "Select payment method" }), _jsx(ChevronRight, { className: "h-4 w-4 shrink-0" })] }));
|
|
25
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod";
|
|
1
2
|
/**
|
|
2
3
|
* Hook that provides connected user's address, profile, and cleaned display name
|
|
3
4
|
* Combines logic for getting connected address from either global account or thirdweb wallets
|
|
4
5
|
*/
|
|
5
|
-
export declare function useConnectedUserProfile(): {
|
|
6
|
+
export declare function useConnectedUserProfile(selectedCryptoPaymentMethod?: CryptoPaymentMethodType): {
|
|
6
7
|
address: string | undefined;
|
|
7
8
|
profile: import("@tanstack/react-query").UseQueryResult<import("../../../global-account/react").CombinedProfile, Error>;
|
|
8
9
|
name: string | null | undefined;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useProfile } from "../../../global-account/react/index.js";
|
|
2
|
+
import { useConnectedWalletDisplay } from "./useConnectedWalletDisplay.js";
|
|
3
3
|
/**
|
|
4
4
|
* Hook that provides connected user's address, profile, and cleaned display name
|
|
5
5
|
* Combines logic for getting connected address from either global account or thirdweb wallets
|
|
6
6
|
*/
|
|
7
|
-
export function useConnectedUserProfile() {
|
|
8
|
-
const {
|
|
9
|
-
const connectedWallets = useConnectedWallets();
|
|
10
|
-
// Get connected address from global account or first connected wallet
|
|
11
|
-
const connectedAddress = globalAddress || connectedWallets?.[0]?.getAccount()?.address;
|
|
7
|
+
export function useConnectedUserProfile(selectedCryptoPaymentMethod) {
|
|
8
|
+
const { walletAddress } = useConnectedWalletDisplay(selectedCryptoPaymentMethod);
|
|
12
9
|
// Fetch profile data for the connected address with cleaned name
|
|
13
|
-
const connectedProfile = useProfile({ address:
|
|
10
|
+
const connectedProfile = useProfile({ address: walletAddress });
|
|
14
11
|
return {
|
|
15
|
-
address:
|
|
12
|
+
address: walletAddress,
|
|
16
13
|
profile: connectedProfile,
|
|
17
14
|
name: connectedProfile.data?.name,
|
|
18
15
|
isLoading: connectedProfile.isLoading,
|
|
@@ -2,8 +2,6 @@ import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMetho
|
|
|
2
2
|
interface UseConnectedWalletDisplayResult {
|
|
3
3
|
walletAddress: string | undefined;
|
|
4
4
|
shouldShowConnectedEOA: boolean;
|
|
5
|
-
shouldShowWagmiWallet: boolean;
|
|
6
|
-
isWalletDuplicated: boolean;
|
|
7
5
|
suggestedPaymentMethod: CryptoPaymentMethodType;
|
|
8
6
|
}
|
|
9
7
|
/**
|
|
@@ -9,23 +9,15 @@ export function useConnectedWalletDisplay(selectedCryptoPaymentMethod) {
|
|
|
9
9
|
const { connectedEOAWallet, connectedSmartWallet } = useAccountWallet();
|
|
10
10
|
const { address: wagmiAddress } = useAccount();
|
|
11
11
|
const globalWalletAddress = connectedSmartWallet?.getAccount()?.address;
|
|
12
|
-
// Helper function to check if two addresses are the same
|
|
13
|
-
const isSameAddress = (addr1, addr2) => {
|
|
14
|
-
if (!addr1 || !addr2)
|
|
15
|
-
return false;
|
|
16
|
-
return addr1.toLowerCase() === addr2.toLowerCase();
|
|
17
|
-
};
|
|
18
12
|
// Check if connectedEOAWallet and wagmi wallet represent the same wallet
|
|
19
13
|
const connectedEOAAddress = connectedEOAWallet?.getAccount()?.address;
|
|
20
|
-
const isWalletDuplicated = isSameAddress(connectedEOAAddress, wagmiAddress) || isSameAddress(globalWalletAddress, wagmiAddress);
|
|
21
14
|
// Determine which wallet to show (prefer connectedEOAWallet if both exist and are the same)
|
|
22
15
|
const shouldShowConnectedEOA = !!connectedEOAWallet;
|
|
23
16
|
// this is disabled because we don't want to display In-App Wallet as a payment method
|
|
24
|
-
const shouldShowWagmiWallet = false; // wagmiWalletIsConnected && (!isWalletDuplicated || !connectedEOAWallet);
|
|
25
17
|
// Determine which address to use based on payment method
|
|
26
18
|
let walletAddress;
|
|
27
19
|
if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET) {
|
|
28
|
-
walletAddress =
|
|
20
|
+
walletAddress = globalWalletAddress;
|
|
29
21
|
}
|
|
30
22
|
else if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
31
23
|
// Prefer connectedEOAWallet, fallback to wagmi wallet
|
|
@@ -42,15 +34,13 @@ export function useConnectedWalletDisplay(selectedCryptoPaymentMethod) {
|
|
|
42
34
|
// If there's a connected EOA or wagmi wallet, suggest CONNECT_WALLET
|
|
43
35
|
suggestedPaymentMethod = CryptoPaymentMethodType.CONNECT_WALLET;
|
|
44
36
|
}
|
|
45
|
-
else if (
|
|
37
|
+
else if (globalWalletAddress) {
|
|
46
38
|
// If only global wallet is available, suggest that
|
|
47
39
|
suggestedPaymentMethod = CryptoPaymentMethodType.GLOBAL_WALLET;
|
|
48
40
|
}
|
|
49
41
|
return {
|
|
50
42
|
walletAddress,
|
|
51
43
|
shouldShowConnectedEOA,
|
|
52
|
-
shouldShowWagmiWallet,
|
|
53
|
-
isWalletDuplicated,
|
|
54
44
|
suggestedPaymentMethod,
|
|
55
45
|
};
|
|
56
46
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CryptoPaymentMethodType } from "./CryptoPaymentMethod";
|
|
2
|
+
interface CryptoPaymentMethodDisplayProps {
|
|
3
|
+
paymentMethod: CryptoPaymentMethodType;
|
|
4
|
+
connectedAddress?: string | null;
|
|
5
|
+
connectedName?: string | null;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Displays the selected crypto payment method with appropriate label
|
|
9
|
+
* - CONNECT_WALLET: Shows wallet address/name or "Connect wallet"
|
|
10
|
+
* - GLOBAL_WALLET: Shows "Global Account"
|
|
11
|
+
* - TRANSFER_CRYPTO: Shows "Transfer crypto"
|
|
12
|
+
* - NONE: Shows "Select payment method"
|
|
13
|
+
*/
|
|
14
|
+
export declare function CryptoPaymentMethodDisplay({ paymentMethod, connectedAddress, connectedName, }: CryptoPaymentMethodDisplayProps): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod";
|
|
1
2
|
/**
|
|
2
3
|
* Hook that provides connected user's address, profile, and cleaned display name
|
|
3
4
|
* Combines logic for getting connected address from either global account or thirdweb wallets
|
|
4
5
|
*/
|
|
5
|
-
export declare function useConnectedUserProfile(): {
|
|
6
|
+
export declare function useConnectedUserProfile(selectedCryptoPaymentMethod?: CryptoPaymentMethodType): {
|
|
6
7
|
address: string | undefined;
|
|
7
8
|
profile: import("@tanstack/react-query").UseQueryResult<import("@b3dotfun/sdk/global-account/react").CombinedProfile, Error>;
|
|
8
9
|
name: string | null | undefined;
|
|
@@ -2,8 +2,6 @@ import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMetho
|
|
|
2
2
|
interface UseConnectedWalletDisplayResult {
|
|
3
3
|
walletAddress: string | undefined;
|
|
4
4
|
shouldShowConnectedEOA: boolean;
|
|
5
|
-
shouldShowWagmiWallet: boolean;
|
|
6
|
-
isWalletDuplicated: boolean;
|
|
7
5
|
suggestedPaymentMethod: CryptoPaymentMethodType;
|
|
8
6
|
}
|
|
9
7
|
/**
|
package/package.json
CHANGED
|
@@ -48,6 +48,7 @@ import { useCryptoPaymentMethodState } from "../hooks/useCryptoPaymentMethodStat
|
|
|
48
48
|
import { useRecipientAddressState } from "../hooks/useRecipientAddressState";
|
|
49
49
|
import { AnySpendFingerprintWrapper, getFingerprintConfig } from "./AnySpendFingerprintWrapper";
|
|
50
50
|
import { CryptoPaymentMethod, CryptoPaymentMethodType } from "./common/CryptoPaymentMethod";
|
|
51
|
+
import { CryptoPaymentMethodDisplay } from "./common/CryptoPaymentMethodDisplay";
|
|
51
52
|
import { FeeBreakDown } from "./common/FeeBreakDown";
|
|
52
53
|
import { FIAT_PAYMENT_METHOD_DISPLAY, FiatPaymentMethod, FiatPaymentMethodComponent } from "./common/FiatPaymentMethod";
|
|
53
54
|
import { OrderDetails } from "./common/OrderDetails";
|
|
@@ -469,7 +470,7 @@ function AnySpendCustomInner({
|
|
|
469
470
|
|
|
470
471
|
const isCreatingOrder = isCreatingRegularOrder || isCreatingOnrampOrder;
|
|
471
472
|
|
|
472
|
-
const { address: connectedAddress, name: connectedName } = useConnectedUserProfile();
|
|
473
|
+
const { address: connectedAddress, name: connectedName } = useConnectedUserProfile(effectiveCryptoPaymentMethod);
|
|
473
474
|
const recipientProfile = useProfile({ address: recipientAddress });
|
|
474
475
|
const recipientName = recipientProfile.data?.name;
|
|
475
476
|
|
|
@@ -951,28 +952,11 @@ function AnySpendCustomInner({
|
|
|
951
952
|
className="text-as-tertiarry flex flex-wrap items-center justify-end gap-2 text-sm transition-colors hover:text-blue-700"
|
|
952
953
|
onClick={() => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD)}
|
|
953
954
|
>
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
</span>
|
|
960
|
-
) : (
|
|
961
|
-
<span className="whitespace-nowrap">Connect wallet</span>
|
|
962
|
-
)}
|
|
963
|
-
<ChevronRight className="h-4 w-4 shrink-0" />
|
|
964
|
-
</>
|
|
965
|
-
) : effectiveCryptoPaymentMethod === CryptoPaymentMethodType.TRANSFER_CRYPTO ? (
|
|
966
|
-
<>
|
|
967
|
-
<span className="whitespace-nowrap">Transfer crypto</span>
|
|
968
|
-
<ChevronRight className="h-4 w-4 shrink-0" />
|
|
969
|
-
</>
|
|
970
|
-
) : (
|
|
971
|
-
<>
|
|
972
|
-
<span className="whitespace-nowrap">Select payment method</span>
|
|
973
|
-
<ChevronRight className="h-4 w-4 shrink-0" />
|
|
974
|
-
</>
|
|
975
|
-
)}
|
|
955
|
+
<CryptoPaymentMethodDisplay
|
|
956
|
+
paymentMethod={effectiveCryptoPaymentMethod}
|
|
957
|
+
connectedAddress={connectedAddress}
|
|
958
|
+
connectedName={connectedName}
|
|
959
|
+
/>
|
|
976
960
|
</button>
|
|
977
961
|
</motion.div>
|
|
978
962
|
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { useProfile, useTokenData } from "@b3dotfun/sdk/global-account/react";
|
|
2
|
-
import { formatUsername } from "@b3dotfun/sdk/shared/utils";
|
|
3
|
-
import { shortenAddress } from "@b3dotfun/sdk/shared/utils/formatAddress";
|
|
4
2
|
import { formatDisplayNumber } from "@b3dotfun/sdk/shared/utils/number";
|
|
5
|
-
import {
|
|
3
|
+
import { Info } from "lucide-react";
|
|
6
4
|
import { motion } from "motion/react";
|
|
7
5
|
import { useEffect, useRef } from "react";
|
|
8
6
|
import { components } from "../../../types/api";
|
|
9
7
|
import { useConnectedWalletDisplay } from "../../hooks/useConnectedWalletDisplay";
|
|
10
8
|
import { CryptoPaymentMethodType } from "./CryptoPaymentMethod";
|
|
9
|
+
import { CryptoPaymentMethodDisplay } from "./CryptoPaymentMethodDisplay";
|
|
11
10
|
import { OrderTokenAmount } from "./OrderTokenAmount";
|
|
12
11
|
import { TokenBalance } from "./TokenBalance";
|
|
13
12
|
|
|
@@ -103,33 +102,11 @@ export function CryptoPaySection({
|
|
|
103
102
|
className="text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors focus:!outline-none"
|
|
104
103
|
onClick={onSelectCryptoPaymentMethod}
|
|
105
104
|
>
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
</div>
|
|
112
|
-
) : (
|
|
113
|
-
"Connect wallet"
|
|
114
|
-
)}
|
|
115
|
-
<ChevronRight className="h-4 w-4" />
|
|
116
|
-
</>
|
|
117
|
-
) : selectedCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET ? (
|
|
118
|
-
<>
|
|
119
|
-
Global Account
|
|
120
|
-
<ChevronRight className="h-4 w-4" />
|
|
121
|
-
</>
|
|
122
|
-
) : selectedCryptoPaymentMethod === CryptoPaymentMethodType.TRANSFER_CRYPTO ? (
|
|
123
|
-
<>
|
|
124
|
-
Transfer crypto
|
|
125
|
-
<ChevronRight className="h-4 w-4" />
|
|
126
|
-
</>
|
|
127
|
-
) : (
|
|
128
|
-
<>
|
|
129
|
-
Select payment method
|
|
130
|
-
<ChevronRight className="h-4 w-4" />
|
|
131
|
-
</>
|
|
132
|
-
)}
|
|
105
|
+
<CryptoPaymentMethodDisplay
|
|
106
|
+
paymentMethod={selectedCryptoPaymentMethod}
|
|
107
|
+
connectedAddress={walletAddress}
|
|
108
|
+
connectedName={connectedName}
|
|
109
|
+
/>
|
|
133
110
|
</button>
|
|
134
111
|
</div>
|
|
135
112
|
<OrderTokenAmount
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { formatUsername } from "@b3dotfun/sdk/shared/utils";
|
|
2
|
+
import { shortenAddress } from "@b3dotfun/sdk/shared/utils/formatAddress";
|
|
3
|
+
import { ChevronRight } from "lucide-react";
|
|
4
|
+
import { CryptoPaymentMethodType } from "./CryptoPaymentMethod";
|
|
5
|
+
|
|
6
|
+
interface CryptoPaymentMethodDisplayProps {
|
|
7
|
+
paymentMethod: CryptoPaymentMethodType;
|
|
8
|
+
connectedAddress?: string | null;
|
|
9
|
+
connectedName?: string | null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Displays the selected crypto payment method with appropriate label
|
|
14
|
+
* - CONNECT_WALLET: Shows wallet address/name or "Connect wallet"
|
|
15
|
+
* - GLOBAL_WALLET: Shows "Global Account"
|
|
16
|
+
* - TRANSFER_CRYPTO: Shows "Transfer crypto"
|
|
17
|
+
* - NONE: Shows "Select payment method"
|
|
18
|
+
*/
|
|
19
|
+
export function CryptoPaymentMethodDisplay({
|
|
20
|
+
paymentMethod,
|
|
21
|
+
connectedAddress,
|
|
22
|
+
connectedName,
|
|
23
|
+
}: CryptoPaymentMethodDisplayProps) {
|
|
24
|
+
if (paymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
25
|
+
return (
|
|
26
|
+
<>
|
|
27
|
+
{connectedAddress ? (
|
|
28
|
+
<span className="text-as-tertiarry whitespace-nowrap">
|
|
29
|
+
{connectedName ? formatUsername(connectedName) : shortenAddress(connectedAddress)}
|
|
30
|
+
</span>
|
|
31
|
+
) : (
|
|
32
|
+
<span className="whitespace-nowrap">Connect wallet</span>
|
|
33
|
+
)}
|
|
34
|
+
<ChevronRight className="h-4 w-4 shrink-0" />
|
|
35
|
+
</>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (paymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET) {
|
|
40
|
+
return (
|
|
41
|
+
<>
|
|
42
|
+
<span className="whitespace-nowrap">Global Account</span>
|
|
43
|
+
<ChevronRight className="h-4 w-4 shrink-0" />
|
|
44
|
+
</>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (paymentMethod === CryptoPaymentMethodType.TRANSFER_CRYPTO) {
|
|
49
|
+
return (
|
|
50
|
+
<>
|
|
51
|
+
<span className="whitespace-nowrap">Transfer crypto</span>
|
|
52
|
+
<ChevronRight className="h-4 w-4 shrink-0" />
|
|
53
|
+
</>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// NONE or any other case
|
|
58
|
+
return (
|
|
59
|
+
<>
|
|
60
|
+
<span className="whitespace-nowrap">Select payment method</span>
|
|
61
|
+
<ChevronRight className="h-4 w-4 shrink-0" />
|
|
62
|
+
</>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useProfile } from "@b3dotfun/sdk/global-account/react";
|
|
2
|
+
import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod";
|
|
3
|
+
import { useConnectedWalletDisplay } from "./useConnectedWalletDisplay";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Hook that provides connected user's address, profile, and cleaned display name
|
|
6
7
|
* Combines logic for getting connected address from either global account or thirdweb wallets
|
|
7
8
|
*/
|
|
8
|
-
export function useConnectedUserProfile() {
|
|
9
|
-
const {
|
|
10
|
-
const connectedWallets = useConnectedWallets();
|
|
11
|
-
|
|
12
|
-
// Get connected address from global account or first connected wallet
|
|
13
|
-
const connectedAddress = globalAddress || connectedWallets?.[0]?.getAccount()?.address;
|
|
9
|
+
export function useConnectedUserProfile(selectedCryptoPaymentMethod?: CryptoPaymentMethodType) {
|
|
10
|
+
const { walletAddress } = useConnectedWalletDisplay(selectedCryptoPaymentMethod);
|
|
14
11
|
|
|
15
12
|
// Fetch profile data for the connected address with cleaned name
|
|
16
|
-
const connectedProfile = useProfile({ address:
|
|
13
|
+
const connectedProfile = useProfile({ address: walletAddress });
|
|
17
14
|
|
|
18
15
|
return {
|
|
19
|
-
address:
|
|
16
|
+
address: walletAddress,
|
|
20
17
|
profile: connectedProfile,
|
|
21
18
|
name: connectedProfile.data?.name,
|
|
22
19
|
isLoading: connectedProfile.isLoading,
|
|
@@ -5,8 +5,6 @@ import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMetho
|
|
|
5
5
|
interface UseConnectedWalletDisplayResult {
|
|
6
6
|
walletAddress: string | undefined;
|
|
7
7
|
shouldShowConnectedEOA: boolean;
|
|
8
|
-
shouldShowWagmiWallet: boolean;
|
|
9
|
-
isWalletDuplicated: boolean;
|
|
10
8
|
suggestedPaymentMethod: CryptoPaymentMethodType;
|
|
11
9
|
}
|
|
12
10
|
|
|
@@ -22,27 +20,18 @@ export function useConnectedWalletDisplay(
|
|
|
22
20
|
|
|
23
21
|
const globalWalletAddress = connectedSmartWallet?.getAccount()?.address;
|
|
24
22
|
|
|
25
|
-
// Helper function to check if two addresses are the same
|
|
26
|
-
const isSameAddress = (addr1?: string, addr2?: string): boolean => {
|
|
27
|
-
if (!addr1 || !addr2) return false;
|
|
28
|
-
return addr1.toLowerCase() === addr2.toLowerCase();
|
|
29
|
-
};
|
|
30
|
-
|
|
31
23
|
// Check if connectedEOAWallet and wagmi wallet represent the same wallet
|
|
32
24
|
const connectedEOAAddress = connectedEOAWallet?.getAccount()?.address;
|
|
33
|
-
const isWalletDuplicated =
|
|
34
|
-
isSameAddress(connectedEOAAddress, wagmiAddress) || isSameAddress(globalWalletAddress, wagmiAddress);
|
|
35
25
|
|
|
36
26
|
// Determine which wallet to show (prefer connectedEOAWallet if both exist and are the same)
|
|
37
27
|
const shouldShowConnectedEOA = !!connectedEOAWallet;
|
|
38
28
|
// this is disabled because we don't want to display In-App Wallet as a payment method
|
|
39
|
-
const shouldShowWagmiWallet = false; // wagmiWalletIsConnected && (!isWalletDuplicated || !connectedEOAWallet);
|
|
40
29
|
|
|
41
30
|
// Determine which address to use based on payment method
|
|
42
31
|
let walletAddress: string | undefined;
|
|
43
32
|
|
|
44
33
|
if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET) {
|
|
45
|
-
walletAddress =
|
|
34
|
+
walletAddress = globalWalletAddress;
|
|
46
35
|
} else if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
47
36
|
// Prefer connectedEOAWallet, fallback to wagmi wallet
|
|
48
37
|
walletAddress = connectedEOAAddress || wagmiAddress;
|
|
@@ -58,7 +47,7 @@ export function useConnectedWalletDisplay(
|
|
|
58
47
|
if (connectedEOAAddress || wagmiAddress) {
|
|
59
48
|
// If there's a connected EOA or wagmi wallet, suggest CONNECT_WALLET
|
|
60
49
|
suggestedPaymentMethod = CryptoPaymentMethodType.CONNECT_WALLET;
|
|
61
|
-
} else if (
|
|
50
|
+
} else if (globalWalletAddress) {
|
|
62
51
|
// If only global wallet is available, suggest that
|
|
63
52
|
suggestedPaymentMethod = CryptoPaymentMethodType.GLOBAL_WALLET;
|
|
64
53
|
}
|
|
@@ -66,8 +55,6 @@ export function useConnectedWalletDisplay(
|
|
|
66
55
|
return {
|
|
67
56
|
walletAddress,
|
|
68
57
|
shouldShowConnectedEOA,
|
|
69
|
-
shouldShowWagmiWallet,
|
|
70
|
-
isWalletDuplicated,
|
|
71
58
|
suggestedPaymentMethod,
|
|
72
59
|
};
|
|
73
60
|
}
|