@b3dotfun/sdk 0.0.83 → 0.0.84-alpha.0
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/constants/index.d.ts +1 -1
- package/dist/cjs/anyspend/constants/index.js +2 -2
- package/dist/cjs/anyspend/react/components/AnySpend.js +21 -9
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +4 -3
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +2 -4
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethodDisplay.js +28 -0
- package/dist/cjs/anyspend/react/components/common/InsufficientDepositPayment.js +1 -1
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +5 -4
- package/dist/cjs/anyspend/react/components/common/OrderToken.js +2 -2
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +1 -1
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmountFiat.js +1 -1
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmountNew.js +2 -2
- package/dist/cjs/anyspend/react/components/common/PaymentStripeWeb2.js +4 -6
- package/dist/cjs/anyspend/react/components/common/PaymentVendorUI.js +41 -2
- package/dist/cjs/anyspend/react/components/common/TransferCryptoDetails.js +1 -1
- package/dist/cjs/anyspend/react/components/webview/WebviewOnrampPayment.js +2 -3
- package/dist/cjs/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/hooks/index.js +1 -0
- package/dist/cjs/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
- package/dist/cjs/anyspend/react/hooks/useConnectedUserProfile.js +5 -8
- package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
- package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.js +2 -12
- package/dist/cjs/anyspend/react/hooks/useHyperliquidTransfer.d.ts +37 -0
- package/dist/cjs/anyspend/react/hooks/useHyperliquidTransfer.js +133 -0
- package/dist/cjs/anyspend/react/providers/AnyspendProvider.js +1 -13
- package/dist/cjs/anyspend/types/chain.d.ts +10 -2
- package/dist/cjs/anyspend/types/chain.js +1 -0
- package/dist/cjs/anyspend/utils/address.d.ts +11 -0
- package/dist/cjs/anyspend/utils/address.js +15 -0
- package/dist/cjs/anyspend/utils/chain.d.ts +20 -1
- package/dist/cjs/anyspend/utils/chain.js +73 -4
- package/dist/cjs/anyspend/utils/token.d.ts +1 -0
- package/dist/cjs/anyspend/utils/token.js +19 -6
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +3 -4
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +1 -1
- package/dist/cjs/global-account/react/hooks/index.d.ts +0 -1
- package/dist/cjs/global-account/react/hooks/index.js +1 -3
- package/dist/cjs/global-account/react/hooks/useAccountWallet.js +11 -10
- package/dist/cjs/shared/utils/payment.utils.d.ts +1 -0
- package/dist/cjs/shared/utils/payment.utils.js +9 -0
- package/dist/esm/anyspend/constants/index.d.ts +1 -1
- package/dist/esm/anyspend/constants/index.js +1 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +22 -10
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +5 -4
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +4 -6
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethodDisplay.js +25 -0
- package/dist/esm/anyspend/react/components/common/InsufficientDepositPayment.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +6 -5
- package/dist/esm/anyspend/react/components/common/OrderToken.js +3 -3
- package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderTokenAmountFiat.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderTokenAmountNew.js +3 -3
- package/dist/esm/anyspend/react/components/common/PaymentStripeWeb2.js +2 -4
- package/dist/esm/anyspend/react/components/common/PaymentVendorUI.js +9 -3
- package/dist/esm/anyspend/react/components/common/TransferCryptoDetails.js +2 -2
- package/dist/esm/anyspend/react/components/webview/WebviewOnrampPayment.js +3 -4
- package/dist/esm/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/esm/anyspend/react/hooks/index.js +1 -0
- package/dist/esm/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
- package/dist/esm/anyspend/react/hooks/useConnectedUserProfile.js +6 -9
- package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
- package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.js +2 -12
- package/dist/esm/anyspend/react/hooks/useHyperliquidTransfer.d.ts +37 -0
- package/dist/esm/anyspend/react/hooks/useHyperliquidTransfer.js +127 -0
- package/dist/esm/anyspend/react/providers/AnyspendProvider.js +1 -13
- package/dist/esm/anyspend/types/chain.d.ts +10 -2
- package/dist/esm/anyspend/types/chain.js +1 -0
- package/dist/esm/anyspend/utils/address.d.ts +11 -0
- package/dist/esm/anyspend/utils/address.js +14 -0
- package/dist/esm/anyspend/utils/chain.d.ts +20 -1
- package/dist/esm/anyspend/utils/chain.js +70 -4
- package/dist/esm/anyspend/utils/token.d.ts +1 -0
- package/dist/esm/anyspend/utils/token.js +19 -7
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +4 -5
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +1 -1
- package/dist/esm/global-account/react/hooks/index.d.ts +0 -1
- package/dist/esm/global-account/react/hooks/index.js +0 -1
- package/dist/esm/global-account/react/hooks/useAccountWallet.js +11 -10
- package/dist/esm/shared/utils/payment.utils.d.ts +1 -0
- package/dist/esm/shared/utils/payment.utils.js +9 -1
- package/dist/types/anyspend/constants/index.d.ts +1 -1
- package/dist/types/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
- package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
- package/dist/types/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
- package/dist/types/anyspend/react/hooks/useHyperliquidTransfer.d.ts +37 -0
- package/dist/types/anyspend/types/chain.d.ts +10 -2
- package/dist/types/anyspend/utils/address.d.ts +11 -0
- package/dist/types/anyspend/utils/chain.d.ts +20 -1
- package/dist/types/anyspend/utils/token.d.ts +1 -0
- package/dist/types/global-account/react/hooks/index.d.ts +0 -1
- package/dist/types/shared/utils/payment.utils.d.ts +1 -0
- package/package.json +1 -1
- package/src/anyspend/constants/index.ts +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +31 -9
- package/src/anyspend/react/components/AnySpendCustom.tsx +9 -25
- package/src/anyspend/react/components/common/CryptoPaySection.tsx +7 -30
- package/src/anyspend/react/components/common/CryptoPaymentMethodDisplay.tsx +64 -0
- package/src/anyspend/react/components/common/InsufficientDepositPayment.tsx +2 -2
- package/src/anyspend/react/components/common/OrderDetails.tsx +6 -5
- package/src/anyspend/react/components/common/OrderToken.tsx +5 -5
- package/src/anyspend/react/components/common/OrderTokenAmount.tsx +3 -3
- package/src/anyspend/react/components/common/OrderTokenAmountFiat.tsx +3 -3
- package/src/anyspend/react/components/common/OrderTokenAmountNew.tsx +6 -6
- package/src/anyspend/react/components/common/PaymentStripeWeb2.tsx +3 -5
- package/src/anyspend/react/components/common/PaymentVendorUI.tsx +26 -2
- package/src/anyspend/react/components/common/TransferCryptoDetails.tsx +2 -2
- package/src/anyspend/react/components/webview/WebviewOnrampPayment.tsx +3 -5
- package/src/anyspend/react/hooks/index.ts +1 -0
- package/src/anyspend/react/hooks/useConnectedUserProfile.ts +7 -10
- package/src/anyspend/react/hooks/useConnectedWalletDisplay.ts +2 -15
- package/src/anyspend/react/hooks/useHyperliquidTransfer.ts +152 -0
- package/src/anyspend/react/providers/AnyspendProvider.tsx +7 -22
- package/src/anyspend/types/chain.ts +10 -1
- package/src/anyspend/utils/address.ts +15 -0
- package/src/anyspend/utils/chain.ts +84 -4
- package/src/anyspend/utils/token.ts +20 -7
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +6 -2
- package/src/global-account/react/components/SignInWithB3/SignIn.tsx +4 -6
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +1 -1
- package/src/global-account/react/hooks/index.ts +0 -1
- package/src/global-account/react/hooks/useAccountWallet.tsx +12 -11
- package/src/shared/utils/payment.utils.ts +10 -1
- package/dist/cjs/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
- package/dist/cjs/global-account/react/hooks/useBestTransactionPath.js +0 -148
- package/dist/esm/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
- package/dist/esm/global-account/react/hooks/useBestTransactionPath.js +0 -145
- package/dist/types/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
- package/src/global-account/react/hooks/useBestTransactionPath.tsx +0 -201
|
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { ChevronsUpDown } from "lucide-react";
|
|
4
4
|
import { useEffect, useRef } from "react";
|
|
5
5
|
import { NumericFormat } from "react-number-format";
|
|
6
|
-
import { ALL_CHAINS, RELAY_SOLANA_MAINNET_CHAIN_ID } from "../../../../anyspend/index.js";
|
|
6
|
+
import { ALL_CHAINS, RELAY_SOLANA_MAINNET_CHAIN_ID, getAvailableChainIds } from "../../../../anyspend/index.js";
|
|
7
7
|
import { Button } from "../../../../global-account/react/index.js";
|
|
8
8
|
import { cn } from "../../../../shared/utils/index.js";
|
|
9
9
|
import { TokenSelector } from "@relayprotocol/relay-kit-ui";
|
|
@@ -53,8 +53,8 @@ export function OrderTokenAmountFiat({ disabled, inputValue, onChangeInput, cont
|
|
|
53
53
|
};
|
|
54
54
|
if (showAsReceiveAmount) {
|
|
55
55
|
// Design-matched token display for receive amounts (like in PanelOnramp)
|
|
56
|
-
return (_jsxs("div", { className: cn("flex items-center justify-between rounded-xl bg-gray-50 p-4", className), children: [_jsxs("div", { className: "flex items-center gap-3", children: [token.metadata?.logoURI ? (_jsx(ChainTokenIcon, { chainUrl: ALL_CHAINS[chainId]?.logoUrl, tokenUrl: token.metadata.logoURI, className: "h-10 w-10" })) : (_jsx("div", { className: "flex h-10 w-10 items-center justify-center rounded-full bg-blue-600", children: _jsx("span", { className: "font-bold text-white", children: token.symbol?.substring(0, 2) || "??" }) })), _jsxs("div", { children: [_jsx("div", { className: "text-base font-semibold text-gray-900", children: token.symbol }), _jsx("div", { className: "text-sm text-gray-600", children: ALL_CHAINS[chainId]?.name || "Unknown" })] })] }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "text-sm text-gray-600", children: "\u2248" }), _jsx("span", { className: "text-lg font-semibold text-gray-900", children: formatAmount(inputValue) }), !hideTokenSelect && (_jsx(TokenSelector, { address: address, chainIdsFilter:
|
|
56
|
+
return (_jsxs("div", { className: cn("flex items-center justify-between rounded-xl bg-gray-50 p-4", className), children: [_jsxs("div", { className: "flex items-center gap-3", children: [token.metadata?.logoURI ? (_jsx(ChainTokenIcon, { chainUrl: ALL_CHAINS[chainId]?.logoUrl, tokenUrl: token.metadata.logoURI, className: "h-10 w-10" })) : (_jsx("div", { className: "flex h-10 w-10 items-center justify-center rounded-full bg-blue-600", children: _jsx("span", { className: "font-bold text-white", children: token.symbol?.substring(0, 2) || "??" }) })), _jsxs("div", { children: [_jsx("div", { className: "text-base font-semibold text-gray-900", children: token.symbol }), _jsx("div", { className: "text-sm text-gray-600", children: ALL_CHAINS[chainId]?.name || "Unknown" })] })] }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "text-sm text-gray-600", children: "\u2248" }), _jsx("span", { className: "text-lg font-semibold text-gray-900", children: formatAmount(inputValue) }), !hideTokenSelect && (_jsx(TokenSelector, { address: address, chainIdsFilter: getAvailableChainIds(context), context: context, fromChainWalletVMSupported: true, isValidAddress: true, lockedChainIds: getAvailableChainIds(context), multiWalletSupportEnabled: true, onAnalyticEvent: undefined, popularChainIds: [1, 8453, RELAY_SOLANA_MAINNET_CHAIN_ID], setToken: handleTokenSelect, supportedWalletVMs: ["evm", "svm"], token: undefined, trigger: _jsx(ChevronsUpDown, { className: "h-4 w-4 cursor-pointer text-gray-400" }) }, `selector-${context}-${token.address}-${chainId}`))] })] }));
|
|
57
57
|
}
|
|
58
58
|
// Original token amount input design for other contexts
|
|
59
|
-
return (_jsx("div", { className: cn("border-as-stroke flex w-full flex-col gap-2 rounded-xl", className), children: _jsxs("div", { className: "flex items-center justify-between gap-3", children: [!canEditAmount ? (_jsx("h2", { className: "text-3xl font-medium text-white", children: inputValue || "--" })) : (_jsx(NumericFormat, { decimalSeparator: ".", allowedDecimalSeparators: [","], thousandSeparator: true, inputMode: "decimal", autoComplete: "off", autoCorrect: "off", type: "text", placeholder: "0.00", minLength: 1, maxLength: 30, spellCheck: "false", className: "placeholder:text-as-primary/70 disabled:text-as-primary/70 text-as-primary w-full bg-transparent text-4xl font-semibold leading-[42px] outline-none sm:text-[30px]", pattern: "^[0-9]*[.,]?[0-9]*$", disabled: disabled, value: inputValue, allowNegative: false, onChange: e => onChangeInput(e.currentTarget.value) }, `input-${token.address}-${chainId}`)), !hideTokenSelect && (_jsx(TokenSelector, { address: address, chainIdsFilter:
|
|
59
|
+
return (_jsx("div", { className: cn("border-as-stroke flex w-full flex-col gap-2 rounded-xl", className), children: _jsxs("div", { className: "flex items-center justify-between gap-3", children: [!canEditAmount ? (_jsx("h2", { className: "text-3xl font-medium text-white", children: inputValue || "--" })) : (_jsx(NumericFormat, { decimalSeparator: ".", allowedDecimalSeparators: [","], thousandSeparator: true, inputMode: "decimal", autoComplete: "off", autoCorrect: "off", type: "text", placeholder: "0.00", minLength: 1, maxLength: 30, spellCheck: "false", className: "placeholder:text-as-primary/70 disabled:text-as-primary/70 text-as-primary w-full bg-transparent text-4xl font-semibold leading-[42px] outline-none sm:text-[30px]", pattern: "^[0-9]*[.,]?[0-9]*$", disabled: disabled, value: inputValue, allowNegative: false, onChange: e => onChangeInput(e.currentTarget.value) }, `input-${token.address}-${chainId}`)), !hideTokenSelect && (_jsx(TokenSelector, { address: address, chainIdsFilter: getAvailableChainIds(context), context: context, fromChainWalletVMSupported: true, isValidAddress: true, lockedChainIds: getAvailableChainIds(context), multiWalletSupportEnabled: true, onAnalyticEvent: undefined, popularChainIds: [1, 8453, RELAY_SOLANA_MAINNET_CHAIN_ID], setToken: handleTokenSelect, supportedWalletVMs: ["evm", "svm"], token: undefined, trigger: _jsxs(Button, { variant: "outline", role: "combobox", className: "bg-b3-react-background border-as-stroke flex h-auto w-fit shrink-0 items-center justify-center gap-2 rounded-xl border-2 px-2 py-1 pr-2 text-center", children: [token.metadata?.logoURI ? (_jsx(ChainTokenIcon, { chainUrl: ALL_CHAINS[chainId]?.logoUrl, tokenUrl: token.metadata.logoURI, className: "h-8 min-h-8 w-8 min-w-8" })) : (_jsx("div", { className: "h-8 w-8 rounded-full bg-gray-700" })), _jsxs("div", { className: "flex flex-col items-start gap-0", children: [_jsx("div", { className: "text-as-primary font-semibold", children: token.symbol }), _jsx("div", { className: "text-as-primary/70 text-xs", children: ALL_CHAINS[chainId]?.name })] }), _jsx(ChevronsUpDown, { className: "h-4 w-4 shrink-0 opacity-70" })] }) }, `selector-${context}-${token.address}-${chainId}`))] }) }, `${context}-${token.address}-${chainId}`));
|
|
60
60
|
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { getStripePromise } from "../../../../shared/utils/payment.utils.js";
|
|
3
3
|
import { OrderDetailsCollapsible, useStripeClientSecret } from "../../../../anyspend/react/index.js";
|
|
4
4
|
import { ShinyButton, useB3, useModalStore, useProfile } from "../../../../global-account/react/index.js";
|
|
5
5
|
import { formatTokenAmount } from "../../../../shared/utils/number.js";
|
|
6
6
|
import { formatStripeAmount } from "../../../../shared/utils/payment.utils.js";
|
|
7
7
|
import { AddressElement, Elements, PaymentElement, useElements, useStripe } from "@stripe/react-stripe-js";
|
|
8
|
-
import { loadStripe } from "@stripe/stripe-js";
|
|
9
8
|
import { X } from "lucide-react";
|
|
10
9
|
import { useEffect, useState } from "react";
|
|
11
10
|
import { AnySpendFingerprintWrapper, getFingerprintConfig } from "../AnySpendFingerprintWrapper.js";
|
|
12
11
|
import HowItWorks from "./HowItWorks.js";
|
|
13
12
|
import PaymentMethodIcons from "./PaymentMethodIcons.js";
|
|
14
|
-
const stripePromise = loadStripe(STRIPE_CONFIG.publishableKey);
|
|
15
13
|
export default function PaymentStripeWeb2({ order, stripePaymentIntentId, onPaymentSuccess }) {
|
|
16
14
|
const { theme } = useB3();
|
|
17
15
|
const fingerprintConfig = getFingerprintConfig();
|
|
@@ -22,7 +20,7 @@ export default function PaymentStripeWeb2({ order, stripePaymentIntentId, onPaym
|
|
|
22
20
|
if (stripeClientSecretError) {
|
|
23
21
|
return _jsx(StripeErrorState, { error: stripeClientSecretError.message });
|
|
24
22
|
}
|
|
25
|
-
return (_jsx(AnySpendFingerprintWrapper, { fingerprint: fingerprintConfig, children: _jsx(Elements, { stripe:
|
|
23
|
+
return (_jsx(AnySpendFingerprintWrapper, { fingerprint: fingerprintConfig, children: _jsx(Elements, { stripe: getStripePromise(), options: {
|
|
26
24
|
clientSecret: clientSecret || undefined,
|
|
27
25
|
appearance: { theme: theme === "light" ? "stripe" : "night" },
|
|
28
26
|
}, children: _jsx(StripePaymentForm, { order: order, clientSecret: clientSecret, onPaymentSuccess: onPaymentSuccess }) }) }));
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { lazy, Suspense } from "react";
|
|
2
3
|
import PaymentOneClick from "./PaymentOneClick.js";
|
|
3
|
-
|
|
4
|
+
// Lazy load Stripe component to prevent loadStripe() from running at module level
|
|
5
|
+
// This prevents EIP-6963 wallet detection events when Stripe is not used
|
|
6
|
+
const PaymentStripeWeb2 = lazy(() => import("./PaymentStripeWeb2"));
|
|
7
|
+
function StripeLoadingFallback() {
|
|
8
|
+
return (_jsx("div", { className: "relative my-8 flex w-full flex-1 flex-col items-center justify-center", children: _jsxs("div", { className: "bg-as-on-surface-1 flex w-full flex-col items-center justify-center gap-4 rounded-2xl p-8", children: [_jsx("div", { className: "bg-as-brand/20 flex h-16 w-16 items-center justify-center rounded-full", children: _jsx("div", { className: "text-as-brand h-8 w-8 animate-spin rounded-full border-2 border-current border-t-transparent" }) }), _jsxs("div", { className: "text-as-primary/70 text-center", children: [_jsx("div", { className: "text-lg font-medium", children: "Loading payment" }), _jsx("div", { className: "text-as-primary/50 mt-2 text-sm", children: "Initializing secure payment form..." })] })] }) }));
|
|
9
|
+
}
|
|
4
10
|
export default function PaymentVendorUI({ order, dstTokenSymbol }) {
|
|
5
11
|
const vendor = order.onrampMetadata?.vendor;
|
|
6
12
|
// Handle one-click payment flows (Coinbase, Stripe redirect)
|
|
@@ -9,7 +15,7 @@ export default function PaymentVendorUI({ order, dstTokenSymbol }) {
|
|
|
9
15
|
}
|
|
10
16
|
// Handle Stripe Web2 payment flow
|
|
11
17
|
if (vendor === "stripe-web2" && order.stripePaymentIntentId) {
|
|
12
|
-
return _jsx(PaymentStripeWeb2, { order: order, stripePaymentIntentId: order.stripePaymentIntentId });
|
|
18
|
+
return (_jsx(Suspense, { fallback: _jsx(StripeLoadingFallback, {}), children: _jsx(PaymentStripeWeb2, { order: order, stripePaymentIntentId: order.stripePaymentIntentId }) }));
|
|
13
19
|
}
|
|
14
20
|
// Return null for unsupported vendors
|
|
15
21
|
return null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { ALL_CHAINS, getChainName, getPaymentUrl,
|
|
3
|
+
import { ALL_CHAINS, getChainName, getPaymentUrl, ZERO_ADDRESS } from "../../../../anyspend/index.js";
|
|
4
4
|
import { CopyToClipboard, ShinyButton, TextLoop, toast } from "../../../../global-account/react/index.js";
|
|
5
5
|
import { cn } from "../../../../shared/utils/index.js";
|
|
6
6
|
import { formatTokenAmount } from "../../../../shared/utils/number.js";
|
|
@@ -67,5 +67,5 @@ export const TransferCryptoDetails = memo(function TransferCryptoDetails({ order
|
|
|
67
67
|
transition: "stroke-dashoffset 1s linear",
|
|
68
68
|
} })] }), _jsx("div", { className: "order-transfer-crypto-timer-text absolute inset-0 flex items-center justify-center", children: _jsx("span", { className: "text-as-primary text-[10px] font-semibold", children: formatTime(timeLeft) }) })] })] }), _jsxs("div", { className: "order-transfer-crypto-content flex w-full flex-col gap-4", children: [_jsxs("div", { className: "order-transfer-crypto-cards flex items-center gap-4", children: [_jsxs("div", { className: "order-transfer-crypto-amount-card w-full", children: [_jsx("span", { className: "order-transfer-crypto-amount-label text-as-content-secondary text-sm font-medium", children: "Amount" }), _jsx("div", { className: "order-transfer-crypto-amount-container border-as-border-primary rounded-lg border p-2 shadow-sm", children: _jsx(CopyToClipboard, { text: roundedUpSrcAmount || "", onCopy: () => {
|
|
69
69
|
toast.success("Amount copied to clipboard");
|
|
70
|
-
}, children: _jsxs("div", { className: "order-transfer-crypto-amount-copy flex cursor-pointer items-center justify-between gap-2", children: [_jsxs("strong", { className: "order-transfer-crypto-amount-text text-as-primary font-semibold", children: [roundedUpSrcAmount, " ", srcToken.symbol] }), _jsx(Copy, { className: "order-transfer-crypto-amount-copy-icon text-as-primary/50 hover:text-as-primary h-4 w-4 transition-all duration-200" })] }) }) })] }), _jsxs("div", { className: "order-transfer-crypto-chain-card w-full", children: [_jsx("span", { className: "order-transfer-crypto-chain-label text-as-content-secondary text-sm font-medium", children: "Chain" }), _jsx("div", { className: "order-transfer-crypto-chain-container border-as-border-primary rounded-lg border p-2 shadow-sm", children: _jsxs("div", { className: "order-transfer-crypto-chain-info flex items-center gap-2", children: [_jsx("img", { src: ALL_CHAINS[order.srcChain].logoUrl, alt: getChainName(order.srcChain), className: cn("order-transfer-crypto-chain-logo h-6 rounded-full", order.srcChain === b3.id && "h-5 rounded-none") }), _jsx("span", { className: "order-transfer-crypto-chain-name text-as-primary text-sm font-semibold", children: getChainName(order.srcChain) })] }) })] })] }), _jsxs("div", { className: "order-transfer-crypto-qr-deposit-card border-b3-react-border bg-as-surface-secondary grid h-[220px] grid-cols-2 overflow-hidden rounded-xl border", children: [_jsx("div", { className: "order-transfer-crypto-qr-section border-as-border-primary h-full w-full border-r", children: _jsx("div", { className: "order-transfer-crypto-qr-wrapper flex justify-center", children: _jsxs("div", { className: "order-transfer-crypto-qr-container bg-as-surface-secondary flex flex-col items-center rounded-lg p-6", children: [_jsx(QRCodeSVG, { value: getPaymentUrl(order.globalAddress, BigInt(order.srcAmount), order.srcTokenAddress ===
|
|
70
|
+
}, children: _jsxs("div", { className: "order-transfer-crypto-amount-copy flex cursor-pointer items-center justify-between gap-2", children: [_jsxs("strong", { className: "order-transfer-crypto-amount-text text-as-primary font-semibold", children: [roundedUpSrcAmount, " ", srcToken.symbol] }), _jsx(Copy, { className: "order-transfer-crypto-amount-copy-icon text-as-primary/50 hover:text-as-primary h-4 w-4 transition-all duration-200" })] }) }) })] }), _jsxs("div", { className: "order-transfer-crypto-chain-card w-full", children: [_jsx("span", { className: "order-transfer-crypto-chain-label text-as-content-secondary text-sm font-medium", children: "Chain" }), _jsx("div", { className: "order-transfer-crypto-chain-container border-as-border-primary rounded-lg border p-2 shadow-sm", children: _jsxs("div", { className: "order-transfer-crypto-chain-info flex items-center gap-2", children: [_jsx("img", { src: ALL_CHAINS[order.srcChain].logoUrl, alt: getChainName(order.srcChain), className: cn("order-transfer-crypto-chain-logo h-6 rounded-full", order.srcChain === b3.id && "h-5 rounded-none") }), _jsx("span", { className: "order-transfer-crypto-chain-name text-as-primary text-sm font-semibold", children: getChainName(order.srcChain) })] }) })] })] }), _jsxs("div", { className: "order-transfer-crypto-qr-deposit-card border-b3-react-border bg-as-surface-secondary grid h-[220px] grid-cols-2 overflow-hidden rounded-xl border", children: [_jsx("div", { className: "order-transfer-crypto-qr-section border-as-border-primary h-full w-full border-r", children: _jsx("div", { className: "order-transfer-crypto-qr-wrapper flex justify-center", children: _jsxs("div", { className: "order-transfer-crypto-qr-container bg-as-surface-secondary flex flex-col items-center rounded-lg p-6", children: [_jsx(QRCodeSVG, { value: getPaymentUrl(order.globalAddress, BigInt(order.srcAmount), order.srcTokenAddress === ZERO_ADDRESS ? "ETH" : order.srcTokenAddress, order.srcChain, srcToken?.decimals), className: "order-transfer-crypto-qr-code bg-as-surface-secondary max-h-48 max-w-48" }), _jsxs("div", { className: "order-transfer-crypto-wallet-hint mt-3 flex items-center justify-center gap-2 text-sm", children: [_jsx("span", { className: "order-transfer-crypto-wallet-text text-as-brand/70 text-sm font-medium", children: "SCAN WITH" }), _jsxs(TextLoop, { interval: 3, children: [_jsx(WalletMetamask, { className: "order-transfer-crypto-wallet-icon h-5 w-5", variant: "branded" }), _jsx(WalletCoinbase, { className: "order-transfer-crypto-wallet-icon h-5 w-5", variant: "branded" }), _jsx(WalletPhantom, { className: "order-transfer-crypto-wallet-icon h-5 w-5", variant: "branded" }), _jsx(WalletTrust, { className: "order-transfer-crypto-wallet-icon h-5 w-5", variant: "branded" })] })] })] }) }) }), _jsxs("div", { className: "order-transfer-crypto-address-section flex h-full w-full flex-col gap-2 p-6", children: [_jsx("span", { className: "order-transfer-crypto-address-label text-as-content-secondary text-sm font-medium", children: "Deposit address:" }), _jsxs("div", { className: "order-transfer-crypto-address-copy flex h-full cursor-pointer flex-col items-stretch justify-between gap-4", onClick: handleCopyAddress, children: [_jsx("div", { className: "order-transfer-crypto-address-text text-as-primary break-all font-mono text-sm font-semibold leading-relaxed", children: order.globalAddress }), _jsx("div", { className: "order-transfer-crypto-address-copy-icon-wrapper place-self-end", children: _jsx(Copy, { className: "order-transfer-crypto-address-copy-icon group-hover:text-as-brand text-as-tertiarry h-4 w-4 cursor-pointer transition-all duration-200" }) })] })] })] }), _jsx(OrderDetailsCollapsible, { order: order, dstToken: dstToken, tournament: tournament, nft: nft, recipientName: recipientName, formattedExpectedDstAmount: formattedExpectedDstAmount })] }), _jsxs("div", { className: "order-transfer-crypto-actions flex flex-col gap-3", children: [_jsx(ShinyButton, { accentColor: "hsl(var(--as-brand))", textColor: "text-white", className: "order-transfer-crypto-copy-btn w-full py-3", onClick: handleCopyAddress, children: "Copy deposit address" }), _jsx(PaymentMethodSwitch, { currentMethod: CryptoPaymentMethodType.TRANSFER_CRYPTO, onMethodChange: onPaymentMethodChange })] })] }));
|
|
71
71
|
});
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { getChainName
|
|
2
|
+
import { getChainName } from "../../../../anyspend/index.js";
|
|
3
|
+
import { getStripePromise } from "../../../../shared/utils/payment.utils.js";
|
|
3
4
|
import { useAnyspendCreateOnrampOrder, useGeoOnrampOptions, useStripeClientSecret } from "../../../../anyspend/react/index.js";
|
|
4
5
|
import { toast } from "../../../../global-account/react/index.js";
|
|
5
6
|
import centerTruncate from "../../../../shared/utils/centerTruncate.js";
|
|
6
7
|
import { AddressElement, Elements, PaymentElement, useElements, useStripe } from "@stripe/react-stripe-js";
|
|
7
|
-
import { loadStripe } from "@stripe/stripe-js";
|
|
8
8
|
import { Loader2 } from "lucide-react";
|
|
9
9
|
import { motion } from "motion/react";
|
|
10
10
|
import { useEffect, useRef, useState } from "react";
|
|
11
11
|
import { formatUnits } from "viem";
|
|
12
12
|
import { AnySpendFingerprintWrapper, getFingerprintConfig } from "../AnySpendFingerprintWrapper.js";
|
|
13
|
-
const stripePromise = loadStripe(STRIPE_CONFIG.publishableKey);
|
|
14
13
|
export function WebviewOnrampPayment(props) {
|
|
15
14
|
const fingerprintConfig = getFingerprintConfig();
|
|
16
15
|
return (_jsx(AnySpendFingerprintWrapper, { fingerprint: fingerprintConfig, children: _jsx(WebviewOnrampPaymentInner, { ...props }) }));
|
|
@@ -163,7 +162,7 @@ function WebviewOnrampPaymentInner({ srcAmountOnRamp, recipientAddress, destinat
|
|
|
163
162
|
if (createdOrder && clientSecret) {
|
|
164
163
|
return (_jsxs("div", { className: "mx-auto flex w-full max-w-[460px] flex-col gap-6", children: [_jsx("div", { className: "overflow-hidden rounded-xl bg-white", children: _jsxs("div", { className: "px-6 py-4", children: [_jsx("h2", { className: "mb-4 text-lg font-semibold", children: "Order summary" }), _jsxs("div", { className: "flex flex-col divide-y", children: [_jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Receiving" }), _jsxs("div", { className: "flex items-center gap-2", children: [destinationToken.metadata?.logoURI && (_jsx("img", { src: destinationToken.metadata.logoURI, alt: destinationToken.symbol, className: "h-5 w-5 rounded-full" })), _jsxs("span", { className: "font-medium", children: [anyspendQuote?.data?.currencyOut?.amount
|
|
165
164
|
? Number(formatUnits(BigInt(anyspendQuote.data.currencyOut.amount), destinationToken.decimals)).toFixed(4)
|
|
166
|
-
: "0", " ", destinationToken.symbol] })] })] }), _jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Network" }), _jsx("span", { className: "font-medium", children: getChainName(destinationToken.chainId) })] }), recipientAddress && (_jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Recipient" }), _jsx("span", { className: "font-medium", children: centerTruncate(recipientAddress) })] })), _jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "You Pay" }), _jsxs("span", { className: "text-lg font-semibold", children: ["$", parseFloat(srcAmountOnRamp).toFixed(2)] })] })] })] }) }), _jsx(Elements, { stripe:
|
|
165
|
+
: "0", " ", destinationToken.symbol] })] })] }), _jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Network" }), _jsx("span", { className: "font-medium", children: getChainName(destinationToken.chainId) })] }), recipientAddress && (_jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Recipient" }), _jsx("span", { className: "font-medium", children: centerTruncate(recipientAddress) })] })), _jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "You Pay" }), _jsxs("span", { className: "text-lg font-semibold", children: ["$", parseFloat(srcAmountOnRamp).toFixed(2)] })] })] })] }) }), _jsx(Elements, { stripe: getStripePromise(), options: {
|
|
167
166
|
clientSecret,
|
|
168
167
|
appearance: {
|
|
169
168
|
theme: "flat",
|
|
@@ -8,6 +8,7 @@ export * from "./useCoinbaseOnrampOptions";
|
|
|
8
8
|
export * from "./useConnectedUserProfile";
|
|
9
9
|
export * from "./useGeoOnrampOptions";
|
|
10
10
|
export * from "./useGetGeo";
|
|
11
|
+
export * from "./useHyperliquidTransfer";
|
|
11
12
|
export * from "./useRecipientAddressState";
|
|
12
13
|
export * from "./useSigMint";
|
|
13
14
|
export * from "./useStripeClientSecret";
|
|
@@ -8,6 +8,7 @@ export * from "./useCoinbaseOnrampOptions.js";
|
|
|
8
8
|
export * from "./useConnectedUserProfile.js";
|
|
9
9
|
export * from "./useGeoOnrampOptions.js";
|
|
10
10
|
export * from "./useGetGeo.js";
|
|
11
|
+
export * from "./useHyperliquidTransfer.js";
|
|
11
12
|
export * from "./useRecipientAddressState.js";
|
|
12
13
|
export * from "./useSigMint.js";
|
|
13
14
|
export * from "./useStripeClientSecret.js";
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod";
|
|
1
2
|
/**
|
|
2
3
|
* Hook that provides connected user's address, profile, and cleaned display name
|
|
3
4
|
* Combines logic for getting connected address from either global account or thirdweb wallets
|
|
4
5
|
*/
|
|
5
|
-
export declare function useConnectedUserProfile(): {
|
|
6
|
+
export declare function useConnectedUserProfile(selectedCryptoPaymentMethod?: CryptoPaymentMethodType): {
|
|
6
7
|
address: string | undefined;
|
|
7
8
|
profile: import("@tanstack/react-query").UseQueryResult<import("../../../global-account/react").CombinedProfile, Error>;
|
|
8
9
|
name: string | null | undefined;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useProfile } from "../../../global-account/react/index.js";
|
|
2
|
+
import { useConnectedWalletDisplay } from "./useConnectedWalletDisplay.js";
|
|
3
3
|
/**
|
|
4
4
|
* Hook that provides connected user's address, profile, and cleaned display name
|
|
5
5
|
* Combines logic for getting connected address from either global account or thirdweb wallets
|
|
6
6
|
*/
|
|
7
|
-
export function useConnectedUserProfile() {
|
|
8
|
-
const {
|
|
9
|
-
const connectedWallets = useConnectedWallets();
|
|
10
|
-
// Get connected address from global account or first connected wallet
|
|
11
|
-
const connectedAddress = globalAddress || connectedWallets?.[0]?.getAccount()?.address;
|
|
7
|
+
export function useConnectedUserProfile(selectedCryptoPaymentMethod) {
|
|
8
|
+
const { walletAddress } = useConnectedWalletDisplay(selectedCryptoPaymentMethod);
|
|
12
9
|
// Fetch profile data for the connected address with cleaned name
|
|
13
|
-
const connectedProfile = useProfile({ address:
|
|
10
|
+
const connectedProfile = useProfile({ address: walletAddress });
|
|
14
11
|
return {
|
|
15
|
-
address:
|
|
12
|
+
address: walletAddress,
|
|
16
13
|
profile: connectedProfile,
|
|
17
14
|
name: connectedProfile.data?.name,
|
|
18
15
|
isLoading: connectedProfile.isLoading,
|
|
@@ -2,8 +2,6 @@ import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMetho
|
|
|
2
2
|
interface UseConnectedWalletDisplayResult {
|
|
3
3
|
walletAddress: string | undefined;
|
|
4
4
|
shouldShowConnectedEOA: boolean;
|
|
5
|
-
shouldShowWagmiWallet: boolean;
|
|
6
|
-
isWalletDuplicated: boolean;
|
|
7
5
|
suggestedPaymentMethod: CryptoPaymentMethodType;
|
|
8
6
|
}
|
|
9
7
|
/**
|
|
@@ -9,23 +9,15 @@ export function useConnectedWalletDisplay(selectedCryptoPaymentMethod) {
|
|
|
9
9
|
const { connectedEOAWallet, connectedSmartWallet } = useAccountWallet();
|
|
10
10
|
const { address: wagmiAddress } = useAccount();
|
|
11
11
|
const globalWalletAddress = connectedSmartWallet?.getAccount()?.address;
|
|
12
|
-
// Helper function to check if two addresses are the same
|
|
13
|
-
const isSameAddress = (addr1, addr2) => {
|
|
14
|
-
if (!addr1 || !addr2)
|
|
15
|
-
return false;
|
|
16
|
-
return addr1.toLowerCase() === addr2.toLowerCase();
|
|
17
|
-
};
|
|
18
12
|
// Check if connectedEOAWallet and wagmi wallet represent the same wallet
|
|
19
13
|
const connectedEOAAddress = connectedEOAWallet?.getAccount()?.address;
|
|
20
|
-
const isWalletDuplicated = isSameAddress(connectedEOAAddress, wagmiAddress) || isSameAddress(globalWalletAddress, wagmiAddress);
|
|
21
14
|
// Determine which wallet to show (prefer connectedEOAWallet if both exist and are the same)
|
|
22
15
|
const shouldShowConnectedEOA = !!connectedEOAWallet;
|
|
23
16
|
// this is disabled because we don't want to display In-App Wallet as a payment method
|
|
24
|
-
const shouldShowWagmiWallet = false; // wagmiWalletIsConnected && (!isWalletDuplicated || !connectedEOAWallet);
|
|
25
17
|
// Determine which address to use based on payment method
|
|
26
18
|
let walletAddress;
|
|
27
19
|
if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET) {
|
|
28
|
-
walletAddress =
|
|
20
|
+
walletAddress = globalWalletAddress;
|
|
29
21
|
}
|
|
30
22
|
else if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
31
23
|
// Prefer connectedEOAWallet, fallback to wagmi wallet
|
|
@@ -42,15 +34,13 @@ export function useConnectedWalletDisplay(selectedCryptoPaymentMethod) {
|
|
|
42
34
|
// If there's a connected EOA or wagmi wallet, suggest CONNECT_WALLET
|
|
43
35
|
suggestedPaymentMethod = CryptoPaymentMethodType.CONNECT_WALLET;
|
|
44
36
|
}
|
|
45
|
-
else if (
|
|
37
|
+
else if (globalWalletAddress) {
|
|
46
38
|
// If only global wallet is available, suggest that
|
|
47
39
|
suggestedPaymentMethod = CryptoPaymentMethodType.GLOBAL_WALLET;
|
|
48
40
|
}
|
|
49
41
|
return {
|
|
50
42
|
walletAddress,
|
|
51
43
|
shouldShowConnectedEOA,
|
|
52
|
-
shouldShowWagmiWallet,
|
|
53
|
-
isWalletDuplicated,
|
|
54
44
|
suggestedPaymentMethod,
|
|
55
45
|
};
|
|
56
46
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
interface HyperliquidTransferParams {
|
|
2
|
+
/** Amount in smallest unit (USDC has 6 decimals) */
|
|
3
|
+
amount: string;
|
|
4
|
+
/** Recipient address */
|
|
5
|
+
destination: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated This hook is NOT USED in production.
|
|
9
|
+
*
|
|
10
|
+
* Hyperliquid is only supported as DESTINATION CHAIN (not source chain).
|
|
11
|
+
* Users cannot send FROM Hyperliquid in our flow, so EIP-712 signing is not needed.
|
|
12
|
+
*
|
|
13
|
+
* This hook was created during initial planning but is kept for:
|
|
14
|
+
* - Reference if we need to support source chain in the future
|
|
15
|
+
* - Understanding how Hyperliquid EIP-712 transfers work
|
|
16
|
+
*
|
|
17
|
+
* DO NOT USE THIS HOOK IN PRODUCTION CODE.
|
|
18
|
+
*
|
|
19
|
+
* Custom hook for handling Hyperliquid transfers via EIP-712 signature.
|
|
20
|
+
* Based on Relay SDK's Hyperliquid implementation.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```tsx
|
|
24
|
+
* const { initiateTransfer } = useHyperliquidTransfer();
|
|
25
|
+
*
|
|
26
|
+
* await initiateTransfer({
|
|
27
|
+
* amount: "1000000", // 1 USDC
|
|
28
|
+
* destination: "0x..."
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function useHyperliquidTransfer(): {
|
|
33
|
+
initiateTransfer: ({ amount, destination }: HyperliquidTransferParams) => Promise<void>;
|
|
34
|
+
getConnectedAddress: () => `0x${string}` | null;
|
|
35
|
+
isWalletConnected: boolean;
|
|
36
|
+
};
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { HYPERLIQUID_CHAIN_ID, HYPERLIQUID_MAINNET } from "../../../anyspend/index.js";
|
|
2
|
+
import { toast } from "../../../global-account/react/index.js";
|
|
3
|
+
import { formatUnits } from "../../../shared/utils/number.js";
|
|
4
|
+
import axios from "axios";
|
|
5
|
+
import { useCallback } from "react";
|
|
6
|
+
import { parseSignature } from "viem";
|
|
7
|
+
import { useWalletClient } from "wagmi";
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated This hook is NOT USED in production.
|
|
10
|
+
*
|
|
11
|
+
* Hyperliquid is only supported as DESTINATION CHAIN (not source chain).
|
|
12
|
+
* Users cannot send FROM Hyperliquid in our flow, so EIP-712 signing is not needed.
|
|
13
|
+
*
|
|
14
|
+
* This hook was created during initial planning but is kept for:
|
|
15
|
+
* - Reference if we need to support source chain in the future
|
|
16
|
+
* - Understanding how Hyperliquid EIP-712 transfers work
|
|
17
|
+
*
|
|
18
|
+
* DO NOT USE THIS HOOK IN PRODUCTION CODE.
|
|
19
|
+
*
|
|
20
|
+
* Custom hook for handling Hyperliquid transfers via EIP-712 signature.
|
|
21
|
+
* Based on Relay SDK's Hyperliquid implementation.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* const { initiateTransfer } = useHyperliquidTransfer();
|
|
26
|
+
*
|
|
27
|
+
* await initiateTransfer({
|
|
28
|
+
* amount: "1000000", // 1 USDC
|
|
29
|
+
* destination: "0x..."
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function useHyperliquidTransfer() {
|
|
34
|
+
const { data: walletClient } = useWalletClient();
|
|
35
|
+
/**
|
|
36
|
+
* Get the connected wallet address if available.
|
|
37
|
+
*/
|
|
38
|
+
const getConnectedAddress = useCallback(() => {
|
|
39
|
+
return walletClient?.account?.address || null;
|
|
40
|
+
}, [walletClient]);
|
|
41
|
+
/**
|
|
42
|
+
* Initiate Hyperliquid transfer by signing EIP-712 message and sending to Hyperliquid API.
|
|
43
|
+
*/
|
|
44
|
+
const initiateTransfer = useCallback(async ({ amount, destination }) => {
|
|
45
|
+
if (!walletClient?.account) {
|
|
46
|
+
toast.error("Please connect your wallet");
|
|
47
|
+
throw new Error("Wallet not connected");
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const currentTime = new Date().getTime();
|
|
51
|
+
// Convert amount from smallest unit (6 decimals) to display format.
|
|
52
|
+
// e.g., "11151533" -> "11.151533"
|
|
53
|
+
const displayAmount = formatUnits(amount, 6);
|
|
54
|
+
// Prepare EIP-712 typed data for Hyperliquid USD send.
|
|
55
|
+
const typedData = {
|
|
56
|
+
domain: {
|
|
57
|
+
name: "HyperliquidSignTransaction",
|
|
58
|
+
version: "1",
|
|
59
|
+
chainId: HYPERLIQUID_CHAIN_ID,
|
|
60
|
+
verifyingContract: "0x0000000000000000000000000000000000000000",
|
|
61
|
+
},
|
|
62
|
+
types: {
|
|
63
|
+
"HyperliquidTransaction:UsdSend": [
|
|
64
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
65
|
+
{ name: "destination", type: "string" },
|
|
66
|
+
{ name: "amount", type: "string" },
|
|
67
|
+
{ name: "time", type: "uint64" },
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
primaryType: "HyperliquidTransaction:UsdSend",
|
|
71
|
+
message: {
|
|
72
|
+
hyperliquidChain: "Mainnet",
|
|
73
|
+
destination: destination.toLowerCase(),
|
|
74
|
+
amount: displayAmount,
|
|
75
|
+
time: BigInt(currentTime),
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
toast.info("Please sign the message in your wallet");
|
|
79
|
+
// Sign EIP-712 message.
|
|
80
|
+
const signature = await walletClient.signTypedData(typedData);
|
|
81
|
+
// Parse signature to get r, s, v components.
|
|
82
|
+
const { r, s, v } = parseSignature(signature);
|
|
83
|
+
toast.info("Sending transaction to Hyperliquid...");
|
|
84
|
+
// Send signature to Hyperliquid API.
|
|
85
|
+
const response = await axios.post(HYPERLIQUID_MAINNET.apiUrl + "/exchange", {
|
|
86
|
+
signature: {
|
|
87
|
+
r,
|
|
88
|
+
s,
|
|
89
|
+
v: Number(v ?? BigInt(0)),
|
|
90
|
+
},
|
|
91
|
+
nonce: currentTime,
|
|
92
|
+
action: {
|
|
93
|
+
type: "usdSend",
|
|
94
|
+
signatureChainId: `0x${HYPERLIQUID_CHAIN_ID.toString(16)}`,
|
|
95
|
+
hyperliquidChain: "Mainnet",
|
|
96
|
+
destination: destination.toLowerCase(),
|
|
97
|
+
amount: displayAmount,
|
|
98
|
+
time: currentTime,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
// Check response status.
|
|
102
|
+
if (!response || response.status !== 200 || response.data?.status !== "ok") {
|
|
103
|
+
const errorMsg = response?.data?.error || "Failed to send transaction to Hyperliquid";
|
|
104
|
+
toast.error(errorMsg);
|
|
105
|
+
throw new Error(errorMsg);
|
|
106
|
+
}
|
|
107
|
+
toast.success("Transaction sent to Hyperliquid successfully!");
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
console.error("Hyperliquid transfer error:", error);
|
|
111
|
+
// Handle user rejection.
|
|
112
|
+
if (error?.message?.includes("User rejected") || error?.code === 4001) {
|
|
113
|
+
toast.error("Transaction signature rejected");
|
|
114
|
+
throw new Error("User rejected signature");
|
|
115
|
+
}
|
|
116
|
+
// Handle other errors.
|
|
117
|
+
const errorMsg = error?.message || "Failed to complete Hyperliquid transfer";
|
|
118
|
+
toast.error(errorMsg);
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}, [walletClient]);
|
|
122
|
+
return {
|
|
123
|
+
initiateTransfer,
|
|
124
|
+
getConnectedAddress,
|
|
125
|
+
isWalletConnected: !!walletClient?.account,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { TooltipProvider } from "../../../global-account/react/index.js";
|
|
4
|
-
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
5
|
-
import { useState } from "react";
|
|
6
4
|
import { FeatureFlagsProvider } from "../contexts/FeatureFlagsContext.js";
|
|
7
5
|
import { StripeRedirectHandler } from "./StripeRedirectHandler.js";
|
|
8
|
-
const defaultQueryClientConfig = {
|
|
9
|
-
defaultOptions: {
|
|
10
|
-
queries: {
|
|
11
|
-
refetchOnWindowFocus: false,
|
|
12
|
-
retry: false,
|
|
13
|
-
staleTime: 30000,
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
6
|
/**
|
|
18
7
|
* AnyspendProvider is a top-level provider that wraps your application to provide
|
|
19
8
|
* query caching and state management for all Anyspend hooks.
|
|
@@ -38,6 +27,5 @@ const defaultQueryClientConfig = {
|
|
|
38
27
|
* ```
|
|
39
28
|
*/
|
|
40
29
|
export const AnyspendProvider = function AnyspendProvider({ children, featureFlags }) {
|
|
41
|
-
|
|
42
|
-
return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(FeatureFlagsProvider, { featureFlags: featureFlags, children: _jsxs(TooltipProvider, { children: [_jsx(StripeRedirectHandler, {}), children] }) }) }));
|
|
30
|
+
return (_jsx(FeatureFlagsProvider, { featureFlags: featureFlags, children: _jsxs(TooltipProvider, { children: [_jsx(StripeRedirectHandler, {}), children] }) }));
|
|
43
31
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Chain } from "viem";
|
|
2
1
|
import { components } from "../../anyspend/types/api";
|
|
2
|
+
import { Chain } from "viem";
|
|
3
3
|
export declare enum ChainType {
|
|
4
4
|
EVM = "evm",
|
|
5
|
-
SOLANA = "solana"
|
|
5
|
+
SOLANA = "solana",
|
|
6
|
+
HYPERLIQUID = "hyperliquid"
|
|
6
7
|
}
|
|
7
8
|
export interface IBaseChain {
|
|
8
9
|
id: number;
|
|
@@ -25,3 +26,10 @@ export interface IEVMChain extends IBaseChain {
|
|
|
25
26
|
export interface ISolanaChain extends IBaseChain {
|
|
26
27
|
type: ChainType.SOLANA;
|
|
27
28
|
}
|
|
29
|
+
export interface IHyperliquidChain extends IBaseChain {
|
|
30
|
+
type: ChainType.HYPERLIQUID;
|
|
31
|
+
apiUrl: string;
|
|
32
|
+
blockExplorer: {
|
|
33
|
+
url: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
export declare function isSolanaAddress(address: string): boolean;
|
|
2
2
|
export declare function isEvmOrSolanaAddress(address: string): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Check if an address is Hyperliquid's special USDC address.
|
|
5
|
+
* Hyperliquid USDC uses a special 34-character format (0x + 32 hex digits)
|
|
6
|
+
* instead of the standard 42-character Ethereum address format.
|
|
7
|
+
* This is required by Relay SDK for Hyperliquid integration.
|
|
8
|
+
*
|
|
9
|
+
* @param chainId - The chain ID to check
|
|
10
|
+
* @param address - The token address to validate
|
|
11
|
+
* @returns true if the address is Hyperliquid USDC's special format
|
|
12
|
+
*/
|
|
13
|
+
export declare function isHyperliquidUSDC(chainId: number, address: string): boolean;
|
|
3
14
|
export declare function normalizeAddress(address: string): string;
|
|
4
15
|
export declare function eqci(a: string | null | undefined, b: string | null | undefined): boolean;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isAddress } from "viem";
|
|
2
|
+
import { HYPERLIQUID_CHAIN_ID } from "./token.js";
|
|
2
3
|
export function isSolanaAddress(address) {
|
|
3
4
|
// Solana addresses are 32-byte base58 strings (usually 32-44 characters)
|
|
4
5
|
const solanaAddressRegex = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
@@ -7,6 +8,19 @@ export function isSolanaAddress(address) {
|
|
|
7
8
|
export function isEvmOrSolanaAddress(address) {
|
|
8
9
|
return isAddress(address) || isSolanaAddress(address);
|
|
9
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Check if an address is Hyperliquid's special USDC address.
|
|
13
|
+
* Hyperliquid USDC uses a special 34-character format (0x + 32 hex digits)
|
|
14
|
+
* instead of the standard 42-character Ethereum address format.
|
|
15
|
+
* This is required by Relay SDK for Hyperliquid integration.
|
|
16
|
+
*
|
|
17
|
+
* @param chainId - The chain ID to check
|
|
18
|
+
* @param address - The token address to validate
|
|
19
|
+
* @returns true if the address is Hyperliquid USDC's special format
|
|
20
|
+
*/
|
|
21
|
+
export function isHyperliquidUSDC(chainId, address) {
|
|
22
|
+
return chainId === HYPERLIQUID_CHAIN_ID && address.toLowerCase() === "0x00000000000000000000000000000000";
|
|
23
|
+
}
|
|
10
24
|
export function normalizeAddress(address) {
|
|
11
25
|
if (isSolanaAddress(address)) {
|
|
12
26
|
return address;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { components } from "../../anyspend/types/api";
|
|
2
2
|
import { Account, Chain, PublicClient, Transport, WalletClient } from "viem";
|
|
3
|
-
import { ChainType, IBaseChain, IEVMChain, ISolanaChain } from "../types/chain";
|
|
3
|
+
import { ChainType, IBaseChain, IEVMChain, IHyperliquidChain, ISolanaChain } from "../types/chain";
|
|
4
4
|
export declare const hyperEVM: {
|
|
5
5
|
blockExplorers: {
|
|
6
6
|
readonly default: {
|
|
@@ -42,8 +42,10 @@ export declare const hyperEVM: {
|
|
|
42
42
|
export declare const EVM_MAINNET: Record<number, IEVMChain>;
|
|
43
43
|
export declare const EVM_TESTNET: Record<number, IEVMChain>;
|
|
44
44
|
export declare const SOLANA_MAINNET: ISolanaChain;
|
|
45
|
+
export declare const HYPERLIQUID_MAINNET: IHyperliquidChain;
|
|
45
46
|
export declare const EVM_CHAINS: Record<number, IEVMChain>;
|
|
46
47
|
export declare const SOLANA_CHAINS: Record<number, ISolanaChain>;
|
|
48
|
+
export declare const HYPERLIQUID_CHAINS: Record<number, IHyperliquidChain>;
|
|
47
49
|
export declare const ALL_CHAINS: Record<number, IBaseChain>;
|
|
48
50
|
export declare function getSolanaChains(network: "mainnet" | "testnet"): ISolanaChain;
|
|
49
51
|
export declare function getAllEvmChains(network: "mainnet" | "testnet"): Record<number, IEVMChain>;
|
|
@@ -63,3 +65,20 @@ export declare function getExplorerAddressUrl(chainId: number, address: string):
|
|
|
63
65
|
export declare function getMulticall3Address(chainId: number): string;
|
|
64
66
|
export declare function getNativeToken(chainId: number): components["schemas"]["Token"];
|
|
65
67
|
export declare function isEvmChain(chainId: number): boolean;
|
|
68
|
+
export declare function isHyperliquidChain(chainId: number): boolean;
|
|
69
|
+
export declare function getHyperliquidChain(chainId: number): IHyperliquidChain;
|
|
70
|
+
/**
|
|
71
|
+
* Get available chain IDs for AnySpend based on context (source or destination).
|
|
72
|
+
* Filters out chains that shouldn't be available for the given context.
|
|
73
|
+
*
|
|
74
|
+
* @param context - "from" for source chains, "to" for destination chains
|
|
75
|
+
* @returns Array of available chain IDs
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* // Get source chains (excludes Hyperliquid)
|
|
79
|
+
* const sourceChains = getAvailableChainIds("from") // [1, 8453, 137, ...]
|
|
80
|
+
*
|
|
81
|
+
* // Get destination chains (includes Hyperliquid)
|
|
82
|
+
* const destChains = getAvailableChainIds("to") // [1, 8453, 137, ..., 1337]
|
|
83
|
+
*/
|
|
84
|
+
export declare function getAvailableChainIds(context: "from" | "to"): number[];
|