@b3dotfun/sdk 0.0.35-alpha.0 → 0.0.35-alpha.2
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.js +5 -3
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +2 -2
- package/dist/cjs/anyspend/react/components/common/ConnectWalletPayment.d.ts +3 -1
- package/dist/cjs/anyspend/react/components/common/ConnectWalletPayment.js +5 -2
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.d.ts +16 -0
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +58 -0
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.d.ts +1 -0
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +22 -15
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +12 -4
- package/dist/cjs/anyspend/react/components/common/PaySection.d.ts +2 -6
- package/dist/cjs/anyspend/react/components/common/PaySection.js +10 -15
- package/dist/cjs/anyspend/react/components/index.d.ts +2 -2
- package/dist/cjs/anyspend/react/components/index.js +5 -5
- package/dist/esm/anyspend/react/components/AnySpend.js +5 -3
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +2 -2
- package/dist/esm/anyspend/react/components/common/ConnectWalletPayment.d.ts +3 -1
- package/dist/esm/anyspend/react/components/common/ConnectWalletPayment.js +5 -2
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.d.ts +16 -0
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +55 -0
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.d.ts +1 -0
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +22 -15
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +12 -4
- package/dist/esm/anyspend/react/components/common/PaySection.d.ts +2 -6
- package/dist/esm/anyspend/react/components/common/PaySection.js +10 -15
- package/dist/esm/anyspend/react/components/index.d.ts +2 -2
- package/dist/esm/anyspend/react/components/index.js +2 -2
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/components/common/ConnectWalletPayment.d.ts +3 -1
- package/dist/types/anyspend/react/components/common/CryptoPaySection.d.ts +16 -0
- package/dist/types/anyspend/react/components/common/CryptoPaymentMethod.d.ts +1 -0
- package/dist/types/anyspend/react/components/common/PaySection.d.ts +2 -6
- package/dist/types/anyspend/react/components/index.d.ts +2 -2
- package/package.json +3 -3
- package/src/anyspend/react/components/AnySpend.tsx +7 -6
- package/src/anyspend/react/components/AnyspendDepositHype.tsx +2 -5
- package/src/anyspend/react/components/common/ConnectWalletPayment.tsx +6 -1
- package/src/anyspend/react/components/common/CryptoPaySection.tsx +153 -0
- package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +80 -43
- package/src/anyspend/react/components/common/OrderDetails.tsx +13 -4
- package/src/anyspend/react/components/common/PaySection.tsx +64 -140
- package/src/anyspend/react/components/index.ts +2 -2
|
@@ -8,6 +8,7 @@ import { formatTokenAmount } from "@b3dotfun/sdk/shared/utils/number";
|
|
|
8
8
|
import { motion } from "framer-motion";
|
|
9
9
|
import { ChevronRight, Loader2 } from "lucide-react";
|
|
10
10
|
import { useAccount } from "wagmi";
|
|
11
|
+
import { CryptoPaymentMethodType } from "./CryptoPaymentMethod";
|
|
11
12
|
import { OrderDetailsCollapsible } from "./OrderDetailsCollapsible";
|
|
12
13
|
|
|
13
14
|
type Tournament = components["schemas"]["Tournament"];
|
|
@@ -22,6 +23,7 @@ interface ConnectWalletPaymentProps {
|
|
|
22
23
|
phantomWalletAddress?: string | null;
|
|
23
24
|
tournament?: Tournament;
|
|
24
25
|
nft?: NFT;
|
|
26
|
+
cryptoPaymentMethod: CryptoPaymentMethodType;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
export default function ConnectWalletPayment({
|
|
@@ -32,6 +34,7 @@ export default function ConnectWalletPayment({
|
|
|
32
34
|
phantomWalletAddress,
|
|
33
35
|
tournament,
|
|
34
36
|
nft,
|
|
37
|
+
cryptoPaymentMethod,
|
|
35
38
|
}: ConnectWalletPaymentProps) {
|
|
36
39
|
const profile = useProfile({ address: order.recipientAddress });
|
|
37
40
|
const recipientName = profile.data?.name?.replace(/\.b3\.fun/g, "");
|
|
@@ -79,7 +82,9 @@ export default function ConnectWalletPayment({
|
|
|
79
82
|
<span className="whitespace-nowrap pl-4 text-lg md:text-sm">
|
|
80
83
|
{order.srcChain === RELAY_SOLANA_MAINNET_CHAIN_ID && phantomWalletAddress
|
|
81
84
|
? "Pay from Phantom Wallet"
|
|
82
|
-
:
|
|
85
|
+
: cryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET
|
|
86
|
+
? "Pay from Global Account"
|
|
87
|
+
: "Pay from Connected Wallet"}
|
|
83
88
|
</span>
|
|
84
89
|
<ChevronRight className="h-4 w-4" />
|
|
85
90
|
</>
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { useAccountWallet, 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
|
+
import { formatDisplayNumber } from "@b3dotfun/sdk/shared/utils/number";
|
|
5
|
+
import { ChevronRight } from "lucide-react";
|
|
6
|
+
import { motion } from "motion/react";
|
|
7
|
+
import { useEffect, useRef } from "react";
|
|
8
|
+
import { useAccount } from "wagmi";
|
|
9
|
+
import { components } from "../../../types/api";
|
|
10
|
+
import { CryptoPaymentMethodType } from "./CryptoPaymentMethod";
|
|
11
|
+
import { OrderTokenAmount } from "./OrderTokenAmount";
|
|
12
|
+
import { TokenBalance } from "./TokenBalance";
|
|
13
|
+
|
|
14
|
+
interface CryptoPaySectionProps {
|
|
15
|
+
// Token state
|
|
16
|
+
selectedSrcChainId: number;
|
|
17
|
+
setSelectedSrcChainId: (chainId: number) => void;
|
|
18
|
+
selectedSrcToken: components["schemas"]["Token"];
|
|
19
|
+
setSelectedSrcToken: (token: components["schemas"]["Token"]) => void;
|
|
20
|
+
srcAmount: string;
|
|
21
|
+
setSrcAmount: (amount: string) => void;
|
|
22
|
+
setIsSrcInputDirty: (dirty: boolean) => void;
|
|
23
|
+
// Payment method state
|
|
24
|
+
selectedCryptoPaymentMethod: CryptoPaymentMethodType;
|
|
25
|
+
onSelectCryptoPaymentMethod: () => void;
|
|
26
|
+
// Quote data
|
|
27
|
+
anyspendQuote?: any;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function CryptoPaySection({
|
|
31
|
+
selectedSrcChainId,
|
|
32
|
+
setSelectedSrcChainId,
|
|
33
|
+
selectedSrcToken,
|
|
34
|
+
setSelectedSrcToken,
|
|
35
|
+
srcAmount,
|
|
36
|
+
setSrcAmount,
|
|
37
|
+
setIsSrcInputDirty,
|
|
38
|
+
selectedCryptoPaymentMethod,
|
|
39
|
+
onSelectCryptoPaymentMethod,
|
|
40
|
+
anyspendQuote,
|
|
41
|
+
}: CryptoPaySectionProps) {
|
|
42
|
+
const { address: connectedAddress, isConnected } = useAccount();
|
|
43
|
+
const { data: profileData } = useProfile({ address: connectedAddress });
|
|
44
|
+
const connectedName = profileData?.displayName;
|
|
45
|
+
const { address: globalAddress } = useAccountWallet();
|
|
46
|
+
const { data: srcTokenMetadata } = useTokenData(selectedSrcToken?.chainId, selectedSrcToken?.address);
|
|
47
|
+
|
|
48
|
+
// Determine which address to use based on payment method
|
|
49
|
+
const walletAddress =
|
|
50
|
+
selectedCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET ? globalAddress : connectedAddress;
|
|
51
|
+
|
|
52
|
+
// Add ref to track if we've applied metadata
|
|
53
|
+
const appliedSrcMetadataRef = useRef(false);
|
|
54
|
+
|
|
55
|
+
// Update source token with metadata
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (selectedSrcToken && srcTokenMetadata && !appliedSrcMetadataRef.current) {
|
|
58
|
+
// Mark as applied
|
|
59
|
+
appliedSrcMetadataRef.current = true;
|
|
60
|
+
|
|
61
|
+
const enhancedToken = {
|
|
62
|
+
...selectedSrcToken,
|
|
63
|
+
decimals: srcTokenMetadata.decimals || selectedSrcToken.decimals,
|
|
64
|
+
symbol: srcTokenMetadata.symbol || selectedSrcToken.symbol,
|
|
65
|
+
name: srcTokenMetadata.name || selectedSrcToken.name,
|
|
66
|
+
metadata: {
|
|
67
|
+
...selectedSrcToken.metadata,
|
|
68
|
+
logoURI: srcTokenMetadata?.logoURI || selectedSrcToken.metadata.logoURI,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
setSelectedSrcToken(enhancedToken);
|
|
72
|
+
}
|
|
73
|
+
}, [srcTokenMetadata, selectedSrcToken, setSelectedSrcToken]);
|
|
74
|
+
|
|
75
|
+
// Reset source token ref when address/chain changes
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
appliedSrcMetadataRef.current = false;
|
|
78
|
+
}, [selectedSrcToken.address, selectedSrcToken.chainId]);
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<motion.div
|
|
82
|
+
initial={{ opacity: 0, y: 20, filter: "blur(10px)" }}
|
|
83
|
+
animate={{ opacity: 1, y: 0, filter: "blur(0px)" }}
|
|
84
|
+
transition={{ duration: 0.3, delay: 0, ease: "easeInOut" }}
|
|
85
|
+
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"
|
|
86
|
+
>
|
|
87
|
+
<div className="flex items-center justify-between">
|
|
88
|
+
<div className="text-as-primary/50 flex h-7 items-center text-sm">Pay</div>
|
|
89
|
+
<button
|
|
90
|
+
className="text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors focus:!outline-none"
|
|
91
|
+
onClick={onSelectCryptoPaymentMethod}
|
|
92
|
+
>
|
|
93
|
+
{selectedCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET ? (
|
|
94
|
+
<>
|
|
95
|
+
{isConnected ? (
|
|
96
|
+
<div className="flex items-center gap-1">
|
|
97
|
+
{connectedName ? formatUsername(connectedName) : shortenAddress(connectedAddress || "")}
|
|
98
|
+
</div>
|
|
99
|
+
) : (
|
|
100
|
+
"Connect wallet"
|
|
101
|
+
)}
|
|
102
|
+
<ChevronRight className="h-4 w-4" />
|
|
103
|
+
</>
|
|
104
|
+
) : selectedCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET ? (
|
|
105
|
+
<>
|
|
106
|
+
Global Account
|
|
107
|
+
<ChevronRight className="h-4 w-4" />
|
|
108
|
+
</>
|
|
109
|
+
) : selectedCryptoPaymentMethod === CryptoPaymentMethodType.TRANSFER_CRYPTO ? (
|
|
110
|
+
<>
|
|
111
|
+
Transfer crypto
|
|
112
|
+
<ChevronRight className="h-4 w-4" />
|
|
113
|
+
</>
|
|
114
|
+
) : (
|
|
115
|
+
<>
|
|
116
|
+
Select payment method
|
|
117
|
+
<ChevronRight className="h-4 w-4" />
|
|
118
|
+
</>
|
|
119
|
+
)}
|
|
120
|
+
</button>
|
|
121
|
+
</div>
|
|
122
|
+
<OrderTokenAmount
|
|
123
|
+
address={walletAddress}
|
|
124
|
+
context="from"
|
|
125
|
+
inputValue={srcAmount}
|
|
126
|
+
onChangeInput={value => {
|
|
127
|
+
setIsSrcInputDirty(true);
|
|
128
|
+
setSrcAmount(value);
|
|
129
|
+
}}
|
|
130
|
+
chainId={selectedSrcChainId}
|
|
131
|
+
setChainId={setSelectedSrcChainId}
|
|
132
|
+
token={selectedSrcToken}
|
|
133
|
+
setToken={setSelectedSrcToken}
|
|
134
|
+
/>
|
|
135
|
+
<div className="flex items-center justify-between">
|
|
136
|
+
<div className="text-as-primary/50 flex h-5 items-center text-sm">
|
|
137
|
+
{formatDisplayNumber(anyspendQuote?.data?.currencyIn?.amountUsd, {
|
|
138
|
+
style: "currency",
|
|
139
|
+
fallback: "",
|
|
140
|
+
})}
|
|
141
|
+
</div>
|
|
142
|
+
<TokenBalance
|
|
143
|
+
token={selectedSrcToken}
|
|
144
|
+
walletAddress={walletAddress}
|
|
145
|
+
onChangeInput={value => {
|
|
146
|
+
setIsSrcInputDirty(true);
|
|
147
|
+
setSrcAmount(value);
|
|
148
|
+
}}
|
|
149
|
+
/>
|
|
150
|
+
</div>
|
|
151
|
+
</motion.div>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
@@ -13,6 +13,7 @@ import { useAccount, useConnect, useDisconnect, useWalletClient } from "wagmi";
|
|
|
13
13
|
export enum CryptoPaymentMethodType {
|
|
14
14
|
NONE = "none",
|
|
15
15
|
CONNECT_WALLET = "connect_wallet",
|
|
16
|
+
GLOBAL_WALLET = "global_wallet",
|
|
16
17
|
TRANSFER_CRYPTO = "transfer_crypto",
|
|
17
18
|
}
|
|
18
19
|
|
|
@@ -37,7 +38,7 @@ export function CryptoPaymentMethod({
|
|
|
37
38
|
onBack,
|
|
38
39
|
onSelectPaymentMethod,
|
|
39
40
|
}: CryptoPaymentMethodProps) {
|
|
40
|
-
const { wallet: globalWallet } = useAccountWallet();
|
|
41
|
+
const { wallet: globalWallet, address: globalAddress } = useAccountWallet();
|
|
41
42
|
const { address, isConnected, connector } = useAccount();
|
|
42
43
|
const { connect, connectors, isPending } = useConnect();
|
|
43
44
|
const { disconnect } = useDisconnect();
|
|
@@ -201,58 +202,94 @@ export function CryptoPaymentMethod({
|
|
|
201
202
|
</button>
|
|
202
203
|
|
|
203
204
|
{/* Installed Wallets Section */}
|
|
204
|
-
{isConnected && (
|
|
205
|
+
{(isConnected || globalAddress) && (
|
|
205
206
|
<div className="installed-wallets">
|
|
206
207
|
<h3 className="text-as-primary/80 mb-3 text-sm font-medium">Connected wallets</h3>
|
|
207
208
|
<div className="space-y-2">
|
|
208
209
|
{/* Current Connected Wallet */}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
<div className="flex items-center
|
|
224
|
-
|
|
225
|
-
<img src={globalWallet.meta.icon} alt="Wallet" className="h-10 w-10 rounded-full" />
|
|
226
|
-
) : (
|
|
210
|
+
{isConnected && (
|
|
211
|
+
<button
|
|
212
|
+
onClick={() => {
|
|
213
|
+
setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
214
|
+
onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
215
|
+
toast.success(`Selected ${connector?.name || "wallet"}`);
|
|
216
|
+
}}
|
|
217
|
+
className={cn(
|
|
218
|
+
"crypto-payment-method-connect-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md",
|
|
219
|
+
selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
|
|
220
|
+
? "connected-wallet border-as-brand bg-as-brand/5"
|
|
221
|
+
: "border-as-border-secondary bg-as-surface-primary hover:border-as-secondary/80",
|
|
222
|
+
)}
|
|
223
|
+
>
|
|
224
|
+
<div className="flex items-center justify-between">
|
|
225
|
+
<div className="flex items-center gap-3">
|
|
227
226
|
<div className="wallet-icon flex h-10 w-10 items-center justify-center rounded-full bg-blue-100">
|
|
228
227
|
<Wallet className="h-5 w-5 text-blue-600" />
|
|
229
228
|
</div>
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
229
|
+
<div className="flex flex-col">
|
|
230
|
+
<span className="text-as-primary font-semibold">{connector?.name || "Connected Wallet"}</span>
|
|
231
|
+
<span className="text-as-primary/60 text-sm">{shortenAddress(address || "")}</span>
|
|
232
|
+
</div>
|
|
233
|
+
</div>
|
|
234
|
+
<div className="flex items-center gap-2">
|
|
235
|
+
{selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET && (
|
|
236
|
+
<div className="h-2 w-2 rounded-full bg-green-500"></div>
|
|
237
|
+
)}
|
|
238
|
+
<button
|
|
239
|
+
onClick={e => {
|
|
240
|
+
e.stopPropagation();
|
|
241
|
+
disconnect();
|
|
242
|
+
toast.success("Wallet disconnected");
|
|
243
|
+
if (selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
244
|
+
setSelectedPaymentMethod(CryptoPaymentMethodType.NONE);
|
|
245
|
+
}
|
|
246
|
+
}}
|
|
247
|
+
className="text-as-primary/60 hover:text-as-primary/80 rounded-lg p-1.5 transition-colors"
|
|
248
|
+
>
|
|
249
|
+
<X className="h-4 w-4" />
|
|
250
|
+
</button>
|
|
234
251
|
</div>
|
|
235
252
|
</div>
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
+
</button>
|
|
254
|
+
)}
|
|
255
|
+
|
|
256
|
+
{/* Global Wallet (B3 Account) */}
|
|
257
|
+
{globalAddress && (
|
|
258
|
+
<button
|
|
259
|
+
onClick={() => {
|
|
260
|
+
setSelectedPaymentMethod(CryptoPaymentMethodType.GLOBAL_WALLET);
|
|
261
|
+
onSelectPaymentMethod(CryptoPaymentMethodType.GLOBAL_WALLET);
|
|
262
|
+
toast.success("Selected B3 Account");
|
|
263
|
+
}}
|
|
264
|
+
className={cn(
|
|
265
|
+
"crypto-payment-method-global-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md",
|
|
266
|
+
selectedPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET
|
|
267
|
+
? "connected-wallet border-as-brand bg-as-brand/5"
|
|
268
|
+
: "border-as-border-secondary bg-as-surface-primary hover:border-as-secondary/80",
|
|
269
|
+
)}
|
|
270
|
+
>
|
|
271
|
+
<div className="flex items-center justify-between">
|
|
272
|
+
<div className="flex items-center gap-3">
|
|
273
|
+
{globalWallet?.meta?.icon ? (
|
|
274
|
+
<img src={globalWallet.meta.icon} alt="Global Account" className="h-10 w-10 rounded-full" />
|
|
275
|
+
) : (
|
|
276
|
+
<div className="wallet-icon flex h-10 w-10 items-center justify-center rounded-full bg-purple-100">
|
|
277
|
+
<Wallet className="h-5 w-5 text-purple-600" />
|
|
278
|
+
</div>
|
|
279
|
+
)}
|
|
280
|
+
<div className="flex flex-col">
|
|
281
|
+
<span className="text-as-primary font-semibold">Global Account</span>
|
|
282
|
+
<span className="text-as-primary/60 text-sm">{shortenAddress(globalAddress || "")}</span>
|
|
283
|
+
</div>
|
|
284
|
+
</div>
|
|
285
|
+
<div className="flex items-center gap-2">
|
|
286
|
+
{selectedPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET && (
|
|
287
|
+
<div className="h-2 w-2 rounded-full bg-green-500"></div>
|
|
288
|
+
)}
|
|
289
|
+
</div>
|
|
253
290
|
</div>
|
|
254
|
-
</
|
|
255
|
-
|
|
291
|
+
</button>
|
|
292
|
+
)}
|
|
256
293
|
</div>
|
|
257
294
|
</div>
|
|
258
295
|
)}
|
|
@@ -240,7 +240,8 @@ export const OrderDetails = memo(function OrderDetails({
|
|
|
240
240
|
const [showQRCode, setShowQRCode] = useState(false);
|
|
241
241
|
const { isLoading: txLoading, isSuccess: txSuccess } = useWaitForTransactionReceipt({ hash: txHash });
|
|
242
242
|
|
|
243
|
-
const { switchChainAndExecuteWithEOA, isSwitchingOrExecuting } =
|
|
243
|
+
const { switchChainAndExecuteWithEOA, switchChainAndExecute, isSwitchingOrExecuting } =
|
|
244
|
+
useUnifiedChainSwitchAndExecute();
|
|
244
245
|
|
|
245
246
|
const roundedUpSrcAmount = useMemo(() => {
|
|
246
247
|
// Display the full transfer amount without rounding since users need to see the exact value they're transferring.
|
|
@@ -293,12 +294,18 @@ export const OrderDetails = memo(function OrderDetails({
|
|
|
293
294
|
value = BigInt(0);
|
|
294
295
|
}
|
|
295
296
|
|
|
296
|
-
|
|
297
|
+
// Use appropriate execution method based on payment method
|
|
298
|
+
let txHash: string | undefined;
|
|
299
|
+
if (effectiveCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET) {
|
|
300
|
+
txHash = await switchChainAndExecute(order.srcChain, { to, data: txData, value });
|
|
301
|
+
} else {
|
|
302
|
+
txHash = await switchChainAndExecuteWithEOA(order.srcChain, { to, data: txData, value });
|
|
303
|
+
}
|
|
297
304
|
|
|
298
305
|
if (txHash) {
|
|
299
306
|
setTxHash(txHash as `0x${string}`);
|
|
300
307
|
}
|
|
301
|
-
}, [order, switchChainAndExecuteWithEOA, depositDeficit]);
|
|
308
|
+
}, [order, switchChainAndExecuteWithEOA, switchChainAndExecute, depositDeficit, effectiveCryptoPaymentMethod]);
|
|
302
309
|
|
|
303
310
|
// Main payment handler that triggers chain switch and payment
|
|
304
311
|
const handlePayment = async () => {
|
|
@@ -994,7 +1001,8 @@ export const OrderDetails = memo(function OrderDetails({
|
|
|
994
1001
|
<>
|
|
995
1002
|
{order.onrampMetadata ? (
|
|
996
1003
|
<PaymentVendorUI order={order} dstTokenSymbol={dstToken.symbol} />
|
|
997
|
-
) : effectiveCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
|
|
1004
|
+
) : effectiveCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET ||
|
|
1005
|
+
effectiveCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET ? (
|
|
998
1006
|
<ConnectWalletPayment
|
|
999
1007
|
order={order}
|
|
1000
1008
|
onPayment={handlePayment}
|
|
@@ -1004,6 +1012,7 @@ export const OrderDetails = memo(function OrderDetails({
|
|
|
1004
1012
|
phantomWalletAddress={phantomWalletAddress}
|
|
1005
1013
|
tournament={tournament}
|
|
1006
1014
|
nft={nft}
|
|
1015
|
+
cryptoPaymentMethod={effectiveCryptoPaymentMethod}
|
|
1007
1016
|
/>
|
|
1008
1017
|
) : effectiveCryptoPaymentMethod === CryptoPaymentMethodType.TRANSFER_CRYPTO ? (
|
|
1009
1018
|
// Transfer Crypto Payment Method - Show new card-based UI
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useProfile, useTokenData } from "@b3dotfun/sdk/global-account/react";
|
|
2
2
|
import { formatUsername } from "@b3dotfun/sdk/shared/utils";
|
|
3
3
|
import { shortenAddress } from "@b3dotfun/sdk/shared/utils/formatAddress";
|
|
4
4
|
import { formatDisplayNumber } from "@b3dotfun/sdk/shared/utils/number";
|
|
@@ -8,12 +8,10 @@ import { useEffect, useRef } from "react";
|
|
|
8
8
|
import { useAccount } from "wagmi";
|
|
9
9
|
import { components } from "../../../types/api";
|
|
10
10
|
import { CryptoPaymentMethodType } from "./CryptoPaymentMethod";
|
|
11
|
-
import { FiatPaymentMethod } from "./FiatPaymentMethod";
|
|
12
11
|
import { OrderTokenAmount } from "./OrderTokenAmount";
|
|
13
12
|
import { TokenBalance } from "./TokenBalance";
|
|
14
13
|
|
|
15
|
-
interface
|
|
16
|
-
paymentType: "crypto" | "fiat";
|
|
14
|
+
interface CryptoPaySectionProps {
|
|
17
15
|
// Token state
|
|
18
16
|
selectedSrcChainId: number;
|
|
19
17
|
setSelectedSrcChainId: (chainId: number) => void;
|
|
@@ -24,15 +22,12 @@ interface PaySectionProps {
|
|
|
24
22
|
setIsSrcInputDirty: (dirty: boolean) => void;
|
|
25
23
|
// Payment method state
|
|
26
24
|
selectedCryptoPaymentMethod: CryptoPaymentMethodType;
|
|
27
|
-
selectedFiatPaymentMethod: FiatPaymentMethod;
|
|
28
25
|
onSelectCryptoPaymentMethod: () => void;
|
|
29
|
-
onSelectFiatPaymentMethod: () => void;
|
|
30
26
|
// Quote data
|
|
31
27
|
anyspendQuote?: any;
|
|
32
28
|
}
|
|
33
29
|
|
|
34
|
-
export function
|
|
35
|
-
paymentType,
|
|
30
|
+
export function CryptoPaySection({
|
|
36
31
|
selectedSrcChainId,
|
|
37
32
|
setSelectedSrcChainId,
|
|
38
33
|
selectedSrcToken,
|
|
@@ -41,11 +36,9 @@ export function PaySection({
|
|
|
41
36
|
setSrcAmount,
|
|
42
37
|
setIsSrcInputDirty,
|
|
43
38
|
selectedCryptoPaymentMethod,
|
|
44
|
-
selectedFiatPaymentMethod,
|
|
45
39
|
onSelectCryptoPaymentMethod,
|
|
46
|
-
onSelectFiatPaymentMethod,
|
|
47
40
|
anyspendQuote,
|
|
48
|
-
}:
|
|
41
|
+
}: CryptoPaySectionProps) {
|
|
49
42
|
const { address: connectedAddress, isConnected } = useAccount();
|
|
50
43
|
const { data: profileData } = useProfile({ address: connectedAddress });
|
|
51
44
|
const connectedName = profileData?.displayName;
|
|
@@ -88,137 +81,68 @@ export function PaySection({
|
|
|
88
81
|
>
|
|
89
82
|
<div className="flex items-center justify-between">
|
|
90
83
|
<div className="text-as-primary/50 flex h-7 items-center text-sm">Pay</div>
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
{connectedName ? formatUsername(connectedName) : shortenAddress(connectedAddress || "")}
|
|
101
|
-
</div>
|
|
102
|
-
) : (
|
|
103
|
-
"Connect wallet"
|
|
104
|
-
)}
|
|
105
|
-
<ChevronRight className="h-4 w-4" />
|
|
106
|
-
</>
|
|
107
|
-
) : selectedCryptoPaymentMethod === CryptoPaymentMethodType.TRANSFER_CRYPTO ? (
|
|
108
|
-
<>
|
|
109
|
-
Transfer crypto
|
|
110
|
-
<ChevronRight className="h-4 w-4" />
|
|
111
|
-
</>
|
|
112
|
-
) : (
|
|
113
|
-
<>
|
|
114
|
-
Select payment method
|
|
115
|
-
<ChevronRight className="h-4 w-4" />
|
|
116
|
-
</>
|
|
117
|
-
)}
|
|
118
|
-
</button>
|
|
119
|
-
) : (
|
|
120
|
-
<button
|
|
121
|
-
className="text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors"
|
|
122
|
-
onClick={onSelectFiatPaymentMethod}
|
|
123
|
-
>
|
|
124
|
-
{selectedFiatPaymentMethod === FiatPaymentMethod.COINBASE_PAY ? (
|
|
125
|
-
<>
|
|
126
|
-
<div className="flex items-center gap-2">
|
|
127
|
-
<div className="flex h-5 w-5 items-center justify-center rounded-full bg-blue-600">
|
|
128
|
-
<span className="text-xs font-bold text-white">C</span>
|
|
129
|
-
</div>
|
|
130
|
-
Coinbase Pay
|
|
84
|
+
<button
|
|
85
|
+
className="text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors focus:!outline-none"
|
|
86
|
+
onClick={onSelectCryptoPaymentMethod}
|
|
87
|
+
>
|
|
88
|
+
{selectedCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET ? (
|
|
89
|
+
<>
|
|
90
|
+
{isConnected ? (
|
|
91
|
+
<div className="flex items-center gap-1">
|
|
92
|
+
{connectedName ? formatUsername(connectedName) : shortenAddress(connectedAddress || "")}
|
|
131
93
|
</div>
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
94
|
+
) : (
|
|
95
|
+
"Connect wallet"
|
|
96
|
+
)}
|
|
97
|
+
<ChevronRight className="h-4 w-4" />
|
|
98
|
+
</>
|
|
99
|
+
) : selectedCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET ? (
|
|
100
|
+
<>
|
|
101
|
+
Global Account
|
|
102
|
+
<ChevronRight className="h-4 w-4" />
|
|
103
|
+
</>
|
|
104
|
+
) : selectedCryptoPaymentMethod === CryptoPaymentMethodType.TRANSFER_CRYPTO ? (
|
|
105
|
+
<>
|
|
106
|
+
Transfer crypto
|
|
107
|
+
<ChevronRight className="h-4 w-4" />
|
|
108
|
+
</>
|
|
109
|
+
) : (
|
|
110
|
+
<>
|
|
111
|
+
Select payment method
|
|
112
|
+
<ChevronRight className="h-4 w-4" />
|
|
113
|
+
</>
|
|
114
|
+
)}
|
|
115
|
+
</button>
|
|
116
|
+
</div>
|
|
117
|
+
<OrderTokenAmount
|
|
118
|
+
address={connectedAddress}
|
|
119
|
+
context="from"
|
|
120
|
+
inputValue={srcAmount}
|
|
121
|
+
onChangeInput={value => {
|
|
122
|
+
setIsSrcInputDirty(true);
|
|
123
|
+
setSrcAmount(value);
|
|
124
|
+
}}
|
|
125
|
+
chainId={selectedSrcChainId}
|
|
126
|
+
setChainId={setSelectedSrcChainId}
|
|
127
|
+
token={selectedSrcToken}
|
|
128
|
+
setToken={setSelectedSrcToken}
|
|
129
|
+
/>
|
|
130
|
+
<div className="flex items-center justify-between">
|
|
131
|
+
<div className="text-as-primary/50 flex h-5 items-center text-sm">
|
|
132
|
+
{formatDisplayNumber(anyspendQuote?.data?.currencyIn?.amountUsd, {
|
|
133
|
+
style: "currency",
|
|
134
|
+
fallback: "",
|
|
135
|
+
})}
|
|
136
|
+
</div>
|
|
137
|
+
<TokenBalance
|
|
138
|
+
token={selectedSrcToken}
|
|
139
|
+
walletAddress={connectedAddress}
|
|
140
|
+
onChangeInput={value => {
|
|
141
|
+
setIsSrcInputDirty(true);
|
|
142
|
+
setSrcAmount(value);
|
|
143
|
+
}}
|
|
144
|
+
/>
|
|
152
145
|
</div>
|
|
153
|
-
{paymentType === "crypto" ? (
|
|
154
|
-
<>
|
|
155
|
-
<OrderTokenAmount
|
|
156
|
-
address={connectedAddress}
|
|
157
|
-
context="from"
|
|
158
|
-
inputValue={srcAmount}
|
|
159
|
-
onChangeInput={value => {
|
|
160
|
-
setIsSrcInputDirty(true);
|
|
161
|
-
setSrcAmount(value);
|
|
162
|
-
}}
|
|
163
|
-
chainId={selectedSrcChainId}
|
|
164
|
-
setChainId={setSelectedSrcChainId}
|
|
165
|
-
token={selectedSrcToken}
|
|
166
|
-
setToken={setSelectedSrcToken}
|
|
167
|
-
/>
|
|
168
|
-
<div className="flex items-center justify-between">
|
|
169
|
-
<div className="text-as-primary/50 flex h-5 items-center text-sm">
|
|
170
|
-
{formatDisplayNumber(anyspendQuote?.data?.currencyIn?.amountUsd, {
|
|
171
|
-
style: "currency",
|
|
172
|
-
fallback: "",
|
|
173
|
-
})}
|
|
174
|
-
</div>
|
|
175
|
-
<TokenBalance
|
|
176
|
-
token={selectedSrcToken}
|
|
177
|
-
walletAddress={connectedAddress}
|
|
178
|
-
onChangeInput={value => {
|
|
179
|
-
setIsSrcInputDirty(true);
|
|
180
|
-
setSrcAmount(value);
|
|
181
|
-
}}
|
|
182
|
-
/>
|
|
183
|
-
</div>
|
|
184
|
-
</>
|
|
185
|
-
) : (
|
|
186
|
-
<>
|
|
187
|
-
{/* Fiat amount input - styled like PanelOnramp */}
|
|
188
|
-
<div className="flex items-center justify-center pb-2 pt-8">
|
|
189
|
-
<div className="flex gap-1">
|
|
190
|
-
<span className="text-as-tertiarry text-2xl font-bold">$</span>
|
|
191
|
-
<Input
|
|
192
|
-
type="text"
|
|
193
|
-
value={srcAmount}
|
|
194
|
-
onChange={e => setSrcAmount(e.target.value.replace(/[^0-9.]/g, ""))}
|
|
195
|
-
placeholder="5"
|
|
196
|
-
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"
|
|
197
|
-
style={{
|
|
198
|
-
width: `${Math.max(50, srcAmount.length * 34)}px`,
|
|
199
|
-
}}
|
|
200
|
-
/>
|
|
201
|
-
</div>
|
|
202
|
-
</div>
|
|
203
|
-
|
|
204
|
-
{/* Quick Amount Buttons */}
|
|
205
|
-
<div className="mx-auto mb-6 inline-grid grid-cols-4 gap-2">
|
|
206
|
-
{["5", "10", "20", "25"].map(value => (
|
|
207
|
-
<button
|
|
208
|
-
key={value}
|
|
209
|
-
onClick={() => setSrcAmount(value)}
|
|
210
|
-
className={`bg-as-surface-secondary border-as-border-secondary hover:border-as-border-secondary h-7 w-14 rounded-lg border text-sm font-medium transition-all duration-200 ${
|
|
211
|
-
srcAmount === value
|
|
212
|
-
? "border-as-border-secondary bg-as-surface-secondary"
|
|
213
|
-
: "bg-as-surface-secondary hover:bg-as-surface-secondary"
|
|
214
|
-
}`}
|
|
215
|
-
>
|
|
216
|
-
${value}
|
|
217
|
-
</button>
|
|
218
|
-
))}
|
|
219
|
-
</div>
|
|
220
|
-
</>
|
|
221
|
-
)}
|
|
222
146
|
</motion.div>
|
|
223
147
|
);
|
|
224
148
|
}
|
|
@@ -5,13 +5,14 @@ export { AnySpendBuySpin } from "./AnySpendBuySpin";
|
|
|
5
5
|
export { AnySpendCustom } from "./AnySpendCustom";
|
|
6
6
|
export * from "./AnySpendFingerprintWrapper";
|
|
7
7
|
export { AnySpendNFT } from "./AnySpendNFT";
|
|
8
|
-
export { AnyspendSignatureMint } from "./AnyspendSignatureMint";
|
|
9
8
|
export { AnySpendStakeB3 } from "./AnySpendStakeB3";
|
|
10
9
|
export { AnySpendTournament } from "./AnySpendTournament";
|
|
10
|
+
export { AnyspendSignatureMint } from "./AnyspendSignatureMint";
|
|
11
11
|
export { AnySpendNFTButton } from "./common/AnySpendNFTButton";
|
|
12
12
|
|
|
13
13
|
// Common Components
|
|
14
14
|
export { ChainTokenIcon } from "./common/ChainTokenIcon";
|
|
15
|
+
export { CryptoPaySection } from "./common/CryptoPaySection";
|
|
15
16
|
export { CryptoReceiveSection } from "./common/CryptoReceiveSection";
|
|
16
17
|
export { OrderDetails } from "./common/OrderDetails";
|
|
17
18
|
export { OrderDetailsCollapsible } from "./common/OrderDetailsCollapsible";
|
|
@@ -20,7 +21,6 @@ export { OrderHistoryItem } from "./common/OrderHistoryItem";
|
|
|
20
21
|
export { OrderStatus } from "./common/OrderStatus";
|
|
21
22
|
export { OrderToken } from "./common/OrderToken";
|
|
22
23
|
export { OrderTokenAmount } from "./common/OrderTokenAmount";
|
|
23
|
-
export { PaySection } from "./common/PaySection";
|
|
24
24
|
export { RecipientSelection } from "./common/RecipientSelection";
|
|
25
25
|
export { StepProgress } from "./common/StepProgress";
|
|
26
26
|
export { TokenBalance } from "./common/TokenBalance";
|