@b3dotfun/sdk 0.0.87 → 0.0.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/cjs/anyspend/react/components/AnySpend.d.ts +5 -0
- package/dist/cjs/anyspend/react/components/AnySpend.js +77 -73
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +0 -1
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.d.ts +1 -1
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +1 -2
- package/dist/cjs/anyspend/react/components/AnySpendDeposit.d.ts +122 -0
- package/dist/cjs/anyspend/react/components/AnySpendDeposit.js +190 -0
- package/dist/cjs/anyspend/react/components/QRDeposit.d.ts +43 -0
- package/dist/cjs/anyspend/react/components/QRDeposit.js +146 -0
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +17 -12
- package/dist/cjs/anyspend/react/components/common/OrderDetailsCollapsible.d.ts +2 -0
- package/dist/cjs/anyspend/react/components/common/OrderDetailsCollapsible.js +12 -5
- package/dist/cjs/anyspend/react/components/common/OrderStatus.js +2 -2
- package/dist/cjs/anyspend/react/components/common/WarningText.d.ts +32 -0
- package/dist/cjs/anyspend/react/components/common/WarningText.js +36 -0
- package/dist/cjs/anyspend/react/components/icons/CreditCardIcon.d.ts +6 -0
- package/dist/cjs/anyspend/react/components/icons/CreditCardIcon.js +6 -0
- package/dist/cjs/anyspend/react/components/icons/QrCodeIcon.d.ts +6 -0
- package/dist/cjs/anyspend/react/components/icons/QrCodeIcon.js +6 -0
- package/dist/cjs/anyspend/react/components/index.d.ts +2 -0
- package/dist/cjs/anyspend/react/components/index.js +3 -1
- 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.d.ts +2 -2
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +35 -11
- package/dist/cjs/anyspend/react/hooks/useCreateDepositFirstOrder.d.ts +24 -0
- package/dist/cjs/anyspend/react/hooks/useCreateDepositFirstOrder.js +86 -0
- package/dist/cjs/anyspend/react/hooks/useSigMint.d.ts +1 -1
- package/dist/cjs/anyspend/utils/format.js +28 -5
- package/dist/cjs/global-account/react/components/AvatarEditor/AvatarEditor.js +2 -1
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +17 -47
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +6 -7
- package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +0 -5
- package/dist/cjs/global-account/react/components/B3Provider/types.js +4 -4
- package/dist/cjs/global-account/react/components/B3Provider/useB3.d.ts +1 -0
- package/dist/cjs/global-account/react/components/B3Provider/useB3.js +1 -0
- package/dist/cjs/global-account/react/components/B3Provider/useB3Account.d.ts +1 -0
- package/dist/cjs/global-account/react/components/B3Provider/useB3Account.js +10 -0
- package/dist/cjs/global-account/react/components/B3Provider/useB3Config.d.ts +9 -0
- package/dist/cjs/global-account/react/components/B3Provider/useB3Config.js +23 -0
- package/dist/cjs/global-account/react/components/LinkAccount/LinkAccount.js +1 -1
- package/dist/cjs/global-account/react/components/LinkAccount/LinkNewAccount.js +1 -2
- package/dist/cjs/global-account/react/components/ManageAccount/ProfileSection.js +2 -1
- package/dist/cjs/global-account/react/components/ManageAccount/SettingsProfileCard.js +2 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3.js +2 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +2 -1
- package/dist/cjs/global-account/react/components/index.d.ts +2 -0
- package/dist/cjs/global-account/react/components/index.js +7 -3
- package/dist/cjs/global-account/react/hooks/useAccountWallet.js +3 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/useAutoSelectWallet.d.ts +7 -0
- package/dist/cjs/global-account/react/hooks/useAutoSelectWallet.js +42 -0
- package/dist/cjs/global-account/react/hooks/useTurnkeyAuth.js +6 -4
- package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +2 -2
- package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +4 -0
- package/dist/esm/anyspend/react/components/AnySpend.d.ts +5 -0
- package/dist/esm/anyspend/react/components/AnySpend.js +77 -73
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +0 -1
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.d.ts +1 -1
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +1 -2
- package/dist/esm/anyspend/react/components/AnySpendDeposit.d.ts +122 -0
- package/dist/esm/anyspend/react/components/AnySpendDeposit.js +187 -0
- package/dist/esm/anyspend/react/components/QRDeposit.d.ts +43 -0
- package/dist/esm/anyspend/react/components/QRDeposit.js +143 -0
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +17 -12
- package/dist/esm/anyspend/react/components/common/OrderDetailsCollapsible.d.ts +2 -0
- package/dist/esm/anyspend/react/components/common/OrderDetailsCollapsible.js +12 -5
- package/dist/esm/anyspend/react/components/common/OrderStatus.js +2 -2
- package/dist/esm/anyspend/react/components/common/WarningText.d.ts +32 -0
- package/dist/esm/anyspend/react/components/common/WarningText.js +32 -0
- package/dist/esm/anyspend/react/components/icons/CreditCardIcon.d.ts +6 -0
- package/dist/esm/anyspend/react/components/icons/CreditCardIcon.js +2 -0
- package/dist/esm/anyspend/react/components/icons/QrCodeIcon.d.ts +6 -0
- package/dist/esm/anyspend/react/components/icons/QrCodeIcon.js +2 -0
- package/dist/esm/anyspend/react/components/index.d.ts +2 -0
- package/dist/esm/anyspend/react/components/index.js +1 -0
- 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.d.ts +2 -2
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +35 -11
- package/dist/esm/anyspend/react/hooks/useCreateDepositFirstOrder.d.ts +24 -0
- package/dist/esm/anyspend/react/hooks/useCreateDepositFirstOrder.js +83 -0
- package/dist/esm/anyspend/react/hooks/useSigMint.d.ts +1 -1
- package/dist/esm/anyspend/utils/format.js +28 -5
- package/dist/esm/global-account/react/components/AvatarEditor/AvatarEditor.js +3 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +21 -51
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +6 -7
- package/dist/esm/global-account/react/components/B3Provider/types.d.ts +0 -5
- package/dist/esm/global-account/react/components/B3Provider/types.js +4 -4
- package/dist/esm/global-account/react/components/B3Provider/useB3.d.ts +1 -0
- package/dist/esm/global-account/react/components/B3Provider/useB3.js +1 -0
- package/dist/esm/global-account/react/components/B3Provider/useB3Account.d.ts +1 -0
- package/dist/esm/global-account/react/components/B3Provider/useB3Account.js +6 -0
- package/dist/esm/global-account/react/components/B3Provider/useB3Config.d.ts +9 -0
- package/dist/esm/global-account/react/components/B3Provider/useB3Config.js +19 -0
- package/dist/esm/global-account/react/components/LinkAccount/LinkAccount.js +2 -2
- package/dist/esm/global-account/react/components/LinkAccount/LinkNewAccount.js +2 -3
- package/dist/esm/global-account/react/components/ManageAccount/ProfileSection.js +3 -2
- package/dist/esm/global-account/react/components/ManageAccount/SettingsProfileCard.js +3 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3.js +3 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +3 -2
- package/dist/esm/global-account/react/components/index.d.ts +2 -0
- package/dist/esm/global-account/react/components/index.js +2 -0
- package/dist/esm/global-account/react/hooks/useAccountWallet.js +4 -3
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +1 -1
- package/dist/esm/global-account/react/hooks/useAutoSelectWallet.d.ts +7 -0
- package/dist/esm/global-account/react/hooks/useAutoSelectWallet.js +39 -0
- package/dist/esm/global-account/react/hooks/useTurnkeyAuth.js +6 -4
- package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +2 -2
- package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +4 -0
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/components/AnySpend.d.ts +5 -0
- package/dist/types/anyspend/react/components/AnySpendCustomExactIn.d.ts +1 -1
- package/dist/types/anyspend/react/components/AnySpendDeposit.d.ts +122 -0
- package/dist/types/anyspend/react/components/QRDeposit.d.ts +43 -0
- package/dist/types/anyspend/react/components/common/OrderDetailsCollapsible.d.ts +2 -0
- package/dist/types/anyspend/react/components/common/WarningText.d.ts +32 -0
- package/dist/types/anyspend/react/components/icons/CreditCardIcon.d.ts +6 -0
- package/dist/types/anyspend/react/components/icons/QrCodeIcon.d.ts +6 -0
- package/dist/types/anyspend/react/components/index.d.ts +2 -0
- package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +2 -2
- package/dist/types/anyspend/react/hooks/useCreateDepositFirstOrder.d.ts +24 -0
- package/dist/types/anyspend/react/hooks/useSigMint.d.ts +1 -1
- package/dist/types/global-account/react/components/B3Provider/types.d.ts +0 -5
- package/dist/types/global-account/react/components/B3Provider/useB3.d.ts +1 -0
- package/dist/types/global-account/react/components/B3Provider/useB3Account.d.ts +1 -0
- package/dist/types/global-account/react/components/B3Provider/useB3Config.d.ts +9 -0
- package/dist/types/global-account/react/components/index.d.ts +2 -0
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +1 -1
- package/dist/types/global-account/react/hooks/useAutoSelectWallet.d.ts +7 -0
- package/dist/types/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/types/global-account/react/stores/useModalStore.d.ts +4 -0
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +105 -85
- package/src/anyspend/react/components/AnySpendCustom.tsx +0 -2
- package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +2 -3
- package/src/anyspend/react/components/AnySpendDeposit.tsx +578 -0
- package/src/anyspend/react/components/QRDeposit.tsx +348 -0
- package/src/anyspend/react/components/common/OrderDetails.tsx +26 -8
- package/src/anyspend/react/components/common/OrderDetailsCollapsible.tsx +20 -8
- package/src/anyspend/react/components/common/OrderStatus.tsx +2 -2
- package/src/anyspend/react/components/common/WarningText.tsx +52 -0
- package/src/anyspend/react/components/icons/CreditCardIcon.tsx +25 -0
- package/src/anyspend/react/components/icons/QrCodeIcon.tsx +25 -0
- package/src/anyspend/react/components/icons/credit-card.svg +5 -0
- package/src/anyspend/react/components/icons/qr-code.svg +5 -0
- package/src/anyspend/react/components/index.ts +2 -0
- package/src/anyspend/react/hooks/index.ts +1 -0
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +37 -12
- package/src/anyspend/react/hooks/useCreateDepositFirstOrder.ts +110 -0
- package/src/anyspend/utils/format.ts +33 -5
- package/src/global-account/react/components/AvatarEditor/AvatarEditor.tsx +10 -2
- package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +6 -7
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +20 -71
- package/src/global-account/react/components/B3Provider/types.ts +8 -9
- package/src/global-account/react/components/B3Provider/useB3.ts +1 -0
- package/src/global-account/react/components/B3Provider/useB3Account.ts +7 -0
- package/src/global-account/react/components/B3Provider/useB3Config.ts +34 -0
- package/src/global-account/react/components/LinkAccount/LinkAccount.tsx +2 -2
- package/src/global-account/react/components/LinkAccount/LinkNewAccount.tsx +2 -3
- package/src/global-account/react/components/ManageAccount/ProfileSection.tsx +10 -2
- package/src/global-account/react/components/ManageAccount/SettingsProfileCard.tsx +3 -2
- package/src/global-account/react/components/SignInWithB3/SignInWithB3.tsx +2 -2
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +5 -2
- package/src/global-account/react/components/index.ts +2 -0
- package/src/global-account/react/hooks/useAccountWallet.tsx +4 -3
- package/src/global-account/react/hooks/useAutoSelectWallet.ts +51 -0
- package/src/global-account/react/hooks/useTurnkeyAuth.ts +7 -5
- package/src/global-account/react/hooks/useUnifiedChainSwitchAndExecute.ts +2 -2
- package/src/global-account/react/stores/useModalStore.ts +4 -0
- package/src/styles/index.css +2 -0
|
@@ -0,0 +1,578 @@
|
|
|
1
|
+
import { HYPERLIQUID_CHAIN_ID } from "@b3dotfun/sdk/anyspend";
|
|
2
|
+
import { components } from "@b3dotfun/sdk/anyspend/types/api";
|
|
3
|
+
import { GetQuoteResponse } from "@b3dotfun/sdk/anyspend/types/api_req_res";
|
|
4
|
+
import { Skeleton, useAccountWallet, useSimBalance } from "@b3dotfun/sdk/global-account/react";
|
|
5
|
+
import { cn } from "@b3dotfun/sdk/shared/utils/cn";
|
|
6
|
+
import {
|
|
7
|
+
NetworkArbitrumOne,
|
|
8
|
+
NetworkBase,
|
|
9
|
+
NetworkBinanceSmartChain,
|
|
10
|
+
NetworkEthereum,
|
|
11
|
+
NetworkOptimism,
|
|
12
|
+
NetworkPolygonPos,
|
|
13
|
+
} from "@web3icons/react";
|
|
14
|
+
import { ChevronRight } from "lucide-react";
|
|
15
|
+
import { useMemo, useState } from "react";
|
|
16
|
+
import { AnySpend } from "./AnySpend";
|
|
17
|
+
import { AnySpendCustomExactIn } from "./AnySpendCustomExactIn";
|
|
18
|
+
import { ChainWarningText } from "./common/WarningText";
|
|
19
|
+
import { CreditCardIcon } from "./icons/CreditCardIcon";
|
|
20
|
+
import { QrCodeIcon } from "./icons/QrCodeIcon";
|
|
21
|
+
import { QRDeposit } from "./QRDeposit";
|
|
22
|
+
|
|
23
|
+
export interface DepositContractConfig {
|
|
24
|
+
/** Custom function ABI JSON string */
|
|
25
|
+
functionAbi: string;
|
|
26
|
+
/** The function name to call */
|
|
27
|
+
functionName: string;
|
|
28
|
+
/** Custom function arguments. Use "{{amount_out}}" for the deposit amount placeholder */
|
|
29
|
+
functionArgs: string[];
|
|
30
|
+
/** The contract address to deposit to */
|
|
31
|
+
to: string;
|
|
32
|
+
/** Optional spender address if different from contract address */
|
|
33
|
+
spenderAddress?: string;
|
|
34
|
+
/** Custom action label */
|
|
35
|
+
action?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ChainConfig {
|
|
39
|
+
/** Chain ID */
|
|
40
|
+
id: number;
|
|
41
|
+
/** Display name */
|
|
42
|
+
name: string;
|
|
43
|
+
/** Optional icon URL */
|
|
44
|
+
iconUrl?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface AnySpendDepositProps {
|
|
48
|
+
/** Order ID to load an existing order */
|
|
49
|
+
loadOrder?: string;
|
|
50
|
+
/** Display mode */
|
|
51
|
+
mode?: "modal" | "page";
|
|
52
|
+
/** The recipient address for the deposit */
|
|
53
|
+
recipientAddress: string;
|
|
54
|
+
/** Payment type - crypto or fiat. If not set, shows chain selection first */
|
|
55
|
+
paymentType?: "crypto" | "fiat";
|
|
56
|
+
/** Source token address to pre-select */
|
|
57
|
+
sourceTokenAddress?: string;
|
|
58
|
+
/** Source chain ID to pre-select. If not provided, shows chain selection */
|
|
59
|
+
sourceTokenChainId?: number;
|
|
60
|
+
/** The destination token to receive */
|
|
61
|
+
destinationToken: components["schemas"]["Token"];
|
|
62
|
+
/** The destination chain ID */
|
|
63
|
+
destinationChainId: number;
|
|
64
|
+
/** Callback when deposit succeeds */
|
|
65
|
+
onSuccess?: (amount: string) => void;
|
|
66
|
+
/** Callback for opening a custom modal (e.g., for special token handling) */
|
|
67
|
+
onOpenCustomModal?: () => void;
|
|
68
|
+
/** Custom footer content */
|
|
69
|
+
mainFooter?: React.ReactNode;
|
|
70
|
+
/** Called when a token is selected. Call event.preventDefault() to prevent default behavior */
|
|
71
|
+
onTokenSelect?: (token: components["schemas"]["Token"], event: { preventDefault: () => void }) => void;
|
|
72
|
+
/** Custom USD input value presets for fiat payment */
|
|
73
|
+
customUsdInputValues?: string[];
|
|
74
|
+
/** Whether to prefer using connected EOA wallet */
|
|
75
|
+
preferEoa?: boolean;
|
|
76
|
+
/** Minimum destination amount required */
|
|
77
|
+
minDestinationAmount?: number;
|
|
78
|
+
/** Custom header component */
|
|
79
|
+
header?: ({
|
|
80
|
+
anyspendPrice,
|
|
81
|
+
isLoadingAnyspendPrice,
|
|
82
|
+
}: {
|
|
83
|
+
anyspendPrice: GetQuoteResponse | undefined;
|
|
84
|
+
isLoadingAnyspendPrice: boolean;
|
|
85
|
+
}) => React.JSX.Element;
|
|
86
|
+
/** Order type for the deposit */
|
|
87
|
+
orderType?: "hype_duel" | "custom_exact_in" | "swap";
|
|
88
|
+
/** Custom action label displayed on buttons */
|
|
89
|
+
actionLabel?: string;
|
|
90
|
+
/** Configuration for depositing to a custom contract.
|
|
91
|
+
* If provided, creates a custom_exact_in order that calls the contract.
|
|
92
|
+
* If not provided, creates a simple hype_duel order for direct deposits.
|
|
93
|
+
*/
|
|
94
|
+
depositContractConfig?: DepositContractConfig;
|
|
95
|
+
/** Whether to show chain selection step. Defaults to true if sourceTokenChainId is not provided */
|
|
96
|
+
showChainSelection?: boolean;
|
|
97
|
+
/** Custom list of supported chains. If not provided, uses default chains */
|
|
98
|
+
supportedChains?: ChainConfig[];
|
|
99
|
+
/** Minimum pool size for filtering tokens (default: 1,000,000) */
|
|
100
|
+
minPoolSize?: number;
|
|
101
|
+
/** Custom title for chain selection step */
|
|
102
|
+
chainSelectionTitle?: string;
|
|
103
|
+
/** Custom description for chain selection step */
|
|
104
|
+
chainSelectionDescription?: string;
|
|
105
|
+
/** Number of top chains to show (default: 3) */
|
|
106
|
+
topChainsCount?: number;
|
|
107
|
+
/** Callback when close button is clicked */
|
|
108
|
+
onClose?: () => void;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Default supported chains
|
|
112
|
+
const DEFAULT_SUPPORTED_CHAINS: ChainConfig[] = [
|
|
113
|
+
{ id: 8453, name: "Base" },
|
|
114
|
+
{ id: 1, name: "Ethereum" },
|
|
115
|
+
{ id: 42161, name: "Arbitrum" },
|
|
116
|
+
{ id: 10, name: "Optimism" },
|
|
117
|
+
{ id: 137, name: "Polygon" },
|
|
118
|
+
{ id: 56, name: "BNB Chain" },
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
// Minimum pool size to filter out low liquidity tokens
|
|
122
|
+
const DEFAULT_MIN_POOL_SIZE = 1_000_000;
|
|
123
|
+
|
|
124
|
+
type DepositStep = "select-chain" | "deposit" | "qr-deposit";
|
|
125
|
+
|
|
126
|
+
function formatUsd(value: number): string {
|
|
127
|
+
return new Intl.NumberFormat("en-US", {
|
|
128
|
+
style: "currency",
|
|
129
|
+
currency: "USD",
|
|
130
|
+
minimumFractionDigits: 0,
|
|
131
|
+
maximumFractionDigits: value >= 100 ? 0 : 2,
|
|
132
|
+
}).format(value);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function formatDecimal(value: number): string {
|
|
136
|
+
return new Intl.NumberFormat("en-US", {
|
|
137
|
+
style: "decimal",
|
|
138
|
+
minimumFractionDigits: 0,
|
|
139
|
+
maximumFractionDigits: value >= 100 ? 0 : 2,
|
|
140
|
+
}).format(value);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Chain icon component
|
|
144
|
+
function ChainIcon({ chainId, className }: { chainId: number; className?: string }) {
|
|
145
|
+
const iconProps = {
|
|
146
|
+
variant: "branded" as const,
|
|
147
|
+
className: cn("anyspend-deposit-chain-icon", className),
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
switch (chainId) {
|
|
151
|
+
case 1:
|
|
152
|
+
return <NetworkEthereum {...iconProps} />;
|
|
153
|
+
case 8453:
|
|
154
|
+
return <NetworkBase {...iconProps} />;
|
|
155
|
+
case 137:
|
|
156
|
+
return <NetworkPolygonPos {...iconProps} />;
|
|
157
|
+
case 42161:
|
|
158
|
+
return <NetworkArbitrumOne {...iconProps} />;
|
|
159
|
+
case 10:
|
|
160
|
+
return <NetworkOptimism {...iconProps} />;
|
|
161
|
+
case 56:
|
|
162
|
+
return <NetworkBinanceSmartChain {...iconProps} />;
|
|
163
|
+
default:
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* A flexible deposit component that wraps AnySpendCustomExactIn with optional chain selection.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* // Simple deposit with chain selection
|
|
173
|
+
* <AnySpendDeposit
|
|
174
|
+
* recipientAddress={userAddress}
|
|
175
|
+
* destinationToken={myToken}
|
|
176
|
+
* destinationChainId={base.id}
|
|
177
|
+
* onSuccess={(amount) => console.log(`Deposited ${amount}`)}
|
|
178
|
+
* />
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* // Skip chain selection by providing sourceTokenChainId
|
|
182
|
+
* <AnySpendDeposit
|
|
183
|
+
* recipientAddress={userAddress}
|
|
184
|
+
* destinationToken={myToken}
|
|
185
|
+
* destinationChainId={base.id}
|
|
186
|
+
* sourceTokenChainId={base.id}
|
|
187
|
+
* onSuccess={(amount) => console.log(`Deposited ${amount}`)}
|
|
188
|
+
* />
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* // Deposit with custom contract
|
|
192
|
+
* <AnySpendDeposit
|
|
193
|
+
* recipientAddress={userAddress}
|
|
194
|
+
* destinationToken={myToken}
|
|
195
|
+
* destinationChainId={base.id}
|
|
196
|
+
* depositContractConfig={{
|
|
197
|
+
* contractAddress: "0x...",
|
|
198
|
+
* functionName: "depositFor",
|
|
199
|
+
* }}
|
|
200
|
+
* onSuccess={(amount) => console.log(`Deposited ${amount}`)}
|
|
201
|
+
* />
|
|
202
|
+
*/
|
|
203
|
+
export function AnySpendDeposit({
|
|
204
|
+
loadOrder,
|
|
205
|
+
mode = "modal",
|
|
206
|
+
recipientAddress,
|
|
207
|
+
paymentType: initialPaymentType,
|
|
208
|
+
sourceTokenAddress,
|
|
209
|
+
sourceTokenChainId: initialSourceChainId,
|
|
210
|
+
destinationToken,
|
|
211
|
+
destinationChainId,
|
|
212
|
+
onSuccess,
|
|
213
|
+
onOpenCustomModal,
|
|
214
|
+
mainFooter,
|
|
215
|
+
onTokenSelect,
|
|
216
|
+
customUsdInputValues,
|
|
217
|
+
preferEoa,
|
|
218
|
+
minDestinationAmount,
|
|
219
|
+
header,
|
|
220
|
+
orderType,
|
|
221
|
+
depositContractConfig,
|
|
222
|
+
showChainSelection,
|
|
223
|
+
supportedChains = DEFAULT_SUPPORTED_CHAINS,
|
|
224
|
+
minPoolSize = DEFAULT_MIN_POOL_SIZE,
|
|
225
|
+
topChainsCount = 3,
|
|
226
|
+
onClose,
|
|
227
|
+
}: AnySpendDepositProps) {
|
|
228
|
+
const { connectedEOAWallet } = useAccountWallet();
|
|
229
|
+
const eoaAddress = connectedEOAWallet?.getAccount()?.address;
|
|
230
|
+
|
|
231
|
+
// Determine if we should show chain selection
|
|
232
|
+
const shouldShowChainSelection = showChainSelection ?? (!initialSourceChainId && !initialPaymentType);
|
|
233
|
+
|
|
234
|
+
const [step, setStep] = useState<DepositStep>(shouldShowChainSelection ? "select-chain" : "deposit");
|
|
235
|
+
const [selectedChainId, setSelectedChainId] = useState<number | undefined>(initialSourceChainId);
|
|
236
|
+
const [paymentType, setPaymentType] = useState<"crypto" | "fiat">(initialPaymentType ?? "crypto");
|
|
237
|
+
|
|
238
|
+
// Fetch balances for EOA wallet
|
|
239
|
+
const { data: balanceData, isLoading: isBalanceLoading } = useSimBalance(
|
|
240
|
+
shouldShowChainSelection ? eoaAddress : undefined,
|
|
241
|
+
supportedChains.map(c => c.id),
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
// Group balances by chain and calculate total USD value per chain
|
|
245
|
+
const chainBalances = useMemo(() => {
|
|
246
|
+
if (!balanceData?.balances) return {};
|
|
247
|
+
|
|
248
|
+
const filteredBalances = balanceData.balances.filter(
|
|
249
|
+
token => token.address === "native" || (token.pool_size && token.pool_size > minPoolSize),
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
return filteredBalances.reduce(
|
|
253
|
+
(acc, token) => {
|
|
254
|
+
const chainId = token.chain_id;
|
|
255
|
+
if (!acc[chainId]) {
|
|
256
|
+
acc[chainId] = {
|
|
257
|
+
chainId,
|
|
258
|
+
chainName: token.chain,
|
|
259
|
+
totalUsdValue: 0,
|
|
260
|
+
tokenCount: 0,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
acc[chainId].totalUsdValue += token.value_usd || 0;
|
|
264
|
+
acc[chainId].tokenCount += 1;
|
|
265
|
+
return acc;
|
|
266
|
+
},
|
|
267
|
+
{} as Record<number, { chainId: number; chainName: string; totalUsdValue: number; tokenCount: number }>,
|
|
268
|
+
);
|
|
269
|
+
}, [balanceData, minPoolSize]);
|
|
270
|
+
|
|
271
|
+
// Sort chains by USD value (highest first)
|
|
272
|
+
const sortedChains = useMemo(() => {
|
|
273
|
+
return supportedChains
|
|
274
|
+
.map(chain => ({
|
|
275
|
+
...chain,
|
|
276
|
+
balance: chainBalances[chain.id]?.totalUsdValue || 0,
|
|
277
|
+
tokenCount: chainBalances[chain.id]?.tokenCount || 0,
|
|
278
|
+
}))
|
|
279
|
+
.sort((a, b) => b.balance - a.balance);
|
|
280
|
+
}, [supportedChains, chainBalances]);
|
|
281
|
+
|
|
282
|
+
// Get top chains with balance
|
|
283
|
+
const topChainsWithBalance = useMemo(() => {
|
|
284
|
+
return sortedChains.filter(chain => chain.balance > 0).slice(0, topChainsCount);
|
|
285
|
+
}, [sortedChains, topChainsCount]);
|
|
286
|
+
|
|
287
|
+
// Calculate total balance across all chains
|
|
288
|
+
const totalBalance = useMemo(() => {
|
|
289
|
+
return Object.values(chainBalances).reduce((sum, chain) => sum + chain.totalUsdValue, 0);
|
|
290
|
+
}, [chainBalances]);
|
|
291
|
+
|
|
292
|
+
if (!recipientAddress) return null;
|
|
293
|
+
|
|
294
|
+
const tokenSymbol = destinationToken.symbol ?? "TOKEN";
|
|
295
|
+
|
|
296
|
+
// Determine order type based on config
|
|
297
|
+
const effectiveOrderType = orderType ?? (depositContractConfig ? "custom_exact_in" : "swap");
|
|
298
|
+
|
|
299
|
+
// Default header if not provided
|
|
300
|
+
const defaultHeader = () => (
|
|
301
|
+
<div className="anyspend-deposit-header mb-4 flex flex-col items-center gap-3 text-center">
|
|
302
|
+
<div>
|
|
303
|
+
<h1 className="anyspend-deposit-title text-as-primary text-xl font-bold">
|
|
304
|
+
{paymentType === "crypto" ? `Deposit ${tokenSymbol}` : "Fund with Fiat"}
|
|
305
|
+
</h1>
|
|
306
|
+
</div>
|
|
307
|
+
</div>
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
const handleSelectChain = (chainId: number) => {
|
|
311
|
+
setSelectedChainId(chainId);
|
|
312
|
+
setPaymentType("crypto");
|
|
313
|
+
setStep("deposit");
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
const handleSelectCrypto = () => {
|
|
317
|
+
setPaymentType("crypto");
|
|
318
|
+
setSelectedChainId(undefined);
|
|
319
|
+
setStep("deposit");
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
const handleSelectFiat = () => {
|
|
323
|
+
setPaymentType("fiat");
|
|
324
|
+
setSelectedChainId(undefined);
|
|
325
|
+
setStep("deposit");
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const handleBack = () => {
|
|
329
|
+
setStep("select-chain");
|
|
330
|
+
setSelectedChainId(undefined);
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
const handleSelectQrDeposit = () => {
|
|
334
|
+
setStep("qr-deposit");
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
// Chain selection view
|
|
338
|
+
if (step === "select-chain") {
|
|
339
|
+
return (
|
|
340
|
+
<div
|
|
341
|
+
className={cn(
|
|
342
|
+
"anyspend-deposit anyspend-deposit-chain-selection font-inter bg-as-surface-primary relative mx-auto w-full max-w-[460px]",
|
|
343
|
+
mode === "page" && "border-as-border-secondary overflow-hidden rounded-2xl border shadow-xl",
|
|
344
|
+
)}
|
|
345
|
+
>
|
|
346
|
+
{/* Close button */}
|
|
347
|
+
{onClose && (
|
|
348
|
+
<button
|
|
349
|
+
onClick={onClose}
|
|
350
|
+
className="anyspend-deposit-close-button text-as-secondary hover:text-as-primary absolute right-4 top-4 z-10"
|
|
351
|
+
>
|
|
352
|
+
<svg className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
353
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
|
354
|
+
</svg>
|
|
355
|
+
</button>
|
|
356
|
+
)}
|
|
357
|
+
<div className="anyspend-deposit-balance-header border-secondary border-b p-5">
|
|
358
|
+
{/* Balance header */}
|
|
359
|
+
{!isBalanceLoading && totalBalance > 0 && (
|
|
360
|
+
<div className="anyspend-deposit-balance">
|
|
361
|
+
<p className="anyspend-deposit-balance-label text-as-secondary text-sm">Your Balance</p>
|
|
362
|
+
<p className="anyspend-deposit-balance-value text-as-primary text-3xl font-semibold">
|
|
363
|
+
{formatDecimal(totalBalance)} <span className="text-sm">USD</span>
|
|
364
|
+
</p>
|
|
365
|
+
</div>
|
|
366
|
+
)}
|
|
367
|
+
{isBalanceLoading && (
|
|
368
|
+
<div className="anyspend-deposit-balance-skeleton">
|
|
369
|
+
<Skeleton className="mb-2 h-4 w-24" />
|
|
370
|
+
<Skeleton className="h-8 w-32" />
|
|
371
|
+
</div>
|
|
372
|
+
)}
|
|
373
|
+
</div>
|
|
374
|
+
<div className="anyspend-deposit-options flex flex-col gap-2 p-6">
|
|
375
|
+
{/* Loading state */}
|
|
376
|
+
{isBalanceLoading && (
|
|
377
|
+
<div className="anyspend-deposit-chains-skeleton flex flex-col gap-2">
|
|
378
|
+
{[...Array(topChainsCount)].map((_, i) => (
|
|
379
|
+
<div key={i} className="border-border-primary flex items-center justify-between rounded-xl border p-4">
|
|
380
|
+
<div className="flex items-center gap-3">
|
|
381
|
+
<Skeleton className="h-6 w-6 rounded-full" />
|
|
382
|
+
<div className="flex flex-col gap-1">
|
|
383
|
+
<Skeleton className="h-4 w-32" />
|
|
384
|
+
<Skeleton className="h-3 w-20" />
|
|
385
|
+
</div>
|
|
386
|
+
</div>
|
|
387
|
+
<Skeleton className="h-5 w-5" />
|
|
388
|
+
</div>
|
|
389
|
+
))}
|
|
390
|
+
</div>
|
|
391
|
+
)}
|
|
392
|
+
|
|
393
|
+
{/* Top chains with balance */}
|
|
394
|
+
{topChainsWithBalance.length > 0 && (
|
|
395
|
+
<div className="anyspend-deposit-chains flex flex-col gap-2">
|
|
396
|
+
{topChainsWithBalance.map(chain => (
|
|
397
|
+
<button
|
|
398
|
+
key={chain.id}
|
|
399
|
+
onClick={() => handleSelectChain(chain.id)}
|
|
400
|
+
className="anyspend-deposit-chain-button border-border-primary hover:border-as-brand hover:bg-as-surface-secondary flex w-full items-center justify-between rounded-xl border p-4 text-left shadow-sm transition-all"
|
|
401
|
+
>
|
|
402
|
+
<div className="anyspend-deposit-chain-content">
|
|
403
|
+
<div className="anyspend-deposit-chain-info">
|
|
404
|
+
<span className="anyspend-deposit-chain-name text-as-primary flex items-center gap-1.5 font-medium">
|
|
405
|
+
Deposit from {chain.name}
|
|
406
|
+
<ChainIcon chainId={chain.id} className="h-5 w-5" />
|
|
407
|
+
</span>
|
|
408
|
+
<p className="anyspend-deposit-chain-balance text-as-secondary text-xs">
|
|
409
|
+
{formatUsd(chain.balance)} available
|
|
410
|
+
</p>
|
|
411
|
+
</div>
|
|
412
|
+
</div>
|
|
413
|
+
<ChevronRight className="anyspend-deposit-chain-chevron text-as-secondary h-5 w-5" />
|
|
414
|
+
</button>
|
|
415
|
+
))}
|
|
416
|
+
</div>
|
|
417
|
+
)}
|
|
418
|
+
|
|
419
|
+
{/* General deposit options */}
|
|
420
|
+
<div className="anyspend-deposit-general-options flex flex-col gap-2">
|
|
421
|
+
{/* Deposit Crypto - any chain */}
|
|
422
|
+
<button
|
|
423
|
+
onClick={handleSelectCrypto}
|
|
424
|
+
className="anyspend-deposit-option-button anyspend-deposit-crypto-button border-border-primary hover:border-as-brand hover:bg-as-surface-secondary flex w-full items-center justify-between rounded-xl border p-4 text-left shadow-sm transition-all"
|
|
425
|
+
>
|
|
426
|
+
<div className="anyspend-deposit-option-content">
|
|
427
|
+
<div className="anyspend-deposit-option-info">
|
|
428
|
+
<span className="anyspend-deposit-option-title text-as-primary font-medium">Deposit Crypto</span>
|
|
429
|
+
<p className="anyspend-deposit-option-description text-as-secondary text-xs">
|
|
430
|
+
Swap from any token on any chain
|
|
431
|
+
</p>
|
|
432
|
+
</div>
|
|
433
|
+
</div>
|
|
434
|
+
<ChevronRight className="anyspend-deposit-option-chevron text-as-secondary h-5 w-5" />
|
|
435
|
+
</button>
|
|
436
|
+
|
|
437
|
+
<div className="anyspend-deposit-divider flex items-center gap-3">
|
|
438
|
+
<div className="bg-as-stroke h-px flex-1" />
|
|
439
|
+
<span className="anyspend-deposit-divider-text text-as-secondary text-sm">More options</span>
|
|
440
|
+
<div className="bg-as-stroke h-px flex-1" />
|
|
441
|
+
</div>
|
|
442
|
+
|
|
443
|
+
{/* Deposit with QR Code */}
|
|
444
|
+
<button
|
|
445
|
+
onClick={handleSelectQrDeposit}
|
|
446
|
+
className="anyspend-deposit-option-button anyspend-deposit-qr-button border-border-primary hover:border-as-brand hover:bg-as-surface-secondary flex w-full items-center justify-between rounded-xl border p-4 text-left shadow-sm transition-all"
|
|
447
|
+
>
|
|
448
|
+
<div className="anyspend-deposit-option-content flex items-center gap-3">
|
|
449
|
+
<QrCodeIcon className="anyspend-deposit-option-icon h-10 w-10" />
|
|
450
|
+
<div className="anyspend-deposit-option-info">
|
|
451
|
+
<span className="anyspend-deposit-option-title text-as-primary font-medium">
|
|
452
|
+
Deposit with QR Code
|
|
453
|
+
</span>
|
|
454
|
+
<p className="anyspend-deposit-option-description text-as-secondary text-xs">
|
|
455
|
+
Send tokens directly to deposit address
|
|
456
|
+
</p>
|
|
457
|
+
</div>
|
|
458
|
+
</div>
|
|
459
|
+
<ChevronRight className="anyspend-deposit-option-chevron text-as-secondary h-5 w-5" />
|
|
460
|
+
</button>
|
|
461
|
+
|
|
462
|
+
{/* Fund with Fiat */}
|
|
463
|
+
<button
|
|
464
|
+
onClick={handleSelectFiat}
|
|
465
|
+
className="anyspend-deposit-option-button anyspend-deposit-fiat-button border-border-primary hover:border-as-brand hover:bg-as-surface-secondary flex w-full items-center justify-between rounded-xl border p-4 text-left transition-all"
|
|
466
|
+
>
|
|
467
|
+
<div className="anyspend-deposit-option-content flex items-center gap-3">
|
|
468
|
+
<CreditCardIcon className="anyspend-deposit-option-icon h-10 w-10" />
|
|
469
|
+
<div className="anyspend-deposit-option-info">
|
|
470
|
+
<span className="anyspend-deposit-option-title text-as-primary font-medium">Fund with Fiat</span>
|
|
471
|
+
<p className="anyspend-deposit-option-description text-as-secondary text-xs">
|
|
472
|
+
Pay with card or bank transfer
|
|
473
|
+
</p>
|
|
474
|
+
</div>
|
|
475
|
+
</div>
|
|
476
|
+
<ChevronRight className="anyspend-deposit-option-chevron text-as-secondary h-5 w-5" />
|
|
477
|
+
</button>
|
|
478
|
+
</div>
|
|
479
|
+
|
|
480
|
+
{/* Chain-specific warning */}
|
|
481
|
+
<ChainWarningText chainId={destinationChainId} className="mt-2" />
|
|
482
|
+
</div>
|
|
483
|
+
</div>
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// QR Deposit view
|
|
488
|
+
if (step === "qr-deposit") {
|
|
489
|
+
return (
|
|
490
|
+
<QRDeposit
|
|
491
|
+
mode={mode}
|
|
492
|
+
recipientAddress={recipientAddress}
|
|
493
|
+
destinationToken={destinationToken}
|
|
494
|
+
destinationChainId={destinationChainId}
|
|
495
|
+
depositContractConfig={depositContractConfig}
|
|
496
|
+
onBack={handleBack}
|
|
497
|
+
onClose={onClose ?? handleBack}
|
|
498
|
+
/>
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// Check if destination is Hyperliquid
|
|
503
|
+
const isHyperliquidDeposit = destinationChainId === HYPERLIQUID_CHAIN_ID;
|
|
504
|
+
|
|
505
|
+
// Deposit view
|
|
506
|
+
return (
|
|
507
|
+
<div className="anyspend-deposit anyspend-deposit-form relative">
|
|
508
|
+
{/* Back button - only show if we came from chain selection */}
|
|
509
|
+
{shouldShowChainSelection && (
|
|
510
|
+
<button
|
|
511
|
+
onClick={handleBack}
|
|
512
|
+
className="anyspend-deposit-back-button text-as-secondary hover:text-as-primary absolute left-4 top-4 z-10 flex items-center gap-1"
|
|
513
|
+
>
|
|
514
|
+
<svg className="anyspend-deposit-back-icon h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
515
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 19l-7-7 7-7" />
|
|
516
|
+
</svg>
|
|
517
|
+
<span className="anyspend-deposit-back-text text-sm">Back</span>
|
|
518
|
+
</button>
|
|
519
|
+
)}
|
|
520
|
+
|
|
521
|
+
{/* Close button */}
|
|
522
|
+
{onClose && (
|
|
523
|
+
<button
|
|
524
|
+
onClick={onClose}
|
|
525
|
+
className="anyspend-deposit-close-button text-as-secondary hover:text-as-primary absolute right-4 top-4 z-10"
|
|
526
|
+
>
|
|
527
|
+
<svg className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
528
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
|
529
|
+
</svg>
|
|
530
|
+
</button>
|
|
531
|
+
)}
|
|
532
|
+
|
|
533
|
+
<div className={cn("anyspend-deposit-form-content", shouldShowChainSelection && "pt-8")}>
|
|
534
|
+
{isHyperliquidDeposit ? (
|
|
535
|
+
<AnySpend
|
|
536
|
+
loadOrder={loadOrder}
|
|
537
|
+
mode={mode}
|
|
538
|
+
defaultActiveTab={paymentType}
|
|
539
|
+
recipientAddress={recipientAddress}
|
|
540
|
+
sourceChainId={selectedChainId}
|
|
541
|
+
destinationTokenAddress={destinationToken.address}
|
|
542
|
+
destinationTokenChainId={destinationChainId}
|
|
543
|
+
onSuccess={txHash => onSuccess?.(txHash ?? "")}
|
|
544
|
+
onTokenSelect={onTokenSelect}
|
|
545
|
+
customUsdInputValues={customUsdInputValues}
|
|
546
|
+
hideHeader
|
|
547
|
+
hideBottomNavigation
|
|
548
|
+
disableUrlParamManagement
|
|
549
|
+
/>
|
|
550
|
+
) : (
|
|
551
|
+
<AnySpendCustomExactIn
|
|
552
|
+
loadOrder={loadOrder}
|
|
553
|
+
mode={mode}
|
|
554
|
+
recipientAddress={recipientAddress}
|
|
555
|
+
paymentType={paymentType}
|
|
556
|
+
sourceTokenAddress={sourceTokenAddress}
|
|
557
|
+
sourceTokenChainId={selectedChainId}
|
|
558
|
+
destinationToken={destinationToken}
|
|
559
|
+
destinationChainId={destinationChainId}
|
|
560
|
+
orderType={effectiveOrderType}
|
|
561
|
+
minDestinationAmount={minDestinationAmount}
|
|
562
|
+
header={header ?? defaultHeader}
|
|
563
|
+
onSuccess={onSuccess}
|
|
564
|
+
onOpenCustomModal={onOpenCustomModal}
|
|
565
|
+
mainFooter={mainFooter}
|
|
566
|
+
onTokenSelect={onTokenSelect}
|
|
567
|
+
customUsdInputValues={customUsdInputValues}
|
|
568
|
+
preferEoa={preferEoa}
|
|
569
|
+
customExactInConfig={depositContractConfig}
|
|
570
|
+
/>
|
|
571
|
+
)}
|
|
572
|
+
</div>
|
|
573
|
+
|
|
574
|
+
{/* Chain-specific warning */}
|
|
575
|
+
<ChainWarningText chainId={destinationChainId} className="px-4 pb-4" />
|
|
576
|
+
</div>
|
|
577
|
+
);
|
|
578
|
+
}
|