@huma-finance/widgets 0.0.48-beta.292 → 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.
@@ -1,10 +1,4 @@
1
- import {
2
- formatBNFixed,
3
- getTrancheVaultContractV2,
4
- PoolInfoV2,
5
- TrancheType,
6
- UnderlyingTokenInfo,
7
- } from '@huma-finance/shared'
1
+ import { UnderlyingTokenInfo } from '@huma-finance/shared'
8
2
  import {
9
3
  css,
10
4
  FormControl,
@@ -14,86 +8,31 @@ import {
14
8
  RadioGroup,
15
9
  useTheme,
16
10
  } from '@mui/material'
17
- import { useWeb3React } from '@web3-react/core'
18
- import { BigNumber } from 'ethers'
19
- import React, { useEffect, useState } from 'react'
11
+ import React from 'react'
20
12
 
13
+ import { WithdrawType } from '.'
21
14
  import { useAppDispatch } from '../../../hooks/useRedux'
22
15
  import { setStep } from '../../../store/widgets.reducers'
23
16
  import { WIDGET_STEP } from '../../../store/widgets.store'
24
17
  import { BottomButton } from '../../BottomButton'
25
- import { LoadingModal } from '../../LoadingModal'
26
18
  import { WrapperModal } from '../../WrapperModal'
27
19
 
28
20
  type Props = {
29
- poolInfo: PoolInfoV2
30
21
  poolUnderlyingToken: UnderlyingTokenInfo
31
- selectedTranche: TrancheType | undefined
32
- seniorWithdrawableAmount: BigNumber | undefined
33
- juniorWithdrawableAmount: BigNumber | undefined
34
- changeTranche: (tranche: TrancheType) => void
22
+ selectedWithdrawType: WithdrawType | undefined
23
+ withdrawTypes: WithdrawType[]
24
+ changeWithdrawType: (WithdrawType: WithdrawType) => void
35
25
  }
36
26
 
37
27
  export function ChooseTranche({
38
- poolInfo,
39
28
  poolUnderlyingToken,
40
- selectedTranche,
41
- seniorWithdrawableAmount,
42
- juniorWithdrawableAmount,
43
- changeTranche,
29
+ selectedWithdrawType,
30
+ withdrawTypes,
31
+ changeWithdrawType,
44
32
  }: Props): React.ReactElement | null {
45
33
  const theme = useTheme()
46
34
  const dispatch = useAppDispatch()
47
- const { provider } = useWeb3React()
48
- const { symbol, decimals } = poolUnderlyingToken
49
- const [seniorWithdrawableShares, setSeniorWithdrawableShares] = useState(
50
- BigNumber.from(0),
51
- )
52
- const [juniorWithdrawableShares, setJuniorWithdrawableShares] = useState(
53
- BigNumber.from(0),
54
- )
55
-
56
- const isLoading =
57
- seniorWithdrawableAmount === undefined ||
58
- juniorWithdrawableAmount === undefined
59
-
60
- useEffect(() => {
61
- const fetchData = async () => {
62
- if (seniorWithdrawableAmount?.gt(0)) {
63
- const seniorVaultContract = await getTrancheVaultContractV2(
64
- poolInfo.poolName,
65
- 'senior',
66
- provider,
67
- )
68
- if (seniorVaultContract) {
69
- const shares = await seniorVaultContract.convertToShares(
70
- seniorWithdrawableAmount,
71
- )
72
- setSeniorWithdrawableShares(shares)
73
- }
74
- }
75
- }
76
- fetchData()
77
- }, [poolInfo.poolName, provider, seniorWithdrawableAmount])
78
-
79
- useEffect(() => {
80
- const fetchData = async () => {
81
- if (juniorWithdrawableAmount?.gt(0)) {
82
- const juniorVaultContract = await getTrancheVaultContractV2(
83
- poolInfo.poolName,
84
- 'senior',
85
- provider,
86
- )
87
- if (juniorVaultContract) {
88
- const shares = await juniorVaultContract.convertToShares(
89
- juniorWithdrawableAmount,
90
- )
91
- setJuniorWithdrawableShares(shares)
92
- }
93
- }
94
- }
95
- fetchData()
96
- }, [poolInfo.poolName, provider, juniorWithdrawableAmount])
35
+ const { symbol } = poolUnderlyingToken
97
36
 
98
37
  const styles = {
99
38
  subTitle: css`
@@ -122,41 +61,21 @@ export function ChooseTranche({
122
61
  `,
123
62
  }
124
63
 
125
- const handleNext = () => {
126
- dispatch(setStep(WIDGET_STEP.Transfer))
64
+ const handleChangeWithdrawType = (withdrawTypeValue: string | number) => {
65
+ const withdrawType = withdrawTypes.find(
66
+ (item) => item.value === withdrawTypeValue,
67
+ )
68
+ if (withdrawType) {
69
+ changeWithdrawType(withdrawType)
70
+ }
127
71
  }
128
72
 
129
- const items: {
130
- label: string
131
- value: TrancheType
132
- disabled: boolean | undefined
133
- }[] = [
134
- {
135
- label: `Withdraw ${formatBNFixed(
136
- seniorWithdrawableAmount,
137
- decimals,
138
- )} ${symbol} from Senior vault (${formatBNFixed(
139
- seniorWithdrawableShares,
140
- decimals,
141
- )} shares)`,
142
- value: 'senior',
143
- disabled: seniorWithdrawableAmount?.lte(0) ?? true,
144
- },
145
- {
146
- label: `Withdraw ${formatBNFixed(
147
- juniorWithdrawableAmount,
148
- decimals,
149
- )} ${symbol} from Junior vault (${formatBNFixed(
150
- juniorWithdrawableShares,
151
- decimals,
152
- )} shares)`,
153
- value: 'junior',
154
- disabled: juniorWithdrawableAmount?.lte(0) ?? true,
155
- },
156
- ]
157
-
158
- if (isLoading) {
159
- return <LoadingModal title={`Withdraw ${symbol}`} />
73
+ const handleNext = () => {
74
+ if (selectedWithdrawType?.type === 'firstLossCover') {
75
+ dispatch(setStep(WIDGET_STEP.ChooseAmount))
76
+ } else {
77
+ dispatch(setStep(WIDGET_STEP.Transfer))
78
+ }
160
79
  }
161
80
 
162
81
  return (
@@ -167,13 +86,12 @@ export function ChooseTranche({
167
86
  aria-labelledby='buttons-group-label'
168
87
  name='radio-buttons-group'
169
88
  css={styles.radioGroup}
170
- onChange={(e) => changeTranche(e.target.value as TrancheType)}
89
+ onChange={(e) => handleChangeWithdrawType(e.target.value)}
171
90
  >
172
- {items.map((item) => (
91
+ {withdrawTypes.map((item) => (
173
92
  <FormControlLabel
174
93
  key={item.label}
175
94
  value={item.value}
176
- disabled={item.disabled}
177
95
  control={
178
96
  <Radio
179
97
  sx={{
@@ -191,7 +109,7 @@ export function ChooseTranche({
191
109
  </FormControl>
192
110
  <BottomButton
193
111
  variant='contained'
194
- disabled={!selectedTranche}
112
+ disabled={!selectedWithdrawType}
195
113
  onClick={handleNext}
196
114
  >
197
115
  NEXT
@@ -0,0 +1,88 @@
1
+ import {
2
+ FirstLossCoverIndex,
3
+ getFirstLossCoverContractV2,
4
+ PoolInfoV2,
5
+ UnderlyingTokenInfo,
6
+ } from '@huma-finance/shared'
7
+ import { useWeb3React } from '@web3-react/core'
8
+ import { ethers } from 'ethers'
9
+ import React, { useEffect, useState } from 'react'
10
+
11
+ import { WithdrawType } from '.'
12
+ import { useAppDispatch } from '../../../hooks/useRedux'
13
+ import { setStep, setWithdrawAmount } from '../../../store/widgets.reducers'
14
+ import { WIDGET_STEP } from '../../../store/widgets.store'
15
+ import { InputAmountModal } from '../../InputAmountModal'
16
+
17
+ type Props = {
18
+ poolInfo: PoolInfoV2
19
+ poolUnderlyingToken: UnderlyingTokenInfo
20
+ selectedWithdrawType: WithdrawType
21
+ }
22
+
23
+ export function ChooseAmount({
24
+ poolInfo,
25
+ poolUnderlyingToken,
26
+ selectedWithdrawType,
27
+ }: Props): React.ReactElement | null {
28
+ const dispatch = useAppDispatch()
29
+ const { provider } = useWeb3React()
30
+ const { symbol } = poolUnderlyingToken
31
+ const [sharePrice, setSharePrice] = useState(0)
32
+ const [currentAmount, setCurrentAmount] = useState<number>(0)
33
+ const [currentShares, setCurrentShares] = useState<number>(0)
34
+ const maxAmountFormatted = ethers.utils.formatUnits(
35
+ selectedWithdrawType.withdrawableAmount,
36
+ poolUnderlyingToken.decimals,
37
+ )
38
+
39
+ useEffect(() => {
40
+ if (selectedWithdrawType.withdrawableAmount.gt(0)) {
41
+ const fetchData = async () => {
42
+ const firstLossCoverContract = await getFirstLossCoverContractV2(
43
+ poolInfo.poolName,
44
+ Number(selectedWithdrawType.value) as FirstLossCoverIndex,
45
+ provider,
46
+ )
47
+ if (firstLossCoverContract) {
48
+ const shares = await firstLossCoverContract.convertToShares(
49
+ selectedWithdrawType.withdrawableAmount,
50
+ )
51
+ const price = selectedWithdrawType.withdrawableAmount.div(shares)
52
+ setSharePrice(price.toNumber())
53
+ }
54
+ }
55
+ fetchData()
56
+ }
57
+ }, [
58
+ poolInfo.poolName,
59
+ provider,
60
+ selectedWithdrawType.value,
61
+ selectedWithdrawType.withdrawableAmount,
62
+ ])
63
+
64
+ const handleChangeAmount = (newAmount: number) => {
65
+ const shares = Number(newAmount) / sharePrice
66
+ setCurrentShares(shares)
67
+ setCurrentAmount(newAmount)
68
+ dispatch(setWithdrawAmount(Number(newAmount)))
69
+ }
70
+
71
+ const handleAction = () => {
72
+ dispatch(setStep(WIDGET_STEP.Transfer))
73
+ }
74
+
75
+ return (
76
+ <InputAmountModal
77
+ title={`Withdraw ${symbol}`}
78
+ subTitle={selectedWithdrawType.label}
79
+ tokenSymbol={symbol}
80
+ currentAmount={currentAmount}
81
+ handleChangeAmount={handleChangeAmount}
82
+ maxAmount={maxAmountFormatted}
83
+ info={`${currentShares.toFixed(1)} Shares`}
84
+ handleAction={handleAction}
85
+ actionText='WITHDRAW'
86
+ />
87
+ )
88
+ }
@@ -0,0 +1,110 @@
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
+ }
@@ -1,15 +1,19 @@
1
1
  import {
2
+ capitalizeFirstLetter,
3
+ FirstLossCoverIndex,
4
+ formatBNFixed,
2
5
  POOL_NAME,
3
- TrancheType,
6
+ useFirstLossCoverStatsV2,
4
7
  usePoolInfoV2,
8
+ usePoolIsReadyForFlcWithdrawalV2,
5
9
  usePoolUnderlyingTokenInfoV2,
6
- useWithdrawableAssetsV2,
10
+ useTrancheWithdrawableAssetsV2,
7
11
  } from '@huma-finance/shared'
8
12
  import { useWeb3React } from '@web3-react/core'
13
+ import { BigNumber } from 'ethers'
9
14
  import React, { useCallback, useEffect, useState } from 'react'
10
15
  import { useDispatch } from 'react-redux'
11
16
 
12
- import { BigNumber } from 'ethers'
13
17
  import { useAppSelector } from '../../../hooks/useRedux'
14
18
  import { setStep } from '../../../store/widgets.reducers'
15
19
  import { selectWidgetState } from '../../../store/widgets.selectors'
@@ -17,8 +21,16 @@ import { WIDGET_STEP } from '../../../store/widgets.store'
17
21
  import { ErrorModal } from '../../ErrorModal'
18
22
  import { WidgetWrapper } from '../../WidgetWrapper'
19
23
  import { ChooseTranche } from './1-ChooseTranche'
20
- import { Transfer } from './2-Transfer'
21
- import { Done } from './3-Done'
24
+ import { ChooseAmount } from './2-ChooseAmount'
25
+ import { Transfer } from './3-Transfer'
26
+ import { Done } from './4-Done'
27
+
28
+ export type WithdrawType = {
29
+ label: string
30
+ value: string
31
+ type: 'tranche' | 'firstLossCover'
32
+ withdrawableAmount: BigNumber
33
+ }
22
34
 
23
35
  /**
24
36
  * Lend pool withdraw props
@@ -43,49 +55,117 @@ export function LendWithdrawV2({
43
55
  const poolName = POOL_NAME[poolNameStr]
44
56
  const poolInfo = usePoolInfoV2(poolName, chainId)
45
57
  const { step, errorMessage } = useAppSelector(selectWidgetState)
58
+ const [withdrawTypes, setWithdrawTypes] = useState<WithdrawType[]>([])
59
+ const [selectedWithdrawType, setSelectedWithdrawType] =
60
+ useState<WithdrawType>()
61
+
46
62
  const [seniorWithdrawableAmount, refreshSeniorWithdrawableAmount] =
47
- useWithdrawableAssetsV2(poolName, 'senior', account, provider)
63
+ useTrancheWithdrawableAssetsV2(poolName, 'senior', account, provider)
48
64
  const [juniorWithdrawableAmount, refreshJuniorWithdrawableAmount] =
49
- useWithdrawableAssetsV2(poolName, 'junior', account, provider)
65
+ useTrancheWithdrawableAssetsV2(poolName, 'junior', account, provider)
66
+ const isReadyForFlcWithdrawal = usePoolIsReadyForFlcWithdrawalV2(
67
+ poolName,
68
+ provider,
69
+ )
70
+ const [flcStats, refreshFlcStats] = useFirstLossCoverStatsV2(
71
+ poolName,
72
+ account,
73
+ provider,
74
+ )
75
+
50
76
  const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
51
- const [selectedTranche, setSelectedTranche] = useState<TrancheType>()
52
- const [withdrawAmount, setWithdrawAmount] = useState<BigNumber>()
77
+ const { symbol, decimals } = poolUnderlyingToken || {}
78
+
79
+ const isLoading =
80
+ !poolInfo ||
81
+ !poolUnderlyingToken ||
82
+ isReadyForFlcWithdrawal === undefined ||
83
+ !seniorWithdrawableAmount ||
84
+ !juniorWithdrawableAmount ||
85
+ !flcStats
53
86
 
54
87
  useEffect(() => {
55
- if (!step) {
56
- dispatch(setStep(WIDGET_STEP.ChooseTranche))
88
+ if (!step && !isLoading) {
89
+ const items: WithdrawType[] = []
90
+ if (seniorWithdrawableAmount.gt(0)) {
91
+ items.push({
92
+ label: `Withdraw ${formatBNFixed(
93
+ seniorWithdrawableAmount,
94
+ decimals!,
95
+ )} ${symbol} from Senior Tranche`,
96
+ value: 'senior',
97
+ type: 'tranche',
98
+ withdrawableAmount: seniorWithdrawableAmount,
99
+ })
100
+ }
101
+ if (juniorWithdrawableAmount.gt(0)) {
102
+ items.push({
103
+ label: `Withdraw ${formatBNFixed(
104
+ juniorWithdrawableAmount,
105
+ decimals!,
106
+ )} ${symbol} from Junior Tranche`,
107
+ value: 'junior',
108
+ type: 'tranche',
109
+ withdrawableAmount: juniorWithdrawableAmount,
110
+ })
111
+ }
112
+ if (isReadyForFlcWithdrawal) {
113
+ flcStats
114
+ .filter((flc) => flc.totalAssets.gt(0))
115
+ .forEach((flc) => {
116
+ items.push({
117
+ label: `Withdraw ${symbol} from ${capitalizeFirstLetter(
118
+ FirstLossCoverIndex[flc.firstLossCoverIndex],
119
+ )} First Loss Cover`,
120
+ value: String(flc.firstLossCoverIndex),
121
+ type: 'firstLossCover',
122
+ withdrawableAmount: flc.totalAssets,
123
+ })
124
+ })
125
+ }
126
+
127
+ setWithdrawTypes(items)
128
+ if (items.length === 1) {
129
+ setSelectedWithdrawType(items[0])
130
+ const step =
131
+ items[0].type === 'firstLossCover'
132
+ ? WIDGET_STEP.ChooseAmount
133
+ : WIDGET_STEP.Transfer
134
+ dispatch(setStep(step))
135
+ } else if (items.length > 1) {
136
+ dispatch(setStep(WIDGET_STEP.ChooseTranche))
137
+ }
57
138
  }
58
- }, [dispatch, step])
139
+ }, [
140
+ decimals,
141
+ dispatch,
142
+ flcStats,
143
+ isLoading,
144
+ isReadyForFlcWithdrawal,
145
+ juniorWithdrawableAmount,
146
+ seniorWithdrawableAmount,
147
+ step,
148
+ symbol,
149
+ ])
59
150
 
60
151
  const handleWithdrawSuccess = useCallback(
61
152
  (blockNumber: number) => {
62
153
  refreshSeniorWithdrawableAmount()
63
154
  refreshJuniorWithdrawableAmount()
155
+ refreshFlcStats()
64
156
  if (handleSuccess) {
65
157
  handleSuccess(blockNumber)
66
158
  }
67
159
  },
68
160
  [
69
161
  handleSuccess,
162
+ refreshFlcStats,
70
163
  refreshJuniorWithdrawableAmount,
71
164
  refreshSeniorWithdrawableAmount,
72
165
  ],
73
166
  )
74
167
 
75
- const handleChangeTranche = useCallback(
76
- (tranche: TrancheType) => {
77
- setSelectedTranche(tranche)
78
- if (tranche === 'senior') {
79
- setWithdrawAmount(seniorWithdrawableAmount)
80
- }
81
- if (tranche === 'junior') {
82
- setWithdrawAmount(juniorWithdrawableAmount)
83
- }
84
- },
85
- [juniorWithdrawableAmount, seniorWithdrawableAmount],
86
- )
87
-
88
- if (!poolInfo || !poolUnderlyingToken) {
168
+ if (isLoading) {
89
169
  return null
90
170
  }
91
171
 
@@ -98,21 +178,30 @@ export function LendWithdrawV2({
98
178
  >
99
179
  {step === WIDGET_STEP.ChooseTranche && (
100
180
  <ChooseTranche
181
+ poolUnderlyingToken={poolUnderlyingToken}
182
+ selectedWithdrawType={selectedWithdrawType}
183
+ withdrawTypes={withdrawTypes}
184
+ changeWithdrawType={setSelectedWithdrawType}
185
+ />
186
+ )}
187
+ {step === WIDGET_STEP.ChooseAmount && selectedWithdrawType && (
188
+ <ChooseAmount
101
189
  poolInfo={poolInfo}
102
190
  poolUnderlyingToken={poolUnderlyingToken}
103
- selectedTranche={selectedTranche}
104
- changeTranche={handleChangeTranche}
105
- seniorWithdrawableAmount={seniorWithdrawableAmount}
106
- juniorWithdrawableAmount={juniorWithdrawableAmount}
191
+ selectedWithdrawType={selectedWithdrawType}
107
192
  />
108
193
  )}
109
- {step === WIDGET_STEP.Transfer && selectedTranche && (
110
- <Transfer poolInfo={poolInfo} selectedTranche={selectedTranche} />
194
+ {step === WIDGET_STEP.Transfer && selectedWithdrawType && (
195
+ <Transfer
196
+ poolInfo={poolInfo}
197
+ poolUnderlyingToken={poolUnderlyingToken}
198
+ selectedWithdrawType={selectedWithdrawType}
199
+ />
111
200
  )}
112
- {step === WIDGET_STEP.Done && withdrawAmount && (
201
+ {step === WIDGET_STEP.Done && selectedWithdrawType && (
113
202
  <Done
114
203
  poolUnderlyingToken={poolUnderlyingToken}
115
- withdrawAmount={withdrawAmount}
204
+ withdrawAmount={selectedWithdrawType.withdrawableAmount}
116
205
  handleAction={handleClose}
117
206
  />
118
207
  )}
@@ -1,48 +0,0 @@
1
- import {
2
- PoolInfoV2,
3
- TrancheType,
4
- useTrancheVaultContractV2,
5
- } from '@huma-finance/shared'
6
- import { useWeb3React } from '@web3-react/core'
7
- import React, { useCallback } from 'react'
8
-
9
- import { useAppDispatch } from '../../../hooks/useRedux'
10
- import { setStep } from '../../../store/widgets.reducers'
11
- import { WIDGET_STEP } from '../../../store/widgets.store'
12
- import { TxSendModalV2 } from '../../TxSendModalV2'
13
-
14
- type Props = {
15
- poolInfo: PoolInfoV2
16
- selectedTranche: TrancheType
17
- }
18
-
19
- export function Transfer({
20
- poolInfo,
21
- selectedTranche,
22
- }: Props): React.ReactElement | null {
23
- const dispatch = useAppDispatch()
24
- const { account, provider } = useWeb3React()
25
- const trancheVaultContract = useTrancheVaultContractV2(
26
- poolInfo.poolName,
27
- selectedTranche,
28
- provider,
29
- account,
30
- )
31
-
32
- const handleSuccess = useCallback(() => {
33
- dispatch(setStep(WIDGET_STEP.Done))
34
- }, [dispatch])
35
-
36
- if (!trancheVaultContract || !account) {
37
- return null
38
- }
39
-
40
- return (
41
- <TxSendModalV2
42
- contract={trancheVaultContract}
43
- method='disburse'
44
- params={[]}
45
- handleSuccess={handleSuccess}
46
- />
47
- )
48
- }