@huma-finance/widgets 0.0.51-beta.346 → 0.0.51-beta.347

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.
@@ -4409,6 +4409,7 @@ function ChooseTranche$1(_ref) {
4409
4409
 
4410
4410
  function ChooseAmount$6(_ref) {
4411
4411
  let {
4412
+ poolInfo,
4412
4413
  poolUnderlyingToken,
4413
4414
  trancheInfo
4414
4415
  } = _ref;
@@ -4416,10 +4417,29 @@ function ChooseAmount$6(_ref) {
4416
4417
  const {
4417
4418
  symbol
4418
4419
  } = poolUnderlyingToken;
4420
+ const {
4421
+ account,
4422
+ provider
4423
+ } = core.useWeb3React();
4419
4424
  const [currentAmount, setCurrentAmount] = React.useState(0);
4420
4425
  const [currentShares, setCurrentShares] = React.useState(0);
4421
4426
  const maxSharesFormatted = ethers.ethers.utils.formatUnits(trancheInfo.shares, poolUnderlyingToken.decimals);
4422
4427
  const sharePrice = trancheInfo.assets.toNumber() / trancheInfo.shares.toNumber();
4428
+ const [depositRecord] = shared.useLenderDepositRecordV2(poolInfo.poolName, trancheInfo.tranche, account, provider);
4429
+ const lpConfig = shared.useLPConfigV2(poolInfo.poolName, provider);
4430
+ const nextEpochStartTime = shared.useNextEpochStartTimeV2(poolInfo.poolName, provider);
4431
+ React.useEffect(() => {
4432
+ if (depositRecord && lpConfig && nextEpochStartTime) {
4433
+ const SECONDS_IN_A_DAY = 24 * 60 * 60;
4434
+ if (nextEpochStartTime < depositRecord.lastDepositTime.toNumber() + lpConfig.withdrawalLockoutPeriodInDays * SECONDS_IN_A_DAY) {
4435
+ dispatch(setStep(WIDGET_STEP.Error));
4436
+ dispatch(setError({
4437
+ errorReason: 'Redemption too soon',
4438
+ errorMessage: "Your last deposit was on ".concat(shared.timestampToLL(depositRecord.lastDepositTime.toNumber()), ". Depositors need to wait ").concat(lpConfig.withdrawalLockoutPeriodInDays, " days before redemption")
4439
+ }));
4440
+ }
4441
+ }
4442
+ }, [depositRecord, dispatch, lpConfig, nextEpochStartTime]);
4423
4443
  const handleChangeShares = newShares => {
4424
4444
  const amount = Number(newShares) * sharePrice;
4425
4445
  setCurrentShares(Number(newShares));
@@ -4430,6 +4450,11 @@ function ChooseAmount$6(_ref) {
4430
4450
  const handleAction = () => {
4431
4451
  dispatch(setStep(WIDGET_STEP.Transfer));
4432
4452
  };
4453
+ if (!depositRecord || !lpConfig || !nextEpochStartTime) {
4454
+ return jsxRuntime.jsx(LoadingModal, {
4455
+ title: "Redemption"
4456
+ });
4457
+ }
4433
4458
  return jsxRuntime.jsx(InputAmountModal, {
4434
4459
  title: "Redemption",
4435
4460
  subTitle: "Enter number of shares to redeem from ".concat(trancheInfo.tranche, " tranche"),
@@ -4586,6 +4611,7 @@ function AddRedemptionV2(_ref) {
4586
4611
  selectedTranche: trancheInfo === null || trancheInfo === void 0 ? void 0 : trancheInfo.tranche,
4587
4612
  changeTranche: handleChangeTranche
4588
4613
  }), step === WIDGET_STEP.ChooseAmount && trancheInfo && jsxRuntime.jsx(ChooseAmount$6, {
4614
+ poolInfo: poolInfo,
4589
4615
  poolUnderlyingToken: poolUnderlyingToken,
4590
4616
  trancheInfo: trancheInfo
4591
4617
  }), step === WIDGET_STEP.Transfer && trancheInfo && jsxRuntime.jsx(Transfer$8, {
@@ -5636,6 +5662,8 @@ function ChooseAmount$4(_ref) {
5636
5662
  } = shared.usePoolSafeAllowanceV2(poolInfo.poolName, account, provider);
5637
5663
  const [balance] = shared.usePoolUnderlyingTokenBalanceV2(poolInfo.poolName, account, provider);
5638
5664
  const maxAmountFormatted = ethers.ethers.utils.formatUnits(balance, poolUnderlyingToken.decimals);
5665
+ const lpConfig = shared.useLPConfigV2(poolInfo.poolName, provider);
5666
+ const isUniTranche = (lpConfig === null || lpConfig === void 0 ? void 0 : lpConfig.maxSeniorJuniorRatio) === 0;
5639
5667
  const handleChangeAmount = newAmount => {
5640
5668
  setCurrentAmount(newAmount);
5641
5669
  dispatch(setSupplyAmount(Number(newAmount)));
@@ -5645,9 +5673,14 @@ function ChooseAmount$4(_ref) {
5645
5673
  const step = currentAmountBN.gt(allowance) ? WIDGET_STEP.ApproveAllowance : WIDGET_STEP.Transfer;
5646
5674
  dispatch(setStep(step));
5647
5675
  };
5676
+ if (!lpConfig) {
5677
+ return jsxRuntime.jsx(LoadingModal, {
5678
+ title: "Supply"
5679
+ });
5680
+ }
5648
5681
  return jsxRuntime.jsx(InputAmountModal, {
5649
5682
  title: "Enter Amount",
5650
- subTitle: "Supplying ".concat(symbol, " with ").concat(selectedTranche),
5683
+ subTitle: "Supplying ".concat(symbol, " with ").concat(isUniTranche ? 'uni tranche' : selectedTranche),
5651
5684
  tokenSymbol: symbol,
5652
5685
  currentAmount: currentAmount,
5653
5686
  handleChangeAmount: handleChangeAmount,