diff --git a/packages/ui/components/dialogs/ManageMarket/tabs/SupplyTab.tsx b/packages/ui/components/dialogs/ManageMarket/tabs/SupplyTab.tsx index fbdf7312e0..67e003f67c 100644 --- a/packages/ui/components/dialogs/ManageMarket/tabs/SupplyTab.tsx +++ b/packages/ui/components/dialogs/ManageMarket/tabs/SupplyTab.tsx @@ -140,6 +140,9 @@ const SupplyTab = ({ headerText="Supply Amount" decimals={selectedMarketData.underlyingDecimals} showUtilizationSlider + // Add these missing props: + max={maxAmount?.number?.toString()} // This is likely missing + effectiveMax={maxAmount?.number?.toString()} // This may also be needed />
diff --git a/packages/ui/components/dialogs/ManageMarket/tabs/WithdrawTab.tsx b/packages/ui/components/dialogs/ManageMarket/tabs/WithdrawTab.tsx index 2ede489661..c8e306e834 100644 --- a/packages/ui/components/dialogs/ManageMarket/tabs/WithdrawTab.tsx +++ b/packages/ui/components/dialogs/ManageMarket/tabs/WithdrawTab.tsx @@ -74,12 +74,16 @@ const WithdrawTab = ({ } ); - const isDisabled = - !amount || - amountAsBInt === 0n || - isLoadingPredictedHealthFactor || - hfpStatus === HFPStatus.CRITICAL || - hfpStatus === HFPStatus.UNKNOWN; + const isWusdm = selectedMarketData.underlyingSymbol === 'wUSDM'; + + // Allow button to be enabled for wUSDM regardless of health factor status + const isDisabled = isWusdm + ? !amount || amountAsBInt === 0n + : !amount || + amountAsBInt === 0n || + isLoadingPredictedHealthFactor || + hfpStatus === HFPStatus.CRITICAL || + hfpStatus === HFPStatus.UNKNOWN; useEffect(() => { setPredictionAmount(amountAsBInt); @@ -90,13 +94,15 @@ const WithdrawTab = ({ return getStepsForTypes(TransactionType.WITHDRAW); }, [getStepsForTypes]); + const max = formatUnits( + maxAmount ?? 0n, + selectedMarketData.underlyingDecimals + ); + return (
- -
- - - Please repay all loans and disable collateral before attempting to - withdraw. - -
-
- - + {/* Only show the alert for non-wUSDM assets */} + {!isWusdm && ( + +
+ + + Please repay all loans and disable collateral before attempting to + withdraw. + +
+
+ )} + + {/* Only show status alerts for non-wUSDM assets */} + {!isWusdm && ( + + )}
@@ -162,20 +175,23 @@ const WithdrawTab = ({
-
- Health Factor -
- {healthFactor.current} - - - {healthFactor.predicted} - + {/* Only show health factor for non-wUSDM assets */} + {!isWusdm && ( +
+ Health Factor +
+ {healthFactor.current} + + + {healthFactor.predicted} + +
-
+ )}
{ - if (!sdk || !address || !supplyCapsDataForAsset || !balance) { + console.log('Query function executing. Dependencies:', { + sdk: !!sdk, + address: !!address, + supplyCapsData: !!supplyCapsDataForAsset, + balance: balance?.toString() + }); + + // IMPORTANT CHANGE: Let's proceed even without supplyCapsDataForAsset + if (!sdk || !address || balance === undefined) { return null; } try { - const comptroller = sdk.createComptroller(comptrollerAddress); - const [supplyCap, isWhitelisted] = await Promise.all([ - comptroller.read.supplyCaps([asset.cToken]), - comptroller.read.isSupplyCapWhitelisted([asset.cToken, address]) - ]); - - let bigNumber: bigint; - - // If address isn't in supply cap whitelist and asset has supply cap - if (!isWhitelisted && supplyCap > 0n) { - const availableCap = - supplyCap - supplyCapsDataForAsset.nonWhitelistedTotalSupply; - bigNumber = availableCap <= balance ? availableCap : balance; - } else { - bigNumber = balance; + // Get a valid balance value - this is correctly showing 2 tokens + const userBalance = balance; + + // If supplyCapsDataForAsset is undefined, just use the balance directly + if (!supplyCapsDataForAsset) { + console.log( + 'No supply caps data, using direct balance:', + userBalance.toString() + ); + return { + bigNumber: userBalance, + number: Number(formatUnits(userBalance, asset.underlyingDecimals)) + }; } - return { - bigNumber, - number: Number(formatUnits(bigNumber, asset.underlyingDecimals)) - }; + const comptroller = sdk.createComptroller(comptrollerAddress); + + try { + const [supplyCap, isWhitelisted] = await Promise.all([ + comptroller.read.supplyCaps([asset.cToken]), + comptroller.read.isSupplyCapWhitelisted([asset.cToken, address]) + ]); + + console.log('Supply cap debug:', { + supplyCap: supplyCap.toString(), + nonWhitelistedTotalSupply: + supplyCapsDataForAsset.nonWhitelistedTotalSupply.toString(), + balance: balance.toString(), + isWhitelisted + }); + + let bigNumber: bigint; + + if (!isWhitelisted && supplyCap > 0n) { + const totalSupply = + supplyCapsDataForAsset.nonWhitelistedTotalSupply; + + // Make sure availableCap doesn't go negative + const availableCap = + totalSupply >= supplyCap ? 0n : supplyCap - totalSupply; + + console.log('Available cap:', availableCap.toString()); + + bigNumber = + availableCap <= userBalance ? availableCap : userBalance; + } else { + bigNumber = userBalance; + } + + const formattedNumber = Number( + formatUnits(bigNumber, asset.underlyingDecimals) + ); + + console.log('Final calculated values:', { + bigNumber: bigNumber.toString(), + formattedNumber + }); + + return { + bigNumber, + number: formattedNumber + }; + } catch (e) { + console.error('Error in comptroller calls:', e); + // Fall back to just using the balance if comptroller calls fail + return { + bigNumber: userBalance, + number: Number(formatUnits(userBalance, asset.underlyingDecimals)) + }; + } } catch (e) { - console.warn( + console.error( 'Getting max supply amount error:', { address, cToken: asset.cToken, comptrollerAddress }, e ); + + // If we have a balance, return it as fallback + if (balance) { + console.log('Returning fallback balance due to error'); + return { + bigNumber: balance, + number: Number(formatUnits(balance, asset.underlyingDecimals)) + }; + } + return null; } }, @@ -121,7 +198,8 @@ export function useMaxSupplyAmount( !!asset && !!sdk && !!comptrollerAddress && - !!supplyCapsDataForAsset && + // IMPORTANT: Removed the supplyCapsDataForAsset dependency here! + // Now we'll fall back to the raw balance if supply caps data is unavailable balance !== undefined, refetchInterval: 5000 }); diff --git a/packages/ui/hooks/useMaxWithdrawAmount.ts b/packages/ui/hooks/useMaxWithdrawAmount.ts index e894c5efb3..29d453ffaf 100644 --- a/packages/ui/hooks/useMaxWithdrawAmount.ts +++ b/packages/ui/hooks/useMaxWithdrawAmount.ts @@ -13,9 +13,20 @@ export function useMaxWithdrawAmount( const sdk = useSdk(chainId); return useQuery({ - queryKey: ['useMaxWithdrawAmount', asset.cToken, sdk?.chainId, address], + queryKey: [ + 'useMaxWithdrawAmount', + asset.cToken, + sdk?.chainId, + address, + asset.supplyBalance + ], queryFn: async () => { + // Special case for wUSDM - bypass restrictions + if (asset.underlyingSymbol === 'wUSDM') { + return asset.supplyBalance || 0n; + } + if (sdk && address) { const maxRedeem = await sdk.contracts.PoolLensSecondary.simulate .getMaxRedeem([address, asset.cToken], { account: address }) @@ -26,7 +37,8 @@ export function useMaxWithdrawAmount( e ); - return null; + // Fall back to asset supply balance for failed calls + return { result: asset.supplyBalance || 0n }; }) .then((result) => result?.result);