@huma-finance/widgets 0.0.48-beta.291 → 0.0.48-beta.296

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, getERC20Contract, usePoolInfoV2, usePoolUnderlyingTokenInfoV2, usePoolSafeAllowanceV2, useAuthErrorHandling, checkIsDev, EAService, EARejectionError, EARejectMessage, EARejectReason, useCLFeeManager, useCLPoolAllowance, usePoolContract, timeUtil, formatNumber, doesChainSupportNotifi, getNotifiDappId, getBlockchainConfigFromChain, CreditState, useCreditContractV2, useCreditStatsV2, CreditStateV2, upScale, toBigNumber, TRANSFER_ABI, FirstLossCoverIndex, useFirstLossCoverContractV2, useFirstLossCoverRequirementV2, useFirstLossCoverAllowanceV2, useFeeManager, combineStyles, isEmpty, useInvoiceNFTContract, useRFPoolAllowance, useLenderDepositRecordV2, useLPConfigV2, useNextEpochStartTimeV2, timestampToLL, getTrancheVaultContractV2, useTrancheVaultContractV2, useCancellableRedemptionInfoV2, useLenderPositionV2, useParamsSearch, IdentityService, CHAINS, configUtil, usePoolAllowance, useLenderApproved, useLenderPosition, useWithdrawlLockoutInSeconds, usePoolUnderlyingTokenBalance, usePoolUnderlyingTokenBalanceV2, useLenderApprovedV2, useLastDepositTime, formatBNFixed, useWithdrawableAssetsV2, useReceivableInfoV2, useReceivableContractV2, CreditEventText, useERC2612Permit, ERC2612_ABI, SuperfluidPoolProcessor_ABI, useMultiSendContract, usePoolUnderlyingToken, hasRFActiveLoan, getWalletAddressAbbr, useFactoring, PoolMap, PoolSubgraphMap, CreditEvent, CURRENCY_CODE, 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, getERC20Contract, usePoolInfoV2, usePoolUnderlyingTokenInfoV2, usePoolSafeAllowanceV2, useAuthErrorHandling, checkIsDev, EAService, EARejectionError, EARejectMessage, EARejectReason, useCLFeeManager, useCLPoolAllowance, usePoolContract, timeUtil, formatNumber, doesChainSupportNotifi, getNotifiDappId, getBlockchainConfigFromChain, CreditState, useCreditContractV2, useCreditStatsV2, CreditStateV2, upScale, toBigNumber, TRANSFER_ABI, FirstLossCoverIndex, useFirstLossCoverContractV2, useFirstLossCoverRequirementV2, useFirstLossCoverAllowanceV2, useFeeManager, combineStyles, isEmpty, useInvoiceNFTContract, useRFPoolAllowance, useLenderDepositRecordV2, useLPConfigV2, useNextEpochStartTimeV2, timestampToLL, getTrancheVaultContractV2, useTrancheVaultContractV2, useCancellableRedemptionInfoV2, useLenderPositionV2, useParamsSearch, IdentityService, CHAINS, configUtil, usePoolAllowance, useLenderApproved, useLenderPosition, useWithdrawlLockoutInSeconds, usePoolUnderlyingTokenBalance, usePoolUnderlyingTokenBalanceV2, getFirstLossCoverContractV2, useLenderApprovedV2, useFirstLossCoverStatsV2, capitalizeFirstLetter, useLastDepositTime, useTrancheWithdrawableAssetsV2, usePoolIsReadyForFlcWithdrawalV2, formatBNFixed, useReceivableInfoV2, useReceivableContractV2, CreditEventText, useERC2612Permit, ERC2612_ABI, SuperfluidPoolProcessor_ABI, useMultiSendContract, usePoolUnderlyingToken, hasRFActiveLoan, getWalletAddressAbbr, useFactoring, PoolMap, PoolSubgraphMap, CreditEvent, CURRENCY_CODE, Provider as Provider$1 } from '@huma-finance/shared';
3
3
  import { useTheme, css, Box, Typography, Tooltip, Button, Dialog, Slider, Input, Divider, TextField, FormControl, FormLabel, RadioGroup, FormControlLabel, Radio, Snackbar, Alert, Skeleton, TablePagination, LinearProgress, createTheme, ThemeProvider } from '@mui/material';
4
4
  import { useAtom, Provider as Provider$2 } from 'jotai';
5
5
  import * as React from 'react';
@@ -2438,7 +2438,7 @@ function ChooseAmountModal(_ref) {
2438
2438
  });
2439
2439
  }
2440
2440
 
2441
- function ChooseAmount$c(_ref) {
2441
+ function ChooseAmount$d(_ref) {
2442
2442
  let {
2443
2443
  poolInfo,
2444
2444
  accountStats
@@ -2915,7 +2915,7 @@ function CreditLineBorrow(_ref) {
2915
2915
  children: [step === WIDGET_STEP.Evaluation && jsx(Evaluation$4, {
2916
2916
  poolInfo: poolInfo,
2917
2917
  handleApprove: approveCallback
2918
- }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$c, {
2918
+ }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$d, {
2919
2919
  poolInfo: poolInfo,
2920
2920
  accountStats: accountStats
2921
2921
  }), step === WIDGET_STEP.ApproveAllowance && jsx(ApproveAllowance$a, {
@@ -3006,7 +3006,7 @@ function InputAmountModal(_ref) {
3006
3006
  });
3007
3007
  }
3008
3008
 
3009
- function ChooseAmount$b(_ref) {
3009
+ function ChooseAmount$c(_ref) {
3010
3010
  let {
3011
3011
  poolInfo,
3012
3012
  poolUnderlyingToken,
@@ -3248,7 +3248,7 @@ function CreditLineBorrowV2(_ref) {
3248
3248
  handleSuccess: handleSuccessCallback,
3249
3249
  children: [!step && jsx(LoadingModal, {
3250
3250
  title: "Borrow"
3251
- }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$b, {
3251
+ }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$c, {
3252
3252
  poolInfo: poolInfo,
3253
3253
  poolUnderlyingToken: poolUnderlyingToken,
3254
3254
  accountStats: accountStats
@@ -3272,7 +3272,7 @@ function CreditLineBorrowV2(_ref) {
3272
3272
  });
3273
3273
  }
3274
3274
 
3275
- function ChooseAmount$a(_ref) {
3275
+ function ChooseAmount$b(_ref) {
3276
3276
  let {
3277
3277
  payoffAmount,
3278
3278
  totalDueAmount,
@@ -3429,7 +3429,7 @@ function CreditLinePayment(_ref) {
3429
3429
  loadingTitle: "Make Payment",
3430
3430
  handleClose: handleClose,
3431
3431
  handleSuccess: handleSuccess,
3432
- children: [step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$a, {
3432
+ children: [step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$b, {
3433
3433
  poolInfo: poolInfo,
3434
3434
  payoffAmount: payoffAmount,
3435
3435
  totalDueAmount: totalDueAmount
@@ -3448,7 +3448,7 @@ function CreditLinePayment(_ref) {
3448
3448
  });
3449
3449
  }
3450
3450
 
3451
- function ChooseAmount$9(_ref) {
3451
+ function ChooseAmount$a(_ref) {
3452
3452
  let {
3453
3453
  payoffAmount: payoffAmountBN,
3454
3454
  totalDueAmount: totalDueAmountBN,
@@ -3470,10 +3470,6 @@ function ChooseAmount$9(_ref) {
3470
3470
  } = usePoolSafeAllowanceV2(poolInfo.poolName, account, provider);
3471
3471
  const totalDueAmount = Number(ethers.utils.formatUnits(totalDueAmountBN, decimals));
3472
3472
  const payoffAmount = Number(ethers.utils.formatUnits(payoffAmountBN, decimals));
3473
- console.log('totalDueAmountBN', totalDueAmountBN.toString());
3474
- console.log('payoffAmountBN', payoffAmountBN.toString());
3475
- console.log('payoffAmount', payoffAmount);
3476
- console.log('currentAmount', currentAmount);
3477
3473
  useEffect(() => {
3478
3474
  setCurrentAmount(totalDueAmount);
3479
3475
  }, [totalDueAmount]);
@@ -3637,7 +3633,7 @@ function CreditLinePaymentV2(_ref) {
3637
3633
  loadingTitle: "Pay",
3638
3634
  handleClose: handleClose,
3639
3635
  handleSuccess: handleSuccess,
3640
- children: [step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$9, {
3636
+ children: [step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$a, {
3641
3637
  poolInfo: poolInfo,
3642
3638
  poolUnderlyingToken: poolUnderlyingToken,
3643
3639
  payoffAmount: payoffAmount,
@@ -3830,7 +3826,7 @@ function Evaluation$3(_ref) {
3830
3826
  });
3831
3827
  }
3832
3828
 
3833
- function ChooseAmount$8(_ref) {
3829
+ function ChooseAmount$9(_ref) {
3834
3830
  var _receivable;
3835
3831
  let {
3836
3832
  poolInfo,
@@ -4111,7 +4107,7 @@ function InvoiceFactoringBorrow(_ref) {
4111
4107
  children: [step === WIDGET_STEP.Evaluation && jsx(Evaluation$3, {
4112
4108
  poolInfo: poolInfo,
4113
4109
  tokenId: tokenId.toString()
4114
- }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$8, {
4110
+ }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$9, {
4115
4111
  poolInfo: poolInfo,
4116
4112
  accountStats: accountStats
4117
4113
  }), step === WIDGET_STEP.ConfirmTransfer && jsx(ConfirmTransfer$1, {}), step === WIDGET_STEP.ApproveNFT && jsx(ApproveNFT, {
@@ -4130,7 +4126,7 @@ function InvoiceFactoringBorrow(_ref) {
4130
4126
  });
4131
4127
  }
4132
4128
 
4133
- function ChooseAmount$7(_ref) {
4129
+ function ChooseAmount$8(_ref) {
4134
4130
  let {
4135
4131
  creditRecord,
4136
4132
  poolInfo
@@ -4275,7 +4271,7 @@ function InvoiceFactoringPayment(_ref) {
4275
4271
  loadingTitle: "Make Payment",
4276
4272
  handleClose: handleClose,
4277
4273
  handleSuccess: handleSuccess,
4278
- children: [step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$7, {
4274
+ children: [step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$8, {
4279
4275
  creditRecord: creditRecord,
4280
4276
  poolInfo: poolInfo
4281
4277
  }), step === WIDGET_STEP.ApproveAllowance && jsx(ApproveAllowance$5, {
@@ -4421,7 +4417,7 @@ function ChooseAction(_ref) {
4421
4417
  });
4422
4418
  }
4423
4419
 
4424
- function ChooseAmount$6(_ref) {
4420
+ function ChooseAmount$7(_ref) {
4425
4421
  let {
4426
4422
  poolInfo,
4427
4423
  poolUnderlyingToken,
@@ -4636,7 +4632,7 @@ function LendRedeemV2(_ref) {
4636
4632
  changeRedemptionType: setRedemptionType,
4637
4633
  seniorPosition: seniorPosition,
4638
4634
  juniorPosition: juniorPosition
4639
- }), step === WIDGET_STEP.ChooseAmount && redemptionType && jsx(ChooseAmount$6, {
4635
+ }), step === WIDGET_STEP.ChooseAmount && redemptionType && jsx(ChooseAmount$7, {
4640
4636
  poolInfo: poolInfo,
4641
4637
  poolUnderlyingToken: poolUnderlyingToken,
4642
4638
  redemptionType: redemptionType,
@@ -5046,7 +5042,7 @@ function Evaluation$2(_ref) {
5046
5042
  });
5047
5043
  }
5048
5044
 
5049
- function ChooseAmount$5(_ref) {
5045
+ function ChooseAmount$6(_ref) {
5050
5046
  let {
5051
5047
  allowance,
5052
5048
  withdrawlLockoutSeconds,
@@ -5253,7 +5249,7 @@ function LendSupply(_ref) {
5253
5249
  poolInfo: poolInfo,
5254
5250
  handleClose: handleClose,
5255
5251
  handleApproveSuccess: handleApproveSuccess
5256
- }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$5, {
5252
+ }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$6, {
5257
5253
  poolInfo: poolInfo,
5258
5254
  allowance: allowance,
5259
5255
  underlyingTokenBalance: balanceWithoutDecimals,
@@ -5278,11 +5274,12 @@ function LendSupply(_ref) {
5278
5274
  }
5279
5275
 
5280
5276
  var _templateObject$9, _templateObject2$7, _templateObject3$6;
5281
- function ChooseTranche$1(_ref) {
5277
+ function ChooseSupplyType(_ref) {
5282
5278
  let {
5283
5279
  poolUnderlyingToken,
5284
- selectedTranche,
5285
- changeTranche
5280
+ selectedSupplyType,
5281
+ supplyTypes,
5282
+ changeSupplyType
5286
5283
  } = _ref;
5287
5284
  const theme = useTheme();
5288
5285
  const dispatch = useAppDispatch();
@@ -5291,16 +5288,15 @@ function ChooseTranche$1(_ref) {
5291
5288
  radioGroup: css(_templateObject2$7 || (_templateObject2$7 = _taggedTemplateLiteral(["\n margin-left: ", ";\n margin-top: ", ";\n "])), theme.spacing(3), theme.spacing(3)),
5292
5289
  formControl: css(_templateObject3$6 || (_templateObject3$6 = _taggedTemplateLiteral(["\n margin-bottom: ", ";\n\n .MuiFormControlLabel-label {\n color: ", ";\n font-family: 'Uni-Neue-Regular';\n font-size: 16px;\n line-height: 150%;\n letter-spacing: 0.15px;\n }\n "])), theme.spacing(1), theme.palette.text.primary)
5293
5290
  };
5291
+ const handleChangeSupplyType = supplyTypeValue => {
5292
+ const supplyType = supplyTypes.find(item => item.value === supplyTypeValue);
5293
+ if (supplyType) {
5294
+ changeSupplyType(supplyType);
5295
+ }
5296
+ };
5294
5297
  const handleNext = () => {
5295
5298
  dispatch(setStep(WIDGET_STEP.ChooseAmount));
5296
5299
  };
5297
- const items = [{
5298
- label: 'Senior',
5299
- value: 'senior'
5300
- }, {
5301
- label: 'Junior',
5302
- value: 'junior'
5303
- }];
5304
5300
  return jsxs(WrapperModal, {
5305
5301
  title: "Supply ".concat(poolUnderlyingToken.symbol),
5306
5302
  children: [jsxs(FormControl, {
@@ -5311,8 +5307,8 @@ function ChooseTranche$1(_ref) {
5311
5307
  "aria-labelledby": "buttons-group-label",
5312
5308
  name: "radio-buttons-group",
5313
5309
  css: styles.radioGroup,
5314
- onChange: e => changeTranche(e.target.value),
5315
- children: items.map(item => jsx(FormControlLabel, {
5310
+ onChange: e => handleChangeSupplyType(e.target.value),
5311
+ children: supplyTypes.map(item => jsx(FormControlLabel, {
5316
5312
  value: item.value,
5317
5313
  control: jsx(Radio, {
5318
5314
  sx: {
@@ -5327,7 +5323,7 @@ function ChooseTranche$1(_ref) {
5327
5323
  })]
5328
5324
  }), jsx(BottomButton, {
5329
5325
  variant: "contained",
5330
- disabled: !selectedTranche,
5326
+ disabled: !selectedSupplyType,
5331
5327
  onClick: handleNext,
5332
5328
  children: "NEXT"
5333
5329
  })]
@@ -5566,11 +5562,11 @@ function Evaluation$1(_ref) {
5566
5562
  });
5567
5563
  }
5568
5564
 
5569
- function ChooseAmount$4(_ref) {
5565
+ function ChooseAmount$5(_ref) {
5570
5566
  let {
5571
5567
  poolInfo,
5572
5568
  poolUnderlyingToken,
5573
- selectedTranche
5569
+ selectedSupplyType
5574
5570
  } = _ref;
5575
5571
  const dispatch = useAppDispatch();
5576
5572
  const {
@@ -5583,22 +5579,28 @@ function ChooseAmount$4(_ref) {
5583
5579
  } = poolUnderlyingToken;
5584
5580
  const [currentAmount, setCurrentAmount] = useState(0);
5585
5581
  const {
5586
- allowance = BigNumber.from(0)
5582
+ allowance: poolSafeAllowance = BigNumber.from(0)
5587
5583
  } = usePoolSafeAllowanceV2(poolInfo.poolName, account, provider);
5588
- const [balance] = usePoolUnderlyingTokenBalanceV2(poolInfo.poolName, account, provider);
5589
- const maxAmountFormatted = ethers.utils.formatUnits(balance, poolUnderlyingToken.decimals);
5584
+ const [firstLossCoverAllowance = BigNumber.from(0)] = useFirstLossCoverAllowanceV2(poolInfo.poolName, Number(selectedSupplyType.value), account, provider);
5585
+ const [underlyingTokenBalance = BigNumber.from(0)] = usePoolUnderlyingTokenBalanceV2(poolInfo.poolName, account, provider);
5586
+ const maxAmountFormatted = ethers.utils.formatUnits(underlyingTokenBalance, poolUnderlyingToken.decimals);
5590
5587
  const handleChangeAmount = newAmount => {
5591
5588
  setCurrentAmount(newAmount);
5592
5589
  dispatch(setSupplyAmount(Number(newAmount)));
5593
5590
  };
5594
5591
  const handleAction = () => {
5595
5592
  const currentAmountBN = ethers.utils.parseUnits(String(currentAmount), decimals);
5596
- const step = currentAmountBN.gt(allowance) ? WIDGET_STEP.ApproveAllowance : WIDGET_STEP.Transfer;
5597
- dispatch(setStep(step));
5593
+ if (selectedSupplyType.type === 'tranche') {
5594
+ const step = currentAmountBN.gt(poolSafeAllowance) ? WIDGET_STEP.ApproveAllowance : WIDGET_STEP.Transfer;
5595
+ dispatch(setStep(step));
5596
+ } else {
5597
+ const step = currentAmountBN.gt(firstLossCoverAllowance) ? WIDGET_STEP.ApproveAllowance : WIDGET_STEP.Transfer;
5598
+ dispatch(setStep(step));
5599
+ }
5598
5600
  };
5599
5601
  return jsx(InputAmountModal, {
5600
5602
  title: "Enter Amount",
5601
- subTitle: "Supplying ".concat(symbol, " with ").concat(selectedTranche),
5603
+ subTitle: "Supplying ".concat(symbol, " with ").concat(selectedSupplyType === null || selectedSupplyType === void 0 ? void 0 : selectedSupplyType.label),
5602
5604
  tokenSymbol: symbol,
5603
5605
  currentAmount: currentAmount,
5604
5606
  handleChangeAmount: handleChangeAmount,
@@ -5612,10 +5614,14 @@ function ChooseAmount$4(_ref) {
5612
5614
  function ApproveAllowance$3(_ref) {
5613
5615
  let {
5614
5616
  poolInfo,
5615
- poolUnderlyingToken
5617
+ poolUnderlyingToken,
5618
+ selectedSupplyType
5616
5619
  } = _ref;
5617
5620
  const dispatch = useAppDispatch();
5618
- const spender = poolInfo.poolSafe;
5621
+ let spender = poolInfo.poolSafe;
5622
+ if (selectedSupplyType.type === 'firstLossCover') {
5623
+ spender = poolInfo.firstLossCovers[Number(selectedSupplyType.value)];
5624
+ }
5619
5625
  const handleSuccess = useCallback(() => {
5620
5626
  dispatch(setStep(WIDGET_STEP.Transfer));
5621
5627
  }, [dispatch]);
@@ -5631,7 +5637,7 @@ function Transfer$5(_ref) {
5631
5637
  let {
5632
5638
  poolInfo,
5633
5639
  poolUnderlyingToken,
5634
- trancheType
5640
+ selectedSupplyType
5635
5641
  } = _ref;
5636
5642
  const dispatch = useAppDispatch();
5637
5643
  const {
@@ -5645,17 +5651,40 @@ function Transfer$5(_ref) {
5645
5651
  decimals
5646
5652
  } = poolUnderlyingToken;
5647
5653
  const supplyBigNumber = ethers.utils.parseUnits(String(supplyAmount), decimals);
5648
- const trancheVaultContract = useTrancheVaultContractV2(poolInfo.poolName, trancheType, provider, account);
5654
+ const [contract, setContract] = useState(undefined);
5655
+ useEffect(() => {
5656
+ const fetchData = async () => {
5657
+ if (account) {
5658
+ if (selectedSupplyType.type === 'tranche') {
5659
+ const trancheVaultContract = await getTrancheVaultContractV2(poolInfo.poolName, selectedSupplyType.value, provider, account);
5660
+ if (trancheVaultContract) {
5661
+ setContract(trancheVaultContract);
5662
+ }
5663
+ }
5664
+ if (selectedSupplyType.type === 'firstLossCover') {
5665
+ const firstLossCoverContract = await getFirstLossCoverContractV2(poolInfo.poolName, Number(selectedSupplyType.value), provider, account);
5666
+ if (firstLossCoverContract) {
5667
+ setContract(firstLossCoverContract);
5668
+ }
5669
+ }
5670
+ }
5671
+ };
5672
+ fetchData();
5673
+ }, [account, poolInfo.poolName, provider, selectedSupplyType.type, selectedSupplyType.value]);
5674
+ const method = selectedSupplyType.type === 'tranche' ? 'deposit' : 'depositCover';
5675
+ const params = selectedSupplyType.type === 'tranche' ? [supplyBigNumber, account] : [supplyBigNumber];
5649
5676
  const handleSuccess = useCallback(() => {
5650
5677
  dispatch(setStep(WIDGET_STEP.Done));
5651
5678
  }, [dispatch]);
5652
- if (!trancheVaultContract || !account) {
5653
- return null;
5679
+ if (!contract) {
5680
+ return jsx(LoadingModal, {
5681
+ title: "Transaction Pending"
5682
+ });
5654
5683
  }
5655
5684
  return jsx(TxSendModalV2, {
5656
- contract: trancheVaultContract,
5657
- method: "deposit",
5658
- params: [supplyBigNumber, account],
5685
+ contract: contract,
5686
+ method: method,
5687
+ params: params,
5659
5688
  handleSuccess: handleSuccess
5660
5689
  });
5661
5690
  }
@@ -5694,10 +5723,9 @@ function Success$4(_ref) {
5694
5723
  events.forEach(event => {
5695
5724
  const {
5696
5725
  from,
5697
- to,
5698
5726
  value
5699
5727
  } = event.args;
5700
- if (from.toLowerCase() === (account === null || account === void 0 ? void 0 : account.toLowerCase()) && to.toLowerCase() === poolInfo.poolSafe.toLowerCase()) {
5728
+ if (from.toLowerCase() === (account === null || account === void 0 ? void 0 : account.toLowerCase())) {
5701
5729
  setSupplyAmount(downScale(value.toString(), decimals));
5702
5730
  }
5703
5731
  });
@@ -5746,36 +5774,50 @@ function LendSupplyV2(_ref) {
5746
5774
  step,
5747
5775
  errorMessage
5748
5776
  } = useAppSelector(selectWidgetState);
5749
- const [selectedTranche, setSelectedTranche] = useState();
5777
+ const [supplyTypes, setSupplyTypes] = useState([]);
5778
+ const [selectedSupplyType, setSelectedSupplyType] = useState();
5750
5779
  const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider);
5751
5780
  const [lenderApprovedSenior] = useLenderApprovedV2(poolName, 'senior', account, provider);
5752
5781
  const [lenderApprovedJunior] = useLenderApprovedV2(poolName, 'junior', account, provider);
5753
- const lenderApproveStatusFetched = lenderApprovedSenior !== undefined && lenderApprovedJunior !== undefined;
5782
+ const [flcStats] = useFirstLossCoverStatsV2(poolName, account, provider);
5783
+ const lenderApproveStatusFetched = lenderApprovedSenior !== undefined && lenderApprovedJunior !== undefined && flcStats !== undefined;
5754
5784
  useEffect(() => {
5755
5785
  if (!step && poolInfo && lenderApproveStatusFetched) {
5756
- if (lenderApprovedJunior && !lenderApprovedSenior) {
5757
- setSelectedTranche('junior');
5758
- dispatch(setStep(WIDGET_STEP.ChooseAmount));
5759
- return;
5786
+ const items = [];
5787
+ if (lenderApprovedSenior) {
5788
+ items.push({
5789
+ label: 'Senior Tranche',
5790
+ value: 'senior',
5791
+ type: 'tranche'
5792
+ });
5760
5793
  }
5761
- if (lenderApprovedSenior && !lenderApprovedJunior) {
5762
- setSelectedTranche('senior');
5763
- dispatch(setStep(WIDGET_STEP.ChooseAmount));
5764
- return;
5794
+ if (lenderApprovedJunior) {
5795
+ items.push({
5796
+ label: 'Junior Tranche',
5797
+ value: 'junior',
5798
+ type: 'tranche'
5799
+ });
5765
5800
  }
5766
- if (lenderApprovedJunior && lenderApprovedSenior) {
5801
+ flcStats.filter(flc => flc.isApproved).forEach(flc => {
5802
+ items.push({
5803
+ label: "".concat(capitalizeFirstLetter(FirstLossCoverIndex[flc.firstLossCoverIndex]), " First Loss Cover"),
5804
+ value: String(flc.firstLossCoverIndex),
5805
+ type: 'firstLossCover'
5806
+ });
5807
+ });
5808
+ if (items.length === 1) {
5809
+ setSelectedSupplyType(items[0]);
5810
+ dispatch(setStep(WIDGET_STEP.ChooseAmount));
5811
+ } else if (items.length > 1) {
5812
+ setSupplyTypes(items);
5767
5813
  dispatch(setStep(WIDGET_STEP.ChooseTranche));
5768
- return;
5769
- }
5770
- if (poolInfo.KYC) {
5814
+ } else if (poolInfo.KYC) {
5771
5815
  dispatch(setStep(WIDGET_STEP.Evaluation));
5772
- return;
5773
- }
5774
- if (poolInfo.supplyLink) {
5816
+ } else if (poolInfo.supplyLink) {
5775
5817
  openInNewTab(poolInfo.supplyLink);
5776
5818
  }
5777
5819
  }
5778
- }, [dispatch, lenderApproveStatusFetched, lenderApprovedJunior, lenderApprovedSenior, poolInfo, step]);
5820
+ }, [dispatch, flcStats, lenderApproveStatusFetched, lenderApprovedJunior, lenderApprovedSenior, poolInfo, step]);
5779
5821
  if (!poolInfo || !poolUnderlyingToken || !lenderApproveStatusFetched) {
5780
5822
  return jsx(WidgetWrapper, {
5781
5823
  isOpen: true,
@@ -5790,24 +5832,26 @@ function LendSupplyV2(_ref) {
5790
5832
  loadingTitle: "Supply ".concat(poolUnderlyingToken.symbol),
5791
5833
  handleClose: handleClose,
5792
5834
  handleSuccess: handleSuccess,
5793
- children: [step === WIDGET_STEP.ChooseTranche && jsx(ChooseTranche$1, {
5835
+ children: [step === WIDGET_STEP.ChooseTranche && jsx(ChooseSupplyType, {
5794
5836
  poolUnderlyingToken: poolUnderlyingToken,
5795
- selectedTranche: selectedTranche,
5796
- changeTranche: setSelectedTranche
5837
+ selectedSupplyType: selectedSupplyType,
5838
+ supplyTypes: supplyTypes,
5839
+ changeSupplyType: setSelectedSupplyType
5797
5840
  }), step === WIDGET_STEP.Evaluation && jsx(Evaluation$1, {
5798
5841
  poolInfo: poolInfo,
5799
5842
  handleClose: handleClose
5800
- }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$4, {
5843
+ }), step === WIDGET_STEP.ChooseAmount && selectedSupplyType && jsx(ChooseAmount$5, {
5801
5844
  poolInfo: poolInfo,
5802
5845
  poolUnderlyingToken: poolUnderlyingToken,
5803
- selectedTranche: selectedTranche
5804
- }), step === WIDGET_STEP.ApproveAllowance && jsx(ApproveAllowance$3, {
5846
+ selectedSupplyType: selectedSupplyType
5847
+ }), step === WIDGET_STEP.ApproveAllowance && selectedSupplyType && jsx(ApproveAllowance$3, {
5805
5848
  poolInfo: poolInfo,
5806
- poolUnderlyingToken: poolUnderlyingToken
5807
- }), step === WIDGET_STEP.Transfer && selectedTranche && jsx(Transfer$5, {
5849
+ poolUnderlyingToken: poolUnderlyingToken,
5850
+ selectedSupplyType: selectedSupplyType
5851
+ }), step === WIDGET_STEP.Transfer && selectedSupplyType && jsx(Transfer$5, {
5808
5852
  poolInfo: poolInfo,
5809
5853
  poolUnderlyingToken: poolUnderlyingToken,
5810
- trancheType: selectedTranche
5854
+ selectedSupplyType: selectedSupplyType
5811
5855
  }), step === WIDGET_STEP.Done && jsx(Success$4, {
5812
5856
  poolInfo: poolInfo,
5813
5857
  poolUnderlyingToken: poolUnderlyingToken,
@@ -5865,7 +5909,7 @@ function CheckWithdrawable(_ref) {
5865
5909
  });
5866
5910
  }
5867
5911
 
5868
- function ChooseAmount$3(_ref) {
5912
+ function ChooseAmount$4(_ref) {
5869
5913
  let {
5870
5914
  lenderPosition,
5871
5915
  poolInfo
@@ -6009,7 +6053,7 @@ function LendWithdraw(_ref) {
6009
6053
  children: [(!step || step === WIDGET_STEP.CheckWithdrawable) && jsx(CheckWithdrawable, {
6010
6054
  poolInfo: poolInfo,
6011
6055
  handleClose: handleClose
6012
- }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$3, {
6056
+ }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$4, {
6013
6057
  poolInfo: poolInfo,
6014
6058
  lenderPosition: lenderPosition
6015
6059
  }), step === WIDGET_STEP.Transfer && jsx(Transfer$4, {
@@ -6028,73 +6072,35 @@ function LendWithdraw(_ref) {
6028
6072
 
6029
6073
  var _templateObject$7, _templateObject2$5, _templateObject3$5;
6030
6074
  function ChooseTranche(_ref) {
6031
- var _seniorWithdrawableAm, _juniorWithdrawableAm;
6032
6075
  let {
6033
- poolInfo,
6034
6076
  poolUnderlyingToken,
6035
- selectedTranche,
6036
- seniorWithdrawableAmount,
6037
- juniorWithdrawableAmount,
6038
- changeTranche
6077
+ selectedWithdrawType,
6078
+ withdrawTypes,
6079
+ changeWithdrawType
6039
6080
  } = _ref;
6040
6081
  const theme = useTheme();
6041
6082
  const dispatch = useAppDispatch();
6042
6083
  const {
6043
- provider
6044
- } = useWeb3React();
6045
- const {
6046
- symbol,
6047
- decimals
6084
+ symbol
6048
6085
  } = poolUnderlyingToken;
6049
- const [seniorWithdrawableShares, setSeniorWithdrawableShares] = useState(BigNumber.from(0));
6050
- const [juniorWithdrawableShares, setJuniorWithdrawableShares] = useState(BigNumber.from(0));
6051
- const isLoading = seniorWithdrawableAmount === undefined || juniorWithdrawableAmount === undefined;
6052
- useEffect(() => {
6053
- const fetchData = async () => {
6054
- if (seniorWithdrawableAmount !== null && seniorWithdrawableAmount !== void 0 && seniorWithdrawableAmount.gt(0)) {
6055
- const seniorVaultContract = await getTrancheVaultContractV2(poolInfo.poolName, 'senior', provider);
6056
- if (seniorVaultContract) {
6057
- const shares = await seniorVaultContract.convertToShares(seniorWithdrawableAmount);
6058
- setSeniorWithdrawableShares(shares);
6059
- }
6060
- }
6061
- };
6062
- fetchData();
6063
- }, [poolInfo.poolName, provider, seniorWithdrawableAmount]);
6064
- useEffect(() => {
6065
- const fetchData = async () => {
6066
- if (juniorWithdrawableAmount !== null && juniorWithdrawableAmount !== void 0 && juniorWithdrawableAmount.gt(0)) {
6067
- const juniorVaultContract = await getTrancheVaultContractV2(poolInfo.poolName, 'senior', provider);
6068
- if (juniorVaultContract) {
6069
- const shares = await juniorVaultContract.convertToShares(juniorWithdrawableAmount);
6070
- setJuniorWithdrawableShares(shares);
6071
- }
6072
- }
6073
- };
6074
- fetchData();
6075
- }, [poolInfo.poolName, provider, juniorWithdrawableAmount]);
6076
6086
  const styles = {
6077
6087
  subTitle: css(_templateObject$7 || (_templateObject$7 = _taggedTemplateLiteral(["\n color: ", " !important;\n font-family: 'Uni-Neue-Regular';\n font-size: 16px;\n line-height: 150%;\n letter-spacing: 0.15px;\n margin-top: ", ";\n margin-left: ", ";\n "])), theme.palette.text.primary, theme.spacing(5), theme.spacing(2)),
6078
6088
  radioGroup: css(_templateObject2$5 || (_templateObject2$5 = _taggedTemplateLiteral(["\n margin-left: ", ";\n margin-top: ", ";\n "])), theme.spacing(3), theme.spacing(3)),
6079
6089
  formControl: css(_templateObject3$5 || (_templateObject3$5 = _taggedTemplateLiteral(["\n margin-bottom: ", ";\n\n .MuiFormControlLabel-label {\n color: ", ";\n font-family: 'Uni-Neue-Regular';\n font-size: 16px;\n line-height: 150%;\n letter-spacing: 0.15px;\n }\n "])), theme.spacing(1), theme.palette.text.primary)
6080
6090
  };
6091
+ const handleChangeWithdrawType = withdrawTypeValue => {
6092
+ const withdrawType = withdrawTypes.find(item => item.value === withdrawTypeValue);
6093
+ if (withdrawType) {
6094
+ changeWithdrawType(withdrawType);
6095
+ }
6096
+ };
6081
6097
  const handleNext = () => {
6082
- dispatch(setStep(WIDGET_STEP.Transfer));
6098
+ if ((selectedWithdrawType === null || selectedWithdrawType === void 0 ? void 0 : selectedWithdrawType.type) === 'firstLossCover') {
6099
+ dispatch(setStep(WIDGET_STEP.ChooseAmount));
6100
+ } else {
6101
+ dispatch(setStep(WIDGET_STEP.Transfer));
6102
+ }
6083
6103
  };
6084
- const items = [{
6085
- label: "Withdraw ".concat(formatBNFixed(seniorWithdrawableAmount, decimals), " ").concat(symbol, " from Senior vault (").concat(formatBNFixed(seniorWithdrawableShares, decimals), " shares)"),
6086
- value: 'senior',
6087
- disabled: (_seniorWithdrawableAm = seniorWithdrawableAmount === null || seniorWithdrawableAmount === void 0 ? void 0 : seniorWithdrawableAmount.lte(0)) !== null && _seniorWithdrawableAm !== void 0 ? _seniorWithdrawableAm : true
6088
- }, {
6089
- label: "Withdraw ".concat(formatBNFixed(juniorWithdrawableAmount, decimals), " ").concat(symbol, " from Junior vault (").concat(formatBNFixed(juniorWithdrawableShares, decimals), " shares)"),
6090
- value: 'junior',
6091
- disabled: (_juniorWithdrawableAm = juniorWithdrawableAmount === null || juniorWithdrawableAmount === void 0 ? void 0 : juniorWithdrawableAmount.lte(0)) !== null && _juniorWithdrawableAm !== void 0 ? _juniorWithdrawableAm : true
6092
- }];
6093
- if (isLoading) {
6094
- return jsx(LoadingModal, {
6095
- title: "Withdraw ".concat(symbol)
6096
- });
6097
- }
6098
6104
  return jsxs(WrapperModal, {
6099
6105
  title: "Withdraw ".concat(symbol),
6100
6106
  children: [jsxs(FormControl, {
@@ -6105,10 +6111,9 @@ function ChooseTranche(_ref) {
6105
6111
  "aria-labelledby": "buttons-group-label",
6106
6112
  name: "radio-buttons-group",
6107
6113
  css: styles.radioGroup,
6108
- onChange: e => changeTranche(e.target.value),
6109
- children: items.map(item => jsx(FormControlLabel, {
6114
+ onChange: e => handleChangeWithdrawType(e.target.value),
6115
+ children: withdrawTypes.map(item => jsx(FormControlLabel, {
6110
6116
  value: item.value,
6111
- disabled: item.disabled,
6112
6117
  control: jsx(Radio, {
6113
6118
  sx: {
6114
6119
  '& .MuiSvgIcon-root': {
@@ -6122,34 +6127,116 @@ function ChooseTranche(_ref) {
6122
6127
  })]
6123
6128
  }), jsx(BottomButton, {
6124
6129
  variant: "contained",
6125
- disabled: !selectedTranche,
6130
+ disabled: !selectedWithdrawType,
6126
6131
  onClick: handleNext,
6127
6132
  children: "NEXT"
6128
6133
  })]
6129
6134
  });
6130
6135
  }
6131
6136
 
6137
+ function ChooseAmount$3(_ref) {
6138
+ let {
6139
+ poolInfo,
6140
+ poolUnderlyingToken,
6141
+ selectedWithdrawType
6142
+ } = _ref;
6143
+ const dispatch = useAppDispatch();
6144
+ const {
6145
+ provider
6146
+ } = useWeb3React();
6147
+ const {
6148
+ symbol
6149
+ } = poolUnderlyingToken;
6150
+ const [sharePrice, setSharePrice] = useState(0);
6151
+ const [currentAmount, setCurrentAmount] = useState(0);
6152
+ const [currentShares, setCurrentShares] = useState(0);
6153
+ const maxAmountFormatted = ethers.utils.formatUnits(selectedWithdrawType.withdrawableAmount, poolUnderlyingToken.decimals);
6154
+ useEffect(() => {
6155
+ if (selectedWithdrawType.withdrawableAmount.gt(0)) {
6156
+ const fetchData = async () => {
6157
+ const firstLossCoverContract = await getFirstLossCoverContractV2(poolInfo.poolName, Number(selectedWithdrawType.value), provider);
6158
+ if (firstLossCoverContract) {
6159
+ const shares = await firstLossCoverContract.convertToShares(selectedWithdrawType.withdrawableAmount);
6160
+ const price = selectedWithdrawType.withdrawableAmount.div(shares);
6161
+ setSharePrice(price.toNumber());
6162
+ }
6163
+ };
6164
+ fetchData();
6165
+ }
6166
+ }, [poolInfo.poolName, provider, selectedWithdrawType.value, selectedWithdrawType.withdrawableAmount]);
6167
+ const handleChangeAmount = newAmount => {
6168
+ const shares = Number(newAmount) / sharePrice;
6169
+ setCurrentShares(shares);
6170
+ setCurrentAmount(newAmount);
6171
+ dispatch(setWithdrawAmount(Number(newAmount)));
6172
+ };
6173
+ const handleAction = () => {
6174
+ dispatch(setStep(WIDGET_STEP.Transfer));
6175
+ };
6176
+ return jsx(InputAmountModal, {
6177
+ title: "Withdraw ".concat(symbol),
6178
+ subTitle: selectedWithdrawType.label,
6179
+ tokenSymbol: symbol,
6180
+ currentAmount: currentAmount,
6181
+ handleChangeAmount: handleChangeAmount,
6182
+ maxAmount: maxAmountFormatted,
6183
+ info: "".concat(currentShares.toFixed(1), " Shares"),
6184
+ handleAction: handleAction,
6185
+ actionText: "WITHDRAW"
6186
+ });
6187
+ }
6188
+
6132
6189
  function Transfer$3(_ref) {
6133
6190
  let {
6134
6191
  poolInfo,
6135
- selectedTranche
6192
+ poolUnderlyingToken,
6193
+ selectedWithdrawType
6136
6194
  } = _ref;
6137
6195
  const dispatch = useAppDispatch();
6138
6196
  const {
6139
6197
  account,
6140
6198
  provider
6141
6199
  } = useWeb3React();
6142
- const trancheVaultContract = useTrancheVaultContractV2(poolInfo.poolName, selectedTranche, provider, account);
6200
+ const {
6201
+ withdrawAmount
6202
+ } = useAppSelector(selectWidgetState);
6203
+ const [firstLossCoverShares, setFirstLossCoverShares] = React__default.useState(undefined);
6204
+ const [contract, setContract] = useState(undefined);
6205
+ useEffect(() => {
6206
+ const fetchData = async () => {
6207
+ if (account) {
6208
+ if (selectedWithdrawType.type === 'tranche') {
6209
+ const trancheVaultContract = await getTrancheVaultContractV2(poolInfo.poolName, selectedWithdrawType.value, provider, account);
6210
+ if (trancheVaultContract) {
6211
+ setContract(trancheVaultContract);
6212
+ }
6213
+ }
6214
+ if (selectedWithdrawType.type === 'firstLossCover') {
6215
+ const firstLossCoverContract = await getFirstLossCoverContractV2(poolInfo.poolName, Number(selectedWithdrawType.value), provider, account);
6216
+ if (firstLossCoverContract) {
6217
+ const shares = await firstLossCoverContract.convertToShares(ethers.utils.parseUnits(String(withdrawAmount), poolUnderlyingToken.decimals));
6218
+ setFirstLossCoverShares(shares);
6219
+ setContract(firstLossCoverContract);
6220
+ }
6221
+ }
6222
+ }
6223
+ };
6224
+ fetchData();
6225
+ }, [account, poolInfo.poolName, poolUnderlyingToken.decimals, provider, selectedWithdrawType.type, selectedWithdrawType.value, withdrawAmount]);
6226
+ const method = selectedWithdrawType.type === 'tranche' ? 'disburse' : 'redeemCover';
6227
+ const params = selectedWithdrawType.type === 'tranche' ? [] : [firstLossCoverShares, account];
6143
6228
  const handleSuccess = useCallback(() => {
6144
6229
  dispatch(setStep(WIDGET_STEP.Done));
6145
6230
  }, [dispatch]);
6146
- if (!trancheVaultContract || !account) {
6147
- return null;
6231
+ if (!account || !contract) {
6232
+ return jsx(LoadingModal, {
6233
+ title: "Transaction Pending"
6234
+ });
6148
6235
  }
6149
6236
  return jsx(TxSendModalV2, {
6150
- contract: trancheVaultContract,
6151
- method: "disburse",
6152
- params: [],
6237
+ contract: contract,
6238
+ method: method,
6239
+ params: params,
6153
6240
  handleSuccess: handleSuccess
6154
6241
  });
6155
6242
  }
@@ -6189,33 +6276,66 @@ function LendWithdrawV2(_ref) {
6189
6276
  step,
6190
6277
  errorMessage
6191
6278
  } = useAppSelector(selectWidgetState);
6192
- const [seniorWithdrawableAmount, refreshSeniorWithdrawableAmount] = useWithdrawableAssetsV2(poolName, 'senior', account, provider);
6193
- const [juniorWithdrawableAmount, refreshJuniorWithdrawableAmount] = useWithdrawableAssetsV2(poolName, 'junior', account, provider);
6279
+ const [withdrawTypes, setWithdrawTypes] = useState([]);
6280
+ const [selectedWithdrawType, setSelectedWithdrawType] = useState();
6281
+ const [seniorWithdrawableAmount, refreshSeniorWithdrawableAmount] = useTrancheWithdrawableAssetsV2(poolName, 'senior', account, provider);
6282
+ const [juniorWithdrawableAmount, refreshJuniorWithdrawableAmount] = useTrancheWithdrawableAssetsV2(poolName, 'junior', account, provider);
6283
+ const isReadyForFlcWithdrawal = usePoolIsReadyForFlcWithdrawalV2(poolName, provider);
6284
+ const [flcStats, refreshFlcStats] = useFirstLossCoverStatsV2(poolName, account, provider);
6194
6285
  const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider);
6195
- const [selectedTranche, setSelectedTranche] = useState();
6196
- const [withdrawAmount, setWithdrawAmount] = useState();
6286
+ const {
6287
+ symbol,
6288
+ decimals
6289
+ } = poolUnderlyingToken || {};
6290
+ const isLoading = !poolInfo || !poolUnderlyingToken || isReadyForFlcWithdrawal === undefined || !seniorWithdrawableAmount || !juniorWithdrawableAmount || !flcStats;
6197
6291
  useEffect(() => {
6198
- if (!step) {
6199
- dispatch(setStep(WIDGET_STEP.ChooseTranche));
6292
+ if (!step && !isLoading) {
6293
+ const items = [];
6294
+ if (seniorWithdrawableAmount.gt(0)) {
6295
+ items.push({
6296
+ label: "Withdraw ".concat(formatBNFixed(seniorWithdrawableAmount, decimals), " ").concat(symbol, " from Senior Tranche"),
6297
+ value: 'senior',
6298
+ type: 'tranche',
6299
+ withdrawableAmount: seniorWithdrawableAmount
6300
+ });
6301
+ }
6302
+ if (juniorWithdrawableAmount.gt(0)) {
6303
+ items.push({
6304
+ label: "Withdraw ".concat(formatBNFixed(juniorWithdrawableAmount, decimals), " ").concat(symbol, " from Junior Tranche"),
6305
+ value: 'junior',
6306
+ type: 'tranche',
6307
+ withdrawableAmount: juniorWithdrawableAmount
6308
+ });
6309
+ }
6310
+ if (isReadyForFlcWithdrawal) {
6311
+ flcStats.filter(flc => flc.totalAssets.gt(0)).forEach(flc => {
6312
+ items.push({
6313
+ label: "Withdraw ".concat(symbol, " from ").concat(capitalizeFirstLetter(FirstLossCoverIndex[flc.firstLossCoverIndex]), " First Loss Cover"),
6314
+ value: String(flc.firstLossCoverIndex),
6315
+ type: 'firstLossCover',
6316
+ withdrawableAmount: flc.totalAssets
6317
+ });
6318
+ });
6319
+ }
6320
+ setWithdrawTypes(items);
6321
+ if (items.length === 1) {
6322
+ setSelectedWithdrawType(items[0]);
6323
+ const step = items[0].type === 'firstLossCover' ? WIDGET_STEP.ChooseAmount : WIDGET_STEP.Transfer;
6324
+ dispatch(setStep(step));
6325
+ } else if (items.length > 1) {
6326
+ dispatch(setStep(WIDGET_STEP.ChooseTranche));
6327
+ }
6200
6328
  }
6201
- }, [dispatch, step]);
6329
+ }, [decimals, dispatch, flcStats, isLoading, isReadyForFlcWithdrawal, juniorWithdrawableAmount, seniorWithdrawableAmount, step, symbol]);
6202
6330
  const handleWithdrawSuccess = useCallback(blockNumber => {
6203
6331
  refreshSeniorWithdrawableAmount();
6204
6332
  refreshJuniorWithdrawableAmount();
6333
+ refreshFlcStats();
6205
6334
  if (handleSuccess) {
6206
6335
  handleSuccess(blockNumber);
6207
6336
  }
6208
- }, [handleSuccess, refreshJuniorWithdrawableAmount, refreshSeniorWithdrawableAmount]);
6209
- const handleChangeTranche = useCallback(tranche => {
6210
- setSelectedTranche(tranche);
6211
- if (tranche === 'senior') {
6212
- setWithdrawAmount(seniorWithdrawableAmount);
6213
- }
6214
- if (tranche === 'junior') {
6215
- setWithdrawAmount(juniorWithdrawableAmount);
6216
- }
6217
- }, [juniorWithdrawableAmount, seniorWithdrawableAmount]);
6218
- if (!poolInfo || !poolUnderlyingToken) {
6337
+ }, [handleSuccess, refreshFlcStats, refreshJuniorWithdrawableAmount, refreshSeniorWithdrawableAmount]);
6338
+ if (isLoading) {
6219
6339
  return null;
6220
6340
  }
6221
6341
  return jsxs(WidgetWrapper, {
@@ -6224,18 +6344,21 @@ function LendWithdrawV2(_ref) {
6224
6344
  handleClose: handleClose,
6225
6345
  handleSuccess: handleWithdrawSuccess,
6226
6346
  children: [step === WIDGET_STEP.ChooseTranche && jsx(ChooseTranche, {
6347
+ poolUnderlyingToken: poolUnderlyingToken,
6348
+ selectedWithdrawType: selectedWithdrawType,
6349
+ withdrawTypes: withdrawTypes,
6350
+ changeWithdrawType: setSelectedWithdrawType
6351
+ }), step === WIDGET_STEP.ChooseAmount && selectedWithdrawType && jsx(ChooseAmount$3, {
6227
6352
  poolInfo: poolInfo,
6228
6353
  poolUnderlyingToken: poolUnderlyingToken,
6229
- selectedTranche: selectedTranche,
6230
- changeTranche: handleChangeTranche,
6231
- seniorWithdrawableAmount: seniorWithdrawableAmount,
6232
- juniorWithdrawableAmount: juniorWithdrawableAmount
6233
- }), step === WIDGET_STEP.Transfer && selectedTranche && jsx(Transfer$3, {
6354
+ selectedWithdrawType: selectedWithdrawType
6355
+ }), step === WIDGET_STEP.Transfer && selectedWithdrawType && jsx(Transfer$3, {
6234
6356
  poolInfo: poolInfo,
6235
- selectedTranche: selectedTranche
6236
- }), step === WIDGET_STEP.Done && withdrawAmount && jsx(Done, {
6237
6357
  poolUnderlyingToken: poolUnderlyingToken,
6238
- withdrawAmount: withdrawAmount,
6358
+ selectedWithdrawType: selectedWithdrawType
6359
+ }), step === WIDGET_STEP.Done && selectedWithdrawType && jsx(Done, {
6360
+ poolUnderlyingToken: poolUnderlyingToken,
6361
+ withdrawAmount: selectedWithdrawType.withdrawableAmount,
6239
6362
  handleAction: handleClose
6240
6363
  }), step === WIDGET_STEP.Error && jsx(ErrorModal, {
6241
6364
  title: "Withdraw",