@huma-finance/widgets 0.0.48-beta.187 → 0.0.48-beta.189
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 +0 -18
- package/dist/cjs/index.cjs +5488 -5814
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -33
- package/dist/index.js +5490 -5815
- package/dist/index.js.map +1 -1
- package/package.json +4 -7
- package/src/components/ApproveAllowanceModal.tsx +7 -0
- package/src/components/Lend/withdraw/2-ChooseAmount.tsx +7 -1
- package/src/components/Lend/withdraw/index.tsx +11 -4
- package/src/components/StreamFactoring/borrow/1-Evaluation.tsx +4 -3
- package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +21 -15
- package/src/components/StreamFactoring/borrow/3-ConfirmTransfer.tsx +3 -8
- package/src/components/StreamFactoring/borrow/5-Permit.tsx +2 -35
- package/src/components/StreamFactoring/borrow/index.tsx +2 -3
- package/src/components/SuperfluidFactoring/SuperfluidFactoredList.tsx +2 -2
- package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +3 -1
- package/src/index.tsx +11 -33
- package/src/components/RequestNetworkInvoiceFactoring/1-Evaluation.tsx +0 -58
- package/src/components/RequestNetworkInvoiceFactoring/2-ChooseAmount.tsx +0 -88
- package/src/components/RequestNetworkInvoiceFactoring/3-ConfirmTransfer.tsx +0 -37
- package/src/components/RequestNetworkInvoiceFactoring/4-ApproveNFT.tsx +0 -55
- package/src/components/RequestNetworkInvoiceFactoring/5-Transfer.tsx +0 -34
- package/src/components/RequestNetworkInvoiceFactoring/6-Success.tsx +0 -20
- package/src/components/RequestNetworkInvoiceFactoring/index.tsx +0 -137
- package/src/cosmos/RequestNetworkBorrow.fixture.tsx +0 -65
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huma-finance/widgets",
|
|
3
|
-
"version": "0.0.48-beta.
|
|
3
|
+
"version": "0.0.48-beta.189+347bf1c",
|
|
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.48-beta.189+347bf1c",
|
|
34
|
+
"@huma-finance/shared": "^0.0.48-beta.189+347bf1c",
|
|
35
35
|
"@mui/icons-material": "^5.3.0",
|
|
36
36
|
"@mui/material": "^5.0.6",
|
|
37
37
|
"@mui/styles": "^5.0.2",
|
|
@@ -39,8 +39,6 @@
|
|
|
39
39
|
"@mui/x-date-pickers": "^5.0.7",
|
|
40
40
|
"@notifi-network/notifi-frontend-client": "^0.75.1",
|
|
41
41
|
"@reduxjs/toolkit": "^1.8.6",
|
|
42
|
-
"@requestnetwork/payment-processor": "0.38.1-next.1918",
|
|
43
|
-
"@requestnetwork/request-client.js": "0.40.1-next.1918",
|
|
44
42
|
"@types/utf8": "^3.0.1",
|
|
45
43
|
"@walletconnect/ethereum-provider": "1.8.0",
|
|
46
44
|
"@walletconnect/jsonrpc-http-connection": "^1.0.3",
|
|
@@ -121,7 +119,6 @@
|
|
|
121
119
|
"@babel/preset-react": "^7.14.5",
|
|
122
120
|
"@emotion/babel-plugin": "^11.10.2",
|
|
123
121
|
"@emotion/babel-preset-css-prop": "^11.2.0",
|
|
124
|
-
"@requestnetwork/types": "^0.36.0",
|
|
125
122
|
"@rollup/plugin-babel": "^6.0.3",
|
|
126
123
|
"@rollup/plugin-commonjs": "^24.0.1",
|
|
127
124
|
"@rollup/plugin-image": "^3.0.2",
|
|
@@ -195,5 +192,5 @@
|
|
|
195
192
|
"optionalDependencies": {
|
|
196
193
|
"encoding": "^0.1.13"
|
|
197
194
|
},
|
|
198
|
-
"gitHead": "
|
|
195
|
+
"gitHead": "347bf1c48c9d6a68b97d6f470c2cc7db26262769"
|
|
199
196
|
}
|
|
@@ -85,6 +85,12 @@ export function ApproveAllowanceModal({
|
|
|
85
85
|
const amountToIncrease = BigNumber.from(targetAllowanceAmount).sub(
|
|
86
86
|
currentAllowance ?? 0,
|
|
87
87
|
)
|
|
88
|
+
|
|
89
|
+
if (amountToIncrease.lte(0)) {
|
|
90
|
+
handleSuccess()
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
|
|
88
94
|
send({
|
|
89
95
|
contract: poolUnderlyingTokenContract!,
|
|
90
96
|
method: 'increaseAllowance',
|
|
@@ -94,6 +100,7 @@ export function ApproveAllowanceModal({
|
|
|
94
100
|
}, [
|
|
95
101
|
account,
|
|
96
102
|
allowanceAmount,
|
|
103
|
+
handleSuccess,
|
|
97
104
|
poolInfo.pool,
|
|
98
105
|
poolUnderlyingTokenContract,
|
|
99
106
|
provider,
|
|
@@ -9,18 +9,24 @@ import { ChooseAmountModal } from '../../ChooseAmountModal'
|
|
|
9
9
|
|
|
10
10
|
type Props = {
|
|
11
11
|
lenderPosition: BigNumber
|
|
12
|
+
poolBalance: BigNumber
|
|
12
13
|
poolInfo: PoolInfoType
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export function ChooseAmount({
|
|
16
17
|
lenderPosition,
|
|
18
|
+
poolBalance,
|
|
17
19
|
poolInfo,
|
|
18
20
|
}: Props): React.ReactElement | null {
|
|
19
21
|
const dispatch = useAppDispatch()
|
|
20
22
|
const { poolUnderlyingToken } = poolInfo
|
|
21
23
|
const { symbol, decimals } = poolUnderlyingToken
|
|
22
24
|
const [currentAmount, setCurrentAmount] = useState(0)
|
|
23
|
-
|
|
25
|
+
// Take the minimum of the pool balance or the lender position
|
|
26
|
+
const withdrawableAmountBN = lenderPosition.lt(poolBalance)
|
|
27
|
+
? lenderPosition
|
|
28
|
+
: poolBalance
|
|
29
|
+
const withdrawableAmount = downScale<number>(withdrawableAmountBN, decimals)
|
|
24
30
|
|
|
25
31
|
const handleChangeAmount = useCallback(
|
|
26
32
|
(newAmount: number) => {
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
POOL_NAME,
|
|
4
4
|
POOL_TYPE,
|
|
5
5
|
useLenderPosition,
|
|
6
|
+
usePoolBalance,
|
|
6
7
|
usePoolInfo,
|
|
7
8
|
} from '@huma-finance/shared'
|
|
8
9
|
import React, { useCallback, useEffect } from 'react'
|
|
@@ -51,21 +52,23 @@ export function LendWithdraw({
|
|
|
51
52
|
poolType,
|
|
52
53
|
account,
|
|
53
54
|
)
|
|
55
|
+
const [poolBalance, refreshPoolBalance] = usePoolBalance(poolName, poolType)
|
|
54
56
|
|
|
55
57
|
useEffect(() => {
|
|
56
|
-
if (!step && lenderPosition) {
|
|
58
|
+
if (!step && lenderPosition && poolBalance) {
|
|
57
59
|
dispatch(setStep(WIDGET_STEP.CheckWithdrawable))
|
|
58
60
|
}
|
|
59
|
-
}, [dispatch, lenderPosition, step])
|
|
61
|
+
}, [dispatch, lenderPosition, poolBalance, step])
|
|
60
62
|
|
|
61
63
|
const handleWithdrawSuccess = useCallback(
|
|
62
64
|
(blockNumber: number) => {
|
|
63
65
|
refreshLenderPosition()
|
|
66
|
+
refreshPoolBalance()
|
|
64
67
|
if (handleSuccess) {
|
|
65
68
|
handleSuccess(blockNumber)
|
|
66
69
|
}
|
|
67
70
|
},
|
|
68
|
-
[handleSuccess, refreshLenderPosition],
|
|
71
|
+
[handleSuccess, refreshLenderPosition, refreshPoolBalance],
|
|
69
72
|
)
|
|
70
73
|
|
|
71
74
|
if (!poolInfo) {
|
|
@@ -82,7 +85,11 @@ export function LendWithdraw({
|
|
|
82
85
|
<CheckWithdrawable poolInfo={poolInfo} handleClose={handleClose} />
|
|
83
86
|
)}
|
|
84
87
|
{step === WIDGET_STEP.ChooseAmount && (
|
|
85
|
-
<ChooseAmount
|
|
88
|
+
<ChooseAmount
|
|
89
|
+
poolInfo={poolInfo}
|
|
90
|
+
lenderPosition={lenderPosition!}
|
|
91
|
+
poolBalance={poolBalance!}
|
|
92
|
+
/>
|
|
86
93
|
)}
|
|
87
94
|
{step === WIDGET_STEP.Transfer && <Transfer poolInfo={poolInfo} />}
|
|
88
95
|
{step === WIDGET_STEP.Done && (
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getAddress } from '@ethersproject/address'
|
|
2
2
|
import { PoolInfoType } from '@huma-finance/shared'
|
|
3
|
+
import { useWeb3React } from '@web3-react/core'
|
|
3
4
|
import React, { useEffect } from 'react'
|
|
4
5
|
|
|
5
6
|
import useEA from '../../../hooks/useEA'
|
|
6
|
-
import { LoadingModal } from '../../LoadingModal'
|
|
7
7
|
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
8
|
+
import { LoadingModal } from '../../LoadingModal'
|
|
8
9
|
import { SignIn } from '../../SignIn'
|
|
9
10
|
|
|
10
11
|
type Props = {
|
|
@@ -35,7 +36,7 @@ export function Evaluation({
|
|
|
35
36
|
receivable: {
|
|
36
37
|
address: poolInfo.assetAddress!,
|
|
37
38
|
},
|
|
38
|
-
payerWalletAddress: payerAddress,
|
|
39
|
+
payerWalletAddress: getAddress(payerAddress),
|
|
39
40
|
superToken,
|
|
40
41
|
},
|
|
41
42
|
},
|
|
@@ -28,20 +28,24 @@ export function ChooseAmount({
|
|
|
28
28
|
const [chargedFees, setChargedFees] = useState(0)
|
|
29
29
|
const [currentAmount, setCurrentAmount] = useState(0)
|
|
30
30
|
const borrowPeriodInSeconds = approval!.terms.intervalInDays * 24 * 60 * 60
|
|
31
|
+
const superTokenDecimals = poolInfo.extra?.superToken?.decimals!
|
|
32
|
+
const underlyingTokenDecimals = poolInfo.poolUnderlyingToken.decimals!
|
|
33
|
+
// To ensure not to borrow all the available flowrate due to contract limitation
|
|
34
|
+
const borrowMaxAmount = Number(approval!.terms.creditLimitFormatted) - 0.01
|
|
31
35
|
|
|
32
36
|
const getBorrowFlowrateAndAmount = useCallback(
|
|
33
37
|
(borrowAmount: number) => {
|
|
34
38
|
const currentFlowRateBN = toBigNumber(currentFlowRate)
|
|
35
|
-
const
|
|
36
|
-
upScale(borrowAmount,
|
|
39
|
+
const borrowAmountSuperTokenBN = toBigNumber(
|
|
40
|
+
upScale(borrowAmount, superTokenDecimals),
|
|
37
41
|
)
|
|
38
42
|
|
|
39
|
-
const
|
|
43
|
+
const totalAmountSuperTokenInBorrowPeriod = currentFlowRateBN.mul(
|
|
40
44
|
borrowPeriodInSeconds,
|
|
41
45
|
)
|
|
42
|
-
let borrowFlowrate =
|
|
46
|
+
let borrowFlowrate = borrowAmountSuperTokenBN
|
|
43
47
|
.mul(currentFlowRateBN)
|
|
44
|
-
.div(
|
|
48
|
+
.div(totalAmountSuperTokenInBorrowPeriod)
|
|
45
49
|
// To ensure enough flowRate due to round down when convert to string
|
|
46
50
|
.add(1)
|
|
47
51
|
|
|
@@ -49,26 +53,28 @@ export function ChooseAmount({
|
|
|
49
53
|
if (borrowFlowrate.gte(currentFlowRateBN)) {
|
|
50
54
|
borrowFlowrate = currentFlowRateBN.sub(1)
|
|
51
55
|
}
|
|
52
|
-
if (borrowAmountBN.gte(approval!.terms.creditLimit)) {
|
|
53
|
-
borrowFlowrate = borrowFlowrate.sub(1)
|
|
54
|
-
}
|
|
55
56
|
|
|
56
57
|
// As borrowFlowrate adds 1, need to calculate the new accurate borrow amount
|
|
57
58
|
const newBorrowAmountBN = borrowFlowrate
|
|
58
|
-
.mul(
|
|
59
|
+
.mul(totalAmountSuperTokenInBorrowPeriod)
|
|
59
60
|
.div(currentFlowRateBN)
|
|
60
|
-
const newBorrowAmount = downScale(
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
const newBorrowAmount = downScale(newBorrowAmountBN, superTokenDecimals)
|
|
62
|
+
const newBorrowAmountUnderlyingTokenBN = toBigNumber(
|
|
63
|
+
upScale(newBorrowAmount, underlyingTokenDecimals),
|
|
63
64
|
)
|
|
64
65
|
|
|
65
66
|
return {
|
|
66
67
|
borrowFlowrate: borrowFlowrate.toString(),
|
|
67
68
|
borrowAmount: Number(newBorrowAmount),
|
|
68
|
-
borrowAmountBN:
|
|
69
|
+
borrowAmountBN: newBorrowAmountUnderlyingTokenBN,
|
|
69
70
|
}
|
|
70
71
|
},
|
|
71
|
-
[
|
|
72
|
+
[
|
|
73
|
+
borrowPeriodInSeconds,
|
|
74
|
+
currentFlowRate,
|
|
75
|
+
superTokenDecimals,
|
|
76
|
+
underlyingTokenDecimals,
|
|
77
|
+
],
|
|
72
78
|
)
|
|
73
79
|
|
|
74
80
|
const handleChangeAmount = useCallback(
|
|
@@ -114,7 +120,7 @@ export function ChooseAmount({
|
|
|
114
120
|
<ChooseAmountModal
|
|
115
121
|
title='Choose Amount'
|
|
116
122
|
description1='Access up to 100% of your stream flowrate'
|
|
117
|
-
sliderMax={
|
|
123
|
+
sliderMax={borrowMaxAmount}
|
|
118
124
|
currentAmount={currentAmount}
|
|
119
125
|
tokenSymbol={approval.token.symbol}
|
|
120
126
|
topLeft='Fees'
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useWeb3React } from '@web3-react/core'
|
|
1
|
+
import { isEmpty } from '@huma-finance/shared'
|
|
3
2
|
import React, { useCallback } from 'react'
|
|
4
3
|
|
|
5
4
|
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
@@ -10,15 +9,11 @@ import { ConfirmTransferModal } from '../../ConfirmTransferModal'
|
|
|
10
9
|
|
|
11
10
|
export function ConfirmTransfer(): React.ReactElement | null {
|
|
12
11
|
const dispatch = useAppDispatch()
|
|
13
|
-
const { chainId } = useWeb3React()
|
|
14
12
|
const { borrowAmount, approval } = useAppSelector(selectWidgetState)
|
|
15
13
|
|
|
16
14
|
const handleAction = useCallback(() => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
: WIDGET_STEP.Permit
|
|
20
|
-
dispatch(setStep(step))
|
|
21
|
-
}, [chainId, dispatch])
|
|
15
|
+
dispatch(setStep(WIDGET_STEP.ApproveAllowance))
|
|
16
|
+
}, [dispatch])
|
|
22
17
|
|
|
23
18
|
if (isEmpty(borrowAmount) || isEmpty(approval)) {
|
|
24
19
|
return null
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
CHAINS,
|
|
3
|
-
Erc2612,
|
|
4
2
|
PoolInfoType,
|
|
5
3
|
SuperfluidPoolProcessor,
|
|
4
|
+
SuperfluidPoolProcessor_ABI,
|
|
6
5
|
useERC2612Permit,
|
|
7
6
|
useMount,
|
|
8
|
-
ERC2612_ABI,
|
|
9
|
-
SuperfluidPoolProcessor_ABI,
|
|
10
7
|
} from '@huma-finance/shared'
|
|
11
8
|
import { BigNumber, Contract, ethers } from 'ethers'
|
|
12
9
|
import React from 'react'
|
|
@@ -25,7 +22,6 @@ import { LoadingModal } from '../../LoadingModal'
|
|
|
25
22
|
type Props = {
|
|
26
23
|
poolInfo: PoolInfoType
|
|
27
24
|
payerAddress: string
|
|
28
|
-
chainId: number
|
|
29
25
|
borrower: string
|
|
30
26
|
superToken: string
|
|
31
27
|
}
|
|
@@ -33,36 +29,15 @@ type Props = {
|
|
|
33
29
|
export function Permit({
|
|
34
30
|
poolInfo,
|
|
35
31
|
payerAddress,
|
|
36
|
-
chainId,
|
|
37
32
|
borrower,
|
|
38
33
|
superToken,
|
|
39
34
|
}: Props): React.ReactElement | null {
|
|
40
35
|
const dispatch = useDispatch()
|
|
41
|
-
const { address: tokenAddress } = poolInfo.poolUnderlyingToken
|
|
42
36
|
const { borrowAmountBN: borrowAmountBNJson, stream } =
|
|
43
37
|
useAppSelector(selectWidgetState)
|
|
44
|
-
const {
|
|
45
|
-
useERC2612Permit()
|
|
38
|
+
const { getTradableStreamPermitMessage } = useERC2612Permit()
|
|
46
39
|
const borrowAmountBN = BigNumber.from(borrowAmountBNJson)
|
|
47
40
|
|
|
48
|
-
const getApproveAllowanceCallData = async () => {
|
|
49
|
-
const erc2612PermitResult = await getERC2612PermitMessage(
|
|
50
|
-
tokenAddress,
|
|
51
|
-
poolInfo.poolProcessor!,
|
|
52
|
-
borrowAmountBN.toString()!,
|
|
53
|
-
)
|
|
54
|
-
const tokenContract = new Contract(tokenAddress, ERC2612_ABI) as Erc2612
|
|
55
|
-
return tokenContract.interface.encodeFunctionData('permit', [
|
|
56
|
-
poolInfo.poolProcessor!,
|
|
57
|
-
borrowAmountBN.toString()!,
|
|
58
|
-
erc2612PermitResult.nonce,
|
|
59
|
-
erc2612PermitResult.deadline,
|
|
60
|
-
erc2612PermitResult.v,
|
|
61
|
-
erc2612PermitResult.r,
|
|
62
|
-
erc2612PermitResult.s,
|
|
63
|
-
])
|
|
64
|
-
}
|
|
65
|
-
|
|
66
41
|
const getDrawdownCallData = async () => {
|
|
67
42
|
const NFTPermitResult = await getTradableStreamPermitMessage(
|
|
68
43
|
poolInfo.assetAddress!,
|
|
@@ -113,14 +88,6 @@ export function Permit({
|
|
|
113
88
|
try {
|
|
114
89
|
const callData = []
|
|
115
90
|
const addresses: string[] = []
|
|
116
|
-
|
|
117
|
-
// The token in Goerli hasn't integrated ERC-2612
|
|
118
|
-
if (!CHAINS[chainId].isTestnet) {
|
|
119
|
-
const approveAllowanceCallData = await getApproveAllowanceCallData()
|
|
120
|
-
addresses.push(tokenAddress)
|
|
121
|
-
callData.push(approveAllowanceCallData)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
91
|
const drawdownCalldata = await getDrawdownCallData()
|
|
125
92
|
addresses.push(poolInfo.poolProcessor!)
|
|
126
93
|
callData.push(drawdownCalldata)
|
|
@@ -39,7 +39,7 @@ export function StreamFactoringBorrow({
|
|
|
39
39
|
handleSuccess,
|
|
40
40
|
}: StreamFactoringBorrowProps): React.ReactElement | null {
|
|
41
41
|
const dispatch = useDispatch()
|
|
42
|
-
const { account
|
|
42
|
+
const { account } = useWeb3React()
|
|
43
43
|
const poolInfo = usePoolInfo(poolName, poolType)
|
|
44
44
|
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
45
45
|
|
|
@@ -71,11 +71,10 @@ export function StreamFactoringBorrow({
|
|
|
71
71
|
{step === WIDGET_STEP.ApproveAllowance && (
|
|
72
72
|
<ApproveAllowance poolInfo={poolInfo} />
|
|
73
73
|
)}
|
|
74
|
-
{step === WIDGET_STEP.Permit && account &&
|
|
74
|
+
{step === WIDGET_STEP.Permit && account && (
|
|
75
75
|
<Permit
|
|
76
76
|
poolInfo={poolInfo}
|
|
77
77
|
payerAddress={payerAddress}
|
|
78
|
-
chainId={chainId}
|
|
79
78
|
borrower={account}
|
|
80
79
|
superToken={superToken}
|
|
81
80
|
/>
|
|
@@ -50,9 +50,9 @@ export function SuperfluidFactoredList({
|
|
|
50
50
|
const setItem = useCallback(
|
|
51
51
|
() =>
|
|
52
52
|
Promise.resolve({
|
|
53
|
-
name: poolInfo?.extra?.
|
|
53
|
+
name: poolInfo?.extra?.superToken?.symbol ?? '',
|
|
54
54
|
}),
|
|
55
|
-
[poolInfo?.extra?.
|
|
55
|
+
[poolInfo?.extra?.superToken],
|
|
56
56
|
)
|
|
57
57
|
|
|
58
58
|
return (
|
|
@@ -106,7 +106,9 @@ export function SuperfluidUpcomingList({
|
|
|
106
106
|
const { data } = useQuery<{ streams: Stream[] }>(GET_RECEIVED_STREAMS, {
|
|
107
107
|
variables: {
|
|
108
108
|
receiver: account ? account.toLowerCase() : undefined,
|
|
109
|
-
tokenIds: poolInfo?.extra?.
|
|
109
|
+
tokenIds: poolInfo?.extra?.superToken
|
|
110
|
+
? [poolInfo.extra.superToken.id]
|
|
111
|
+
: [],
|
|
110
112
|
},
|
|
111
113
|
})
|
|
112
114
|
|
package/src/index.tsx
CHANGED
|
@@ -10,6 +10,7 @@ import { Provider as Eip1193Provider } from '@web3-react/types'
|
|
|
10
10
|
import { Provider as AtomProvider } from 'jotai'
|
|
11
11
|
import { Provider as ReduxProvider } from 'react-redux'
|
|
12
12
|
|
|
13
|
+
import { useEffect, useState } from 'react'
|
|
13
14
|
import { ChainSupportProvider } from './components/ChainSupportProvider'
|
|
14
15
|
import {
|
|
15
16
|
CreditLineApprove,
|
|
@@ -37,10 +38,6 @@ import { SuperfluidFactoring } from './components/SuperfluidFactoring'
|
|
|
37
38
|
import { store } from './store'
|
|
38
39
|
import { themeHuma } from './theme'
|
|
39
40
|
import { WCProps } from './utilTypes'
|
|
40
|
-
import {
|
|
41
|
-
RequestNetworkInvoiceFactoringBorrow,
|
|
42
|
-
RequestNetworkInvoiceFactoringBorrowProps,
|
|
43
|
-
} from './components/RequestNetworkInvoiceFactoring'
|
|
44
41
|
|
|
45
42
|
/**
|
|
46
43
|
* Mapping of your JSON-RPC connections indexed by chainId
|
|
@@ -67,11 +64,17 @@ type WidgetProps = {
|
|
|
67
64
|
|
|
68
65
|
function Widget(props: WCProps<WidgetProps>) {
|
|
69
66
|
const { children, provider } = props
|
|
67
|
+
const [chainId, setChainId] = useState<number | undefined>(undefined)
|
|
70
68
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
const getChainId = async () => {
|
|
71
|
+
if (provider instanceof JsonRpcProvider) {
|
|
72
|
+
const network = await provider.getNetwork()
|
|
73
|
+
setChainId(network?.chainId)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
getChainId()
|
|
77
|
+
}, [provider])
|
|
75
78
|
|
|
76
79
|
return (
|
|
77
80
|
<ThemeProvider theme={themeHuma}>
|
|
@@ -86,31 +89,6 @@ function Widget(props: WCProps<WidgetProps>) {
|
|
|
86
89
|
)
|
|
87
90
|
}
|
|
88
91
|
|
|
89
|
-
/**
|
|
90
|
-
* Invoice factoring pool borrow widget props
|
|
91
|
-
* @typedef {Object} RequestNetworkInvoiceFactoringBorrowWidgetProps
|
|
92
|
-
* @property {RequestNetworkInvoiceFactoringBorrowProps} RequestNetworkInvoiceFactoringBorrowProps - Invoice factoring pool borrow props.
|
|
93
|
-
* @property {WidgetProps} WidgetProps - Widget general props.
|
|
94
|
-
*/
|
|
95
|
-
type RequestNetworkInvoiceFactoringBorrowWidgetProps =
|
|
96
|
-
RequestNetworkInvoiceFactoringBorrowProps & WidgetProps
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Invoice factoring borrow widget
|
|
100
|
-
*
|
|
101
|
-
* @param {RequestNetworkInvoiceFactoringBorrowWidgetProps} props - The invoice factoring pool borrow widget props.
|
|
102
|
-
* @returns Invoice factoring pool borrow widget component
|
|
103
|
-
*/
|
|
104
|
-
export function RequestNetworkInvoiceFactoringBorrowWidget(
|
|
105
|
-
props: RequestNetworkInvoiceFactoringBorrowWidgetProps,
|
|
106
|
-
) {
|
|
107
|
-
return (
|
|
108
|
-
<Widget {...props}>
|
|
109
|
-
<RequestNetworkInvoiceFactoringBorrow {...props} />
|
|
110
|
-
</Widget>
|
|
111
|
-
)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
92
|
/**
|
|
115
93
|
* Invoice factoring pool borrow widget props
|
|
116
94
|
* @typedef {Object} InvoiceFactoringBorrowWidgetProps
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { useWeb3React } from '@web3-react/core'
|
|
2
|
-
import { PoolInfoType, toBigNumber } from '@huma-finance/shared'
|
|
3
|
-
import React, { useEffect } from 'react'
|
|
4
|
-
|
|
5
|
-
import useEA from '../../hooks/useEA'
|
|
6
|
-
import { LoadingModal } from '../LoadingModal'
|
|
7
|
-
import { WIDGET_STEP } from '../../store/widgets.store'
|
|
8
|
-
import { SignIn } from '../SignIn'
|
|
9
|
-
|
|
10
|
-
type Props = {
|
|
11
|
-
poolInfo: PoolInfoType
|
|
12
|
-
tokenId: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function Evaluation({ poolInfo, tokenId }: Props): React.ReactElement {
|
|
16
|
-
const {
|
|
17
|
-
checkingEA,
|
|
18
|
-
isWalletOwnershipVerificationRequired,
|
|
19
|
-
isWalletOwnershipVerified,
|
|
20
|
-
} = useEA()
|
|
21
|
-
const { account, chainId } = useWeb3React()
|
|
22
|
-
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
if (account && chainId) {
|
|
25
|
-
checkingEA(
|
|
26
|
-
{
|
|
27
|
-
poolAddress: poolInfo.pool,
|
|
28
|
-
borrowerWalletAddress: account,
|
|
29
|
-
context: {
|
|
30
|
-
receivable: {
|
|
31
|
-
address: poolInfo.assetAddress!,
|
|
32
|
-
param: toBigNumber(tokenId).toHexString(),
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
WIDGET_STEP.ChooseAmount,
|
|
37
|
-
)
|
|
38
|
-
}
|
|
39
|
-
}, [
|
|
40
|
-
account,
|
|
41
|
-
chainId,
|
|
42
|
-
checkingEA,
|
|
43
|
-
poolInfo.assetAddress,
|
|
44
|
-
poolInfo.pool,
|
|
45
|
-
tokenId,
|
|
46
|
-
isWalletOwnershipVerified,
|
|
47
|
-
])
|
|
48
|
-
|
|
49
|
-
if (isWalletOwnershipVerificationRequired) {
|
|
50
|
-
return <SignIn />
|
|
51
|
-
}
|
|
52
|
-
return (
|
|
53
|
-
<LoadingModal
|
|
54
|
-
title='Checking Invoice'
|
|
55
|
-
description='Checking if the invoice qualifies for factoring...'
|
|
56
|
-
/>
|
|
57
|
-
)
|
|
58
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AccountStats,
|
|
3
|
-
PoolInfoType,
|
|
4
|
-
upScale,
|
|
5
|
-
useFeeManager,
|
|
6
|
-
} from '@huma-finance/shared'
|
|
7
|
-
import React, { useCallback, useState } from 'react'
|
|
8
|
-
|
|
9
|
-
import { useAppDispatch, useAppSelector } from '../../hooks/useRedux'
|
|
10
|
-
import { setBorrowInfo } from '../../store/widgets.reducers'
|
|
11
|
-
import { selectWidgetState } from '../../store/widgets.selectors'
|
|
12
|
-
import { WIDGET_STEP } from '../../store/widgets.store'
|
|
13
|
-
import { ChooseAmountModal } from '../ChooseAmountModal'
|
|
14
|
-
|
|
15
|
-
type Props = {
|
|
16
|
-
poolInfo: PoolInfoType
|
|
17
|
-
accountStats: AccountStats
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function ChooseAmount({
|
|
21
|
-
poolInfo,
|
|
22
|
-
accountStats,
|
|
23
|
-
}: Props): React.ReactElement | null {
|
|
24
|
-
const dispatch = useAppDispatch()
|
|
25
|
-
const { creditRecord } = accountStats
|
|
26
|
-
const [chargedFees, setChargedFees] = useState(0)
|
|
27
|
-
const [currentAmount, setCurrentAmount] = useState(0)
|
|
28
|
-
const { approval } = useAppSelector(selectWidgetState)
|
|
29
|
-
const { getFeesCharged } = useFeeManager(poolInfo.poolName, poolInfo.poolType)
|
|
30
|
-
const [remainder, setRemainder] = useState<string | number | undefined>(
|
|
31
|
-
approval!.receivable?.amountFormatted,
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
const getAvailableCreditLimit = () => {
|
|
35
|
-
if (approval && creditRecord) {
|
|
36
|
-
const principal = creditRecord.unbilledPrincipal
|
|
37
|
-
.add(creditRecord.totalDue)
|
|
38
|
-
.sub(creditRecord.feesAndInterestDue)
|
|
39
|
-
.toNumber()
|
|
40
|
-
return Number(approval.terms.creditLimitFormatted) - principal
|
|
41
|
-
}
|
|
42
|
-
return 0
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const handleChangeAmount = useCallback(
|
|
46
|
-
(newAmount: number) => {
|
|
47
|
-
if (approval) {
|
|
48
|
-
setCurrentAmount(newAmount)
|
|
49
|
-
setChargedFees(getFeesCharged(newAmount))
|
|
50
|
-
setRemainder(Number(approval.receivable!.amountFormatted) - newAmount)
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
[approval, getFeesCharged],
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
const handleAction = useCallback(() => {
|
|
57
|
-
dispatch(
|
|
58
|
-
setBorrowInfo({
|
|
59
|
-
borrowAmount: currentAmount,
|
|
60
|
-
borrowAmountBN: upScale(currentAmount, approval?.token.decimal),
|
|
61
|
-
chargedFees,
|
|
62
|
-
remainder: Number(remainder!),
|
|
63
|
-
nextStep: WIDGET_STEP.ConfirmTransfer,
|
|
64
|
-
}),
|
|
65
|
-
)
|
|
66
|
-
}, [approval?.token.decimal, chargedFees, currentAmount, dispatch, remainder])
|
|
67
|
-
|
|
68
|
-
if (!approval) {
|
|
69
|
-
return null
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return (
|
|
73
|
-
<ChooseAmountModal
|
|
74
|
-
title='Choose Amount'
|
|
75
|
-
description1='Access up to 80% of your invoice value'
|
|
76
|
-
description2='The remainder will be sent to your wallet when the invoice is paid'
|
|
77
|
-
sliderMax={getAvailableCreditLimit()}
|
|
78
|
-
currentAmount={currentAmount}
|
|
79
|
-
tokenSymbol={approval.token.symbol}
|
|
80
|
-
topLeft='Fees'
|
|
81
|
-
topRight={`${chargedFees} ${approval.token.symbol}`}
|
|
82
|
-
downLeft='Remainder'
|
|
83
|
-
downRight={`${remainder} ${approval.token.symbol}`}
|
|
84
|
-
handleChangeAmount={handleChangeAmount}
|
|
85
|
-
handleAction={handleAction}
|
|
86
|
-
/>
|
|
87
|
-
)
|
|
88
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { isEmpty } from '@huma-finance/shared'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
|
|
4
|
-
import { useAppDispatch, useAppSelector } from '../../hooks/useRedux'
|
|
5
|
-
import { setStep } from '../../store/widgets.reducers'
|
|
6
|
-
import { selectWidgetState } from '../../store/widgets.selectors'
|
|
7
|
-
import { WIDGET_STEP } from '../../store/widgets.store'
|
|
8
|
-
import { ConfirmTransferModal } from '../ConfirmTransferModal'
|
|
9
|
-
|
|
10
|
-
export function ConfirmTransfer(): React.ReactElement | null {
|
|
11
|
-
const dispatch = useAppDispatch()
|
|
12
|
-
const { borrowAmountNet, approval } = useAppSelector(selectWidgetState)
|
|
13
|
-
|
|
14
|
-
const handleAction = () => {
|
|
15
|
-
dispatch(setStep(WIDGET_STEP.ApproveNFT))
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (isEmpty(borrowAmountNet) || isEmpty(approval)) {
|
|
19
|
-
return null
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<ConfirmTransferModal
|
|
24
|
-
title='Confirm transaction details'
|
|
25
|
-
description={`Huma keeps your Invoice NFT as collateral until it's fully paid.`}
|
|
26
|
-
items={[
|
|
27
|
-
{ leftText: 'Invoice NFT', rightText: 'Huma' },
|
|
28
|
-
{
|
|
29
|
-
leftText: `${borrowAmountNet!} ${approval?.token.symbol}`,
|
|
30
|
-
rightText: 'You',
|
|
31
|
-
},
|
|
32
|
-
]}
|
|
33
|
-
actionText='APPROVE TRANSFER'
|
|
34
|
-
handleAction={handleAction}
|
|
35
|
-
/>
|
|
36
|
-
)
|
|
37
|
-
}
|