@b3dotfun/sdk 0.0.34 → 0.0.35-alpha.1
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/cjs/global-account/react/components/B3DynamicModal.js +1 -1
- package/dist/cjs/global-account/react/components/ManageAccount/ManageAccount.js +6 -3
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3.js +3 -3
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +13 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +3 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +4 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +3 -0
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +1 -0
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +20 -0
- package/dist/cjs/global-account/react/stores/useAuthStore.d.ts +4 -0
- package/dist/cjs/global-account/react/stores/useAuthStore.js +4 -0
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +2 -0
- 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/esm/global-account/react/components/B3DynamicModal.js +1 -1
- package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +6 -3
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3.js +3 -3
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +13 -1
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +3 -1
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +4 -1
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +3 -0
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +1 -0
- package/dist/esm/global-account/react/hooks/useAuthentication.js +21 -1
- package/dist/esm/global-account/react/stores/useAuthStore.d.ts +4 -0
- package/dist/esm/global-account/react/stores/useAuthStore.js +4 -0
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +2 -0
- 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/dist/types/global-account/react/hooks/useAuthentication.d.ts +1 -0
- package/dist/types/global-account/react/stores/useAuthStore.d.ts +4 -0
- package/dist/types/global-account/react/stores/useModalStore.d.ts +2 -0
- package/package.json +1 -1
- 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
- package/src/global-account/react/components/B3DynamicModal.tsx +1 -6
- package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +92 -82
- package/src/global-account/react/components/SignInWithB3/SignInWithB3.tsx +3 -3
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +13 -1
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +3 -1
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +5 -2
- package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +3 -0
- package/src/global-account/react/hooks/useAuthentication.ts +24 -1
- package/src/global-account/react/stores/useAuthStore.ts +8 -0
- package/src/global-account/react/stores/useModalStore.ts +2 -0
- package/src/styles/index.css +5 -2
|
@@ -13,10 +13,11 @@ export var CryptoPaymentMethodType;
|
|
|
13
13
|
(function (CryptoPaymentMethodType) {
|
|
14
14
|
CryptoPaymentMethodType["NONE"] = "none";
|
|
15
15
|
CryptoPaymentMethodType["CONNECT_WALLET"] = "connect_wallet";
|
|
16
|
+
CryptoPaymentMethodType["GLOBAL_WALLET"] = "global_wallet";
|
|
16
17
|
CryptoPaymentMethodType["TRANSFER_CRYPTO"] = "transfer_crypto";
|
|
17
18
|
})(CryptoPaymentMethodType || (CryptoPaymentMethodType = {}));
|
|
18
19
|
export function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentMethod, isCreatingOrder, onBack, onSelectPaymentMethod, }) {
|
|
19
|
-
const { wallet: globalWallet } = useAccountWallet();
|
|
20
|
+
const { wallet: globalWallet, address: globalAddress } = useAccountWallet();
|
|
20
21
|
const { address, isConnected, connector } = useAccount();
|
|
21
22
|
const { connect, connectors, isPending } = useConnect();
|
|
22
23
|
const { disconnect } = useDisconnect();
|
|
@@ -122,20 +123,26 @@ export function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentM
|
|
|
122
123
|
}, 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: () => {
|
|
123
124
|
setSelectedPaymentMethod(CryptoPaymentMethodType.TRANSFER_CRYPTO);
|
|
124
125
|
onSelectPaymentMethod(CryptoPaymentMethodType.TRANSFER_CRYPTO);
|
|
125
|
-
}, 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" }),
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
126
|
+
}, 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 || globalAddress) && (_jsxs("div", { className: "installed-wallets", children: [_jsx("h3", { className: "text-as-primary/80 mb-3 text-sm font-medium", children: "Connected wallets" }), _jsxs("div", { className: "space-y-2", children: [isConnected && (_jsx("button", { onClick: () => {
|
|
127
|
+
setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
128
|
+
onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
129
|
+
toast.success(`Selected ${connector?.name || "wallet"}`);
|
|
130
|
+
}, 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
|
|
131
|
+
? "connected-wallet border-as-brand bg-as-brand/5"
|
|
132
|
+
: "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: [_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 => {
|
|
133
|
+
e.stopPropagation();
|
|
134
|
+
disconnect();
|
|
135
|
+
toast.success("Wallet disconnected");
|
|
136
|
+
if (selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
137
|
+
setSelectedPaymentMethod(CryptoPaymentMethodType.NONE);
|
|
138
|
+
}
|
|
139
|
+
}, 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" }) })] })] }) })), globalAddress && (_jsx("button", { onClick: () => {
|
|
140
|
+
setSelectedPaymentMethod(CryptoPaymentMethodType.GLOBAL_WALLET);
|
|
141
|
+
onSelectPaymentMethod(CryptoPaymentMethodType.GLOBAL_WALLET);
|
|
142
|
+
toast.success("Selected B3 Account");
|
|
143
|
+
}, className: cn("crypto-payment-method-global-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md", selectedPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET
|
|
144
|
+
? "connected-wallet border-as-brand bg-as-brand/5"
|
|
145
|
+
: "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: "Global Account", className: "h-10 w-10 rounded-full" })) : (_jsx("div", { className: "wallet-icon flex h-10 w-10 items-center justify-center rounded-full bg-purple-100", children: _jsx(Wallet, { className: "h-5 w-5 text-purple-600" }) })), _jsxs("div", { className: "flex flex-col", children: [_jsx("span", { className: "text-as-primary font-semibold", children: "Global Account" }), _jsx("span", { className: "text-as-primary/60 text-sm", children: shortenAddress(globalAddress || "") })] })] }), _jsx("div", { className: "flex items-center gap-2", children: selectedPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET && (_jsx("div", { className: "h-2 w-2 rounded-full bg-green-500" })) })] }) }))] })] }))] })] }), showWalletModal &&
|
|
139
146
|
createPortal(_jsx("div", { className: "wallet-connection-modal 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: [_jsx("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white", children: isConnected ? "Switch wallet or account" : "Choose wallet to connect" }), _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: _jsx("div", { className: "space-y-3", children: walletOptions.map(walletOption => {
|
|
140
147
|
const isCurrentWallet = isConnected && connector?.name === walletOption.connector?.name;
|
|
141
148
|
return (_jsx("button", { onClick: async () => {
|
|
@@ -148,7 +148,7 @@ export const OrderDetails = memo(function OrderDetails({ mode = "modal", order,
|
|
|
148
148
|
const [txHash, setTxHash] = useState();
|
|
149
149
|
const [showQRCode, setShowQRCode] = useState(false);
|
|
150
150
|
const { isLoading: txLoading, isSuccess: txSuccess } = useWaitForTransactionReceipt({ hash: txHash });
|
|
151
|
-
const { switchChainAndExecuteWithEOA, isSwitchingOrExecuting } = useUnifiedChainSwitchAndExecute();
|
|
151
|
+
const { switchChainAndExecuteWithEOA, switchChainAndExecute, isSwitchingOrExecuting } = useUnifiedChainSwitchAndExecute();
|
|
152
152
|
const roundedUpSrcAmount = useMemo(() => {
|
|
153
153
|
// Display the full transfer amount without rounding since users need to see the exact value they're transferring.
|
|
154
154
|
// Use 21 significant digits (max allowed by Intl.NumberFormat)
|
|
@@ -192,11 +192,18 @@ export const OrderDetails = memo(function OrderDetails({ mode = "modal", order,
|
|
|
192
192
|
to = order.srcTokenAddress;
|
|
193
193
|
value = BigInt(0);
|
|
194
194
|
}
|
|
195
|
-
|
|
195
|
+
// Use appropriate execution method based on payment method
|
|
196
|
+
let txHash;
|
|
197
|
+
if (effectiveCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET) {
|
|
198
|
+
txHash = await switchChainAndExecute(order.srcChain, { to, data: txData, value });
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
txHash = await switchChainAndExecuteWithEOA(order.srcChain, { to, data: txData, value });
|
|
202
|
+
}
|
|
196
203
|
if (txHash) {
|
|
197
204
|
setTxHash(txHash);
|
|
198
205
|
}
|
|
199
|
-
}, [order, switchChainAndExecuteWithEOA, depositDeficit]);
|
|
206
|
+
}, [order, switchChainAndExecuteWithEOA, switchChainAndExecute, depositDeficit, effectiveCryptoPaymentMethod]);
|
|
200
207
|
// Main payment handler that triggers chain switch and payment
|
|
201
208
|
const handlePayment = async () => {
|
|
202
209
|
console.log("Initiating payment process. Target chain:", order.srcChain, "Current chain:", walletClient?.chain?.id);
|
|
@@ -475,7 +482,8 @@ export const OrderDetails = memo(function OrderDetails({ mode = "modal", order,
|
|
|
475
482
|
? `Waiting for payment`
|
|
476
483
|
: `Waiting for deposit ${formattedDepositDeficit} ${srcToken.symbol}`, chainId: order.srcChain, tx: null, isProcessing: true, delay: 0.5 }))] }) })] }) }), !depositEnoughAmount && order.status !== "expired" && (_jsx(InsufficientDepositPayment, { order: order, srcToken: srcToken, depositDeficit: depositDeficit, phantomWalletAddress: phantomWalletAddress, txLoading: txLoading, isSwitchingOrExecuting: isSwitchingOrExecuting, onPayment: handlePayment }))] }));
|
|
477
484
|
}
|
|
478
|
-
return (_jsxs(_Fragment, { children: [statusDisplay === "processing" && (_jsx(_Fragment, { children: order.onrampMetadata ? (_jsx(PaymentVendorUI, { order: order, dstTokenSymbol: dstToken.symbol })) : effectiveCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
|
|
485
|
+
return (_jsxs(_Fragment, { children: [statusDisplay === "processing" && (_jsx(_Fragment, { children: order.onrampMetadata ? (_jsx(PaymentVendorUI, { order: order, dstTokenSymbol: dstToken.symbol })) : effectiveCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET ||
|
|
486
|
+
effectiveCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET ? (_jsx(ConnectWalletPayment, { order: order, onPayment: handlePayment, onCancel: handleBack, txLoading: txLoading, isSwitchingOrExecuting: isSwitchingOrExecuting, phantomWalletAddress: phantomWalletAddress, tournament: tournament, nft: nft, cryptoPaymentMethod: effectiveCryptoPaymentMethod })) : effectiveCryptoPaymentMethod === CryptoPaymentMethodType.TRANSFER_CRYPTO ? (
|
|
479
487
|
// Transfer Crypto Payment Method - Show new card-based UI
|
|
480
488
|
_jsx(TransferCryptoDetails, { order: order, recipientName: recipientName, srcToken: srcToken, dstToken: dstToken, tournament: tournament, nft: nft, onBack: handleBack })) : (_jsxs("div", { className: "relative flex w-full flex-1 flex-col", children: [_jsxs("div", { className: "flex flex-col gap-1", children: [_jsx("span", { className: "text-as-primary/50", children: "Please send" }), _jsxs("div", { className: "flex w-full flex-wrap items-center gap-6 sm:justify-between sm:gap-0", children: [_jsx(CopyToClipboard, { text: roundedUpSrcAmount, onCopy: () => {
|
|
481
489
|
toast.success("Copied to clipboard");
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { components } from "../../../types/api";
|
|
2
2
|
import { CryptoPaymentMethodType } from "./CryptoPaymentMethod";
|
|
3
|
-
|
|
4
|
-
interface PaySectionProps {
|
|
5
|
-
paymentType: "crypto" | "fiat";
|
|
3
|
+
interface CryptoPaySectionProps {
|
|
6
4
|
selectedSrcChainId: number;
|
|
7
5
|
setSelectedSrcChainId: (chainId: number) => void;
|
|
8
6
|
selectedSrcToken: components["schemas"]["Token"];
|
|
@@ -11,10 +9,8 @@ interface PaySectionProps {
|
|
|
11
9
|
setSrcAmount: (amount: string) => void;
|
|
12
10
|
setIsSrcInputDirty: (dirty: boolean) => void;
|
|
13
11
|
selectedCryptoPaymentMethod: CryptoPaymentMethodType;
|
|
14
|
-
selectedFiatPaymentMethod: FiatPaymentMethod;
|
|
15
12
|
onSelectCryptoPaymentMethod: () => void;
|
|
16
|
-
onSelectFiatPaymentMethod: () => void;
|
|
17
13
|
anyspendQuote?: any;
|
|
18
14
|
}
|
|
19
|
-
export declare function
|
|
15
|
+
export declare function CryptoPaySection({ selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, setIsSrcInputDirty, selectedCryptoPaymentMethod, onSelectCryptoPaymentMethod, anyspendQuote, }: CryptoPaySectionProps): import("react/jsx-runtime").JSX.Element;
|
|
20
16
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { 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";
|
|
@@ -8,10 +8,9 @@ import { motion } from "motion/react";
|
|
|
8
8
|
import { useEffect, useRef } from "react";
|
|
9
9
|
import { useAccount } from "wagmi";
|
|
10
10
|
import { CryptoPaymentMethodType } from "./CryptoPaymentMethod.js";
|
|
11
|
-
import { FiatPaymentMethod } from "./FiatPaymentMethod.js";
|
|
12
11
|
import { OrderTokenAmount } from "./OrderTokenAmount.js";
|
|
13
12
|
import { TokenBalance } from "./TokenBalance.js";
|
|
14
|
-
export function
|
|
13
|
+
export function CryptoPaySection({ selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, setIsSrcInputDirty, selectedCryptoPaymentMethod, onSelectCryptoPaymentMethod, anyspendQuote, }) {
|
|
15
14
|
const { address: connectedAddress, isConnected } = useAccount();
|
|
16
15
|
const { data: profileData } = useProfile({ address: connectedAddress });
|
|
17
16
|
const connectedName = profileData?.displayName;
|
|
@@ -40,18 +39,14 @@ export function PaySection({ paymentType, selectedSrcChainId, setSelectedSrcChai
|
|
|
40
39
|
useEffect(() => {
|
|
41
40
|
appliedSrcMetadataRef.current = false;
|
|
42
41
|
}, [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: [_jsx("div", { className: "text-as-primary/50 flex h-7 items-center text-sm", children: "Pay" }),
|
|
42
|
+
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: [_jsx("div", { className: "text-as-primary/50 flex h-7 items-center text-sm", children: "Pay" }), _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.GLOBAL_WALLET ? (_jsxs(_Fragment, { children: ["Global Account", _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(OrderTokenAmount, { address: connectedAddress, context: "from", inputValue: srcAmount, onChangeInput: value => {
|
|
43
|
+
setIsSrcInputDirty(true);
|
|
44
|
+
setSrcAmount(value);
|
|
45
|
+
}, 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, {
|
|
46
|
+
style: "currency",
|
|
47
|
+
fallback: "",
|
|
48
|
+
}) }), _jsx(TokenBalance, { token: selectedSrcToken, walletAddress: connectedAddress, onChangeInput: value => {
|
|
44
49
|
setIsSrcInputDirty(true);
|
|
45
50
|
setSrcAmount(value);
|
|
46
|
-
}
|
|
47
|
-
style: "currency",
|
|
48
|
-
fallback: "",
|
|
49
|
-
}) }), _jsx(TokenBalance, { token: selectedSrcToken, walletAddress: connectedAddress, onChangeInput: value => {
|
|
50
|
-
setIsSrcInputDirty(true);
|
|
51
|
-
setSrcAmount(value);
|
|
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: {
|
|
53
|
-
width: `${Math.max(50, srcAmount.length * 34)}px`,
|
|
54
|
-
} })] }) }), _jsx("div", { className: "mx-auto mb-6 inline-grid grid-cols-4 gap-2", children: ["5", "10", "20", "25"].map(value => (_jsxs("button", { onClick: () => setSrcAmount(value), 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 ${srcAmount === value
|
|
55
|
-
? "border-as-border-secondary bg-as-surface-secondary"
|
|
56
|
-
: "bg-as-surface-secondary hover:bg-as-surface-secondary"}`, children: ["$", value] }, value))) })] }))] }));
|
|
51
|
+
} })] })] }));
|
|
57
52
|
}
|
|
@@ -4,11 +4,12 @@ export { AnySpendBuySpin } from "./AnySpendBuySpin";
|
|
|
4
4
|
export { AnySpendCustom } from "./AnySpendCustom";
|
|
5
5
|
export * from "./AnySpendFingerprintWrapper";
|
|
6
6
|
export { AnySpendNFT } from "./AnySpendNFT";
|
|
7
|
-
export { AnyspendSignatureMint } from "./AnyspendSignatureMint";
|
|
8
7
|
export { AnySpendStakeB3 } from "./AnySpendStakeB3";
|
|
9
8
|
export { AnySpendTournament } from "./AnySpendTournament";
|
|
9
|
+
export { AnyspendSignatureMint } from "./AnyspendSignatureMint";
|
|
10
10
|
export { AnySpendNFTButton } from "./common/AnySpendNFTButton";
|
|
11
11
|
export { ChainTokenIcon } from "./common/ChainTokenIcon";
|
|
12
|
+
export { CryptoPaySection } from "./common/CryptoPaySection";
|
|
12
13
|
export { CryptoReceiveSection } from "./common/CryptoReceiveSection";
|
|
13
14
|
export { OrderDetails } from "./common/OrderDetails";
|
|
14
15
|
export { OrderDetailsCollapsible } from "./common/OrderDetailsCollapsible";
|
|
@@ -17,7 +18,6 @@ export { OrderHistoryItem } from "./common/OrderHistoryItem";
|
|
|
17
18
|
export { OrderStatus } from "./common/OrderStatus";
|
|
18
19
|
export { OrderToken } from "./common/OrderToken";
|
|
19
20
|
export { OrderTokenAmount } from "./common/OrderTokenAmount";
|
|
20
|
-
export { PaySection } from "./common/PaySection";
|
|
21
21
|
export { RecipientSelection } from "./common/RecipientSelection";
|
|
22
22
|
export { StepProgress } from "./common/StepProgress";
|
|
23
23
|
export { TokenBalance } from "./common/TokenBalance";
|
|
@@ -5,12 +5,13 @@ export { AnySpendBuySpin } from "./AnySpendBuySpin.js";
|
|
|
5
5
|
export { AnySpendCustom } from "./AnySpendCustom.js";
|
|
6
6
|
export * from "./AnySpendFingerprintWrapper.js";
|
|
7
7
|
export { AnySpendNFT } from "./AnySpendNFT.js";
|
|
8
|
-
export { AnyspendSignatureMint } from "./AnyspendSignatureMint.js";
|
|
9
8
|
export { AnySpendStakeB3 } from "./AnySpendStakeB3.js";
|
|
10
9
|
export { AnySpendTournament } from "./AnySpendTournament.js";
|
|
10
|
+
export { AnyspendSignatureMint } from "./AnyspendSignatureMint.js";
|
|
11
11
|
export { AnySpendNFTButton } from "./common/AnySpendNFTButton.js";
|
|
12
12
|
// Common Components
|
|
13
13
|
export { ChainTokenIcon } from "./common/ChainTokenIcon.js";
|
|
14
|
+
export { CryptoPaySection } from "./common/CryptoPaySection.js";
|
|
14
15
|
export { CryptoReceiveSection } from "./common/CryptoReceiveSection.js";
|
|
15
16
|
export { OrderDetails } from "./common/OrderDetails.js";
|
|
16
17
|
export { OrderDetailsCollapsible } from "./common/OrderDetailsCollapsible.js";
|
|
@@ -19,7 +20,6 @@ export { OrderHistoryItem } from "./common/OrderHistoryItem.js";
|
|
|
19
20
|
export { OrderStatus } from "./common/OrderStatus.js";
|
|
20
21
|
export { OrderToken } from "./common/OrderToken.js";
|
|
21
22
|
export { OrderTokenAmount } from "./common/OrderTokenAmount.js";
|
|
22
|
-
export { PaySection } from "./common/PaySection.js";
|
|
23
23
|
export { RecipientSelection } from "./common/RecipientSelection.js";
|
|
24
24
|
export { StepProgress } from "./common/StepProgress.js";
|
|
25
25
|
export { TokenBalance } from "./common/TokenBalance.js";
|
|
@@ -89,5 +89,5 @@ export function B3DynamicModal() {
|
|
|
89
89
|
const ModalContent = isMobile ? DrawerContent : DialogContent;
|
|
90
90
|
const ModalTitle = isMobile ? DrawerTitle : DialogTitle;
|
|
91
91
|
const ModalDescription = isMobile ? DrawerDescription : DialogDescription;
|
|
92
|
-
return (_jsx(ModalComponent, { open: isOpen, onOpenChange: setB3ModalOpen, children: _jsxs(ModalContent, { className: cn(contentClass, "rounded-2xl bg-white shadow-xl dark:bg-gray-900", "border border-gray-200 dark:border-gray-800", "mx-auto w-full max-w-md", "sm:max-w-lg sm:rounded-b-none"), hideCloseButton: hideCloseButton, children: [_jsx(ModalTitle, { className: "sr-only hidden", children: contentType?.type || "Modal" }), _jsx(ModalDescription, { className: "sr-only hidden", children: contentType?.type || "Modal Body" }), _jsxs("div", { className: cn("no-scrollbar max-h-[90dvh] overflow-auto sm:max-h-[80dvh]"
|
|
92
|
+
return (_jsx(ModalComponent, { open: isOpen, onOpenChange: setB3ModalOpen, children: _jsxs(ModalContent, { className: cn(contentClass, "rounded-2xl bg-white shadow-xl dark:bg-gray-900", "border border-gray-200 dark:border-gray-800", "mx-auto w-full max-w-md", "sm:max-w-lg sm:rounded-b-none"), hideCloseButton: hideCloseButton, children: [_jsx(ModalTitle, { className: "sr-only hidden", children: contentType?.type || "Modal" }), _jsx(ModalDescription, { className: "sr-only hidden", children: contentType?.type || "Modal Body" }), _jsxs("div", { className: cn("no-scrollbar max-h-[90dvh] overflow-auto sm:max-h-[80dvh]"), children: [history.length > 0 && contentType?.showBackButton && (_jsxs("button", { onClick: navigateBack, className: "flex items-center gap-2 px-6 py-4 text-gray-600 transition-colors hover:text-gray-900 dark:text-gray-400 dark:hover:text-white", children: [_jsxs("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [_jsx("path", { d: "M15.8337 10H4.16699", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }), _jsx("path", { d: "M10.0003 15.8334L4.16699 10L10.0003 4.16669", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })] }), _jsx("span", { className: "text-sm font-medium", children: "Back" })] })), renderContent()] })] }) }));
|
|
93
93
|
}
|
|
@@ -53,13 +53,14 @@ export function ManageAccount({ onLogout, onSwap: _onSwap, onDeposit: _onDeposit
|
|
|
53
53
|
const [unlinkingAccountId, setUnlinkingAccountId] = useState(null);
|
|
54
54
|
const { data: profilesRaw = [], isLoading: isLoadingProfiles } = useProfiles({ client });
|
|
55
55
|
const { mutate: unlinkProfile, isPending: isUnlinking } = useUnlinkProfile();
|
|
56
|
-
const { setB3ModalOpen, setB3ModalContentType, isLinking } = useModalStore();
|
|
56
|
+
const { setB3ModalOpen, setB3ModalContentType, isLinking, contentType } = useModalStore();
|
|
57
57
|
const { user, setUser } = useB3();
|
|
58
58
|
const [isUpdatingCode, setIsUpdatingCode] = useState(false);
|
|
59
59
|
const [newReferralCode, setNewReferralCode] = useState("");
|
|
60
60
|
const [isEditingCode, setIsEditingCode] = useState(false);
|
|
61
61
|
const referallCodeRef = useRef(null);
|
|
62
62
|
const { data: referrals, isLoading: isLoadingReferrals } = useQueryB3("referrals", "find", { query: { referrerId: user?.userId } }, !!user?.userId);
|
|
63
|
+
const showReferralInfo = contentType?.showReferralInfo ?? false;
|
|
63
64
|
const mutationOptions = {
|
|
64
65
|
onError: (error) => {
|
|
65
66
|
console.error("Error Unlinking account:", error);
|
|
@@ -145,7 +146,9 @@ export function ManageAccount({ onLogout, onSwap: _onSwap, onDeposit: _onDeposit
|
|
|
145
146
|
},
|
|
146
147
|
});
|
|
147
148
|
};
|
|
148
|
-
return (_jsxs("div", { className: "space-y-8", children: [_jsxs("div", { className: "space-y-4", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("h3", { className: "text-b3-grey font-neue-montreal-semibold text-xl", children: "Linked Accounts" }), _jsxs(Button, { className: "bg-b3-primary-wash hover:bg-b3-primary-wash/70 flex items-center gap-2 rounded-full px-4 py-2", onClick: handleOpenLinkModal, disabled: isLinking, children: [isLinking ? (_jsx(Loader2, { className: "text-b3-primary-blue animate-spin", size: 16 })) : (_jsx(LinkIcon, { size: 16, className: "text-b3-primary-blue" })), _jsx("span", { className: "text-b3-grey font-neue-montreal-semibold", children: isLinking ? "Linking..." : "Link New Account" })] })] }), isLoadingProfiles ? (_jsx("div", { className: "flex justify-center py-8", children: _jsx(Loader2, { className: "text-b3-grey animate-spin" }) })) : profiles.length > 0 ? (_jsx("div", { className: "space-y-4", children: profiles.map(profile => (_jsxs("div", { className: "bg-b3-line flex items-center justify-between rounded-xl p-4", children: [_jsxs("div", { className: "flex items-center gap-3", children: [profile.imageUrl ? (_jsx("img", { src: profile.imageUrl, alt: profile.title, className: "size-10 rounded-full" })) : (_jsx("div", { className: "bg-b3-primary-wash flex h-10 w-10 items-center justify-center rounded-full", children: _jsx("span", { className: "text-b3-grey font-neue-montreal-semibold text-sm uppercase", children: profile.initial }) })), _jsxs("div", { children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "text-b3-grey font-neue-montreal-semibold", children: profile.title }), _jsx("span", { className: "text-b3-foreground-muted font-neue-montreal-medium bg-b3-primary-wash rounded px-2 py-0.5 text-xs", children: profile.type.toUpperCase() })] }), _jsx("div", { className: "text-b3-foreground-muted font-neue-montreal-medium text-sm", children: profile.subtitle })] })] }), _jsx(Button, { variant: "ghost", size: "icon", className: "text-b3-grey hover:text-b3-negative", onClick: () => handleUnlink(profile), disabled: unlinkingAccountId === profile.title || isUnlinking, children: unlinkingAccountId === profile.title || isUnlinking ? (_jsx(Loader2, { className: "animate-spin" })) : (_jsx(UnlinkIcon, { size: 16 })) })] }, profile.title))) })) : (_jsx("div", { className: "text-b3-foreground-muted py-8 text-center", children: "No linked accounts found" }))] }),
|
|
149
|
+
return (_jsxs("div", { className: "space-y-8", children: [_jsxs("div", { className: "space-y-4", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("h3", { className: "text-b3-grey font-neue-montreal-semibold text-xl", children: "Linked Accounts" }), _jsxs(Button, { className: "bg-b3-primary-wash hover:bg-b3-primary-wash/70 flex items-center gap-2 rounded-full px-4 py-2", onClick: handleOpenLinkModal, disabled: isLinking, children: [isLinking ? (_jsx(Loader2, { className: "text-b3-primary-blue animate-spin", size: 16 })) : (_jsx(LinkIcon, { size: 16, className: "text-b3-primary-blue" })), _jsx("span", { className: "text-b3-grey font-neue-montreal-semibold", children: isLinking ? "Linking..." : "Link New Account" })] })] }), isLoadingProfiles ? (_jsx("div", { className: "flex justify-center py-8", children: _jsx(Loader2, { className: "text-b3-grey animate-spin" }) })) : profiles.length > 0 ? (_jsx("div", { className: "space-y-4", children: profiles.map(profile => (_jsxs("div", { className: "bg-b3-line flex items-center justify-between rounded-xl p-4", children: [_jsxs("div", { className: "flex items-center gap-3", children: [profile.imageUrl ? (_jsx("img", { src: profile.imageUrl, alt: profile.title, className: "size-10 rounded-full" })) : (_jsx("div", { className: "bg-b3-primary-wash flex h-10 w-10 items-center justify-center rounded-full", children: _jsx("span", { className: "text-b3-grey font-neue-montreal-semibold text-sm uppercase", children: profile.initial }) })), _jsxs("div", { children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "text-b3-grey font-neue-montreal-semibold", children: profile.title }), _jsx("span", { className: "text-b3-foreground-muted font-neue-montreal-medium bg-b3-primary-wash rounded px-2 py-0.5 text-xs", children: profile.type.toUpperCase() })] }), _jsx("div", { className: "text-b3-foreground-muted font-neue-montreal-medium text-sm", children: profile.subtitle })] })] }), _jsx(Button, { variant: "ghost", size: "icon", className: "text-b3-grey hover:text-b3-negative", onClick: () => handleUnlink(profile), disabled: unlinkingAccountId === profile.title || isUnlinking, children: unlinkingAccountId === profile.title || isUnlinking ? (_jsx(Loader2, { className: "animate-spin" })) : (_jsx(UnlinkIcon, { size: 16 })) })] }, profile.title))) })) : (_jsx("div", { className: "text-b3-foreground-muted py-8 text-center", children: "No linked accounts found" }))] }), showReferralInfo && (
|
|
150
|
+
/* Referral Section */
|
|
151
|
+
_jsxs("div", { className: "space-y-4", children: [_jsx("h3", { className: "text-b3-grey font-neue-montreal-semibold text-xl", children: "Referrals" }), _jsxs("div", { className: "bg-b3-line rounded-xl p-4", children: [isEditingCode && (_jsxs("div", { children: [_jsx("div", { className: "text-b3-grey font-neue-montreal-semibold", children: "Your Referral Code" }), _jsx("div", { className: "text-b3-foreground-muted font-neue-montreal-medium text-sm", children: "Share this code with friends to earn rewards" })] })), _jsxs("div", { className: "flex items-center justify-between", children: [!isEditingCode && (_jsxs("div", { children: [_jsx("div", { className: "text-b3-grey font-neue-montreal-semibold", children: "Your Referral Code" }), _jsx("div", { className: "text-b3-foreground-muted font-neue-montreal-medium text-sm", children: "Share this code with friends to earn rewards" })] })), _jsx("div", { className: "flex items-center gap-2", children: isEditingCode ? (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("input", { type: "text", value: newReferralCode, onChange: e => setNewReferralCode(e.target.value), className: "rounded-lg border border-gray-200 bg-white px-3 py-1.5 text-sm", placeholder: "Enter new code", ref: referallCodeRef }), _jsx(Button, { size: "sm", onClick: handleUpdateReferralCode, disabled: isUpdatingCode || !newReferralCode, children: isUpdatingCode ? _jsx(Loader2, { className: "h-4 w-4 animate-spin" }) : "Save" }), _jsx(Button, { size: "sm", variant: "ghost", onClick: () => {
|
|
149
152
|
setIsEditingCode(false);
|
|
150
153
|
setNewReferralCode("");
|
|
151
154
|
}, children: "Cancel" })] })) : (_jsxs(_Fragment, { children: [_jsx("div", { className: "rounded-lg border border-gray-200 bg-white px-3 py-1.5 text-sm", children: currentReferralCode }), _jsx(Button, { size: "icon", variant: "ghost", onClick: handleCopyCode, children: _jsx(Copy, { className: "h-4 w-4" }) }), _jsx(Button, { size: "icon", variant: "ghost", onClick: () => {
|
|
@@ -153,7 +156,7 @@ export function ManageAccount({ onLogout, onSwap: _onSwap, onDeposit: _onDeposit
|
|
|
153
156
|
setTimeout(() => {
|
|
154
157
|
referallCodeRef.current?.focus();
|
|
155
158
|
}, 100);
|
|
156
|
-
}, children: _jsx(Pencil, { className: "h-4 w-4" }) })] })) })] })] }), _jsxs("div", { className: "bg-b3-line rounded-xl p-4", children: [_jsx("div", { className: "text-b3-grey font-neue-montreal-semibold mb-4", children: "Referred Users" }), isLoadingReferrals ? (_jsx("div", { className: "flex justify-center py-4", children: _jsx(Loader2, { className: "h-6 w-6 animate-spin text-gray-400" }) })) : referrals?.data?.length ? (_jsx("div", { className: "space-y-3", children: referrals.data.map((referral) => (_jsxs("div", { className: "flex items-center justify-between rounded-lg bg-white p-3", children: [_jsx("div", { className: "text-sm font-medium", children: referral.referreeId }), _jsx("div", { className: "text-sm text-gray-500", children: new Date(referral.createdAt).toLocaleDateString() })] }, String(referral._id)))) })) : (_jsx("div", { className: "py-4 text-center text-gray-500", children: "No referred users yet" }))] })] }), _jsxs("div", { className: "space-y-4", children: [_jsx("h3", { className: "text-b3-grey font-neue-montreal-semibold text-xl", children: "Account Preferences" }), _jsx("div", { className: "bg-b3-line rounded-xl p-4", children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { children: [_jsx("div", { className: "text-b3-grey font-neue-montreal-semibold", children: "Dark Mode" }), _jsx("div", { className: "text-b3-foreground-muted font-neue-montreal-medium text-sm", children: "Switch between light and dark theme" })] }), _jsx("div", { className: "bg-b3-primary-wash h-6 w-12 rounded-full" })] }) })] }), _jsxs("div", { className: "border-b3-line flex items-center justify-between rounded-2xl border p-4", children: [_jsxs("div", { children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("img", { src: "https://cdn.b3.fun/b3_logo.svg", alt: "B3", className: "h-4" }), _jsx("h3", { className: "font-neue-montreal-semibold text-b3-grey", children: "Global Account" })] }), _jsx("p", { className: "text-b3-foreground-muted font-neue-montreal-medium mt-2 text-sm", children: "Your universal account for all B3 apps" })] }), _jsx("button", { className: "text-b3-grey hover:text-b3-grey/80 hover:bg-b3-line border-b3-line flex size-12 items-center justify-center rounded-full border", onClick: onLogoutEnhanced, children: logoutLoading ? _jsx(Loader2, { className: "animate-spin" }) : _jsx(SignOutIcon, { size: 16, className: "text-b3-grey" }) })] })] }));
|
|
159
|
+
}, children: _jsx(Pencil, { className: "h-4 w-4" }) })] })) })] })] }), _jsxs("div", { className: "bg-b3-line rounded-xl p-4", children: [_jsx("div", { className: "text-b3-grey font-neue-montreal-semibold mb-4", children: "Referred Users" }), isLoadingReferrals ? (_jsx("div", { className: "flex justify-center py-4", children: _jsx(Loader2, { className: "h-6 w-6 animate-spin text-gray-400" }) })) : referrals?.data?.length ? (_jsx("div", { className: "space-y-3", children: referrals.data.map((referral) => (_jsxs("div", { className: "flex items-center justify-between rounded-lg bg-white p-3", children: [_jsx("div", { className: "text-sm font-medium", children: referral.referreeId }), _jsx("div", { className: "text-sm text-gray-500", children: new Date(referral.createdAt).toLocaleDateString() })] }, String(referral._id)))) })) : (_jsx("div", { className: "py-4 text-center text-gray-500", children: "No referred users yet" }))] })] })), _jsxs("div", { className: "space-y-4", children: [_jsx("h3", { className: "text-b3-grey font-neue-montreal-semibold text-xl", children: "Account Preferences" }), _jsx("div", { className: "bg-b3-line rounded-xl p-4", children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { children: [_jsx("div", { className: "text-b3-grey font-neue-montreal-semibold", children: "Dark Mode" }), _jsx("div", { className: "text-b3-foreground-muted font-neue-montreal-medium text-sm", children: "Switch between light and dark theme" })] }), _jsx("div", { className: "bg-b3-primary-wash h-6 w-12 rounded-full" })] }) })] }), _jsxs("div", { className: "border-b3-line flex items-center justify-between rounded-2xl border p-4", children: [_jsxs("div", { children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("img", { src: "https://cdn.b3.fun/b3_logo.svg", alt: "B3", className: "h-4" }), _jsx("h3", { className: "font-neue-montreal-semibold text-b3-grey", children: "Global Account" })] }), _jsx("p", { className: "text-b3-foreground-muted font-neue-montreal-medium mt-2 text-sm", children: "Your universal account for all B3 apps" })] }), _jsx("button", { className: "text-b3-grey hover:text-b3-grey/80 hover:bg-b3-line border-b3-line flex size-12 items-center justify-center rounded-full border", onClick: onLogoutEnhanced, children: logoutLoading ? _jsx(Loader2, { className: "animate-spin" }) : _jsx(SignOutIcon, { size: 16, className: "text-b3-grey" }) })] })] }));
|
|
157
160
|
};
|
|
158
161
|
return (_jsx("div", { className: "b3-manage-account bg-b3-background flex flex-col rounded-xl", children: _jsx("div", { className: "flex-1", children: _jsxs(TabsPrimitive, { defaultValue: activeTab, onValueChange: value => {
|
|
159
162
|
const tab = value;
|
|
@@ -6,7 +6,7 @@ import { Loading } from "../ui/Loading.js";
|
|
|
6
6
|
export function SignInWithB3(props) {
|
|
7
7
|
const { setB3ModalOpen, setB3ModalContentType, setEcoSystemAccountAddress } = useModalStore();
|
|
8
8
|
const { account } = useB3();
|
|
9
|
-
const {
|
|
9
|
+
const { isAuthenticatingV2, isAuthenticated } = useAuthentication(props.partnerId, props.loginWithSiwe);
|
|
10
10
|
const isMobile = useIsMobile();
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
if (account) {
|
|
@@ -21,10 +21,10 @@ export function SignInWithB3(props) {
|
|
|
21
21
|
});
|
|
22
22
|
setB3ModalOpen(true);
|
|
23
23
|
};
|
|
24
|
-
if (
|
|
24
|
+
if (isAuthenticated) {
|
|
25
25
|
return _jsx(ManageAccountButton, { ...props });
|
|
26
26
|
}
|
|
27
|
-
if (
|
|
27
|
+
if (isAuthenticatingV2) {
|
|
28
28
|
return (_jsx(StyleRoot, { children: _jsxs(Button, { disabled: true, style: { backgroundColor: "#3368ef" }, className: "flex items-center gap-2 text-white", children: [props.withLogo !== false && (_jsx("img", { src: "https://cdn.b3.fun/b3_logo_white.svg", alt: "B3 Logo", className: "h-5 w-5" })), props.loadingButtonText || (isMobile ? _jsx(Loading, { size: "sm" }) : "Signing in…")] }) }));
|
|
29
29
|
}
|
|
30
30
|
return (_jsx(StyleRoot, { children: _jsx(Button, { onClick: handleClick, style: { backgroundColor: "#3368ef" }, className: "b3-sign-in-button flex items-center gap-2 font-medium text-white", children: props.buttonText ? (props.buttonText) : (_jsxs(_Fragment, { children: [_jsx("span", { children: "Sign in with" }), props.withLogo !== false && (_jsx("img", { src: "https://cdn.b3.fun/b3_logo_white.svg", alt: "B3 Logo", className: "h-5 w-6" }))] })) }) }));
|
|
@@ -19,6 +19,7 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
19
19
|
const { setB3ModalContentType, setB3ModalOpen, isOpen } = useModalStore();
|
|
20
20
|
const account = useActiveAccount();
|
|
21
21
|
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
22
|
+
const setIsAuthenticatingV2 = useAuthStore(state => state.setIsAuthenticatingV2);
|
|
22
23
|
const isAuthenticating = useAuthStore(state => state.isAuthenticating);
|
|
23
24
|
const isConnected = useAuthStore(state => state.isConnected);
|
|
24
25
|
const setIsConnected = useAuthStore(state => state.setIsConnected);
|
|
@@ -163,6 +164,7 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
163
164
|
if (loginWithSiwe) {
|
|
164
165
|
debug("setIsAuthenticating:true:1");
|
|
165
166
|
setIsAuthenticating(true);
|
|
167
|
+
setIsAuthenticatingV2(true);
|
|
166
168
|
const userAuth = await authenticate(account, partnerId);
|
|
167
169
|
setUser(userAuth.user);
|
|
168
170
|
}
|
|
@@ -170,7 +172,17 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
170
172
|
onLoginSuccess?.(account);
|
|
171
173
|
debug("setIsAuthenticating:false:1");
|
|
172
174
|
setIsAuthenticating(false);
|
|
173
|
-
|
|
175
|
+
setIsAuthenticatingV2(false);
|
|
176
|
+
}, [
|
|
177
|
+
loginWithSiwe,
|
|
178
|
+
onLoginSuccess,
|
|
179
|
+
setIsAuthenticating,
|
|
180
|
+
authenticate,
|
|
181
|
+
partnerId,
|
|
182
|
+
setUser,
|
|
183
|
+
setIsConnected,
|
|
184
|
+
setIsAuthenticatingV2,
|
|
185
|
+
]);
|
|
174
186
|
useEffect(() => {
|
|
175
187
|
if (step === "permissions") {
|
|
176
188
|
setB3ModalContentType({
|
|
@@ -6,6 +6,7 @@ const debug = debugB3React("SignInWithB3Privy");
|
|
|
6
6
|
export function SignInWithB3Privy({ onSuccess, onError, partnerId, chain }) {
|
|
7
7
|
const { isLoading, connectTw, fullToken } = useHandleConnectWithPrivy(partnerId, chain, onSuccess);
|
|
8
8
|
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
9
|
+
const setIsAuthenticatingV2 = useAuthStore(state => state.setIsAuthenticatingV2);
|
|
9
10
|
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
10
11
|
const { logout } = useAuthentication(partnerId);
|
|
11
12
|
debug("@@SignInWithB3Privy", {
|
|
@@ -33,10 +34,11 @@ export function SignInWithB3Privy({ onSuccess, onError, partnerId, chain }) {
|
|
|
33
34
|
finally {
|
|
34
35
|
debug("setIsAuthenticating:false:7");
|
|
35
36
|
setIsAuthenticating(false);
|
|
37
|
+
setIsAuthenticatingV2(false);
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
autoConnect();
|
|
39
|
-
}, [connectTw, onSuccess, onError, setIsAuthenticating, setIsAuthenticated, logout]);
|
|
41
|
+
}, [connectTw, onSuccess, onError, setIsAuthenticating, setIsAuthenticated, logout, setIsAuthenticatingV2]);
|
|
40
42
|
// Currently we auto login, so we can show loading immediately and the onSuccess will proceed to the next modal
|
|
41
43
|
return (_jsx("div", { className: "flex aspect-square items-center justify-center p-6", children: _jsx(Loading, { variant: "white", size: "lg" }) }));
|
|
42
44
|
}
|
|
@@ -13,7 +13,7 @@ export function LoginStepContainer({ children, partnerId }) {
|
|
|
13
13
|
},
|
|
14
14
|
}, !!partnerId);
|
|
15
15
|
const partnerLogo = partner?.data?.[0]?.loginCustomization?.logoUrl;
|
|
16
|
-
return (_jsxs("div", { className: "flex flex-col items-center justify-center", children: [partnerLogo && (_jsx("img", { src: partnerLogo, alt: "Partner Logo", className: "partner-logo mb-6
|
|
16
|
+
return (_jsxs("div", { className: "flex flex-col items-center justify-center pt-6", children: [partnerLogo && (_jsx("img", { src: partnerLogo, alt: "Partner Logo", className: "partner-logo mb-6 h-12 w-auto object-contain" })), children, _jsxs("h2", { className: "mt-6 flex items-center gap-2 text-lg font-bold", children: ["Powered by", _jsx("img", { alt: "B3 Logo", className: "h-5", src: "https://cdn.b3.fun/b3_logo.svg" }), "Connect"] })] }));
|
|
17
17
|
}
|
|
18
18
|
export function LoginStep({ onSuccess, onError, partnerId, chain }) {
|
|
19
19
|
const wallet = ecosystemWallet(ecosystemWalletId, {
|
|
@@ -21,6 +21,7 @@ export function LoginStep({ onSuccess, onError, partnerId, chain }) {
|
|
|
21
21
|
});
|
|
22
22
|
const { theme } = useB3();
|
|
23
23
|
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
24
|
+
const setIsAuthenticatingV2 = useAuthStore(state => state.setIsAuthenticatingV2);
|
|
24
25
|
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
25
26
|
const { logout } = useAuthentication(partnerId);
|
|
26
27
|
return (_jsx(LoginStepContainer, { partnerId: partnerId, children: _jsx(ConnectEmbed, { showThirdwebBranding: false, client: client, chain: chain, wallets: [wallet], theme: theme === "light"
|
|
@@ -61,6 +62,7 @@ export function LoginStep({ onSuccess, onError, partnerId, chain }) {
|
|
|
61
62
|
}, className: "b3-login-step", onConnect: async (wallet) => {
|
|
62
63
|
try {
|
|
63
64
|
setIsAuthenticating(true);
|
|
65
|
+
setIsAuthenticatingV2(true);
|
|
64
66
|
debug("setIsAuthenticating:true:6");
|
|
65
67
|
const account = wallet.getAccount();
|
|
66
68
|
if (!account)
|
|
@@ -77,6 +79,7 @@ export function LoginStep({ onSuccess, onError, partnerId, chain }) {
|
|
|
77
79
|
finally {
|
|
78
80
|
debug("setIsAuthenticating:false:6");
|
|
79
81
|
setIsAuthenticating(false);
|
|
82
|
+
setIsAuthenticatingV2(false);
|
|
80
83
|
}
|
|
81
84
|
} }) }));
|
|
82
85
|
}
|
|
@@ -10,6 +10,7 @@ export function LoginStepCustom({ onSuccess, onError, partnerId, chain, strategi
|
|
|
10
10
|
const [showAllWallets, setShowAllWallets] = useState(false);
|
|
11
11
|
const { connect } = useConnect(partnerId, chain);
|
|
12
12
|
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
13
|
+
const setIsAuthenticatingV2 = useAuthStore(state => state.setIsAuthenticatingV2);
|
|
13
14
|
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
14
15
|
const { logout } = useAuthentication(partnerId);
|
|
15
16
|
const { connect: connectTW } = useConnectTW();
|
|
@@ -23,6 +24,7 @@ export function LoginStepCustom({ onSuccess, onError, partnerId, chain, strategi
|
|
|
23
24
|
setIsLoading(true);
|
|
24
25
|
debug("setIsAuthenticating:true:3");
|
|
25
26
|
setIsAuthenticating(true);
|
|
27
|
+
setIsAuthenticatingV2(true);
|
|
26
28
|
const options = getConnectOptionsFromStrategy(strategy);
|
|
27
29
|
let connectResult;
|
|
28
30
|
if (automaticallySetFirstEoa) {
|
|
@@ -57,6 +59,7 @@ export function LoginStepCustom({ onSuccess, onError, partnerId, chain, strategi
|
|
|
57
59
|
setIsLoading(false);
|
|
58
60
|
debug("setIsAuthenticating:false:3");
|
|
59
61
|
setIsAuthenticating(false);
|
|
62
|
+
setIsAuthenticatingV2(false);
|
|
60
63
|
}
|
|
61
64
|
};
|
|
62
65
|
return (_jsxs(LoginStepContainer, { partnerId: partnerId, children: [authStrategies.length > 0 && (_jsx("div", { className: "mb-6 grid w-full grid-cols-4 gap-4", children: authStrategies.map(strategy => {
|
|
@@ -9,4 +9,5 @@ export declare function useAuthentication(partnerId: string, loginWithSiwe?: boo
|
|
|
9
9
|
wallet: import("thirdweb/dist/types/wallets/in-app/core/wallet/types").EcosystemWallet;
|
|
10
10
|
preAuthenticate: typeof preAuthenticate;
|
|
11
11
|
connect: (strategyOptions?: import("thirdweb/wallets").SingleStepAuthArgsType) => Promise<import("thirdweb/wallets").Wallet | null>;
|
|
12
|
+
isAuthenticatingV2: boolean;
|
|
12
13
|
};
|
|
@@ -4,7 +4,7 @@ import { ecosystemWalletId } from "../../../shared/constants/index.js";
|
|
|
4
4
|
import { b3MainnetThirdWeb } from "../../../shared/constants/chains/supported.js";
|
|
5
5
|
import { debugB3React } from "../../../shared/utils/debug.js";
|
|
6
6
|
import { client } from "../../../shared/utils/thirdweb.js";
|
|
7
|
-
import { useEffect } from "react";
|
|
7
|
+
import { useEffect, useRef } from "react";
|
|
8
8
|
import { useActiveWallet, useAutoConnect, useConnectedWallets, useDisconnect } from "thirdweb/react";
|
|
9
9
|
import { ecosystemWallet } from "thirdweb/wallets";
|
|
10
10
|
import { preAuthenticate } from "thirdweb/wallets/in-app";
|
|
@@ -25,6 +25,11 @@ export function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
25
25
|
const setIsConnected = useAuthStore(state => state.setIsConnected);
|
|
26
26
|
const isConnecting = useAuthStore(state => state.isConnecting);
|
|
27
27
|
const isConnected = useAuthStore(state => state.isConnected);
|
|
28
|
+
const useAutoConnectLoadingPrevious = useRef(false);
|
|
29
|
+
const setIsAuthenticatingV2 = useAuthStore(state => state.setIsAuthenticatingV2);
|
|
30
|
+
const isAuthenticatingV2 = useAuthStore(state => state.isAuthenticatingV2);
|
|
31
|
+
const hasStartedConnecting = useAuthStore(state => state.hasStartedConnecting);
|
|
32
|
+
const setHasStartedConnecting = useAuthStore(state => state.setHasStartedConnecting);
|
|
28
33
|
const { connect } = useConnect(partnerId, b3MainnetThirdWeb);
|
|
29
34
|
const wallet = ecosystemWallet(ecosystemWalletId, {
|
|
30
35
|
partnerId: partnerId,
|
|
@@ -33,11 +38,13 @@ export function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
33
38
|
client,
|
|
34
39
|
wallets: [wallet],
|
|
35
40
|
onConnect: async (wallet) => {
|
|
41
|
+
setHasStartedConnecting(true);
|
|
36
42
|
try {
|
|
37
43
|
setIsConnected(true);
|
|
38
44
|
if (!loginWithSiwe) {
|
|
39
45
|
debug("Skipping SIWE login", { loginWithSiwe });
|
|
40
46
|
setIsAuthenticated(true);
|
|
47
|
+
setIsAuthenticatingV2(false);
|
|
41
48
|
return;
|
|
42
49
|
}
|
|
43
50
|
debug("setIsAuthenticating:true:4");
|
|
@@ -51,6 +58,7 @@ export function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
51
58
|
const userAuth = await app.reAuthenticate();
|
|
52
59
|
setUser(userAuth.user);
|
|
53
60
|
setIsAuthenticated(true);
|
|
61
|
+
setIsAuthenticatingV2(false);
|
|
54
62
|
debug("Re-authenticated successfully", { userAuth });
|
|
55
63
|
}
|
|
56
64
|
catch (error) {
|
|
@@ -59,6 +67,7 @@ export function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
59
67
|
const userAuth = await authenticate(account, partnerId);
|
|
60
68
|
setUser(userAuth.user);
|
|
61
69
|
setIsAuthenticated(true);
|
|
70
|
+
setIsAuthenticatingV2(false);
|
|
62
71
|
debug("Fresh authentication successful", { userAuth });
|
|
63
72
|
}
|
|
64
73
|
}
|
|
@@ -68,8 +77,18 @@ export function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
68
77
|
debug("setIsAuthenticating:false:4");
|
|
69
78
|
setUser();
|
|
70
79
|
}
|
|
80
|
+
setIsAuthenticatingV2(false);
|
|
71
81
|
},
|
|
72
82
|
});
|
|
83
|
+
/**
|
|
84
|
+
* useAutoConnectLoading starts as false
|
|
85
|
+
*/
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
|
|
88
|
+
setIsAuthenticatingV2(false);
|
|
89
|
+
}
|
|
90
|
+
useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
|
|
91
|
+
}, [useAutoConnectLoading]);
|
|
73
92
|
// Ensure isAuthenticating stays true until we're fully ready
|
|
74
93
|
useEffect(() => {
|
|
75
94
|
if (useAutoConnectLoading) {
|
|
@@ -128,5 +147,6 @@ export function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
128
147
|
wallet,
|
|
129
148
|
preAuthenticate,
|
|
130
149
|
connect,
|
|
150
|
+
isAuthenticatingV2,
|
|
131
151
|
};
|
|
132
152
|
}
|
|
@@ -25,6 +25,10 @@ interface AuthState {
|
|
|
25
25
|
onError?: (error: Error) => void;
|
|
26
26
|
}) => void;
|
|
27
27
|
reset: () => void;
|
|
28
|
+
isAuthenticatingV2: boolean;
|
|
29
|
+
setIsAuthenticatingV2: (isAuthenticating: boolean) => void;
|
|
30
|
+
hasStartedConnecting: boolean;
|
|
31
|
+
setHasStartedConnecting: (hasStartedConnecting: boolean) => void;
|
|
28
32
|
}
|
|
29
33
|
export declare const useAuthStore: import("zustand").UseBoundStore<import("zustand").StoreApi<AuthState>>;
|
|
30
34
|
export {};
|
|
@@ -37,4 +37,8 @@ export const useAuthStore = create(set => ({
|
|
|
37
37
|
onSuccess: undefined,
|
|
38
38
|
onError: undefined,
|
|
39
39
|
}),
|
|
40
|
+
isAuthenticatingV2: true,
|
|
41
|
+
setIsAuthenticatingV2: isAuthenticating => set({ isAuthenticatingV2: isAuthenticating }),
|
|
42
|
+
hasStartedConnecting: false,
|
|
43
|
+
setHasStartedConnecting: hasStartedConnecting => set({ hasStartedConnecting }),
|
|
40
44
|
}));
|
|
@@ -82,6 +82,8 @@ export interface ManageAccountModalProps extends BaseModalProps {
|
|
|
82
82
|
activeTab?: "overview" | "tokens" | "nfts" | "apps" | "settings";
|
|
83
83
|
/** Function to set the active tab */
|
|
84
84
|
setActiveTab?: (tab: "overview" | "tokens" | "nfts" | "apps" | "settings") => void;
|
|
85
|
+
/** Whether to show the referral information */
|
|
86
|
+
showReferralInfo?: boolean;
|
|
85
87
|
}
|
|
86
88
|
/**
|
|
87
89
|
* Props for the AnySpend modal
|