@huma-finance/widgets 0.0.48-beta.186 → 0.0.48-beta.188

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huma-finance/widgets",
3
- "version": "0.0.48-beta.186+0a076b2",
3
+ "version": "0.0.48-beta.188+fa13511",
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.186+0a076b2",
34
- "@huma-finance/shared": "^0.0.48-beta.186+0a076b2",
33
+ "@huma-finance/sdk": "^0.0.47",
34
+ "@huma-finance/shared": "^0.0.47",
35
35
  "@mui/icons-material": "^5.3.0",
36
36
  "@mui/material": "^5.0.6",
37
37
  "@mui/styles": "^5.0.2",
@@ -192,5 +192,5 @@
192
192
  "optionalDependencies": {
193
193
  "encoding": "^0.1.13"
194
194
  },
195
- "gitHead": "0a076b2a0a92ec06e3d311e1541f7b3c0ab52b21"
195
+ "gitHead": "fa13511dd738b17865b849f8744c28bdf3393c3f"
196
196
  }
@@ -9,18 +9,24 @@ import { ChooseAmountModal } from '../../ChooseAmountModal'
9
9
 
10
10
  type Props = {
11
11
  lenderPosition: BigNumber
12
+ poolBalance: BigNumber
12
13
  poolInfo: PoolInfoType
13
14
  }
14
15
 
15
16
  export function ChooseAmount({
16
17
  lenderPosition,
18
+ poolBalance,
17
19
  poolInfo,
18
20
  }: Props): React.ReactElement | null {
19
21
  const dispatch = useAppDispatch()
20
22
  const { poolUnderlyingToken } = poolInfo
21
23
  const { symbol, decimals } = poolUnderlyingToken
22
24
  const [currentAmount, setCurrentAmount] = useState(0)
23
- const withdrawableAmount = downScale<number>(lenderPosition, decimals)
25
+ // Take the minimum of the pool balance or the lender position
26
+ const withdrawableAmountBN = lenderPosition.lt(poolBalance)
27
+ ? lenderPosition
28
+ : poolBalance
29
+ const withdrawableAmount = downScale<number>(withdrawableAmountBN, decimals)
24
30
 
25
31
  const handleChangeAmount = useCallback(
26
32
  (newAmount: number) => {
@@ -3,6 +3,7 @@ import {
3
3
  POOL_NAME,
4
4
  POOL_TYPE,
5
5
  useLenderPosition,
6
+ usePoolBalance,
6
7
  usePoolInfo,
7
8
  } from '@huma-finance/shared'
8
9
  import React, { useCallback, useEffect } from 'react'
@@ -51,21 +52,23 @@ export function LendWithdraw({
51
52
  poolType,
52
53
  account,
53
54
  )
55
+ const [poolBalance, refreshPoolBalance] = usePoolBalance(poolName, poolType)
54
56
 
55
57
  useEffect(() => {
56
- if (!step && lenderPosition) {
58
+ if (!step && lenderPosition && poolBalance) {
57
59
  dispatch(setStep(WIDGET_STEP.CheckWithdrawable))
58
60
  }
59
- }, [dispatch, lenderPosition, step])
61
+ }, [dispatch, lenderPosition, poolBalance, step])
60
62
 
61
63
  const handleWithdrawSuccess = useCallback(
62
64
  (blockNumber: number) => {
63
65
  refreshLenderPosition()
66
+ refreshPoolBalance()
64
67
  if (handleSuccess) {
65
68
  handleSuccess(blockNumber)
66
69
  }
67
70
  },
68
- [handleSuccess, refreshLenderPosition],
71
+ [handleSuccess, refreshLenderPosition, refreshPoolBalance],
69
72
  )
70
73
 
71
74
  if (!poolInfo) {
@@ -82,7 +85,11 @@ export function LendWithdraw({
82
85
  <CheckWithdrawable poolInfo={poolInfo} handleClose={handleClose} />
83
86
  )}
84
87
  {step === WIDGET_STEP.ChooseAmount && (
85
- <ChooseAmount poolInfo={poolInfo} lenderPosition={lenderPosition!} />
88
+ <ChooseAmount
89
+ poolInfo={poolInfo}
90
+ lenderPosition={lenderPosition!}
91
+ poolBalance={poolBalance!}
92
+ />
86
93
  )}
87
94
  {step === WIDGET_STEP.Transfer && <Transfer poolInfo={poolInfo} />}
88
95
  {step === WIDGET_STEP.Done && (