@b3dotfun/sdk 0.0.29-alpha.3 → 0.0.29-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/AnyspendDepositHype.js +3 -1
- package/dist/cjs/anyspend/react/components/common/ConnectWalletPayment.js +9 -1
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +130 -41
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +3 -3
- package/dist/cjs/anyspend/react/components/common/PaySection.js +6 -4
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +29 -0
- package/dist/cjs/anyspend/react/hooks/useSigMint.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.d.ts +1 -0
- package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +1 -0
- package/dist/cjs/shared/constants/chains/b3Chain.d.ts +2 -2
- package/dist/cjs/shared/constants/chains/supported.d.ts +4 -4
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +3 -1
- package/dist/esm/anyspend/react/components/common/ConnectWalletPayment.js +6 -1
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +133 -44
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +3 -3
- package/dist/esm/anyspend/react/components/common/PaySection.js +7 -5
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +30 -1
- package/dist/esm/anyspend/react/hooks/useSigMint.d.ts +1 -1
- package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.d.ts +1 -0
- package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +1 -0
- package/dist/esm/shared/constants/chains/b3Chain.d.ts +2 -2
- package/dist/esm/shared/constants/chains/supported.d.ts +4 -4
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/hooks/useSigMint.d.ts +1 -1
- package/dist/types/global-account/react/hooks/useUnifiedChainSwitchAndExecute.d.ts +1 -0
- package/dist/types/shared/constants/chains/b3Chain.d.ts +2 -2
- package/dist/types/shared/constants/chains/supported.d.ts +4 -4
- package/package.json +1 -1
- package/src/anyspend/react/components/AnyspendDepositHype.tsx +4 -0
- package/src/anyspend/react/components/common/ConnectWalletPayment.tsx +9 -0
- package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +289 -103
- package/src/anyspend/react/components/common/OrderDetails.tsx +3 -3
- package/src/anyspend/react/components/common/PaySection.tsx +9 -7
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +33 -1
- package/src/global-account/react/hooks/useUnifiedChainSwitchAndExecute.ts +1 -0
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { useAccountWallet } from "../../../../global-account/react/index.js";
|
|
4
|
-
import { thirdwebB3Mainnet } from "../../../../shared/constants/chains/b3Chain.js";
|
|
5
4
|
import { cn } from "../../../../shared/utils/cn.js";
|
|
6
5
|
import { shortenAddress } from "../../../../shared/utils/formatAddress.js";
|
|
7
|
-
import {
|
|
8
|
-
import { ChevronLeft, ChevronRightCircle, Wallet, X } from "lucide-react";
|
|
6
|
+
import { ChevronLeft, ChevronRightCircle, Wallet, X, ZapIcon } from "lucide-react";
|
|
9
7
|
import { useState } from "react";
|
|
10
8
|
import { createPortal } from "react-dom";
|
|
11
9
|
import { toast } from "sonner";
|
|
12
|
-
import {
|
|
13
|
-
import { createWallet } from "thirdweb/wallets";
|
|
14
|
-
import { useDisconnect } from "wagmi";
|
|
10
|
+
import { useAccount, useConnect, useDisconnect, useWalletClient } from "wagmi";
|
|
15
11
|
export var CryptoPaymentMethodType;
|
|
16
12
|
(function (CryptoPaymentMethodType) {
|
|
17
13
|
CryptoPaymentMethodType["NONE"] = "none";
|
|
@@ -20,45 +16,138 @@ export var CryptoPaymentMethodType;
|
|
|
20
16
|
})(CryptoPaymentMethodType || (CryptoPaymentMethodType = {}));
|
|
21
17
|
export function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentMethod, isCreatingOrder, onBack, onSelectPaymentMethod, }) {
|
|
22
18
|
const { wallet: globalWallet } = useAccountWallet();
|
|
23
|
-
const
|
|
19
|
+
const { address, isConnected, connector } = useAccount();
|
|
20
|
+
const { connect, connectors, isPending } = useConnect();
|
|
24
21
|
const { disconnect } = useDisconnect();
|
|
25
|
-
const {
|
|
22
|
+
const { data: walletClient } = useWalletClient();
|
|
26
23
|
const [showWalletModal, setShowWalletModal] = useState(false);
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
24
|
+
const [selectedWalletConnector, setSelectedWalletConnector] = useState(null);
|
|
25
|
+
const [modalStep, setModalStep] = useState("wallet-selection");
|
|
26
|
+
// Define available wallet connectors
|
|
27
|
+
const availableConnectors = connectors.filter(connector => ["MetaMask", "WalletConnect", "Coinbase Wallet", "Rainbow"].includes(connector.name));
|
|
28
|
+
// Define wallet options with icons and info
|
|
29
|
+
const walletOptions = [
|
|
30
|
+
{
|
|
31
|
+
id: "metamask",
|
|
32
|
+
name: "MetaMask",
|
|
33
|
+
icon: "🦊",
|
|
34
|
+
description: "Connect using MetaMask browser extension",
|
|
35
|
+
connector: availableConnectors.find(c => c.name === "MetaMask"),
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: "coinbase",
|
|
39
|
+
name: "Coinbase Wallet",
|
|
40
|
+
icon: "🔵",
|
|
41
|
+
description: "Connect using Coinbase Wallet",
|
|
42
|
+
connector: availableConnectors.find(c => c.name === "Coinbase Wallet"),
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "rainbow",
|
|
46
|
+
name: "Rainbow",
|
|
47
|
+
icon: "🌈",
|
|
48
|
+
description: "Connect using Rainbow wallet",
|
|
49
|
+
connector: availableConnectors.find(c => c.name === "Rainbow"),
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "walletconnect",
|
|
53
|
+
name: "WalletConnect",
|
|
54
|
+
icon: "🔗",
|
|
55
|
+
description: "Connect using WalletConnect protocol",
|
|
56
|
+
connector: availableConnectors.find(c => c.name === "WalletConnect"),
|
|
57
|
+
},
|
|
58
|
+
].filter(wallet => wallet.connector); // Only show wallets that have available connectors
|
|
59
|
+
// Reset modal state when closing
|
|
60
|
+
const handleCloseModal = () => {
|
|
61
|
+
setShowWalletModal(false);
|
|
62
|
+
setModalStep("wallet-selection");
|
|
63
|
+
setSelectedWalletConnector(null);
|
|
64
|
+
};
|
|
65
|
+
// Function to request wallet permissions for specific wallet
|
|
66
|
+
const requestWalletPermissions = async (walletConnector) => {
|
|
67
|
+
try {
|
|
68
|
+
// If a specific wallet connector is provided and it's different from current
|
|
69
|
+
if (walletConnector && connector?.name !== walletConnector.name) {
|
|
70
|
+
// Disconnect current and connect to the selected wallet
|
|
71
|
+
// if (isConnected) {
|
|
72
|
+
// disconnect();
|
|
73
|
+
// // Small delay to ensure disconnection
|
|
74
|
+
// await new Promise(resolve => setTimeout(resolve, 100));
|
|
75
|
+
// }
|
|
76
|
+
await connect({ connector: walletConnector });
|
|
77
|
+
setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
78
|
+
onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
79
|
+
toast.success(`Connected to ${walletConnector.name}`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// If same wallet or no specific wallet, request permissions for account switching
|
|
83
|
+
if (walletClient && "request" in walletClient) {
|
|
84
|
+
await walletClient.request({
|
|
85
|
+
method: "wallet_requestPermissions",
|
|
86
|
+
params: [{ eth_accounts: {} }],
|
|
87
|
+
});
|
|
88
|
+
toast.success("Account selection completed");
|
|
89
|
+
setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
90
|
+
onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// Fallback: show modal for manual wallet selection
|
|
94
|
+
setShowWalletModal(true);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.error("Failed to request wallet permissions:", error);
|
|
99
|
+
if (error && typeof error === "object" && "message" in error) {
|
|
100
|
+
const errorMessage = error.message.toLowerCase();
|
|
101
|
+
if (errorMessage.includes("rejected") ||
|
|
102
|
+
errorMessage.includes("denied") ||
|
|
103
|
+
errorMessage.includes("cancelled")) {
|
|
104
|
+
toast.error("Account selection cancelled");
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
toast.error("Failed to open account selection");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
toast.error("Failed to open account selection");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
return (_jsxs("div", { className: "crypto-payment-method mx-auto h-fit w-[460px] max-w-full", children: [_jsxs("div", { className: cn("relative flex flex-col gap-10"), children: [_jsx("button", { onClick: onBack, className: "text-as-quaternary hover:text-as-primary absolute flex h-8 w-8 items-center justify-center rounded-lg transition-colors", children: _jsx(ChevronLeft, { className: "h-6 w-6" }) }), _jsx("div", { className: "flex items-center justify-around gap-4", children: _jsx("div", { className: "flex-1 text-center", children: _jsx("h2", { className: "text-as-primary text-lg font-semibold", children: "Select a payment method" }) }) }), _jsxs("div", { className: "crypto-payment-methods flex flex-col gap-6", children: [_jsxs("button", { onClick: () => {
|
|
116
|
+
// Always show wallet selection modal first
|
|
117
|
+
setShowWalletModal(true);
|
|
118
|
+
}, className: "crypto-payment-method-connect-wallet bg-as-surface-primary border-as-border-secondary hover:border-as-secondary/80 group flex w-full items-center justify-between gap-4 rounded-xl border px-4 py-3.5 transition-all duration-200 hover:shadow-md", children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsx("div", { className: "wallet-icon flex h-8 w-8 items-center justify-center rounded-full bg-blue-100", children: _jsx(Wallet, { className: "h-4 w-4 text-blue-600" }) }), _jsx("div", { className: "flex flex-col items-start text-left", children: _jsx("h4", { className: "text-as-primary font-semibold", children: "Connect wallet" }) })] }), _jsx(ChevronRightCircle, { className: "text-as-primary/40 group-hover:text-as-primary/60 h-5 w-5 transition-colors" })] }), _jsxs("button", { onClick: () => {
|
|
51
119
|
setSelectedPaymentMethod(CryptoPaymentMethodType.TRANSFER_CRYPTO);
|
|
52
120
|
onSelectPaymentMethod(CryptoPaymentMethodType.TRANSFER_CRYPTO);
|
|
53
|
-
}, disabled: isCreatingOrder, className: "crypto-payment-method-transfer bg-as-surface-primary border-as-border-secondary hover:border-as-secondary/80 group flex w-full items-center justify-between gap-4 rounded-xl border px-4 py-3.5 transition-all duration-200 hover:shadow-md", children: [_jsx("div", { className: "flex flex-col items-start text-left", children: _jsx("h4", { className: "text-as-primary font-semibold", children: "Transfer crypto" }) }), _jsx(ChevronRightCircle, { className: "text-as-primary/40 group-hover:text-as-primary/60 h-5 w-5 transition-colors" })] })
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
121
|
+
}, disabled: isCreatingOrder, className: "crypto-payment-method-transfer bg-as-surface-primary border-as-border-secondary hover:border-as-secondary/80 group flex w-full items-center justify-between gap-4 rounded-xl border px-4 py-3.5 transition-all duration-200 hover:shadow-md", children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsx("div", { className: "wallet-icon flex h-8 w-8 items-center justify-center rounded-full bg-orange-100", children: _jsx(ZapIcon, { className: "h-4 w-4" }) }), _jsx("div", { className: "flex flex-col items-start text-left", children: _jsx("h4", { className: "text-as-primary font-semibold", children: "Transfer crypto" }) })] }), _jsx(ChevronRightCircle, { className: "text-as-primary/40 group-hover:text-as-primary/60 h-5 w-5 transition-colors" })] }), isConnected && (_jsxs("div", { className: "installed-wallets", children: [_jsx("h3", { className: "text-as-primary/80 mb-3 text-sm font-medium", children: "Connected wallets" }), _jsx("div", { className: "space-y-2", children: _jsx("button", { onClick: () => {
|
|
122
|
+
setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
123
|
+
onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
124
|
+
toast.success(`Selected ${connector?.name || "wallet"}`);
|
|
125
|
+
}, className: cn("crypto-payment-method-connect-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md", selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
|
|
126
|
+
? "connected-wallet border-as-brand bg-as-brand/5"
|
|
127
|
+
: "border-as-border-secondary bg-as-surface-primary hover:border-as-secondary/80"), children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-3", children: [globalWallet?.meta?.icon ? (_jsx("img", { src: globalWallet.meta.icon, alt: "Wallet", className: "h-10 w-10 rounded-full" })) : (_jsx("div", { className: "wallet-icon flex h-10 w-10 items-center justify-center rounded-full bg-blue-100", children: _jsx(Wallet, { className: "h-5 w-5 text-blue-600" }) })), _jsxs("div", { className: "flex flex-col", children: [_jsx("span", { className: "text-as-primary font-semibold", children: connector?.name || "Connected Wallet" }), _jsx("span", { className: "text-as-primary/60 text-sm", children: shortenAddress(address || "") })] })] }), _jsxs("div", { className: "flex items-center gap-2", children: [selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET && (_jsx("div", { className: "h-2 w-2 rounded-full bg-green-500" })), _jsx("button", { onClick: e => {
|
|
128
|
+
e.stopPropagation();
|
|
129
|
+
disconnect();
|
|
130
|
+
toast.success("Wallet disconnected");
|
|
131
|
+
if (selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
132
|
+
setSelectedPaymentMethod(CryptoPaymentMethodType.NONE);
|
|
133
|
+
}
|
|
134
|
+
}, className: "text-as-primary/60 hover:text-as-primary/80 rounded-lg p-1.5 transition-colors", children: _jsx(X, { className: "h-4 w-4" }) })] })] }) }) })] }))] })] }), showWalletModal &&
|
|
135
|
+
createPortal(_jsx("div", { className: "pointer-events-auto fixed inset-0 z-[9999] flex items-center justify-center bg-black/50", children: _jsxs("div", { className: "max-h-[80vh] w-[400px] max-w-[90vw] overflow-auto rounded-xl bg-white p-6 dark:bg-gray-900", children: [_jsxs("div", { className: "mb-4 flex items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-2", children: [modalStep === "account-selection" && (_jsx("button", { onClick: () => setModalStep("wallet-selection"), className: "text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200", children: _jsx(ChevronLeft, { className: "h-5 w-5" }) })), _jsx("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white", children: modalStep === "wallet-selection"
|
|
136
|
+
? "Select a payment method"
|
|
137
|
+
: `Connect ${selectedWalletConnector?.name}` })] }), _jsx("button", { onClick: handleCloseModal, className: "text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200", children: _jsx(X, { className: "h-5 w-5" }) })] }), _jsx("div", { className: "space-y-4", children: modalStep === "wallet-selection" ? (_jsx(_Fragment, { children: _jsxs("div", { className: "space-y-3", children: [_jsx("h4", { className: "text-sm font-medium text-gray-700 dark:text-gray-300", children: isConnected ? "Switch wallet or account" : "Choose wallet to connect" }), walletOptions.map(walletOption => {
|
|
138
|
+
const isCurrentWallet = isConnected && connector?.name === walletOption.connector?.name;
|
|
139
|
+
return (_jsx("button", { onClick: async () => {
|
|
140
|
+
setSelectedWalletConnector(walletOption.connector);
|
|
141
|
+
setModalStep("account-selection");
|
|
142
|
+
}, disabled: isPending, className: `w-full rounded-xl border p-4 text-left transition-all hover:shadow-md disabled:opacity-50 ${isCurrentWallet
|
|
143
|
+
? "border-blue-500 bg-blue-50 dark:bg-blue-900/20"
|
|
144
|
+
: "border-gray-200 bg-white hover:border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:hover:border-gray-500"}`, children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsx("div", { className: `flex h-12 w-12 items-center justify-center rounded-xl text-xl ${isCurrentWallet ? "bg-blue-100 dark:bg-blue-800" : "bg-gray-100 dark:bg-gray-700"}`, children: walletOption.icon }), _jsxs("div", { children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("div", { className: "text-sm font-semibold text-gray-900 dark:text-white", children: walletOption.name }), isCurrentWallet && (_jsx("span", { className: "rounded-full bg-blue-100 px-2 py-0.5 text-xs font-medium text-blue-700 dark:bg-blue-800 dark:text-blue-200", children: "Connected" }))] }), _jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400", children: isCurrentWallet ? "Switch account or reconnect" : walletOption.description })] })] }), _jsx(ChevronRightCircle, { className: "h-5 w-5 text-gray-400" })] }) }, walletOption.id));
|
|
145
|
+
})] }) })) : (
|
|
146
|
+
/* Account Selection Step */
|
|
147
|
+
_jsxs("div", { className: "space-y-4", children: [_jsxs("p", { className: "text-sm text-gray-600 dark:text-gray-400", children: ["Connect to ", selectedWalletConnector?.name, " to view available accounts"] }), _jsx("button", { onClick: async () => {
|
|
148
|
+
handleCloseModal();
|
|
149
|
+
await requestWalletPermissions(selectedWalletConnector);
|
|
150
|
+
}, disabled: isPending, className: "w-full rounded-lg border border-gray-200 bg-white p-4 text-center transition-all hover:border-gray-300 hover:shadow-md disabled:opacity-50 dark:border-gray-600 dark:bg-gray-800 dark:hover:border-gray-500", children: _jsxs("div", { className: "flex items-center justify-center gap-3", children: [_jsx("div", { className: "flex h-10 w-10 items-center justify-center rounded-lg bg-gray-100 dark:bg-gray-700", children: _jsx(Wallet, { className: "h-5 w-5 text-gray-600 dark:text-gray-400" }) }), _jsxs("div", { children: [_jsx("div", { className: "text-sm font-medium text-gray-900 dark:text-white", children: isPending
|
|
151
|
+
? `Connecting to ${selectedWalletConnector?.name}...`
|
|
152
|
+
: `Connect ${selectedWalletConnector?.name}` }), _jsx("div", { className: "text-xs text-gray-500 dark:text-gray-400", children: isPending ? "Please check your wallet" : "Click to connect and select account" })] })] }) })] })) })] }) }), typeof window !== "undefined" ? document.getElementById("b3-root") || document.body : document.body)] }));
|
|
64
153
|
}
|
|
@@ -139,7 +139,7 @@ export const OrderDetails = memo(function OrderDetails({ mode = "modal", order,
|
|
|
139
139
|
const [txHash, setTxHash] = useState();
|
|
140
140
|
const [showQRCode, setShowQRCode] = useState(false);
|
|
141
141
|
const { isLoading: txLoading, isSuccess: txSuccess } = useWaitForTransactionReceipt({ hash: txHash });
|
|
142
|
-
const {
|
|
142
|
+
const { switchChainAndExecuteWithEOA, isSwitchingOrExecuting } = useUnifiedChainSwitchAndExecute();
|
|
143
143
|
const { colorMode } = useColorMode();
|
|
144
144
|
const roundedUpSrcAmount = useMemo(() => {
|
|
145
145
|
// Display the full transfer amount without rounding since users need to see the exact value they're transferring.
|
|
@@ -169,11 +169,11 @@ export const OrderDetails = memo(function OrderDetails({ mode = "modal", order,
|
|
|
169
169
|
to = order.srcTokenAddress;
|
|
170
170
|
value = BigInt(0);
|
|
171
171
|
}
|
|
172
|
-
const txHash = await
|
|
172
|
+
const txHash = await switchChainAndExecuteWithEOA(order.srcChain, { to, data: txData, value });
|
|
173
173
|
if (txHash) {
|
|
174
174
|
setTxHash(txHash);
|
|
175
175
|
}
|
|
176
|
-
}, [order,
|
|
176
|
+
}, [order, switchChainAndExecuteWithEOA]);
|
|
177
177
|
// Main payment handler that triggers chain switch and payment
|
|
178
178
|
const handlePayment = async () => {
|
|
179
179
|
console.log("Initiating payment process. Target chain:", order.srcChain, "Current chain:", walletClient?.chain?.id);
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Input,
|
|
2
|
+
import { Input, useProfile, useTokenData } from "../../../../global-account/react/index.js";
|
|
3
3
|
import { formatUsername } from "../../../../shared/utils/index.js";
|
|
4
4
|
import { shortenAddress } from "../../../../shared/utils/formatAddress.js";
|
|
5
5
|
import { formatDisplayNumber } from "../../../../shared/utils/number.js";
|
|
6
6
|
import { ChevronRight } from "lucide-react";
|
|
7
7
|
import { motion } from "motion/react";
|
|
8
8
|
import { useEffect, useRef } from "react";
|
|
9
|
+
import { useAccount } from "wagmi";
|
|
9
10
|
import { CryptoPaymentMethodType } from "./CryptoPaymentMethod.js";
|
|
10
11
|
import { FiatPaymentMethod } from "./FiatPaymentMethod.js";
|
|
11
12
|
import { OrderTokenAmount } from "./OrderTokenAmount.js";
|
|
12
13
|
import { TokenBalance } from "./TokenBalance.js";
|
|
13
14
|
export function PaySection({ paymentType, selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, setIsSrcInputDirty, selectedCryptoPaymentMethod, selectedFiatPaymentMethod, onSelectCryptoPaymentMethod, onSelectFiatPaymentMethod, anyspendQuote, }) {
|
|
14
|
-
const { address:
|
|
15
|
-
const
|
|
15
|
+
const { address: connectedAddress, isConnected } = useAccount();
|
|
16
|
+
const { data: profileData } = useProfile({ address: connectedAddress });
|
|
17
|
+
const connectedName = profileData?.displayName;
|
|
16
18
|
const { data: srcTokenMetadata } = useTokenData(selectedSrcToken?.chainId, selectedSrcToken?.address);
|
|
17
19
|
// Add ref to track if we've applied metadata
|
|
18
20
|
const appliedSrcMetadataRef = useRef(false);
|
|
@@ -38,13 +40,13 @@ export function PaySection({ paymentType, selectedSrcChainId, setSelectedSrcChai
|
|
|
38
40
|
useEffect(() => {
|
|
39
41
|
appliedSrcMetadataRef.current = false;
|
|
40
42
|
}, [selectedSrcToken.address, selectedSrcToken.chainId]);
|
|
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: "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: [_jsx("div", { className: "text-as-primary/50 flex h-7 items-center text-sm", children: "Pay" }), paymentType === "crypto" ? (_jsx("button", { className: "text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors", onClick: onSelectCryptoPaymentMethod, children: selectedCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET ? (_jsxs(_Fragment, { children: [
|
|
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: "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: [_jsx("div", { className: "text-as-primary/50 flex h-7 items-center text-sm", children: "Pay" }), paymentType === "crypto" ? (_jsx("button", { className: "text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors focus:!outline-none", onClick: onSelectCryptoPaymentMethod, children: selectedCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET ? (_jsxs(_Fragment, { children: [isConnected ? (_jsx("div", { className: "flex items-center gap-1", children: connectedName ? formatUsername(connectedName) : shortenAddress(connectedAddress || "") })) : ("Connect wallet"), _jsx(ChevronRight, { className: "h-4 w-4" })] })) : selectedCryptoPaymentMethod === CryptoPaymentMethodType.TRANSFER_CRYPTO ? (_jsxs(_Fragment, { children: ["Transfer crypto", _jsx(ChevronRight, { className: "h-4 w-4" })] })) : (_jsxs(_Fragment, { children: ["Select payment method", _jsx(ChevronRight, { className: "h-4 w-4" })] })) })) : (_jsx("button", { className: "text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors", onClick: onSelectFiatPaymentMethod, children: selectedFiatPaymentMethod === FiatPaymentMethod.COINBASE_PAY ? (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("div", { className: "flex h-5 w-5 items-center justify-center rounded-full bg-blue-600", children: _jsx("span", { className: "text-xs font-bold text-white", children: "C" }) }), "Coinbase Pay"] }), _jsx(ChevronRight, { className: "h-4 w-4" })] })) : selectedFiatPaymentMethod === FiatPaymentMethod.STRIPE ? (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("div", { className: "flex h-5 w-5 items-center justify-center rounded-full bg-blue-600", children: _jsx("span", { className: "text-xs font-bold text-white", children: "S" }) }), "Credit/Debit Card"] }), _jsx(ChevronRight, { className: "h-4 w-4" })] })) : (_jsxs(_Fragment, { children: ["Select payment method", _jsx(ChevronRight, { className: "h-4 w-4" })] })) }))] }), paymentType === "crypto" ? (_jsxs(_Fragment, { children: [_jsx(OrderTokenAmount, { address: connectedAddress, context: "from", inputValue: srcAmount, onChangeInput: value => {
|
|
42
44
|
setIsSrcInputDirty(true);
|
|
43
45
|
setSrcAmount(value);
|
|
44
46
|
}, chainId: selectedSrcChainId, setChainId: setSelectedSrcChainId, token: selectedSrcToken, setToken: setSelectedSrcToken }), _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, {
|
|
45
47
|
style: "currency",
|
|
46
48
|
fallback: "",
|
|
47
|
-
}) }), _jsx(TokenBalance, { token: selectedSrcToken, walletAddress:
|
|
49
|
+
}) }), _jsx(TokenBalance, { token: selectedSrcToken, walletAddress: connectedAddress, onChangeInput: value => {
|
|
48
50
|
setIsSrcInputDirty(true);
|
|
49
51
|
setSrcAmount(value);
|
|
50
52
|
} })] })] })) : (_jsxs(_Fragment, { children: [_jsx("div", { className: "flex items-center justify-center pb-2 pt-8", children: _jsxs("div", { className: "flex gap-1", children: [_jsx("span", { className: "text-as-tertiarry text-2xl font-bold", children: "$" }), _jsx(Input, { type: "text", value: srcAmount, onChange: e => setSrcAmount(e.target.value.replace(/[^0-9.]/g, "")), placeholder: "5", className: "text-as-primary placeholder:text-as-primary/50 h-auto min-w-[70px] border-0 bg-transparent p-0 px-3 pt-1 text-4xl font-bold focus-visible:ring-0 focus-visible:ring-offset-0", style: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { B3_TOKEN, getDefaultToken, USDC_BASE } from "../../../anyspend/index.js";
|
|
2
2
|
import { useAnyspendCreateOnrampOrder, useAnyspendCreateOrder, useAnyspendOrderAndTransactions, useAnyspendQuote, useGeoOnrampOptions, } from "../../../anyspend/react/index.js";
|
|
3
3
|
import { anyspendService } from "../../../anyspend/services/anyspend.js";
|
|
4
|
-
import { useAccountWallet, useProfile } from "../../../global-account/react/index.js";
|
|
4
|
+
import { useAccountWallet, useProfile, useRouter, useSearchParamsSSR } from "../../../global-account/react/index.js";
|
|
5
5
|
import { formatTokenAmount, formatUnits } from "../../../shared/utils/number.js";
|
|
6
6
|
import { useEffect, useState } from "react";
|
|
7
7
|
import { toast } from "sonner";
|
|
@@ -19,6 +19,8 @@ export var PanelView;
|
|
|
19
19
|
PanelView[PanelView["LOADING"] = 5] = "LOADING";
|
|
20
20
|
})(PanelView || (PanelView = {}));
|
|
21
21
|
export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder, isDepositMode = false, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, }) {
|
|
22
|
+
const searchParams = useSearchParamsSSR();
|
|
23
|
+
const router = useRouter();
|
|
22
24
|
// Panel and order state
|
|
23
25
|
const [activePanel, setActivePanel] = useState(loadOrder ? PanelView.ORDER_DETAILS : PanelView.MAIN);
|
|
24
26
|
const [orderId, setOrderId] = useState(loadOrder);
|
|
@@ -45,6 +47,11 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
|
|
|
45
47
|
setSelectedRecipientAddress(globalAddress);
|
|
46
48
|
}
|
|
47
49
|
}, [selectedRecipientAddress, globalAddress]);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (paymentType === "crypto") {
|
|
52
|
+
setSelectedCryptoPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
53
|
+
}
|
|
54
|
+
}, [paymentType]);
|
|
48
55
|
// Fetch specific token when sourceTokenAddress and sourceTokenChainId are provided
|
|
49
56
|
useEffect(() => {
|
|
50
57
|
const fetchSourceToken = async () => {
|
|
@@ -99,6 +106,16 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
|
|
|
99
106
|
setDstAmount("");
|
|
100
107
|
}
|
|
101
108
|
}, [anyspendQuote]);
|
|
109
|
+
// Update useEffect for URL parameter to not override loadOrder
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (loadOrder)
|
|
112
|
+
return; // Skip if we have a loadOrder
|
|
113
|
+
const orderIdParam = searchParams.get("orderId");
|
|
114
|
+
if (orderIdParam) {
|
|
115
|
+
setOrderId(orderIdParam);
|
|
116
|
+
setActivePanel(PanelView.ORDER_DETAILS);
|
|
117
|
+
}
|
|
118
|
+
}, [searchParams, loadOrder]);
|
|
102
119
|
// Order creation hooks
|
|
103
120
|
const { createOrder, isCreatingOrder } = useAnyspendCreateOrder({
|
|
104
121
|
onSuccess: data => {
|
|
@@ -106,6 +123,18 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
|
|
|
106
123
|
setOrderId(newOrderId);
|
|
107
124
|
setActivePanel(PanelView.ORDER_DETAILS);
|
|
108
125
|
onOrderSuccess?.(newOrderId);
|
|
126
|
+
// Add orderId and payment method to URL for persistence
|
|
127
|
+
const params = new URLSearchParams(searchParams.toString()); // Preserve existing params
|
|
128
|
+
params.set("orderId", newOrderId);
|
|
129
|
+
if (selectedCryptoPaymentMethod !== CryptoPaymentMethodType.NONE) {
|
|
130
|
+
console.log("Setting cryptoPaymentMethod in URL:", selectedCryptoPaymentMethod);
|
|
131
|
+
params.set("cryptoPaymentMethod", selectedCryptoPaymentMethod);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
console.log("Payment method is NONE, not setting in URL");
|
|
135
|
+
}
|
|
136
|
+
console.log("Final URL params:", params.toString());
|
|
137
|
+
router.push(`${window.location.pathname}?${params.toString()}`);
|
|
109
138
|
},
|
|
110
139
|
onError: error => {
|
|
111
140
|
console.error(error);
|
|
@@ -5,6 +5,7 @@ export interface UnifiedTransactionParams {
|
|
|
5
5
|
}
|
|
6
6
|
export declare function useUnifiedChainSwitchAndExecute(): {
|
|
7
7
|
switchChainAndExecute: (targetChainId: number, params: UnifiedTransactionParams) => Promise<string | undefined>;
|
|
8
|
+
switchChainAndExecuteWithEOA: (targetChainId: number, params: UnifiedTransactionParams) => Promise<string | undefined>;
|
|
8
9
|
isSwitchingOrExecuting: boolean;
|
|
9
10
|
isActiveSmartWallet: boolean | undefined;
|
|
10
11
|
isActiveEOAWallet: boolean | undefined;
|
|
@@ -158,6 +158,7 @@ export function useUnifiedChainSwitchAndExecute() {
|
|
|
158
158
|
}, [isActiveSmartWallet, isActiveEOAWallet, handleAASendTransaction, handleEOASwitchChainAndSendTransaction]);
|
|
159
159
|
return {
|
|
160
160
|
switchChainAndExecute,
|
|
161
|
+
switchChainAndExecuteWithEOA: handleEOASwitchChainAndSendTransaction,
|
|
161
162
|
isSwitchingOrExecuting,
|
|
162
163
|
isActiveSmartWallet,
|
|
163
164
|
isActiveEOAWallet,
|
|
@@ -88,9 +88,9 @@ export declare const getViemChainConfig: (config: ChainNetworks) => {
|
|
|
88
88
|
readonly rpc: string;
|
|
89
89
|
readonly icon: {
|
|
90
90
|
format: string;
|
|
91
|
-
url: string;
|
|
92
|
-
width: number;
|
|
93
91
|
height: number;
|
|
92
|
+
width: number;
|
|
93
|
+
url: string;
|
|
94
94
|
};
|
|
95
95
|
};
|
|
96
96
|
export declare const thirdwebB3Testnet: ThirdwebChain;
|
|
@@ -10,9 +10,9 @@ export declare const supportedChainNetworks: {
|
|
|
10
10
|
testnet?: boolean | undefined;
|
|
11
11
|
fees?: Record<string, any> | undefined;
|
|
12
12
|
formatters?: Record<string, any> | undefined;
|
|
13
|
+
color?: string | undefined;
|
|
13
14
|
testnetConfigID?: number | undefined;
|
|
14
15
|
badge?: string | undefined;
|
|
15
|
-
color?: string | undefined;
|
|
16
16
|
enabledFeatures?: string[] | undefined;
|
|
17
17
|
blockExplorers: {
|
|
18
18
|
default: string;
|
|
@@ -35,13 +35,13 @@ export declare const supportedChainNetworks: {
|
|
|
35
35
|
uri: string;
|
|
36
36
|
}[];
|
|
37
37
|
};
|
|
38
|
-
_id: string | {};
|
|
39
38
|
icon: {
|
|
40
39
|
format: string;
|
|
41
|
-
url: string;
|
|
42
|
-
width: number;
|
|
43
40
|
height: number;
|
|
41
|
+
width: number;
|
|
42
|
+
url: string;
|
|
44
43
|
};
|
|
44
|
+
_id: string | {};
|
|
45
45
|
}[];
|
|
46
46
|
export declare const coingeckoChains: Record<number, {
|
|
47
47
|
coingecko_id: string;
|