@huma-finance/widgets 0.0.48-beta.186 → 0.0.48-beta.188

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.
@@ -4799,6 +4799,7 @@ function CheckWithdrawable(_ref) {
4799
4799
 
4800
4800
  function ChooseAmount$1(_ref) {
4801
4801
  var lenderPosition = _ref.lenderPosition,
4802
+ poolBalance = _ref.poolBalance,
4802
4803
  poolInfo = _ref.poolInfo;
4803
4804
  var dispatch = useAppDispatch();
4804
4805
  var poolUnderlyingToken = poolInfo.poolUnderlyingToken;
@@ -4808,7 +4809,9 @@ function ChooseAmount$1(_ref) {
4808
4809
  _useState2 = _slicedToArray(_useState, 2),
4809
4810
  currentAmount = _useState2[0],
4810
4811
  setCurrentAmount = _useState2[1];
4811
- var withdrawableAmount = shared.downScale(lenderPosition, decimals);
4812
+ // Take the minimum of the pool balance or the lender position
4813
+ var withdrawableAmountBN = lenderPosition.lt(poolBalance) ? lenderPosition : poolBalance;
4814
+ var withdrawableAmount = shared.downScale(withdrawableAmountBN, decimals);
4812
4815
  var handleChangeAmount = React.useCallback(function (newAmount) {
4813
4816
  setCurrentAmount(newAmount);
4814
4817
  dispatch(setWithdrawAmount(newAmount));
@@ -4904,17 +4907,22 @@ function LendWithdraw(_ref) {
4904
4907
  _useLenderPosition2 = _slicedToArray(_useLenderPosition, 2),
4905
4908
  lenderPosition = _useLenderPosition2[0],
4906
4909
  refreshLenderPosition = _useLenderPosition2[1];
4910
+ var _usePoolBalance = shared.usePoolBalance(poolName, poolType),
4911
+ _usePoolBalance2 = _slicedToArray(_usePoolBalance, 2),
4912
+ poolBalance = _usePoolBalance2[0],
4913
+ refreshPoolBalance = _usePoolBalance2[1];
4907
4914
  React.useEffect(function () {
4908
- if (!step && lenderPosition) {
4915
+ if (!step && lenderPosition && poolBalance) {
4909
4916
  dispatch(setStep(WIDGET_STEP.CheckWithdrawable));
4910
4917
  }
4911
- }, [dispatch, lenderPosition, step]);
4918
+ }, [dispatch, lenderPosition, poolBalance, step]);
4912
4919
  var handleWithdrawSuccess = React.useCallback(function (blockNumber) {
4913
4920
  refreshLenderPosition();
4921
+ refreshPoolBalance();
4914
4922
  if (handleSuccess) {
4915
4923
  handleSuccess(blockNumber);
4916
4924
  }
4917
- }, [handleSuccess, refreshLenderPosition]);
4925
+ }, [handleSuccess, refreshLenderPosition, refreshPoolBalance]);
4918
4926
  if (!poolInfo) {
4919
4927
  return null;
4920
4928
  }
@@ -4927,7 +4935,8 @@ function LendWithdraw(_ref) {
4927
4935
  handleClose: handleClose
4928
4936
  }), step === WIDGET_STEP.ChooseAmount && jsxRuntime.jsx(ChooseAmount$1, {
4929
4937
  poolInfo: poolInfo,
4930
- lenderPosition: lenderPosition
4938
+ lenderPosition: lenderPosition,
4939
+ poolBalance: poolBalance
4931
4940
  }), step === WIDGET_STEP.Transfer && jsxRuntime.jsx(Transfer$1, {
4932
4941
  poolInfo: poolInfo
4933
4942
  }), step === WIDGET_STEP.Done && jsxRuntime.jsx(Success$1, {