@huma-finance/widgets 0.0.48-v2.278 → 0.0.48-v2.296

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,9 +2,10 @@ import {
2
2
  PoolInfoV2,
3
3
  TrancheType,
4
4
  UnderlyingTokenInfo,
5
+ formatNumber,
5
6
  usePoolSafeAllowanceV2,
7
+ usePoolUnderlyingTokenBalanceV2,
6
8
  } from '@huma-finance/shared'
7
- import { Box, css, TextField, useTheme } from '@mui/material'
8
9
  import { useWeb3React } from '@web3-react/core'
9
10
  import { BigNumber, ethers } from 'ethers'
10
11
  import React, { useState } from 'react'
@@ -12,9 +13,7 @@ import React, { useState } from 'react'
12
13
  import { useAppDispatch } from '../../../hooks/useRedux'
13
14
  import { setStep, setSupplyAmount } from '../../../store/widgets.reducers'
14
15
  import { WIDGET_STEP } from '../../../store/widgets.store'
15
- import { BottomButton } from '../../BottomButton'
16
- import { NumericFormatCustom } from '../../NumericFormatCustom'
17
- import { WrapperModal } from '../../WrapperModal'
16
+ import { InputAmountModal } from '../../InputAmountModal'
18
17
 
19
18
  type Props = {
20
19
  poolInfo: PoolInfoV2
@@ -27,7 +26,6 @@ export function ChooseAmount({
27
26
  poolUnderlyingToken,
28
27
  selectedTranche,
29
28
  }: Props): React.ReactElement | null {
30
- const theme = useTheme()
31
29
  const dispatch = useAppDispatch()
32
30
  const { account, provider } = useWeb3React()
33
31
  const { symbol, decimals } = poolUnderlyingToken
@@ -37,38 +35,17 @@ export function ChooseAmount({
37
35
  account,
38
36
  provider,
39
37
  )
40
- const [inputTouched, setInputTouched] = useState(false)
41
-
42
- const styles = {
43
- inputAmountWrapper: css`
44
- margin-bottom: ${theme.spacing(1)};
45
- margin-top: ${theme.spacing(16)};
46
- `,
47
- inputAmount: css`
48
- ${theme.cssMixins.rowSpaceBetweened};
49
- `,
50
- inputField: css`
51
- input {
52
- width: 100%;
53
- color: ${theme.palette.text.primary};
54
- font-family: 'Uni-Neue-Black';
55
- font-size: 40px;
56
- line-height: 133.4%;
57
- }
58
- `,
59
- inputFieldSymbol: css`
60
- color: ${theme.palette.text.primary};
61
- font-family: 'Uni-Neue-Black';
62
- font-size: 40px;
63
- line-height: 133.4%;
64
- `,
65
- }
38
+ const [balance] = usePoolUnderlyingTokenBalanceV2(
39
+ poolInfo.poolName,
40
+ account,
41
+ provider,
42
+ )
43
+ const maxAmountFormatted = ethers.utils.formatUnits(
44
+ balance,
45
+ poolUnderlyingToken.decimals,
46
+ )
66
47
 
67
- const handleChangeAmount = (
68
- event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>,
69
- ) => {
70
- setInputTouched(true)
71
- const newAmount = event.target.value
48
+ const handleChangeAmount = (newAmount: number) => {
72
49
  setCurrentAmount(newAmount)
73
50
  dispatch(setSupplyAmount(Number(newAmount)))
74
51
  }
@@ -85,38 +62,16 @@ export function ChooseAmount({
85
62
  }
86
63
 
87
64
  return (
88
- <WrapperModal
65
+ <InputAmountModal
89
66
  title='Enter Amount'
90
67
  subTitle={`Supplying ${symbol} with ${selectedTranche}`}
91
- >
92
- <Box css={styles.inputAmountWrapper}>
93
- <Box css={styles.inputAmount}>
94
- <TextField
95
- css={styles.inputField}
96
- value={!inputTouched && currentAmount === 0 ? '' : currentAmount}
97
- onChange={handleChangeAmount}
98
- InputProps={{
99
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
100
- inputComponent: NumericFormatCustom as any,
101
- endAdornment: (
102
- <Box component='span' css={styles.inputFieldSymbol}>
103
- {symbol}
104
- </Box>
105
- ),
106
- }}
107
- placeholder='0'
108
- variant='standard'
109
- />
110
- </Box>
111
- </Box>
112
-
113
- <BottomButton
114
- variant='contained'
115
- onClick={handleAction}
116
- disabled={Number(currentAmount) <= 0}
117
- >
118
- SUPPLY
119
- </BottomButton>
120
- </WrapperModal>
68
+ tokenSymbol={symbol}
69
+ currentAmount={currentAmount}
70
+ handleChangeAmount={handleChangeAmount}
71
+ maxAmount={maxAmountFormatted}
72
+ info={`${formatNumber(maxAmountFormatted)} Available`}
73
+ handleAction={handleAction}
74
+ actionText='SUPPLY'
75
+ />
121
76
  )
122
77
  }
@@ -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
  })
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  CreditStatsV2,
3
+ formatNumber,
3
4
  timeUtil,
4
5
  UnderlyingTokenInfo,
5
6
  } from '@huma-finance/shared'
@@ -27,7 +28,7 @@ export function Success({
27
28
  const dueDate = timeUtil.timestampToLL(creditRecord?.nextDueDate.toNumber())
28
29
 
29
30
  const content = [
30
- `${borrowAmountNet} ${symbol} is now in your wallet.`,
31
+ `${formatNumber(borrowAmountNet)} ${symbol} is now in your wallet.`,
31
32
  `Note: your payment will be automatically deducted on ${dueDate}.`,
32
33
  ]
33
34
 
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  decodeLogs,
3
3
  downScale,
4
- formatMoney,
4
+ formatNumber,
5
5
  TRANSFER_ABI,
6
6
  UnderlyingTokenInfo,
7
7
  } from '@huma-finance/shared'
@@ -37,12 +37,12 @@ export function Success({
37
37
  }
38
38
  }, [decimals, successTxReceipt])
39
39
 
40
- const amoutFormatted = formatMoney(paidAmount)
40
+ const amountFormatted = formatNumber(paidAmount)
41
41
  const content =
42
42
  paymentType === PaymentType.PaymentWithReceivable
43
- ? [`You successfully paid ${amoutFormatted} ${symbol}.`]
43
+ ? [`You successfully paid ${amountFormatted} ${symbol}.`]
44
44
  : [
45
- `You successfully paid ${amoutFormatted} ${symbol} and borrowed ${amoutFormatted} ${symbol}.`,
45
+ `You successfully paid ${amountFormatted} ${symbol} and borrowed ${amountFormatted} ${symbol}.`,
46
46
  ]
47
47
 
48
48
  return <TxDoneModal handleAction={handleAction} content={content} />
@@ -1,4 +1,6 @@
1
+ import { formatNumber } from '@huma-finance/shared'
1
2
  import React from 'react'
3
+
2
4
  import { useAppSelector } from '../../../hooks/useRedux'
3
5
  import { selectWidgetState } from '../../../store/widgets.selectors'
4
6
  import { TxDoneModal } from '../../TxDoneModal'
@@ -11,7 +13,7 @@ export function Success({ handleAction }: Props): React.ReactElement {
11
13
  const { borrowAmount, approval } = useAppSelector(selectWidgetState)
12
14
 
13
15
  const content = [
14
- `${borrowAmount?.toFixed(2)} ${
16
+ `${formatNumber(borrowAmount)} ${
15
17
  approval?.token.symbol
16
18
  } is now in your wallet.`,
17
19
  ]