@huma-finance/widgets 0.0.51-beta.227 → 0.0.51-beta.347
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/API.md +454 -0
- package/dist/cjs/index.cjs +6097 -3790
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.d.ts +280 -2
- package/dist/index.js +6089 -3792
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/components/ApproveAllowanceModal.tsx +3 -1
- package/src/components/ApproveAllowanceModalV2.tsx +141 -0
- package/src/components/CreditLine/approve/index.tsx +9 -3
- package/src/components/CreditLine/autoPaybackV2/1-ApproveAllowance.tsx +33 -0
- package/src/components/CreditLine/autoPaybackV2/2-Success.tsx +13 -0
- package/src/components/CreditLine/autoPaybackV2/index.tsx +87 -0
- package/src/components/CreditLine/borrow/2-ChooseAmount.tsx +12 -3
- package/src/components/CreditLine/borrow/5-Success.tsx +7 -2
- package/src/components/CreditLine/borrow/index.tsx +4 -2
- package/src/components/CreditLine/borrowV2/1-ChooseAmount.tsx +81 -0
- package/src/components/CreditLine/borrowV2/2-ApproveAllowance.tsx +33 -0
- package/src/components/CreditLine/borrowV2/3-Transfer.tsx +50 -0
- package/src/components/CreditLine/borrowV2/4-Success.tsx +42 -0
- package/src/components/CreditLine/borrowV2/5-Notifications.tsx +10 -0
- package/src/components/CreditLine/borrowV2/index.tsx +140 -0
- package/src/components/CreditLine/payment/1-ChooseAmount.tsx +9 -5
- package/src/components/CreditLine/payment/3-Transfer.tsx +1 -5
- package/src/components/CreditLine/payment/4-Success.tsx +2 -2
- package/src/components/CreditLine/payment/index.tsx +4 -2
- package/src/components/CreditLine/paymentV2/1-ChooseAmount.tsx +96 -0
- package/src/components/CreditLine/paymentV2/2-ApproveAllowance.tsx +33 -0
- package/src/components/CreditLine/paymentV2/3-Transfer.tsx +55 -0
- package/src/components/CreditLine/paymentV2/4-Success.tsx +42 -0
- package/src/components/CreditLine/paymentV2/index.tsx +111 -0
- package/src/components/CreditLine/supplyFLC/1-ApproveAllowance.tsx +40 -0
- package/src/components/CreditLine/supplyFLC/2-Transfer.tsx +53 -0
- package/src/components/CreditLine/supplyFLC/3-Success.tsx +26 -0
- package/src/components/CreditLine/supplyFLC/index.tsx +121 -0
- package/src/components/Factoring/FactoredList.tsx +2 -1
- package/src/components/InputAmountModal.tsx +156 -0
- package/src/components/InvoiceFactoring/borrow/2-ChooseAmount.tsx +8 -1
- package/src/components/InvoiceFactoring/borrow/4-ApproveNFT.tsx +6 -2
- package/src/components/InvoiceFactoring/borrow/6-Success.tsx +5 -1
- package/src/components/InvoiceFactoring/borrow/index.tsx +9 -3
- package/src/components/InvoiceFactoring/payment/1-ChooseAmount.tsx +7 -2
- package/src/components/InvoiceFactoring/payment/index.tsx +9 -3
- package/src/components/Lend/addRedemptionV2/1-ChooseTranche.tsx +114 -0
- package/src/components/Lend/addRedemptionV2/2-ChooseAmount.tsx +114 -0
- package/src/components/Lend/addRedemptionV2/3-Transfer.tsx +56 -0
- package/src/components/Lend/addRedemptionV2/4-Done.tsx +20 -0
- package/src/components/Lend/addRedemptionV2/index.tsx +173 -0
- package/src/components/Lend/cancelRedemptionV2 /1-Transfer.tsx +51 -0
- package/src/components/Lend/cancelRedemptionV2 /2-Done.tsx +29 -0
- package/src/components/Lend/cancelRedemptionV2 /index.tsx +120 -0
- package/src/components/Lend/supply/1-Evaluation/EvaluationKYC.tsx +19 -2
- package/src/components/Lend/supply/2-ChooseAmount.tsx +1 -0
- package/src/components/Lend/supply/index.tsx +17 -3
- package/src/components/Lend/supplyV2/1-ChooseTranche.tsx +116 -0
- package/src/components/Lend/supplyV2/2-Evaluation.tsx +345 -0
- package/src/components/Lend/supplyV2/3-ChooseAmount.tsx +87 -0
- package/src/components/Lend/supplyV2/4-ApproveAllowance.tsx +33 -0
- package/src/components/Lend/supplyV2/5-Transfer.tsx +59 -0
- package/src/components/Lend/supplyV2/6-Success.tsx +79 -0
- package/src/components/Lend/supplyV2/7-Notifications.tsx +10 -0
- package/src/components/Lend/supplyV2/index.tsx +175 -0
- package/src/components/Lend/withdraw/1-CheckWithdrawble.tsx +5 -1
- package/src/components/Lend/withdraw/index.tsx +10 -3
- package/src/components/Lend/withdrawV2/1-ConfirmTransfer.tsx +135 -0
- package/src/components/Lend/withdrawV2/2-Transfer.tsx +50 -0
- package/src/components/Lend/withdrawV2/3-Done.tsx +31 -0
- package/src/components/Lend/withdrawV2/index.tsx +177 -0
- package/src/components/Notifi/NotifiSubscriptionModal.tsx +26 -38
- package/src/components/NumericFormatCustom.tsx +33 -0
- package/src/components/ReceivableBackedCreditLine/borrow/1-ChooseAmount.tsx +101 -0
- package/src/components/ReceivableBackedCreditLine/borrow/2-ApproveAllowance.tsx +33 -0
- package/src/components/ReceivableBackedCreditLine/borrow/3-ApproveReceivable.tsx +64 -0
- package/src/components/ReceivableBackedCreditLine/borrow/4-Transfer.tsx +61 -0
- package/src/components/ReceivableBackedCreditLine/borrow/5-Success.tsx +42 -0
- package/src/components/ReceivableBackedCreditLine/borrow/6-Notifications.tsx +10 -0
- package/src/components/ReceivableBackedCreditLine/borrow/index.tsx +148 -0
- package/src/components/ReceivableBackedCreditLine/payment/1-ChoosePaymentType.tsx +115 -0
- package/src/components/ReceivableBackedCreditLine/payment/2-ChooseAmount.tsx +84 -0
- package/src/components/ReceivableBackedCreditLine/payment/3-ApproveAllowance.tsx +41 -0
- package/src/components/ReceivableBackedCreditLine/payment/4-CreateReceivable.tsx +107 -0
- package/src/components/ReceivableBackedCreditLine/payment/5-ApproveReceivable.tsx +64 -0
- package/src/components/ReceivableBackedCreditLine/payment/6-Transfer.tsx +107 -0
- package/src/components/ReceivableBackedCreditLine/payment/7-Success.tsx +49 -0
- package/src/components/ReceivableBackedCreditLine/payment/index.tsx +159 -0
- package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +8 -1
- package/src/components/StreamFactoring/borrow/6-Transfer.tsx +3 -1
- package/src/components/StreamFactoring/borrow/7-Success.tsx +3 -1
- package/src/components/StreamFactoring/borrow/index.tsx +2 -2
- package/src/components/TxDoneModal.tsx +1 -1
- package/src/components/TxSendModal.tsx +8 -2
- package/src/components/TxSendModalV2.tsx +51 -0
- package/src/hooks/useNotifi.ts +4 -6
- package/src/index.tsx +268 -1
- package/src/store/widgets.reducers.ts +15 -0
- 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.51-beta.
|
|
3
|
+
"version": "0.0.51-beta.347+91129f3",
|
|
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.
|
|
34
|
-
"@huma-finance/shared": "^0.0.
|
|
33
|
+
"@huma-finance/sdk": "^0.0.51-beta.347+91129f3",
|
|
34
|
+
"@huma-finance/shared": "^0.0.51-beta.347+91129f3",
|
|
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": "
|
|
196
|
+
"gitHead": "91129f368c265e7b589b93b13a110770151d10c5"
|
|
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)
|
|
@@ -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(
|
|
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(
|
|
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(
|
|
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)
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
CreditRecordType,
|
|
3
|
+
PoolInfoType,
|
|
4
|
+
formatNumber,
|
|
5
|
+
timeUtil,
|
|
6
|
+
} from '@huma-finance/shared'
|
|
2
7
|
import React from 'react'
|
|
3
8
|
|
|
4
9
|
import { useAppSelector } from '../../../hooks/useRedux'
|
|
@@ -24,7 +29,7 @@ export function Success({
|
|
|
24
29
|
const dueDate = timeUtil.timestampToLL(creditRecord?.dueDate.toNumber())
|
|
25
30
|
|
|
26
31
|
const content = [
|
|
27
|
-
`${borrowAmountNet} ${symbol} is now in your wallet.`,
|
|
32
|
+
`${formatNumber(borrowAmountNet)} ${symbol} is now in your wallet.`,
|
|
28
33
|
`Note: your payment will be automatically deducted on ${dueDate}.`,
|
|
29
34
|
]
|
|
30
35
|
|
|
@@ -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,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CreditStatsV2,
|
|
3
|
+
formatNumber,
|
|
4
|
+
PoolInfoV2,
|
|
5
|
+
UnderlyingTokenInfo,
|
|
6
|
+
usePoolSafeAllowanceV2,
|
|
7
|
+
} from '@huma-finance/shared'
|
|
8
|
+
import { useWeb3React } from '@web3-react/core'
|
|
9
|
+
import { ethers } from 'ethers'
|
|
10
|
+
import React, { useCallback, 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 { InputAmountModal } from '../../InputAmountModal'
|
|
16
|
+
import { LoadingModal } from '../../LoadingModal'
|
|
17
|
+
|
|
18
|
+
type Props = {
|
|
19
|
+
poolInfo: PoolInfoV2
|
|
20
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
21
|
+
accountStats: CreditStatsV2
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function ChooseAmount({
|
|
25
|
+
poolInfo,
|
|
26
|
+
poolUnderlyingToken,
|
|
27
|
+
accountStats,
|
|
28
|
+
}: Props): React.ReactElement | null {
|
|
29
|
+
const dispatch = useAppDispatch()
|
|
30
|
+
const { account, provider } = useWeb3React()
|
|
31
|
+
const { symbol, decimals } = poolUnderlyingToken!
|
|
32
|
+
const [currentAmount, setCurrentAmount] = useState(0)
|
|
33
|
+
const { creditAvailable } = accountStats
|
|
34
|
+
const creditAvailableFormatted = creditAvailable
|
|
35
|
+
? Number(ethers.utils.formatUnits(creditAvailable, decimals))
|
|
36
|
+
: 0
|
|
37
|
+
|
|
38
|
+
const { autopayEnabled } = usePoolSafeAllowanceV2(
|
|
39
|
+
poolInfo.poolName,
|
|
40
|
+
account,
|
|
41
|
+
provider,
|
|
42
|
+
)
|
|
43
|
+
const handleChangeAmount = useCallback((newAmount: number) => {
|
|
44
|
+
setCurrentAmount(newAmount)
|
|
45
|
+
}, [])
|
|
46
|
+
|
|
47
|
+
const handleAction = useCallback(() => {
|
|
48
|
+
const nextStep = autopayEnabled
|
|
49
|
+
? WIDGET_STEP.Transfer
|
|
50
|
+
: WIDGET_STEP.ApproveAllowance
|
|
51
|
+
|
|
52
|
+
dispatch(
|
|
53
|
+
setBorrowInfo({
|
|
54
|
+
borrowAmount: currentAmount,
|
|
55
|
+
borrowAmountBN: ethers.utils
|
|
56
|
+
.parseUnits(currentAmount.toString(), decimals)
|
|
57
|
+
.toJSON(),
|
|
58
|
+
chargedFees: 0,
|
|
59
|
+
nextStep,
|
|
60
|
+
}),
|
|
61
|
+
)
|
|
62
|
+
}, [autopayEnabled, currentAmount, decimals, dispatch])
|
|
63
|
+
|
|
64
|
+
if (autopayEnabled === undefined) {
|
|
65
|
+
return <LoadingModal title='Borrow' />
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<InputAmountModal
|
|
70
|
+
title='Borrow'
|
|
71
|
+
subTitle='Choose Amount'
|
|
72
|
+
tokenSymbol={symbol}
|
|
73
|
+
currentAmount={currentAmount}
|
|
74
|
+
handleChangeAmount={handleChangeAmount}
|
|
75
|
+
maxAmount={creditAvailableFormatted}
|
|
76
|
+
info={`${formatNumber(creditAvailableFormatted)} Available`}
|
|
77
|
+
handleAction={handleAction}
|
|
78
|
+
actionText='BORROW'
|
|
79
|
+
/>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
@@ -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={[borrowAmountBN]}
|
|
47
|
+
handleSuccess={handleSuccess}
|
|
48
|
+
/>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CreditStatsV2,
|
|
3
|
+
formatNumber,
|
|
4
|
+
timeUtil,
|
|
5
|
+
UnderlyingTokenInfo,
|
|
6
|
+
} from '@huma-finance/shared'
|
|
7
|
+
import React from 'react'
|
|
8
|
+
|
|
9
|
+
import { useAppSelector } from '../../../hooks/useRedux'
|
|
10
|
+
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
11
|
+
import { TxDoneModal } from '../../TxDoneModal'
|
|
12
|
+
|
|
13
|
+
type Props = {
|
|
14
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
15
|
+
creditRecord: CreditStatsV2['creditRecord']
|
|
16
|
+
handleAction: () => void
|
|
17
|
+
hasNextStep: boolean
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function Success({
|
|
21
|
+
poolUnderlyingToken,
|
|
22
|
+
creditRecord,
|
|
23
|
+
handleAction,
|
|
24
|
+
hasNextStep,
|
|
25
|
+
}: Props): React.ReactElement {
|
|
26
|
+
const { borrowAmountNet } = useAppSelector(selectWidgetState)
|
|
27
|
+
const { symbol } = poolUnderlyingToken
|
|
28
|
+
const dueDate = timeUtil.timestampToLL(creditRecord?.nextDueDate.toNumber())
|
|
29
|
+
|
|
30
|
+
const content = [
|
|
31
|
+
`${formatNumber(borrowAmountNet)} ${symbol} is now in your wallet.`,
|
|
32
|
+
`Note: your payment will be automatically deducted on ${dueDate}.`,
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<TxDoneModal
|
|
37
|
+
handleAction={handleAction}
|
|
38
|
+
content={content}
|
|
39
|
+
buttonText={hasNextStep ? "WHAT'S NEXT" : undefined}
|
|
40
|
+
/>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
@@ -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
|
+
}
|