@huma-finance/widgets 0.0.61-beta.551 → 0.0.61-beta.552

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
@@ -6081,14 +6081,24 @@ function ChooseAmount$4(_ref) {
6081
6081
  const step = currentAmountBN.gt(allowance) ? WIDGET_STEP.ApproveAllowance : WIDGET_STEP.Transfer;
6082
6082
  dispatch(setStep(step));
6083
6083
  };
6084
- const getAvailable = () => {
6085
- const trancheCap = selectedTranche === 'junior' ? juniorAvailableCapBN : seniorAvailableCapBN;
6084
+ const getTrancheCap = () => {
6085
+ if (selectedTranche === 'junior') {
6086
+ return juniorAvailableCapBN;
6087
+ }
6088
+ return seniorAvailableCapBN;
6089
+ };
6090
+ const getMaxAmount = () => {
6091
+ const trancheCap = getTrancheCap();
6086
6092
  return balance.gt(trancheCap) ? trancheCap : balance;
6087
6093
  };
6088
6094
  const getInfos = () => {
6089
- const available = getAvailable();
6090
- const infos = ["".concat(formatNumber(ethers.utils.formatUnits(available, decimals)), " remaining capacity")];
6091
- return infos;
6095
+ const trancheCap = getTrancheCap();
6096
+ const currentAmountBN = ethers.utils.parseUnits(String(currentAmount), decimals);
6097
+ const remainingCap = trancheCap.sub(currentAmountBN);
6098
+ if (remainingCap.lt(0)) {
6099
+ return ['0 remaining capacity'];
6100
+ }
6101
+ return ["".concat(formatNumber(ethers.utils.formatUnits(remainingCap, decimals)), " remaining capacity")];
6092
6102
  };
6093
6103
  return jsx(InputAmountModal, {
6094
6104
  title: "Enter Amount",
@@ -6096,7 +6106,7 @@ function ChooseAmount$4(_ref) {
6096
6106
  tokenSymbol: symbol,
6097
6107
  currentAmount: currentAmount,
6098
6108
  handleChangeAmount: handleChangeAmount,
6099
- maxAmount: Number(ethers.utils.formatUnits(getAvailable(), decimals)),
6109
+ maxAmount: Number(ethers.utils.formatUnits(getMaxAmount(), decimals)),
6100
6110
  maxAmountTitle: "".concat(formatNumber(ethers.utils.formatUnits(balance, decimals)), " balance"),
6101
6111
  infos: getInfos(),
6102
6112
  handleAction: handleAction,