Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/actions/ActionHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/components/actions/SafeActionHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -464,4 +464,3 @@ export default function SafeActionHandler({ actionType, tokenType }: SafeActionH
/>
);
}

8 changes: 4 additions & 4 deletions src/components/vault/Auction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand Down Expand Up @@ -208,8 +208,8 @@ export default function Auction() {
<div className="flex justify-between">
<span className="text-blue-700">Auction Started:</span>
<span className="font-medium text-blue-900">
{auctionStartBlock && auctionStartBlock > 0n ? (
auctionStartTimestamp ?
{auctionStartBlock !== null && auctionStartBlock > 0n ? (
auctionStartTimestamp !== null ?
new Date(auctionStartTimestamp * 1000).toLocaleString() :
`Block ${auctionStartBlock.toString()}`
) : 'Not Started'}
Expand All @@ -225,7 +225,7 @@ export default function Auction() {
</div>

{/* Auction Progress Bar */}
{auctionStartBlock && auctionStartBlock > 0n && auctionDuration && (
{auctionStartBlock !== null && auctionStartBlock > 0n && auctionDuration && (
<div className="mt-3">
<div className="flex justify-between items-center mb-2">
<span className="text-blue-700 text-sm">Auction Progress:</span>
Expand Down
4 changes: 2 additions & 2 deletions src/components/vault/AuctionHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand Down Expand Up @@ -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;
}

Expand Down
16 changes: 8 additions & 8 deletions src/components/vault/FlashLoanDepositWithdrawHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -337,7 +337,7 @@ export default function FlashLoanDepositWithdrawHandler({ actionType }: FlashLoa
}, [estimatedShares]);

useEffect(() => {
if (!estimatedShares || estimatedShares <= 0n) {
if (estimatedShares === null || estimatedShares <= 0n) {
return;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -659,7 +659,7 @@ export default function FlashLoanDepositWithdrawHandler({ actionType }: FlashLoa
)}

{/* Preview Section */}
{!!estimatedShares && estimatedShares > 0n && previewData && !isErrorLoadingPreview && (
{estimatedShares !== null && estimatedShares > 0n && previewData && !isErrorLoadingPreview && (
<PreviewBox
receive={receive}
provide={provide}
Expand All @@ -669,7 +669,7 @@ export default function FlashLoanDepositWithdrawHandler({ actionType }: FlashLoa
)}

{/* Preview Error */}
{!!estimatedShares && (isErrorLoadingPreview || invalidRebalanceMode) && (
{estimatedShares !== null && (isErrorLoadingPreview || invalidRebalanceMode) && (
<div className="p-3 bg-red-50 border border-red-200 rounded-lg text-red-700 text-sm">
<span>
{invalidRebalanceMode
Expand All @@ -680,7 +680,7 @@ export default function FlashLoanDepositWithdrawHandler({ actionType }: FlashLoa
)}

{/* Balance warning */}
{hasInsufficientBalance && !!estimatedShares && estimatedShares > 0n && (
{hasInsufficientBalance && estimatedShares !== null && estimatedShares > 0n && (
<div className="p-3 bg-red-50 border border-red-200 rounded-lg text-red-700 text-sm">
<span>
Insufficient balance.
Expand All @@ -692,7 +692,7 @@ export default function FlashLoanDepositWithdrawHandler({ actionType }: FlashLoa
type="submit"
disabled={
loading ||
!estimatedShares ||
estimatedShares === null ||
estimatedShares <= 0n ||
isApproving ||
isWrapping ||
Expand Down
12 changes: 6 additions & 6 deletions src/components/vault/FlashLoanHelperHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -578,7 +578,7 @@ export default function FlashLoanHelperHandler({ helperType }: FlashLoanHelperHa
)}

{/* Preview Section */}
{!!sharesToProcess && sharesToProcess > 0n && previewData && !isErrorLoadingPreview && (
{sharesToProcess !== null && sharesToProcess > 0n && previewData && !isErrorLoadingPreview && (
<PreviewBox
receive={receive}
provide={provide}
Expand All @@ -588,7 +588,7 @@ export default function FlashLoanHelperHandler({ helperType }: FlashLoanHelperHa
)}

{/* Preview Error */}
{!!sharesToProcess && (isErrorLoadingPreview || invalidRebalanceMode) && (
{sharesToProcess !== null && (isErrorLoadingPreview || invalidRebalanceMode) && (
<div className="p-3 bg-red-50 border border-red-200 rounded-lg text-red-700 text-sm">
<div className="flex items-center space-x-2">
<svg
Expand All @@ -614,7 +614,7 @@ export default function FlashLoanHelperHandler({ helperType }: FlashLoanHelperHa
)}

{/* Balance warning */}
{hasInsufficientBalance && !!sharesToProcess && sharesToProcess > 0n && (
{hasInsufficientBalance && sharesToProcess !== null && sharesToProcess > 0n && (
<div className="p-3 bg-red-50 border border-red-200 rounded-lg text-red-700 text-sm">
<div className="flex items-center space-x-2">
<svg
Expand Down Expand Up @@ -642,7 +642,7 @@ export default function FlashLoanHelperHandler({ helperType }: FlashLoanHelperHa
type="submit"
disabled={
loading ||
!sharesToProcess ||
sharesToProcess === null ||
sharesToProcess <= 0n ||
sharesToProcess > parseUnits(maxAmount, sharesDecimals) ||
isApproving ||
Expand Down
16 changes: 8 additions & 8 deletions src/components/vault/Info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -234,7 +234,7 @@ export default function Info() {
</div>
{positionInBorrowTokens && (
<div className="text-gray-700 text-xs mt-0.5">
<TransitionLoader isLoading={!tokenPrice}>
<TransitionLoader isLoading={tokenPrice === null}>
{formatUsdValue(positionUsdValue)}
</TransitionLoader>
</div>
Expand Down Expand Up @@ -299,7 +299,7 @@ export default function Info() {
<div className="w-full flex justify-between items-start text-sm mb-2">
<div className="font-medium text-gray-700">Points rate:</div>
<div className="min-w-[60px] text-right">
<TransitionLoader isLoading={!pointsRate}>
<TransitionLoader isLoading={pointsRate === null}>
{pointsRateDisplay}
</TransitionLoader>
</div>
Expand All @@ -326,7 +326,7 @@ export default function Info() {
</div>
{isMainnet && (
<div className="text-gray-700 text-xs mt-0.5">
<TransitionLoader isLoading={!collateralTokenPrice}>
<TransitionLoader isLoading={collateralTokenPrice === null}>
{formatUsdValue(tvlUsdValue)}
</TransitionLoader>
</div>
Expand All @@ -353,7 +353,7 @@ export default function Info() {
</div>
{isMainnet && (
<div className="text-gray-700 text-xs mt-0.5">
<TransitionLoader isLoading={!tokenPrice}>
<TransitionLoader isLoading={tokenPrice === null}>
{formatUsdValue(usdValue)}
</TransitionLoader>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/vault/VaultBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down Expand Up @@ -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'}
</TransitionLoader>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useMaxAmountUsd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down