diff --git a/src/components/actions/ActionHandler.tsx b/src/components/actions/ActionHandler.tsx index e7b7830..e928333 100644 --- a/src/components/actions/ActionHandler.tsx +++ b/src/components/actions/ActionHandler.tsx @@ -259,7 +259,7 @@ export default function ActionHandler({ actionType, tokenType }: ActionHandlerPr if (isMaxSelected && (actionType === 'redeem' || actionType === 'withdraw')) { const maxBeforeTx = await refetchMaxBeforeTx(); - if (!maxBeforeTx) { + if (maxBeforeTx === undefined) { setError('Error refetching max amount before tx.'); console.error('Error refetching max amount before tx.'); return; diff --git a/src/components/actions/SafeActionHandler.tsx b/src/components/actions/SafeActionHandler.tsx index 4e54de9..606361a 100644 --- a/src/components/actions/SafeActionHandler.tsx +++ b/src/components/actions/SafeActionHandler.tsx @@ -386,7 +386,7 @@ export default function SafeActionHandler({ actionType, tokenType }: SafeActionH if (isMaxSelected && (actionType === 'redeem' || actionType === 'withdraw')) { const maxBeforeTx = await refetchMaxBeforeTx(); - if (!maxBeforeTx) { + if (maxBeforeTx === undefined) { setError('Error refetching max amount before tx.'); console.error('Error refetching max amount before tx.'); setLoading(false); @@ -464,4 +464,3 @@ export default function SafeActionHandler({ actionType, tokenType }: SafeActionH /> ); } - diff --git a/src/components/vault/Auction.tsx b/src/components/vault/Auction.tsx index c406a72..d379b44 100644 --- a/src/components/vault/Auction.tsx +++ b/src/components/vault/Auction.tsx @@ -132,7 +132,7 @@ export default function Auction() { // Calculate auction progress const calculateAuctionProgress = () => { - if (!auctionStartBlock || !currentBlock || !auctionDuration || auctionStartBlock === 0n) { + if (auctionStartBlock === null || !currentBlock || !auctionDuration || auctionStartBlock === 0n) { return { progress: 0, currentStep: 0, isComplete: false }; } @@ -208,8 +208,8 @@ export default function Auction() {
Auction Started: - {auctionStartBlock && auctionStartBlock > 0n ? ( - auctionStartTimestamp ? + {auctionStartBlock !== null && auctionStartBlock > 0n ? ( + auctionStartTimestamp !== null ? new Date(auctionStartTimestamp * 1000).toLocaleString() : `Block ${auctionStartBlock.toString()}` ) : 'Not Started'} @@ -225,7 +225,7 @@ export default function Auction() {
{/* Auction Progress Bar */} - {auctionStartBlock && auctionStartBlock > 0n && auctionDuration && ( + {auctionStartBlock !== null && auctionStartBlock > 0n && auctionDuration && (
Auction Progress: diff --git a/src/components/vault/AuctionHandler.tsx b/src/components/vault/AuctionHandler.tsx index afb76e0..d598734 100644 --- a/src/components/vault/AuctionHandler.tsx +++ b/src/components/vault/AuctionHandler.tsx @@ -27,7 +27,7 @@ export default function AuctionHandler({ futureBorrowAssets, futureCollateralAss const receive: { amount: bigint; tokenType: 'borrow' | 'collateral' }[] = []; const provide: { amount: bigint; tokenType: 'borrow' | 'collateral' }[] = []; - if (!amount || !previewData) { + if ((amount === null || amount === 0n) || !previewData) { return { receive, provide }; } @@ -183,7 +183,7 @@ export default function AuctionHandler({ futureBorrowAssets, futureCollateralAss }, [amount, auctionType]); const checkAndApproveRequiredAssets = async () => { - if (!address || !vaultAddress || !amount) { + if (!address || !vaultAddress || amount === null || amount === 0n) { return; } diff --git a/src/components/vault/FlashLoanDepositWithdrawHandler.tsx b/src/components/vault/FlashLoanDepositWithdrawHandler.tsx index 15fbe68..ea99708 100644 --- a/src/components/vault/FlashLoanDepositWithdrawHandler.tsx +++ b/src/components/vault/FlashLoanDepositWithdrawHandler.tsx @@ -268,7 +268,7 @@ export default function FlashLoanDepositWithdrawHandler({ actionType }: FlashLoa vaultLens }) - if (!shares) return; + if (!shares) return; // Here we need return if 0 and if undefined shares = applyFlashLoanDepositWithdrawSlippage(shares); setEstimatedShares(shares); @@ -328,7 +328,7 @@ export default function FlashLoanDepositWithdrawHandler({ actionType }: FlashLoa useEffect(() => { // Reset state if input is empty or invalid - if (!estimatedShares || estimatedShares <= 0n) { + if (estimatedShares === null || estimatedShares <= 0n) { setPreviewedWstEthAmount(null); setEthToWrapValue(''); setHasInsufficientBalance(false); @@ -337,7 +337,7 @@ export default function FlashLoanDepositWithdrawHandler({ actionType }: FlashLoa }, [estimatedShares]); useEffect(() => { - if (!estimatedShares || estimatedShares <= 0n) { + if (estimatedShares === null || estimatedShares <= 0n) { return; } @@ -458,7 +458,7 @@ export default function FlashLoanDepositWithdrawHandler({ actionType }: FlashLoa const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); - if (!helper || !address || !estimatedShares || estimatedShares <= 0n) return; + if (!helper || !address || estimatedShares === null || estimatedShares <= 0n) return; setLoading(true); setError(null); @@ -659,7 +659,7 @@ export default function FlashLoanDepositWithdrawHandler({ actionType }: FlashLoa )} {/* Preview Section */} - {!!estimatedShares && estimatedShares > 0n && previewData && !isErrorLoadingPreview && ( + {estimatedShares !== null && estimatedShares > 0n && previewData && !isErrorLoadingPreview && ( {invalidRebalanceMode @@ -680,7 +680,7 @@ export default function FlashLoanDepositWithdrawHandler({ actionType }: FlashLoa )} {/* Balance warning */} - {hasInsufficientBalance && !!estimatedShares && estimatedShares > 0n && ( + {hasInsufficientBalance && estimatedShares !== null && estimatedShares > 0n && (
Insufficient balance. @@ -692,7 +692,7 @@ export default function FlashLoanDepositWithdrawHandler({ actionType }: FlashLoa type="submit" disabled={ loading || - !estimatedShares || + estimatedShares === null || estimatedShares <= 0n || isApproving || isWrapping || diff --git a/src/components/vault/FlashLoanHelperHandler.tsx b/src/components/vault/FlashLoanHelperHandler.tsx index 8586a0a..5fc0995 100644 --- a/src/components/vault/FlashLoanHelperHandler.tsx +++ b/src/components/vault/FlashLoanHelperHandler.tsx @@ -258,7 +258,7 @@ export default function FlashLoanHelperHandler({ helperType }: FlashLoanHelperHa useEffect(() => { // Reset state if input is empty or invalid - if (!sharesToProcess || sharesToProcess <= 0n) { + if (sharesToProcess === null || sharesToProcess <= 0n) { setPreviewedWstEthAmount(null); setEthToWrapValue(''); setHasInsufficientBalance(false); @@ -387,7 +387,7 @@ export default function FlashLoanHelperHandler({ helperType }: FlashLoanHelperHa const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); - if (!helper || !address || !sharesToProcess || sharesToProcess <= 0n) return; + if (!helper || !address || sharesToProcess === null || sharesToProcess <= 0n) return; setLoading(true); setError(null); @@ -578,7 +578,7 @@ export default function FlashLoanHelperHandler({ helperType }: FlashLoanHelperHa )} {/* Preview Section */} - {!!sharesToProcess && sharesToProcess > 0n && previewData && !isErrorLoadingPreview && ( + {sharesToProcess !== null && sharesToProcess > 0n && previewData && !isErrorLoadingPreview && (
0n && ( + {hasInsufficientBalance && sharesToProcess !== null && sharesToProcess > 0n && (
parseUnits(maxAmount, sharesDecimals) || isApproving || diff --git a/src/components/vault/Info.tsx b/src/components/vault/Info.tsx index 2948de4..949eb5e 100644 --- a/src/components/vault/Info.tsx +++ b/src/components/vault/Info.tsx @@ -76,7 +76,7 @@ export default function Info() { }, [isMainnet, address, publicProvider]); const pointsRateDisplay = useMemo(() => { - if (!pointsRate) return null; + if (pointsRate === null) return null; // Base rate is what comes from API // If NFT holder: Boosted rate (~42% boost) if (hasNft) { @@ -126,7 +126,7 @@ export default function Info() { // Calculate USD value const usdValue = useMemo(() => { - if (!isMainnet || !tokenPrice || !totalAssets) { + if (!isMainnet || tokenPrice === null || !totalAssets || totalAssets === '0') { return null; } const totalAssetsNum = parseFloat(totalAssets); @@ -138,7 +138,7 @@ export default function Info() { // Calculate TVL USD value const tvlUsdValue = useMemo(() => { - if (!isMainnet || !collateralTokenPrice || !tvl) { + if (!isMainnet || collateralTokenPrice === null || !tvl || tvl === '0') { return null; } const tvlNum = parseFloat(tvl); @@ -176,7 +176,7 @@ export default function Info() { // Calculate position USD value const positionUsdValue = useMemo(() => { - if (!isMainnet || !tokenPrice || !positionInBorrowTokens) { + if (!isMainnet || tokenPrice === null || !positionInBorrowTokens || positionInBorrowTokens === '0') { return null; } const positionNum = parseFloat(positionInBorrowTokens); @@ -234,7 +234,7 @@ export default function Info() {
{positionInBorrowTokens && (
- + {formatUsdValue(positionUsdValue)}
@@ -299,7 +299,7 @@ export default function Info() {
Points rate:
- + {pointsRateDisplay}
@@ -326,7 +326,7 @@ export default function Info() {
{isMainnet && (
- + {formatUsdValue(tvlUsdValue)}
@@ -353,7 +353,7 @@ export default function Info() {
{isMainnet && (
- + {formatUsdValue(usdValue)}
diff --git a/src/components/vault/VaultBlock.tsx b/src/components/vault/VaultBlock.tsx index 175bc40..1342220 100644 --- a/src/components/vault/VaultBlock.tsx +++ b/src/components/vault/VaultBlock.tsx @@ -344,7 +344,7 @@ export default function VaultBlock({ address }: VaultBlockProps) { }, [address, currentNetwork]); const formattedDeposits = useMemo(() => { - if (!dynamicData.deposits) return null; + if (dynamicData.deposits === null) return null; return formatUnits(dynamicData.deposits, vaultDecimals.borrowTokenDecimals); }, [dynamicData.deposits, vaultDecimals.borrowTokenDecimals]); @@ -437,7 +437,7 @@ export default function VaultBlock({ address }: VaultBlockProps) { isLoading={isLoadingPointsRate} isFailedToLoad={pointsRateLoadFailed} > - {pointsRate ? `~${pointsRate} per 1 token / day` : ''} + {pointsRate !== null ? `~${pointsRate} per 1 token / day` : 'No Points'}
diff --git a/src/hooks/useMaxAmountUsd.ts b/src/hooks/useMaxAmountUsd.ts index f961276..78364d4 100644 --- a/src/hooks/useMaxAmountUsd.ts +++ b/src/hooks/useMaxAmountUsd.ts @@ -17,7 +17,7 @@ export function useMaxAmountUsd(options: UseMaxAmountUsdOptions): number | null useEffect(() => { const { maxAmount, tokenPrice, needConvertFromShares, vaultLens, sharesDecimals, borrowTokenDecimals } = options; - const needToSkip = !maxAmount || !tokenPrice || (needConvertFromShares && (!vaultLens || !sharesDecimals || !borrowTokenDecimals)); + const needToSkip = !maxAmount || tokenPrice === null || (needConvertFromShares && (!vaultLens || sharesDecimals === null || borrowTokenDecimals === null)); if (needToSkip) { setMaxAmountUsd(null);