@huma-finance/widgets 0.0.48-beta.202 → 0.0.48-beta.279

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 (91) hide show
  1. package/API.md +407 -0
  2. package/dist/cjs/index.cjs +6063 -3827
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/index.d.ts +248 -1
  5. package/dist/index.js +6056 -3829
  6. package/dist/index.js.map +1 -1
  7. package/package.json +5 -4
  8. package/src/components/ApproveAllowanceModal.tsx +3 -8
  9. package/src/components/ApproveAllowanceModalV2.tsx +141 -0
  10. package/src/components/CreditLine/approve/index.tsx +9 -3
  11. package/src/components/CreditLine/autoPaybackV2/1-ApproveAllowance.tsx +33 -0
  12. package/src/components/CreditLine/autoPaybackV2/2-Success.tsx +13 -0
  13. package/src/components/CreditLine/autoPaybackV2/index.tsx +87 -0
  14. package/src/components/CreditLine/borrow/2-ChooseAmount.tsx +12 -3
  15. package/src/components/CreditLine/borrow/index.tsx +4 -2
  16. package/src/components/CreditLine/borrowV2/1-ChooseAmount.tsx +79 -0
  17. package/src/components/CreditLine/borrowV2/2-ApproveAllowance.tsx +33 -0
  18. package/src/components/CreditLine/borrowV2/3-Transfer.tsx +50 -0
  19. package/src/components/CreditLine/borrowV2/4-Success.tsx +41 -0
  20. package/src/components/CreditLine/borrowV2/5-Notifications.tsx +10 -0
  21. package/src/components/CreditLine/borrowV2/index.tsx +140 -0
  22. package/src/components/CreditLine/payment/1-ChooseAmount.tsx +7 -2
  23. package/src/components/CreditLine/payment/index.tsx +4 -2
  24. package/src/components/CreditLine/paymentV2/1-ChooseAmount.tsx +86 -0
  25. package/src/components/CreditLine/paymentV2/2-ApproveAllowance.tsx +33 -0
  26. package/src/components/CreditLine/paymentV2/3-Transfer.tsx +55 -0
  27. package/src/components/CreditLine/paymentV2/4-Success.tsx +42 -0
  28. package/src/components/CreditLine/paymentV2/index.tsx +111 -0
  29. package/src/components/CreditLine/supplyFLC/1-ApproveAllowance.tsx +40 -0
  30. package/src/components/CreditLine/supplyFLC/2-Transfer.tsx +53 -0
  31. package/src/components/CreditLine/supplyFLC/3-Success.tsx +26 -0
  32. package/src/components/CreditLine/supplyFLC/index.tsx +121 -0
  33. package/src/components/Factoring/FactoredList.tsx +2 -1
  34. package/src/components/InvoiceFactoring/borrow/2-ChooseAmount.tsx +8 -1
  35. package/src/components/InvoiceFactoring/borrow/4-ApproveNFT.tsx +6 -2
  36. package/src/components/InvoiceFactoring/borrow/index.tsx +9 -3
  37. package/src/components/InvoiceFactoring/payment/1-ChooseAmount.tsx +7 -2
  38. package/src/components/InvoiceFactoring/payment/index.tsx +9 -3
  39. package/src/components/Lend/redeemV2/1-ChooseAction.tsx +236 -0
  40. package/src/components/Lend/redeemV2/2-ChooseAmount.tsx +162 -0
  41. package/src/components/Lend/redeemV2/3-Transfer.tsx +61 -0
  42. package/src/components/Lend/redeemV2/4-Done.tsx +33 -0
  43. package/src/components/Lend/redeemV2/index.tsx +207 -0
  44. package/src/components/Lend/supply/1-Evaluation/EvaluationKYC.tsx +19 -2
  45. package/src/components/Lend/supply/index.tsx +17 -3
  46. package/src/components/Lend/supplyV2/1-ChooseTranche.tsx +155 -0
  47. package/src/components/Lend/supplyV2/2-Evaluation.tsx +345 -0
  48. package/src/components/Lend/supplyV2/3-ChooseAmount.tsx +122 -0
  49. package/src/components/Lend/supplyV2/4-ApproveAllowance.tsx +33 -0
  50. package/src/components/Lend/supplyV2/5-Transfer.tsx +59 -0
  51. package/src/components/Lend/supplyV2/6-Success.tsx +79 -0
  52. package/src/components/Lend/supplyV2/7-Notifications.tsx +10 -0
  53. package/src/components/Lend/supplyV2/index.tsx +127 -0
  54. package/src/components/Lend/withdraw/1-CheckWithdrawble.tsx +5 -1
  55. package/src/components/Lend/withdraw/2-ChooseAmount.tsx +1 -7
  56. package/src/components/Lend/withdraw/index.tsx +8 -13
  57. package/src/components/Lend/withdrawV2/1-ChooseTranche.tsx +201 -0
  58. package/src/components/Lend/withdrawV2/2-Transfer.tsx +48 -0
  59. package/src/components/Lend/withdrawV2/3-Done.tsx +31 -0
  60. package/src/components/Lend/withdrawV2/index.tsx +129 -0
  61. package/src/components/Notifi/NotifiSubscriptionModal.tsx +29 -37
  62. package/src/components/NumericFormatCustom.tsx +31 -0
  63. package/src/components/ReceivableBackedCreditLine/borrow/1-ChooseAmount.tsx +101 -0
  64. package/src/components/ReceivableBackedCreditLine/borrow/2-ApproveAllowance.tsx +33 -0
  65. package/src/components/ReceivableBackedCreditLine/borrow/3-ApproveReceivable.tsx +64 -0
  66. package/src/components/ReceivableBackedCreditLine/borrow/4-Transfer.tsx +61 -0
  67. package/src/components/ReceivableBackedCreditLine/borrow/5-Success.tsx +41 -0
  68. package/src/components/ReceivableBackedCreditLine/borrow/6-Notifications.tsx +10 -0
  69. package/src/components/ReceivableBackedCreditLine/borrow/index.tsx +148 -0
  70. package/src/components/ReceivableBackedCreditLine/payment/1-ChoosePaymentType.tsx +115 -0
  71. package/src/components/ReceivableBackedCreditLine/payment/2-ChooseAmount.tsx +84 -0
  72. package/src/components/ReceivableBackedCreditLine/payment/3-ApproveAllowance.tsx +41 -0
  73. package/src/components/ReceivableBackedCreditLine/payment/4-CreateReceivable.tsx +107 -0
  74. package/src/components/ReceivableBackedCreditLine/payment/5-ApproveReceivable.tsx +64 -0
  75. package/src/components/ReceivableBackedCreditLine/payment/6-Transfer.tsx +107 -0
  76. package/src/components/ReceivableBackedCreditLine/payment/7-Success.tsx +49 -0
  77. package/src/components/ReceivableBackedCreditLine/payment/index.tsx +159 -0
  78. package/src/components/StreamFactoring/borrow/1-Evaluation.tsx +3 -4
  79. package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +23 -22
  80. package/src/components/StreamFactoring/borrow/3-ConfirmTransfer.tsx +8 -3
  81. package/src/components/StreamFactoring/borrow/5-Permit.tsx +35 -2
  82. package/src/components/StreamFactoring/borrow/6-Transfer.tsx +3 -1
  83. package/src/components/StreamFactoring/borrow/index.tsx +4 -3
  84. package/src/components/SuperfluidFactoring/SuperfluidFactoredList.tsx +2 -2
  85. package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +1 -3
  86. package/src/components/TxDoneModal.tsx +1 -1
  87. package/src/components/TxSendModal.tsx +8 -2
  88. package/src/components/TxSendModalV2.tsx +51 -0
  89. package/src/index.tsx +239 -1
  90. package/src/store/widgets.reducers.ts +15 -0
  91. package/src/store/widgets.store.ts +6 -0
@@ -1,38 +1,30 @@
1
- import React, { useCallback, useState } from 'react'
2
- import { useWeb3React } from '@web3-react/core'
3
- import {
4
- NotifiFrontendClient,
5
- Uint8SignMessageFunction,
6
- SignMessageParams,
7
- CardConfigItemV1,
8
- DirectPushEventTypeItem,
9
- EventTypeItem,
10
- BroadcastEventTypeItem,
11
- } from '@notifi-network/notifi-frontend-client'
12
1
  import {
13
2
  checkIsDev,
14
3
  getBlockchainConfigFromChain,
15
4
  txAtom,
16
5
  } from '@huma-finance/shared'
17
- import { ethers } from 'ethers'
6
+ import { Box, css, TextField, Typography, useTheme } from '@mui/material'
18
7
  import {
19
- Box,
20
- Input,
21
- InputAdornment,
22
- Typography,
23
- css,
24
- useTheme,
25
- } from '@mui/material'
26
- import Email from '@mui/icons-material/Email'
8
+ BroadcastEventTypeItem,
9
+ CardConfigItemV1,
10
+ DirectPushEventTypeItem,
11
+ EventTypeItem,
12
+ NotifiFrontendClient,
13
+ SignMessageParams,
14
+ Uint8SignMessageFunction,
15
+ } from '@notifi-network/notifi-frontend-client'
16
+ import { useWeb3React } from '@web3-react/core'
17
+ import { ethers } from 'ethers'
27
18
  import { useResetAtom } from 'jotai/utils'
19
+ import React, { useCallback, useState } from 'react'
28
20
 
29
- import { WrapperModal } from '../WrapperModal'
21
+ import { useNotifiClient } from '../../hooks/useNotifi'
22
+ import { useAppDispatch } from '../../hooks/useRedux'
23
+ import { resetState } from '../../store/widgets.reducers'
30
24
  import { BottomButton } from '../BottomButton'
31
- import { LoadingModal } from '../LoadingModal'
32
25
  import { CheckIcon } from '../icons'
33
- import { resetState } from '../../store/widgets.reducers'
34
- import { useAppDispatch } from '../../hooks/useRedux'
35
- import { useNotifiClient } from '../../hooks/useNotifi'
26
+ import { LoadingModal } from '../LoadingModal'
27
+ import { WrapperModal } from '../WrapperModal'
36
28
 
37
29
  type Props = {
38
30
  handleSuccess: () => void
@@ -176,7 +168,7 @@ export function NotifiSubscriptionModal({
176
168
  margin-top: ${theme.spacing(6)};
177
169
  `,
178
170
  inputField: css`
179
- width: 90%;
171
+ width: 100%;
180
172
  font-size: 16px;
181
173
  `,
182
174
  inputWrapper: css`
@@ -215,33 +207,33 @@ export function NotifiSubscriptionModal({
215
207
 
216
208
  return (
217
209
  <WrapperModal title='Connect Your Email'>
218
- <Typography variant='body2' margin={theme.spacing(1, 0)}>
219
- Connect your wallet to receive important emails about your account
210
+ <Typography
211
+ variant='body2'
212
+ textAlign='justify'
213
+ margin={theme.spacing(6, 0, 4, 0)}
214
+ >
215
+ Connect your emails to receive important update about your account.
220
216
  </Typography>
221
217
  <Box css={styles.inputWrapper}>
222
- <Input
218
+ <TextField
223
219
  css={styles.inputField}
220
+ label='Your Email'
224
221
  type='email'
225
222
  value={emailAddress}
226
223
  onChange={handleEmailAddressChange}
227
- placeholder='youremail@example.com'
228
- startAdornment={
229
- <InputAdornment position='start'>
230
- <Email />
231
- </InputAdornment>
232
- }
224
+ variant='standard'
233
225
  />
234
226
  </Box>
235
227
  <Box css={styles.disclaimer}>
236
228
  You can adjust these settings at any time by clicking the alert icon in
237
- the header
229
+ the header.
238
230
  </Box>
239
231
  <BottomButton
240
232
  variant='contained'
241
233
  onClick={logInAndSubscribe}
242
234
  disabled={!emailValid || isLoading}
243
235
  >
244
- CONNECT WALLET
236
+ CONNECT EMAIL
245
237
  </BottomButton>
246
238
  </WrapperModal>
247
239
  )
@@ -0,0 +1,31 @@
1
+ import React from 'react'
2
+ import { NumericFormat, NumericFormatProps } from 'react-number-format'
3
+
4
+ interface CustomProps {
5
+ onChange: (event: { target: { name: string; value: string } }) => void
6
+ name: string
7
+ }
8
+
9
+ export const NumericFormatCustom = React.forwardRef<
10
+ NumericFormatProps,
11
+ CustomProps
12
+ >((props, ref) => {
13
+ const { onChange, ...other } = props
14
+
15
+ return (
16
+ <NumericFormat
17
+ {...other}
18
+ getInputRef={ref}
19
+ onValueChange={(values) => {
20
+ onChange({
21
+ target: {
22
+ name: props.name,
23
+ value: values.value,
24
+ },
25
+ })
26
+ }}
27
+ thousandSeparator
28
+ valueIsNumericString
29
+ />
30
+ )
31
+ })
@@ -0,0 +1,101 @@
1
+ import {
2
+ CreditStatsV2,
3
+ PoolInfoV2,
4
+ UnderlyingTokenInfo,
5
+ usePoolSafeAllowanceV2,
6
+ useReceivableInfoV2,
7
+ } from '@huma-finance/shared'
8
+ import { useWeb3React } from '@web3-react/core'
9
+ import { BigNumber, ethers } from 'ethers'
10
+ import React, { useCallback, useEffect, useState } from 'react'
11
+
12
+ import { useAppDispatch } from '../../../hooks/useRedux'
13
+ import { setBorrowInfo } from '../../../store/widgets.reducers'
14
+ import { WIDGET_STEP } from '../../../store/widgets.store'
15
+ import { ChooseAmountModal } from '../../ChooseAmountModal'
16
+ import { LoadingModal } from '../../LoadingModal'
17
+
18
+ type Props = {
19
+ poolInfo: PoolInfoV2
20
+ poolUnderlyingToken: UnderlyingTokenInfo
21
+ accountStats: CreditStatsV2
22
+ tokenId: string
23
+ }
24
+
25
+ export function ChooseAmount({
26
+ poolInfo,
27
+ poolUnderlyingToken,
28
+ accountStats,
29
+ tokenId,
30
+ }: Props): React.ReactElement | null {
31
+ const dispatch = useAppDispatch()
32
+ const { account, provider } = useWeb3React()
33
+ const { symbol, decimals } = poolUnderlyingToken!
34
+ const [currentAmount, setCurrentAmount] = useState(0)
35
+ const { creditAvailable } = accountStats
36
+ const receivableInfo = useReceivableInfoV2(
37
+ poolInfo.poolName,
38
+ tokenId,
39
+ provider,
40
+ )
41
+ const { autopayEnabled } = usePoolSafeAllowanceV2(
42
+ poolInfo.poolName,
43
+ account,
44
+ provider,
45
+ )
46
+ const [maxAmount, setMaxAmount] = useState(0)
47
+
48
+ useEffect(() => {
49
+ if (creditAvailable) {
50
+ let maxAmountBN: BigNumber = creditAvailable
51
+
52
+ if (receivableInfo) {
53
+ const receivableAmountBN = BigNumber.from(
54
+ receivableInfo.receivableAmount,
55
+ )
56
+ maxAmountBN = receivableAmountBN.lte(creditAvailable)
57
+ ? receivableAmountBN
58
+ : creditAvailable
59
+ }
60
+ setMaxAmount(Number(ethers.utils.formatUnits(maxAmountBN, decimals)))
61
+ }
62
+ }, [creditAvailable, decimals, receivableInfo])
63
+
64
+ const handleChangeAmount = useCallback((newAmount: number) => {
65
+ setCurrentAmount(newAmount)
66
+ }, [])
67
+
68
+ const handleAction = useCallback(() => {
69
+ const nextStep = autopayEnabled
70
+ ? WIDGET_STEP.ApproveNFT
71
+ : WIDGET_STEP.ApproveAllowance
72
+
73
+ dispatch(
74
+ setBorrowInfo({
75
+ borrowAmount: currentAmount,
76
+ borrowAmountBN: ethers.utils
77
+ .parseUnits(currentAmount.toString(), decimals)
78
+ .toJSON(),
79
+ chargedFees: 0,
80
+ nextStep,
81
+ }),
82
+ )
83
+ }, [autopayEnabled, currentAmount, decimals, dispatch])
84
+
85
+ if (autopayEnabled === undefined || (tokenId && !receivableInfo)) {
86
+ return <LoadingModal title='Borrow' />
87
+ }
88
+
89
+ return (
90
+ <ChooseAmountModal
91
+ title='Borrow'
92
+ description1='Choose Amount'
93
+ sliderMax={maxAmount}
94
+ currentAmount={currentAmount}
95
+ tokenSymbol={symbol}
96
+ handleChangeAmount={handleChangeAmount}
97
+ handleAction={handleAction}
98
+ actionText='Borrow'
99
+ />
100
+ )
101
+ }
@@ -0,0 +1,33 @@
1
+ import { PoolInfoV2, UnderlyingTokenInfo } from '@huma-finance/shared'
2
+ import React, { useCallback } from 'react'
3
+
4
+ import { useAppDispatch } from '../../../hooks/useRedux'
5
+ import { setStep } from '../../../store/widgets.reducers'
6
+ import { WIDGET_STEP } from '../../../store/widgets.store'
7
+ import { ApproveAllowanceModalV2 } from '../../ApproveAllowanceModalV2'
8
+
9
+ type Props = {
10
+ poolInfo: PoolInfoV2
11
+ poolUnderlyingToken: UnderlyingTokenInfo
12
+ }
13
+
14
+ export function ApproveAllowance({
15
+ poolInfo,
16
+ poolUnderlyingToken,
17
+ }: Props): React.ReactElement | null {
18
+ const dispatch = useAppDispatch()
19
+
20
+ const handleSuccess = useCallback(() => {
21
+ dispatch(setStep(WIDGET_STEP.ApproveNFT))
22
+ }, [dispatch])
23
+
24
+ return (
25
+ <ApproveAllowanceModalV2
26
+ poolInfo={poolInfo}
27
+ spender={poolInfo.poolSafe}
28
+ poolUnderlyingToken={poolUnderlyingToken}
29
+ handleSuccess={handleSuccess}
30
+ showAutoPayback
31
+ />
32
+ )
33
+ }
@@ -0,0 +1,64 @@
1
+ import {
2
+ PoolInfoV2,
3
+ sendTxAtom,
4
+ txAtom,
5
+ TxStateType,
6
+ useReceivableContractV2,
7
+ } from '@huma-finance/shared'
8
+ import { useWeb3React } from '@web3-react/core'
9
+ import { useAtom } from 'jotai'
10
+ import { useResetAtom } from 'jotai/utils'
11
+ import React, { useEffect } from 'react'
12
+
13
+ import { useAppDispatch } from '../../../hooks/useRedux'
14
+ import { setStep } from '../../../store/widgets.reducers'
15
+ import { WIDGET_STEP } from '../../../store/widgets.store'
16
+ import { LoadingModal } from '../../LoadingModal'
17
+ import { ViewOnExplorer } from '../../ViewOnExplorer'
18
+
19
+ type Props = {
20
+ poolInfo: PoolInfoV2
21
+ tokenId: string
22
+ }
23
+
24
+ export function ApproveReceivable({
25
+ poolInfo,
26
+ tokenId,
27
+ }: Props): React.ReactElement {
28
+ const dispatch = useAppDispatch()
29
+ const { provider, account } = useWeb3React()
30
+ const [{ state, txHash }, send] = useAtom(sendTxAtom)
31
+ const reset = useResetAtom(txAtom)
32
+ const receivableContract = useReceivableContractV2(
33
+ poolInfo.poolName,
34
+ provider,
35
+ account,
36
+ )
37
+
38
+ useEffect(() => {
39
+ if (state === TxStateType.Success) {
40
+ reset()
41
+ dispatch(setStep(WIDGET_STEP.Transfer))
42
+ }
43
+ }, [dispatch, reset, state])
44
+
45
+ useEffect(() => {
46
+ if (receivableContract) {
47
+ send({
48
+ contract: receivableContract,
49
+ method: 'approve',
50
+ params: [poolInfo.poolCredit, tokenId],
51
+ provider,
52
+ })
53
+ }
54
+ }, [poolInfo.poolCredit, provider, receivableContract, send, tokenId])
55
+
56
+ return (
57
+ <LoadingModal
58
+ title='Approve Receivable'
59
+ description='Waiting for approval confirmation...'
60
+ >
61
+ <ViewOnExplorer txHash={txHash} />
62
+ </LoadingModal>
63
+ )
64
+ }
@@ -0,0 +1,61 @@
1
+ import { drawdownWithReceivable } from '@huma-finance/sdk'
2
+ import { PoolInfoV2 } from '@huma-finance/shared'
3
+ import { useWeb3React } from '@web3-react/core'
4
+ import { BigNumber } from 'ethers'
5
+ import React, { useEffect, useState } from 'react'
6
+
7
+ import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
8
+ import { setStep } from '../../../store/widgets.reducers'
9
+ import { selectWidgetState } from '../../../store/widgets.selectors'
10
+ import { WIDGET_STEP } from '../../../store/widgets.store'
11
+ import { LoadingModal } from '../../LoadingModal'
12
+ import { ViewOnExplorer } from '../../ViewOnExplorer'
13
+
14
+ type Props = {
15
+ poolInfo: PoolInfoV2
16
+ tokenId: string
17
+ }
18
+
19
+ export function Transfer({ poolInfo, tokenId }: Props): React.ReactElement {
20
+ const dispatch = useAppDispatch()
21
+ const { provider, account } = useWeb3React()
22
+ const { borrowAmountBN: borrowAmountBNJson } =
23
+ useAppSelector(selectWidgetState)
24
+ const borrowAmountBN = BigNumber.from(borrowAmountBNJson).toString()
25
+ const [txHash, setTxHash] = useState('')
26
+
27
+ useEffect(() => {
28
+ const sendTx = async () => {
29
+ if (provider) {
30
+ try {
31
+ const tx = await drawdownWithReceivable(
32
+ provider.getSigner(),
33
+ poolInfo.poolName,
34
+ tokenId,
35
+ borrowAmountBN,
36
+ )
37
+ setTxHash(tx.hash)
38
+ await tx.wait()
39
+ dispatch(setStep(WIDGET_STEP.Done))
40
+ } catch (e) {
41
+ console.error(e)
42
+ dispatch(setStep(WIDGET_STEP.Error))
43
+ }
44
+ }
45
+ }
46
+ sendTx()
47
+ }, [borrowAmountBN, dispatch, poolInfo.poolName, provider, tokenId])
48
+
49
+ if (!account || !provider) {
50
+ return <LoadingModal title='Borrow' />
51
+ }
52
+
53
+ return (
54
+ <LoadingModal
55
+ title='Transaction Pending'
56
+ description='Waiting for confirmation...'
57
+ >
58
+ <ViewOnExplorer txHash={txHash} />
59
+ </LoadingModal>
60
+ )
61
+ }
@@ -0,0 +1,41 @@
1
+ import {
2
+ CreditStatsV2,
3
+ timeUtil,
4
+ UnderlyingTokenInfo,
5
+ } from '@huma-finance/shared'
6
+ import React from 'react'
7
+
8
+ import { useAppSelector } from '../../../hooks/useRedux'
9
+ import { selectWidgetState } from '../../../store/widgets.selectors'
10
+ import { TxDoneModal } from '../../TxDoneModal'
11
+
12
+ type Props = {
13
+ poolUnderlyingToken: UnderlyingTokenInfo
14
+ creditRecord: CreditStatsV2['creditRecord']
15
+ handleAction: () => void
16
+ hasNextStep: boolean
17
+ }
18
+
19
+ export function Success({
20
+ poolUnderlyingToken,
21
+ creditRecord,
22
+ handleAction,
23
+ hasNextStep,
24
+ }: Props): React.ReactElement {
25
+ const { borrowAmountNet } = useAppSelector(selectWidgetState)
26
+ const { symbol } = poolUnderlyingToken
27
+ const dueDate = timeUtil.timestampToLL(creditRecord?.nextDueDate.toNumber())
28
+
29
+ const content = [
30
+ `${borrowAmountNet} ${symbol} is now in your wallet.`,
31
+ `Note: your payment will be automatically deducted on ${dueDate}.`,
32
+ ]
33
+
34
+ return (
35
+ <TxDoneModal
36
+ handleAction={handleAction}
37
+ content={content}
38
+ buttonText={hasNextStep ? "WHAT'S NEXT" : undefined}
39
+ />
40
+ )
41
+ }
@@ -0,0 +1,10 @@
1
+ import React from 'react'
2
+ import { NotifiSubscriptionModal } from '../../Notifi/NotifiSubscriptionModal'
3
+
4
+ type Props = {
5
+ handleAction: () => void
6
+ }
7
+
8
+ export function Notifications({ handleAction }: Props): React.ReactElement {
9
+ return <NotifiSubscriptionModal handleSuccess={handleAction} />
10
+ }
@@ -0,0 +1,148 @@
1
+ import {
2
+ CreditStateV2,
3
+ POOL_NAME,
4
+ useCreditStatsV2,
5
+ usePoolInfoV2,
6
+ usePoolUnderlyingTokenInfoV2,
7
+ } from '@huma-finance/shared'
8
+ import { useWeb3React } from '@web3-react/core'
9
+ import React, { useCallback, useEffect } from 'react'
10
+ import { useDispatch } from 'react-redux'
11
+
12
+ import {
13
+ useDoesChainSupportNotifi,
14
+ useIsFirstTimeNotifiUser,
15
+ } from '../../../hooks/useNotifi'
16
+ import { useAppSelector } from '../../../hooks/useRedux'
17
+ import { setStep } from '../../../store/widgets.reducers'
18
+ import { selectWidgetState } from '../../../store/widgets.selectors'
19
+ import { WIDGET_STEP } from '../../../store/widgets.store'
20
+ import { ErrorModal } from '../../ErrorModal'
21
+ import { WidgetWrapper } from '../../WidgetWrapper'
22
+ import { ChooseAmount } from './1-ChooseAmount'
23
+ import { ApproveAllowance } from './2-ApproveAllowance'
24
+ import { ApproveReceivable } from './3-ApproveReceivable'
25
+ import { Transfer } from './4-Transfer'
26
+ import { Success } from './5-Success'
27
+ import { Notifications } from './6-Notifications'
28
+
29
+ /**
30
+ * Receivable backed credit line pool borrow props V2
31
+ * @typedef {Object} ReceivableBackedCreditLineBorrowPropsV2
32
+ * @property {POOL_NAME} poolName The name of the pool.
33
+ * @property {tokenId} tokenId The receivable token id.
34
+ * @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
35
+ * @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the credit line pool borrow action is successful.
36
+ */
37
+ export interface ReceivableBackedCreditLineBorrowPropsV2 {
38
+ poolName: keyof typeof POOL_NAME
39
+ tokenId: string
40
+ handleClose: () => void
41
+ handleSuccess?: (blockNumber?: number) => void
42
+ }
43
+
44
+ export function ReceivableBackedCreditLineBorrowV2({
45
+ poolName: poolNameStr,
46
+ tokenId,
47
+ handleClose,
48
+ handleSuccess,
49
+ }: ReceivableBackedCreditLineBorrowPropsV2): React.ReactElement | null {
50
+ const dispatch = useDispatch()
51
+ const poolName = POOL_NAME[poolNameStr]
52
+ const { account, chainId, provider } = useWeb3React()
53
+ const poolInfo = usePoolInfoV2(poolName, chainId)
54
+ const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
55
+ const { step, errorMessage } = useAppSelector(selectWidgetState)
56
+ const [accountStats, refreshAccountStats] = useCreditStatsV2(
57
+ poolName,
58
+ account,
59
+ provider,
60
+ )
61
+ const { isFirstTimeNotifiUser } = useIsFirstTimeNotifiUser(account, chainId)
62
+ const { notifiChainSupported } = useDoesChainSupportNotifi(account, chainId)
63
+ const { creditRecord } = accountStats
64
+ const accountState = creditRecord?.state
65
+
66
+ useEffect(() => {
67
+ if (!step && accountState !== undefined) {
68
+ if (accountState >= CreditStateV2.Approved) {
69
+ dispatch(setStep(WIDGET_STEP.ChooseAmount))
70
+ }
71
+ }
72
+ }, [accountState, dispatch, step])
73
+
74
+ const setupNotificationsOrClose = useCallback(() => {
75
+ if (isFirstTimeNotifiUser && notifiChainSupported) {
76
+ dispatch(setStep(WIDGET_STEP.Notifications))
77
+ } else {
78
+ handleClose()
79
+ }
80
+ }, [dispatch, handleClose, isFirstTimeNotifiUser, notifiChainSupported])
81
+
82
+ const handleSuccessCallback = useCallback(() => {
83
+ refreshAccountStats()
84
+ if (handleSuccess) {
85
+ handleSuccess()
86
+ }
87
+ }, [handleSuccess, refreshAccountStats])
88
+
89
+ if (!poolInfo || !poolUnderlyingToken || !creditRecord || !step) {
90
+ return (
91
+ <WidgetWrapper
92
+ isOpen
93
+ isLoading
94
+ loadingTitle='Borrow'
95
+ handleClose={handleClose}
96
+ handleSuccess={handleSuccessCallback}
97
+ />
98
+ )
99
+ }
100
+
101
+ return (
102
+ <WidgetWrapper
103
+ isOpen
104
+ loadingTitle='Borrow'
105
+ handleClose={handleClose}
106
+ handleSuccess={handleSuccessCallback}
107
+ >
108
+ {step === WIDGET_STEP.ChooseAmount && (
109
+ <ChooseAmount
110
+ poolInfo={poolInfo}
111
+ poolUnderlyingToken={poolUnderlyingToken}
112
+ accountStats={accountStats}
113
+ tokenId={tokenId}
114
+ />
115
+ )}
116
+ {step === WIDGET_STEP.ApproveAllowance && (
117
+ <ApproveAllowance
118
+ poolInfo={poolInfo}
119
+ poolUnderlyingToken={poolUnderlyingToken}
120
+ />
121
+ )}
122
+ {step === WIDGET_STEP.ApproveNFT && tokenId && (
123
+ <ApproveReceivable poolInfo={poolInfo} tokenId={tokenId} />
124
+ )}
125
+ {step === WIDGET_STEP.Transfer && tokenId && (
126
+ <Transfer poolInfo={poolInfo} tokenId={tokenId} />
127
+ )}
128
+ {step === WIDGET_STEP.Done && (
129
+ <Success
130
+ poolUnderlyingToken={poolUnderlyingToken}
131
+ handleAction={setupNotificationsOrClose}
132
+ creditRecord={accountStats.creditRecord!}
133
+ hasNextStep={isFirstTimeNotifiUser}
134
+ />
135
+ )}
136
+ {step === WIDGET_STEP.Notifications && (
137
+ <Notifications handleAction={handleClose} />
138
+ )}
139
+ {step === WIDGET_STEP.Error && (
140
+ <ErrorModal
141
+ title='Borrow'
142
+ errorMessage={errorMessage}
143
+ handleOk={handleClose}
144
+ />
145
+ )}
146
+ </WidgetWrapper>
147
+ )
148
+ }