@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
|
@@ -0,0 +1,140 @@
|
|
|
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 { LoadingModal } from '../../LoadingModal'
|
|
22
|
+
import { WidgetWrapper } from '../../WidgetWrapper'
|
|
23
|
+
import { ChooseAmount } from './1-ChooseAmount'
|
|
24
|
+
import { ApproveAllowance } from './2-ApproveAllowance'
|
|
25
|
+
import { Transfer } from './3-Transfer'
|
|
26
|
+
import { Success } from './4-Success'
|
|
27
|
+
import { Notifications } from './5-Notifications'
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Credit line pool borrow props V2
|
|
31
|
+
* @typedef {Object} CreditLineBorrowPropsV2
|
|
32
|
+
* @property {POOL_NAME} poolName The name of the pool.
|
|
33
|
+
* @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
|
|
34
|
+
* @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the credit line pool borrow action is successful.
|
|
35
|
+
*/
|
|
36
|
+
export interface CreditLineBorrowPropsV2 {
|
|
37
|
+
poolName: keyof typeof POOL_NAME
|
|
38
|
+
handleClose: () => void
|
|
39
|
+
handleSuccess?: (blockNumber?: number) => void
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function CreditLineBorrowV2({
|
|
43
|
+
poolName: poolNameStr,
|
|
44
|
+
handleClose,
|
|
45
|
+
handleSuccess,
|
|
46
|
+
}: CreditLineBorrowPropsV2): React.ReactElement | null {
|
|
47
|
+
const dispatch = useDispatch()
|
|
48
|
+
const poolName = POOL_NAME[poolNameStr]
|
|
49
|
+
const { account, chainId, provider } = useWeb3React()
|
|
50
|
+
const poolInfo = usePoolInfoV2(poolName, chainId)
|
|
51
|
+
const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
|
|
52
|
+
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
53
|
+
const [accountStats, refreshAccountStats] = useCreditStatsV2(
|
|
54
|
+
poolName,
|
|
55
|
+
account,
|
|
56
|
+
provider,
|
|
57
|
+
)
|
|
58
|
+
const { isFirstTimeNotifiUser } = useIsFirstTimeNotifiUser(account, chainId)
|
|
59
|
+
const { notifiChainSupported } = useDoesChainSupportNotifi(account, chainId)
|
|
60
|
+
const { creditRecord } = accountStats
|
|
61
|
+
const accountState = creditRecord?.state
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (!step && accountState !== undefined) {
|
|
65
|
+
if (accountState >= CreditStateV2.Approved) {
|
|
66
|
+
dispatch(setStep(WIDGET_STEP.ChooseAmount))
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}, [accountState, dispatch, step])
|
|
70
|
+
|
|
71
|
+
const setupNotificationsOrClose = useCallback(() => {
|
|
72
|
+
if (isFirstTimeNotifiUser && notifiChainSupported) {
|
|
73
|
+
dispatch(setStep(WIDGET_STEP.Notifications))
|
|
74
|
+
} else {
|
|
75
|
+
handleClose()
|
|
76
|
+
}
|
|
77
|
+
}, [dispatch, handleClose, isFirstTimeNotifiUser, notifiChainSupported])
|
|
78
|
+
|
|
79
|
+
const handleSuccessCallback = useCallback(() => {
|
|
80
|
+
refreshAccountStats()
|
|
81
|
+
if (handleSuccess) {
|
|
82
|
+
handleSuccess()
|
|
83
|
+
}
|
|
84
|
+
}, [handleSuccess, refreshAccountStats])
|
|
85
|
+
|
|
86
|
+
if (!poolInfo || !poolUnderlyingToken || !creditRecord) {
|
|
87
|
+
return (
|
|
88
|
+
<WidgetWrapper
|
|
89
|
+
isOpen
|
|
90
|
+
isLoading
|
|
91
|
+
loadingTitle='Borrow'
|
|
92
|
+
handleClose={handleClose}
|
|
93
|
+
handleSuccess={handleSuccessCallback}
|
|
94
|
+
/>
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<WidgetWrapper
|
|
100
|
+
isOpen
|
|
101
|
+
loadingTitle='Borrow'
|
|
102
|
+
handleClose={handleClose}
|
|
103
|
+
handleSuccess={handleSuccessCallback}
|
|
104
|
+
>
|
|
105
|
+
{!step && <LoadingModal title='Borrow' />}
|
|
106
|
+
{step === WIDGET_STEP.ChooseAmount && (
|
|
107
|
+
<ChooseAmount
|
|
108
|
+
poolInfo={poolInfo}
|
|
109
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
110
|
+
accountStats={accountStats}
|
|
111
|
+
/>
|
|
112
|
+
)}
|
|
113
|
+
{step === WIDGET_STEP.ApproveAllowance && (
|
|
114
|
+
<ApproveAllowance
|
|
115
|
+
poolInfo={poolInfo}
|
|
116
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
117
|
+
/>
|
|
118
|
+
)}
|
|
119
|
+
{step === WIDGET_STEP.Transfer && <Transfer poolInfo={poolInfo} />}
|
|
120
|
+
{step === WIDGET_STEP.Done && (
|
|
121
|
+
<Success
|
|
122
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
123
|
+
handleAction={setupNotificationsOrClose}
|
|
124
|
+
creditRecord={accountStats.creditRecord!}
|
|
125
|
+
hasNextStep={isFirstTimeNotifiUser}
|
|
126
|
+
/>
|
|
127
|
+
)}
|
|
128
|
+
{step === WIDGET_STEP.Notifications && (
|
|
129
|
+
<Notifications handleAction={handleClose} />
|
|
130
|
+
)}
|
|
131
|
+
{step === WIDGET_STEP.Error && (
|
|
132
|
+
<ErrorModal
|
|
133
|
+
title='Borrow'
|
|
134
|
+
errorMessage={errorMessage}
|
|
135
|
+
handleOk={handleClose}
|
|
136
|
+
/>
|
|
137
|
+
)}
|
|
138
|
+
</WidgetWrapper>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
useCLPoolAllowance,
|
|
7
7
|
} from '@huma-finance/shared'
|
|
8
8
|
import React, { useCallback, useEffect, useState } from 'react'
|
|
9
|
-
import { BigNumber } from 'ethers'
|
|
10
9
|
|
|
11
10
|
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
12
11
|
import { setPaymentAmount, setStep } from '../../../store/widgets.reducers'
|
|
@@ -25,10 +24,15 @@ export function ChooseAmount({
|
|
|
25
24
|
poolInfo,
|
|
26
25
|
}: Props): React.ReactElement | null {
|
|
27
26
|
const dispatch = useAppDispatch()
|
|
28
|
-
const { account } = useWeb3React()
|
|
27
|
+
const { account, chainId, provider } = useWeb3React()
|
|
29
28
|
const { symbol, decimals } = poolInfo.poolUnderlyingToken
|
|
30
29
|
const [currentAmount, setCurrentAmount] = useState(0)
|
|
31
|
-
const { allowance } = useCLPoolAllowance(
|
|
30
|
+
const { allowance } = useCLPoolAllowance(
|
|
31
|
+
poolInfo.poolName,
|
|
32
|
+
chainId,
|
|
33
|
+
account,
|
|
34
|
+
provider,
|
|
35
|
+
)
|
|
32
36
|
|
|
33
37
|
useEffect(() => {
|
|
34
38
|
setCurrentAmount(totalDueAmount)
|
|
@@ -44,8 +48,8 @@ export function ChooseAmount({
|
|
|
44
48
|
)
|
|
45
49
|
|
|
46
50
|
const handleAction = useCallback(() => {
|
|
47
|
-
const payAmount = upScale
|
|
48
|
-
const step = payAmount.gt(allowance)
|
|
51
|
+
const payAmount = upScale(currentAmount, decimals)
|
|
52
|
+
const step = toBigNumber(payAmount).gt(allowance)
|
|
49
53
|
? WIDGET_STEP.ApproveAllowance
|
|
50
54
|
: WIDGET_STEP.Transfer
|
|
51
55
|
dispatch(setStep(step))
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useWeb3React } from '@web3-react/core'
|
|
2
2
|
import { PoolInfoType, toBigNumber, upScale } from '@huma-finance/shared'
|
|
3
3
|
import React, { useCallback } from 'react'
|
|
4
|
-
import { BigNumber } from 'ethers'
|
|
5
4
|
|
|
6
5
|
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
7
6
|
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
@@ -18,10 +17,7 @@ export function Transfer({ poolInfo }: Props): React.ReactElement {
|
|
|
18
17
|
const { account } = useWeb3React()
|
|
19
18
|
const { paymentAmount } = useAppSelector(selectWidgetState)
|
|
20
19
|
const { decimals } = poolInfo.poolUnderlyingToken
|
|
21
|
-
const paymentBigNumber = upScale
|
|
22
|
-
toBigNumber(paymentAmount!),
|
|
23
|
-
decimals,
|
|
24
|
-
)
|
|
20
|
+
const paymentBigNumber = toBigNumber(upScale(paymentAmount!, decimals))
|
|
25
21
|
|
|
26
22
|
const handleSuccess = useCallback(() => {
|
|
27
23
|
dispatch(setStep(WIDGET_STEP.Done))
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
decodeLogs,
|
|
3
3
|
downScale,
|
|
4
|
-
|
|
4
|
+
formatNumber,
|
|
5
5
|
PoolInfoType,
|
|
6
6
|
sendTxAtom,
|
|
7
7
|
TRANSFER_ABI,
|
|
@@ -32,7 +32,7 @@ export function Success({ poolInfo, handleAction }: Props): React.ReactElement {
|
|
|
32
32
|
}, [decimals, txReceipt])
|
|
33
33
|
|
|
34
34
|
const content = [
|
|
35
|
-
`You successfully paid ${
|
|
35
|
+
`You successfully paid ${formatNumber(payedAmount)} ${symbol}.`,
|
|
36
36
|
]
|
|
37
37
|
|
|
38
38
|
return <TxDoneModal handleAction={handleAction} content={content} />
|
|
@@ -41,15 +41,17 @@ export function CreditLinePayment({
|
|
|
41
41
|
handleSuccess,
|
|
42
42
|
}: CreditLinePaymentProps): React.ReactElement | null {
|
|
43
43
|
const dispatch = useDispatch()
|
|
44
|
-
const { account } = useWeb3React()
|
|
44
|
+
const { account, chainId, provider } = useWeb3React()
|
|
45
45
|
const poolName = POOL_NAME[poolNameStr]
|
|
46
46
|
const poolType = POOL_TYPE[poolTypeStr]
|
|
47
|
-
const poolInfo = usePoolInfo(poolName, poolType)
|
|
47
|
+
const poolInfo = usePoolInfo(poolName, poolType, chainId)
|
|
48
48
|
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
49
49
|
const [{ creditRecord, payoffAmount, totalDueAmount }] = useAccountStats(
|
|
50
50
|
poolName,
|
|
51
51
|
poolType,
|
|
52
|
+
chainId,
|
|
52
53
|
account,
|
|
54
|
+
provider,
|
|
53
55
|
)
|
|
54
56
|
|
|
55
57
|
useEffect(() => {
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatNumber,
|
|
3
|
+
PoolInfoV2,
|
|
4
|
+
toBigNumber,
|
|
5
|
+
UnderlyingTokenInfo,
|
|
6
|
+
upScale,
|
|
7
|
+
usePoolSafeAllowanceV2,
|
|
8
|
+
} from '@huma-finance/shared'
|
|
9
|
+
import { useWeb3React } from '@web3-react/core'
|
|
10
|
+
import { BigNumber, ethers } from 'ethers'
|
|
11
|
+
import React, { useCallback, useEffect, useState } from 'react'
|
|
12
|
+
|
|
13
|
+
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
14
|
+
import { setPaymentAmount, setStep } from '../../../store/widgets.reducers'
|
|
15
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
16
|
+
import { InputAmountModal } from '../../InputAmountModal'
|
|
17
|
+
import { LoadingModal } from '../../LoadingModal'
|
|
18
|
+
|
|
19
|
+
type Props = {
|
|
20
|
+
payoffAmount: BigNumber
|
|
21
|
+
totalDueAmount: BigNumber
|
|
22
|
+
poolInfo: PoolInfoV2
|
|
23
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function ChooseAmount({
|
|
27
|
+
payoffAmount: payoffAmountBN,
|
|
28
|
+
totalDueAmount: totalDueAmountBN,
|
|
29
|
+
poolInfo,
|
|
30
|
+
poolUnderlyingToken,
|
|
31
|
+
}: Props): React.ReactElement | null {
|
|
32
|
+
const dispatch = useAppDispatch()
|
|
33
|
+
const { account, provider } = useWeb3React()
|
|
34
|
+
const { symbol, decimals } = poolUnderlyingToken
|
|
35
|
+
const [currentAmount, setCurrentAmount] = useState(0)
|
|
36
|
+
const { allowance } = usePoolSafeAllowanceV2(
|
|
37
|
+
poolInfo.poolName,
|
|
38
|
+
account,
|
|
39
|
+
provider,
|
|
40
|
+
)
|
|
41
|
+
const totalDueAmount = Number(
|
|
42
|
+
ethers.utils.formatUnits(totalDueAmountBN, decimals),
|
|
43
|
+
)
|
|
44
|
+
const payoffAmount = Number(
|
|
45
|
+
ethers.utils.formatUnits(payoffAmountBN, decimals),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
console.log('totalDueAmountBN', totalDueAmountBN.toString())
|
|
49
|
+
console.log('payoffAmountBN', payoffAmountBN.toString())
|
|
50
|
+
console.log('payoffAmount', payoffAmount)
|
|
51
|
+
console.log('currentAmount', currentAmount)
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
setCurrentAmount(totalDueAmount)
|
|
55
|
+
}, [totalDueAmount])
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
setCurrentAmount(totalDueAmount)
|
|
59
|
+
dispatch(setPaymentAmount({ paymentAmount: totalDueAmount }))
|
|
60
|
+
}, [dispatch, totalDueAmount])
|
|
61
|
+
|
|
62
|
+
const handleChangeAmount = useCallback(
|
|
63
|
+
(newAmount: number) => {
|
|
64
|
+
setCurrentAmount(newAmount)
|
|
65
|
+
dispatch(setPaymentAmount({ paymentAmount: newAmount }))
|
|
66
|
+
},
|
|
67
|
+
[dispatch],
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
const handleAction = useCallback(() => {
|
|
71
|
+
const payAmount = upScale(currentAmount, decimals)
|
|
72
|
+
const step = toBigNumber(payAmount).gt(allowance!)
|
|
73
|
+
? WIDGET_STEP.ApproveAllowance
|
|
74
|
+
: WIDGET_STEP.Transfer
|
|
75
|
+
dispatch(setStep(step))
|
|
76
|
+
}, [allowance, currentAmount, decimals, dispatch])
|
|
77
|
+
|
|
78
|
+
if (!allowance) {
|
|
79
|
+
return <LoadingModal title='Pay' />
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<InputAmountModal
|
|
84
|
+
title='Pay'
|
|
85
|
+
subTitle='Enter Amount'
|
|
86
|
+
tokenSymbol={symbol}
|
|
87
|
+
currentAmount={currentAmount}
|
|
88
|
+
handleChangeAmount={handleChangeAmount}
|
|
89
|
+
maxAmount={payoffAmount}
|
|
90
|
+
maxAmountText='Pay Off'
|
|
91
|
+
info={`${formatNumber(totalDueAmount.toFixed(0))} Due`}
|
|
92
|
+
handleAction={handleAction}
|
|
93
|
+
actionText='PAY'
|
|
94
|
+
/>
|
|
95
|
+
)
|
|
96
|
+
}
|
|
@@ -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 {
|
|
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,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PoolInfoV2,
|
|
3
|
+
toBigNumber,
|
|
4
|
+
UnderlyingTokenInfo,
|
|
5
|
+
upScale,
|
|
6
|
+
useCreditContractV2,
|
|
7
|
+
} from '@huma-finance/shared'
|
|
8
|
+
import { useWeb3React } from '@web3-react/core'
|
|
9
|
+
import React, { useCallback } from 'react'
|
|
10
|
+
|
|
11
|
+
import { useAppDispatch, 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 { LoadingModal } from '../../LoadingModal'
|
|
16
|
+
import { TxSendModalV2 } from '../../TxSendModalV2'
|
|
17
|
+
|
|
18
|
+
type Props = {
|
|
19
|
+
poolInfo: PoolInfoV2
|
|
20
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function Transfer({
|
|
24
|
+
poolInfo,
|
|
25
|
+
poolUnderlyingToken,
|
|
26
|
+
}: Props): React.ReactElement {
|
|
27
|
+
const dispatch = useAppDispatch()
|
|
28
|
+
const { account, provider } = useWeb3React()
|
|
29
|
+
const { paymentAmount } = useAppSelector(selectWidgetState)
|
|
30
|
+
const { decimals } = poolUnderlyingToken
|
|
31
|
+
const paymentBigNumber = toBigNumber(upScale(paymentAmount!, decimals))
|
|
32
|
+
const creditContract = useCreditContractV2(
|
|
33
|
+
poolInfo.poolName,
|
|
34
|
+
provider,
|
|
35
|
+
account,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
const handleSuccess = useCallback(() => {
|
|
39
|
+
dispatch(setStep(WIDGET_STEP.Done))
|
|
40
|
+
}, [dispatch])
|
|
41
|
+
|
|
42
|
+
if (!account || !creditContract) {
|
|
43
|
+
return <LoadingModal title='Pay' />
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<TxSendModalV2
|
|
48
|
+
title='Pay'
|
|
49
|
+
contract={creditContract}
|
|
50
|
+
method='makePayment'
|
|
51
|
+
params={[account, paymentBigNumber]}
|
|
52
|
+
handleSuccess={handleSuccess}
|
|
53
|
+
/>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decodeLogs,
|
|
3
|
+
downScale,
|
|
4
|
+
formatNumber,
|
|
5
|
+
sendTxAtom,
|
|
6
|
+
TRANSFER_ABI,
|
|
7
|
+
UnderlyingTokenInfo,
|
|
8
|
+
} from '@huma-finance/shared'
|
|
9
|
+
import { useAtom } from 'jotai'
|
|
10
|
+
import React, { useEffect, useState } from 'react'
|
|
11
|
+
|
|
12
|
+
import { TxDoneModal } from '../../TxDoneModal'
|
|
13
|
+
|
|
14
|
+
type Props = {
|
|
15
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
16
|
+
handleAction: () => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function Success({
|
|
20
|
+
poolUnderlyingToken,
|
|
21
|
+
handleAction,
|
|
22
|
+
}: Props): React.ReactElement {
|
|
23
|
+
const { symbol, decimals } = poolUnderlyingToken
|
|
24
|
+
const [{ txReceipt }] = useAtom(sendTxAtom)
|
|
25
|
+
const [paidAmount, setPaidAmount] = useState<string | undefined>()
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (txReceipt) {
|
|
29
|
+
const [event] = decodeLogs(txReceipt.logs, TRANSFER_ABI)
|
|
30
|
+
if (event) {
|
|
31
|
+
const paidAmount = downScale(event.args.value.toString(), decimals)
|
|
32
|
+
setPaidAmount(paidAmount)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}, [decimals, txReceipt])
|
|
36
|
+
|
|
37
|
+
const content = [
|
|
38
|
+
`You successfully paid ${formatNumber(paidAmount)} ${symbol}.`,
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
return <TxDoneModal handleAction={handleAction} content={content} />
|
|
42
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {
|
|
2
|
+
POOL_NAME,
|
|
3
|
+
useCreditStatsV2,
|
|
4
|
+
usePoolInfoV2,
|
|
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 { ChooseAmount } from './1-ChooseAmount'
|
|
18
|
+
import { ApproveAllowance } from './2-ApproveAllowance'
|
|
19
|
+
import { Transfer } from './3-Transfer'
|
|
20
|
+
import { Success } from './4-Success'
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Credit line pool payment props V2
|
|
24
|
+
* @typedef {Object} CreditLinePaymentPropsV2
|
|
25
|
+
* @property {POOL_NAME} poolName The name of the pool.
|
|
26
|
+
* @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
|
|
27
|
+
* @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the credit line pool payment action is successful.
|
|
28
|
+
*/
|
|
29
|
+
export type CreditLinePaymentPropsV2 = {
|
|
30
|
+
poolName: keyof typeof POOL_NAME
|
|
31
|
+
handleClose: () => void
|
|
32
|
+
handleSuccess?: (blockNumber?: number) => void
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function CreditLinePaymentV2({
|
|
36
|
+
poolName: poolNameStr,
|
|
37
|
+
handleClose,
|
|
38
|
+
handleSuccess,
|
|
39
|
+
}: CreditLinePaymentPropsV2): React.ReactElement | null {
|
|
40
|
+
const dispatch = useDispatch()
|
|
41
|
+
const { account, chainId, provider } = useWeb3React()
|
|
42
|
+
const poolName = POOL_NAME[poolNameStr]
|
|
43
|
+
const poolInfo = usePoolInfoV2(poolName, chainId)
|
|
44
|
+
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
45
|
+
const [{ creditRecord, totalDueAmount, payoffAmount }] = useCreditStatsV2(
|
|
46
|
+
poolName,
|
|
47
|
+
account,
|
|
48
|
+
provider,
|
|
49
|
+
)
|
|
50
|
+
const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
dispatch(setStep(WIDGET_STEP.ChooseAmount))
|
|
54
|
+
}, [dispatch])
|
|
55
|
+
|
|
56
|
+
if (!poolInfo || !creditRecord || !poolUnderlyingToken) {
|
|
57
|
+
return (
|
|
58
|
+
<WidgetWrapper
|
|
59
|
+
isOpen
|
|
60
|
+
isLoading
|
|
61
|
+
loadingTitle='Pay'
|
|
62
|
+
handleClose={handleClose}
|
|
63
|
+
handleSuccess={handleSuccess}
|
|
64
|
+
/>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<WidgetWrapper
|
|
70
|
+
isOpen
|
|
71
|
+
isLoading={!creditRecord}
|
|
72
|
+
loadingTitle='Pay'
|
|
73
|
+
handleClose={handleClose}
|
|
74
|
+
handleSuccess={handleSuccess}
|
|
75
|
+
>
|
|
76
|
+
{step === WIDGET_STEP.ChooseAmount && (
|
|
77
|
+
<ChooseAmount
|
|
78
|
+
poolInfo={poolInfo}
|
|
79
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
80
|
+
payoffAmount={payoffAmount!}
|
|
81
|
+
totalDueAmount={totalDueAmount!}
|
|
82
|
+
/>
|
|
83
|
+
)}
|
|
84
|
+
{step === WIDGET_STEP.ApproveAllowance && (
|
|
85
|
+
<ApproveAllowance
|
|
86
|
+
poolInfo={poolInfo}
|
|
87
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
88
|
+
/>
|
|
89
|
+
)}
|
|
90
|
+
{step === WIDGET_STEP.Transfer && (
|
|
91
|
+
<Transfer
|
|
92
|
+
poolInfo={poolInfo}
|
|
93
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
94
|
+
/>
|
|
95
|
+
)}
|
|
96
|
+
{step === WIDGET_STEP.Done && (
|
|
97
|
+
<Success
|
|
98
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
99
|
+
handleAction={handleClose}
|
|
100
|
+
/>
|
|
101
|
+
)}
|
|
102
|
+
{step === WIDGET_STEP.Error && (
|
|
103
|
+
<ErrorModal
|
|
104
|
+
title='Pay'
|
|
105
|
+
errorMessage={errorMessage}
|
|
106
|
+
handleOk={handleClose}
|
|
107
|
+
/>
|
|
108
|
+
)}
|
|
109
|
+
</WidgetWrapper>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FirstLossCoverIndex,
|
|
3
|
+
PoolInfoV2,
|
|
4
|
+
UnderlyingTokenInfo,
|
|
5
|
+
} from '@huma-finance/shared'
|
|
6
|
+
import { BigNumber } from 'ethers'
|
|
7
|
+
import React from 'react'
|
|
8
|
+
|
|
9
|
+
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
10
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
11
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
12
|
+
import { ApproveAllowanceModalV2 } from '../../ApproveAllowanceModalV2'
|
|
13
|
+
|
|
14
|
+
type Props = {
|
|
15
|
+
poolInfo: PoolInfoV2
|
|
16
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
17
|
+
amountToDeposit: BigNumber
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function ApproveAllowance({
|
|
21
|
+
poolInfo,
|
|
22
|
+
poolUnderlyingToken,
|
|
23
|
+
amountToDeposit,
|
|
24
|
+
}: Props): React.ReactElement {
|
|
25
|
+
const dispatch = useAppDispatch()
|
|
26
|
+
|
|
27
|
+
const handleSuccess = () => {
|
|
28
|
+
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<ApproveAllowanceModalV2
|
|
33
|
+
poolInfo={poolInfo}
|
|
34
|
+
spender={poolInfo.firstLossCovers[FirstLossCoverIndex.borrower]}
|
|
35
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
36
|
+
allowanceAmount={amountToDeposit}
|
|
37
|
+
handleSuccess={handleSuccess}
|
|
38
|
+
/>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FirstLossCoverIndex,
|
|
3
|
+
PoolInfoV2,
|
|
4
|
+
useFirstLossCoverContractV2,
|
|
5
|
+
} from '@huma-finance/shared'
|
|
6
|
+
import { useWeb3React } from '@web3-react/core'
|
|
7
|
+
import { BigNumber } from 'ethers'
|
|
8
|
+
import React, { useCallback } from 'react'
|
|
9
|
+
|
|
10
|
+
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
11
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
12
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
13
|
+
import { LoadingModal } from '../../LoadingModal'
|
|
14
|
+
import { TxSendModalV2 } from '../../TxSendModalV2'
|
|
15
|
+
|
|
16
|
+
type Props = {
|
|
17
|
+
poolInfo: PoolInfoV2
|
|
18
|
+
amountToDeposit: BigNumber
|
|
19
|
+
title: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function Transfer({
|
|
23
|
+
poolInfo,
|
|
24
|
+
amountToDeposit,
|
|
25
|
+
title,
|
|
26
|
+
}: Props): React.ReactElement | null {
|
|
27
|
+
const dispatch = useAppDispatch()
|
|
28
|
+
const { provider, account } = useWeb3React()
|
|
29
|
+
const firstLossCoverContract = useFirstLossCoverContractV2(
|
|
30
|
+
poolInfo.poolName,
|
|
31
|
+
FirstLossCoverIndex.borrower,
|
|
32
|
+
provider,
|
|
33
|
+
account,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
const handleSuccess = useCallback(() => {
|
|
37
|
+
dispatch(setStep(WIDGET_STEP.Done))
|
|
38
|
+
}, [dispatch])
|
|
39
|
+
|
|
40
|
+
if (!firstLossCoverContract) {
|
|
41
|
+
return <LoadingModal title={title} />
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<TxSendModalV2
|
|
46
|
+
title={title}
|
|
47
|
+
contract={firstLossCoverContract}
|
|
48
|
+
method='depositCover'
|
|
49
|
+
params={[amountToDeposit]}
|
|
50
|
+
handleSuccess={handleSuccess}
|
|
51
|
+
/>
|
|
52
|
+
)
|
|
53
|
+
}
|