@huma-finance/widgets 0.0.8 → 0.0.11
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/dist/cjs/index.cjs +139 -131
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.js +139 -131
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/Activity.tsx +123 -123
- package/src/components/AllowListModal.tsx +113 -113
- package/src/components/ApproveAllowanceModal.tsx +118 -118
- package/src/components/ChooseAmountModal.tsx +315 -315
- package/src/components/CreditLine/borrow/1-Evaluation.tsx +158 -159
- package/src/components/CreditLine/borrow/2-AllowList.tsx +34 -34
- package/src/components/CreditLine/borrow/3-ChooseAmount.tsx +74 -74
- package/src/components/CreditLine/borrow/4-ApproveAllowance.tsx +29 -29
- package/src/components/CreditLine/borrow/5-Transfer.tsx +30 -30
- package/src/components/CreditLine/borrow/6-Success.tsx +30 -30
- package/src/components/CreditLine/borrow/index.tsx +119 -119
- package/src/components/CreditLine/payment/1-ChooseAmount.tsx +67 -67
- package/src/components/CreditLine/payment/2-ApproveAllowance.tsx +23 -23
- package/src/components/CreditLine/payment/3-Transfer.tsx +34 -34
- package/src/components/CreditLine/payment/4-Success.tsx +39 -39
- package/src/components/CreditLine/payment/index.tsx +94 -94
- package/src/components/ErrorModal.tsx +132 -132
- package/src/components/Factoring/FactoredList.tsx +143 -143
- package/src/components/Factoring/UpcomingList.tsx +90 -90
- package/src/components/InvoiceFactoring/borrow/1-Evaluation.tsx +52 -46
- package/src/components/InvoiceFactoring/borrow/2-AllowList.tsx +34 -34
- package/src/components/InvoiceFactoring/borrow/3-ChooseAmount.tsx +86 -92
- package/src/components/InvoiceFactoring/borrow/4-ConfirmTransfer.tsx +104 -104
- package/src/components/InvoiceFactoring/borrow/5-ApproveNFT.tsx +55 -55
- package/src/components/InvoiceFactoring/borrow/6-Transfer.tsx +34 -34
- package/src/components/InvoiceFactoring/borrow/7-Success.tsx +3 -3
- package/src/components/InvoiceFactoring/borrow/index.tsx +96 -96
- package/src/components/InvoiceFactoring/payment/1-ChooseAmount.tsx +67 -67
- package/src/components/InvoiceFactoring/payment/2-ApproveAllowance.tsx +23 -23
- package/src/components/InvoiceFactoring/payment/3-Transfer.tsx +34 -34
- package/src/components/InvoiceFactoring/payment/4-Success.tsx +23 -23
- package/src/components/InvoiceFactoring/payment/index.tsx +86 -86
- package/src/components/Lend/supply/1-Evaluation.tsx +86 -86
- package/src/components/Lend/supply/2-ChooseAmount.tsx +70 -70
- package/src/components/Lend/supply/3-ApproveAllowance.tsx +25 -25
- package/src/components/Lend/supply/4-ConfirmTransfer.tsx +104 -104
- package/src/components/Lend/supply/6-Transfer.tsx +32 -32
- package/src/components/Lend/supply/7-Success.tsx +49 -49
- package/src/components/Lend/supply/index.tsx +144 -144
- package/src/components/Lend/withdraw/1-CheckWithdrawble.tsx +73 -73
- package/src/components/Lend/withdraw/2-ChooseAmount.tsx +50 -50
- package/src/components/Lend/withdraw/3-Transfer.tsx +32 -32
- package/src/components/Lend/withdraw/4-Success.tsx +49 -49
- package/src/components/Lend/withdraw/index.tsx +101 -101
- package/src/components/StreamFactoring/borrow/1-Evaluation.tsx +47 -57
- package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +124 -124
- package/src/components/StreamFactoring/borrow/3-ConfirmTransfer.tsx +104 -104
- package/src/components/StreamFactoring/borrow/4-ApproveAllowance.tsx +65 -65
- package/src/components/StreamFactoring/borrow/5-Permit.tsx +144 -144
- package/src/components/StreamFactoring/borrow/6-Transfer.tsx +37 -37
- package/src/components/StreamFactoring/borrow/7-Success.tsx +2 -2
- package/src/components/StreamFactoring/borrow/index.tsx +94 -95
- package/src/components/StreamFactoring/payment/ChooseAmount.tsx +54 -54
- package/src/components/StreamFactoring/payment/Success.tsx +23 -23
- package/src/components/StreamFactoring/payment/Transfer.tsx +34 -34
- package/src/components/StreamFactoring/payment/index.tsx +66 -66
- package/src/components/SuperfluidFactoring/SuperfluidFactoredList.tsx +61 -61
- package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +185 -185
- package/src/components/SuperfluidFactoring/index.tsx +85 -85
- package/src/components/TxDoneModal.tsx +83 -83
- package/src/components/TxSendModal.tsx +59 -59
- package/src/components/ViewOnExplorer.tsx +26 -26
- package/src/components/WidgetWrapper.tsx +74 -74
- package/src/components/humaModal/HumaModal.tsx +68 -68
- package/src/cosmos/SDKTesting.fixture.tsx +557 -515
- package/src/hooks/useEA.ts +72 -70
- package/src/index.tsx +219 -219
- package/src/store/widgets.reducers.ts +120 -120
- package/src/store/widgets.store.ts +55 -55
- package/src/theme/components.ts +1 -1
- package/src/theme/hooks/useGetSizes.ts +0 -3
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
import { useWeb3React } from '@web3-react/core'
|
|
2
|
-
import { BigNumber } from 'ethers'
|
|
3
|
-
import {
|
|
4
|
-
POOL_NAME,
|
|
5
|
-
POOL_TYPE,
|
|
6
|
-
useAccountStats,
|
|
7
|
-
usePoolInfo,
|
|
8
|
-
} from '@huma-finance/shared'
|
|
9
|
-
import React, { useEffect } from 'react'
|
|
10
|
-
import { useDispatch } from 'react-redux'
|
|
11
|
-
|
|
12
|
-
import { useAppSelector } from '../../../hooks/useRedux'
|
|
13
|
-
import { setStep } from '../../../store/widgets.reducers'
|
|
14
|
-
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
15
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
16
|
-
import { ErrorModal } from '../../ErrorModal'
|
|
17
|
-
import { WidgetWrapper } from '../../WidgetWrapper'
|
|
18
|
-
import { Evaluation } from './1-Evaluation'
|
|
19
|
-
import { AllowList } from './2-AllowList'
|
|
20
|
-
import { ChooseAmount } from './3-ChooseAmount'
|
|
21
|
-
import { ConfirmTransfer } from './4-ConfirmTransfer'
|
|
22
|
-
import { ApproveNFT } from './5-ApproveNFT'
|
|
23
|
-
import { Transfer } from './6-Transfer'
|
|
24
|
-
import { Success } from './7-Success'
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Invoice factoring pool borrow props
|
|
28
|
-
* @typedef {Object} InvoiceFactoringBorrowProps
|
|
29
|
-
* @property {POOL_NAME} poolName The name of the pool.
|
|
30
|
-
* @property {POOL_TYPE} poolType The type of the pool.
|
|
31
|
-
* @property {string|BigNumber} tokenId The NFT token id representing invoice.
|
|
32
|
-
* @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
|
|
33
|
-
* @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the invoice pool borrow action is successful.
|
|
34
|
-
*/
|
|
35
|
-
export interface InvoiceFactoringBorrowProps {
|
|
36
|
-
poolName: keyof typeof POOL_NAME
|
|
37
|
-
poolType: keyof typeof POOL_TYPE
|
|
38
|
-
tokenId: string | BigNumber
|
|
39
|
-
handleClose: () => void
|
|
40
|
-
handleSuccess?: (blockNumber?: number) => void
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function InvoiceFactoringBorrow({
|
|
44
|
-
poolName: poolNameStr,
|
|
45
|
-
poolType: poolTypeStr,
|
|
46
|
-
tokenId,
|
|
47
|
-
handleClose,
|
|
48
|
-
handleSuccess,
|
|
49
|
-
}: InvoiceFactoringBorrowProps): React.ReactElement | null {
|
|
50
|
-
const dispatch = useDispatch()
|
|
51
|
-
const { account } = useWeb3React()
|
|
52
|
-
const poolName = POOL_NAME[poolNameStr]
|
|
53
|
-
const poolType = POOL_TYPE[poolTypeStr]
|
|
54
|
-
const poolInfo = usePoolInfo(poolName, poolType)
|
|
55
|
-
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
56
|
-
const [accountStats] = useAccountStats(poolName, poolType, account)
|
|
57
|
-
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
dispatch(setStep(WIDGET_STEP.Evaluation))
|
|
60
|
-
}, [dispatch])
|
|
61
|
-
|
|
62
|
-
if (!poolInfo) {
|
|
63
|
-
return null
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<WidgetWrapper
|
|
68
|
-
isOpen
|
|
69
|
-
handleClose={handleClose}
|
|
70
|
-
handleSuccess={handleSuccess}
|
|
71
|
-
>
|
|
72
|
-
{step === WIDGET_STEP.Evaluation && (
|
|
73
|
-
<Evaluation poolInfo={poolInfo} tokenId={tokenId.toString()} />
|
|
74
|
-
)}
|
|
75
|
-
{step === WIDGET_STEP.AddToAllowList && <AllowList poolInfo={poolInfo} />}
|
|
76
|
-
{step === WIDGET_STEP.ChooseAmount && (
|
|
77
|
-
<ChooseAmount poolInfo={poolInfo} accountStats={accountStats} />
|
|
78
|
-
)}
|
|
79
|
-
{step === WIDGET_STEP.ConfirmTransfer && <ConfirmTransfer />}
|
|
80
|
-
{step === WIDGET_STEP.ApproveNFT && (
|
|
81
|
-
<ApproveNFT poolInfo={poolInfo} tokenId={tokenId.toString()} />
|
|
82
|
-
)}
|
|
83
|
-
{step === WIDGET_STEP.Transfer && (
|
|
84
|
-
<Transfer poolInfo={poolInfo} tokenId={tokenId.toString()} />
|
|
85
|
-
)}
|
|
86
|
-
{step === WIDGET_STEP.Done && <Success handleAction={handleClose} />}
|
|
87
|
-
{step === WIDGET_STEP.Error && (
|
|
88
|
-
<ErrorModal
|
|
89
|
-
title='Invoice Factoring'
|
|
90
|
-
errorMessage={errorMessage}
|
|
91
|
-
handleOk={handleClose}
|
|
92
|
-
/>
|
|
93
|
-
)}
|
|
94
|
-
</WidgetWrapper>
|
|
95
|
-
)
|
|
96
|
-
}
|
|
1
|
+
import { useWeb3React } from '@web3-react/core'
|
|
2
|
+
import { BigNumber } from 'ethers'
|
|
3
|
+
import {
|
|
4
|
+
POOL_NAME,
|
|
5
|
+
POOL_TYPE,
|
|
6
|
+
useAccountStats,
|
|
7
|
+
usePoolInfo,
|
|
8
|
+
} from '@huma-finance/shared'
|
|
9
|
+
import React, { useEffect } from 'react'
|
|
10
|
+
import { useDispatch } from 'react-redux'
|
|
11
|
+
|
|
12
|
+
import { useAppSelector } from '../../../hooks/useRedux'
|
|
13
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
14
|
+
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
15
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
16
|
+
import { ErrorModal } from '../../ErrorModal'
|
|
17
|
+
import { WidgetWrapper } from '../../WidgetWrapper'
|
|
18
|
+
import { Evaluation } from './1-Evaluation'
|
|
19
|
+
import { AllowList } from './2-AllowList'
|
|
20
|
+
import { ChooseAmount } from './3-ChooseAmount'
|
|
21
|
+
import { ConfirmTransfer } from './4-ConfirmTransfer'
|
|
22
|
+
import { ApproveNFT } from './5-ApproveNFT'
|
|
23
|
+
import { Transfer } from './6-Transfer'
|
|
24
|
+
import { Success } from './7-Success'
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Invoice factoring pool borrow props
|
|
28
|
+
* @typedef {Object} InvoiceFactoringBorrowProps
|
|
29
|
+
* @property {POOL_NAME} poolName The name of the pool.
|
|
30
|
+
* @property {POOL_TYPE} poolType The type of the pool.
|
|
31
|
+
* @property {string|BigNumber} tokenId The NFT token id representing invoice.
|
|
32
|
+
* @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
|
|
33
|
+
* @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the invoice pool borrow action is successful.
|
|
34
|
+
*/
|
|
35
|
+
export interface InvoiceFactoringBorrowProps {
|
|
36
|
+
poolName: keyof typeof POOL_NAME
|
|
37
|
+
poolType: keyof typeof POOL_TYPE
|
|
38
|
+
tokenId: string | BigNumber
|
|
39
|
+
handleClose: () => void
|
|
40
|
+
handleSuccess?: (blockNumber?: number) => void
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function InvoiceFactoringBorrow({
|
|
44
|
+
poolName: poolNameStr,
|
|
45
|
+
poolType: poolTypeStr,
|
|
46
|
+
tokenId,
|
|
47
|
+
handleClose,
|
|
48
|
+
handleSuccess,
|
|
49
|
+
}: InvoiceFactoringBorrowProps): React.ReactElement | null {
|
|
50
|
+
const dispatch = useDispatch()
|
|
51
|
+
const { account } = useWeb3React()
|
|
52
|
+
const poolName = POOL_NAME[poolNameStr]
|
|
53
|
+
const poolType = POOL_TYPE[poolTypeStr]
|
|
54
|
+
const poolInfo = usePoolInfo(poolName, poolType)
|
|
55
|
+
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
56
|
+
const [accountStats] = useAccountStats(poolName, poolType, account)
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
dispatch(setStep(WIDGET_STEP.Evaluation))
|
|
60
|
+
}, [dispatch])
|
|
61
|
+
|
|
62
|
+
if (!poolInfo) {
|
|
63
|
+
return null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<WidgetWrapper
|
|
68
|
+
isOpen
|
|
69
|
+
handleClose={handleClose}
|
|
70
|
+
handleSuccess={handleSuccess}
|
|
71
|
+
>
|
|
72
|
+
{step === WIDGET_STEP.Evaluation && (
|
|
73
|
+
<Evaluation poolInfo={poolInfo} tokenId={tokenId.toString()} />
|
|
74
|
+
)}
|
|
75
|
+
{step === WIDGET_STEP.AddToAllowList && <AllowList poolInfo={poolInfo} />}
|
|
76
|
+
{step === WIDGET_STEP.ChooseAmount && (
|
|
77
|
+
<ChooseAmount poolInfo={poolInfo} accountStats={accountStats} />
|
|
78
|
+
)}
|
|
79
|
+
{step === WIDGET_STEP.ConfirmTransfer && <ConfirmTransfer />}
|
|
80
|
+
{step === WIDGET_STEP.ApproveNFT && (
|
|
81
|
+
<ApproveNFT poolInfo={poolInfo} tokenId={tokenId.toString()} />
|
|
82
|
+
)}
|
|
83
|
+
{step === WIDGET_STEP.Transfer && (
|
|
84
|
+
<Transfer poolInfo={poolInfo} tokenId={tokenId.toString()} />
|
|
85
|
+
)}
|
|
86
|
+
{step === WIDGET_STEP.Done && <Success handleAction={handleClose} />}
|
|
87
|
+
{step === WIDGET_STEP.Error && (
|
|
88
|
+
<ErrorModal
|
|
89
|
+
title='Invoice Factoring'
|
|
90
|
+
errorMessage={errorMessage}
|
|
91
|
+
handleOk={handleClose}
|
|
92
|
+
/>
|
|
93
|
+
)}
|
|
94
|
+
</WidgetWrapper>
|
|
95
|
+
)
|
|
96
|
+
}
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import { useWeb3React } from '@web3-react/core'
|
|
2
|
-
import {
|
|
3
|
-
CreditRecordType,
|
|
4
|
-
downScale,
|
|
5
|
-
PoolInfoType,
|
|
6
|
-
toBigNumber,
|
|
7
|
-
upScale,
|
|
8
|
-
useRFPoolAllowance,
|
|
9
|
-
} from '@huma-finance/shared'
|
|
10
|
-
import React, { useCallback, useState } from 'react'
|
|
11
|
-
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
12
|
-
import { setPaymentAmount, setStep } from '../../../store/widgets.reducers'
|
|
13
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
14
|
-
import { ChooseAmountModal } from '../../ChooseAmountModal'
|
|
15
|
-
|
|
16
|
-
type Props = {
|
|
17
|
-
creditRecord: CreditRecordType
|
|
18
|
-
poolInfo: PoolInfoType
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function ChooseAmount({
|
|
22
|
-
creditRecord,
|
|
23
|
-
poolInfo,
|
|
24
|
-
}: Props): React.ReactElement | null {
|
|
25
|
-
const dispatch = useAppDispatch()
|
|
26
|
-
const { account } = useWeb3React()
|
|
27
|
-
const { symbol, decimals } = poolInfo.poolUnderlyingToken
|
|
28
|
-
const totalDue = downScale<number>(creditRecord.totalDue.toNumber(), decimals)
|
|
29
|
-
const { allowance } = useRFPoolAllowance(poolInfo.poolName, account)
|
|
30
|
-
const [remainingDue, setRemainingDue] = useState(totalDue)
|
|
31
|
-
const [currentAmount, setCurrentAmount] = useState(0)
|
|
32
|
-
|
|
33
|
-
const handleChangeAmount = useCallback(
|
|
34
|
-
(newAmount: number) => {
|
|
35
|
-
setCurrentAmount(newAmount)
|
|
36
|
-
const remainDueAmount = totalDue - newAmount
|
|
37
|
-
setRemainingDue(remainDueAmount)
|
|
38
|
-
dispatch(setPaymentAmount({ paymentAmount: newAmount, remainDueAmount }))
|
|
39
|
-
},
|
|
40
|
-
[dispatch, totalDue],
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
const handleAction = useCallback(() => {
|
|
44
|
-
const payAmount = upScale(currentAmount, decimals)
|
|
45
|
-
const nextStep = toBigNumber(payAmount).gt(allowance)
|
|
46
|
-
? WIDGET_STEP.ApproveAllowance
|
|
47
|
-
: WIDGET_STEP.Transfer
|
|
48
|
-
dispatch(setStep(nextStep))
|
|
49
|
-
}, [allowance, currentAmount, decimals, dispatch])
|
|
50
|
-
|
|
51
|
-
return (
|
|
52
|
-
<ChooseAmountModal
|
|
53
|
-
title='Make the payment'
|
|
54
|
-
description1='Choose amount'
|
|
55
|
-
sliderMax={totalDue}
|
|
56
|
-
currentAmount={currentAmount}
|
|
57
|
-
tokenSymbol={symbol}
|
|
58
|
-
topLeft='Total Due'
|
|
59
|
-
topRight={`${totalDue} ${symbol}`}
|
|
60
|
-
downLeft='Remaining Due'
|
|
61
|
-
downRight={`${remainingDue} ${symbol}`}
|
|
62
|
-
handleChangeAmount={handleChangeAmount}
|
|
63
|
-
handleAction={handleAction}
|
|
64
|
-
actionText='make payment'
|
|
65
|
-
/>
|
|
66
|
-
)
|
|
67
|
-
}
|
|
1
|
+
import { useWeb3React } from '@web3-react/core'
|
|
2
|
+
import {
|
|
3
|
+
CreditRecordType,
|
|
4
|
+
downScale,
|
|
5
|
+
PoolInfoType,
|
|
6
|
+
toBigNumber,
|
|
7
|
+
upScale,
|
|
8
|
+
useRFPoolAllowance,
|
|
9
|
+
} from '@huma-finance/shared'
|
|
10
|
+
import React, { useCallback, useState } from 'react'
|
|
11
|
+
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
12
|
+
import { setPaymentAmount, setStep } from '../../../store/widgets.reducers'
|
|
13
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
14
|
+
import { ChooseAmountModal } from '../../ChooseAmountModal'
|
|
15
|
+
|
|
16
|
+
type Props = {
|
|
17
|
+
creditRecord: CreditRecordType
|
|
18
|
+
poolInfo: PoolInfoType
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function ChooseAmount({
|
|
22
|
+
creditRecord,
|
|
23
|
+
poolInfo,
|
|
24
|
+
}: Props): React.ReactElement | null {
|
|
25
|
+
const dispatch = useAppDispatch()
|
|
26
|
+
const { account } = useWeb3React()
|
|
27
|
+
const { symbol, decimals } = poolInfo.poolUnderlyingToken
|
|
28
|
+
const totalDue = downScale<number>(creditRecord.totalDue.toNumber(), decimals)
|
|
29
|
+
const { allowance } = useRFPoolAllowance(poolInfo.poolName, account)
|
|
30
|
+
const [remainingDue, setRemainingDue] = useState(totalDue)
|
|
31
|
+
const [currentAmount, setCurrentAmount] = useState(0)
|
|
32
|
+
|
|
33
|
+
const handleChangeAmount = useCallback(
|
|
34
|
+
(newAmount: number) => {
|
|
35
|
+
setCurrentAmount(newAmount)
|
|
36
|
+
const remainDueAmount = totalDue - newAmount
|
|
37
|
+
setRemainingDue(remainDueAmount)
|
|
38
|
+
dispatch(setPaymentAmount({ paymentAmount: newAmount, remainDueAmount }))
|
|
39
|
+
},
|
|
40
|
+
[dispatch, totalDue],
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
const handleAction = useCallback(() => {
|
|
44
|
+
const payAmount = upScale(currentAmount, decimals)
|
|
45
|
+
const nextStep = toBigNumber(payAmount).gt(allowance)
|
|
46
|
+
? WIDGET_STEP.ApproveAllowance
|
|
47
|
+
: WIDGET_STEP.Transfer
|
|
48
|
+
dispatch(setStep(nextStep))
|
|
49
|
+
}, [allowance, currentAmount, decimals, dispatch])
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<ChooseAmountModal
|
|
53
|
+
title='Make the payment'
|
|
54
|
+
description1='Choose amount'
|
|
55
|
+
sliderMax={totalDue}
|
|
56
|
+
currentAmount={currentAmount}
|
|
57
|
+
tokenSymbol={symbol}
|
|
58
|
+
topLeft='Total Due'
|
|
59
|
+
topRight={`${totalDue} ${symbol}`}
|
|
60
|
+
downLeft='Remaining Due'
|
|
61
|
+
downRight={`${remainingDue} ${symbol}`}
|
|
62
|
+
handleChangeAmount={handleChangeAmount}
|
|
63
|
+
handleAction={handleAction}
|
|
64
|
+
actionText='make payment'
|
|
65
|
+
/>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { PoolInfoType } 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 { ApproveAllowanceModal } from '../../ApproveAllowanceModal'
|
|
8
|
-
|
|
9
|
-
type Props = {
|
|
10
|
-
poolInfo: PoolInfoType
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function ApproveAllowance({ poolInfo }: Props): React.ReactElement {
|
|
14
|
-
const dispatch = useAppDispatch()
|
|
15
|
-
|
|
16
|
-
const handleSuccess = useCallback(() => {
|
|
17
|
-
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
18
|
-
}, [dispatch])
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<ApproveAllowanceModal poolInfo={poolInfo} handleSuccess={handleSuccess} />
|
|
22
|
-
)
|
|
23
|
-
}
|
|
1
|
+
import { PoolInfoType } 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 { ApproveAllowanceModal } from '../../ApproveAllowanceModal'
|
|
8
|
+
|
|
9
|
+
type Props = {
|
|
10
|
+
poolInfo: PoolInfoType
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function ApproveAllowance({ poolInfo }: Props): React.ReactElement {
|
|
14
|
+
const dispatch = useAppDispatch()
|
|
15
|
+
|
|
16
|
+
const handleSuccess = useCallback(() => {
|
|
17
|
+
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
18
|
+
}, [dispatch])
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<ApproveAllowanceModal poolInfo={poolInfo} handleSuccess={handleSuccess} />
|
|
22
|
+
)
|
|
23
|
+
}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { useWeb3React } from '@web3-react/core'
|
|
2
|
-
import { PoolInfoType, toBigNumber, upScale } from '@huma-finance/shared'
|
|
3
|
-
import React, { useCallback } from 'react'
|
|
4
|
-
|
|
5
|
-
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
6
|
-
import { setStep } from '../../../store/widgets.reducers'
|
|
7
|
-
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
8
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
9
|
-
import { TxSendModal } from '../../TxSendModal'
|
|
10
|
-
|
|
11
|
-
type Props = {
|
|
12
|
-
poolInfo: PoolInfoType
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function Transfer({ poolInfo }: Props): React.ReactElement {
|
|
16
|
-
const dispatch = useAppDispatch()
|
|
17
|
-
const { account } = useWeb3React()
|
|
18
|
-
const { decimals } = poolInfo.poolUnderlyingToken
|
|
19
|
-
const { paymentAmount } = useAppSelector(selectWidgetState)
|
|
20
|
-
const paymentBigNumber = toBigNumber(upScale(paymentAmount!, decimals))
|
|
21
|
-
|
|
22
|
-
const handleSuccess = useCallback(() => {
|
|
23
|
-
dispatch(setStep(WIDGET_STEP.Done))
|
|
24
|
-
}, [dispatch])
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<TxSendModal
|
|
28
|
-
poolInfo={poolInfo}
|
|
29
|
-
method='makePayment'
|
|
30
|
-
params={[account, paymentBigNumber]}
|
|
31
|
-
handleSuccess={handleSuccess}
|
|
32
|
-
/>
|
|
33
|
-
)
|
|
34
|
-
}
|
|
1
|
+
import { useWeb3React } from '@web3-react/core'
|
|
2
|
+
import { PoolInfoType, toBigNumber, upScale } from '@huma-finance/shared'
|
|
3
|
+
import React, { useCallback } from 'react'
|
|
4
|
+
|
|
5
|
+
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
6
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
7
|
+
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
8
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
9
|
+
import { TxSendModal } from '../../TxSendModal'
|
|
10
|
+
|
|
11
|
+
type Props = {
|
|
12
|
+
poolInfo: PoolInfoType
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function Transfer({ poolInfo }: Props): React.ReactElement {
|
|
16
|
+
const dispatch = useAppDispatch()
|
|
17
|
+
const { account } = useWeb3React()
|
|
18
|
+
const { decimals } = poolInfo.poolUnderlyingToken
|
|
19
|
+
const { paymentAmount } = useAppSelector(selectWidgetState)
|
|
20
|
+
const paymentBigNumber = toBigNumber(upScale(paymentAmount!, decimals))
|
|
21
|
+
|
|
22
|
+
const handleSuccess = useCallback(() => {
|
|
23
|
+
dispatch(setStep(WIDGET_STEP.Done))
|
|
24
|
+
}, [dispatch])
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<TxSendModal
|
|
28
|
+
poolInfo={poolInfo}
|
|
29
|
+
method='makePayment'
|
|
30
|
+
params={[account, paymentBigNumber]}
|
|
31
|
+
handleSuccess={handleSuccess}
|
|
32
|
+
/>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { PoolInfoType } from '@huma-finance/shared'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
|
|
4
|
-
import { useAppSelector } from '../../../hooks/useRedux'
|
|
5
|
-
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
6
|
-
import { TxDoneModal } from '../../TxDoneModal'
|
|
7
|
-
|
|
8
|
-
type Props = {
|
|
9
|
-
poolInfo: PoolInfoType
|
|
10
|
-
handleAction: () => void
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function Success({ poolInfo, handleAction }: Props): React.ReactElement {
|
|
14
|
-
const { symbol } = poolInfo.poolUnderlyingToken
|
|
15
|
-
const { paymentAmount, remainDueAmount } = useAppSelector(selectWidgetState)
|
|
16
|
-
|
|
17
|
-
const content = [
|
|
18
|
-
`You have successfully made a payment of ${paymentAmount} ${symbol}.`,
|
|
19
|
-
`The remaining due amount is ${remainDueAmount} ${symbol}.`,
|
|
20
|
-
]
|
|
21
|
-
|
|
22
|
-
return <TxDoneModal handleAction={handleAction} content={content} />
|
|
23
|
-
}
|
|
1
|
+
import { PoolInfoType } from '@huma-finance/shared'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import { useAppSelector } from '../../../hooks/useRedux'
|
|
5
|
+
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
6
|
+
import { TxDoneModal } from '../../TxDoneModal'
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
poolInfo: PoolInfoType
|
|
10
|
+
handleAction: () => void
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function Success({ poolInfo, handleAction }: Props): React.ReactElement {
|
|
14
|
+
const { symbol } = poolInfo.poolUnderlyingToken
|
|
15
|
+
const { paymentAmount, remainDueAmount } = useAppSelector(selectWidgetState)
|
|
16
|
+
|
|
17
|
+
const content = [
|
|
18
|
+
`You have successfully made a payment of ${paymentAmount} ${symbol}.`,
|
|
19
|
+
`The remaining due amount is ${remainDueAmount} ${symbol}.`,
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
return <TxDoneModal handleAction={handleAction} content={content} />
|
|
23
|
+
}
|
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
import { useWeb3React } from '@web3-react/core'
|
|
2
|
-
import {
|
|
3
|
-
POOL_NAME,
|
|
4
|
-
POOL_TYPE,
|
|
5
|
-
useAccountStats,
|
|
6
|
-
usePoolInfo,
|
|
7
|
-
} from '@huma-finance/shared'
|
|
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
|
-
* Invoice factoring pool payment props
|
|
24
|
-
* @typedef {Object} InvoiceFactoringPaymentProps
|
|
25
|
-
* @property {POOL_NAME} poolName The name of the pool.
|
|
26
|
-
* @property {POOL_TYPE} poolType The type of the pool.
|
|
27
|
-
* @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
|
|
28
|
-
* @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the invoice pool payment action is successful.
|
|
29
|
-
*/
|
|
30
|
-
export type InvoiceFactoringPaymentProps = {
|
|
31
|
-
poolName: keyof typeof POOL_NAME
|
|
32
|
-
poolType: keyof typeof POOL_TYPE
|
|
33
|
-
handleClose: () => void
|
|
34
|
-
handleSuccess?: (blockNumber?: number) => void
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function InvoiceFactoringPayment({
|
|
38
|
-
poolName: poolNameStr,
|
|
39
|
-
poolType: poolTypeStr,
|
|
40
|
-
handleClose,
|
|
41
|
-
handleSuccess,
|
|
42
|
-
}: InvoiceFactoringPaymentProps): React.ReactElement | null {
|
|
43
|
-
const dispatch = useDispatch()
|
|
44
|
-
const { account } = useWeb3React()
|
|
45
|
-
const poolName = POOL_NAME[poolNameStr]
|
|
46
|
-
const poolType = POOL_TYPE[poolTypeStr]
|
|
47
|
-
const poolInfo = usePoolInfo(poolName, poolType)
|
|
48
|
-
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
49
|
-
const [{ creditRecord }] = useAccountStats(poolName, poolType, account)
|
|
50
|
-
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
dispatch(setStep(WIDGET_STEP.ChooseAmount))
|
|
53
|
-
}, [dispatch])
|
|
54
|
-
|
|
55
|
-
if (!poolInfo) {
|
|
56
|
-
return null
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return (
|
|
60
|
-
<WidgetWrapper
|
|
61
|
-
isOpen
|
|
62
|
-
isLoading={!creditRecord}
|
|
63
|
-
loadingTitle='Make Payment'
|
|
64
|
-
handleClose={handleClose}
|
|
65
|
-
handleSuccess={handleSuccess}
|
|
66
|
-
>
|
|
67
|
-
{step === WIDGET_STEP.ChooseAmount && (
|
|
68
|
-
<ChooseAmount creditRecord={creditRecord!} poolInfo={poolInfo} />
|
|
69
|
-
)}
|
|
70
|
-
{step === WIDGET_STEP.ApproveAllowance && (
|
|
71
|
-
<ApproveAllowance poolInfo={poolInfo} />
|
|
72
|
-
)}
|
|
73
|
-
{step === WIDGET_STEP.Transfer && <Transfer poolInfo={poolInfo} />}
|
|
74
|
-
{step === WIDGET_STEP.Done && (
|
|
75
|
-
<Success poolInfo={poolInfo} handleAction={handleClose} />
|
|
76
|
-
)}
|
|
77
|
-
{step === WIDGET_STEP.Error && (
|
|
78
|
-
<ErrorModal
|
|
79
|
-
title='Make Payment'
|
|
80
|
-
errorMessage={errorMessage}
|
|
81
|
-
handleOk={handleClose}
|
|
82
|
-
/>
|
|
83
|
-
)}
|
|
84
|
-
</WidgetWrapper>
|
|
85
|
-
)
|
|
86
|
-
}
|
|
1
|
+
import { useWeb3React } from '@web3-react/core'
|
|
2
|
+
import {
|
|
3
|
+
POOL_NAME,
|
|
4
|
+
POOL_TYPE,
|
|
5
|
+
useAccountStats,
|
|
6
|
+
usePoolInfo,
|
|
7
|
+
} from '@huma-finance/shared'
|
|
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
|
+
* Invoice factoring pool payment props
|
|
24
|
+
* @typedef {Object} InvoiceFactoringPaymentProps
|
|
25
|
+
* @property {POOL_NAME} poolName The name of the pool.
|
|
26
|
+
* @property {POOL_TYPE} poolType The type of the pool.
|
|
27
|
+
* @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
|
|
28
|
+
* @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the invoice pool payment action is successful.
|
|
29
|
+
*/
|
|
30
|
+
export type InvoiceFactoringPaymentProps = {
|
|
31
|
+
poolName: keyof typeof POOL_NAME
|
|
32
|
+
poolType: keyof typeof POOL_TYPE
|
|
33
|
+
handleClose: () => void
|
|
34
|
+
handleSuccess?: (blockNumber?: number) => void
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function InvoiceFactoringPayment({
|
|
38
|
+
poolName: poolNameStr,
|
|
39
|
+
poolType: poolTypeStr,
|
|
40
|
+
handleClose,
|
|
41
|
+
handleSuccess,
|
|
42
|
+
}: InvoiceFactoringPaymentProps): React.ReactElement | null {
|
|
43
|
+
const dispatch = useDispatch()
|
|
44
|
+
const { account } = useWeb3React()
|
|
45
|
+
const poolName = POOL_NAME[poolNameStr]
|
|
46
|
+
const poolType = POOL_TYPE[poolTypeStr]
|
|
47
|
+
const poolInfo = usePoolInfo(poolName, poolType)
|
|
48
|
+
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
49
|
+
const [{ creditRecord }] = useAccountStats(poolName, poolType, account)
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
dispatch(setStep(WIDGET_STEP.ChooseAmount))
|
|
53
|
+
}, [dispatch])
|
|
54
|
+
|
|
55
|
+
if (!poolInfo) {
|
|
56
|
+
return null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<WidgetWrapper
|
|
61
|
+
isOpen
|
|
62
|
+
isLoading={!creditRecord}
|
|
63
|
+
loadingTitle='Make Payment'
|
|
64
|
+
handleClose={handleClose}
|
|
65
|
+
handleSuccess={handleSuccess}
|
|
66
|
+
>
|
|
67
|
+
{step === WIDGET_STEP.ChooseAmount && (
|
|
68
|
+
<ChooseAmount creditRecord={creditRecord!} poolInfo={poolInfo} />
|
|
69
|
+
)}
|
|
70
|
+
{step === WIDGET_STEP.ApproveAllowance && (
|
|
71
|
+
<ApproveAllowance poolInfo={poolInfo} />
|
|
72
|
+
)}
|
|
73
|
+
{step === WIDGET_STEP.Transfer && <Transfer poolInfo={poolInfo} />}
|
|
74
|
+
{step === WIDGET_STEP.Done && (
|
|
75
|
+
<Success poolInfo={poolInfo} handleAction={handleClose} />
|
|
76
|
+
)}
|
|
77
|
+
{step === WIDGET_STEP.Error && (
|
|
78
|
+
<ErrorModal
|
|
79
|
+
title='Make Payment'
|
|
80
|
+
errorMessage={errorMessage}
|
|
81
|
+
handleOk={handleClose}
|
|
82
|
+
/>
|
|
83
|
+
)}
|
|
84
|
+
</WidgetWrapper>
|
|
85
|
+
)
|
|
86
|
+
}
|