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

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 (34) hide show
  1. package/API.md +69 -22
  2. package/dist/cjs/index.cjs +2062 -2185
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/index.d.ts +45 -14
  5. package/dist/index.js +2061 -2185
  6. package/dist/index.js.map +1 -1
  7. package/package.json +4 -4
  8. package/src/components/CreditLine/paymentV2/1-ChooseAmount.tsx +5 -0
  9. package/src/components/InputAmountModal.tsx +3 -1
  10. package/src/components/Lend/{withdrawV2 → addRedemptionV2}/1-ChooseTranche.tsx +25 -30
  11. package/src/components/Lend/addRedemptionV2/2-ChooseAmount.tsx +61 -0
  12. package/src/components/Lend/{redeemV2 → addRedemptionV2}/3-Transfer.tsx +7 -12
  13. package/src/components/Lend/addRedemptionV2/4-Done.tsx +20 -0
  14. package/src/components/Lend/addRedemptionV2/index.tsx +172 -0
  15. package/src/components/Lend/cancelRedemptionV2 /1-Transfer.tsx +51 -0
  16. package/src/components/Lend/cancelRedemptionV2 /2-Done.tsx +29 -0
  17. package/src/components/Lend/cancelRedemptionV2 /index.tsx +120 -0
  18. package/src/components/Lend/supplyV2/1-ChooseTranche.tsx +23 -21
  19. package/src/components/Lend/supplyV2/3-ChooseAmount.tsx +20 -30
  20. package/src/components/Lend/supplyV2/4-ApproveAllowance.tsx +2 -15
  21. package/src/components/Lend/supplyV2/5-Transfer.tsx +14 -58
  22. package/src/components/Lend/supplyV2/6-Success.tsx +5 -2
  23. package/src/components/Lend/supplyV2/index.tsx +31 -59
  24. package/src/components/Lend/withdrawV2/1-ConfirmTransfer.tsx +131 -0
  25. package/src/components/Lend/withdrawV2/2-Transfer.tsx +48 -0
  26. package/src/components/Lend/withdrawV2/index.tsx +53 -136
  27. package/src/index.tsx +44 -15
  28. package/src/components/Lend/redeemV2/1-ChooseAction.tsx +0 -237
  29. package/src/components/Lend/redeemV2/2-ChooseAmount.tsx +0 -101
  30. package/src/components/Lend/redeemV2/4-Done.tsx +0 -33
  31. package/src/components/Lend/redeemV2/index.tsx +0 -207
  32. package/src/components/Lend/withdrawV2/2-ChooseAmount.tsx +0 -88
  33. package/src/components/Lend/withdrawV2/3-Transfer.tsx +0 -110
  34. /package/src/components/Lend/withdrawV2/{4-Done.tsx → 3-Done.tsx} +0 -0
@@ -1,4 +1,4 @@
1
- import { UnderlyingTokenInfo } from '@huma-finance/shared'
1
+ import { TrancheType, UnderlyingTokenInfo } from '@huma-finance/shared'
2
2
  import {
3
3
  css,
4
4
  FormControl,
@@ -10,7 +10,6 @@ import {
10
10
  } from '@mui/material'
11
11
  import React from 'react'
12
12
 
13
- import { SupplyType } from '.'
14
13
  import { useAppDispatch } from '../../../hooks/useRedux'
15
14
  import { setStep } from '../../../store/widgets.reducers'
16
15
  import { WIDGET_STEP } from '../../../store/widgets.store'
@@ -19,16 +18,14 @@ import { WrapperModal } from '../../WrapperModal'
19
18
 
20
19
  type Props = {
21
20
  poolUnderlyingToken: UnderlyingTokenInfo
22
- selectedSupplyType: SupplyType | undefined
23
- supplyTypes: SupplyType[]
24
- changeSupplyType: (supplyType: SupplyType) => void
21
+ selectedTranche: TrancheType | undefined
22
+ changeTranche: (tranche: TrancheType) => void
25
23
  }
26
24
 
27
- export function ChooseSupplyType({
25
+ export function ChooseTranche({
28
26
  poolUnderlyingToken,
29
- selectedSupplyType,
30
- supplyTypes,
31
- changeSupplyType,
27
+ selectedTranche,
28
+ changeTranche,
32
29
  }: Props): React.ReactElement | null {
33
30
  const theme = useTheme()
34
31
  const dispatch = useAppDispatch()
@@ -60,19 +57,24 @@ export function ChooseSupplyType({
60
57
  `,
61
58
  }
62
59
 
63
- const handleChangeSupplyType = (supplyTypeValue: string | number) => {
64
- const supplyType = supplyTypes.find(
65
- (item) => item.value === supplyTypeValue,
66
- )
67
- if (supplyType) {
68
- changeSupplyType(supplyType)
69
- }
70
- }
71
-
72
60
  const handleNext = () => {
73
61
  dispatch(setStep(WIDGET_STEP.ChooseAmount))
74
62
  }
75
63
 
64
+ const items: {
65
+ label: string
66
+ value: TrancheType
67
+ }[] = [
68
+ {
69
+ label: 'Senior',
70
+ value: 'senior',
71
+ },
72
+ {
73
+ label: 'Junior',
74
+ value: 'junior',
75
+ },
76
+ ]
77
+
76
78
  return (
77
79
  <WrapperModal title={`Supply ${poolUnderlyingToken.symbol}`}>
78
80
  <FormControl>
@@ -81,9 +83,9 @@ export function ChooseSupplyType({
81
83
  aria-labelledby='buttons-group-label'
82
84
  name='radio-buttons-group'
83
85
  css={styles.radioGroup}
84
- onChange={(e) => handleChangeSupplyType(e.target.value)}
86
+ onChange={(e) => changeTranche(e.target.value as TrancheType)}
85
87
  >
86
- {supplyTypes.map((item) => (
88
+ {items.map((item) => (
87
89
  <FormControlLabel
88
90
  key={item.label}
89
91
  value={item.value}
@@ -104,7 +106,7 @@ export function ChooseSupplyType({
104
106
  </FormControl>
105
107
  <BottomButton
106
108
  variant='contained'
107
- disabled={!selectedSupplyType}
109
+ disabled={!selectedTranche}
108
110
  onClick={handleNext}
109
111
  >
110
112
  NEXT
@@ -1,9 +1,8 @@
1
1
  import {
2
- FirstLossCoverIndex,
3
- formatNumber,
4
2
  PoolInfoV2,
3
+ TrancheType,
5
4
  UnderlyingTokenInfo,
6
- useFirstLossCoverAllowanceV2,
5
+ formatNumber,
7
6
  usePoolSafeAllowanceV2,
8
7
  usePoolUnderlyingTokenBalanceV2,
9
8
  } from '@huma-finance/shared'
@@ -11,7 +10,6 @@ import { useWeb3React } from '@web3-react/core'
11
10
  import { BigNumber, ethers } from 'ethers'
12
11
  import React, { useState } from 'react'
13
12
 
14
- import { SupplyType } from '.'
15
13
  import { useAppDispatch } from '../../../hooks/useRedux'
16
14
  import { setStep, setSupplyAmount } from '../../../store/widgets.reducers'
17
15
  import { WIDGET_STEP } from '../../../store/widgets.store'
@@ -20,31 +18,30 @@ import { InputAmountModal } from '../../InputAmountModal'
20
18
  type Props = {
21
19
  poolInfo: PoolInfoV2
22
20
  poolUnderlyingToken: UnderlyingTokenInfo
23
- selectedSupplyType: SupplyType
21
+ selectedTranche: TrancheType | undefined
24
22
  }
25
23
 
26
24
  export function ChooseAmount({
27
25
  poolInfo,
28
26
  poolUnderlyingToken,
29
- selectedSupplyType,
27
+ selectedTranche,
30
28
  }: Props): React.ReactElement | null {
31
29
  const dispatch = useAppDispatch()
32
30
  const { account, provider } = useWeb3React()
33
31
  const { symbol, decimals } = poolUnderlyingToken
34
32
  const [currentAmount, setCurrentAmount] = useState<number | string>(0)
35
- const { allowance: poolSafeAllowance = BigNumber.from(0) } =
36
- usePoolSafeAllowanceV2(poolInfo.poolName, account, provider)
37
- const [firstLossCoverAllowance = BigNumber.from(0)] =
38
- useFirstLossCoverAllowanceV2(
39
- poolInfo.poolName,
40
- Number(selectedSupplyType.value) as FirstLossCoverIndex,
41
- account,
42
- provider,
43
- )
44
- const [underlyingTokenBalance = BigNumber.from(0)] =
45
- usePoolUnderlyingTokenBalanceV2(poolInfo.poolName, account, provider)
33
+ const { allowance = BigNumber.from(0) } = usePoolSafeAllowanceV2(
34
+ poolInfo.poolName,
35
+ account,
36
+ provider,
37
+ )
38
+ const [balance] = usePoolUnderlyingTokenBalanceV2(
39
+ poolInfo.poolName,
40
+ account,
41
+ provider,
42
+ )
46
43
  const maxAmountFormatted = ethers.utils.formatUnits(
47
- underlyingTokenBalance,
44
+ balance,
48
45
  poolUnderlyingToken.decimals,
49
46
  )
50
47
 
@@ -58,23 +55,16 @@ export function ChooseAmount({
58
55
  String(currentAmount),
59
56
  decimals,
60
57
  )
61
- if (selectedSupplyType.type === 'tranche') {
62
- const step = currentAmountBN.gt(poolSafeAllowance)
63
- ? WIDGET_STEP.ApproveAllowance
64
- : WIDGET_STEP.Transfer
65
- dispatch(setStep(step))
66
- } else {
67
- const step = currentAmountBN.gt(firstLossCoverAllowance)
68
- ? WIDGET_STEP.ApproveAllowance
69
- : WIDGET_STEP.Transfer
70
- dispatch(setStep(step))
71
- }
58
+ const step = currentAmountBN.gt(allowance)
59
+ ? WIDGET_STEP.ApproveAllowance
60
+ : WIDGET_STEP.Transfer
61
+ dispatch(setStep(step))
72
62
  }
73
63
 
74
64
  return (
75
65
  <InputAmountModal
76
66
  title='Enter Amount'
77
- subTitle={`Supplying ${symbol} with ${selectedSupplyType?.label}`}
67
+ subTitle={`Supplying ${symbol} with ${selectedTranche}`}
78
68
  tokenSymbol={symbol}
79
69
  currentAmount={currentAmount}
80
70
  handleChangeAmount={handleChangeAmount}
@@ -1,11 +1,6 @@
1
- import {
2
- FirstLossCoverIndex,
3
- PoolInfoV2,
4
- UnderlyingTokenInfo,
5
- } from '@huma-finance/shared'
1
+ import { PoolInfoV2, UnderlyingTokenInfo } from '@huma-finance/shared'
6
2
  import React, { useCallback } from 'react'
7
3
 
8
- import { SupplyType } from '.'
9
4
  import { useAppDispatch } from '../../../hooks/useRedux'
10
5
  import { setStep } from '../../../store/widgets.reducers'
11
6
  import { WIDGET_STEP } from '../../../store/widgets.store'
@@ -14,22 +9,14 @@ import { ApproveAllowanceModalV2 } from '../../ApproveAllowanceModalV2'
14
9
  type Props = {
15
10
  poolInfo: PoolInfoV2
16
11
  poolUnderlyingToken: UnderlyingTokenInfo
17
- selectedSupplyType: SupplyType
18
12
  }
19
13
 
20
14
  export function ApproveAllowance({
21
15
  poolInfo,
22
16
  poolUnderlyingToken,
23
- selectedSupplyType,
24
17
  }: Props): React.ReactElement | null {
25
18
  const dispatch = useAppDispatch()
26
- let spender = poolInfo.poolSafe
27
- if (selectedSupplyType.type === 'firstLossCover') {
28
- spender =
29
- poolInfo.firstLossCovers[
30
- Number(selectedSupplyType.value) as FirstLossCoverIndex
31
- ]
32
- }
19
+ const spender = poolInfo.poolSafe
33
20
 
34
21
  const handleSuccess = useCallback(() => {
35
22
  dispatch(setStep(WIDGET_STEP.Transfer))
@@ -1,34 +1,30 @@
1
1
  import {
2
- FirstLossCoverIndex,
3
- getFirstLossCoverContractV2,
4
- getTrancheVaultContractV2,
5
2
  PoolInfoV2,
3
+ useTrancheVaultContractV2,
6
4
  TrancheType,
7
5
  UnderlyingTokenInfo,
8
6
  } from '@huma-finance/shared'
9
7
  import { useWeb3React } from '@web3-react/core'
10
8
  import { ethers } from 'ethers'
11
- import React, { useCallback, useEffect, useState } from 'react'
9
+ import React, { useCallback } from 'react'
12
10
 
13
- import { SupplyType } from '.'
14
11
  import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
15
12
  import { setStep } from '../../../store/widgets.reducers'
16
13
  import { selectWidgetState } from '../../../store/widgets.selectors'
17
14
  import { WIDGET_STEP } from '../../../store/widgets.store'
18
- import { LoadingModal } from '../../LoadingModal'
19
15
  import { TxSendModalV2 } from '../../TxSendModalV2'
20
16
 
21
17
  type Props = {
22
18
  poolInfo: PoolInfoV2
23
19
  poolUnderlyingToken: UnderlyingTokenInfo
24
- selectedSupplyType: SupplyType
20
+ trancheType: TrancheType
25
21
  }
26
22
 
27
23
  export function Transfer({
28
24
  poolInfo,
29
25
  poolUnderlyingToken,
30
- selectedSupplyType,
31
- }: Props): React.ReactElement {
26
+ trancheType,
27
+ }: Props): React.ReactElement | null {
32
28
  const dispatch = useAppDispatch()
33
29
  const { account, provider } = useWeb3React()
34
30
  const { supplyAmount } = useAppSelector(selectWidgetState)
@@ -37,66 +33,26 @@ export function Transfer({
37
33
  String(supplyAmount),
38
34
  decimals,
39
35
  )
40
- const [contract, setContract] = useState<ethers.Contract | undefined>(
41
- undefined,
42
- )
43
-
44
- useEffect(() => {
45
- const fetchData = async () => {
46
- if (account) {
47
- if (selectedSupplyType.type === 'tranche') {
48
- const trancheVaultContract = await getTrancheVaultContractV2(
49
- poolInfo.poolName,
50
- selectedSupplyType.value as TrancheType,
51
- provider,
52
- account,
53
- )
54
- if (trancheVaultContract) {
55
- setContract(trancheVaultContract)
56
- }
57
- }
58
- if (selectedSupplyType.type === 'firstLossCover') {
59
- const firstLossCoverContract = await getFirstLossCoverContractV2(
60
- poolInfo.poolName,
61
- Number(selectedSupplyType.value) as FirstLossCoverIndex,
62
- provider,
63
- account,
64
- )
65
- if (firstLossCoverContract) {
66
- setContract(firstLossCoverContract)
67
- }
68
- }
69
- }
70
- }
71
- fetchData()
72
- }, [
73
- account,
36
+ const trancheVaultContract = useTrancheVaultContractV2(
74
37
  poolInfo.poolName,
38
+ trancheType,
75
39
  provider,
76
- selectedSupplyType.type,
77
- selectedSupplyType.value,
78
- ])
79
-
80
- const method =
81
- selectedSupplyType.type === 'tranche' ? 'deposit' : 'depositCover'
82
- const params =
83
- selectedSupplyType.type === 'tranche'
84
- ? [supplyBigNumber, account]
85
- : [supplyBigNumber]
40
+ account,
41
+ )
86
42
 
87
43
  const handleSuccess = useCallback(() => {
88
44
  dispatch(setStep(WIDGET_STEP.Done))
89
45
  }, [dispatch])
90
46
 
91
- if (!contract) {
92
- return <LoadingModal title='Transaction Pending' />
47
+ if (!trancheVaultContract || !account) {
48
+ return null
93
49
  }
94
50
 
95
51
  return (
96
52
  <TxSendModalV2
97
- contract={contract}
98
- method={method}
99
- params={params}
53
+ contract={trancheVaultContract}
54
+ method='deposit'
55
+ params={[supplyBigNumber, account]}
100
56
  handleSuccess={handleSuccess}
101
57
  />
102
58
  )
@@ -45,8 +45,11 @@ export function Success({
45
45
  const events = decodeLogs(txReceipt.logs, TRANSFER_ABI)
46
46
  if (events) {
47
47
  events.forEach((event) => {
48
- const { from, value } = event.args
49
- if (from.toLowerCase() === account?.toLowerCase()) {
48
+ const { from, to, value } = event.args
49
+ if (
50
+ from.toLowerCase() === account?.toLowerCase() &&
51
+ to.toLowerCase() === poolInfo.poolSafe.toLowerCase()
52
+ ) {
50
53
  setSupplyAmount(downScale(value.toString(), decimals))
51
54
  }
52
55
  })
@@ -1,9 +1,7 @@
1
1
  import {
2
- capitalizeFirstLetter,
3
- FirstLossCoverIndex,
4
- openInNewTab,
5
2
  POOL_NAME,
6
- useFirstLossCoverStatsV2,
3
+ TrancheType,
4
+ openInNewTab,
7
5
  useLenderApprovedV2,
8
6
  usePoolInfoV2,
9
7
  usePoolUnderlyingTokenInfoV2,
@@ -18,7 +16,7 @@ import { selectWidgetState } from '../../../store/widgets.selectors'
18
16
  import { WIDGET_STEP } from '../../../store/widgets.store'
19
17
  import { ErrorModal } from '../../ErrorModal'
20
18
  import { WidgetWrapper } from '../../WidgetWrapper'
21
- import { ChooseSupplyType } from './1-ChooseTranche'
19
+ import { ChooseTranche } from './1-ChooseTranche'
22
20
  import { Evaluation } from './2-Evaluation'
23
21
  import { ChooseAmount } from './3-ChooseAmount'
24
22
  import { ApproveAllowance } from './4-ApproveAllowance'
@@ -26,12 +24,6 @@ import { Transfer } from './5-Transfer'
26
24
  import { Success } from './6-Success'
27
25
  import { Notifications } from './7-Notifications'
28
26
 
29
- export type SupplyType = {
30
- label: string
31
- value: string
32
- type: 'tranche' | 'firstLossCover'
33
- }
34
-
35
27
  /**
36
28
  * Lend pool supply props
37
29
  * @typedef {Object} LendSupplyPropsV2
@@ -55,8 +47,7 @@ export function LendSupplyV2({
55
47
  const { chainId, provider, account } = useWeb3React()
56
48
  const poolInfo = usePoolInfoV2(poolName, chainId)
57
49
  const { step, errorMessage } = useAppSelector(selectWidgetState)
58
- const [supplyTypes, setSupplyTypes] = useState<SupplyType[]>([])
59
- const [selectedSupplyType, setSelectedSupplyType] = useState<SupplyType>()
50
+ const [selectedTranche, setSelectedTranche] = useState<TrancheType>()
60
51
  const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
61
52
 
62
53
  const [lenderApprovedSenior] = useLenderApprovedV2(
@@ -71,57 +62,40 @@ export function LendSupplyV2({
71
62
  account,
72
63
  provider,
73
64
  )
74
- const [flcStats] = useFirstLossCoverStatsV2(poolName, account, provider)
75
65
 
76
66
  const lenderApproveStatusFetched =
77
- lenderApprovedSenior !== undefined &&
78
- lenderApprovedJunior !== undefined &&
79
- flcStats !== undefined
67
+ lenderApprovedSenior !== undefined && lenderApprovedJunior !== undefined
80
68
 
81
69
  useEffect(() => {
82
70
  if (!step && poolInfo && lenderApproveStatusFetched) {
83
- const items: SupplyType[] = []
84
- if (lenderApprovedSenior) {
85
- items.push({
86
- label: 'Senior Tranche',
87
- value: 'senior',
88
- type: 'tranche',
89
- })
90
- }
91
- if (lenderApprovedJunior) {
92
- items.push({
93
- label: 'Junior Tranche',
94
- value: 'junior',
95
- type: 'tranche',
96
- })
71
+ if (lenderApprovedJunior && !lenderApprovedSenior) {
72
+ setSelectedTranche('junior')
73
+ dispatch(setStep(WIDGET_STEP.ChooseAmount))
74
+ return
97
75
  }
98
- flcStats
99
- .filter((flc) => flc.isApproved)
100
- .forEach((flc) => {
101
- items.push({
102
- label: `${capitalizeFirstLetter(
103
- FirstLossCoverIndex[flc.firstLossCoverIndex],
104
- )} First Loss Cover`,
105
- value: String(flc.firstLossCoverIndex),
106
- type: 'firstLossCover',
107
- })
108
- })
109
76
 
110
- if (items.length === 1) {
111
- setSelectedSupplyType(items[0])
77
+ if (lenderApprovedSenior && !lenderApprovedJunior) {
78
+ setSelectedTranche('senior')
112
79
  dispatch(setStep(WIDGET_STEP.ChooseAmount))
113
- } else if (items.length > 1) {
114
- setSupplyTypes(items)
80
+ return
81
+ }
82
+
83
+ if (lenderApprovedJunior && lenderApprovedSenior) {
115
84
  dispatch(setStep(WIDGET_STEP.ChooseTranche))
116
- } else if (poolInfo.KYC) {
85
+ return
86
+ }
87
+
88
+ if (poolInfo.KYC) {
117
89
  dispatch(setStep(WIDGET_STEP.Evaluation))
118
- } else if (poolInfo.supplyLink) {
90
+ return
91
+ }
92
+
93
+ if (poolInfo.supplyLink) {
119
94
  openInNewTab(poolInfo.supplyLink)
120
95
  }
121
96
  }
122
97
  }, [
123
98
  dispatch,
124
- flcStats,
125
99
  lenderApproveStatusFetched,
126
100
  lenderApprovedJunior,
127
101
  lenderApprovedSenior,
@@ -149,35 +123,33 @@ export function LendSupplyV2({
149
123
  handleSuccess={handleSuccess}
150
124
  >
151
125
  {step === WIDGET_STEP.ChooseTranche && (
152
- <ChooseSupplyType
126
+ <ChooseTranche
153
127
  poolUnderlyingToken={poolUnderlyingToken}
154
- selectedSupplyType={selectedSupplyType}
155
- supplyTypes={supplyTypes}
156
- changeSupplyType={setSelectedSupplyType}
128
+ selectedTranche={selectedTranche}
129
+ changeTranche={setSelectedTranche}
157
130
  />
158
131
  )}
159
132
  {step === WIDGET_STEP.Evaluation && (
160
133
  <Evaluation poolInfo={poolInfo} handleClose={handleClose} />
161
134
  )}
162
- {step === WIDGET_STEP.ChooseAmount && selectedSupplyType && (
135
+ {step === WIDGET_STEP.ChooseAmount && (
163
136
  <ChooseAmount
164
137
  poolInfo={poolInfo}
165
138
  poolUnderlyingToken={poolUnderlyingToken}
166
- selectedSupplyType={selectedSupplyType}
139
+ selectedTranche={selectedTranche}
167
140
  />
168
141
  )}
169
- {step === WIDGET_STEP.ApproveAllowance && selectedSupplyType && (
142
+ {step === WIDGET_STEP.ApproveAllowance && (
170
143
  <ApproveAllowance
171
144
  poolInfo={poolInfo}
172
145
  poolUnderlyingToken={poolUnderlyingToken}
173
- selectedSupplyType={selectedSupplyType}
174
146
  />
175
147
  )}
176
- {step === WIDGET_STEP.Transfer && selectedSupplyType && (
148
+ {step === WIDGET_STEP.Transfer && selectedTranche && (
177
149
  <Transfer
178
150
  poolInfo={poolInfo}
179
151
  poolUnderlyingToken={poolUnderlyingToken}
180
- selectedSupplyType={selectedSupplyType}
152
+ trancheType={selectedTranche}
181
153
  />
182
154
  )}
183
155
  {step === WIDGET_STEP.Done && (
@@ -0,0 +1,131 @@
1
+ import {
2
+ PoolInfoV2,
3
+ TrancheRedemptionStatus,
4
+ TrancheType,
5
+ UnderlyingTokenInfo,
6
+ formatAmount,
7
+ getTrancheVaultContractV2,
8
+ } from '@huma-finance/shared'
9
+ import { Box, Divider, css, useTheme } from '@mui/material'
10
+ import React, { useEffect, useState } from 'react'
11
+ import { useDispatch } from 'react-redux'
12
+
13
+ import { useWeb3React } from '@web3-react/core'
14
+ import { setStep } from '../../../store/widgets.reducers'
15
+ import { WIDGET_STEP } from '../../../store/widgets.store'
16
+ import { BottomButton } from '../../BottomButton'
17
+ import { WrapperModal } from '../../WrapperModal'
18
+
19
+ type Props = {
20
+ poolInfo: PoolInfoV2
21
+ tranche: TrancheType
22
+ poolUnderlyingToken: UnderlyingTokenInfo
23
+ redemptionStatus: TrancheRedemptionStatus
24
+ }
25
+
26
+ export function ConfirmTransfer({
27
+ poolInfo,
28
+ tranche,
29
+ poolUnderlyingToken,
30
+ redemptionStatus,
31
+ }: Props): React.ReactElement {
32
+ const theme = useTheme()
33
+ const dispatch = useDispatch()
34
+ const { provider } = useWeb3React()
35
+ const { symbol, decimals } = poolUnderlyingToken
36
+ const { lenderRedemptionRecords, cancellableRedemptionShares } =
37
+ redemptionStatus
38
+ const { numSharesRequested } = lenderRedemptionRecords
39
+ const sharesProcessed = formatAmount(
40
+ numSharesRequested.sub(cancellableRedemptionShares),
41
+ decimals,
42
+ )
43
+ const withdrawableAmount = formatAmount(
44
+ redemptionStatus.withdrawableAssets,
45
+ decimals,
46
+ )
47
+ const [sharePrice, setSharePrice] = useState(0)
48
+
49
+ useEffect(() => {
50
+ const fetchData = async () => {
51
+ const vaultContract = await getTrancheVaultContractV2(
52
+ poolInfo.poolName,
53
+ tranche,
54
+ provider,
55
+ )
56
+ if (vaultContract) {
57
+ const shares = await vaultContract.convertToShares(
58
+ redemptionStatus.withdrawableAssets,
59
+ )
60
+ setSharePrice(
61
+ redemptionStatus.withdrawableAssets.toNumber() / shares.toNumber(),
62
+ )
63
+ }
64
+ }
65
+ fetchData()
66
+ }, [
67
+ poolInfo.poolName,
68
+ provider,
69
+ redemptionStatus.withdrawableAssets,
70
+ tranche,
71
+ ])
72
+
73
+ const goToWithdraw = () => {
74
+ dispatch(setStep(WIDGET_STEP.Transfer))
75
+ }
76
+
77
+ const styles = {
78
+ itemWrapper: css`
79
+ margin-top: ${theme.spacing(9)};
80
+ color: ${theme.palette.text.primary};
81
+ font-family: 'Uni-Neue-Regular';
82
+ font-size: 16px;
83
+ line-height: 175%;
84
+ letter-spacing: 0.15px;
85
+ `,
86
+ item: css`
87
+ display: flex;
88
+ justify-content: space-between;
89
+ align-items: center;
90
+ margin-bottom: ${theme.spacing(3)};
91
+ `,
92
+ itemValue: css`
93
+ font-size: 20px;
94
+ font-family: 'Uni-Neue-Bold';
95
+ `,
96
+ divider: css`
97
+ border-color: #eae6f0;
98
+ margin-bottom: ${theme.spacing(3)};
99
+ `,
100
+ }
101
+
102
+ return (
103
+ <WrapperModal
104
+ title={`Withdraw ${symbol}`}
105
+ subTitle='Withdraw all the available amount'
106
+ >
107
+ <Box css={styles.itemWrapper}>
108
+ <Box css={styles.item}>
109
+ <Box>Shares processed</Box>
110
+ <Box css={styles.itemValue}>{sharesProcessed}</Box>
111
+ </Box>
112
+ <Box css={styles.item}>
113
+ <Box>Price Per Share</Box>
114
+ <Box css={styles.itemValue}>
115
+ {sharePrice.toFixed(1)} {symbol}
116
+ </Box>
117
+ </Box>
118
+ <Divider css={styles.divider} orientation='horizontal' />
119
+ <Box css={styles.item}>
120
+ <Box fontWeight={700}>Available to withdraw</Box>
121
+ <Box css={styles.itemValue}>
122
+ {withdrawableAmount} {symbol}
123
+ </Box>
124
+ </Box>
125
+ </Box>
126
+ <BottomButton variant='contained' onClick={goToWithdraw}>
127
+ WITHDRAW
128
+ </BottomButton>
129
+ </WrapperModal>
130
+ )
131
+ }
@@ -0,0 +1,48 @@
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
+ tranche: TrancheType
17
+ }
18
+
19
+ export function Transfer({
20
+ poolInfo,
21
+ tranche,
22
+ }: Props): React.ReactElement | null {
23
+ const dispatch = useAppDispatch()
24
+ const { account, provider } = useWeb3React()
25
+ const trancheVaultContract = useTrancheVaultContractV2(
26
+ poolInfo.poolName,
27
+ tranche,
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
+ }