@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.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { JsonRpcProvider } from '@ethersproject/providers';
2
- import { txAtom, useMQ, supportedChainId, sendTxAtom, isTxFailed, getExplorerUrl, openInNewTab, usePoolUnderlyingTokenContract, TxStateType, useMount, decodeLogs, ERC20_ABI, downScale, formatMoney, POOL_NAME, POOL_TYPE, usePoolInfo, useAccountStats, useAuthErrorHandling, checkIsDev, EARejectionError, EARejectMessage, EARejectReason, EAService, useCLFeeManager, useCLPoolAllowance, usePoolContract, timeUtil, doesChainSupportNotifi, getNotifiDappId, getBlockchainConfigFromChain, CreditState, upScale, toBigNumber, TRANSFER_ABI, useFeeManager, combineStyles, isEmpty, useInvoiceNFTContract, useRFPoolAllowance, useParamsSearch, IdentityService, CHAINS, configUtil, usePoolAllowance, useLenderApproved, useLenderPosition, useWithdrawlLockoutInSeconds, usePoolUnderlyingTokenBalance, useLastDepositTime, CreditEventText, useERC2612Permit, ERC2612_ABI, SuperfluidPoolProcessor_ABI, useMultiSendContract, usePoolUnderlyingToken, hasRFActiveLoan, timestampToLL, getWalletAddressAbbr, useFactoring, PoolMap, PoolSubgraphMap, CreditEvent, Provider as Provider$1 } from '@huma-finance/shared';
2
+ import { txAtom, useMQ, supportedChainId, sendTxAtom, isTxFailed, getExplorerUrl, openInNewTab, usePoolUnderlyingTokenContract, TxStateType, useMount, decodeLogs, ERC20_ABI, downScale, formatMoney, POOL_NAME, POOL_TYPE, usePoolInfo, useAccountStats, useAuthErrorHandling, checkIsDev, EARejectionError, EARejectMessage, EARejectReason, EAService, useCLFeeManager, useCLPoolAllowance, usePoolContract, timeUtil, doesChainSupportNotifi, getNotifiDappId, getBlockchainConfigFromChain, CreditState, upScale, toBigNumber, TRANSFER_ABI, useFeeManager, combineStyles, isEmpty, useInvoiceNFTContract, useRFPoolAllowance, useParamsSearch, IdentityService, CHAINS, configUtil, usePoolAllowance, useLenderApproved, useLenderPosition, useWithdrawlLockoutInSeconds, usePoolUnderlyingTokenBalance, useLastDepositTime, usePoolBalance, CreditEventText, useERC2612Permit, ERC2612_ABI, SuperfluidPoolProcessor_ABI, useMultiSendContract, usePoolUnderlyingToken, hasRFActiveLoan, timestampToLL, getWalletAddressAbbr, useFactoring, PoolMap, PoolSubgraphMap, CreditEvent, Provider as Provider$1 } from '@huma-finance/shared';
3
3
  import { useTheme, css, Box, Typography, Tooltip, Button, Dialog, Slider, Input, Divider, InputAdornment, Snackbar, Alert, Skeleton, TablePagination, LinearProgress, createTheme, ThemeProvider } from '@mui/material';
4
4
  import { useAtom, Provider as Provider$2 } from 'jotai';
5
5
  import { useSelector, useDispatch, Provider } from 'react-redux';
@@ -4760,6 +4760,7 @@ function CheckWithdrawable(_ref) {
4760
4760
 
4761
4761
  function ChooseAmount$1(_ref) {
4762
4762
  var lenderPosition = _ref.lenderPosition,
4763
+ poolBalance = _ref.poolBalance,
4763
4764
  poolInfo = _ref.poolInfo;
4764
4765
  var dispatch = useAppDispatch();
4765
4766
  var poolUnderlyingToken = poolInfo.poolUnderlyingToken;
@@ -4769,7 +4770,9 @@ function ChooseAmount$1(_ref) {
4769
4770
  _useState2 = _slicedToArray(_useState, 2),
4770
4771
  currentAmount = _useState2[0],
4771
4772
  setCurrentAmount = _useState2[1];
4772
- var withdrawableAmount = downScale(lenderPosition, decimals);
4773
+ // Take the minimum of the pool balance or the lender position
4774
+ var withdrawableAmountBN = lenderPosition.lt(poolBalance) ? lenderPosition : poolBalance;
4775
+ var withdrawableAmount = downScale(withdrawableAmountBN, decimals);
4773
4776
  var handleChangeAmount = useCallback(function (newAmount) {
4774
4777
  setCurrentAmount(newAmount);
4775
4778
  dispatch(setWithdrawAmount(newAmount));
@@ -4865,17 +4868,22 @@ function LendWithdraw(_ref) {
4865
4868
  _useLenderPosition2 = _slicedToArray(_useLenderPosition, 2),
4866
4869
  lenderPosition = _useLenderPosition2[0],
4867
4870
  refreshLenderPosition = _useLenderPosition2[1];
4871
+ var _usePoolBalance = usePoolBalance(poolName, poolType),
4872
+ _usePoolBalance2 = _slicedToArray(_usePoolBalance, 2),
4873
+ poolBalance = _usePoolBalance2[0],
4874
+ refreshPoolBalance = _usePoolBalance2[1];
4868
4875
  useEffect(function () {
4869
- if (!step && lenderPosition) {
4876
+ if (!step && lenderPosition && poolBalance) {
4870
4877
  dispatch(setStep(WIDGET_STEP.CheckWithdrawable));
4871
4878
  }
4872
- }, [dispatch, lenderPosition, step]);
4879
+ }, [dispatch, lenderPosition, poolBalance, step]);
4873
4880
  var handleWithdrawSuccess = useCallback(function (blockNumber) {
4874
4881
  refreshLenderPosition();
4882
+ refreshPoolBalance();
4875
4883
  if (handleSuccess) {
4876
4884
  handleSuccess(blockNumber);
4877
4885
  }
4878
- }, [handleSuccess, refreshLenderPosition]);
4886
+ }, [handleSuccess, refreshLenderPosition, refreshPoolBalance]);
4879
4887
  if (!poolInfo) {
4880
4888
  return null;
4881
4889
  }
@@ -4888,7 +4896,8 @@ function LendWithdraw(_ref) {
4888
4896
  handleClose: handleClose
4889
4897
  }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$1, {
4890
4898
  poolInfo: poolInfo,
4891
- lenderPosition: lenderPosition
4899
+ lenderPosition: lenderPosition,
4900
+ poolBalance: poolBalance
4892
4901
  }), step === WIDGET_STEP.Transfer && jsx(Transfer$1, {
4893
4902
  poolInfo: poolInfo
4894
4903
  }), step === WIDGET_STEP.Done && jsx(Success$1, {