@huma-finance/widgets 0.0.48-beta.187 → 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';
@@ -27,8 +27,6 @@ import TableCell from '@mui/material/TableCell';
27
27
  import TableContainer from '@mui/material/TableContainer';
28
28
  import TableHead from '@mui/material/TableHead';
29
29
  import TableRow from '@mui/material/TableRow';
30
- import { RequestNetwork } from '@requestnetwork/request-client.js';
31
- import { getReceivableTokenIdForRequest } from '@requestnetwork/payment-processor';
32
30
 
33
31
  function _typeof$1(obj) {
34
32
  "@babel/helpers - typeof";
@@ -2309,7 +2307,7 @@ function TxDoneModal(_ref) {
2309
2307
  });
2310
2308
  }
2311
2309
 
2312
- function Success$8(_ref) {
2310
+ function Success$7(_ref) {
2313
2311
  var poolInfo = _ref.poolInfo,
2314
2312
  handleAction = _ref.handleAction;
2315
2313
  var _poolInfo$poolUnderly = poolInfo.poolUnderlyingToken,
@@ -2373,7 +2371,7 @@ function CreditLineApprove(_ref) {
2373
2371
  children: [step === WIDGET_STEP.ApproveAllowance && jsx(ApproveAllowance$5, {
2374
2372
  poolInfo: poolInfo,
2375
2373
  amount: amount
2376
- }), step === WIDGET_STEP.Done && jsx(Success$8, {
2374
+ }), step === WIDGET_STEP.Done && jsx(Success$7, {
2377
2375
  poolInfo: poolInfo,
2378
2376
  handleAction: handleClose
2379
2377
  }), step === WIDGET_STEP.Error && jsx(ErrorModal, {
@@ -2477,7 +2475,7 @@ function SignIn() {
2477
2475
  }
2478
2476
 
2479
2477
  var _templateObject$b, _templateObject2$9, _templateObject3$7, _templateObject4$6, _templateObject5$3, _templateObject6$2, _templateObject7$2;
2480
- function Evaluation$4(_ref) {
2478
+ function Evaluation$3(_ref) {
2481
2479
  var poolInfo = _ref.poolInfo,
2482
2480
  handleApprove = _ref.handleApprove;
2483
2481
  var theme = useTheme();
@@ -2776,7 +2774,7 @@ function ChooseAmountModal(_ref) {
2776
2774
  });
2777
2775
  }
2778
2776
 
2779
- function ChooseAmount$7(_ref) {
2777
+ function ChooseAmount$6(_ref) {
2780
2778
  var poolInfo = _ref.poolInfo,
2781
2779
  accountStats = _ref.accountStats;
2782
2780
  var dispatch = useAppDispatch();
@@ -2883,7 +2881,7 @@ function TxSendModal(_ref) {
2883
2881
  });
2884
2882
  }
2885
2883
 
2886
- function Transfer$7(_ref) {
2884
+ function Transfer$6(_ref) {
2887
2885
  var poolInfo = _ref.poolInfo;
2888
2886
  var dispatch = useAppDispatch();
2889
2887
  var reset = useResetAtom(txAtom);
@@ -2903,7 +2901,7 @@ function Transfer$7(_ref) {
2903
2901
  });
2904
2902
  }
2905
2903
 
2906
- function Success$7(_ref) {
2904
+ function Success$6(_ref) {
2907
2905
  var poolInfo = _ref.poolInfo,
2908
2906
  creditRecord = _ref.creditRecord,
2909
2907
  handleAction = _ref.handleAction,
@@ -3376,17 +3374,17 @@ function CreditLineBorrow(_ref) {
3376
3374
  loadingTitle: "Borrow",
3377
3375
  handleClose: handleClose,
3378
3376
  handleSuccess: handleSuccess,
3379
- children: [step === WIDGET_STEP.Evaluation && jsx(Evaluation$4, {
3377
+ children: [step === WIDGET_STEP.Evaluation && jsx(Evaluation$3, {
3380
3378
  poolInfo: poolInfo,
3381
3379
  handleApprove: approveCallback
3382
- }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$7, {
3380
+ }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$6, {
3383
3381
  poolInfo: poolInfo,
3384
3382
  accountStats: accountStats
3385
3383
  }), step === WIDGET_STEP.ApproveAllowance && jsx(ApproveAllowance$4, {
3386
3384
  poolInfo: poolInfo
3387
- }), step === WIDGET_STEP.Transfer && jsx(Transfer$7, {
3385
+ }), step === WIDGET_STEP.Transfer && jsx(Transfer$6, {
3388
3386
  poolInfo: poolInfo
3389
- }), step === WIDGET_STEP.Done && jsx(Success$7, {
3387
+ }), step === WIDGET_STEP.Done && jsx(Success$6, {
3390
3388
  poolInfo: poolInfo,
3391
3389
  handleAction: setupNotificationsOrClose,
3392
3390
  creditRecord: creditRecord,
@@ -3401,7 +3399,7 @@ function CreditLineBorrow(_ref) {
3401
3399
  });
3402
3400
  }
3403
3401
 
3404
- function ChooseAmount$6(_ref) {
3402
+ function ChooseAmount$5(_ref) {
3405
3403
  var payoffAmount = _ref.payoffAmount,
3406
3404
  totalDueAmount = _ref.totalDueAmount,
3407
3405
  poolInfo = _ref.poolInfo;
@@ -3460,7 +3458,7 @@ function ApproveAllowance$3(_ref) {
3460
3458
  });
3461
3459
  }
3462
3460
 
3463
- function Transfer$6(_ref) {
3461
+ function Transfer$5(_ref) {
3464
3462
  var poolInfo = _ref.poolInfo;
3465
3463
  var dispatch = useAppDispatch();
3466
3464
  var _useWeb3React = useWeb3React(),
@@ -3480,7 +3478,7 @@ function Transfer$6(_ref) {
3480
3478
  });
3481
3479
  }
3482
3480
 
3483
- function Success$6(_ref) {
3481
+ function Success$5(_ref) {
3484
3482
  var poolInfo = _ref.poolInfo,
3485
3483
  handleAction = _ref.handleAction;
3486
3484
  var _poolInfo$poolUnderly = poolInfo.poolUnderlyingToken,
@@ -3543,15 +3541,15 @@ function CreditLinePayment(_ref) {
3543
3541
  loadingTitle: "Make Payment",
3544
3542
  handleClose: handleClose,
3545
3543
  handleSuccess: handleSuccess,
3546
- children: [step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$6, {
3544
+ children: [step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$5, {
3547
3545
  poolInfo: poolInfo,
3548
3546
  payoffAmount: payoffAmount,
3549
3547
  totalDueAmount: totalDueAmount
3550
3548
  }), step === WIDGET_STEP.ApproveAllowance && jsx(ApproveAllowance$3, {
3551
3549
  poolInfo: poolInfo
3552
- }), step === WIDGET_STEP.Transfer && jsx(Transfer$6, {
3550
+ }), step === WIDGET_STEP.Transfer && jsx(Transfer$5, {
3553
3551
  poolInfo: poolInfo
3554
- }), step === WIDGET_STEP.Done && jsx(Success$6, {
3552
+ }), step === WIDGET_STEP.Done && jsx(Success$5, {
3555
3553
  poolInfo: poolInfo,
3556
3554
  handleAction: handleClose
3557
3555
  }), step === WIDGET_STEP.Error && jsx(ErrorModal, {
@@ -3562,7 +3560,7 @@ function CreditLinePayment(_ref) {
3562
3560
  });
3563
3561
  }
3564
3562
 
3565
- function Evaluation$3(_ref) {
3563
+ function Evaluation$2(_ref) {
3566
3564
  var poolInfo = _ref.poolInfo,
3567
3565
  tokenId = _ref.tokenId;
3568
3566
  var _useEA = useEA(),
@@ -3595,7 +3593,7 @@ function Evaluation$3(_ref) {
3595
3593
  });
3596
3594
  }
3597
3595
 
3598
- function ChooseAmount$5(_ref) {
3596
+ function ChooseAmount$4(_ref) {
3599
3597
  var _receivable;
3600
3598
  var poolInfo = _ref.poolInfo,
3601
3599
  accountStats = _ref.accountStats;
@@ -3731,7 +3729,7 @@ function ConfirmTransferModal(_ref) {
3731
3729
  });
3732
3730
  }
3733
3731
 
3734
- function ConfirmTransfer$2() {
3732
+ function ConfirmTransfer$1() {
3735
3733
  var dispatch = useAppDispatch();
3736
3734
  var _useAppSelector = useAppSelector(selectWidgetState),
3737
3735
  borrowAmountNet = _useAppSelector.borrowAmountNet,
@@ -3757,7 +3755,7 @@ function ConfirmTransfer$2() {
3757
3755
  });
3758
3756
  }
3759
3757
 
3760
- function ApproveNFT$1(_ref) {
3758
+ function ApproveNFT(_ref) {
3761
3759
  var poolInfo = _ref.poolInfo,
3762
3760
  tokenId = _ref.tokenId;
3763
3761
  var dispatch = useAppDispatch();
@@ -3794,7 +3792,7 @@ function ApproveNFT$1(_ref) {
3794
3792
  });
3795
3793
  }
3796
3794
 
3797
- function Transfer$5(_ref) {
3795
+ function Transfer$4(_ref) {
3798
3796
  var poolInfo = _ref.poolInfo,
3799
3797
  tokenId = _ref.tokenId;
3800
3798
  var dispatch = useAppDispatch();
@@ -3814,7 +3812,7 @@ function Transfer$5(_ref) {
3814
3812
  });
3815
3813
  }
3816
3814
 
3817
- function Success$5(_ref) {
3815
+ function Success$4(_ref) {
3818
3816
  var handleAction = _ref.handleAction;
3819
3817
  var _useAppSelector = useAppSelector(selectWidgetState),
3820
3818
  borrowAmountNet = _useAppSelector.borrowAmountNet,
@@ -3855,19 +3853,19 @@ function InvoiceFactoringBorrow(_ref) {
3855
3853
  isOpen: true,
3856
3854
  handleClose: handleClose,
3857
3855
  handleSuccess: handleSuccess,
3858
- children: [step === WIDGET_STEP.Evaluation && jsx(Evaluation$3, {
3856
+ children: [step === WIDGET_STEP.Evaluation && jsx(Evaluation$2, {
3859
3857
  poolInfo: poolInfo,
3860
3858
  tokenId: tokenId.toString()
3861
- }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$5, {
3859
+ }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$4, {
3862
3860
  poolInfo: poolInfo,
3863
3861
  accountStats: accountStats
3864
- }), step === WIDGET_STEP.ConfirmTransfer && jsx(ConfirmTransfer$2, {}), step === WIDGET_STEP.ApproveNFT && jsx(ApproveNFT$1, {
3862
+ }), step === WIDGET_STEP.ConfirmTransfer && jsx(ConfirmTransfer$1, {}), step === WIDGET_STEP.ApproveNFT && jsx(ApproveNFT, {
3865
3863
  poolInfo: poolInfo,
3866
3864
  tokenId: tokenId.toString()
3867
- }), step === WIDGET_STEP.Transfer && jsx(Transfer$5, {
3865
+ }), step === WIDGET_STEP.Transfer && jsx(Transfer$4, {
3868
3866
  poolInfo: poolInfo,
3869
3867
  tokenId: tokenId.toString()
3870
- }), step === WIDGET_STEP.Done && jsx(Success$5, {
3868
+ }), step === WIDGET_STEP.Done && jsx(Success$4, {
3871
3869
  handleAction: handleClose
3872
3870
  }), step === WIDGET_STEP.Error && jsx(ErrorModal, {
3873
3871
  title: "Invoice Factoring",
@@ -3877,7 +3875,7 @@ function InvoiceFactoringBorrow(_ref) {
3877
3875
  });
3878
3876
  }
3879
3877
 
3880
- function ChooseAmount$4(_ref) {
3878
+ function ChooseAmount$3(_ref) {
3881
3879
  var creditRecord = _ref.creditRecord,
3882
3880
  poolInfo = _ref.poolInfo;
3883
3881
  var dispatch = useAppDispatch();
@@ -3939,7 +3937,7 @@ function ApproveAllowance$2(_ref) {
3939
3937
  });
3940
3938
  }
3941
3939
 
3942
- function Transfer$4(_ref) {
3940
+ function Transfer$3(_ref) {
3943
3941
  var poolInfo = _ref.poolInfo;
3944
3942
  var dispatch = useAppDispatch();
3945
3943
  var _useWeb3React = useWeb3React(),
@@ -3959,7 +3957,7 @@ function Transfer$4(_ref) {
3959
3957
  });
3960
3958
  }
3961
3959
 
3962
- function Success$4(_ref) {
3960
+ function Success$3(_ref) {
3963
3961
  var poolInfo = _ref.poolInfo,
3964
3962
  handleAction = _ref.handleAction;
3965
3963
  var symbol = poolInfo.poolUnderlyingToken.symbol;
@@ -4002,14 +4000,14 @@ function InvoiceFactoringPayment(_ref) {
4002
4000
  loadingTitle: "Make Payment",
4003
4001
  handleClose: handleClose,
4004
4002
  handleSuccess: handleSuccess,
4005
- children: [step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$4, {
4003
+ children: [step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$3, {
4006
4004
  creditRecord: creditRecord,
4007
4005
  poolInfo: poolInfo
4008
4006
  }), step === WIDGET_STEP.ApproveAllowance && jsx(ApproveAllowance$2, {
4009
4007
  poolInfo: poolInfo
4010
- }), step === WIDGET_STEP.Transfer && jsx(Transfer$4, {
4008
+ }), step === WIDGET_STEP.Transfer && jsx(Transfer$3, {
4011
4009
  poolInfo: poolInfo
4012
- }), step === WIDGET_STEP.Done && jsx(Success$4, {
4010
+ }), step === WIDGET_STEP.Done && jsx(Success$3, {
4013
4011
  poolInfo: poolInfo,
4014
4012
  handleAction: handleClose
4015
4013
  }), step === WIDGET_STEP.Error && jsx(ErrorModal, {
@@ -4493,7 +4491,7 @@ function EvaluationKYC(_ref) {
4493
4491
  });
4494
4492
  }
4495
4493
 
4496
- function Evaluation$2(_ref) {
4494
+ function Evaluation$1(_ref) {
4497
4495
  var _poolInfo$extra;
4498
4496
  var poolInfo = _ref.poolInfo,
4499
4497
  handleClose = _ref.handleClose,
@@ -4512,7 +4510,7 @@ function Evaluation$2(_ref) {
4512
4510
  });
4513
4511
  }
4514
4512
 
4515
- function ChooseAmount$3(_ref) {
4513
+ function ChooseAmount$2(_ref) {
4516
4514
  var allowance = _ref.allowance,
4517
4515
  withdrawlLockoutSeconds = _ref.withdrawlLockoutSeconds,
4518
4516
  underlyingTokenBalance = _ref.underlyingTokenBalance,
@@ -4564,7 +4562,7 @@ function ApproveAllowance$1(_ref) {
4564
4562
  });
4565
4563
  }
4566
4564
 
4567
- function Transfer$3(_ref) {
4565
+ function Transfer$2(_ref) {
4568
4566
  var poolInfo = _ref.poolInfo;
4569
4567
  var dispatch = useAppDispatch();
4570
4568
  var _useAppSelector = useAppSelector(selectWidgetState),
@@ -4582,7 +4580,7 @@ function Transfer$3(_ref) {
4582
4580
  });
4583
4581
  }
4584
4582
 
4585
- function Success$3(_ref) {
4583
+ function Success$2(_ref) {
4586
4584
  var poolInfo = _ref.poolInfo,
4587
4585
  handleAction = _ref.handleAction,
4588
4586
  hasNextStep = _ref.hasNextStep;
@@ -4694,20 +4692,20 @@ function LendSupply(_ref) {
4694
4692
  loadingTitle: "Supply ".concat(poolInfo.poolUnderlyingToken.symbol),
4695
4693
  handleClose: handleClose,
4696
4694
  handleSuccess: handleSupplySuccess,
4697
- children: [step === WIDGET_STEP.Evaluation && jsx(Evaluation$2, {
4695
+ children: [step === WIDGET_STEP.Evaluation && jsx(Evaluation$1, {
4698
4696
  poolInfo: poolInfo,
4699
4697
  handleClose: handleClose,
4700
4698
  handleApproveSuccess: handleApproveSuccess
4701
- }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$3, {
4699
+ }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$2, {
4702
4700
  poolInfo: poolInfo,
4703
4701
  allowance: allowance,
4704
4702
  underlyingTokenBalance: balanceWithoutDecimals,
4705
4703
  withdrawlLockoutSeconds: withdrawlLockoutSeconds
4706
4704
  }), step === WIDGET_STEP.ApproveAllowance && jsx(ApproveAllowance$1, {
4707
4705
  poolInfo: poolInfo
4708
- }), step === WIDGET_STEP.Transfer && jsx(Transfer$3, {
4706
+ }), step === WIDGET_STEP.Transfer && jsx(Transfer$2, {
4709
4707
  poolInfo: poolInfo
4710
- }), step === WIDGET_STEP.Done && jsx(Success$3, {
4708
+ }), step === WIDGET_STEP.Done && jsx(Success$2, {
4711
4709
  poolInfo: poolInfo,
4712
4710
  handleAction: setupNotificationsOrClose,
4713
4711
  hasNextStep: isFirstTimeNotifiUser
@@ -4760,8 +4758,9 @@ function CheckWithdrawable(_ref) {
4760
4758
  });
4761
4759
  }
4762
4760
 
4763
- function ChooseAmount$2(_ref) {
4761
+ function ChooseAmount$1(_ref) {
4764
4762
  var lenderPosition = _ref.lenderPosition,
4763
+ poolBalance = _ref.poolBalance,
4765
4764
  poolInfo = _ref.poolInfo;
4766
4765
  var dispatch = useAppDispatch();
4767
4766
  var poolUnderlyingToken = poolInfo.poolUnderlyingToken;
@@ -4771,7 +4770,9 @@ function ChooseAmount$2(_ref) {
4771
4770
  _useState2 = _slicedToArray(_useState, 2),
4772
4771
  currentAmount = _useState2[0],
4773
4772
  setCurrentAmount = _useState2[1];
4774
- 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);
4775
4776
  var handleChangeAmount = useCallback(function (newAmount) {
4776
4777
  setCurrentAmount(newAmount);
4777
4778
  dispatch(setWithdrawAmount(newAmount));
@@ -4792,7 +4793,7 @@ function ChooseAmount$2(_ref) {
4792
4793
  });
4793
4794
  }
4794
4795
 
4795
- function Transfer$2(_ref) {
4796
+ function Transfer$1(_ref) {
4796
4797
  var poolInfo = _ref.poolInfo;
4797
4798
  var dispatch = useAppDispatch();
4798
4799
  var decimals = poolInfo.poolUnderlyingToken.decimals;
@@ -4810,7 +4811,7 @@ function Transfer$2(_ref) {
4810
4811
  });
4811
4812
  }
4812
4813
 
4813
- function Success$2(_ref) {
4814
+ function Success$1(_ref) {
4814
4815
  var poolInfo = _ref.poolInfo,
4815
4816
  handleAction = _ref.handleAction;
4816
4817
  var _useWeb3React = useWeb3React(),
@@ -4867,17 +4868,22 @@ function LendWithdraw(_ref) {
4867
4868
  _useLenderPosition2 = _slicedToArray(_useLenderPosition, 2),
4868
4869
  lenderPosition = _useLenderPosition2[0],
4869
4870
  refreshLenderPosition = _useLenderPosition2[1];
4871
+ var _usePoolBalance = usePoolBalance(poolName, poolType),
4872
+ _usePoolBalance2 = _slicedToArray(_usePoolBalance, 2),
4873
+ poolBalance = _usePoolBalance2[0],
4874
+ refreshPoolBalance = _usePoolBalance2[1];
4870
4875
  useEffect(function () {
4871
- if (!step && lenderPosition) {
4876
+ if (!step && lenderPosition && poolBalance) {
4872
4877
  dispatch(setStep(WIDGET_STEP.CheckWithdrawable));
4873
4878
  }
4874
- }, [dispatch, lenderPosition, step]);
4879
+ }, [dispatch, lenderPosition, poolBalance, step]);
4875
4880
  var handleWithdrawSuccess = useCallback(function (blockNumber) {
4876
4881
  refreshLenderPosition();
4882
+ refreshPoolBalance();
4877
4883
  if (handleSuccess) {
4878
4884
  handleSuccess(blockNumber);
4879
4885
  }
4880
- }, [handleSuccess, refreshLenderPosition]);
4886
+ }, [handleSuccess, refreshLenderPosition, refreshPoolBalance]);
4881
4887
  if (!poolInfo) {
4882
4888
  return null;
4883
4889
  }
@@ -4888,12 +4894,13 @@ function LendWithdraw(_ref) {
4888
4894
  children: [(!step || step === WIDGET_STEP.CheckWithdrawable) && jsx(CheckWithdrawable, {
4889
4895
  poolInfo: poolInfo,
4890
4896
  handleClose: handleClose
4891
- }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$2, {
4897
+ }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$1, {
4892
4898
  poolInfo: poolInfo,
4893
- lenderPosition: lenderPosition
4894
- }), step === WIDGET_STEP.Transfer && jsx(Transfer$2, {
4899
+ lenderPosition: lenderPosition,
4900
+ poolBalance: poolBalance
4901
+ }), step === WIDGET_STEP.Transfer && jsx(Transfer$1, {
4895
4902
  poolInfo: poolInfo
4896
- }), step === WIDGET_STEP.Done && jsx(Success$2, {
4903
+ }), step === WIDGET_STEP.Done && jsx(Success$1, {
4897
4904
  poolInfo: poolInfo,
4898
4905
  handleAction: handleClose
4899
4906
  }), step === WIDGET_STEP.Error && jsx(ErrorModal, {
@@ -5186,7 +5193,7 @@ function ApolloWrapper(_ref) {
5186
5193
  });
5187
5194
  }
5188
5195
 
5189
- function Evaluation$1(_ref) {
5196
+ function Evaluation(_ref) {
5190
5197
  var poolInfo = _ref.poolInfo,
5191
5198
  payerAddress = _ref.payerAddress,
5192
5199
  superToken = _ref.superToken;
@@ -5220,7 +5227,7 @@ function Evaluation$1(_ref) {
5220
5227
  });
5221
5228
  }
5222
5229
 
5223
- function ChooseAmount$1(_ref) {
5230
+ function ChooseAmount(_ref) {
5224
5231
  var poolInfo = _ref.poolInfo,
5225
5232
  currentFlowRate = _ref.currentFlowRate;
5226
5233
  var dispatch = useAppDispatch();
@@ -5301,7 +5308,7 @@ function ChooseAmount$1(_ref) {
5301
5308
  });
5302
5309
  }
5303
5310
 
5304
- function ConfirmTransfer$1() {
5311
+ function ConfirmTransfer() {
5305
5312
  var dispatch = useAppDispatch();
5306
5313
  var _useWeb3React = useWeb3React(),
5307
5314
  chainId = _useWeb3React.chainId;
@@ -5463,7 +5470,7 @@ function Permit(_ref) {
5463
5470
  });
5464
5471
  }
5465
5472
 
5466
- function Transfer$1(_ref) {
5473
+ function Transfer(_ref) {
5467
5474
  var poolInfo = _ref.poolInfo;
5468
5475
  var dispatch = useAppDispatch();
5469
5476
  var multiSendContract = useMultiSendContract();
@@ -5485,7 +5492,7 @@ function Transfer$1(_ref) {
5485
5492
  });
5486
5493
  }
5487
5494
 
5488
- function Success$1(_ref) {
5495
+ function Success(_ref) {
5489
5496
  var handleAction = _ref.handleAction;
5490
5497
  var _useAppSelector = useAppSelector(selectWidgetState),
5491
5498
  borrowAmount = _useAppSelector.borrowAmount,
@@ -5524,14 +5531,14 @@ function StreamFactoringBorrow(_ref) {
5524
5531
  isOpen: isOpen,
5525
5532
  handleClose: handleClose,
5526
5533
  handleSuccess: handleSuccess,
5527
- children: [step === WIDGET_STEP.Evaluation && jsx(Evaluation$1, {
5534
+ children: [step === WIDGET_STEP.Evaluation && jsx(Evaluation, {
5528
5535
  poolInfo: poolInfo,
5529
5536
  payerAddress: payerAddress,
5530
5537
  superToken: superToken
5531
- }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount$1, {
5538
+ }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount, {
5532
5539
  poolInfo: poolInfo,
5533
5540
  currentFlowRate: currentFlowRate
5534
- }), step === WIDGET_STEP.ConfirmTransfer && jsx(ConfirmTransfer$1, {}), step === WIDGET_STEP.ApproveAllowance && jsx(ApproveAllowance, {
5541
+ }), step === WIDGET_STEP.ConfirmTransfer && jsx(ConfirmTransfer, {}), step === WIDGET_STEP.ApproveAllowance && jsx(ApproveAllowance, {
5535
5542
  poolInfo: poolInfo
5536
5543
  }), step === WIDGET_STEP.Permit && account && chainId && jsx(Permit, {
5537
5544
  poolInfo: poolInfo,
@@ -5539,9 +5546,9 @@ function StreamFactoringBorrow(_ref) {
5539
5546
  chainId: chainId,
5540
5547
  borrower: account,
5541
5548
  superToken: superToken
5542
- }), step === WIDGET_STEP.Transfer && jsx(Transfer$1, {
5549
+ }), step === WIDGET_STEP.Transfer && jsx(Transfer, {
5543
5550
  poolInfo: poolInfo
5544
- }), step === WIDGET_STEP.Done && jsx(Success$1, {
5551
+ }), step === WIDGET_STEP.Done && jsx(Success, {
5545
5552
  handleAction: handleClose
5546
5553
  }), step === WIDGET_STEP.Error && jsx(ErrorModal, {
5547
5554
  title: "Stream Borrowing",
@@ -6341,315 +6348,6 @@ var themeHuma = createTheme(themeBase, {
6341
6348
  components: components(themeBase)
6342
6349
  });
6343
6350
 
6344
- function Evaluation(_ref) {
6345
- var poolInfo = _ref.poolInfo,
6346
- tokenId = _ref.tokenId;
6347
- var _useEA = useEA(),
6348
- checkingEA = _useEA.checkingEA,
6349
- isWalletOwnershipVerificationRequired = _useEA.isWalletOwnershipVerificationRequired,
6350
- isWalletOwnershipVerified = _useEA.isWalletOwnershipVerified;
6351
- var _useWeb3React = useWeb3React(),
6352
- account = _useWeb3React.account,
6353
- chainId = _useWeb3React.chainId;
6354
- useEffect(function () {
6355
- if (account && chainId) {
6356
- checkingEA({
6357
- poolAddress: poolInfo.pool,
6358
- borrowerWalletAddress: account,
6359
- context: {
6360
- receivable: {
6361
- address: poolInfo.assetAddress,
6362
- param: toBigNumber(tokenId).toHexString()
6363
- }
6364
- }
6365
- }, WIDGET_STEP.ChooseAmount);
6366
- }
6367
- }, [account, chainId, checkingEA, poolInfo.assetAddress, poolInfo.pool, tokenId, isWalletOwnershipVerified]);
6368
- if (isWalletOwnershipVerificationRequired) {
6369
- return jsx(SignIn, {});
6370
- }
6371
- return jsx(LoadingModal, {
6372
- title: "Checking Invoice",
6373
- description: "Checking if the invoice qualifies for factoring..."
6374
- });
6375
- }
6376
-
6377
- function ChooseAmount(_ref) {
6378
- var _receivable;
6379
- var poolInfo = _ref.poolInfo,
6380
- accountStats = _ref.accountStats;
6381
- var dispatch = useAppDispatch();
6382
- var creditRecord = accountStats.creditRecord;
6383
- var _useState = useState(0),
6384
- _useState2 = _slicedToArray(_useState, 2),
6385
- chargedFees = _useState2[0],
6386
- setChargedFees = _useState2[1];
6387
- var _useState3 = useState(0),
6388
- _useState4 = _slicedToArray(_useState3, 2),
6389
- currentAmount = _useState4[0],
6390
- setCurrentAmount = _useState4[1];
6391
- var _useAppSelector = useAppSelector(selectWidgetState),
6392
- approval = _useAppSelector.approval;
6393
- var _useFeeManager = useFeeManager(poolInfo.poolName, poolInfo.poolType),
6394
- getFeesCharged = _useFeeManager.getFeesCharged;
6395
- var _useState5 = useState((_receivable = approval.receivable) === null || _receivable === void 0 ? void 0 : _receivable.amountFormatted),
6396
- _useState6 = _slicedToArray(_useState5, 2),
6397
- remainder = _useState6[0],
6398
- setRemainder = _useState6[1];
6399
- var getAvailableCreditLimit = function getAvailableCreditLimit() {
6400
- if (approval && creditRecord) {
6401
- var principal = creditRecord.unbilledPrincipal.add(creditRecord.totalDue).sub(creditRecord.feesAndInterestDue).toNumber();
6402
- return Number(approval.terms.creditLimitFormatted) - principal;
6403
- }
6404
- return 0;
6405
- };
6406
- var handleChangeAmount = useCallback(function (newAmount) {
6407
- if (approval) {
6408
- setCurrentAmount(newAmount);
6409
- setChargedFees(getFeesCharged(newAmount));
6410
- setRemainder(Number(approval.receivable.amountFormatted) - newAmount);
6411
- }
6412
- }, [approval, getFeesCharged]);
6413
- var handleAction = useCallback(function () {
6414
- dispatch(setBorrowInfo({
6415
- borrowAmount: currentAmount,
6416
- borrowAmountBN: upScale(currentAmount, approval === null || approval === void 0 ? void 0 : approval.token.decimal),
6417
- chargedFees: chargedFees,
6418
- remainder: Number(remainder),
6419
- nextStep: WIDGET_STEP.ConfirmTransfer
6420
- }));
6421
- }, [approval === null || approval === void 0 ? void 0 : approval.token.decimal, chargedFees, currentAmount, dispatch, remainder]);
6422
- if (!approval) {
6423
- return null;
6424
- }
6425
- return jsx(ChooseAmountModal, {
6426
- title: "Choose Amount",
6427
- description1: "Access up to 80% of your invoice value",
6428
- description2: "The remainder will be sent to your wallet when the invoice is paid",
6429
- sliderMax: getAvailableCreditLimit(),
6430
- currentAmount: currentAmount,
6431
- tokenSymbol: approval.token.symbol,
6432
- topLeft: "Fees",
6433
- topRight: "".concat(chargedFees, " ").concat(approval.token.symbol),
6434
- downLeft: "Remainder",
6435
- downRight: "".concat(remainder, " ").concat(approval.token.symbol),
6436
- handleChangeAmount: handleChangeAmount,
6437
- handleAction: handleAction
6438
- });
6439
- }
6440
-
6441
- function ConfirmTransfer() {
6442
- var dispatch = useAppDispatch();
6443
- var _useAppSelector = useAppSelector(selectWidgetState),
6444
- borrowAmountNet = _useAppSelector.borrowAmountNet,
6445
- approval = _useAppSelector.approval;
6446
- var handleAction = function handleAction() {
6447
- dispatch(setStep(WIDGET_STEP.ApproveNFT));
6448
- };
6449
- if (isEmpty(borrowAmountNet) || isEmpty(approval)) {
6450
- return null;
6451
- }
6452
- return jsx(ConfirmTransferModal, {
6453
- title: "Confirm transaction details",
6454
- description: "Huma keeps your Invoice NFT as collateral until it's fully paid.",
6455
- items: [{
6456
- leftText: 'Invoice NFT',
6457
- rightText: 'Huma'
6458
- }, {
6459
- leftText: "".concat(borrowAmountNet, " ").concat(approval === null || approval === void 0 ? void 0 : approval.token.symbol),
6460
- rightText: 'You'
6461
- }],
6462
- actionText: "APPROVE TRANSFER",
6463
- handleAction: handleAction
6464
- });
6465
- }
6466
-
6467
- function ApproveNFT(_ref) {
6468
- var poolInfo = _ref.poolInfo,
6469
- tokenId = _ref.tokenId;
6470
- var dispatch = useAppDispatch();
6471
- var _useWeb3React = useWeb3React(),
6472
- provider = _useWeb3React.provider;
6473
- var _useAtom = useAtom(sendTxAtom),
6474
- _useAtom2 = _slicedToArray(_useAtom, 2),
6475
- _useAtom2$ = _useAtom2[0],
6476
- state = _useAtom2$.state,
6477
- txHash = _useAtom2$.txHash,
6478
- send = _useAtom2[1];
6479
- var reset = useResetAtom(txAtom);
6480
- var invoiceNFTContract = useInvoiceNFTContract(poolInfo.poolName);
6481
- useEffect(function () {
6482
- if (state === TxStateType.Success) {
6483
- reset();
6484
- dispatch(setStep(WIDGET_STEP.Transfer));
6485
- }
6486
- }, [dispatch, reset, state]);
6487
- useEffect(function () {
6488
- send({
6489
- contract: invoiceNFTContract,
6490
- method: 'approve',
6491
- params: [poolInfo.pool, tokenId],
6492
- provider: provider
6493
- });
6494
- }, [invoiceNFTContract, poolInfo.pool, provider, send, tokenId]);
6495
- return jsx(LoadingModal, {
6496
- title: "Approve Invoice Transfer",
6497
- description: "Waiting for approval confirmation...",
6498
- children: jsx(ViewOnExplorer, {
6499
- txHash: txHash
6500
- })
6501
- });
6502
- }
6503
-
6504
- function Transfer(_ref) {
6505
- var poolInfo = _ref.poolInfo,
6506
- tokenId = _ref.tokenId;
6507
- var dispatch = useAppDispatch();
6508
- var decimals = poolInfo.poolUnderlyingToken.decimals;
6509
- var _useAppSelector = useAppSelector(selectWidgetState),
6510
- borrowAmount = _useAppSelector.borrowAmount;
6511
- var requestLoanBigNumber = toBigNumber(upScale(borrowAmount, decimals));
6512
- var handleSuccess = useCallback(function () {
6513
- dispatch(setStep(WIDGET_STEP.Done));
6514
- }, [dispatch]);
6515
- return jsx(TxSendModal, {
6516
- poolInfo: poolInfo,
6517
- title: "Transfer Invoice and Money",
6518
- method: "drawdownWithReceivable",
6519
- params: [requestLoanBigNumber, poolInfo.assetAddress, tokenId],
6520
- handleSuccess: handleSuccess
6521
- });
6522
- }
6523
-
6524
- function Success(_ref) {
6525
- var handleAction = _ref.handleAction;
6526
- var _useAppSelector = useAppSelector(selectWidgetState),
6527
- borrowAmountNet = _useAppSelector.borrowAmountNet,
6528
- remainder = _useAppSelector.remainder,
6529
- approval = _useAppSelector.approval;
6530
- var content = ["".concat(borrowAmountNet, " ").concat(approval === null || approval === void 0 ? void 0 : approval.token.symbol, " is now in your wallet."), "The remaining ".concat(remainder, " ").concat(approval === null || approval === void 0 ? void 0 : approval.token.symbol, " will be sent to your wallet when the invoice is paid.")];
6531
- return jsx(TxDoneModal, {
6532
- handleAction: handleAction,
6533
- content: content
6534
- });
6535
- }
6536
-
6537
- function RequestNetworkInvoiceFactoringBorrow(_ref) {
6538
- var poolNameStr = _ref.poolName,
6539
- poolTypeStr = _ref.poolType,
6540
- requestId = _ref.requestId,
6541
- handleClose = _ref.handleClose,
6542
- handleSuccess = _ref.handleSuccess;
6543
- var dispatch = useDispatch();
6544
- var _useWeb3React = useWeb3React(),
6545
- account = _useWeb3React.account,
6546
- provider = _useWeb3React.provider;
6547
- var poolName = POOL_NAME[poolNameStr];
6548
- var poolType = POOL_TYPE[poolTypeStr];
6549
- var poolInfo = usePoolInfo(poolName, poolType);
6550
- var _useAppSelector = useAppSelector(selectWidgetState),
6551
- step = _useAppSelector.step,
6552
- errorMessage = _useAppSelector.errorMessage;
6553
- var _useAccountStats = useAccountStats(poolName, poolType, account),
6554
- _useAccountStats2 = _slicedToArray(_useAccountStats, 1),
6555
- accountStats = _useAccountStats2[0];
6556
- var _useState = useState(),
6557
- _useState2 = _slicedToArray(_useState, 2),
6558
- tokenId = _useState2[0],
6559
- setTokenId = _useState2[1];
6560
- var _useState3 = useState(true),
6561
- _useState4 = _slicedToArray(_useState3, 2),
6562
- isLoading = _useState4[0],
6563
- setIsLoading = _useState4[1];
6564
- useEffect(function () {
6565
- dispatch(setStep(WIDGET_STEP.Evaluation));
6566
- }, [dispatch]);
6567
- useEffect(function () {
6568
- if (provider == null) {
6569
- return function () {}; // Return empty func to satisty consistent return lint rule
6570
- }
6571
-
6572
- // Refetch every 5 seconds until requestData is non-null
6573
- var interval = setInterval(function () {
6574
- function getInvoice() {
6575
- return _getInvoice.apply(this, arguments);
6576
- }
6577
- function _getInvoice() {
6578
- _getInvoice = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
6579
- var requestNetwork, request, requestData, tokenId;
6580
- return regenerator.wrap(function _callee$(_context) {
6581
- while (1) switch (_context.prev = _context.next) {
6582
- case 0:
6583
- if (!(provider == null)) {
6584
- _context.next = 2;
6585
- break;
6586
- }
6587
- return _context.abrupt("return");
6588
- case 2:
6589
- requestNetwork = new RequestNetwork({
6590
- nodeConnectionConfig: {
6591
- baseURL: "https://xdai.gateway.request.network/"
6592
- }
6593
- });
6594
- _context.next = 5;
6595
- return requestNetwork.fromRequestId(requestId);
6596
- case 5:
6597
- request = _context.sent;
6598
- requestData = request.getData();
6599
- _context.next = 9;
6600
- return getReceivableTokenIdForRequest(requestData, provider);
6601
- case 9:
6602
- tokenId = _context.sent;
6603
- // Check if token ID exists yet for this request
6604
- if (tokenId) {
6605
- setTokenId(tokenId);
6606
- setIsLoading(false);
6607
- clearInterval(interval);
6608
- }
6609
- case 11:
6610
- case "end":
6611
- return _context.stop();
6612
- }
6613
- }, _callee);
6614
- }));
6615
- return _getInvoice.apply(this, arguments);
6616
- }
6617
- getInvoice();
6618
- }, 5000);
6619
- return function () {
6620
- return clearInterval(interval);
6621
- };
6622
- }, [provider, requestId]);
6623
- if (!poolInfo) {
6624
- return null;
6625
- }
6626
- return jsxs(WidgetWrapper, {
6627
- isOpen: true,
6628
- isLoading: isLoading,
6629
- handleClose: handleClose,
6630
- handleSuccess: handleSuccess,
6631
- children: [step === WIDGET_STEP.Evaluation && jsx(Evaluation, {
6632
- poolInfo: poolInfo,
6633
- tokenId: tokenId.toString()
6634
- }), step === WIDGET_STEP.ChooseAmount && jsx(ChooseAmount, {
6635
- poolInfo: poolInfo,
6636
- accountStats: accountStats
6637
- }), step === WIDGET_STEP.ConfirmTransfer && jsx(ConfirmTransfer, {}), step === WIDGET_STEP.ApproveNFT && jsx(ApproveNFT, {
6638
- poolInfo: poolInfo,
6639
- tokenId: tokenId.toString()
6640
- }), step === WIDGET_STEP.Transfer && jsx(Transfer, {
6641
- poolInfo: poolInfo,
6642
- tokenId: tokenId.toString()
6643
- }), step === WIDGET_STEP.Done && jsx(Success, {
6644
- handleAction: handleClose
6645
- }), step === WIDGET_STEP.Error && jsx(ErrorModal, {
6646
- title: "Invoice Factoring",
6647
- errorMessage: errorMessage,
6648
- handleOk: handleClose
6649
- })]
6650
- });
6651
- }
6652
-
6653
6351
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6654
6352
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6655
6353
  function Widget(props) {
@@ -6675,25 +6373,6 @@ function Widget(props) {
6675
6373
  });
6676
6374
  }
6677
6375
 
6678
- /**
6679
- * Invoice factoring pool borrow widget props
6680
- * @typedef {Object} RequestNetworkInvoiceFactoringBorrowWidgetProps
6681
- * @property {RequestNetworkInvoiceFactoringBorrowProps} RequestNetworkInvoiceFactoringBorrowProps - Invoice factoring pool borrow props.
6682
- * @property {WidgetProps} WidgetProps - Widget general props.
6683
- */
6684
-
6685
- /**
6686
- * Invoice factoring borrow widget
6687
- *
6688
- * @param {RequestNetworkInvoiceFactoringBorrowWidgetProps} props - The invoice factoring pool borrow widget props.
6689
- * @returns Invoice factoring pool borrow widget component
6690
- */
6691
- function RequestNetworkInvoiceFactoringBorrowWidget(props) {
6692
- return jsx(Widget, _objectSpread(_objectSpread({}, props), {}, {
6693
- children: jsx(RequestNetworkInvoiceFactoringBorrow, _objectSpread({}, props))
6694
- }));
6695
- }
6696
-
6697
6376
  /**
6698
6377
  * Invoice factoring pool borrow widget props
6699
6378
  * @typedef {Object} InvoiceFactoringBorrowWidgetProps
@@ -6840,5 +6519,5 @@ function SuperfluidFactoringWidget(props) {
6840
6519
  }));
6841
6520
  }
6842
6521
 
6843
- export { CreditLineApproveWidget, CreditLineBorrowWidget, CreditLinePaymentWidget, InvoiceFactoringBorrowWidget, InvoiceFactoringPaymentWidget, LendSupplyWidget, LendWithdrawWidget, RequestNetworkInvoiceFactoringBorrowWidget, SuperfluidFactoringWidget };
6522
+ export { CreditLineApproveWidget, CreditLineBorrowWidget, CreditLinePaymentWidget, InvoiceFactoringBorrowWidget, InvoiceFactoringPaymentWidget, LendSupplyWidget, LendWithdrawWidget, SuperfluidFactoringWidget };
6844
6523
  //# sourceMappingURL=index.js.map