@huma-finance/widgets 0.0.59-beta.480 → 0.0.59-beta.482

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.
@@ -2,6 +2,7 @@ import {
2
2
  POOL_NAME,
3
3
  TrancheType,
4
4
  openInNewTab,
5
+ useLPConfigV2,
5
6
  useLenderApprovedV2,
6
7
  usePoolInfoV2,
7
8
  usePoolUnderlyingTokenInfoV2,
@@ -28,17 +29,20 @@ import { Notifications } from './7-Notifications'
28
29
  * Lend pool supply props
29
30
  * @typedef {Object} LendSupplyPropsV2
30
31
  * @property {POOL_NAME} poolName The name of the pool.
32
+ * @property {boolean} shouldApproveAll To check if should approve both tranches.
31
33
  * @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
32
34
  * @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the lending pool supply action is successful.
33
35
  */
34
36
  export interface LendSupplyPropsV2 {
35
37
  poolName: keyof typeof POOL_NAME
38
+ shouldApproveAll?: boolean
36
39
  handleClose: () => void
37
40
  handleSuccess?: (blockNumber?: number) => void
38
41
  }
39
42
 
40
43
  export function LendSupplyV2({
41
44
  poolName: poolNameStr,
45
+ shouldApproveAll,
42
46
  handleClose,
43
47
  handleSuccess,
44
48
  }: LendSupplyPropsV2): React.ReactElement | null {
@@ -49,7 +53,8 @@ export function LendSupplyV2({
49
53
  const { step, errorMessage } = useAppSelector(selectWidgetState)
50
54
  const [selectedTranche, setSelectedTranche] = useState<TrancheType>()
51
55
  const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
52
-
56
+ const lpConfig = useLPConfigV2(poolName, provider)
57
+ const isUniTranche = lpConfig?.maxSeniorJuniorRatio === 0
53
58
  const [lenderApprovedSenior] = useLenderApprovedV2(
54
59
  poolName,
55
60
  'senior',
@@ -67,7 +72,21 @@ export function LendSupplyV2({
67
72
  lenderApprovedSenior !== undefined && lenderApprovedJunior !== undefined
68
73
 
69
74
  useEffect(() => {
70
- if (!step && poolInfo && lenderApproveStatusFetched) {
75
+ if (!step && poolInfo && lenderApproveStatusFetched && lpConfig) {
76
+ if (
77
+ shouldApproveAll &&
78
+ !isUniTranche &&
79
+ (!lenderApprovedJunior || !lenderApprovedSenior)
80
+ ) {
81
+ if (poolInfo.KYC) {
82
+ dispatch(setStep(WIDGET_STEP.Evaluation))
83
+ } else if (poolInfo.supplyLink) {
84
+ openInNewTab(poolInfo.supplyLink)
85
+ handleClose()
86
+ }
87
+ return
88
+ }
89
+
71
90
  if (lenderApprovedJunior && !lenderApprovedSenior) {
72
91
  setSelectedTranche('junior')
73
92
  dispatch(setStep(WIDGET_STEP.ChooseAmount))
@@ -98,14 +117,22 @@ export function LendSupplyV2({
98
117
  }, [
99
118
  dispatch,
100
119
  handleClose,
120
+ isUniTranche,
101
121
  lenderApproveStatusFetched,
102
122
  lenderApprovedJunior,
103
123
  lenderApprovedSenior,
124
+ lpConfig,
104
125
  poolInfo,
126
+ shouldApproveAll,
105
127
  step,
106
128
  ])
107
129
 
108
- if (!poolInfo || !poolUnderlyingToken || !lenderApproveStatusFetched) {
130
+ if (
131
+ !poolInfo ||
132
+ !poolUnderlyingToken ||
133
+ !lenderApproveStatusFetched ||
134
+ !lpConfig
135
+ ) {
109
136
  return (
110
137
  <WidgetWrapper
111
138
  isOpen
@@ -132,13 +159,19 @@ export function LendSupplyV2({
132
159
  />
133
160
  )}
134
161
  {step === WIDGET_STEP.Evaluation && (
135
- <Evaluation poolInfo={poolInfo} handleClose={handleClose} />
162
+ <Evaluation
163
+ poolInfo={poolInfo}
164
+ handleClose={handleClose}
165
+ isUniTranche={isUniTranche}
166
+ changeTranche={setSelectedTranche}
167
+ />
136
168
  )}
137
169
  {step === WIDGET_STEP.ChooseAmount && (
138
170
  <ChooseAmount
139
171
  poolInfo={poolInfo}
140
172
  poolUnderlyingToken={poolUnderlyingToken}
141
173
  selectedTranche={selectedTranche}
174
+ isUniTranche={isUniTranche}
142
175
  />
143
176
  )}
144
177
  {step === WIDGET_STEP.ApproveAllowance && (
@@ -48,6 +48,7 @@ export function HumaModal({
48
48
 
49
49
  return (
50
50
  <Dialog
51
+ id='huma-modal'
51
52
  disableScrollLock
52
53
  maxWidth={false}
53
54
  fullScreen={isXsSize}
@@ -108,7 +108,6 @@ export const widgetSlice = createSlice({
108
108
  payload,
109
109
  }: PayloadAction<{ errorMessage: string; errorReason?: string }>,
110
110
  ) => {
111
- console.trace()
112
111
  state.errorMessage = payload.errorMessage
113
112
  state.errorReason = payload.errorReason
114
113
  state.step = WIDGET_STEP.Error