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

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.
Files changed (35) hide show
  1. package/API.md +69 -22
  2. package/dist/cjs/index.cjs +2105 -2188
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/index.d.ts +45 -14
  5. package/dist/index.js +2105 -2189
  6. package/dist/index.js.map +1 -1
  7. package/package.json +4 -4
  8. package/src/components/CreditLine/borrowV2/3-Transfer.tsx +1 -1
  9. package/src/components/CreditLine/paymentV2/1-ChooseAmount.tsx +5 -0
  10. package/src/components/InputAmountModal.tsx +32 -5
  11. package/src/components/Lend/{withdrawV2 → addRedemptionV2}/1-ChooseTranche.tsx +25 -30
  12. package/src/components/Lend/addRedemptionV2/2-ChooseAmount.tsx +62 -0
  13. package/src/components/Lend/{redeemV2 → addRedemptionV2}/3-Transfer.tsx +7 -12
  14. package/src/components/Lend/addRedemptionV2/4-Done.tsx +20 -0
  15. package/src/components/Lend/addRedemptionV2/index.tsx +172 -0
  16. package/src/components/Lend/cancelRedemptionV2 /1-Transfer.tsx +51 -0
  17. package/src/components/Lend/cancelRedemptionV2 /2-Done.tsx +29 -0
  18. package/src/components/Lend/cancelRedemptionV2 /index.tsx +120 -0
  19. package/src/components/Lend/supplyV2/1-ChooseTranche.tsx +23 -21
  20. package/src/components/Lend/supplyV2/3-ChooseAmount.tsx +20 -30
  21. package/src/components/Lend/supplyV2/4-ApproveAllowance.tsx +2 -15
  22. package/src/components/Lend/supplyV2/5-Transfer.tsx +14 -58
  23. package/src/components/Lend/supplyV2/6-Success.tsx +5 -2
  24. package/src/components/Lend/supplyV2/index.tsx +31 -59
  25. package/src/components/Lend/withdrawV2/1-ConfirmTransfer.tsx +135 -0
  26. package/src/components/Lend/withdrawV2/2-Transfer.tsx +50 -0
  27. package/src/components/Lend/withdrawV2/index.tsx +89 -130
  28. package/src/index.tsx +44 -15
  29. package/src/components/Lend/redeemV2/1-ChooseAction.tsx +0 -237
  30. package/src/components/Lend/redeemV2/2-ChooseAmount.tsx +0 -101
  31. package/src/components/Lend/redeemV2/4-Done.tsx +0 -33
  32. package/src/components/Lend/redeemV2/index.tsx +0 -207
  33. package/src/components/Lend/withdrawV2/2-ChooseAmount.tsx +0 -88
  34. package/src/components/Lend/withdrawV2/3-Transfer.tsx +0 -110
  35. /package/src/components/Lend/withdrawV2/{4-Done.tsx → 3-Done.tsx} +0 -0
@@ -1,110 +0,0 @@
1
- import {
2
- FirstLossCoverIndex,
3
- getFirstLossCoverContractV2,
4
- getTrancheVaultContractV2,
5
- PoolInfoV2,
6
- TrancheType,
7
- UnderlyingTokenInfo,
8
- } from '@huma-finance/shared'
9
- import { useWeb3React } from '@web3-react/core'
10
- import { BigNumber, ethers } from 'ethers'
11
- import React, { useCallback, useEffect, useState } from 'react'
12
-
13
- import { WithdrawType } from '.'
14
- import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
15
- import { setStep } from '../../../store/widgets.reducers'
16
- import { selectWidgetState } from '../../../store/widgets.selectors'
17
- import { WIDGET_STEP } from '../../../store/widgets.store'
18
- import { LoadingModal } from '../../LoadingModal'
19
- import { TxSendModalV2 } from '../../TxSendModalV2'
20
-
21
- type Props = {
22
- poolInfo: PoolInfoV2
23
- poolUnderlyingToken: UnderlyingTokenInfo
24
- selectedWithdrawType: WithdrawType
25
- }
26
-
27
- export function Transfer({
28
- poolInfo,
29
- poolUnderlyingToken,
30
- selectedWithdrawType,
31
- }: Props): React.ReactElement | null {
32
- const dispatch = useAppDispatch()
33
- const { account, provider } = useWeb3React()
34
- const { withdrawAmount } = useAppSelector(selectWidgetState)
35
- const [firstLossCoverShares, setFirstLossCoverShares] = React.useState<
36
- BigNumber | undefined
37
- >(undefined)
38
- const [contract, setContract] = useState<ethers.Contract | undefined>(
39
- undefined,
40
- )
41
-
42
- useEffect(() => {
43
- const fetchData = async () => {
44
- if (account) {
45
- if (selectedWithdrawType.type === 'tranche') {
46
- const trancheVaultContract = await getTrancheVaultContractV2(
47
- poolInfo.poolName,
48
- selectedWithdrawType.value as TrancheType,
49
- provider,
50
- account,
51
- )
52
- if (trancheVaultContract) {
53
- setContract(trancheVaultContract)
54
- }
55
- }
56
- if (selectedWithdrawType.type === 'firstLossCover') {
57
- const firstLossCoverContract = await getFirstLossCoverContractV2(
58
- poolInfo.poolName,
59
- Number(selectedWithdrawType.value) as FirstLossCoverIndex,
60
- provider,
61
- account,
62
- )
63
- if (firstLossCoverContract) {
64
- const shares = await firstLossCoverContract.convertToShares(
65
- ethers.utils.parseUnits(
66
- String(withdrawAmount),
67
- poolUnderlyingToken.decimals,
68
- ),
69
- )
70
- setFirstLossCoverShares(shares)
71
- setContract(firstLossCoverContract)
72
- }
73
- }
74
- }
75
- }
76
- fetchData()
77
- }, [
78
- account,
79
- poolInfo.poolName,
80
- poolUnderlyingToken.decimals,
81
- provider,
82
- selectedWithdrawType.type,
83
- selectedWithdrawType.value,
84
- withdrawAmount,
85
- ])
86
-
87
- const method =
88
- selectedWithdrawType.type === 'tranche' ? 'disburse' : 'redeemCover'
89
- const params =
90
- selectedWithdrawType.type === 'tranche'
91
- ? []
92
- : [firstLossCoverShares, account]
93
-
94
- const handleSuccess = useCallback(() => {
95
- dispatch(setStep(WIDGET_STEP.Done))
96
- }, [dispatch])
97
-
98
- if (!account || !contract) {
99
- return <LoadingModal title='Transaction Pending' />
100
- }
101
-
102
- return (
103
- <TxSendModalV2
104
- contract={contract}
105
- method={method}
106
- params={params}
107
- handleSuccess={handleSuccess}
108
- />
109
- )
110
- }