@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huma-finance/widgets",
3
- "version": "0.0.48-beta.296+a50d41c",
3
+ "version": "0.0.48-beta.298+d1ebb18",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -30,8 +30,8 @@
30
30
  "@ethersproject/experimental": "^5.7.0",
31
31
  "@ethersproject/providers": "^5.6.0",
32
32
  "@ethersproject/units": "^5.6.0",
33
- "@huma-finance/sdk": "^0.0.48-beta.296+a50d41c",
34
- "@huma-finance/shared": "^0.0.48-beta.296+a50d41c",
33
+ "@huma-finance/sdk": "^0.0.48-beta.298+d1ebb18",
34
+ "@huma-finance/shared": "^0.0.48-beta.298+d1ebb18",
35
35
  "@mui/icons-material": "^5.3.0",
36
36
  "@mui/material": "^5.0.6",
37
37
  "@mui/styles": "^5.0.2",
@@ -193,5 +193,5 @@
193
193
  "optionalDependencies": {
194
194
  "encoding": "^0.1.13"
195
195
  },
196
- "gitHead": "a50d41ce9bafdb1b8894da5c38a139b4efcda676"
196
+ "gitHead": "d1ebb189766905904362198e7b0205e2b2ff39bc"
197
197
  }
@@ -43,7 +43,7 @@ export function Transfer({ poolInfo }: Props): React.ReactElement {
43
43
  title='Borrow'
44
44
  contract={creditContract}
45
45
  method='drawdown'
46
- params={[account, borrowAmountBN]}
46
+ params={[borrowAmountBN]}
47
47
  handleSuccess={handleSuccess}
48
48
  />
49
49
  )
@@ -45,6 +45,11 @@ export function ChooseAmount({
45
45
  ethers.utils.formatUnits(payoffAmountBN, decimals),
46
46
  )
47
47
 
48
+ console.log('totalDueAmountBN', totalDueAmountBN.toString())
49
+ console.log('payoffAmountBN', payoffAmountBN.toString())
50
+ console.log('payoffAmount', payoffAmount)
51
+ console.log('currentAmount', currentAmount)
52
+
48
53
  useEffect(() => {
49
54
  setCurrentAmount(totalDueAmount)
50
55
  }, [totalDueAmount])
@@ -10,9 +10,11 @@ type Props = {
10
10
  subTitle: string
11
11
  actionText: string
12
12
  tokenSymbol: string
13
+ suffix?: string
13
14
  currentAmount: number | string
14
15
  maxAmount: number | string
15
16
  maxAmountText?: string
17
+ maxAmountTitle?: string
16
18
  info?: string
17
19
  handleChangeAmount: (amount: number) => void
18
20
  handleAction: () => void
@@ -23,16 +25,18 @@ export function InputAmountModal({
23
25
  subTitle,
24
26
  actionText,
25
27
  tokenSymbol,
28
+ suffix: defaultSuffix,
26
29
  currentAmount,
27
30
  maxAmount,
28
31
  maxAmountText = 'MAX',
32
+ maxAmountTitle,
29
33
  info,
30
34
  handleChangeAmount,
31
35
  handleAction,
32
36
  }: Props): React.ReactElement | null {
33
37
  const theme = useTheme()
34
38
  const [inputTouched, setInputTouched] = useState(false)
35
- const suffix = ` ${tokenSymbol}`
39
+ const suffix = ` ${defaultSuffix ?? tokenSymbol}`
36
40
 
37
41
  const styles = {
38
42
  inputAmountWrapper: css`
@@ -51,23 +55,39 @@ export function InputAmountModal({
51
55
  line-height: 133.4%;
52
56
  }
53
57
  `,
58
+ maxWrapper: css`
59
+ position: relative;
60
+ display: flex;
61
+ justify-content: flex-end;
62
+ `,
63
+ maxTitle: css`
64
+ position: absolute;
65
+ color: ${theme.palette.text.primary};
66
+ font-family: 'Uni-Neue-Regular';
67
+ font-size: 12px;
68
+ line-height: 166%;
69
+ letter-spacing: 0.4px;
70
+ top: ${theme.spacing(-3)};
71
+ width: 200px;
72
+ text-align: right;
73
+ `,
54
74
  max: css`
55
75
  display: flex;
56
76
  min-width: fit-content;
57
77
  justify-content: center;
58
78
  align-items: center;
59
79
  border-radius: 32px;
60
- background: var(--Purple-3, #f7f1ff);
80
+ background: #f7f1ff;
61
81
  padding: 4px 10px;
62
82
  gap: 8px;
63
- color: var(--Purple-1, #b246ff);
83
+ color: #b246ff;
64
84
  font-family: 'Uni-Neue-Bold';
65
85
  font-size: 13px;
66
86
  line-height: 22px;
67
87
  letter-spacing: 0.46px;
68
88
  `,
69
89
  info: css`
70
- color: var(--Black-5, #6b6572);
90
+ color: ${theme.palette.text.primary};
71
91
  font-family: 'Uni-Neue-Bold';
72
92
  font-size: 20px;
73
93
  line-height: 160%;
@@ -105,7 +125,14 @@ export function InputAmountModal({
105
125
  placeholder={`0${suffix}`}
106
126
  variant='standard'
107
127
  InputProps={{
108
- endAdornment: (
128
+ endAdornment: maxAmountTitle ? (
129
+ <Box css={styles.maxWrapper}>
130
+ <Box css={styles.maxTitle}>{maxAmountTitle}</Box>
131
+ <Button css={styles.max} onClick={setMaxAmount}>
132
+ {maxAmountText}
133
+ </Button>
134
+ </Box>
135
+ ) : (
109
136
  <Button css={styles.max} onClick={setMaxAmount}>
110
137
  {maxAmountText}
111
138
  </Button>
@@ -1,4 +1,4 @@
1
- import { UnderlyingTokenInfo } from '@huma-finance/shared'
1
+ import { TrancheType } 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 { WithdrawType } 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'
@@ -18,21 +17,16 @@ import { BottomButton } from '../../BottomButton'
18
17
  import { WrapperModal } from '../../WrapperModal'
19
18
 
20
19
  type Props = {
21
- poolUnderlyingToken: UnderlyingTokenInfo
22
- selectedWithdrawType: WithdrawType | undefined
23
- withdrawTypes: WithdrawType[]
24
- changeWithdrawType: (WithdrawType: WithdrawType) => void
20
+ selectedTranche: TrancheType | undefined
21
+ changeTranche: (tranche: TrancheType) => void
25
22
  }
26
23
 
27
24
  export function ChooseTranche({
28
- poolUnderlyingToken,
29
- selectedWithdrawType,
30
- withdrawTypes,
31
- changeWithdrawType,
25
+ selectedTranche,
26
+ changeTranche,
32
27
  }: Props): React.ReactElement | null {
33
28
  const theme = useTheme()
34
29
  const dispatch = useAppDispatch()
35
- const { symbol } = poolUnderlyingToken
36
30
 
37
31
  const styles = {
38
32
  subTitle: css`
@@ -61,34 +55,35 @@ export function ChooseTranche({
61
55
  `,
62
56
  }
63
57
 
64
- const handleChangeWithdrawType = (withdrawTypeValue: string | number) => {
65
- const withdrawType = withdrawTypes.find(
66
- (item) => item.value === withdrawTypeValue,
67
- )
68
- if (withdrawType) {
69
- changeWithdrawType(withdrawType)
70
- }
71
- }
72
-
73
58
  const handleNext = () => {
74
- if (selectedWithdrawType?.type === 'firstLossCover') {
75
- dispatch(setStep(WIDGET_STEP.ChooseAmount))
76
- } else {
77
- dispatch(setStep(WIDGET_STEP.Transfer))
78
- }
59
+ dispatch(setStep(WIDGET_STEP.ChooseAmount))
79
60
  }
80
61
 
62
+ const items: {
63
+ label: string
64
+ value: TrancheType
65
+ }[] = [
66
+ {
67
+ label: 'Senior',
68
+ value: 'senior',
69
+ },
70
+ {
71
+ label: 'Junior',
72
+ value: 'junior',
73
+ },
74
+ ]
75
+
81
76
  return (
82
- <WrapperModal title={`Withdraw ${symbol}`}>
77
+ <WrapperModal title='Redemption'>
83
78
  <FormControl>
84
- <FormLabel css={styles.subTitle}>Select Withdraw Type</FormLabel>
79
+ <FormLabel css={styles.subTitle}>Select Tranche Type</FormLabel>
85
80
  <RadioGroup
86
81
  aria-labelledby='buttons-group-label'
87
82
  name='radio-buttons-group'
88
83
  css={styles.radioGroup}
89
- onChange={(e) => handleChangeWithdrawType(e.target.value)}
84
+ onChange={(e) => changeTranche(e.target.value as TrancheType)}
90
85
  >
91
- {withdrawTypes.map((item) => (
86
+ {items.map((item) => (
92
87
  <FormControlLabel
93
88
  key={item.label}
94
89
  value={item.value}
@@ -109,7 +104,7 @@ export function ChooseTranche({
109
104
  </FormControl>
110
105
  <BottomButton
111
106
  variant='contained'
112
- disabled={!selectedWithdrawType}
107
+ disabled={!selectedTranche}
113
108
  onClick={handleNext}
114
109
  >
115
110
  NEXT
@@ -0,0 +1,62 @@
1
+ import { formatNumber, UnderlyingTokenInfo } from '@huma-finance/shared'
2
+ import { ethers } from 'ethers'
3
+ import React, { useState } from 'react'
4
+
5
+ import { TrancheInfo } from '.'
6
+ import { useAppDispatch } from '../../../hooks/useRedux'
7
+ import {
8
+ setRedeemAmount,
9
+ setRedeemShares,
10
+ setStep,
11
+ } from '../../../store/widgets.reducers'
12
+ import { WIDGET_STEP } from '../../../store/widgets.store'
13
+ import { InputAmountModal } from '../../InputAmountModal'
14
+
15
+ type Props = {
16
+ poolUnderlyingToken: UnderlyingTokenInfo
17
+ trancheInfo: TrancheInfo
18
+ }
19
+
20
+ export function ChooseAmount({
21
+ poolUnderlyingToken,
22
+ trancheInfo,
23
+ }: Props): React.ReactElement | null {
24
+ const dispatch = useAppDispatch()
25
+ const { symbol } = poolUnderlyingToken
26
+ const [currentAmount, setCurrentAmount] = useState<number>(0)
27
+ const [currentShares, setCurrentShares] = useState<number>(0)
28
+ const maxSharesFormatted = ethers.utils.formatUnits(
29
+ trancheInfo.shares,
30
+ poolUnderlyingToken.decimals,
31
+ )
32
+ const sharePrice =
33
+ trancheInfo.assets.toNumber() / trancheInfo.shares.toNumber()
34
+
35
+ const handleChangeShares = (newShares: number) => {
36
+ const amount = Number(newShares) * sharePrice
37
+ setCurrentShares(Number(newShares))
38
+ setCurrentAmount(amount)
39
+ dispatch(setRedeemShares(Number(newShares)))
40
+ dispatch(setRedeemAmount(amount))
41
+ }
42
+
43
+ const handleAction = () => {
44
+ dispatch(setStep(WIDGET_STEP.Transfer))
45
+ }
46
+
47
+ return (
48
+ <InputAmountModal
49
+ title='Redemption'
50
+ subTitle={`Enter number of shares to redeem from ${trancheInfo.tranche} tranche`}
51
+ tokenSymbol={symbol}
52
+ currentAmount={currentShares}
53
+ handleChangeAmount={handleChangeShares}
54
+ maxAmount={maxSharesFormatted}
55
+ info={`${String(formatNumber(currentAmount))} ${symbol}`}
56
+ maxAmountTitle={`${formatNumber(maxSharesFormatted)} Shares`}
57
+ suffix='Shares'
58
+ handleAction={handleAction}
59
+ actionText='REQUEST'
60
+ />
61
+ )
62
+ }
@@ -4,10 +4,10 @@ import {
4
4
  useTrancheVaultContractV2,
5
5
  } from '@huma-finance/shared'
6
6
  import { useWeb3React } from '@web3-react/core'
7
+ import { ethers } from 'ethers'
7
8
  import React, { useCallback } from 'react'
8
9
 
9
- import { ethers } from 'ethers'
10
- import { REDEMPTION_TYPE, RedemptionActionInfo } from '.'
10
+ import { TrancheInfo } from '.'
11
11
  import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
12
12
  import { setStep } from '../../../store/widgets.reducers'
13
13
  import { selectWidgetState } from '../../../store/widgets.selectors'
@@ -17,43 +17,38 @@ import { TxSendModalV2 } from '../../TxSendModalV2'
17
17
  type Props = {
18
18
  poolInfo: PoolInfoV2
19
19
  poolUnderlyingToken: UnderlyingTokenInfo
20
- redemptionType: REDEMPTION_TYPE
20
+ trancheInfo: TrancheInfo
21
21
  }
22
22
 
23
23
  export function Transfer({
24
24
  poolInfo,
25
25
  poolUnderlyingToken,
26
- redemptionType,
26
+ trancheInfo,
27
27
  }: Props): React.ReactElement | null {
28
28
  const dispatch = useAppDispatch()
29
29
  const { decimals } = poolUnderlyingToken
30
30
  const { account, provider } = useWeb3React()
31
31
  const { redeemShares } = useAppSelector(selectWidgetState)
32
- const redemptionActionInfo = RedemptionActionInfo[redemptionType]
33
32
  const trancheVaultContract = useTrancheVaultContractV2(
34
33
  poolInfo.poolName,
35
- redemptionActionInfo.tranche,
34
+ trancheInfo.tranche,
36
35
  provider,
37
36
  account,
38
37
  )
39
38
  const redeemSharesBN = ethers.utils.parseUnits(String(redeemShares), decimals)
40
- const method =
41
- redemptionActionInfo.action === 'Create'
42
- ? 'addRedemptionRequest'
43
- : 'cancelRedemptionRequest'
44
39
 
45
40
  const handleSuccess = useCallback(() => {
46
41
  dispatch(setStep(WIDGET_STEP.Done))
47
42
  }, [dispatch])
48
43
 
49
- if (!trancheVaultContract || !account) {
44
+ if (!trancheVaultContract) {
50
45
  return null
51
46
  }
52
47
 
53
48
  return (
54
49
  <TxSendModalV2
55
50
  contract={trancheVaultContract}
56
- method={method}
51
+ method='addRedemptionRequest'
57
52
  params={[redeemSharesBN]}
58
53
  handleSuccess={handleSuccess}
59
54
  />
@@ -0,0 +1,20 @@
1
+ import { formatNumber } from '@huma-finance/shared'
2
+ import React from 'react'
3
+
4
+ import { useAppSelector } from '../../../hooks/useRedux'
5
+ import { selectWidgetState } from '../../../store/widgets.selectors'
6
+ import { TxDoneModal } from '../../TxDoneModal'
7
+
8
+ type Props = {
9
+ handleAction: () => void
10
+ }
11
+
12
+ export function Done({ handleAction }: Props): React.ReactElement {
13
+ const { redeemShares } = useAppSelector(selectWidgetState)
14
+
15
+ const content = [
16
+ `${formatNumber(redeemShares)} shares requested for redemption`,
17
+ ]
18
+
19
+ return <TxDoneModal handleAction={handleAction} content={content} />
20
+ }
@@ -0,0 +1,172 @@
1
+ import {
2
+ getTrancheAssetsAndShares,
3
+ POOL_NAME,
4
+ TrancheType,
5
+ usePoolInfoV2,
6
+ usePoolUnderlyingTokenInfoV2,
7
+ } from '@huma-finance/shared'
8
+ import { useWeb3React } from '@web3-react/core'
9
+ import { BigNumber } from 'ethers'
10
+ import React, { useCallback, 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 { ChooseAmount } from './2-ChooseAmount'
21
+ import { Transfer } from './3-Transfer'
22
+ import { Done } from './4-Done'
23
+
24
+ export type TrancheInfo = {
25
+ tranche: TrancheType
26
+ assets: BigNumber
27
+ shares: BigNumber
28
+ }
29
+
30
+ /**
31
+ * Lend pool add redemption props
32
+ * @typedef {Object} AddRedemptionPropsV2
33
+ * @property {POOL_NAME} poolName The name of the pool.
34
+ * @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
35
+ * @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the lending pool withdraw action is successful.
36
+ */
37
+ export type AddRedemptionPropsV2 = {
38
+ poolName: keyof typeof POOL_NAME
39
+ handleClose: () => void
40
+ handleSuccess?: (blockNumber?: number) => void
41
+ }
42
+
43
+ export function AddRedemptionV2({
44
+ poolName: poolNameStr,
45
+ handleClose,
46
+ handleSuccess,
47
+ }: AddRedemptionPropsV2): React.ReactElement | null {
48
+ const title = 'Redemption'
49
+ const dispatch = useDispatch()
50
+ const { account, chainId, provider } = useWeb3React()
51
+ const poolName = POOL_NAME[poolNameStr]
52
+ const poolInfo = usePoolInfoV2(poolName, chainId)
53
+ const { step, errorMessage, errorReason } = useAppSelector(selectWidgetState)
54
+ const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
55
+ const [seniorTrancheInfo, setSeniorTrancheInfo] = useState<TrancheInfo>()
56
+ const [juniorTrancheInfo, setJuniorTrancheInfo] = useState<TrancheInfo>()
57
+ const [trancheInfo, setTrancheInfo] = useState<TrancheInfo>()
58
+ const trancheInfoFetched = seniorTrancheInfo && juniorTrancheInfo
59
+
60
+ useEffect(() => {
61
+ if (account) {
62
+ getTrancheAssetsAndShares(poolName, 'senior', account, provider).then(
63
+ (info) => {
64
+ if (info) {
65
+ setSeniorTrancheInfo({ ...info, tranche: 'senior' })
66
+ }
67
+ },
68
+ )
69
+ getTrancheAssetsAndShares(poolName, 'junior', account, provider).then(
70
+ (info) => {
71
+ if (info) {
72
+ setJuniorTrancheInfo({ ...info, tranche: 'junior' })
73
+ }
74
+ },
75
+ )
76
+ }
77
+ }, [account, poolName, provider])
78
+
79
+ useEffect(() => {
80
+ if (!step && trancheInfoFetched) {
81
+ if (juniorTrancheInfo.assets.gt(0) && seniorTrancheInfo.assets.lte(0)) {
82
+ setTrancheInfo(juniorTrancheInfo)
83
+ dispatch(setStep(WIDGET_STEP.ChooseAmount))
84
+ return
85
+ }
86
+
87
+ if (seniorTrancheInfo.assets.gt(0) && juniorTrancheInfo.assets.lte(0)) {
88
+ setTrancheInfo(seniorTrancheInfo)
89
+ dispatch(setStep(WIDGET_STEP.ChooseAmount))
90
+ return
91
+ }
92
+
93
+ if (juniorTrancheInfo.assets.gt(0) && seniorTrancheInfo.assets.gt(0)) {
94
+ dispatch(setStep(WIDGET_STEP.ChooseTranche))
95
+ }
96
+ }
97
+ }, [dispatch, juniorTrancheInfo, seniorTrancheInfo, step, trancheInfoFetched])
98
+
99
+ const handleRedeemSuccess = useCallback(
100
+ (blockNumber: number) => {
101
+ if (handleSuccess) {
102
+ handleSuccess(blockNumber)
103
+ }
104
+ },
105
+ [handleSuccess],
106
+ )
107
+
108
+ const handleChangeTranche = useCallback(
109
+ (tranche: TrancheType) => {
110
+ if (tranche === 'senior') {
111
+ setTrancheInfo(seniorTrancheInfo)
112
+ } else if (tranche === 'junior') {
113
+ setTrancheInfo(juniorTrancheInfo)
114
+ } else {
115
+ setTrancheInfo(undefined)
116
+ }
117
+ },
118
+ [juniorTrancheInfo, seniorTrancheInfo],
119
+ )
120
+
121
+ if (!poolInfo || !poolUnderlyingToken || !trancheInfoFetched) {
122
+ return (
123
+ <WidgetWrapper
124
+ isOpen
125
+ isLoading
126
+ loadingTitle={title}
127
+ handleClose={handleClose}
128
+ handleSuccess={handleSuccess}
129
+ />
130
+ )
131
+ }
132
+
133
+ return (
134
+ <WidgetWrapper
135
+ isOpen
136
+ loadingTitle={title}
137
+ handleClose={handleClose}
138
+ handleSuccess={handleRedeemSuccess}
139
+ >
140
+ {step === WIDGET_STEP.ChooseTranche && (
141
+ <ChooseTranche
142
+ selectedTranche={trancheInfo?.tranche}
143
+ changeTranche={handleChangeTranche}
144
+ />
145
+ )}
146
+ {step === WIDGET_STEP.ChooseAmount && trancheInfo && (
147
+ <ChooseAmount
148
+ poolUnderlyingToken={poolUnderlyingToken}
149
+ trancheInfo={trancheInfo}
150
+ />
151
+ )}
152
+ {step === WIDGET_STEP.Transfer && trancheInfo && (
153
+ <Transfer
154
+ poolInfo={poolInfo}
155
+ poolUnderlyingToken={poolUnderlyingToken}
156
+ trancheInfo={trancheInfo}
157
+ />
158
+ )}
159
+ {step === WIDGET_STEP.Done && trancheInfo && (
160
+ <Done handleAction={handleClose} />
161
+ )}
162
+ {step === WIDGET_STEP.Error && (
163
+ <ErrorModal
164
+ title={title}
165
+ errorReason={errorReason}
166
+ errorMessage={errorMessage}
167
+ handleOk={handleClose}
168
+ />
169
+ )}
170
+ </WidgetWrapper>
171
+ )
172
+ }
@@ -0,0 +1,51 @@
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 { RedemptionInfo } from '.'
10
+ import { useAppDispatch } from '../../../hooks/useRedux'
11
+ import { setStep } from '../../../store/widgets.reducers'
12
+ import { WIDGET_STEP } from '../../../store/widgets.store'
13
+ import { TxSendModalV2 } from '../../TxSendModalV2'
14
+
15
+ type Props = {
16
+ poolInfo: PoolInfoV2
17
+ trancheType: TrancheType
18
+ redemptionInfo: RedemptionInfo
19
+ }
20
+
21
+ export function Transfer({
22
+ poolInfo,
23
+ trancheType,
24
+ redemptionInfo,
25
+ }: Props): React.ReactElement | null {
26
+ const dispatch = useAppDispatch()
27
+ const { account, provider } = useWeb3React()
28
+ const trancheVaultContract = useTrancheVaultContractV2(
29
+ poolInfo.poolName,
30
+ trancheType,
31
+ provider,
32
+ account,
33
+ )
34
+
35
+ const handleSuccess = useCallback(() => {
36
+ dispatch(setStep(WIDGET_STEP.Done))
37
+ }, [dispatch])
38
+
39
+ if (!trancheVaultContract) {
40
+ return null
41
+ }
42
+
43
+ return (
44
+ <TxSendModalV2
45
+ contract={trancheVaultContract}
46
+ method='cancelRedemptionRequest'
47
+ params={[redemptionInfo.shares]}
48
+ handleSuccess={handleSuccess}
49
+ />
50
+ )
51
+ }
@@ -0,0 +1,29 @@
1
+ import { UnderlyingTokenInfo } from '@huma-finance/shared'
2
+ import { ethers } from 'ethers'
3
+ import React from 'react'
4
+
5
+ import { RedemptionInfo } from '.'
6
+ import { TxDoneModal } from '../../TxDoneModal'
7
+
8
+ type Props = {
9
+ poolUnderlyingToken: UnderlyingTokenInfo
10
+ redemptionInfo: RedemptionInfo
11
+ handleAction: () => void
12
+ }
13
+
14
+ export function Done({
15
+ poolUnderlyingToken,
16
+ redemptionInfo,
17
+ handleAction,
18
+ }: Props): React.ReactElement {
19
+ const shares = ethers.utils.formatUnits(
20
+ redemptionInfo.shares,
21
+ poolUnderlyingToken.decimals,
22
+ )
23
+
24
+ const content = [
25
+ `You successfully canceled ${shares} shares redemption request.`,
26
+ ]
27
+
28
+ return <TxDoneModal handleAction={handleAction} content={content} />
29
+ }