11import React , { useEffect , useState } from "react" ;
22import { Activity , ShieldCheck , TrendingUp , Wallet as WalletIcon , AlertTriangle , Info } from "./icons" ;
3- import { useState , useEffect } from "react" ;
4- import { Activity , ShieldCheck , TrendingUp , Wallet as WalletIcon , Loader2 } from "./icons" ;
5- import { hasCustomRpcConfig , networkConfig } from "../config/network" ;
63import { useVault } from "../context/VaultContext" ;
74import ApiStatusBanner from "./ApiStatusBanner" ;
85import VaultPerformanceChart from "./VaultPerformanceChart" ;
@@ -11,9 +8,6 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "./Tabs";
118import { FormField , SubmitButton } from "../forms" ;
129import CopyButton from "./CopyButton" ;
1310import { useDepositMutation , useWithdrawMutation } from "../hooks/useVaultMutations" ;
14- import TransactionStatus , { type ActionStatus } from "./TransactionStatus" ;
15- import { useDepositMutation , useWithdrawMutation } from "../hooks/useVaultMutations" ;
16- import CopyButton from "./CopyButton" ;
1711
1812interface VaultDashboardProps {
1913 walletAddress : string | null ;
@@ -51,23 +45,20 @@ const VaultCapWarning: React.FC<{ utilization: number; isReached: boolean }> = (
5145 ) ;
5246} ;
5347
54- function buildFakeTxHash ( walletAddress : string , action : "deposit" | "withdraw" , amount : number ) : string {
55- const seed = `${ walletAddress } -${ action } -${ amount . toFixed ( 2 ) } -${ Date . now ( ) } ` ;
56- let hash = "" ;
57- for ( let i = 0 ; i < 64 ; i += 1 ) {
58- const code = seed . charCodeAt ( i % seed . length ) ;
59- hash += ( ( code + i * 13 ) % 16 ) . toString ( 16 ) ;
60- }
61- return hash ;
62- }
63-
64- const STATUS_VISIBLE_MS = 12000 ;
65-
6648const VaultDashboard : React . FC < VaultDashboardProps > = ( {
6749 walletAddress,
6850 usdcBalance = 0 ,
6951} ) => {
70- const { formattedTvl, formattedApy, summary, error, isLoading } = useVault ( ) ;
52+ const {
53+ formattedTvl,
54+ formattedApy,
55+ summary,
56+ error,
57+ isLoading,
58+ utilization,
59+ isCapWarning,
60+ isCapReached,
61+ } = useVault ( ) ;
7162 const toast = useToast ( ) ;
7263 const [ activeTab , setActiveTab ] = useState < "deposit" | "withdraw" > ( "deposit" ) ;
7364 const [ amount , setAmount ] = useState ( "" ) ;
@@ -87,11 +78,7 @@ const VaultDashboard: React.FC<VaultDashboardProps> = ({
8778 return ( ) => window . removeEventListener ( 'TRIGGER_DEPOSIT' , handleTrigger ) ;
8879 } , [ ] ) ;
8980
90- const isProcessing = depositMutation . isPending
91- ? "deposit"
92- : withdrawMutation . isPending
93- ? "withdraw"
94- : null ;
81+ const isBusy = depositMutation . isPending || withdrawMutation . isPending ;
9582
9683 const availableBalance = walletAddress ? usdcBalance : 0 ;
9784 const strategy = summary . strategy ;
@@ -302,67 +289,38 @@ const VaultDashboard: React.FC<VaultDashboardProps> = ({
302289 onClick = { ( ) => setAmount ( availableBalance . toFixed ( 2 ) ) }
303290 disabled = { ! walletAddress || availableBalance <= 0 || isBusy || ( tab === "deposit" && isCapReached ) }
304291 >
305- < div style = { { marginBottom : "24px" } } >
306- < div className = "flex justify-between items-center" style = { { marginBottom : "16px" } } >
307- < div style = { { color : "var(--text-secondary)" , fontSize : "0.9rem" } } >
308- { tab === "deposit" ? "Amount to deposit" : "Amount to withdraw" }
309- </ div >
310- < div style = { { color : "var(--text-secondary)" , fontSize : "0.85rem" } } >
311- Balance: < span style = { { color : "var(--text-primary)" , fontWeight : 600 } } > { availableBalance . toFixed ( 2 ) } </ span >
312- </ div >
313- </ div >
314-
315- < div className = "input-group" >
316- < div className = "input-wrapper" >
317- < span style = { { color : "var(--text-secondary)" , paddingRight : "12px" , borderRight : "1px solid var(--border-glass)" , marginRight : "16px" } } > USDC</ span >
318- < input className = "input-field" type = "number" placeholder = "0.00" value = { amount } onChange = { ( e ) => setAmount ( e . target . value ) } disabled = { isProcessing !== null } />
319- < button className = "btn-max" onClick = { ( ) => setAmount ( availableBalance . toFixed ( 2 ) ) } disabled = { ! walletAddress || availableBalance <= 0 || isProcessing !== null } >
320292 MAX
321293 </ button >
322294 </ div >
323- </ div >
324295
325- < SubmitButton
326- loading = { isBusy && activeTab === tab }
327- disabled = { ! walletAddress || isBusy || ! amount || Number ( amount ) <= 0 || ( tab === "deposit" && isCapReached ) }
328- label = { tab === "deposit" ? ( isCapReached ? "Vault is full" : "Approve & Deposit" ) : "Withdraw Funds" }
329- loadingLabel = "Waiting for confirmation..."
330- />
331- </ form >
332- </ div >
296+ < div className = "glass-panel" style = { { padding : "14px 16px" , background : "rgba(0, 0, 0, 0.15)" , marginBottom : "16px" } } >
297+ < div className = "flex justify-between items-center" style = { { marginBottom : "6px" } } >
298+ < span style = { { color : "var(--text-secondary)" , fontSize : "0.86rem" } } > Estimated protocol fee</ span >
299+ < span style = { { fontSize : "0.9rem" , fontWeight : 600 } } >
300+ { isValidAmount ? `${ estimatedFee . toFixed ( 4 ) } USDC` : "0.0000 USDC" }
301+ </ span >
302+ </ div >
303+ < div className = "flex justify-between items-center" >
304+ < span style = { { color : "var(--text-secondary)" , fontSize : "0.82rem" } } >
305+ { tab === "deposit" ? "Estimated net deposit" : "Estimated net withdrawal" }
306+ </ span >
307+ < span style = { { fontSize : "0.9rem" , fontWeight : 600 } } >
308+ { isValidAmount ? `${ estimatedNetAmount . toFixed ( 4 ) } USDC` : "0.0000 USDC" }
309+ </ span >
310+ </ div >
311+ < div style = { { marginTop : "6px" , color : "var(--text-secondary)" , fontSize : "0.75rem" } } >
312+ Network fee: { summary . networkFeeEstimate }
313+ </ div >
314+ </ div >
333315
334- < div className = "glass-panel" style = { { padding : "14px 16px" , background : "rgba(0, 0, 0, 0.15)" , marginBottom : "16px" } } >
335- < div className = "flex justify-between items-center" style = { { marginBottom : "6px" } } >
336- < span style = { { color : "var(--text-secondary)" , fontSize : "0.86rem" } } > Estimated protocol fee</ span >
337- < span style = { { fontSize : "0.9rem" , fontWeight : 600 } } >
338- { isValidAmount ? `${ estimatedFee . toFixed ( 4 ) } USDC` : "0.0000 USDC" }
339- </ span >
340- </ div >
341- < div className = "flex justify-between items-center" >
342- < span style = { { color : "var(--text-secondary)" , fontSize : "0.82rem" } } >
343- { tab === "deposit" ? "Estimated net deposit" : "Estimated net withdrawal" }
344- </ span >
345- < span style = { { fontSize : "0.9rem" , fontWeight : 600 } } >
346- { isValidAmount ? `${ estimatedNetAmount . toFixed ( 4 ) } USDC` : "0.0000 USDC" }
347- </ span >
348- </ div >
349- < div style = { { marginTop : "6px" , color : "var(--text-secondary)" , fontSize : "0.75rem" } } >
350- Network fee: { summary . networkFeeEstimate }
316+ < SubmitButton
317+ loading = { isBusy && activeTab === tab }
318+ disabled = { ! walletAddress || isBusy || ! amount || Number ( amount ) <= 0 || ( tab === "deposit" && isCapReached ) }
319+ label = { tab === "deposit" ? ( isCapReached ? "Vault is full" : "Approve & Deposit" ) : "Withdraw Funds" }
320+ loadingLabel = "Processing Transaction..."
321+ />
351322 </ div >
352- </ div >
353-
354- < button className = "btn btn-primary" style = { { width : "100%" , padding : "16px" } } onClick = { ( ) => handleTransaction ( tab ) } disabled = { isProcessing !== null || ! amount || Number ( amount ) <= 0 } >
355- { isProcessing === tab ? "Processing Transaction..." : tab === "deposit" ? "Approve & Deposit" : "Withdraw Funds" }
356- < button className = "btn btn-primary" style = { { width : "100%" , padding : "16px" , display : "flex" , alignItems : "center" , justifyContent : "center" , gap : "8px" } } onClick = { ( ) => handleTransaction ( tab ) } disabled = { isProcessing !== null || ! amount || Number ( amount ) <= 0 } >
357- { isProcessing === tab ? (
358- < >
359- < Loader2 size = { 16 } className = "spin" style = { { animation : "spin 0.9s linear infinite" } } />
360- Processing Transaction...
361- </ >
362- ) : (
363- tab === "deposit" ? "Approve & Deposit" : "Withdraw Funds"
364- ) }
365- </ button >
323+ </ form >
366324 </ TabsContent >
367325 ) ) }
368326 </ Tabs >
0 commit comments