@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
@@ -0,0 +1,120 @@
1
+ import {
2
+ POOL_NAME,
3
+ TrancheType,
4
+ useCancellableRedemptionInfoV2,
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 } 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 { Transfer } from './1-Transfer'
20
+ import { Done } from './2-Done'
21
+
22
+ export type RedemptionInfo = {
23
+ shares: BigNumber
24
+ amount: BigNumber
25
+ }
26
+
27
+ /**
28
+ * Lend pool cancel redemption request props
29
+ * @typedef {Object} CancelRedemptionPropsV2
30
+ * @property {POOL_NAME} poolName The name of the pool.
31
+ * @property {TrancheType} trancheType The type of the tranche.
32
+ * @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
33
+ * @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the lending pool withdraw action is successful.
34
+ */
35
+ export type CancelRedemptionPropsV2 = {
36
+ poolName: keyof typeof POOL_NAME
37
+ trancheType: TrancheType
38
+ handleClose: () => void
39
+ handleSuccess?: (blockNumber?: number) => void
40
+ }
41
+
42
+ export function CancelRedemptionV2({
43
+ poolName: poolNameStr,
44
+ trancheType,
45
+ handleClose,
46
+ handleSuccess,
47
+ }: CancelRedemptionPropsV2): React.ReactElement | null {
48
+ const title = 'Cancel 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 [redemptionInfo] = useCancellableRedemptionInfoV2(
56
+ poolName,
57
+ trancheType,
58
+ account,
59
+ provider,
60
+ )
61
+
62
+ useEffect(() => {
63
+ if (!step) {
64
+ dispatch(setStep(WIDGET_STEP.Transfer))
65
+ }
66
+ }, [dispatch, step])
67
+
68
+ const handleRedeemSuccess = useCallback(
69
+ (blockNumber: number) => {
70
+ if (handleSuccess) {
71
+ handleSuccess(blockNumber)
72
+ }
73
+ },
74
+ [handleSuccess],
75
+ )
76
+
77
+ if (!poolInfo || !poolUnderlyingToken || !redemptionInfo) {
78
+ return (
79
+ <WidgetWrapper
80
+ isOpen
81
+ isLoading
82
+ loadingTitle={title}
83
+ handleClose={handleClose}
84
+ handleSuccess={handleSuccess}
85
+ />
86
+ )
87
+ }
88
+
89
+ return (
90
+ <WidgetWrapper
91
+ isOpen
92
+ loadingTitle={title}
93
+ handleClose={handleClose}
94
+ handleSuccess={handleRedeemSuccess}
95
+ >
96
+ {step === WIDGET_STEP.Transfer && (
97
+ <Transfer
98
+ poolInfo={poolInfo}
99
+ trancheType={trancheType}
100
+ redemptionInfo={redemptionInfo}
101
+ />
102
+ )}
103
+ {step === WIDGET_STEP.Done && (
104
+ <Done
105
+ poolUnderlyingToken={poolUnderlyingToken}
106
+ handleAction={handleClose}
107
+ redemptionInfo={redemptionInfo}
108
+ />
109
+ )}
110
+ {step === WIDGET_STEP.Error && (
111
+ <ErrorModal
112
+ title={title}
113
+ errorReason={errorReason}
114
+ errorMessage={errorMessage}
115
+ handleOk={handleClose}
116
+ />
117
+ )}
118
+ </WidgetWrapper>
119
+ )
120
+ }
@@ -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]}
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 && (