@b3dotfun/sdk 0.0.21 → 0.0.22-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/README.md +28 -0
- package/dist/cjs/anyspend/react/components/AnySpend.js +8 -8
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +2 -0
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +2 -0
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +3 -0
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +4 -1
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +4 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +9 -9
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +3 -1
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +2 -0
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +4 -1
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +4 -1
- package/dist/esm/global-account/react/hooks/useAuthentication.js +4 -1
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +18 -20
- package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +3 -1
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +2 -0
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +2 -2
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +4 -1
- package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +4 -1
- package/src/global-account/react/hooks/useAuthentication.ts +4 -2
package/README.md
CHANGED
|
@@ -418,3 +418,31 @@ try {
|
|
|
418
418
|
---
|
|
419
419
|
|
|
420
420
|
For more detailed examples and advanced usage patterns, refer to the individual module documentation and type definitions.
|
|
421
|
+
|
|
422
|
+
## Local dev
|
|
423
|
+
|
|
424
|
+
If you are testing with one of the demos in this repo, simply make changes and they will reflect. If you are testing outside of this repo, follow the instructions below.
|
|
425
|
+
|
|
426
|
+
Initial setup
|
|
427
|
+
|
|
428
|
+
```
|
|
429
|
+
yalc publish # run this in sdk folder
|
|
430
|
+
yalc add @b3dotfun/sdk # run this in your other project
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
After making changes
|
|
434
|
+
|
|
435
|
+
```
|
|
436
|
+
yalc publish # run this in sdk folder
|
|
437
|
+
yalc update # run this in your other project
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
## Debugging
|
|
441
|
+
|
|
442
|
+
If you want to debug with existing logs that we provide, simply run this in your browser console, on the app you are debugging
|
|
443
|
+
|
|
444
|
+
```
|
|
445
|
+
localStorage.setItem('debug', '@@b3dotfun/sdk**')
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
Now, if you filter your console logs for `@@b3dotFun`, you will see several logs we provide.
|
|
@@ -292,7 +292,10 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, isMai
|
|
|
292
292
|
// );
|
|
293
293
|
// State for recipient selection
|
|
294
294
|
const [recipientAddress, setRecipientAddress] = (0, react_4.useState)();
|
|
295
|
-
const { address: globalAddress, wallet: globalWallet } = (0, react_2.useAccountWallet)();
|
|
295
|
+
const { address: globalAddress, wallet: globalWallet, ensName: connectedName } = (0, react_2.useAccountWallet)();
|
|
296
|
+
const connectedAddress = globalWallet?.address;
|
|
297
|
+
const recipientProfile = (0, react_2.useProfile)({ address: recipientAddress, fresh: true });
|
|
298
|
+
const recipientName = recipientProfile.data?.name;
|
|
296
299
|
// Set default recipient address when wallet changes
|
|
297
300
|
(0, react_4.useEffect)(() => {
|
|
298
301
|
setRecipientAddress(recipientAddressFromProps || globalAddress);
|
|
@@ -342,9 +345,6 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, isMai
|
|
|
342
345
|
amount: srcAmountOnrampInWei,
|
|
343
346
|
onrampVendor: getOnrampVendor(selectedFiatPaymentMethod),
|
|
344
347
|
});
|
|
345
|
-
const { address: connectedAddress, name: connectedName, profile: connectedProfile } = (0, react_1.useConnectedUserProfile)();
|
|
346
|
-
const recipientProfile = (0, react_2.useProfile)({ address: recipientAddress });
|
|
347
|
-
const recipientName = (0, utils_1.formatUsername)(recipientProfile.data?.name ?? "");
|
|
348
348
|
// Load custom recipients from local storage on mount
|
|
349
349
|
(0, react_4.useEffect)(() => {
|
|
350
350
|
try {
|
|
@@ -807,7 +807,7 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, isMai
|
|
|
807
807
|
setActiveTab("fiat");
|
|
808
808
|
setSelectedCryptoPaymentMethod(CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE); // Reset crypto payment method when switching to fiat
|
|
809
809
|
setSelectedFiatPaymentMethod(FiatPaymentMethod_1.FiatPaymentMethod.NONE); // Reset fiat payment method when switching to fiat
|
|
810
|
-
}, children: "Pay with Fiat" })] }) }), (0, jsx_runtime_1.jsxs)("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: [activeTab === "crypto" ? ((0, jsx_runtime_1.jsxs)(react_3.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: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("div", { className: "text-as-primary/50 flex h-7 items-center text-sm", children: "Pay" }), (0, jsx_runtime_1.jsx)("button", { className: "text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors", onClick: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), children: selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [connectedAddress ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [
|
|
810
|
+
}, children: "Pay with Fiat" })] }) }), (0, jsx_runtime_1.jsxs)("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: [activeTab === "crypto" ? ((0, jsx_runtime_1.jsxs)(react_3.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: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("div", { className: "text-as-primary/50 flex h-7 items-center text-sm", children: "Pay" }), (0, jsx_runtime_1.jsx)("button", { className: "text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors", onClick: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), children: selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [connectedAddress ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [globalWallet?.meta?.icon && ((0, jsx_runtime_1.jsx)("img", { src: globalWallet.meta.icon || "", alt: globalWallet.ensName || "", className: "bg-b3-react-foreground size-6 rounded-full object-cover opacity-100" })), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-1", children: [connectedName && (0, jsx_runtime_1.jsx)("span", { children: (0, utils_1.formatUsername)(connectedName) }), (0, jsx_runtime_1.jsx)("span", { children: (0, formatAddress_1.shortenAddress)(connectedAddress || "") })] })] })) : ("Connect wallet"), (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "h-4 w-4" })] })) : selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.TRANSFER_CRYPTO ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Transfer crypto", (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "h-4 w-4" })] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Select payment method", (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "h-4 w-4" })] })) })] }), (0, jsx_runtime_1.jsx)(OrderTokenAmount_1.OrderTokenAmount, { address: globalAddress, context: "from", inputValue: srcAmount, onChangeInput: value => {
|
|
811
811
|
setIsSrcInputDirty(true);
|
|
812
812
|
setSrcAmount(value);
|
|
813
813
|
}, chainId: selectedSrcChainId, setChainId: setSelectedSrcChainId, token: selectedSrcToken, setToken: setSelectedSrcToken }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("div", { className: "text-as-primary/50 flex h-5 items-center text-sm", children: (0, number_1.formatDisplayNumber)(anyspendQuote?.data?.currencyIn?.amountUsd, { style: "currency", fallback: "" }) }), (0, jsx_runtime_1.jsx)(TokenBalance_1.TokenBalance, { token: selectedSrcToken, walletAddress: globalAddress, onChangeInput: value => {
|
|
@@ -832,7 +832,7 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, isMai
|
|
|
832
832
|
const tempDstAmount = dstAmount;
|
|
833
833
|
setSrcAmount(tempDstAmount);
|
|
834
834
|
setDstAmount(tempSrcAmount);
|
|
835
|
-
}, children: (0, jsx_runtime_1.jsx)("div", { className: "relative flex items-center justify-center transition-opacity", children: (0, jsx_runtime_1.jsx)(lucide_react_1.ArrowDown, { className: "text-as-primary/50 h-5 w-5" }) }) }), activeTab !== "fiat" && ((0, jsx_runtime_1.jsxs)(react_3.motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0.1, 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: [(0, jsx_runtime_1.jsxs)("div", { className: "flex w-full items-center justify-between", children: [(0, jsx_runtime_1.jsx)("div", { className: "text-as-primary/50 flex h-7 items-center text-sm", children: "Receive" }), recipientAddress ? ((0, jsx_runtime_1.jsx)("button", { className: (0, cn_1.cn)("text-as-tertiarry flex h-7 items-center gap-2 rounded-lg"), onClick: () => setActivePanel(PanelView.RECIPIENT_SELECTION), children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [
|
|
835
|
+
}, children: (0, jsx_runtime_1.jsx)("div", { className: "relative flex items-center justify-center transition-opacity", children: (0, jsx_runtime_1.jsx)(lucide_react_1.ArrowDown, { className: "text-as-primary/50 h-5 w-5" }) }) }), activeTab !== "fiat" && ((0, jsx_runtime_1.jsxs)(react_3.motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0.1, 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: [(0, jsx_runtime_1.jsxs)("div", { className: "flex w-full items-center justify-between", children: [(0, jsx_runtime_1.jsx)("div", { className: "text-as-primary/50 flex h-7 items-center text-sm", children: "Receive" }), recipientAddress ? ((0, jsx_runtime_1.jsx)("button", { className: (0, cn_1.cn)("text-as-tertiarry flex h-7 items-center gap-2 rounded-lg"), onClick: () => setActivePanel(PanelView.RECIPIENT_SELECTION), children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [recipientAddress ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [recipientProfile?.data?.avatar && ((0, jsx_runtime_1.jsx)("img", { src: recipientProfile.data?.avatar || "", alt: "Connected Wallet", className: "bg-as-primary h-6 w-6 rounded-full" })), (0, jsx_runtime_1.jsxs)("span", { className: "text-as-tertiarry flex items-center gap-1 text-sm", children: [recipientName && (0, jsx_runtime_1.jsx)("span", { children: (0, utils_1.formatUsername)(recipientName) }), (0, jsx_runtime_1.jsx)("span", { children: (0, formatAddress_1.shortenAddress)(recipientAddress || "") })] })] })) : ("Connect wallet"), (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "h-4 w-4" })] }) })) : ((0, jsx_runtime_1.jsx)("button", { className: "text-as-primary/70 flex items-center gap-1 rounded-lg", onClick: () => setActivePanel(PanelView.RECIPIENT_SELECTION), children: (0, jsx_runtime_1.jsx)("div", { className: "text-sm font-medium", children: "Select recipient" }) }))] }), isBuyMode ? (
|
|
836
836
|
// Fixed destination token display in buy mode
|
|
837
837
|
(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("div", { className: "text-as-primary text-2xl font-bold", children: dstAmount || "0" }), (0, jsx_runtime_1.jsxs)("div", { className: "bg-as-brand/10 border-as-brand/30 flex items-center gap-3 rounded-xl border px-4 py-3", children: [selectedDstToken.metadata?.logoURI && ((0, jsx_runtime_1.jsx)("img", { src: selectedDstToken.metadata.logoURI, alt: selectedDstToken.symbol, className: "h-8 w-8 rounded-full" })), (0, jsx_runtime_1.jsx)("span", { className: "text-as-brand text-lg font-bold", children: selectedDstToken.symbol })] })] })) : ((0, jsx_runtime_1.jsx)(OrderTokenAmount_1.OrderTokenAmount, { address: recipientAddress, context: "to", inputValue: dstAmount, onChangeInput: value => {
|
|
838
838
|
setIsSrcInputDirty(false);
|
|
@@ -849,8 +849,8 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, isMai
|
|
|
849
849
|
}
|
|
850
850
|
// Using inline style to ensure color displays
|
|
851
851
|
return ((0, jsx_runtime_1.jsxs)("span", { className: "ml-2", style: { color: percentageNum >= 10 ? "red" : "#FFD700" }, children: ["(", isNegative ? "-" : "", percentage, "%)"] }));
|
|
852
|
-
})()] })] }))] }), getAnyspendQuoteError && ((0, jsx_runtime_1.jsxs)("div", { className: "bg-as-on-surface-1 flex w-full max-w-[460px] items-center gap-2 rounded-2xl
|
|
853
|
-
const onrampPaymentView = ((0, jsx_runtime_1.jsx)(PanelOnrampPayment_1.PanelOnrampPayment, { srcAmountOnRamp: srcAmountOnRamp, recipientName: recipientName, recipientAddress: recipientAddress, isMainnet: isMainnet, isBuyMode: isBuyMode, destinationTokenChainId: destinationTokenChainId, destinationTokenAddress: destinationTokenAddress, selectedDstChainId: selectedDstChainId, selectedDstToken: selectedDstToken, orderType: "swap", anyspendQuote: anyspendQuote, globalAddress: globalAddress, onOrderCreated: orderId => {
|
|
852
|
+
})()] })] }))] }), getAnyspendQuoteError && ((0, jsx_runtime_1.jsxs)("div", { className: "bg-as-on-surface-1 flex w-full max-w-[460px] items-center gap-2 rounded-2xl px-4 py-2", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.CircleAlert, { className: "bg-as-red h-4 min-h-4 w-4 min-w-4 rounded-full p-0 text-sm font-medium text-white" }), (0, jsx_runtime_1.jsx)("div", { className: "text-as-red text-sm", children: getAnyspendQuoteError.message })] })), (0, jsx_runtime_1.jsxs)(react_3.motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: (0, cn_1.cn)("mt-4 flex w-full max-w-[460px] flex-col gap-2", getAnyspendQuoteError && "mt-0"), children: [(0, jsx_runtime_1.jsxs)(react_2.ShinyButton, { accentColor: "hsl(var(--as-brand))", disabled: btnInfo.disable, onClick: onMainButtonClick, className: (0, cn_1.cn)("relative w-full", btnInfo.error ? "!bg-as-red" : btnInfo.disable ? "!bg-as-on-surface-2" : "!bg-as-brand"), textClassName: (0, cn_1.cn)(btnInfo.error ? "text-white" : btnInfo.disable ? "text-as-secondary" : "text-white"), children: [btnInfo.text, !btnInfo.disable && !btnInfo.error && ((0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRightCircle, { className: "absolute right-0 top-1/2 h-6 w-6 -translate-y-1/2 opacity-70" }))] }), !hideTransactionHistoryButton && (globalAddress || recipientAddress) ? ((0, jsx_runtime_1.jsxs)(react_2.Button, { variant: "link", onClick: onClickHistory, className: "text-as-primary/50 hover:text-as-primary flex items-center gap-1 transition-colors", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.HistoryIcon, { className: "h-4 w-4" }), " ", (0, jsx_runtime_1.jsx)("span", { className: "pr-4", children: "Transaction History" })] })) : null] })] }));
|
|
853
|
+
const onrampPaymentView = ((0, jsx_runtime_1.jsx)(PanelOnrampPayment_1.PanelOnrampPayment, { srcAmountOnRamp: srcAmountOnRamp, recipientName: recipientName || undefined, recipientAddress: recipientAddress, isMainnet: isMainnet, isBuyMode: isBuyMode, destinationTokenChainId: destinationTokenChainId, destinationTokenAddress: destinationTokenAddress, selectedDstChainId: selectedDstChainId, selectedDstToken: selectedDstToken, orderType: "swap", anyspendQuote: anyspendQuote, globalAddress: globalAddress, onOrderCreated: orderId => {
|
|
854
854
|
setOrderId(orderId);
|
|
855
855
|
setActivePanel(PanelView.ORDER_DETAILS);
|
|
856
856
|
// Add orderId and payment method to URL for persistence
|
|
@@ -26,6 +26,7 @@ function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentMethod,
|
|
|
26
26
|
const { wallet: globalWallet } = (0, react_1.useAccountWallet)();
|
|
27
27
|
const activeWallet = (0, react_3.useActiveWallet)();
|
|
28
28
|
const { disconnect } = (0, wagmi_1.useDisconnect)();
|
|
29
|
+
const { disconnect: disconnectThirdweb } = (0, react_3.useDisconnect)();
|
|
29
30
|
const [showWalletModal, setShowWalletModal] = (0, react_2.useState)(false);
|
|
30
31
|
// Define available wallets for the modal
|
|
31
32
|
const availableWallets = [
|
|
@@ -45,6 +46,7 @@ function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentMethod,
|
|
|
45
46
|
onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
46
47
|
}, className: "bg-as-brand hover:bg-as-brand/90 rounded-lg px-3 py-1.5 text-sm font-medium text-white transition-colors", children: "Use Wallet" }), (0, jsx_runtime_1.jsx)("button", { onClick: async () => {
|
|
47
48
|
disconnect();
|
|
49
|
+
disconnectThirdweb(activeWallet);
|
|
48
50
|
sonner_1.toast.success("Wallet disconnected");
|
|
49
51
|
if (selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
50
52
|
setSelectedPaymentMethod(CryptoPaymentMethodType.NONE);
|
|
@@ -164,12 +164,14 @@ function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onE
|
|
|
164
164
|
debug("Authenticating with B3 via SIWE");
|
|
165
165
|
setIsConnected(true);
|
|
166
166
|
if (loginWithSiwe) {
|
|
167
|
+
debug("@@setIsAuthenticating:true:1");
|
|
167
168
|
setIsAuthenticating(true);
|
|
168
169
|
const userAuth = await authenticate(account, partnerId);
|
|
169
170
|
setUser(userAuth.user);
|
|
170
171
|
}
|
|
171
172
|
debug("handleLoginSuccess:account", account);
|
|
172
173
|
onLoginSuccess?.(account);
|
|
174
|
+
debug("@@setIsAuthenticating:false:1");
|
|
173
175
|
setIsAuthenticating(false);
|
|
174
176
|
}, [loginWithSiwe, onLoginSuccess, setIsAuthenticating, authenticate, partnerId, setUser, setIsConnected]);
|
|
175
177
|
(0, react_2.useEffect)(() => {
|
|
@@ -18,7 +18,6 @@ function SignInWithB3Privy({ onSuccess, onError, partnerId, chain }) {
|
|
|
18
18
|
(0, react_2.useEffect)(() => {
|
|
19
19
|
async function autoConnect() {
|
|
20
20
|
try {
|
|
21
|
-
setIsAuthenticating(true);
|
|
22
21
|
const connectResult = await connectTw();
|
|
23
22
|
const account = connectResult?.getAccount();
|
|
24
23
|
if (!account) {
|
|
@@ -35,6 +34,7 @@ function SignInWithB3Privy({ onSuccess, onError, partnerId, chain }) {
|
|
|
35
34
|
setIsAuthenticated(false);
|
|
36
35
|
}
|
|
37
36
|
finally {
|
|
37
|
+
debug("@@setIsAuthenticating:false:7");
|
|
38
38
|
setIsAuthenticating(false);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -5,6 +5,7 @@ exports.LoginStep = LoginStep;
|
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
6
|
const react_1 = require("../../../../../global-account/react");
|
|
7
7
|
const constants_1 = require("../../../../../shared/constants");
|
|
8
|
+
const debug_1 = require("../../../../../shared/utils/debug");
|
|
8
9
|
const thirdweb_1 = require("../../../../../shared/utils/thirdweb");
|
|
9
10
|
const react_2 = require("thirdweb/react");
|
|
10
11
|
const wallets_1 = require("thirdweb/wallets");
|
|
@@ -64,6 +65,7 @@ function LoginStep({ onSuccess, onError, partnerId, chain }) {
|
|
|
64
65
|
}, onConnect: async (wallet) => {
|
|
65
66
|
try {
|
|
66
67
|
setIsAuthenticating(true);
|
|
68
|
+
(0, debug_1.debug)("@@setIsAuthenticating:true:6");
|
|
67
69
|
const account = wallet.getAccount();
|
|
68
70
|
if (!account)
|
|
69
71
|
throw new Error("No account found");
|
|
@@ -77,6 +79,7 @@ function LoginStep({ onSuccess, onError, partnerId, chain }) {
|
|
|
77
79
|
setIsAuthenticated(false);
|
|
78
80
|
}
|
|
79
81
|
finally {
|
|
82
|
+
(0, debug_1.debug)("@@setIsAuthenticating:false:6");
|
|
80
83
|
setIsAuthenticating(false);
|
|
81
84
|
}
|
|
82
85
|
} }) }));
|
|
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.LoginStepCustom = LoginStepCustom;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("../../../../../global-account/react");
|
|
6
|
+
const debug_1 = require("../../../../../shared/utils/debug");
|
|
7
|
+
const thirdweb_1 = require("../../../../../shared/utils/thirdweb");
|
|
6
8
|
const react_2 = require("react");
|
|
7
9
|
const react_3 = require("thirdweb/react");
|
|
8
10
|
const wallets_1 = require("thirdweb/wallets");
|
|
9
|
-
const thirdweb_1 = require("../../../../../shared/utils/thirdweb");
|
|
10
11
|
function LoginStepCustom({ onSuccess, onError, partnerId, chain, strategies, maxInitialWallets = 2, automaticallySetFirstEoa, }) {
|
|
11
12
|
const [isLoading, setIsLoading] = (0, react_2.useState)(false);
|
|
12
13
|
const [showAllWallets, setShowAllWallets] = (0, react_2.useState)(false);
|
|
@@ -23,6 +24,7 @@ function LoginStepCustom({ onSuccess, onError, partnerId, chain, strategies, max
|
|
|
23
24
|
const handleConnect = async (strategy) => {
|
|
24
25
|
try {
|
|
25
26
|
setIsLoading(true);
|
|
27
|
+
(0, debug_1.debug)("@@setIsAuthenticating:true:3");
|
|
26
28
|
setIsAuthenticating(true);
|
|
27
29
|
const options = (0, react_1.getConnectOptionsFromStrategy)(strategy);
|
|
28
30
|
let connectResult;
|
|
@@ -56,6 +58,7 @@ function LoginStepCustom({ onSuccess, onError, partnerId, chain, strategies, max
|
|
|
56
58
|
}
|
|
57
59
|
finally {
|
|
58
60
|
setIsLoading(false);
|
|
61
|
+
(0, debug_1.debug)("@@setIsAuthenticating:false:3");
|
|
59
62
|
setIsAuthenticating(false);
|
|
60
63
|
}
|
|
61
64
|
};
|
|
@@ -46,6 +46,7 @@ function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
46
46
|
setIsAuthenticated(true);
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
+
debug("@@setIsAuthenticating:true:4");
|
|
49
50
|
setIsAuthenticating(true);
|
|
50
51
|
const account = await wallet.getAccount();
|
|
51
52
|
if (!account) {
|
|
@@ -70,6 +71,7 @@ function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
70
71
|
catch (error) {
|
|
71
72
|
debug("Auto-connect authentication failed", { error });
|
|
72
73
|
setIsAuthenticated(false);
|
|
74
|
+
debug("@@setIsAuthenticating:false:4");
|
|
73
75
|
setUser();
|
|
74
76
|
}
|
|
75
77
|
},
|
|
@@ -77,19 +79,20 @@ function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
77
79
|
// Ensure isAuthenticating stays true until we're fully ready
|
|
78
80
|
(0, react_2.useEffect)(() => {
|
|
79
81
|
if (useAutoConnectLoading) {
|
|
80
|
-
setIsAuthenticating(true);
|
|
81
82
|
setIsConnecting(true);
|
|
82
83
|
}
|
|
83
84
|
else if (!isAuthenticated) {
|
|
84
85
|
// Only set isAuthenticating to false if we're not authenticated
|
|
85
86
|
// This prevents the flicker state where both isAuthenticating and isAuthenticated are false
|
|
86
87
|
const timeout = setTimeout(() => {
|
|
88
|
+
debug("@@setIsAuthenticating:false:5a");
|
|
87
89
|
setIsAuthenticating(false);
|
|
88
90
|
setIsConnecting(false);
|
|
89
91
|
}, 100); // Add a small delay to prevent quick flickers
|
|
90
92
|
return () => clearTimeout(timeout);
|
|
91
93
|
}
|
|
92
94
|
else {
|
|
95
|
+
debug("@@setIsAuthenticating:false:5b");
|
|
93
96
|
setIsAuthenticating(false);
|
|
94
97
|
setIsConnecting(false);
|
|
95
98
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { getDefaultToken, USDC_BASE } from "../../../anyspend/index.js";
|
|
4
|
-
import { useAnyspendCreateOnrampOrder, useAnyspendCreateOrder, useAnyspendOrderAndTransactions, useAnyspendQuote,
|
|
4
|
+
import { useAnyspendCreateOnrampOrder, useAnyspendCreateOrder, useAnyspendOrderAndTransactions, useAnyspendQuote, useGeoOnrampOptions, } from "../../../anyspend/react/index.js";
|
|
5
5
|
import { Button, ShinyButton, StyleRoot, TransitionPanel, useAccountWallet, useProfile, useRouter, useSearchParamsSSR, useTokenData, useTokenFromUrl, } from "../../../global-account/react/index.js";
|
|
6
6
|
import { formatUsername } from "../../../shared/utils/index.js";
|
|
7
7
|
import { cn } from "../../../shared/utils/cn.js";
|
|
@@ -285,7 +285,10 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, isMai
|
|
|
285
285
|
// );
|
|
286
286
|
// State for recipient selection
|
|
287
287
|
const [recipientAddress, setRecipientAddress] = useState();
|
|
288
|
-
const { address: globalAddress, wallet: globalWallet } = useAccountWallet();
|
|
288
|
+
const { address: globalAddress, wallet: globalWallet, ensName: connectedName } = useAccountWallet();
|
|
289
|
+
const connectedAddress = globalWallet?.address;
|
|
290
|
+
const recipientProfile = useProfile({ address: recipientAddress, fresh: true });
|
|
291
|
+
const recipientName = recipientProfile.data?.name;
|
|
289
292
|
// Set default recipient address when wallet changes
|
|
290
293
|
useEffect(() => {
|
|
291
294
|
setRecipientAddress(recipientAddressFromProps || globalAddress);
|
|
@@ -335,9 +338,6 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, isMai
|
|
|
335
338
|
amount: srcAmountOnrampInWei,
|
|
336
339
|
onrampVendor: getOnrampVendor(selectedFiatPaymentMethod),
|
|
337
340
|
});
|
|
338
|
-
const { address: connectedAddress, name: connectedName, profile: connectedProfile } = useConnectedUserProfile();
|
|
339
|
-
const recipientProfile = useProfile({ address: recipientAddress });
|
|
340
|
-
const recipientName = formatUsername(recipientProfile.data?.name ?? "");
|
|
341
341
|
// Load custom recipients from local storage on mount
|
|
342
342
|
useEffect(() => {
|
|
343
343
|
try {
|
|
@@ -800,7 +800,7 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, isMai
|
|
|
800
800
|
setActiveTab("fiat");
|
|
801
801
|
setSelectedCryptoPaymentMethod(CryptoPaymentMethodType.NONE); // Reset crypto payment method when switching to fiat
|
|
802
802
|
setSelectedFiatPaymentMethod(FiatPaymentMethod.NONE); // Reset fiat payment method when switching to fiat
|
|
803
|
-
}, children: "Pay with Fiat" })] }) }), _jsxs("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: [activeTab === "crypto" ? (_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" }), _jsx("button", { className: "text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors", onClick: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), children: selectedCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET ? (_jsxs(_Fragment, { children: [connectedAddress ? (_jsxs(_Fragment, { children: [
|
|
803
|
+
}, children: "Pay with Fiat" })] }) }), _jsxs("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: [activeTab === "crypto" ? (_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" }), _jsx("button", { className: "text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors", onClick: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), children: selectedCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET ? (_jsxs(_Fragment, { children: [connectedAddress ? (_jsxs(_Fragment, { children: [globalWallet?.meta?.icon && (_jsx("img", { src: globalWallet.meta.icon || "", alt: globalWallet.ensName || "", className: "bg-b3-react-foreground size-6 rounded-full object-cover opacity-100" })), _jsxs("div", { className: "flex items-center gap-1", children: [connectedName && _jsx("span", { children: formatUsername(connectedName) }), _jsx("span", { children: 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(OrderTokenAmount, { address: globalAddress, context: "from", inputValue: srcAmount, onChangeInput: value => {
|
|
804
804
|
setIsSrcInputDirty(true);
|
|
805
805
|
setSrcAmount(value);
|
|
806
806
|
}, 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, { style: "currency", fallback: "" }) }), _jsx(TokenBalance, { token: selectedSrcToken, walletAddress: globalAddress, onChangeInput: value => {
|
|
@@ -825,7 +825,7 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, isMai
|
|
|
825
825
|
const tempDstAmount = dstAmount;
|
|
826
826
|
setSrcAmount(tempDstAmount);
|
|
827
827
|
setDstAmount(tempSrcAmount);
|
|
828
|
-
}, children: _jsx("div", { className: "relative flex items-center justify-center transition-opacity", children: _jsx(ArrowDown, { className: "text-as-primary/50 h-5 w-5" }) }) }), activeTab !== "fiat" && (_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.1, 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 w-full items-center justify-between", children: [_jsx("div", { className: "text-as-primary/50 flex h-7 items-center text-sm", children: "Receive" }), recipientAddress ? (_jsx("button", { className: cn("text-as-tertiarry flex h-7 items-center gap-2 rounded-lg"), onClick: () => setActivePanel(PanelView.RECIPIENT_SELECTION), children: _jsxs(_Fragment, { children: [
|
|
828
|
+
}, children: _jsx("div", { className: "relative flex items-center justify-center transition-opacity", children: _jsx(ArrowDown, { className: "text-as-primary/50 h-5 w-5" }) }) }), activeTab !== "fiat" && (_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.1, 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 w-full items-center justify-between", children: [_jsx("div", { className: "text-as-primary/50 flex h-7 items-center text-sm", children: "Receive" }), recipientAddress ? (_jsx("button", { className: cn("text-as-tertiarry flex h-7 items-center gap-2 rounded-lg"), onClick: () => setActivePanel(PanelView.RECIPIENT_SELECTION), children: _jsxs(_Fragment, { children: [recipientAddress ? (_jsxs(_Fragment, { children: [recipientProfile?.data?.avatar && (_jsx("img", { src: recipientProfile.data?.avatar || "", alt: "Connected Wallet", className: "bg-as-primary h-6 w-6 rounded-full" })), _jsxs("span", { className: "text-as-tertiarry flex items-center gap-1 text-sm", children: [recipientName && _jsx("span", { children: formatUsername(recipientName) }), _jsx("span", { children: shortenAddress(recipientAddress || "") })] })] })) : ("Connect wallet"), _jsx(ChevronRight, { className: "h-4 w-4" })] }) })) : (_jsx("button", { className: "text-as-primary/70 flex items-center gap-1 rounded-lg", onClick: () => setActivePanel(PanelView.RECIPIENT_SELECTION), children: _jsx("div", { className: "text-sm font-medium", children: "Select recipient" }) }))] }), isBuyMode ? (
|
|
829
829
|
// Fixed destination token display in buy mode
|
|
830
830
|
_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-as-primary text-2xl font-bold", children: dstAmount || "0" }), _jsxs("div", { className: "bg-as-brand/10 border-as-brand/30 flex items-center gap-3 rounded-xl border px-4 py-3", children: [selectedDstToken.metadata?.logoURI && (_jsx("img", { src: selectedDstToken.metadata.logoURI, alt: selectedDstToken.symbol, className: "h-8 w-8 rounded-full" })), _jsx("span", { className: "text-as-brand text-lg font-bold", children: selectedDstToken.symbol })] })] })) : (_jsx(OrderTokenAmount, { address: recipientAddress, context: "to", inputValue: dstAmount, onChangeInput: value => {
|
|
831
831
|
setIsSrcInputDirty(false);
|
|
@@ -842,8 +842,8 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, isMai
|
|
|
842
842
|
}
|
|
843
843
|
// Using inline style to ensure color displays
|
|
844
844
|
return (_jsxs("span", { className: "ml-2", style: { color: percentageNum >= 10 ? "red" : "#FFD700" }, children: ["(", isNegative ? "-" : "", percentage, "%)"] }));
|
|
845
|
-
})()] })] }))] }), getAnyspendQuoteError && (_jsxs("div", { className: "bg-as-on-surface-1 flex w-full max-w-[460px] items-center gap-2 rounded-2xl
|
|
846
|
-
const onrampPaymentView = (_jsx(PanelOnrampPayment, { srcAmountOnRamp: srcAmountOnRamp, recipientName: recipientName, recipientAddress: recipientAddress, isMainnet: isMainnet, isBuyMode: isBuyMode, destinationTokenChainId: destinationTokenChainId, destinationTokenAddress: destinationTokenAddress, selectedDstChainId: selectedDstChainId, selectedDstToken: selectedDstToken, orderType: "swap", anyspendQuote: anyspendQuote, globalAddress: globalAddress, onOrderCreated: orderId => {
|
|
845
|
+
})()] })] }))] }), getAnyspendQuoteError && (_jsxs("div", { className: "bg-as-on-surface-1 flex w-full max-w-[460px] items-center gap-2 rounded-2xl px-4 py-2", children: [_jsx(CircleAlert, { className: "bg-as-red h-4 min-h-4 w-4 min-w-4 rounded-full p-0 text-sm font-medium text-white" }), _jsx("div", { className: "text-as-red text-sm", children: getAnyspendQuoteError.message })] })), _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.2, ease: "easeInOut" }, className: cn("mt-4 flex w-full max-w-[460px] flex-col gap-2", getAnyspendQuoteError && "mt-0"), children: [_jsxs(ShinyButton, { accentColor: "hsl(var(--as-brand))", disabled: btnInfo.disable, onClick: onMainButtonClick, className: cn("relative w-full", btnInfo.error ? "!bg-as-red" : btnInfo.disable ? "!bg-as-on-surface-2" : "!bg-as-brand"), textClassName: cn(btnInfo.error ? "text-white" : btnInfo.disable ? "text-as-secondary" : "text-white"), children: [btnInfo.text, !btnInfo.disable && !btnInfo.error && (_jsx(ChevronRightCircle, { className: "absolute right-0 top-1/2 h-6 w-6 -translate-y-1/2 opacity-70" }))] }), !hideTransactionHistoryButton && (globalAddress || recipientAddress) ? (_jsxs(Button, { variant: "link", onClick: onClickHistory, className: "text-as-primary/50 hover:text-as-primary flex items-center gap-1 transition-colors", children: [_jsx(HistoryIcon, { className: "h-4 w-4" }), " ", _jsx("span", { className: "pr-4", children: "Transaction History" })] })) : null] })] }));
|
|
846
|
+
const onrampPaymentView = (_jsx(PanelOnrampPayment, { srcAmountOnRamp: srcAmountOnRamp, recipientName: recipientName || undefined, recipientAddress: recipientAddress, isMainnet: isMainnet, isBuyMode: isBuyMode, destinationTokenChainId: destinationTokenChainId, destinationTokenAddress: destinationTokenAddress, selectedDstChainId: selectedDstChainId, selectedDstToken: selectedDstToken, orderType: "swap", anyspendQuote: anyspendQuote, globalAddress: globalAddress, onOrderCreated: orderId => {
|
|
847
847
|
setOrderId(orderId);
|
|
848
848
|
setActivePanel(PanelView.ORDER_DETAILS);
|
|
849
849
|
// Add orderId and payment method to URL for persistence
|
|
@@ -9,7 +9,7 @@ import { ChevronLeft, ChevronRightCircle, Wallet, X } from "lucide-react";
|
|
|
9
9
|
import { useState } from "react";
|
|
10
10
|
import { createPortal } from "react-dom";
|
|
11
11
|
import { toast } from "sonner";
|
|
12
|
-
import { ConnectEmbed, lightTheme, useActiveWallet } from "thirdweb/react";
|
|
12
|
+
import { ConnectEmbed, lightTheme, useActiveWallet, useDisconnect as useThirdwebDisconnect } from "thirdweb/react";
|
|
13
13
|
import { createWallet } from "thirdweb/wallets";
|
|
14
14
|
import { useDisconnect } from "wagmi";
|
|
15
15
|
export var CryptoPaymentMethodType;
|
|
@@ -22,6 +22,7 @@ export function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentM
|
|
|
22
22
|
const { wallet: globalWallet } = useAccountWallet();
|
|
23
23
|
const activeWallet = useActiveWallet();
|
|
24
24
|
const { disconnect } = useDisconnect();
|
|
25
|
+
const { disconnect: disconnectThirdweb } = useThirdwebDisconnect();
|
|
25
26
|
const [showWalletModal, setShowWalletModal] = useState(false);
|
|
26
27
|
// Define available wallets for the modal
|
|
27
28
|
const availableWallets = [
|
|
@@ -41,6 +42,7 @@ export function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentM
|
|
|
41
42
|
onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
42
43
|
}, className: "bg-as-brand hover:bg-as-brand/90 rounded-lg px-3 py-1.5 text-sm font-medium text-white transition-colors", children: "Use Wallet" }), _jsx("button", { onClick: async () => {
|
|
43
44
|
disconnect();
|
|
45
|
+
disconnectThirdweb(activeWallet);
|
|
44
46
|
toast.success("Wallet disconnected");
|
|
45
47
|
if (selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
46
48
|
setSelectedPaymentMethod(CryptoPaymentMethodType.NONE);
|
|
@@ -161,12 +161,14 @@ export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySucce
|
|
|
161
161
|
debug("Authenticating with B3 via SIWE");
|
|
162
162
|
setIsConnected(true);
|
|
163
163
|
if (loginWithSiwe) {
|
|
164
|
+
debug("@@setIsAuthenticating:true:1");
|
|
164
165
|
setIsAuthenticating(true);
|
|
165
166
|
const userAuth = await authenticate(account, partnerId);
|
|
166
167
|
setUser(userAuth.user);
|
|
167
168
|
}
|
|
168
169
|
debug("handleLoginSuccess:account", account);
|
|
169
170
|
onLoginSuccess?.(account);
|
|
171
|
+
debug("@@setIsAuthenticating:false:1");
|
|
170
172
|
setIsAuthenticating(false);
|
|
171
173
|
}, [loginWithSiwe, onLoginSuccess, setIsAuthenticating, authenticate, partnerId, setUser, setIsConnected]);
|
|
172
174
|
useEffect(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Loading, useAuthentication,
|
|
2
|
+
import { Loading, useAuthentication, useAuthStore, useHandleConnectWithPrivy, } from "../../../../global-account/react/index.js";
|
|
3
3
|
import { debugB3React } from "../../../../shared/utils/debug.js";
|
|
4
4
|
import { useEffect } from "react";
|
|
5
5
|
const debug = debugB3React("SignInWithB3Privy");
|
|
@@ -15,7 +15,6 @@ export function SignInWithB3Privy({ onSuccess, onError, partnerId, chain }) {
|
|
|
15
15
|
useEffect(() => {
|
|
16
16
|
async function autoConnect() {
|
|
17
17
|
try {
|
|
18
|
-
setIsAuthenticating(true);
|
|
19
18
|
const connectResult = await connectTw();
|
|
20
19
|
const account = connectResult?.getAccount();
|
|
21
20
|
if (!account) {
|
|
@@ -32,6 +31,7 @@ export function SignInWithB3Privy({ onSuccess, onError, partnerId, chain }) {
|
|
|
32
31
|
setIsAuthenticated(false);
|
|
33
32
|
}
|
|
34
33
|
finally {
|
|
34
|
+
debug("@@setIsAuthenticating:false:7");
|
|
35
35
|
setIsAuthenticating(false);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useAuthentication,
|
|
2
|
+
import { useAuthentication, useAuthStore, useB3, useQueryB3 } from "../../../../../global-account/react/index.js";
|
|
3
3
|
import { ecosystemWalletId } from "../../../../../shared/constants/index.js";
|
|
4
|
+
import { debug } from "../../../../../shared/utils/debug.js";
|
|
4
5
|
import { client } from "../../../../../shared/utils/thirdweb.js";
|
|
5
6
|
import { ConnectEmbed, darkTheme, lightTheme } from "thirdweb/react";
|
|
6
7
|
import { ecosystemWallet } from "thirdweb/wallets";
|
|
@@ -60,6 +61,7 @@ export function LoginStep({ onSuccess, onError, partnerId, chain }) {
|
|
|
60
61
|
}, onConnect: async (wallet) => {
|
|
61
62
|
try {
|
|
62
63
|
setIsAuthenticating(true);
|
|
64
|
+
debug("@@setIsAuthenticating:true:6");
|
|
63
65
|
const account = wallet.getAccount();
|
|
64
66
|
if (!account)
|
|
65
67
|
throw new Error("No account found");
|
|
@@ -73,6 +75,7 @@ export function LoginStep({ onSuccess, onError, partnerId, chain }) {
|
|
|
73
75
|
setIsAuthenticated(false);
|
|
74
76
|
}
|
|
75
77
|
finally {
|
|
78
|
+
debug("@@setIsAuthenticating:false:6");
|
|
76
79
|
setIsAuthenticating(false);
|
|
77
80
|
}
|
|
78
81
|
} }) }));
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { AuthButton, Button, getConnectOptionsFromStrategy, isWalletType, LoginStepContainer, useAuthentication, useAuthStore, useConnect, WalletRow, } from "../../../../../global-account/react/index.js";
|
|
3
|
+
import { debug } from "../../../../../shared/utils/debug.js";
|
|
4
|
+
import { client } from "../../../../../shared/utils/thirdweb.js";
|
|
3
5
|
import { useState } from "react";
|
|
4
6
|
import { useConnect as useConnectTW } from "thirdweb/react";
|
|
5
7
|
import { createWallet } from "thirdweb/wallets";
|
|
6
|
-
import { client } from "../../../../../shared/utils/thirdweb.js";
|
|
7
8
|
export function LoginStepCustom({ onSuccess, onError, partnerId, chain, strategies, maxInitialWallets = 2, automaticallySetFirstEoa, }) {
|
|
8
9
|
const [isLoading, setIsLoading] = useState(false);
|
|
9
10
|
const [showAllWallets, setShowAllWallets] = useState(false);
|
|
@@ -20,6 +21,7 @@ export function LoginStepCustom({ onSuccess, onError, partnerId, chain, strategi
|
|
|
20
21
|
const handleConnect = async (strategy) => {
|
|
21
22
|
try {
|
|
22
23
|
setIsLoading(true);
|
|
24
|
+
debug("@@setIsAuthenticating:true:3");
|
|
23
25
|
setIsAuthenticating(true);
|
|
24
26
|
const options = getConnectOptionsFromStrategy(strategy);
|
|
25
27
|
let connectResult;
|
|
@@ -53,6 +55,7 @@ export function LoginStepCustom({ onSuccess, onError, partnerId, chain, strategi
|
|
|
53
55
|
}
|
|
54
56
|
finally {
|
|
55
57
|
setIsLoading(false);
|
|
58
|
+
debug("@@setIsAuthenticating:false:3");
|
|
56
59
|
setIsAuthenticating(false);
|
|
57
60
|
}
|
|
58
61
|
};
|
|
@@ -40,6 +40,7 @@ export function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
40
40
|
setIsAuthenticated(true);
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
|
+
debug("@@setIsAuthenticating:true:4");
|
|
43
44
|
setIsAuthenticating(true);
|
|
44
45
|
const account = await wallet.getAccount();
|
|
45
46
|
if (!account) {
|
|
@@ -64,6 +65,7 @@ export function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
64
65
|
catch (error) {
|
|
65
66
|
debug("Auto-connect authentication failed", { error });
|
|
66
67
|
setIsAuthenticated(false);
|
|
68
|
+
debug("@@setIsAuthenticating:false:4");
|
|
67
69
|
setUser();
|
|
68
70
|
}
|
|
69
71
|
},
|
|
@@ -71,19 +73,20 @@ export function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
71
73
|
// Ensure isAuthenticating stays true until we're fully ready
|
|
72
74
|
useEffect(() => {
|
|
73
75
|
if (useAutoConnectLoading) {
|
|
74
|
-
setIsAuthenticating(true);
|
|
75
76
|
setIsConnecting(true);
|
|
76
77
|
}
|
|
77
78
|
else if (!isAuthenticated) {
|
|
78
79
|
// Only set isAuthenticating to false if we're not authenticated
|
|
79
80
|
// This prevents the flicker state where both isAuthenticating and isAuthenticated are false
|
|
80
81
|
const timeout = setTimeout(() => {
|
|
82
|
+
debug("@@setIsAuthenticating:false:5a");
|
|
81
83
|
setIsAuthenticating(false);
|
|
82
84
|
setIsConnecting(false);
|
|
83
85
|
}, 100); // Add a small delay to prevent quick flickers
|
|
84
86
|
return () => clearTimeout(timeout);
|
|
85
87
|
}
|
|
86
88
|
else {
|
|
89
|
+
debug("@@setIsAuthenticating:false:5b");
|
|
87
90
|
setIsAuthenticating(false);
|
|
88
91
|
setIsConnecting(false);
|
|
89
92
|
}
|
package/package.json
CHANGED
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
useAnyspendCreateOrder,
|
|
7
7
|
useAnyspendOrderAndTransactions,
|
|
8
8
|
useAnyspendQuote,
|
|
9
|
-
useConnectedUserProfile,
|
|
10
9
|
useGeoOnrampOptions,
|
|
11
10
|
} from "@b3dotfun/sdk/anyspend/react";
|
|
12
11
|
import {
|
|
@@ -405,7 +404,10 @@ function AnySpendInner({
|
|
|
405
404
|
// State for recipient selection
|
|
406
405
|
const [recipientAddress, setRecipientAddress] = useState<string | undefined>();
|
|
407
406
|
|
|
408
|
-
const { address: globalAddress, wallet: globalWallet } = useAccountWallet();
|
|
407
|
+
const { address: globalAddress, wallet: globalWallet, ensName: connectedName } = useAccountWallet();
|
|
408
|
+
const connectedAddress = globalWallet?.address;
|
|
409
|
+
const recipientProfile = useProfile({ address: recipientAddress, fresh: true });
|
|
410
|
+
const recipientName = recipientProfile.data?.name;
|
|
409
411
|
|
|
410
412
|
// Set default recipient address when wallet changes
|
|
411
413
|
useEffect(() => {
|
|
@@ -465,10 +467,6 @@ function AnySpendInner({
|
|
|
465
467
|
},
|
|
466
468
|
);
|
|
467
469
|
|
|
468
|
-
const { address: connectedAddress, name: connectedName, profile: connectedProfile } = useConnectedUserProfile();
|
|
469
|
-
const recipientProfile = useProfile({ address: recipientAddress });
|
|
470
|
-
const recipientName = formatUsername(recipientProfile.data?.name ?? "");
|
|
471
|
-
|
|
472
470
|
// Load custom recipients from local storage on mount
|
|
473
471
|
useEffect(() => {
|
|
474
472
|
try {
|
|
@@ -1080,16 +1078,16 @@ function AnySpendInner({
|
|
|
1080
1078
|
<>
|
|
1081
1079
|
{connectedAddress ? (
|
|
1082
1080
|
<>
|
|
1083
|
-
{
|
|
1081
|
+
{globalWallet?.meta?.icon && (
|
|
1084
1082
|
<img
|
|
1085
|
-
src={
|
|
1086
|
-
alt={
|
|
1087
|
-
className="bg-b3-react-foreground size-
|
|
1083
|
+
src={globalWallet.meta.icon || ""}
|
|
1084
|
+
alt={globalWallet.ensName || ""}
|
|
1085
|
+
className="bg-b3-react-foreground size-6 rounded-full object-cover opacity-100"
|
|
1088
1086
|
/>
|
|
1089
1087
|
)}
|
|
1090
1088
|
<div className="flex items-center gap-1">
|
|
1091
|
-
{
|
|
1092
|
-
<span>{shortenAddress(
|
|
1089
|
+
{connectedName && <span>{formatUsername(connectedName)}</span>}
|
|
1090
|
+
<span>{shortenAddress(connectedAddress || "")}</span>
|
|
1093
1091
|
</div>
|
|
1094
1092
|
</>
|
|
1095
1093
|
) : (
|
|
@@ -1211,18 +1209,18 @@ function AnySpendInner({
|
|
|
1211
1209
|
onClick={() => setActivePanel(PanelView.RECIPIENT_SELECTION)}
|
|
1212
1210
|
>
|
|
1213
1211
|
<>
|
|
1214
|
-
{
|
|
1212
|
+
{recipientAddress ? (
|
|
1215
1213
|
<>
|
|
1216
|
-
{
|
|
1214
|
+
{recipientProfile?.data?.avatar && (
|
|
1217
1215
|
<img
|
|
1218
|
-
src={
|
|
1216
|
+
src={recipientProfile.data?.avatar || ""}
|
|
1219
1217
|
alt="Connected Wallet"
|
|
1220
1218
|
className="bg-as-primary h-6 w-6 rounded-full"
|
|
1221
1219
|
/>
|
|
1222
1220
|
)}
|
|
1223
1221
|
<span className="text-as-tertiarry flex items-center gap-1 text-sm">
|
|
1224
|
-
{
|
|
1225
|
-
<span>{shortenAddress(
|
|
1222
|
+
{recipientName && <span>{formatUsername(recipientName)}</span>}
|
|
1223
|
+
<span>{shortenAddress(recipientAddress || "")}</span>
|
|
1226
1224
|
</span>
|
|
1227
1225
|
</>
|
|
1228
1226
|
) : (
|
|
@@ -1324,7 +1322,7 @@ function AnySpendInner({
|
|
|
1324
1322
|
|
|
1325
1323
|
{/* Error message section */}
|
|
1326
1324
|
{getAnyspendQuoteError && (
|
|
1327
|
-
<div className="bg-as-on-surface-1 flex w-full max-w-[460px] items-center gap-2 rounded-2xl
|
|
1325
|
+
<div className="bg-as-on-surface-1 flex w-full max-w-[460px] items-center gap-2 rounded-2xl px-4 py-2">
|
|
1328
1326
|
<CircleAlert className="bg-as-red h-4 min-h-4 w-4 min-w-4 rounded-full p-0 text-sm font-medium text-white" />
|
|
1329
1327
|
<div className="text-as-red text-sm">{getAnyspendQuoteError.message}</div>
|
|
1330
1328
|
</div>
|
|
@@ -1335,7 +1333,7 @@ function AnySpendInner({
|
|
|
1335
1333
|
initial={{ opacity: 0, y: 20, filter: "blur(10px)" }}
|
|
1336
1334
|
animate={{ opacity: 1, y: 0, filter: "blur(0px)" }}
|
|
1337
1335
|
transition={{ duration: 0.3, delay: 0.2, ease: "easeInOut" }}
|
|
1338
|
-
className="mt-4 flex w-full max-w-[460px] flex-col gap-2
|
|
1336
|
+
className={cn("mt-4 flex w-full max-w-[460px] flex-col gap-2", getAnyspendQuoteError && "mt-0")}
|
|
1339
1337
|
>
|
|
1340
1338
|
<ShinyButton
|
|
1341
1339
|
accentColor={"hsl(var(--as-brand))"}
|
|
@@ -1369,7 +1367,7 @@ function AnySpendInner({
|
|
|
1369
1367
|
const onrampPaymentView = (
|
|
1370
1368
|
<PanelOnrampPayment
|
|
1371
1369
|
srcAmountOnRamp={srcAmountOnRamp}
|
|
1372
|
-
recipientName={recipientName}
|
|
1370
|
+
recipientName={recipientName || undefined}
|
|
1373
1371
|
recipientAddress={recipientAddress}
|
|
1374
1372
|
isMainnet={isMainnet}
|
|
1375
1373
|
isBuyMode={isBuyMode}
|
|
@@ -9,7 +9,7 @@ import { ChevronLeft, ChevronRightCircle, Wallet, X } from "lucide-react";
|
|
|
9
9
|
import { useState } from "react";
|
|
10
10
|
import { createPortal } from "react-dom";
|
|
11
11
|
import { toast } from "sonner";
|
|
12
|
-
import { ConnectEmbed, lightTheme, useActiveWallet } from "thirdweb/react";
|
|
12
|
+
import { ConnectEmbed, lightTheme, useActiveWallet, useDisconnect as useThirdwebDisconnect } from "thirdweb/react";
|
|
13
13
|
import { createWallet } from "thirdweb/wallets";
|
|
14
14
|
import { useDisconnect } from "wagmi";
|
|
15
15
|
|
|
@@ -43,6 +43,7 @@ export function CryptoPaymentMethod({
|
|
|
43
43
|
const { wallet: globalWallet } = useAccountWallet();
|
|
44
44
|
const activeWallet = useActiveWallet();
|
|
45
45
|
const { disconnect } = useDisconnect();
|
|
46
|
+
const { disconnect: disconnectThirdweb } = useThirdwebDisconnect();
|
|
46
47
|
const [showWalletModal, setShowWalletModal] = useState(false);
|
|
47
48
|
|
|
48
49
|
// Define available wallets for the modal
|
|
@@ -123,6 +124,7 @@ export function CryptoPaymentMethod({
|
|
|
123
124
|
<button
|
|
124
125
|
onClick={async () => {
|
|
125
126
|
disconnect();
|
|
127
|
+
disconnectThirdweb(activeWallet);
|
|
126
128
|
toast.success("Wallet disconnected");
|
|
127
129
|
if (selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
128
130
|
setSelectedPaymentMethod(CryptoPaymentMethodType.NONE);
|
|
@@ -196,12 +196,14 @@ export function SignInWithB3Flow({
|
|
|
196
196
|
debug("Authenticating with B3 via SIWE");
|
|
197
197
|
setIsConnected(true);
|
|
198
198
|
if (loginWithSiwe) {
|
|
199
|
+
debug("@@setIsAuthenticating:true:1");
|
|
199
200
|
setIsAuthenticating(true);
|
|
200
201
|
const userAuth = await authenticate(account, partnerId);
|
|
201
202
|
setUser(userAuth.user);
|
|
202
203
|
}
|
|
203
204
|
debug("handleLoginSuccess:account", account);
|
|
204
205
|
onLoginSuccess?.(account);
|
|
206
|
+
debug("@@setIsAuthenticating:false:1");
|
|
205
207
|
setIsAuthenticating(false);
|
|
206
208
|
},
|
|
207
209
|
[loginWithSiwe, onLoginSuccess, setIsAuthenticating, authenticate, partnerId, setUser, setIsConnected],
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Loading,
|
|
3
3
|
useAuthentication,
|
|
4
|
-
useHandleConnectWithPrivy,
|
|
5
4
|
useAuthStore,
|
|
5
|
+
useHandleConnectWithPrivy,
|
|
6
6
|
} from "@b3dotfun/sdk/global-account/react";
|
|
7
7
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
8
8
|
import { useEffect } from "react";
|
|
@@ -32,7 +32,6 @@ export function SignInWithB3Privy({ onSuccess, onError, partnerId, chain }: Sign
|
|
|
32
32
|
useEffect(() => {
|
|
33
33
|
async function autoConnect() {
|
|
34
34
|
try {
|
|
35
|
-
setIsAuthenticating(true);
|
|
36
35
|
const connectResult = await connectTw();
|
|
37
36
|
const account = connectResult?.getAccount();
|
|
38
37
|
if (!account) {
|
|
@@ -47,6 +46,7 @@ export function SignInWithB3Privy({ onSuccess, onError, partnerId, chain }: Sign
|
|
|
47
46
|
await logout();
|
|
48
47
|
setIsAuthenticated(false);
|
|
49
48
|
} finally {
|
|
49
|
+
debug("@@setIsAuthenticating:false:7");
|
|
50
50
|
setIsAuthenticating(false);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { useAuthentication,
|
|
1
|
+
import { useAuthentication, useAuthStore, useB3, useQueryB3 } from "@b3dotfun/sdk/global-account/react";
|
|
2
2
|
import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
|
|
3
|
+
import { debug } from "@b3dotfun/sdk/shared/utils/debug";
|
|
3
4
|
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
4
5
|
import { Chain } from "thirdweb";
|
|
5
6
|
import { ConnectEmbed, darkTheme, lightTheme } from "thirdweb/react";
|
|
@@ -113,6 +114,7 @@ export function LoginStep({ onSuccess, onError, partnerId, chain }: LoginStepPro
|
|
|
113
114
|
onConnect={async wallet => {
|
|
114
115
|
try {
|
|
115
116
|
setIsAuthenticating(true);
|
|
117
|
+
debug("@@setIsAuthenticating:true:6");
|
|
116
118
|
|
|
117
119
|
const account = wallet.getAccount();
|
|
118
120
|
if (!account) throw new Error("No account found");
|
|
@@ -126,6 +128,7 @@ export function LoginStep({ onSuccess, onError, partnerId, chain }: LoginStepPro
|
|
|
126
128
|
await logout();
|
|
127
129
|
setIsAuthenticated(false);
|
|
128
130
|
} finally {
|
|
131
|
+
debug("@@setIsAuthenticating:false:6");
|
|
129
132
|
setIsAuthenticating(false);
|
|
130
133
|
}
|
|
131
134
|
}}
|
|
@@ -10,11 +10,12 @@ import {
|
|
|
10
10
|
useConnect,
|
|
11
11
|
WalletRow,
|
|
12
12
|
} from "@b3dotfun/sdk/global-account/react";
|
|
13
|
+
import { debug } from "@b3dotfun/sdk/shared/utils/debug";
|
|
14
|
+
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
13
15
|
import { useState } from "react";
|
|
14
16
|
import { Chain } from "thirdweb";
|
|
15
17
|
import { useConnect as useConnectTW } from "thirdweb/react";
|
|
16
18
|
import { Account, createWallet, Wallet, WalletId } from "thirdweb/wallets";
|
|
17
|
-
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
18
19
|
|
|
19
20
|
interface LoginStepCustomProps {
|
|
20
21
|
automaticallySetFirstEoa: boolean;
|
|
@@ -52,6 +53,7 @@ export function LoginStepCustom({
|
|
|
52
53
|
const handleConnect = async (strategy: AllowedStrategy) => {
|
|
53
54
|
try {
|
|
54
55
|
setIsLoading(true);
|
|
56
|
+
debug("@@setIsAuthenticating:true:3");
|
|
55
57
|
setIsAuthenticating(true);
|
|
56
58
|
const options = getConnectOptionsFromStrategy(strategy);
|
|
57
59
|
let connectResult: Wallet | null;
|
|
@@ -84,6 +86,7 @@ export function LoginStepCustom({
|
|
|
84
86
|
setIsAuthenticated(false);
|
|
85
87
|
} finally {
|
|
86
88
|
setIsLoading(false);
|
|
89
|
+
debug("@@setIsAuthenticating:false:3");
|
|
87
90
|
setIsAuthenticating(false);
|
|
88
91
|
}
|
|
89
92
|
};
|
|
@@ -44,7 +44,7 @@ export function useAuthentication(partnerId: string, loginWithSiwe?: boolean) {
|
|
|
44
44
|
setIsAuthenticated(true);
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
debug("@@setIsAuthenticating:true:4");
|
|
48
48
|
setIsAuthenticating(true);
|
|
49
49
|
const account = await wallet.getAccount();
|
|
50
50
|
if (!account) {
|
|
@@ -68,6 +68,7 @@ export function useAuthentication(partnerId: string, loginWithSiwe?: boolean) {
|
|
|
68
68
|
} catch (error) {
|
|
69
69
|
debug("Auto-connect authentication failed", { error });
|
|
70
70
|
setIsAuthenticated(false);
|
|
71
|
+
debug("@@setIsAuthenticating:false:4");
|
|
71
72
|
setUser();
|
|
72
73
|
}
|
|
73
74
|
},
|
|
@@ -76,17 +77,18 @@ export function useAuthentication(partnerId: string, loginWithSiwe?: boolean) {
|
|
|
76
77
|
// Ensure isAuthenticating stays true until we're fully ready
|
|
77
78
|
useEffect(() => {
|
|
78
79
|
if (useAutoConnectLoading) {
|
|
79
|
-
setIsAuthenticating(true);
|
|
80
80
|
setIsConnecting(true);
|
|
81
81
|
} else if (!isAuthenticated) {
|
|
82
82
|
// Only set isAuthenticating to false if we're not authenticated
|
|
83
83
|
// This prevents the flicker state where both isAuthenticating and isAuthenticated are false
|
|
84
84
|
const timeout = setTimeout(() => {
|
|
85
|
+
debug("@@setIsAuthenticating:false:5a");
|
|
85
86
|
setIsAuthenticating(false);
|
|
86
87
|
setIsConnecting(false);
|
|
87
88
|
}, 100); // Add a small delay to prevent quick flickers
|
|
88
89
|
return () => clearTimeout(timeout);
|
|
89
90
|
} else {
|
|
91
|
+
debug("@@setIsAuthenticating:false:5b");
|
|
90
92
|
setIsAuthenticating(false);
|
|
91
93
|
setIsConnecting(false);
|
|
92
94
|
}
|