@huma-finance/widgets 0.0.48-beta.284 → 0.0.48-beta.286

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,8 @@
1
1
  import {
2
2
  POOL_NAME,
3
3
  TrancheType,
4
+ openInNewTab,
5
+ useLenderApprovedV2,
4
6
  usePoolInfoV2,
5
7
  usePoolUnderlyingTokenInfoV2,
6
8
  } from '@huma-finance/shared'
@@ -42,19 +44,66 @@ export function LendSupplyV2({
42
44
  }: LendSupplyPropsV2): React.ReactElement | null {
43
45
  const dispatch = useDispatch()
44
46
  const poolName = POOL_NAME[poolNameStr]
45
- const { chainId, provider } = useWeb3React()
47
+ const { chainId, provider, account } = useWeb3React()
46
48
  const poolInfo = usePoolInfoV2(poolName, chainId)
47
49
  const { step, errorMessage } = useAppSelector(selectWidgetState)
48
50
  const [selectedTranche, setSelectedTranche] = useState<TrancheType>()
49
51
  const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
50
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
+
51
69
  useEffect(() => {
52
- if (!step) {
53
- dispatch(setStep(WIDGET_STEP.ChooseTranche))
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
+ }
54
96
  }
55
- }, [dispatch, step])
97
+ }, [
98
+ dispatch,
99
+ lenderApproveStatusFetched,
100
+ lenderApprovedJunior,
101
+ lenderApprovedSenior,
102
+ poolInfo,
103
+ step,
104
+ ])
56
105
 
57
- if (!poolInfo || !poolUnderlyingToken) {
106
+ if (!poolInfo || !poolUnderlyingToken || !lenderApproveStatusFetched) {
58
107
  return (
59
108
  <WidgetWrapper
60
109
  isOpen
@@ -75,7 +124,6 @@ export function LendSupplyV2({
75
124
  >
76
125
  {step === WIDGET_STEP.ChooseTranche && (
77
126
  <ChooseTranche
78
- poolInfo={poolInfo}
79
127
  poolUnderlyingToken={poolUnderlyingToken}
80
128
  selectedTranche={selectedTranche}
81
129
  changeTranche={setSelectedTranche}
@@ -4,13 +4,14 @@ import { NumericFormat, NumericFormatProps } from 'react-number-format'
4
4
  interface CustomProps {
5
5
  onChange: (event: { target: { name: string; value: string } }) => void
6
6
  name: string
7
+ suffix?: string
7
8
  }
8
9
 
9
10
  export const NumericFormatCustom = React.forwardRef<
10
11
  NumericFormatProps,
11
12
  CustomProps
12
13
  >((props, ref) => {
13
- const { onChange, ...other } = props
14
+ const { onChange, suffix, ...other } = props
14
15
 
15
16
  return (
16
17
  <NumericFormat
@@ -26,6 +27,7 @@ export const NumericFormatCustom = React.forwardRef<
26
27
  }}
27
28
  thousandSeparator
28
29
  valueIsNumericString
30
+ suffix={suffix}
29
31
  />
30
32
  )
31
33
  })