@huma-finance/widgets 0.0.51-beta.225 → 0.0.51-beta.346

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 (95) hide show
  1. package/API.md +454 -0
  2. package/dist/cjs/index.cjs +6069 -3795
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/index.d.ts +280 -2
  5. package/dist/index.js +6061 -3797
  6. package/dist/index.js.map +1 -1
  7. package/package.json +5 -4
  8. package/src/components/ApproveAllowanceModal.tsx +3 -1
  9. package/src/components/ApproveAllowanceModalV2.tsx +141 -0
  10. package/src/components/CreditLine/approve/index.tsx +9 -3
  11. package/src/components/CreditLine/autoPaybackV2/1-ApproveAllowance.tsx +33 -0
  12. package/src/components/CreditLine/autoPaybackV2/2-Success.tsx +13 -0
  13. package/src/components/CreditLine/autoPaybackV2/index.tsx +87 -0
  14. package/src/components/CreditLine/borrow/2-ChooseAmount.tsx +12 -3
  15. package/src/components/CreditLine/borrow/5-Success.tsx +7 -2
  16. package/src/components/CreditLine/borrow/index.tsx +4 -2
  17. package/src/components/CreditLine/borrowV2/1-ChooseAmount.tsx +81 -0
  18. package/src/components/CreditLine/borrowV2/2-ApproveAllowance.tsx +33 -0
  19. package/src/components/CreditLine/borrowV2/3-Transfer.tsx +50 -0
  20. package/src/components/CreditLine/borrowV2/4-Success.tsx +42 -0
  21. package/src/components/CreditLine/borrowV2/5-Notifications.tsx +10 -0
  22. package/src/components/CreditLine/borrowV2/index.tsx +140 -0
  23. package/src/components/CreditLine/payment/1-ChooseAmount.tsx +7 -2
  24. package/src/components/CreditLine/payment/4-Success.tsx +2 -2
  25. package/src/components/CreditLine/payment/index.tsx +4 -2
  26. package/src/components/CreditLine/paymentV2/1-ChooseAmount.tsx +96 -0
  27. package/src/components/CreditLine/paymentV2/2-ApproveAllowance.tsx +33 -0
  28. package/src/components/CreditLine/paymentV2/3-Transfer.tsx +55 -0
  29. package/src/components/CreditLine/paymentV2/4-Success.tsx +42 -0
  30. package/src/components/CreditLine/paymentV2/index.tsx +111 -0
  31. package/src/components/CreditLine/supplyFLC/1-ApproveAllowance.tsx +40 -0
  32. package/src/components/CreditLine/supplyFLC/2-Transfer.tsx +53 -0
  33. package/src/components/CreditLine/supplyFLC/3-Success.tsx +26 -0
  34. package/src/components/CreditLine/supplyFLC/index.tsx +121 -0
  35. package/src/components/Factoring/FactoredList.tsx +2 -1
  36. package/src/components/InputAmountModal.tsx +156 -0
  37. package/src/components/InvoiceFactoring/borrow/2-ChooseAmount.tsx +8 -1
  38. package/src/components/InvoiceFactoring/borrow/4-ApproveNFT.tsx +6 -2
  39. package/src/components/InvoiceFactoring/borrow/6-Success.tsx +5 -1
  40. package/src/components/InvoiceFactoring/borrow/index.tsx +9 -3
  41. package/src/components/InvoiceFactoring/payment/1-ChooseAmount.tsx +7 -2
  42. package/src/components/InvoiceFactoring/payment/index.tsx +9 -3
  43. package/src/components/Lend/addRedemptionV2/1-ChooseTranche.tsx +114 -0
  44. package/src/components/Lend/addRedemptionV2/2-ChooseAmount.tsx +62 -0
  45. package/src/components/Lend/addRedemptionV2/3-Transfer.tsx +56 -0
  46. package/src/components/Lend/addRedemptionV2/4-Done.tsx +20 -0
  47. package/src/components/Lend/addRedemptionV2/index.tsx +172 -0
  48. package/src/components/Lend/cancelRedemptionV2 /1-Transfer.tsx +51 -0
  49. package/src/components/Lend/cancelRedemptionV2 /2-Done.tsx +29 -0
  50. package/src/components/Lend/cancelRedemptionV2 /index.tsx +120 -0
  51. package/src/components/Lend/supply/1-Evaluation/EvaluationKYC.tsx +19 -2
  52. package/src/components/Lend/supply/2-ChooseAmount.tsx +1 -0
  53. package/src/components/Lend/supply/index.tsx +17 -3
  54. package/src/components/Lend/supplyV2/1-ChooseTranche.tsx +116 -0
  55. package/src/components/Lend/supplyV2/2-Evaluation.tsx +345 -0
  56. package/src/components/Lend/supplyV2/3-ChooseAmount.tsx +77 -0
  57. package/src/components/Lend/supplyV2/4-ApproveAllowance.tsx +33 -0
  58. package/src/components/Lend/supplyV2/5-Transfer.tsx +59 -0
  59. package/src/components/Lend/supplyV2/6-Success.tsx +79 -0
  60. package/src/components/Lend/supplyV2/7-Notifications.tsx +10 -0
  61. package/src/components/Lend/supplyV2/index.tsx +175 -0
  62. package/src/components/Lend/withdraw/1-CheckWithdrawble.tsx +5 -1
  63. package/src/components/Lend/withdraw/index.tsx +10 -3
  64. package/src/components/Lend/withdrawV2/1-ConfirmTransfer.tsx +135 -0
  65. package/src/components/Lend/withdrawV2/2-Transfer.tsx +50 -0
  66. package/src/components/Lend/withdrawV2/3-Done.tsx +31 -0
  67. package/src/components/Lend/withdrawV2/index.tsx +177 -0
  68. package/src/components/Notifi/NotifiSubscriptionModal.tsx +26 -38
  69. package/src/components/NumericFormatCustom.tsx +33 -0
  70. package/src/components/ReceivableBackedCreditLine/borrow/1-ChooseAmount.tsx +101 -0
  71. package/src/components/ReceivableBackedCreditLine/borrow/2-ApproveAllowance.tsx +33 -0
  72. package/src/components/ReceivableBackedCreditLine/borrow/3-ApproveReceivable.tsx +64 -0
  73. package/src/components/ReceivableBackedCreditLine/borrow/4-Transfer.tsx +61 -0
  74. package/src/components/ReceivableBackedCreditLine/borrow/5-Success.tsx +42 -0
  75. package/src/components/ReceivableBackedCreditLine/borrow/6-Notifications.tsx +10 -0
  76. package/src/components/ReceivableBackedCreditLine/borrow/index.tsx +148 -0
  77. package/src/components/ReceivableBackedCreditLine/payment/1-ChoosePaymentType.tsx +115 -0
  78. package/src/components/ReceivableBackedCreditLine/payment/2-ChooseAmount.tsx +84 -0
  79. package/src/components/ReceivableBackedCreditLine/payment/3-ApproveAllowance.tsx +41 -0
  80. package/src/components/ReceivableBackedCreditLine/payment/4-CreateReceivable.tsx +107 -0
  81. package/src/components/ReceivableBackedCreditLine/payment/5-ApproveReceivable.tsx +64 -0
  82. package/src/components/ReceivableBackedCreditLine/payment/6-Transfer.tsx +107 -0
  83. package/src/components/ReceivableBackedCreditLine/payment/7-Success.tsx +49 -0
  84. package/src/components/ReceivableBackedCreditLine/payment/index.tsx +159 -0
  85. package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +8 -1
  86. package/src/components/StreamFactoring/borrow/6-Transfer.tsx +3 -1
  87. package/src/components/StreamFactoring/borrow/7-Success.tsx +3 -1
  88. package/src/components/StreamFactoring/borrow/index.tsx +2 -2
  89. package/src/components/TxDoneModal.tsx +1 -1
  90. package/src/components/TxSendModal.tsx +8 -2
  91. package/src/components/TxSendModalV2.tsx +51 -0
  92. package/src/hooks/useNotifi.ts +4 -6
  93. package/src/index.tsx +268 -1
  94. package/src/store/widgets.reducers.ts +15 -0
  95. package/src/store/widgets.store.ts +6 -0
@@ -0,0 +1,175 @@
1
+ import {
2
+ POOL_NAME,
3
+ TrancheType,
4
+ openInNewTab,
5
+ useLenderApprovedV2,
6
+ usePoolInfoV2,
7
+ usePoolUnderlyingTokenInfoV2,
8
+ } from '@huma-finance/shared'
9
+ import { useWeb3React } from '@web3-react/core'
10
+ import React, { useEffect, useState } from 'react'
11
+ import { useDispatch } from 'react-redux'
12
+
13
+ import { useAppSelector } from '../../../hooks/useRedux'
14
+ import { setStep } from '../../../store/widgets.reducers'
15
+ import { selectWidgetState } from '../../../store/widgets.selectors'
16
+ import { WIDGET_STEP } from '../../../store/widgets.store'
17
+ import { ErrorModal } from '../../ErrorModal'
18
+ import { WidgetWrapper } from '../../WidgetWrapper'
19
+ import { ChooseTranche } from './1-ChooseTranche'
20
+ import { Evaluation } from './2-Evaluation'
21
+ import { ChooseAmount } from './3-ChooseAmount'
22
+ import { ApproveAllowance } from './4-ApproveAllowance'
23
+ import { Transfer } from './5-Transfer'
24
+ import { Success } from './6-Success'
25
+ import { Notifications } from './7-Notifications'
26
+
27
+ /**
28
+ * Lend pool supply props
29
+ * @typedef {Object} LendSupplyPropsV2
30
+ * @property {POOL_NAME} poolName The name of the pool.
31
+ * @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
32
+ * @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the lending pool supply action is successful.
33
+ */
34
+ export interface LendSupplyPropsV2 {
35
+ poolName: keyof typeof POOL_NAME
36
+ handleClose: () => void
37
+ handleSuccess?: (blockNumber?: number) => void
38
+ }
39
+
40
+ export function LendSupplyV2({
41
+ poolName: poolNameStr,
42
+ handleClose,
43
+ handleSuccess,
44
+ }: LendSupplyPropsV2): React.ReactElement | null {
45
+ const dispatch = useDispatch()
46
+ const poolName = POOL_NAME[poolNameStr]
47
+ const { chainId, provider, account } = useWeb3React()
48
+ const poolInfo = usePoolInfoV2(poolName, chainId)
49
+ const { step, errorMessage } = useAppSelector(selectWidgetState)
50
+ const [selectedTranche, setSelectedTranche] = useState<TrancheType>()
51
+ const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
52
+
53
+ const [lenderApprovedSenior] = useLenderApprovedV2(
54
+ poolName,
55
+ 'senior',
56
+ account,
57
+ provider,
58
+ )
59
+ const [lenderApprovedJunior] = useLenderApprovedV2(
60
+ poolName,
61
+ 'junior',
62
+ account,
63
+ provider,
64
+ )
65
+
66
+ const lenderApproveStatusFetched =
67
+ lenderApprovedSenior !== undefined && lenderApprovedJunior !== undefined
68
+
69
+ useEffect(() => {
70
+ if (!step && poolInfo && lenderApproveStatusFetched) {
71
+ if (lenderApprovedJunior && !lenderApprovedSenior) {
72
+ setSelectedTranche('junior')
73
+ dispatch(setStep(WIDGET_STEP.ChooseAmount))
74
+ return
75
+ }
76
+
77
+ if (lenderApprovedSenior && !lenderApprovedJunior) {
78
+ setSelectedTranche('senior')
79
+ dispatch(setStep(WIDGET_STEP.ChooseAmount))
80
+ return
81
+ }
82
+
83
+ if (lenderApprovedJunior && lenderApprovedSenior) {
84
+ dispatch(setStep(WIDGET_STEP.ChooseTranche))
85
+ return
86
+ }
87
+
88
+ if (poolInfo.KYC) {
89
+ dispatch(setStep(WIDGET_STEP.Evaluation))
90
+ return
91
+ }
92
+
93
+ if (poolInfo.supplyLink) {
94
+ openInNewTab(poolInfo.supplyLink)
95
+ }
96
+ }
97
+ }, [
98
+ dispatch,
99
+ lenderApproveStatusFetched,
100
+ lenderApprovedJunior,
101
+ lenderApprovedSenior,
102
+ poolInfo,
103
+ step,
104
+ ])
105
+
106
+ if (!poolInfo || !poolUnderlyingToken || !lenderApproveStatusFetched) {
107
+ return (
108
+ <WidgetWrapper
109
+ isOpen
110
+ isLoading
111
+ loadingTitle='Supply'
112
+ handleClose={handleClose}
113
+ handleSuccess={handleSuccess}
114
+ />
115
+ )
116
+ }
117
+
118
+ return (
119
+ <WidgetWrapper
120
+ isOpen
121
+ loadingTitle={`Supply ${poolUnderlyingToken.symbol}`}
122
+ handleClose={handleClose}
123
+ handleSuccess={handleSuccess}
124
+ >
125
+ {step === WIDGET_STEP.ChooseTranche && (
126
+ <ChooseTranche
127
+ poolUnderlyingToken={poolUnderlyingToken}
128
+ selectedTranche={selectedTranche}
129
+ changeTranche={setSelectedTranche}
130
+ />
131
+ )}
132
+ {step === WIDGET_STEP.Evaluation && (
133
+ <Evaluation poolInfo={poolInfo} handleClose={handleClose} />
134
+ )}
135
+ {step === WIDGET_STEP.ChooseAmount && (
136
+ <ChooseAmount
137
+ poolInfo={poolInfo}
138
+ poolUnderlyingToken={poolUnderlyingToken}
139
+ selectedTranche={selectedTranche}
140
+ />
141
+ )}
142
+ {step === WIDGET_STEP.ApproveAllowance && (
143
+ <ApproveAllowance
144
+ poolInfo={poolInfo}
145
+ poolUnderlyingToken={poolUnderlyingToken}
146
+ />
147
+ )}
148
+ {step === WIDGET_STEP.Transfer && selectedTranche && (
149
+ <Transfer
150
+ poolInfo={poolInfo}
151
+ poolUnderlyingToken={poolUnderlyingToken}
152
+ trancheType={selectedTranche}
153
+ />
154
+ )}
155
+ {step === WIDGET_STEP.Done && (
156
+ <Success
157
+ poolInfo={poolInfo}
158
+ poolUnderlyingToken={poolUnderlyingToken}
159
+ handleAction={handleClose}
160
+ />
161
+ )}
162
+ {step === WIDGET_STEP.Notifications && (
163
+ <Notifications handleAction={handleClose} />
164
+ )}
165
+ {step === WIDGET_STEP.Error && (
166
+ <ErrorModal
167
+ title='Supply'
168
+ errorReason='Sorry there was an error'
169
+ errorMessage={errorMessage}
170
+ handleOk={handleClose}
171
+ />
172
+ )}
173
+ </WidgetWrapper>
174
+ )
175
+ }
@@ -23,15 +23,19 @@ export function CheckWithdrawable({
23
23
  handleClose,
24
24
  }: Props): React.ReactElement | null {
25
25
  const dispatch = useAppDispatch()
26
- const { account } = useWeb3React()
26
+ const { account, chainId, provider } = useWeb3React()
27
27
  const withdrawlLockoutSeconds = useWithdrawlLockoutInSeconds(
28
28
  poolInfo.poolName,
29
29
  poolInfo.poolType,
30
+ chainId,
31
+ provider,
30
32
  )
31
33
  const lastDepositTime = useLastDepositTime(
32
34
  poolInfo.poolName,
33
35
  poolInfo.poolType,
36
+ chainId,
34
37
  account,
38
+ provider,
35
39
  )
36
40
 
37
41
  const { symbol } = poolInfo.poolUnderlyingToken
@@ -42,17 +42,24 @@ export function LendWithdraw({
42
42
  handleSuccess,
43
43
  }: LendWithdrawProps): React.ReactElement | null {
44
44
  const dispatch = useDispatch()
45
- const { account } = useWeb3React()
45
+ const { account, chainId, provider } = useWeb3React()
46
46
  const poolName = POOL_NAME[poolNameStr]
47
47
  const poolType = POOL_TYPE[poolTypeStr]
48
- const poolInfo = usePoolInfo(poolName, poolType)
48
+ const poolInfo = usePoolInfo(poolName, poolType, chainId)
49
49
  const { step, errorMessage } = useAppSelector(selectWidgetState)
50
50
  const [lenderPosition, refreshLenderPosition] = useLenderPosition(
51
51
  poolName,
52
52
  poolType,
53
+ chainId,
53
54
  account,
55
+ provider,
56
+ )
57
+ const [poolBalance, refreshPoolBalance] = usePoolBalance(
58
+ poolName,
59
+ poolType,
60
+ chainId,
61
+ provider,
54
62
  )
55
- const [poolBalance, refreshPoolBalance] = usePoolBalance(poolName, poolType)
56
63
 
57
64
  useEffect(() => {
58
65
  if (!step && lenderPosition && poolBalance) {
@@ -0,0 +1,135 @@
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
+ poolIsClosed: boolean
25
+ }
26
+
27
+ export function ConfirmTransfer({
28
+ poolInfo,
29
+ tranche,
30
+ poolUnderlyingToken,
31
+ redemptionStatus,
32
+ poolIsClosed,
33
+ }: Props): React.ReactElement {
34
+ const theme = useTheme()
35
+ const dispatch = useDispatch()
36
+ const { provider } = useWeb3React()
37
+ const { symbol, decimals } = poolUnderlyingToken
38
+ const { lenderRedemptionRecords, cancellableRedemptionShares } =
39
+ redemptionStatus
40
+ const { numSharesRequested } = lenderRedemptionRecords
41
+ const sharesProcessed = formatAmount(
42
+ numSharesRequested.sub(cancellableRedemptionShares),
43
+ decimals,
44
+ )
45
+ const withdrawableAmount = formatAmount(
46
+ redemptionStatus.withdrawableAssets,
47
+ decimals,
48
+ )
49
+ const [sharePrice, setSharePrice] = useState(0)
50
+
51
+ useEffect(() => {
52
+ const fetchData = async () => {
53
+ const vaultContract = await getTrancheVaultContractV2(
54
+ poolInfo.poolName,
55
+ tranche,
56
+ provider,
57
+ )
58
+ if (vaultContract) {
59
+ const shares = await vaultContract.convertToShares(
60
+ redemptionStatus.withdrawableAssets,
61
+ )
62
+ setSharePrice(
63
+ redemptionStatus.withdrawableAssets.toNumber() / shares.toNumber(),
64
+ )
65
+ }
66
+ }
67
+ fetchData()
68
+ }, [
69
+ poolInfo.poolName,
70
+ provider,
71
+ redemptionStatus.withdrawableAssets,
72
+ tranche,
73
+ ])
74
+
75
+ const goToWithdraw = () => {
76
+ dispatch(setStep(WIDGET_STEP.Transfer))
77
+ }
78
+
79
+ const styles = {
80
+ itemWrapper: css`
81
+ margin-top: ${theme.spacing(9)};
82
+ color: ${theme.palette.text.primary};
83
+ font-family: 'Uni-Neue-Regular';
84
+ font-size: 16px;
85
+ line-height: 175%;
86
+ letter-spacing: 0.15px;
87
+ `,
88
+ item: css`
89
+ display: flex;
90
+ justify-content: space-between;
91
+ align-items: center;
92
+ margin-bottom: ${theme.spacing(3)};
93
+ `,
94
+ itemValue: css`
95
+ font-size: 20px;
96
+ font-family: 'Uni-Neue-Bold';
97
+ `,
98
+ divider: css`
99
+ border-color: #eae6f0;
100
+ margin-bottom: ${theme.spacing(3)};
101
+ `,
102
+ }
103
+
104
+ return (
105
+ <WrapperModal
106
+ title={`Withdraw ${symbol}`}
107
+ subTitle='Withdraw all the available amount'
108
+ >
109
+ <Box css={styles.itemWrapper}>
110
+ {!poolIsClosed && (
111
+ <Box css={styles.item}>
112
+ <Box>Shares processed</Box>
113
+ <Box css={styles.itemValue}>{sharesProcessed}</Box>
114
+ </Box>
115
+ )}
116
+ <Box css={styles.item}>
117
+ <Box>Price Per Share</Box>
118
+ <Box css={styles.itemValue}>
119
+ {sharePrice.toFixed(1)} {symbol}
120
+ </Box>
121
+ </Box>
122
+ <Divider css={styles.divider} orientation='horizontal' />
123
+ <Box css={styles.item}>
124
+ <Box fontWeight={700}>Available to withdraw</Box>
125
+ <Box css={styles.itemValue}>
126
+ {withdrawableAmount} {symbol}
127
+ </Box>
128
+ </Box>
129
+ </Box>
130
+ <BottomButton variant='contained' onClick={goToWithdraw}>
131
+ WITHDRAW
132
+ </BottomButton>
133
+ </WrapperModal>
134
+ )
135
+ }
@@ -0,0 +1,50 @@
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
+ poolIsClosed: boolean
18
+ }
19
+
20
+ export function Transfer({
21
+ poolInfo,
22
+ tranche,
23
+ poolIsClosed,
24
+ }: Props): React.ReactElement | null {
25
+ const dispatch = useAppDispatch()
26
+ const { account, provider } = useWeb3React()
27
+ const trancheVaultContract = useTrancheVaultContractV2(
28
+ poolInfo.poolName,
29
+ tranche,
30
+ provider,
31
+ account,
32
+ )
33
+
34
+ const handleSuccess = useCallback(() => {
35
+ dispatch(setStep(WIDGET_STEP.Done))
36
+ }, [dispatch])
37
+
38
+ if (!trancheVaultContract || !account) {
39
+ return null
40
+ }
41
+
42
+ return (
43
+ <TxSendModalV2
44
+ contract={trancheVaultContract}
45
+ method={poolIsClosed ? 'withdrawAfterPoolClosure' : 'disburse'}
46
+ params={[]}
47
+ handleSuccess={handleSuccess}
48
+ />
49
+ )
50
+ }
@@ -0,0 +1,31 @@
1
+ import { formatMoney, UnderlyingTokenInfo } from '@huma-finance/shared'
2
+ import { BigNumber, ethers } from 'ethers'
3
+ import React from 'react'
4
+
5
+ import { TxDoneModal } from '../../TxDoneModal'
6
+
7
+ type Props = {
8
+ poolUnderlyingToken: UnderlyingTokenInfo
9
+ withdrawAmount: BigNumber
10
+ handleAction: () => void
11
+ }
12
+
13
+ export function Done({
14
+ poolUnderlyingToken,
15
+ withdrawAmount,
16
+ handleAction,
17
+ }: Props): React.ReactElement {
18
+ const { symbol } = poolUnderlyingToken
19
+ const withdrawAmountFormatted = ethers.utils.formatUnits(
20
+ withdrawAmount,
21
+ poolUnderlyingToken.decimals,
22
+ )
23
+
24
+ const content = [
25
+ `You successfully withdrew ${formatMoney(
26
+ withdrawAmountFormatted,
27
+ )} ${symbol}.`,
28
+ ]
29
+
30
+ return <TxDoneModal handleAction={handleAction} content={content} />
31
+ }
@@ -0,0 +1,177 @@
1
+ import {
2
+ getPoolContractV2,
3
+ getTrancheRedemptionStatusV2,
4
+ POOL_NAME,
5
+ TrancheRedemptionStatus,
6
+ TrancheType,
7
+ usePoolInfoV2,
8
+ usePoolUnderlyingTokenInfoV2,
9
+ } from '@huma-finance/shared'
10
+ import { useWeb3React } from '@web3-react/core'
11
+ import React, { useCallback, useEffect, useState } from 'react'
12
+ import { useDispatch } from 'react-redux'
13
+
14
+ import { 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 { ErrorModal } from '../../ErrorModal'
19
+ import { WidgetWrapper } from '../../WidgetWrapper'
20
+ import { ConfirmTransfer } from './1-ConfirmTransfer'
21
+ import { Transfer } from './2-Transfer'
22
+ import { Done } from './3-Done'
23
+
24
+ /**
25
+ * Lend pool withdraw props
26
+ * @typedef {Object} LendWithdrawPropsV2
27
+ * @property {POOL_NAME} poolName The name of the pool.
28
+ * @property {TrancheType} trancheType The type of the tranche.
29
+ * @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
30
+ * @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the lending pool withdraw action is successful.
31
+ */
32
+ export type LendWithdrawPropsV2 = {
33
+ poolName: keyof typeof POOL_NAME
34
+ trancheType: TrancheType
35
+ handleClose: () => void
36
+ handleSuccess?: (blockNumber?: number) => void
37
+ }
38
+
39
+ export function LendWithdrawV2({
40
+ poolName: poolNameStr,
41
+ trancheType,
42
+ handleClose,
43
+ handleSuccess,
44
+ }: LendWithdrawPropsV2): React.ReactElement | null {
45
+ const dispatch = useDispatch()
46
+ const { account, chainId, provider } = useWeb3React()
47
+ const poolName = POOL_NAME[poolNameStr]
48
+ const poolInfo = usePoolInfoV2(poolName, chainId)
49
+ const { step, errorMessage } = useAppSelector(selectWidgetState)
50
+ const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
51
+ const title = poolUnderlyingToken
52
+ ? `Withdraw ${poolUnderlyingToken.symbol}`
53
+ : 'Withdraw'
54
+
55
+ const [redemptionStatus, setRedemptionStatus] = React.useState<
56
+ TrancheRedemptionStatus | undefined
57
+ >()
58
+ const [poolIsClosed, setPoolIsClosed] = useState<boolean | undefined>(
59
+ undefined,
60
+ )
61
+
62
+ useEffect(() => {
63
+ const fetchData = async () => {
64
+ if (account && provider) {
65
+ const result = await getTrancheRedemptionStatusV2(
66
+ poolName,
67
+ trancheType,
68
+ account,
69
+ provider,
70
+ )
71
+ setRedemptionStatus(result)
72
+ }
73
+ }
74
+ fetchData()
75
+ }, [account, poolName, provider, trancheType])
76
+
77
+ useEffect(() => {
78
+ const fetchData = async () => {
79
+ if (account && provider) {
80
+ const result = await getTrancheRedemptionStatusV2(
81
+ poolName,
82
+ trancheType,
83
+ account,
84
+ provider,
85
+ )
86
+ setRedemptionStatus(result)
87
+ }
88
+ }
89
+ fetchData()
90
+ }, [account, poolName, provider, trancheType])
91
+
92
+ useEffect(() => {
93
+ const fetchData = async () => {
94
+ if (account && provider) {
95
+ const poolContract = await getPoolContractV2(poolName, provider)
96
+ if (poolContract) {
97
+ const poolIsClosed = await poolContract.isPoolClosed()
98
+ setPoolIsClosed(poolIsClosed)
99
+ }
100
+ }
101
+ }
102
+ fetchData()
103
+ }, [account, poolName, provider])
104
+
105
+ useEffect(() => {
106
+ if (!step) {
107
+ dispatch(setStep(WIDGET_STEP.ConfirmTransfer))
108
+ }
109
+ }, [dispatch, step])
110
+
111
+ const handleWithdrawSuccess = useCallback(
112
+ (blockNumber: number) => {
113
+ if (handleSuccess) {
114
+ handleSuccess(blockNumber)
115
+ }
116
+ },
117
+ [handleSuccess],
118
+ )
119
+
120
+ if (
121
+ !poolInfo ||
122
+ !poolUnderlyingToken ||
123
+ !redemptionStatus ||
124
+ poolIsClosed === undefined
125
+ ) {
126
+ return (
127
+ <WidgetWrapper
128
+ isOpen
129
+ isLoading
130
+ loadingTitle={title}
131
+ handleClose={handleClose}
132
+ handleSuccess={handleSuccess}
133
+ />
134
+ )
135
+ }
136
+
137
+ return (
138
+ <WidgetWrapper
139
+ isOpen
140
+ loadingTitle={title}
141
+ handleClose={handleClose}
142
+ handleSuccess={handleWithdrawSuccess}
143
+ >
144
+ {step === WIDGET_STEP.ConfirmTransfer && (
145
+ <ConfirmTransfer
146
+ poolInfo={poolInfo}
147
+ tranche={trancheType}
148
+ redemptionStatus={redemptionStatus}
149
+ poolUnderlyingToken={poolUnderlyingToken}
150
+ poolIsClosed={poolIsClosed}
151
+ />
152
+ )}
153
+ {step === WIDGET_STEP.Transfer && (
154
+ <Transfer
155
+ poolInfo={poolInfo}
156
+ tranche={trancheType}
157
+ poolIsClosed={poolIsClosed}
158
+ />
159
+ )}
160
+ {step === WIDGET_STEP.Done && (
161
+ <Done
162
+ poolUnderlyingToken={poolUnderlyingToken}
163
+ withdrawAmount={redemptionStatus.withdrawableAssets}
164
+ handleAction={handleClose}
165
+ />
166
+ )}
167
+ {step === WIDGET_STEP.Error && (
168
+ <ErrorModal
169
+ title={title}
170
+ errorReason='Sorry there was an error'
171
+ errorMessage={errorMessage}
172
+ handleOk={handleClose}
173
+ />
174
+ )}
175
+ </WidgetWrapper>
176
+ )
177
+ }