@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huma-finance/widgets",
3
- "version": "0.0.48-beta.202+b9c113c",
3
+ "version": "0.0.48-beta.279+26f5a23",
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.202+b9c113c",
34
- "@huma-finance/shared": "^0.0.48-beta.202+b9c113c",
33
+ "@huma-finance/sdk": "^0.0.48-beta.279+26f5a23",
34
+ "@huma-finance/shared": "^0.0.48-beta.279+26f5a23",
35
35
  "@mui/icons-material": "^5.3.0",
36
36
  "@mui/material": "^5.0.6",
37
37
  "@mui/styles": "^5.0.2",
@@ -68,6 +68,7 @@
68
68
  "react": "^18.2.0",
69
69
  "react-app-rewired": "^2.2.1",
70
70
  "react-dom": "^18.2.0",
71
+ "react-number-format": "^5.3.1",
71
72
  "react-redux": "^8.0.4",
72
73
  "react-router": "^5.2.1",
73
74
  "react-router-dom": "^5.3.0",
@@ -192,5 +193,5 @@
192
193
  "optionalDependencies": {
193
194
  "encoding": "^0.1.13"
194
195
  },
195
- "gitHead": "b9c113c904ce6e232761fa6398191ebcd4ef9877"
196
+ "gitHead": "26f5a230e2ab5ff9257d7451ef1621f4c7e54eb2"
196
197
  }
@@ -38,12 +38,14 @@ export function ApproveAllowanceModal({
38
38
  handleSuccess,
39
39
  }: Props): React.ReactElement | null {
40
40
  const theme = useTheme()
41
- const { provider, account } = useWeb3React()
41
+ const { provider, account, chainId } = useWeb3React()
42
42
  const { poolUnderlyingToken } = poolInfo
43
43
  const { symbol } = poolUnderlyingToken
44
44
  const poolUnderlyingTokenContract = usePoolUnderlyingTokenContract(
45
45
  poolInfo.poolName,
46
46
  poolInfo.poolType,
47
+ chainId,
48
+ provider,
47
49
  )
48
50
  const reset = useResetAtom(txAtom)
49
51
  const [{ state, txHash }, send] = useAtom(sendTxAtom)
@@ -85,12 +87,6 @@ export function ApproveAllowanceModal({
85
87
  const amountToIncrease = BigNumber.from(targetAllowanceAmount).sub(
86
88
  currentAllowance ?? 0,
87
89
  )
88
-
89
- if (amountToIncrease.lte(0)) {
90
- handleSuccess()
91
- return
92
- }
93
-
94
90
  send({
95
91
  contract: poolUnderlyingTokenContract!,
96
92
  method: 'increaseAllowance',
@@ -100,7 +96,6 @@ export function ApproveAllowanceModal({
100
96
  }, [
101
97
  account,
102
98
  allowanceAmount,
103
- handleSuccess,
104
99
  poolInfo.pool,
105
100
  poolUnderlyingTokenContract,
106
101
  provider,
@@ -0,0 +1,141 @@
1
+ import { MaxUint256 } from '@ethersproject/constants'
2
+ import {
3
+ getERC20Contract,
4
+ PoolInfoV2,
5
+ sendTxAtom,
6
+ txAtom,
7
+ TxStateType,
8
+ UnderlyingTokenInfo,
9
+ useMount,
10
+ } from '@huma-finance/shared'
11
+ import { Box, css, useTheme } from '@mui/material'
12
+ import { useWeb3React } from '@web3-react/core'
13
+ import { BigNumber, BigNumberish } from 'ethers'
14
+ import { useAtom } from 'jotai'
15
+ import { useResetAtom } from 'jotai/utils'
16
+ import React, { useCallback, useEffect } from 'react'
17
+
18
+ import { BottomButton } from './BottomButton'
19
+ import { AutoPaybackImg } from './images'
20
+ import { LoadingModal } from './LoadingModal'
21
+ import { ViewOnExplorer } from './ViewOnExplorer'
22
+ import { WrapperModal } from './WrapperModal'
23
+
24
+ type Props = {
25
+ poolInfo: PoolInfoV2
26
+ poolUnderlyingToken: UnderlyingTokenInfo
27
+ showAutoPayback?: boolean
28
+ allowanceAmount?: BigNumberish
29
+ spender?: string
30
+ resetAfterSuccess?: boolean
31
+ handleSuccess: () => void
32
+ }
33
+
34
+ export function ApproveAllowanceModalV2({
35
+ poolInfo,
36
+ poolUnderlyingToken,
37
+ showAutoPayback = false,
38
+ allowanceAmount,
39
+ spender,
40
+ resetAfterSuccess = true,
41
+ handleSuccess,
42
+ }: Props): React.ReactElement | null {
43
+ const theme = useTheme()
44
+ const { provider, account } = useWeb3React()
45
+ const reset = useResetAtom(txAtom)
46
+ const [{ state, txHash }, send] = useAtom(sendTxAtom)
47
+ const waitingForAccept = state === TxStateType.New
48
+ const { symbol, address } = poolUnderlyingToken
49
+
50
+ useEffect(() => {
51
+ if (state === TxStateType.Success) {
52
+ if (resetAfterSuccess) {
53
+ reset()
54
+ }
55
+ handleSuccess()
56
+ }
57
+ }, [handleSuccess, reset, resetAfterSuccess, state])
58
+
59
+ const styles = {
60
+ iconWrapper: css`
61
+ ${theme.cssMixins.rowCentered};
62
+ margin-top: ${theme.spacing(6)};
63
+ & > img {
64
+ width: 220px;
65
+ }
66
+ `,
67
+ description: css`
68
+ margin-top: ${theme.spacing(4)};
69
+ font-family: 'Uni-Neue-Regular';
70
+ font-size: 16px;
71
+ color: #a8a1b2;
72
+ padding: ${theme.spacing(0, 1)};
73
+ `,
74
+ }
75
+
76
+ const sendIncreaseAllowance = useCallback(async () => {
77
+ const allowanceSpender = spender ?? poolInfo.pool
78
+ const targetAllowanceAmount = allowanceAmount ?? MaxUint256
79
+ const underlyingTokenContract = await getERC20Contract(
80
+ address,
81
+ provider,
82
+ account,
83
+ )
84
+ const currentAllowance = await underlyingTokenContract?.allowance(
85
+ account!,
86
+ allowanceSpender,
87
+ )
88
+ const amountToIncrease = BigNumber.from(targetAllowanceAmount).sub(
89
+ currentAllowance ?? 0,
90
+ )
91
+ send({
92
+ contract: underlyingTokenContract!,
93
+ method: 'increaseAllowance',
94
+ params: [allowanceSpender, amountToIncrease],
95
+ provider,
96
+ })
97
+ }, [
98
+ account,
99
+ address,
100
+ allowanceAmount,
101
+ poolInfo.pool,
102
+ provider,
103
+ send,
104
+ spender,
105
+ ])
106
+
107
+ useMount(() => {
108
+ if (!showAutoPayback) {
109
+ sendIncreaseAllowance()
110
+ }
111
+ })
112
+
113
+ if (showAutoPayback && waitingForAccept) {
114
+ return (
115
+ <WrapperModal
116
+ title='Auto Payback'
117
+ subTitle='Enable auto payback and never miss payments. You only need to do it once.'
118
+ >
119
+ <Box css={styles.iconWrapper}>
120
+ <img src={AutoPaybackImg} alt='auto-payback' />
121
+ </Box>
122
+ <Box css={styles.description}>
123
+ This allowance transaction removes the need to confirm follow up{' '}
124
+ {symbol} transactions. Gas is on us.
125
+ </Box>
126
+ <BottomButton variant='contained' onClick={sendIncreaseAllowance}>
127
+ APPROVE {symbol} PAYMENTS
128
+ </BottomButton>
129
+ </WrapperModal>
130
+ )
131
+ }
132
+
133
+ return (
134
+ <LoadingModal
135
+ title={`Approve ${symbol}`}
136
+ description='Waiting for approval confirmation...'
137
+ >
138
+ <ViewOnExplorer txHash={txHash} />
139
+ </LoadingModal>
140
+ )
141
+ }
@@ -43,12 +43,18 @@ export function CreditLineApprove({
43
43
  handleSuccess,
44
44
  }: CreditLineApproveProps): React.ReactElement | null {
45
45
  const dispatch = useDispatch()
46
- const { account } = useWeb3React()
46
+ const { account, chainId, provider } = useWeb3React()
47
47
  const poolName = POOL_NAME[poolNameStr]
48
48
  const poolType = POOL_TYPE[poolTypeStr]
49
- const poolInfo = usePoolInfo(poolName, poolType)
49
+ const poolInfo = usePoolInfo(poolName, poolType, chainId)
50
50
  const { step, errorMessage } = useAppSelector(selectWidgetState)
51
- const [accountStats] = useAccountStats(poolName, poolType, account)
51
+ const [accountStats] = useAccountStats(
52
+ poolName,
53
+ poolType,
54
+ chainId,
55
+ account,
56
+ provider,
57
+ )
52
58
  const { creditRecord } = accountStats
53
59
 
54
60
  useEffect(() => {
@@ -0,0 +1,33 @@
1
+ import { PoolInfoV2, UnderlyingTokenInfo } from '@huma-finance/shared'
2
+ import React 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 {
18
+ const dispatch = useAppDispatch()
19
+
20
+ const handleSuccess = () => {
21
+ dispatch(setStep(WIDGET_STEP.Done))
22
+ }
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,13 @@
1
+ import React from 'react'
2
+
3
+ import { TxDoneModal } from '../../TxDoneModal'
4
+
5
+ type Props = {
6
+ handleAction: () => void
7
+ }
8
+
9
+ export function Success({ handleAction }: Props): React.ReactElement {
10
+ const content = [`You have successfully enabled auto payback.`]
11
+
12
+ return <TxDoneModal handleAction={handleAction} content={content} />
13
+ }
@@ -0,0 +1,87 @@
1
+ import {
2
+ POOL_NAME,
3
+ usePoolInfoV2,
4
+ usePoolSafeAllowanceV2,
5
+ usePoolUnderlyingTokenInfoV2,
6
+ } from '@huma-finance/shared'
7
+ import { useWeb3React } from '@web3-react/core'
8
+ import React, { useEffect } from 'react'
9
+ import { useDispatch } from 'react-redux'
10
+
11
+ import { useAppSelector } from '../../../hooks/useRedux'
12
+ import { setStep } from '../../../store/widgets.reducers'
13
+ import { selectWidgetState } from '../../../store/widgets.selectors'
14
+ import { WIDGET_STEP } from '../../../store/widgets.store'
15
+ import { ErrorModal } from '../../ErrorModal'
16
+ import { WidgetWrapper } from '../../WidgetWrapper'
17
+ import { ApproveAllowance } from './1-ApproveAllowance'
18
+ import { Success } from './2-Success'
19
+
20
+ /**
21
+ * Auto payback props V2
22
+ * @typedef {Object} AutoPaybackPropsV2
23
+ * @property {POOL_NAME} poolName The name of the pool.
24
+ * @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
25
+ * @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the credit line pool borrow action is successful.
26
+ */
27
+ export interface AutoPaybackPropsV2 {
28
+ poolName: keyof typeof POOL_NAME
29
+ handleClose: () => void
30
+ handleSuccess?: (blockNumber?: number) => void
31
+ }
32
+
33
+ export function AutoPaybackV2({
34
+ poolName: poolNameStr,
35
+ handleClose,
36
+ handleSuccess,
37
+ }: AutoPaybackPropsV2): React.ReactElement | null {
38
+ const dispatch = useDispatch()
39
+ const poolName = POOL_NAME[poolNameStr]
40
+ const { account, chainId, provider } = useWeb3React()
41
+ const poolInfo = usePoolInfoV2(poolName, chainId)
42
+ const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
43
+ const { step, errorMessage } = useAppSelector(selectWidgetState)
44
+ const { autopayEnabled } = usePoolSafeAllowanceV2(poolName, account, provider)
45
+
46
+ useEffect(() => {
47
+ if (!step && !autopayEnabled) {
48
+ dispatch(setStep(WIDGET_STEP.ApproveAllowance))
49
+ }
50
+ }, [autopayEnabled, dispatch, step])
51
+
52
+ if (!poolInfo || !poolUnderlyingToken || autopayEnabled === undefined) {
53
+ return (
54
+ <WidgetWrapper
55
+ isOpen
56
+ isLoading
57
+ loadingTitle='Auto Payback'
58
+ handleClose={handleClose}
59
+ handleSuccess={handleSuccess}
60
+ />
61
+ )
62
+ }
63
+
64
+ return (
65
+ <WidgetWrapper
66
+ isOpen
67
+ loadingTitle='Auto Payback'
68
+ handleClose={handleClose}
69
+ handleSuccess={handleSuccess}
70
+ >
71
+ {step === WIDGET_STEP.ApproveAllowance && (
72
+ <ApproveAllowance
73
+ poolInfo={poolInfo}
74
+ poolUnderlyingToken={poolUnderlyingToken}
75
+ />
76
+ )}
77
+ {step === WIDGET_STEP.Done && <Success handleAction={handleClose} />}
78
+ {step === WIDGET_STEP.Error && (
79
+ <ErrorModal
80
+ title='Auto Payback'
81
+ errorMessage={errorMessage}
82
+ handleOk={handleClose}
83
+ />
84
+ )}
85
+ </WidgetWrapper>
86
+ )
87
+ }
@@ -23,15 +23,24 @@ export function ChooseAmount({
23
23
  accountStats,
24
24
  }: Props): React.ReactElement | null {
25
25
  const dispatch = useAppDispatch()
26
- const { account } = useWeb3React()
26
+ const { account, chainId, provider } = useWeb3React()
27
27
  const { poolUnderlyingToken } = poolInfo
28
28
  const { symbol, decimals } = poolUnderlyingToken
29
- const { getFeesCharged } = useCLFeeManager(poolInfo.poolName)
29
+ const { getFeesCharged } = useCLFeeManager(
30
+ poolInfo.poolName,
31
+ chainId,
32
+ provider,
33
+ )
30
34
  const [chargedFees, setChargedFees] = useState(0)
31
35
  const [currentAmount, setCurrentAmount] = useState(0)
32
36
  const { creditRecordStatic, creditAvailableAmount } = accountStats
33
37
 
34
- const { approved } = useCLPoolAllowance(poolInfo.poolName, account)
38
+ const { approved } = useCLPoolAllowance(
39
+ poolInfo.poolName,
40
+ chainId,
41
+ account,
42
+ provider,
43
+ )
35
44
  const handleChangeAmount = useCallback(
36
45
  (newAmount: number) => {
37
46
  setCurrentAmount(newAmount)
@@ -51,15 +51,17 @@ export function CreditLineBorrow({
51
51
  handleSuccess,
52
52
  }: CreditLineBorrowProps): React.ReactElement | null {
53
53
  const dispatch = useDispatch()
54
- const { account, chainId } = useWeb3React()
54
+ const { account, chainId, provider } = useWeb3React()
55
55
  const poolName = POOL_NAME[poolNameStr]
56
56
  const poolType = POOL_TYPE[poolTypeStr]
57
- const poolInfo = usePoolInfo(poolName, poolType)
57
+ const poolInfo = usePoolInfo(poolName, poolType, chainId)
58
58
  const { step, errorMessage } = useAppSelector(selectWidgetState)
59
59
  const [accountStats, refreshAccountStats] = useAccountStats(
60
60
  poolName,
61
61
  poolType,
62
+ chainId,
62
63
  account,
64
+ provider,
63
65
  )
64
66
  const { isFirstTimeNotifiUser } = useIsFirstTimeNotifiUser(account, chainId)
65
67
  const { notifiChainSupported } = useDoesChainSupportNotifi(account, chainId)
@@ -0,0 +1,79 @@
1
+ import {
2
+ CreditStatsV2,
3
+ PoolInfoV2,
4
+ UnderlyingTokenInfo,
5
+ usePoolSafeAllowanceV2,
6
+ } from '@huma-finance/shared'
7
+ import { useWeb3React } from '@web3-react/core'
8
+ import { ethers } from 'ethers'
9
+ import React, { useCallback, useState } from 'react'
10
+
11
+ import { useAppDispatch } from '../../../hooks/useRedux'
12
+ import { setBorrowInfo } from '../../../store/widgets.reducers'
13
+ import { WIDGET_STEP } from '../../../store/widgets.store'
14
+ import { ChooseAmountModal } from '../../ChooseAmountModal'
15
+ import { LoadingModal } from '../../LoadingModal'
16
+
17
+ type Props = {
18
+ poolInfo: PoolInfoV2
19
+ poolUnderlyingToken: UnderlyingTokenInfo
20
+ accountStats: CreditStatsV2
21
+ }
22
+
23
+ export function ChooseAmount({
24
+ poolInfo,
25
+ poolUnderlyingToken,
26
+ accountStats,
27
+ }: Props): React.ReactElement | null {
28
+ const dispatch = useAppDispatch()
29
+ const { account, provider } = useWeb3React()
30
+ const { symbol, decimals } = poolUnderlyingToken!
31
+ const [currentAmount, setCurrentAmount] = useState(0)
32
+ const { creditAvailable } = accountStats
33
+ const creditAvailableFormatted = creditAvailable
34
+ ? Number(ethers.utils.formatUnits(creditAvailable, decimals))
35
+ : 0
36
+
37
+ const { autopayEnabled } = usePoolSafeAllowanceV2(
38
+ poolInfo.poolName,
39
+ account,
40
+ provider,
41
+ )
42
+ const handleChangeAmount = useCallback((newAmount: number) => {
43
+ setCurrentAmount(newAmount)
44
+ }, [])
45
+
46
+ const handleAction = useCallback(() => {
47
+ const nextStep = autopayEnabled
48
+ ? WIDGET_STEP.Transfer
49
+ : WIDGET_STEP.ApproveAllowance
50
+
51
+ dispatch(
52
+ setBorrowInfo({
53
+ borrowAmount: currentAmount,
54
+ borrowAmountBN: ethers.utils
55
+ .parseUnits(currentAmount.toString(), decimals)
56
+ .toJSON(),
57
+ chargedFees: 0,
58
+ nextStep,
59
+ }),
60
+ )
61
+ }, [autopayEnabled, currentAmount, decimals, dispatch])
62
+
63
+ if (autopayEnabled === undefined) {
64
+ return <LoadingModal title='Borrow' />
65
+ }
66
+
67
+ return (
68
+ <ChooseAmountModal
69
+ title='Borrow'
70
+ description1='Choose Amount'
71
+ sliderMax={creditAvailableFormatted}
72
+ currentAmount={currentAmount}
73
+ tokenSymbol={symbol}
74
+ handleChangeAmount={handleChangeAmount}
75
+ handleAction={handleAction}
76
+ actionText='borrow'
77
+ />
78
+ )
79
+ }
@@ -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.Transfer))
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,50 @@
1
+ import { PoolInfoV2, txAtom, useCreditContractV2 } from '@huma-finance/shared'
2
+ import { useWeb3React } from '@web3-react/core'
3
+ import { BigNumber } from 'ethers'
4
+ import { useResetAtom } from 'jotai/utils'
5
+ import React, { useCallback } 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 { TxSendModalV2 } from '../../TxSendModalV2'
13
+
14
+ type Props = {
15
+ poolInfo: PoolInfoV2
16
+ }
17
+
18
+ export function Transfer({ poolInfo }: Props): React.ReactElement {
19
+ const dispatch = useAppDispatch()
20
+ const { provider, account } = useWeb3React()
21
+ const reset = useResetAtom(txAtom)
22
+ const { borrowAmountBN: borrowAmountBNJson } =
23
+ useAppSelector(selectWidgetState)
24
+ const borrowAmountBN = BigNumber.from(borrowAmountBNJson)
25
+ const creditContract = useCreditContractV2(
26
+ poolInfo.poolName,
27
+ provider,
28
+ account,
29
+ )
30
+
31
+ const handleSuccess = useCallback(() => {
32
+ reset()
33
+ const nextStep = WIDGET_STEP.Done
34
+ dispatch(setStep(nextStep))
35
+ }, [dispatch, reset])
36
+
37
+ if (!account || !creditContract) {
38
+ return <LoadingModal title='Borrow' />
39
+ }
40
+
41
+ return (
42
+ <TxSendModalV2
43
+ title='Borrow'
44
+ contract={creditContract}
45
+ method='drawdown'
46
+ params={[account, borrowAmountBN]}
47
+ handleSuccess={handleSuccess}
48
+ />
49
+ )
50
+ }
@@ -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
+ }