@b3dotfun/sdk 0.0.83-test.0 → 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 -12
- package/dist/cjs/anyspend/react/components/AnySpendCollectorClubPurchase.js +1 -1
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +4 -6
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +2 -4
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +47 -177
- 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/useAnyspendFlow.js +0 -3
- 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 +58 -1
- package/dist/cjs/anyspend/utils/chain.js +94 -4
- package/dist/cjs/anyspend/utils/token.d.ts +4 -0
- package/dist/cjs/anyspend/utils/token.js +35 -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/SignInWithB3Flow.js +12 -57
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +1 -1
- package/dist/cjs/global-account/react/hooks/index.d.ts +0 -2
- package/dist/cjs/global-account/react/hooks/index.js +1 -5
- package/dist/cjs/global-account/react/hooks/useAccountWallet.js +11 -10
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +63 -72
- package/dist/cjs/global-account/react/hooks/useTWAuth.d.ts +0 -3
- package/dist/cjs/global-account/react/hooks/useTWAuth.js +0 -8
- package/dist/cjs/global-account/react/hooks/useTurnkeyAuth.js +24 -54
- package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +1 -1
- 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 -13
- package/dist/esm/anyspend/react/components/AnySpendCollectorClubPurchase.js +1 -1
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +5 -7
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +4 -6
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +45 -175
- 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/useAnyspendFlow.js +0 -3
- 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 +58 -1
- package/dist/esm/anyspend/utils/chain.js +91 -4
- package/dist/esm/anyspend/utils/token.d.ts +4 -0
- package/dist/esm/anyspend/utils/token.js +32 -6
- 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/SignInWithB3Flow.js +12 -57
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +1 -1
- package/dist/esm/global-account/react/hooks/index.d.ts +0 -2
- package/dist/esm/global-account/react/hooks/index.js +0 -2
- package/dist/esm/global-account/react/hooks/useAccountWallet.js +11 -10
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.js +63 -72
- package/dist/esm/global-account/react/hooks/useTWAuth.d.ts +0 -3
- package/dist/esm/global-account/react/hooks/useTWAuth.js +0 -8
- package/dist/esm/global-account/react/hooks/useTurnkeyAuth.js +24 -54
- package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/esm/shared/utils/payment.utils.d.ts +1 -0
- package/dist/esm/shared/utils/payment.utils.js +9 -1
- package/dist/styles/index.css +1 -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 +58 -1
- package/dist/types/anyspend/utils/token.d.ts +4 -0
- package/dist/types/global-account/react/hooks/index.d.ts +0 -2
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/types/global-account/react/hooks/useTWAuth.d.ts +0 -3
- package/dist/types/global-account/react/hooks/useUserQuery.d.ts +1 -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 -13
- package/src/anyspend/react/components/AnySpendCollectorClubPurchase.tsx +1 -1
- package/src/anyspend/react/components/AnySpendCustom.tsx +9 -29
- package/src/anyspend/react/components/common/CryptoPaySection.tsx +7 -30
- package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +22 -253
- 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/useAnyspendFlow.ts +0 -4
- 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 +115 -5
- package/src/anyspend/utils/token.ts +36 -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/SignInWithB3Flow.tsx +22 -77
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +1 -1
- package/src/global-account/react/hooks/index.ts +0 -2
- package/src/global-account/react/hooks/useAccountWallet.tsx +12 -11
- package/src/global-account/react/hooks/useAuthentication.ts +85 -88
- package/src/global-account/react/hooks/useTWAuth.tsx +0 -10
- package/src/global-account/react/hooks/useTurnkeyAuth.ts +26 -59
- package/src/shared/utils/payment.utils.ts +10 -1
- package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +0 -10
- package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +0 -73
- package/dist/cjs/global-account/react/hooks/useAuth.d.ts +0 -76
- package/dist/cjs/global-account/react/hooks/useAuth.js +0 -338
- 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/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +0 -10
- package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +0 -70
- package/dist/esm/global-account/react/hooks/useAuth.d.ts +0 -76
- package/dist/esm/global-account/react/hooks/useAuth.js +0 -332
- 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/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +0 -10
- package/dist/types/global-account/react/hooks/useAuth.d.ts +0 -76
- package/dist/types/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
- package/src/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.ts +0 -80
- package/src/global-account/react/hooks/useAuth.ts +0 -380
- package/src/global-account/react/hooks/useBestTransactionPath.tsx +0 -201
|
@@ -1,12 +1,32 @@
|
|
|
1
|
+
import { lazy, Suspense } from "react";
|
|
1
2
|
import { components } from "@b3dotfun/sdk/anyspend/types/api";
|
|
2
3
|
import PaymentOneClick from "./PaymentOneClick";
|
|
3
|
-
|
|
4
|
+
|
|
5
|
+
// Lazy load Stripe component to prevent loadStripe() from running at module level
|
|
6
|
+
// This prevents EIP-6963 wallet detection events when Stripe is not used
|
|
7
|
+
const PaymentStripeWeb2 = lazy(() => import("./PaymentStripeWeb2"));
|
|
4
8
|
|
|
5
9
|
interface PaymentVendorUIProps {
|
|
6
10
|
order: components["schemas"]["Order"];
|
|
7
11
|
dstTokenSymbol: string;
|
|
8
12
|
}
|
|
9
13
|
|
|
14
|
+
function StripeLoadingFallback() {
|
|
15
|
+
return (
|
|
16
|
+
<div className="relative my-8 flex w-full flex-1 flex-col items-center justify-center">
|
|
17
|
+
<div className="bg-as-on-surface-1 flex w-full flex-col items-center justify-center gap-4 rounded-2xl p-8">
|
|
18
|
+
<div className="bg-as-brand/20 flex h-16 w-16 items-center justify-center rounded-full">
|
|
19
|
+
<div className="text-as-brand h-8 w-8 animate-spin rounded-full border-2 border-current border-t-transparent" />
|
|
20
|
+
</div>
|
|
21
|
+
<div className="text-as-primary/70 text-center">
|
|
22
|
+
<div className="text-lg font-medium">Loading payment</div>
|
|
23
|
+
<div className="text-as-primary/50 mt-2 text-sm">Initializing secure payment form...</div>
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
10
30
|
export default function PaymentVendorUI({ order, dstTokenSymbol }: PaymentVendorUIProps) {
|
|
11
31
|
const vendor = order.onrampMetadata?.vendor;
|
|
12
32
|
|
|
@@ -17,7 +37,11 @@ export default function PaymentVendorUI({ order, dstTokenSymbol }: PaymentVendor
|
|
|
17
37
|
|
|
18
38
|
// Handle Stripe Web2 payment flow
|
|
19
39
|
if (vendor === "stripe-web2" && order.stripePaymentIntentId) {
|
|
20
|
-
return
|
|
40
|
+
return (
|
|
41
|
+
<Suspense fallback={<StripeLoadingFallback />}>
|
|
42
|
+
<PaymentStripeWeb2 order={order} stripePaymentIntentId={order.stripePaymentIntentId} />
|
|
43
|
+
</Suspense>
|
|
44
|
+
);
|
|
21
45
|
}
|
|
22
46
|
|
|
23
47
|
// Return null for unsupported vendors
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { ALL_CHAINS, getChainName, getPaymentUrl,
|
|
3
|
+
import { ALL_CHAINS, getChainName, getPaymentUrl, ZERO_ADDRESS } from "@b3dotfun/sdk/anyspend";
|
|
4
4
|
import { components } from "@b3dotfun/sdk/anyspend/types/api";
|
|
5
5
|
import { CopyToClipboard, ShinyButton, TextLoop, toast } from "@b3dotfun/sdk/global-account/react";
|
|
6
6
|
import { cn } from "@b3dotfun/sdk/shared/utils";
|
|
@@ -206,7 +206,7 @@ export const TransferCryptoDetails = memo(function TransferCryptoDetails({
|
|
|
206
206
|
value={getPaymentUrl(
|
|
207
207
|
order.globalAddress,
|
|
208
208
|
BigInt(order.srcAmount),
|
|
209
|
-
order.srcTokenAddress ===
|
|
209
|
+
order.srcTokenAddress === ZERO_ADDRESS ? "ETH" : order.srcTokenAddress,
|
|
210
210
|
order.srcChain,
|
|
211
211
|
srcToken?.decimals,
|
|
212
212
|
)}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { getChainName
|
|
1
|
+
import { getChainName } from "@b3dotfun/sdk/anyspend";
|
|
2
|
+
import { getStripePromise } from "@b3dotfun/sdk/shared/utils/payment.utils";
|
|
2
3
|
import { useAnyspendCreateOnrampOrder, useGeoOnrampOptions, useStripeClientSecret } from "@b3dotfun/sdk/anyspend/react";
|
|
3
4
|
import { components } from "@b3dotfun/sdk/anyspend/types/api";
|
|
4
5
|
import { GetQuoteResponse } from "@b3dotfun/sdk/anyspend/types/api_req_res";
|
|
5
6
|
import { toast } from "@b3dotfun/sdk/global-account/react";
|
|
6
7
|
import centerTruncate from "@b3dotfun/sdk/shared/utils/centerTruncate";
|
|
7
8
|
import { AddressElement, Elements, PaymentElement, useElements, useStripe } from "@stripe/react-stripe-js";
|
|
8
|
-
import { loadStripe } from "@stripe/stripe-js";
|
|
9
9
|
import { Loader2 } from "lucide-react";
|
|
10
10
|
import { motion } from "motion/react";
|
|
11
11
|
import { useEffect, useRef, useState } from "react";
|
|
@@ -13,8 +13,6 @@ import { useEffect, useRef, useState } from "react";
|
|
|
13
13
|
import { formatUnits } from "viem";
|
|
14
14
|
import { AnySpendFingerprintWrapper, getFingerprintConfig } from "../AnySpendFingerprintWrapper";
|
|
15
15
|
|
|
16
|
-
const stripePromise = loadStripe(STRIPE_CONFIG.publishableKey);
|
|
17
|
-
|
|
18
16
|
interface WebviewOnrampPaymentProps {
|
|
19
17
|
srcAmountOnRamp: string;
|
|
20
18
|
recipientAddress?: string;
|
|
@@ -309,7 +307,7 @@ function WebviewOnrampPaymentInner({
|
|
|
309
307
|
|
|
310
308
|
{/* Stripe Elements */}
|
|
311
309
|
<Elements
|
|
312
|
-
stripe={
|
|
310
|
+
stripe={getStripePromise()}
|
|
313
311
|
options={{
|
|
314
312
|
clientSecret,
|
|
315
313
|
appearance: {
|
|
@@ -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";
|
|
@@ -24,7 +24,6 @@ import { components } from "../../types/api";
|
|
|
24
24
|
import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod";
|
|
25
25
|
import { FiatPaymentMethod } from "../components/common/FiatPaymentMethod";
|
|
26
26
|
import { useAutoSelectCryptoPaymentMethod } from "./useAutoSelectCryptoPaymentMethod";
|
|
27
|
-
import { useAutoSetActiveWalletFromWagmi } from "./useAutoSetActiveWalletFromWagmi";
|
|
28
27
|
import { useConnectedWalletDisplay } from "./useConnectedWalletDisplay";
|
|
29
28
|
import { useCryptoPaymentMethodState } from "./useCryptoPaymentMethodState";
|
|
30
29
|
import { useRecipientAddressState } from "./useRecipientAddressState";
|
|
@@ -111,9 +110,6 @@ export function useAnyspendFlow({
|
|
|
111
110
|
const { address: globalAddress } = useAccountWallet();
|
|
112
111
|
const { walletAddress } = useConnectedWalletDisplay(effectiveCryptoPaymentMethod);
|
|
113
112
|
|
|
114
|
-
// Auto-set active wallet from wagmi
|
|
115
|
-
useAutoSetActiveWalletFromWagmi();
|
|
116
|
-
|
|
117
113
|
// Recipient address state - hook automatically manages priority: props > user selection > wallet/global
|
|
118
114
|
const { setSelectedRecipientAddress, effectiveRecipientAddress } = useRecipientAddressState({
|
|
119
115
|
recipientAddressFromProps: recipientAddress,
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useProfile } from "@b3dotfun/sdk/global-account/react";
|
|
2
|
+
import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod";
|
|
3
|
+
import { useConnectedWalletDisplay } from "./useConnectedWalletDisplay";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Hook that provides connected user's address, profile, and cleaned display name
|
|
6
7
|
* Combines logic for getting connected address from either global account or thirdweb wallets
|
|
7
8
|
*/
|
|
8
|
-
export function useConnectedUserProfile() {
|
|
9
|
-
const {
|
|
10
|
-
const connectedWallets = useConnectedWallets();
|
|
11
|
-
|
|
12
|
-
// Get connected address from global account or first connected wallet
|
|
13
|
-
const connectedAddress = globalAddress || connectedWallets?.[0]?.getAccount()?.address;
|
|
9
|
+
export function useConnectedUserProfile(selectedCryptoPaymentMethod?: CryptoPaymentMethodType) {
|
|
10
|
+
const { walletAddress } = useConnectedWalletDisplay(selectedCryptoPaymentMethod);
|
|
14
11
|
|
|
15
12
|
// Fetch profile data for the connected address with cleaned name
|
|
16
|
-
const connectedProfile = useProfile({ address:
|
|
13
|
+
const connectedProfile = useProfile({ address: walletAddress });
|
|
17
14
|
|
|
18
15
|
return {
|
|
19
|
-
address:
|
|
16
|
+
address: walletAddress,
|
|
20
17
|
profile: connectedProfile,
|
|
21
18
|
name: connectedProfile.data?.name,
|
|
22
19
|
isLoading: connectedProfile.isLoading,
|
|
@@ -5,8 +5,6 @@ import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMetho
|
|
|
5
5
|
interface UseConnectedWalletDisplayResult {
|
|
6
6
|
walletAddress: string | undefined;
|
|
7
7
|
shouldShowConnectedEOA: boolean;
|
|
8
|
-
shouldShowWagmiWallet: boolean;
|
|
9
|
-
isWalletDuplicated: boolean;
|
|
10
8
|
suggestedPaymentMethod: CryptoPaymentMethodType;
|
|
11
9
|
}
|
|
12
10
|
|
|
@@ -22,27 +20,18 @@ export function useConnectedWalletDisplay(
|
|
|
22
20
|
|
|
23
21
|
const globalWalletAddress = connectedSmartWallet?.getAccount()?.address;
|
|
24
22
|
|
|
25
|
-
// Helper function to check if two addresses are the same
|
|
26
|
-
const isSameAddress = (addr1?: string, addr2?: string): boolean => {
|
|
27
|
-
if (!addr1 || !addr2) return false;
|
|
28
|
-
return addr1.toLowerCase() === addr2.toLowerCase();
|
|
29
|
-
};
|
|
30
|
-
|
|
31
23
|
// Check if connectedEOAWallet and wagmi wallet represent the same wallet
|
|
32
24
|
const connectedEOAAddress = connectedEOAWallet?.getAccount()?.address;
|
|
33
|
-
const isWalletDuplicated =
|
|
34
|
-
isSameAddress(connectedEOAAddress, wagmiAddress) || isSameAddress(globalWalletAddress, wagmiAddress);
|
|
35
25
|
|
|
36
26
|
// Determine which wallet to show (prefer connectedEOAWallet if both exist and are the same)
|
|
37
27
|
const shouldShowConnectedEOA = !!connectedEOAWallet;
|
|
38
28
|
// this is disabled because we don't want to display In-App Wallet as a payment method
|
|
39
|
-
const shouldShowWagmiWallet = false; // wagmiWalletIsConnected && (!isWalletDuplicated || !connectedEOAWallet);
|
|
40
29
|
|
|
41
30
|
// Determine which address to use based on payment method
|
|
42
31
|
let walletAddress: string | undefined;
|
|
43
32
|
|
|
44
33
|
if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET) {
|
|
45
|
-
walletAddress =
|
|
34
|
+
walletAddress = globalWalletAddress;
|
|
46
35
|
} else if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
47
36
|
// Prefer connectedEOAWallet, fallback to wagmi wallet
|
|
48
37
|
walletAddress = connectedEOAAddress || wagmiAddress;
|
|
@@ -58,7 +47,7 @@ export function useConnectedWalletDisplay(
|
|
|
58
47
|
if (connectedEOAAddress || wagmiAddress) {
|
|
59
48
|
// If there's a connected EOA or wagmi wallet, suggest CONNECT_WALLET
|
|
60
49
|
suggestedPaymentMethod = CryptoPaymentMethodType.CONNECT_WALLET;
|
|
61
|
-
} else if (
|
|
50
|
+
} else if (globalWalletAddress) {
|
|
62
51
|
// If only global wallet is available, suggest that
|
|
63
52
|
suggestedPaymentMethod = CryptoPaymentMethodType.GLOBAL_WALLET;
|
|
64
53
|
}
|
|
@@ -66,8 +55,6 @@ export function useConnectedWalletDisplay(
|
|
|
66
55
|
return {
|
|
67
56
|
walletAddress,
|
|
68
57
|
shouldShowConnectedEOA,
|
|
69
|
-
shouldShowWagmiWallet,
|
|
70
|
-
isWalletDuplicated,
|
|
71
58
|
suggestedPaymentMethod,
|
|
72
59
|
};
|
|
73
60
|
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { HYPERLIQUID_CHAIN_ID, HYPERLIQUID_MAINNET } from "@b3dotfun/sdk/anyspend";
|
|
2
|
+
import { toast } from "@b3dotfun/sdk/global-account/react";
|
|
3
|
+
import { formatUnits } from "@b3dotfun/sdk/shared/utils/number";
|
|
4
|
+
import axios from "axios";
|
|
5
|
+
import { useCallback } from "react";
|
|
6
|
+
import { parseSignature } from "viem";
|
|
7
|
+
import { useWalletClient } from "wagmi";
|
|
8
|
+
|
|
9
|
+
interface HyperliquidTransferParams {
|
|
10
|
+
/** Amount in smallest unit (USDC has 6 decimals) */
|
|
11
|
+
amount: string;
|
|
12
|
+
/** Recipient address */
|
|
13
|
+
destination: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated This hook is NOT USED in production.
|
|
18
|
+
*
|
|
19
|
+
* Hyperliquid is only supported as DESTINATION CHAIN (not source chain).
|
|
20
|
+
* Users cannot send FROM Hyperliquid in our flow, so EIP-712 signing is not needed.
|
|
21
|
+
*
|
|
22
|
+
* This hook was created during initial planning but is kept for:
|
|
23
|
+
* - Reference if we need to support source chain in the future
|
|
24
|
+
* - Understanding how Hyperliquid EIP-712 transfers work
|
|
25
|
+
*
|
|
26
|
+
* DO NOT USE THIS HOOK IN PRODUCTION CODE.
|
|
27
|
+
*
|
|
28
|
+
* Custom hook for handling Hyperliquid transfers via EIP-712 signature.
|
|
29
|
+
* Based on Relay SDK's Hyperliquid implementation.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* const { initiateTransfer } = useHyperliquidTransfer();
|
|
34
|
+
*
|
|
35
|
+
* await initiateTransfer({
|
|
36
|
+
* amount: "1000000", // 1 USDC
|
|
37
|
+
* destination: "0x..."
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function useHyperliquidTransfer() {
|
|
42
|
+
const { data: walletClient } = useWalletClient();
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get the connected wallet address if available.
|
|
46
|
+
*/
|
|
47
|
+
const getConnectedAddress = useCallback(() => {
|
|
48
|
+
return walletClient?.account?.address || null;
|
|
49
|
+
}, [walletClient]);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Initiate Hyperliquid transfer by signing EIP-712 message and sending to Hyperliquid API.
|
|
53
|
+
*/
|
|
54
|
+
const initiateTransfer = useCallback(
|
|
55
|
+
async ({ amount, destination }: HyperliquidTransferParams): Promise<void> => {
|
|
56
|
+
if (!walletClient?.account) {
|
|
57
|
+
toast.error("Please connect your wallet");
|
|
58
|
+
throw new Error("Wallet not connected");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
const currentTime = new Date().getTime();
|
|
63
|
+
|
|
64
|
+
// Convert amount from smallest unit (6 decimals) to display format.
|
|
65
|
+
// e.g., "11151533" -> "11.151533"
|
|
66
|
+
const displayAmount = formatUnits(amount, 6);
|
|
67
|
+
|
|
68
|
+
// Prepare EIP-712 typed data for Hyperliquid USD send.
|
|
69
|
+
const typedData = {
|
|
70
|
+
domain: {
|
|
71
|
+
name: "HyperliquidSignTransaction",
|
|
72
|
+
version: "1",
|
|
73
|
+
chainId: HYPERLIQUID_CHAIN_ID,
|
|
74
|
+
verifyingContract: "0x0000000000000000000000000000000000000000" as `0x${string}`,
|
|
75
|
+
},
|
|
76
|
+
types: {
|
|
77
|
+
"HyperliquidTransaction:UsdSend": [
|
|
78
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
79
|
+
{ name: "destination", type: "string" },
|
|
80
|
+
{ name: "amount", type: "string" },
|
|
81
|
+
{ name: "time", type: "uint64" },
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
primaryType: "HyperliquidTransaction:UsdSend" as const,
|
|
85
|
+
message: {
|
|
86
|
+
hyperliquidChain: "Mainnet",
|
|
87
|
+
destination: destination.toLowerCase(),
|
|
88
|
+
amount: displayAmount,
|
|
89
|
+
time: BigInt(currentTime),
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
toast.info("Please sign the message in your wallet");
|
|
94
|
+
|
|
95
|
+
// Sign EIP-712 message.
|
|
96
|
+
const signature = await walletClient.signTypedData(typedData);
|
|
97
|
+
|
|
98
|
+
// Parse signature to get r, s, v components.
|
|
99
|
+
const { r, s, v } = parseSignature(signature);
|
|
100
|
+
|
|
101
|
+
toast.info("Sending transaction to Hyperliquid...");
|
|
102
|
+
|
|
103
|
+
// Send signature to Hyperliquid API.
|
|
104
|
+
const response = await axios.post(HYPERLIQUID_MAINNET.apiUrl + "/exchange", {
|
|
105
|
+
signature: {
|
|
106
|
+
r,
|
|
107
|
+
s,
|
|
108
|
+
v: Number(v ?? BigInt(0)),
|
|
109
|
+
},
|
|
110
|
+
nonce: currentTime,
|
|
111
|
+
action: {
|
|
112
|
+
type: "usdSend",
|
|
113
|
+
signatureChainId: `0x${HYPERLIQUID_CHAIN_ID.toString(16)}`,
|
|
114
|
+
hyperliquidChain: "Mainnet",
|
|
115
|
+
destination: destination.toLowerCase(),
|
|
116
|
+
amount: displayAmount,
|
|
117
|
+
time: currentTime,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Check response status.
|
|
122
|
+
if (!response || response.status !== 200 || response.data?.status !== "ok") {
|
|
123
|
+
const errorMsg = response?.data?.error || "Failed to send transaction to Hyperliquid";
|
|
124
|
+
toast.error(errorMsg);
|
|
125
|
+
throw new Error(errorMsg);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
toast.success("Transaction sent to Hyperliquid successfully!");
|
|
129
|
+
} catch (error: any) {
|
|
130
|
+
console.error("Hyperliquid transfer error:", error);
|
|
131
|
+
|
|
132
|
+
// Handle user rejection.
|
|
133
|
+
if (error?.message?.includes("User rejected") || error?.code === 4001) {
|
|
134
|
+
toast.error("Transaction signature rejected");
|
|
135
|
+
throw new Error("User rejected signature");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Handle other errors.
|
|
139
|
+
const errorMsg = error?.message || "Failed to complete Hyperliquid transfer";
|
|
140
|
+
toast.error(errorMsg);
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
[walletClient],
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
initiateTransfer,
|
|
149
|
+
getConnectedAddress,
|
|
150
|
+
isWalletConnected: !!walletClient?.account,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { TooltipProvider } from "@b3dotfun/sdk/global-account/react";
|
|
4
|
-
import {
|
|
5
|
-
import { ReactNode, useState } from "react";
|
|
4
|
+
import { ReactNode } from "react";
|
|
6
5
|
import { FeatureFlags, FeatureFlagsProvider } from "../contexts/FeatureFlagsContext";
|
|
7
6
|
import { StripeRedirectHandler } from "./StripeRedirectHandler";
|
|
8
7
|
|
|
@@ -11,16 +10,6 @@ interface AnyspendProviderProps {
|
|
|
11
10
|
featureFlags?: FeatureFlags;
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
const defaultQueryClientConfig = {
|
|
15
|
-
defaultOptions: {
|
|
16
|
-
queries: {
|
|
17
|
-
refetchOnWindowFocus: false,
|
|
18
|
-
retry: false,
|
|
19
|
-
staleTime: 30000,
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
} as const;
|
|
23
|
-
|
|
24
13
|
/**
|
|
25
14
|
* AnyspendProvider is a top-level provider that wraps your application to provide
|
|
26
15
|
* query caching and state management for all Anyspend hooks.
|
|
@@ -45,16 +34,12 @@ const defaultQueryClientConfig = {
|
|
|
45
34
|
* ```
|
|
46
35
|
*/
|
|
47
36
|
export const AnyspendProvider = function AnyspendProvider({ children, featureFlags }: AnyspendProviderProps) {
|
|
48
|
-
const [queryClient] = useState(() => new QueryClient(defaultQueryClientConfig));
|
|
49
|
-
|
|
50
37
|
return (
|
|
51
|
-
<
|
|
52
|
-
<
|
|
53
|
-
<
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
</FeatureFlagsProvider>
|
|
58
|
-
</QueryClientProvider>
|
|
38
|
+
<FeatureFlagsProvider featureFlags={featureFlags}>
|
|
39
|
+
<TooltipProvider>
|
|
40
|
+
<StripeRedirectHandler />
|
|
41
|
+
{children}
|
|
42
|
+
</TooltipProvider>
|
|
43
|
+
</FeatureFlagsProvider>
|
|
59
44
|
);
|
|
60
45
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Chain } from "viem";
|
|
2
1
|
import { components } from "@b3dotfun/sdk/anyspend/types/api";
|
|
2
|
+
import { Chain } from "viem";
|
|
3
3
|
|
|
4
4
|
export enum ChainType {
|
|
5
5
|
EVM = "evm",
|
|
6
6
|
SOLANA = "solana",
|
|
7
|
+
HYPERLIQUID = "hyperliquid",
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export interface IBaseChain {
|
|
@@ -29,3 +30,11 @@ export interface IEVMChain extends IBaseChain {
|
|
|
29
30
|
export interface ISolanaChain extends IBaseChain {
|
|
30
31
|
type: ChainType.SOLANA;
|
|
31
32
|
}
|
|
33
|
+
|
|
34
|
+
export interface IHyperliquidChain extends IBaseChain {
|
|
35
|
+
type: ChainType.HYPERLIQUID;
|
|
36
|
+
apiUrl: string;
|
|
37
|
+
blockExplorer: {
|
|
38
|
+
url: string;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isAddress } from "viem";
|
|
2
|
+
import { HYPERLIQUID_CHAIN_ID } from "./token";
|
|
2
3
|
|
|
3
4
|
export function isSolanaAddress(address: string): boolean {
|
|
4
5
|
// Solana addresses are 32-byte base58 strings (usually 32-44 characters)
|
|
@@ -10,6 +11,20 @@ export function isEvmOrSolanaAddress(address: string): boolean {
|
|
|
10
11
|
return isAddress(address) || isSolanaAddress(address);
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Check if an address is Hyperliquid's special USDC address.
|
|
16
|
+
* Hyperliquid USDC uses a special 34-character format (0x + 32 hex digits)
|
|
17
|
+
* instead of the standard 42-character Ethereum address format.
|
|
18
|
+
* This is required by Relay SDK for Hyperliquid integration.
|
|
19
|
+
*
|
|
20
|
+
* @param chainId - The chain ID to check
|
|
21
|
+
* @param address - The token address to validate
|
|
22
|
+
* @returns true if the address is Hyperliquid USDC's special format
|
|
23
|
+
*/
|
|
24
|
+
export function isHyperliquidUSDC(chainId: number, address: string): boolean {
|
|
25
|
+
return chainId === HYPERLIQUID_CHAIN_ID && address.toLowerCase() === "0x00000000000000000000000000000000";
|
|
26
|
+
}
|
|
27
|
+
|
|
13
28
|
export function normalizeAddress(address: string): string {
|
|
14
29
|
if (isSolanaAddress(address)) {
|
|
15
30
|
return address;
|
|
@@ -14,13 +14,31 @@ import {
|
|
|
14
14
|
WalletClient,
|
|
15
15
|
} from "viem";
|
|
16
16
|
import { abstract, arbitrum, avalanche, b3, base, bsc, mainnet, optimism, polygon } from "viem/chains";
|
|
17
|
-
import { ChainType, IBaseChain, IEVMChain, ISolanaChain } from "../types/chain";
|
|
18
|
-
import {
|
|
17
|
+
import { ChainType, IBaseChain, IEVMChain, IHyperliquidChain, ISolanaChain } from "../types/chain";
|
|
18
|
+
import {
|
|
19
|
+
getAvaxToken,
|
|
20
|
+
getBnbToken,
|
|
21
|
+
getEthToken,
|
|
22
|
+
getHyperEVMNativeToken,
|
|
23
|
+
getHyperliquidUSDCToken,
|
|
24
|
+
getPolToken,
|
|
25
|
+
getSolanaToken,
|
|
26
|
+
HYPEREVM_CHAIN_ID,
|
|
27
|
+
HYPERLIQUID_CHAIN_ID,
|
|
28
|
+
} from "./token";
|
|
19
29
|
|
|
20
30
|
function getCustomEvmChain(chain: Chain, rpcUrl: string): Chain {
|
|
21
31
|
return defineChain({ ...chain, rpcUrls: { default: { http: [rpcUrl] } } });
|
|
22
32
|
}
|
|
23
33
|
|
|
34
|
+
export const hyperEVM = defineChain({
|
|
35
|
+
id: HYPEREVM_CHAIN_ID,
|
|
36
|
+
name: "HyperEVM",
|
|
37
|
+
nativeCurrency: { name: "HyperEVM", symbol: "HYPE", decimals: 18 },
|
|
38
|
+
rpcUrls: { default: { http: ["https://rpc.hyperliquid.xyz/evm"] } },
|
|
39
|
+
blockExplorers: { default: { name: "HyperEVM Explorer", url: "https://hyperevmscan.io/" } },
|
|
40
|
+
});
|
|
41
|
+
|
|
24
42
|
// export const b4testnet = defineChain({
|
|
25
43
|
// id: 19934,
|
|
26
44
|
// name: "B4 Testnet",
|
|
@@ -189,6 +207,20 @@ export const EVM_MAINNET: Record<number, IEVMChain> = {
|
|
|
189
207
|
coingeckoName: "abstract",
|
|
190
208
|
wethAddress: "0x3439153eb7af838ad19d56e1571fbd09333c2809",
|
|
191
209
|
},
|
|
210
|
+
[hyperEVM.id]: {
|
|
211
|
+
id: hyperEVM.id,
|
|
212
|
+
name: hyperEVM.name,
|
|
213
|
+
logoUrl: "https://s2.coinmarketcap.com/static/img/coins/64x64/32196.png",
|
|
214
|
+
type: ChainType.EVM,
|
|
215
|
+
nativeRequired: parseEther("0.01"),
|
|
216
|
+
canDepositNative: true,
|
|
217
|
+
defaultToken: getHyperEVMNativeToken(),
|
|
218
|
+
nativeToken: getHyperEVMNativeToken(),
|
|
219
|
+
viem: hyperEVM,
|
|
220
|
+
pollingInterval: 1000, // 1 second for Hyperliquid
|
|
221
|
+
coingeckoName: "hyperevm",
|
|
222
|
+
wethAddress: "0x5555555555555555555555555555555555555555",
|
|
223
|
+
},
|
|
192
224
|
};
|
|
193
225
|
|
|
194
226
|
export const EVM_TESTNET: Record<number, IEVMChain> = {
|
|
@@ -253,11 +285,31 @@ export const SOLANA_MAINNET: ISolanaChain = {
|
|
|
253
285
|
coingeckoName: "solana",
|
|
254
286
|
};
|
|
255
287
|
|
|
288
|
+
export const HYPERLIQUID_MAINNET: IHyperliquidChain = {
|
|
289
|
+
id: HYPERLIQUID_CHAIN_ID,
|
|
290
|
+
name: "Hyperliquid",
|
|
291
|
+
type: ChainType.HYPERLIQUID,
|
|
292
|
+
logoUrl: "https://s2.coinmarketcap.com/static/img/coins/64x64/32196.png",
|
|
293
|
+
nativeRequired: BigInt(0), // No native transfer needed - using Relay's useDepositAddress flow (USDC is native)
|
|
294
|
+
canDepositNative: true, // Can deposit USDC (native token)
|
|
295
|
+
defaultToken: getHyperliquidUSDCToken(),
|
|
296
|
+
nativeToken: getHyperliquidUSDCToken(),
|
|
297
|
+
coingeckoName: null,
|
|
298
|
+
apiUrl: "https://api.hyperliquid.xyz",
|
|
299
|
+
blockExplorer: {
|
|
300
|
+
url: "https://app.hyperliquid.xyz/explorer",
|
|
301
|
+
},
|
|
302
|
+
};
|
|
303
|
+
|
|
256
304
|
export const EVM_CHAINS: Record<number, IEVMChain> = { ...EVM_MAINNET, ...EVM_TESTNET };
|
|
257
305
|
|
|
258
306
|
export const SOLANA_CHAINS: Record<number, ISolanaChain> = { [RELAY_SOLANA_MAINNET_CHAIN_ID]: SOLANA_MAINNET };
|
|
259
307
|
|
|
260
|
-
export const
|
|
308
|
+
export const HYPERLIQUID_CHAINS: Record<number, IHyperliquidChain> = {
|
|
309
|
+
[HYPERLIQUID_CHAIN_ID]: HYPERLIQUID_MAINNET,
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
export const ALL_CHAINS: Record<number, IBaseChain> = { ...EVM_CHAINS, ...SOLANA_CHAINS, ...HYPERLIQUID_CHAINS };
|
|
261
313
|
|
|
262
314
|
export function getSolanaChains(network: "mainnet" | "testnet"): ISolanaChain {
|
|
263
315
|
invariant(network === "mainnet", "Solana chain is only supported on mainnet");
|
|
@@ -305,7 +357,9 @@ export function canDepositNative(chainId: number): boolean {
|
|
|
305
357
|
}
|
|
306
358
|
|
|
307
359
|
export function isMainnet(chainId: number): boolean {
|
|
308
|
-
return
|
|
360
|
+
return (
|
|
361
|
+
EVM_MAINNET[chainId] !== undefined || RELAY_SOLANA_MAINNET_CHAIN_ID === chainId || HYPERLIQUID_CHAIN_ID === chainId
|
|
362
|
+
);
|
|
309
363
|
}
|
|
310
364
|
|
|
311
365
|
export function isTestnet(chainId: number): boolean {
|
|
@@ -319,7 +373,13 @@ export function getDefaultToken(chainId: number): components["schemas"]["Token"]
|
|
|
319
373
|
|
|
320
374
|
export function getChainName(chainId: number): string {
|
|
321
375
|
invariant(ALL_CHAINS[chainId], `Chain ${chainId} is not supported`);
|
|
322
|
-
|
|
376
|
+
const chain = ALL_CHAINS[chainId];
|
|
377
|
+
|
|
378
|
+
if (isEvmChain(chainId)) {
|
|
379
|
+
return (chain as IEVMChain).viem.name;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return chain.name;
|
|
323
383
|
}
|
|
324
384
|
|
|
325
385
|
export function getCoingeckoName(chainId: number): string | null {
|
|
@@ -481,6 +541,13 @@ export function getPaymentUrl(address: string, amount: bigint, currency: string,
|
|
|
481
541
|
return url;
|
|
482
542
|
}
|
|
483
543
|
|
|
544
|
+
case ChainType.HYPERLIQUID: {
|
|
545
|
+
// NOTE: Hyperliquid is only supported as destination chain (not source chain).
|
|
546
|
+
// Payment URLs are not needed since users cannot send FROM Hyperliquid in our flow.
|
|
547
|
+
// Return address as placeholder (this code path should not be reached).
|
|
548
|
+
return address;
|
|
549
|
+
}
|
|
550
|
+
|
|
484
551
|
default:
|
|
485
552
|
// Fallback to just the address if chain type is unknown
|
|
486
553
|
return address;
|
|
@@ -494,6 +561,10 @@ export function getExplorerTxUrl(chainId: number, txHash: string) {
|
|
|
494
561
|
if (EVM_CHAINS[chainId]) {
|
|
495
562
|
return EVM_CHAINS[chainId].viem.blockExplorers?.default.url + "/tx/" + txHash;
|
|
496
563
|
}
|
|
564
|
+
if (HYPERLIQUID_CHAINS[chainId]) {
|
|
565
|
+
return HYPERLIQUID_CHAINS[chainId].blockExplorer.url + "/tx/" + txHash;
|
|
566
|
+
}
|
|
567
|
+
// Default to Solscan for Solana transactions
|
|
497
568
|
return "https://solscan.io/tx/" + txHash;
|
|
498
569
|
}
|
|
499
570
|
|
|
@@ -501,6 +572,10 @@ export function getExplorerAddressUrl(chainId: number, address: string) {
|
|
|
501
572
|
if (EVM_CHAINS[chainId]) {
|
|
502
573
|
return EVM_CHAINS[chainId].viem.blockExplorers?.default.url + "/address/" + address;
|
|
503
574
|
}
|
|
575
|
+
if (HYPERLIQUID_CHAINS[chainId]) {
|
|
576
|
+
return HYPERLIQUID_CHAINS[chainId].blockExplorer.url + "/address/" + address;
|
|
577
|
+
}
|
|
578
|
+
// Default to Solscan for Solana addresses
|
|
504
579
|
return "https://solscan.io/account/" + address;
|
|
505
580
|
}
|
|
506
581
|
|
|
@@ -520,3 +595,38 @@ export function getNativeToken(chainId: number): components["schemas"]["Token"]
|
|
|
520
595
|
export function isEvmChain(chainId: number): boolean {
|
|
521
596
|
return Boolean(EVM_CHAINS[chainId]);
|
|
522
597
|
}
|
|
598
|
+
|
|
599
|
+
export function isHyperliquidChain(chainId: number): boolean {
|
|
600
|
+
return HYPERLIQUID_CHAINS[chainId] !== undefined;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
export function getHyperliquidChain(chainId: number): IHyperliquidChain {
|
|
604
|
+
invariant(HYPERLIQUID_CHAINS[chainId], `Chain ${chainId} is not a Hyperliquid chain`);
|
|
605
|
+
return HYPERLIQUID_CHAINS[chainId];
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Get available chain IDs for AnySpend based on context (source or destination).
|
|
610
|
+
* Filters out chains that shouldn't be available for the given context.
|
|
611
|
+
*
|
|
612
|
+
* @param context - "from" for source chains, "to" for destination chains
|
|
613
|
+
* @returns Array of available chain IDs
|
|
614
|
+
*
|
|
615
|
+
* @example
|
|
616
|
+
* // Get source chains (excludes Hyperliquid)
|
|
617
|
+
* const sourceChains = getAvailableChainIds("from") // [1, 8453, 137, ...]
|
|
618
|
+
*
|
|
619
|
+
* // Get destination chains (includes Hyperliquid)
|
|
620
|
+
* const destChains = getAvailableChainIds("to") // [1, 8453, 137, ..., 1337]
|
|
621
|
+
*/
|
|
622
|
+
export function getAvailableChainIds(context: "from" | "to"): number[] {
|
|
623
|
+
const allChainIds = Object.values(ALL_CHAINS).map(chain => chain.id);
|
|
624
|
+
|
|
625
|
+
if (context === "from") {
|
|
626
|
+
// Hyperliquid is only supported as destination chain, not source chain
|
|
627
|
+
return allChainIds.filter(chainId => chainId !== HYPERLIQUID_CHAIN_ID);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// For destination ("to"), all chains are available including Hyperliquid
|
|
631
|
+
return allChainIds;
|
|
632
|
+
}
|