@huma-finance/widgets 0.0.11 → 0.0.13
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 +6 -5
- package/dist/cjs/index.cjs +5058 -5959
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.js +5059 -5960
- package/dist/index.js.map +1 -1
- package/package.json +16 -16
- package/src/components/ApproveAllowanceModal.tsx +5 -2
- package/src/components/ChainNotSupportedModal.tsx +31 -0
- package/src/components/ChooseAmountModal.tsx +322 -315
- package/src/components/ConfirmTransferModal.tsx +153 -0
- package/src/components/CreditLine/borrow/1-Evaluation.tsx +1 -2
- package/src/components/CreditLine/borrow/{3-ChooseAmount.tsx → 2-ChooseAmount.tsx} +2 -8
- package/src/components/CreditLine/borrow/{5-Transfer.tsx → 3-Transfer.tsx} +17 -3
- package/src/components/CreditLine/borrow/4-ApproveAllowance.tsx +1 -1
- package/src/components/CreditLine/borrow/index.tsx +3 -5
- package/src/components/Factoring/FactoredList.tsx +1 -1
- package/src/components/InvoiceFactoring/borrow/1-Evaluation.tsx +1 -4
- package/src/components/InvoiceFactoring/borrow/{3-ChooseAmount.tsx → 2-ChooseAmount.tsx} +5 -3
- package/src/components/InvoiceFactoring/borrow/3-ConfirmTransfer.tsx +37 -0
- package/src/components/InvoiceFactoring/borrow/index.tsx +5 -7
- package/src/components/StreamFactoring/borrow/1-Evaluation.tsx +11 -3
- package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +4 -1
- package/src/components/StreamFactoring/borrow/3-ConfirmTransfer.tsx +18 -80
- package/src/components/StreamFactoring/borrow/4-ApproveAllowance.tsx +4 -36
- package/src/components/StreamFactoring/borrow/5-Permit.tsx +14 -14
- package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +1 -1
- package/src/cosmos/CreditLineBorrow.fixture.tsx +1 -0
- package/src/cosmos/CreditLinePayment.fixture.tsx +1 -0
- package/src/cosmos/SDKTesting.fixture.tsx +615 -557
- package/src/cosmos/SuperfluidFactoringBorrow.fixture.tsx +3 -0
- package/src/cosmos/utils/env.ts +6 -0
- package/src/hooks/useEA.ts +10 -29
- package/src/index.tsx +75 -7
- package/src/reportWebVitals.ts +9 -9
- package/src/store/widgets.store.ts +0 -1
- package/src/utilTypes.d.ts +2 -0
- package/webpack.cosmos.js +9 -9
- package/src/components/AllowListModal.tsx +0 -113
- package/src/components/CreditLine/borrow/2-AllowList.tsx +0 -34
- package/src/components/InvoiceFactoring/borrow/2-AllowList.tsx +0 -34
- package/src/components/InvoiceFactoring/borrow/4-ConfirmTransfer.tsx +0 -104
- /package/src/components/CreditLine/borrow/{6-Success.tsx → 5-Success.tsx} +0 -0
- /package/src/components/InvoiceFactoring/borrow/{5-ApproveNFT.tsx → 4-ApproveNFT.tsx} +0 -0
- /package/src/components/InvoiceFactoring/borrow/{6-Transfer.tsx → 5-Transfer.tsx} +0 -0
- /package/src/components/InvoiceFactoring/borrow/{7-Success.tsx → 6-Success.tsx} +0 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { combineStyles } from '@huma-finance/shared'
|
|
2
|
+
import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos'
|
|
3
|
+
import { Box, Button, css, Typography, useTheme } from '@mui/material'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
|
|
6
|
+
import { ReceiptIcon, UsdcIcon } from './icons'
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
title: string
|
|
10
|
+
description: string
|
|
11
|
+
items: [
|
|
12
|
+
{ leftText: string; rightText: string },
|
|
13
|
+
{ leftText: string; rightText: string },
|
|
14
|
+
]
|
|
15
|
+
actionText: string
|
|
16
|
+
handleAction: () => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function ConfirmTransferModal({
|
|
20
|
+
title,
|
|
21
|
+
description,
|
|
22
|
+
items,
|
|
23
|
+
actionText,
|
|
24
|
+
handleAction,
|
|
25
|
+
}: Props): React.ReactElement | null {
|
|
26
|
+
const theme = useTheme()
|
|
27
|
+
|
|
28
|
+
const styles = {
|
|
29
|
+
wrapper: css`
|
|
30
|
+
height: 518px;
|
|
31
|
+
position: relative;
|
|
32
|
+
${theme.cssMixins.colStretch};
|
|
33
|
+
`,
|
|
34
|
+
header: css`
|
|
35
|
+
${theme.cssMixins.rowHCentered};
|
|
36
|
+
margin-top: -5px;
|
|
37
|
+
`,
|
|
38
|
+
description: css`
|
|
39
|
+
font-family: 'Uni-Neue-Regular';
|
|
40
|
+
font-size: 16px;
|
|
41
|
+
color: #49505b;
|
|
42
|
+
margin-top: 30px;
|
|
43
|
+
text-align: center;
|
|
44
|
+
`,
|
|
45
|
+
transferWrapper: css`
|
|
46
|
+
margin-top: 75px;
|
|
47
|
+
`,
|
|
48
|
+
transfer: css`
|
|
49
|
+
font-family: 'Uni-Neue-Regular';
|
|
50
|
+
${theme.cssMixins.rowSpaceBetweened}
|
|
51
|
+
${theme.cssMixins.rowVCentered}
|
|
52
|
+
height: 72px;
|
|
53
|
+
background: #f9f8fa;
|
|
54
|
+
border-radius: 4px;
|
|
55
|
+
font-weight: 500;
|
|
56
|
+
font-size: 16px;
|
|
57
|
+
color: #49505b;
|
|
58
|
+
padding: 24px 20px;
|
|
59
|
+
margin-bottom: 9px;
|
|
60
|
+
position: relative;
|
|
61
|
+
box-sizing: border-box;
|
|
62
|
+
`,
|
|
63
|
+
transferItem: css`
|
|
64
|
+
${theme.cssMixins.rowVCentered}
|
|
65
|
+
`,
|
|
66
|
+
arrow: css`
|
|
67
|
+
@keyframes bounceAlpha {
|
|
68
|
+
0% {
|
|
69
|
+
opacity: 1;
|
|
70
|
+
transform: translateX(0px) scale(1);
|
|
71
|
+
}
|
|
72
|
+
25% {
|
|
73
|
+
opacity: 0;
|
|
74
|
+
transform: translateX(10px) scale(0.9);
|
|
75
|
+
}
|
|
76
|
+
26% {
|
|
77
|
+
opacity: 0;
|
|
78
|
+
transform: translateX(-10px) scale(0.9);
|
|
79
|
+
}
|
|
80
|
+
55% {
|
|
81
|
+
opacity: 1;
|
|
82
|
+
transform: translateX(0px) scale(1);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
animation-name: bounceAlpha;
|
|
86
|
+
animation-duration: 1.4s;
|
|
87
|
+
animation-iteration-count: infinite;
|
|
88
|
+
animation-timing-function: linear;
|
|
89
|
+
|
|
90
|
+
color: #b246ff;
|
|
91
|
+
position: absolute;
|
|
92
|
+
margin: auto;
|
|
93
|
+
top: 0;
|
|
94
|
+
left: calc(15% + 36px);
|
|
95
|
+
bottom: 0;
|
|
96
|
+
right: 0;
|
|
97
|
+
width: 16px;
|
|
98
|
+
height: 16px;
|
|
99
|
+
`,
|
|
100
|
+
arrowFirst: css`
|
|
101
|
+
left: calc(15% + 20px);
|
|
102
|
+
animation-delay: 0.2s;
|
|
103
|
+
`,
|
|
104
|
+
okButton: css`
|
|
105
|
+
width: 100%;
|
|
106
|
+
position: absolute;
|
|
107
|
+
bottom: 0;
|
|
108
|
+
`,
|
|
109
|
+
usdcIcon: css`
|
|
110
|
+
width: 22px;
|
|
111
|
+
margin-right: 20px;
|
|
112
|
+
& > path:first-of-type {
|
|
113
|
+
fill: #76707e;
|
|
114
|
+
}
|
|
115
|
+
`,
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<Box css={styles.wrapper}>
|
|
120
|
+
<Typography variant='h6' css={styles.header}>
|
|
121
|
+
{title}
|
|
122
|
+
</Typography>
|
|
123
|
+
<Box css={styles.description}>{description}</Box>
|
|
124
|
+
<Box css={styles.transferWrapper}>
|
|
125
|
+
<Box css={styles.transfer}>
|
|
126
|
+
<Box css={styles.transferItem}>
|
|
127
|
+
<ReceiptIcon css={{ width: '24px', marginRight: '20px' }} />
|
|
128
|
+
{items[0].leftText}
|
|
129
|
+
</Box>
|
|
130
|
+
<ArrowForwardIosIcon
|
|
131
|
+
css={combineStyles([styles.arrow, styles.arrowFirst])}
|
|
132
|
+
/>
|
|
133
|
+
<ArrowForwardIosIcon css={styles.arrow} />
|
|
134
|
+
<Box>{items[0].rightText}</Box>
|
|
135
|
+
</Box>
|
|
136
|
+
<Box css={styles.transfer}>
|
|
137
|
+
<Box css={styles.transferItem}>
|
|
138
|
+
<UsdcIcon css={styles.usdcIcon} />
|
|
139
|
+
{items[1].leftText}
|
|
140
|
+
</Box>
|
|
141
|
+
<ArrowForwardIosIcon
|
|
142
|
+
css={combineStyles([styles.arrow, styles.arrowFirst])}
|
|
143
|
+
/>
|
|
144
|
+
<ArrowForwardIosIcon css={styles.arrow} />
|
|
145
|
+
<Box>{items[1].rightText}</Box>
|
|
146
|
+
</Box>
|
|
147
|
+
</Box>
|
|
148
|
+
<Button variant='contained' css={styles.okButton} onClick={handleAction}>
|
|
149
|
+
{actionText}
|
|
150
|
+
</Button>
|
|
151
|
+
</Box>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Box, Button, css, Typography, useTheme } from '@mui/material'
|
|
2
2
|
import { useWeb3React } from '@web3-react/core'
|
|
3
|
-
import {
|
|
3
|
+
import { PoolInfoType } from '@huma-finance/shared'
|
|
4
4
|
import React, { useEffect, useState } from 'react'
|
|
5
5
|
|
|
6
6
|
import useEA from '../../../hooks/useEA'
|
|
@@ -34,7 +34,6 @@ export function Evaluation({
|
|
|
34
34
|
borrowerWalletAddress: account,
|
|
35
35
|
},
|
|
36
36
|
WIDGET_STEP.Evaluation,
|
|
37
|
-
chainId === ChainEnum.Goerli,
|
|
38
37
|
)
|
|
39
38
|
handleApprove()
|
|
40
39
|
setStatus('success')
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { useWeb3React } from '@web3-react/core'
|
|
2
1
|
import {
|
|
3
2
|
AccountStats,
|
|
4
3
|
PoolInfoType,
|
|
5
4
|
upScale,
|
|
6
5
|
useCLFeeManager,
|
|
7
|
-
useCLPoolAllowance,
|
|
8
6
|
} from '@huma-finance/shared'
|
|
9
7
|
import React, { useCallback, useState } from 'react'
|
|
10
8
|
|
|
@@ -23,10 +21,8 @@ export function ChooseAmount({
|
|
|
23
21
|
accountStats,
|
|
24
22
|
}: Props): React.ReactElement | null {
|
|
25
23
|
const dispatch = useAppDispatch()
|
|
26
|
-
const { account } = useWeb3React()
|
|
27
24
|
const { poolUnderlyingToken } = poolInfo
|
|
28
25
|
const { symbol, decimals } = poolUnderlyingToken
|
|
29
|
-
const { approved } = useCLPoolAllowance(poolInfo.poolName, account)
|
|
30
26
|
const { getFeesCharged } = useCLFeeManager(poolInfo.poolName)
|
|
31
27
|
const [chargedFees, setChargedFees] = useState(0)
|
|
32
28
|
const [currentAmount, setCurrentAmount] = useState(0)
|
|
@@ -42,9 +38,7 @@ export function ChooseAmount({
|
|
|
42
38
|
)
|
|
43
39
|
|
|
44
40
|
const handleAction = useCallback(() => {
|
|
45
|
-
const nextStep =
|
|
46
|
-
? WIDGET_STEP.Transfer
|
|
47
|
-
: WIDGET_STEP.ApproveAllowance
|
|
41
|
+
const nextStep = WIDGET_STEP.Transfer
|
|
48
42
|
dispatch(
|
|
49
43
|
setBorrowInfo({
|
|
50
44
|
borrowAmount: currentAmount,
|
|
@@ -53,7 +47,7 @@ export function ChooseAmount({
|
|
|
53
47
|
nextStep,
|
|
54
48
|
}),
|
|
55
49
|
)
|
|
56
|
-
}, [
|
|
50
|
+
}, [chargedFees, currentAmount, decimals, dispatch])
|
|
57
51
|
|
|
58
52
|
return (
|
|
59
53
|
<ChooseAmountModal
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
PoolInfoType,
|
|
3
|
+
toBigNumber,
|
|
4
|
+
txAtom,
|
|
5
|
+
useCLPoolAllowance,
|
|
6
|
+
} from '@huma-finance/shared'
|
|
2
7
|
import React, { useCallback } from 'react'
|
|
3
8
|
|
|
9
|
+
import { useResetAtom } from 'jotai/utils'
|
|
10
|
+
import { useWeb3React } from '@web3-react/core'
|
|
4
11
|
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
5
12
|
import { setStep } from '../../../store/widgets.reducers'
|
|
6
13
|
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
@@ -13,11 +20,18 @@ type Props = {
|
|
|
13
20
|
|
|
14
21
|
export function Transfer({ poolInfo }: Props): React.ReactElement {
|
|
15
22
|
const dispatch = useAppDispatch()
|
|
23
|
+
const reset = useResetAtom(txAtom)
|
|
24
|
+
const { account } = useWeb3React()
|
|
16
25
|
const { borrowAmountBN } = useAppSelector(selectWidgetState)
|
|
26
|
+
const { allowance } = useCLPoolAllowance(poolInfo.poolName, account)
|
|
17
27
|
|
|
18
28
|
const handleSuccess = useCallback(() => {
|
|
19
|
-
|
|
20
|
-
|
|
29
|
+
reset()
|
|
30
|
+
const nextStep = allowance.gte(toBigNumber(borrowAmountBN!))
|
|
31
|
+
? WIDGET_STEP.Done
|
|
32
|
+
: WIDGET_STEP.ApproveAllowance
|
|
33
|
+
dispatch(setStep(nextStep))
|
|
34
|
+
}, [allowance, borrowAmountBN, dispatch, reset])
|
|
21
35
|
|
|
22
36
|
return (
|
|
23
37
|
<TxSendModal
|
|
@@ -16,11 +16,10 @@ import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
|
16
16
|
import { ErrorModal } from '../../ErrorModal'
|
|
17
17
|
import { WidgetWrapper } from '../../WidgetWrapper'
|
|
18
18
|
import { Evaluation } from './1-Evaluation'
|
|
19
|
-
import {
|
|
20
|
-
import { ChooseAmount } from './3-ChooseAmount'
|
|
19
|
+
import { ChooseAmount } from './2-ChooseAmount'
|
|
21
20
|
import { ApproveAllowance } from './4-ApproveAllowance'
|
|
22
|
-
import { Transfer } from './
|
|
23
|
-
import { Success } from './
|
|
21
|
+
import { Transfer } from './3-Transfer'
|
|
22
|
+
import { Success } from './5-Success'
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
25
|
* Credit line pool borrow props
|
|
@@ -92,7 +91,6 @@ export function CreditLineBorrow({
|
|
|
92
91
|
{step === WIDGET_STEP.Evaluation && (
|
|
93
92
|
<Evaluation poolInfo={poolInfo} handleApprove={approveCallback} />
|
|
94
93
|
)}
|
|
95
|
-
{step === WIDGET_STEP.AddToAllowList && <AllowList poolInfo={poolInfo} />}
|
|
96
94
|
{step === WIDGET_STEP.ChooseAmount && (
|
|
97
95
|
<ChooseAmount poolInfo={poolInfo} accountStats={accountStats} />
|
|
98
96
|
)}
|
|
@@ -58,7 +58,7 @@ export function FactoredList<T>({
|
|
|
58
58
|
let factoredItem = {
|
|
59
59
|
id,
|
|
60
60
|
due: dueDate,
|
|
61
|
-
icon: <ReceiptIcon css={{ width: '
|
|
61
|
+
icon: <ReceiptIcon css={{ width: '24px' }} />,
|
|
62
62
|
amount: formatMoney(downScale(receivableAmount.toString(), decimals)),
|
|
63
63
|
factored: formatMoney(downScale(totalDue.toString(), decimals)),
|
|
64
64
|
remained: formatMoney(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useWeb3React } from '@web3-react/core'
|
|
2
|
-
import {
|
|
2
|
+
import { PoolInfoType, toBigNumber } from '@huma-finance/shared'
|
|
3
3
|
import React, { useEffect } from 'react'
|
|
4
4
|
|
|
5
5
|
import useEA from '../../../hooks/useEA'
|
|
@@ -21,8 +21,6 @@ export function Evaluation({ poolInfo, tokenId }: Props): React.ReactElement {
|
|
|
21
21
|
{
|
|
22
22
|
poolAddress: poolInfo.pool,
|
|
23
23
|
borrowerWalletAddress: account,
|
|
24
|
-
receivableAddress: poolInfo.assetAddress,
|
|
25
|
-
receivableParam: toBigNumber(tokenId).toHexString(),
|
|
26
24
|
context: {
|
|
27
25
|
receivable: {
|
|
28
26
|
address: poolInfo.assetAddress!,
|
|
@@ -31,7 +29,6 @@ export function Evaluation({ poolInfo, tokenId }: Props): React.ReactElement {
|
|
|
31
29
|
},
|
|
32
30
|
},
|
|
33
31
|
WIDGET_STEP.ChooseAmount,
|
|
34
|
-
chainId === ChainEnum.Goerli,
|
|
35
32
|
)
|
|
36
33
|
}
|
|
37
34
|
}, [
|
|
@@ -27,7 +27,9 @@ export function ChooseAmount({
|
|
|
27
27
|
const [currentAmount, setCurrentAmount] = useState(0)
|
|
28
28
|
const { approval } = useAppSelector(selectWidgetState)
|
|
29
29
|
const { getFeesCharged } = useFeeManager(poolInfo.poolName, poolInfo.poolType)
|
|
30
|
-
const [remainder, setRemainder] = useState(
|
|
30
|
+
const [remainder, setRemainder] = useState<string | number | undefined>(
|
|
31
|
+
approval!.receivable?.amountFormatted,
|
|
32
|
+
)
|
|
31
33
|
|
|
32
34
|
const getAvailableCreditLimit = () => {
|
|
33
35
|
if (approval && creditRecord) {
|
|
@@ -35,7 +37,7 @@ export function ChooseAmount({
|
|
|
35
37
|
.add(creditRecord.totalDue)
|
|
36
38
|
.sub(creditRecord.feesAndInterestDue)
|
|
37
39
|
.toNumber()
|
|
38
|
-
return Number(approval.terms.
|
|
40
|
+
return Number(approval.terms.creditLimitFormatted) - principal
|
|
39
41
|
}
|
|
40
42
|
return 0
|
|
41
43
|
}
|
|
@@ -45,7 +47,7 @@ export function ChooseAmount({
|
|
|
45
47
|
if (approval) {
|
|
46
48
|
setCurrentAmount(newAmount)
|
|
47
49
|
setChargedFees(getFeesCharged(newAmount))
|
|
48
|
-
setRemainder(Number(approval.receivable!.
|
|
50
|
+
setRemainder(Number(approval.receivable!.amountFormatted) - newAmount)
|
|
49
51
|
}
|
|
50
52
|
},
|
|
51
53
|
[approval, getFeesCharged],
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
}
|
|
@@ -16,12 +16,11 @@ import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
|
16
16
|
import { ErrorModal } from '../../ErrorModal'
|
|
17
17
|
import { WidgetWrapper } from '../../WidgetWrapper'
|
|
18
18
|
import { Evaluation } from './1-Evaluation'
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import { Success } from './7-Success'
|
|
19
|
+
import { ChooseAmount } from './2-ChooseAmount'
|
|
20
|
+
import { ConfirmTransfer } from './3-ConfirmTransfer'
|
|
21
|
+
import { ApproveNFT } from './4-ApproveNFT'
|
|
22
|
+
import { Transfer } from './5-Transfer'
|
|
23
|
+
import { Success } from './6-Success'
|
|
25
24
|
|
|
26
25
|
/**
|
|
27
26
|
* Invoice factoring pool borrow props
|
|
@@ -72,7 +71,6 @@ export function InvoiceFactoringBorrow({
|
|
|
72
71
|
{step === WIDGET_STEP.Evaluation && (
|
|
73
72
|
<Evaluation poolInfo={poolInfo} tokenId={tokenId.toString()} />
|
|
74
73
|
)}
|
|
75
|
-
{step === WIDGET_STEP.AddToAllowList && <AllowList poolInfo={poolInfo} />}
|
|
76
74
|
{step === WIDGET_STEP.ChooseAmount && (
|
|
77
75
|
<ChooseAmount poolInfo={poolInfo} accountStats={accountStats} />
|
|
78
76
|
)}
|
|
@@ -26,9 +26,10 @@ export function Evaluation({
|
|
|
26
26
|
{
|
|
27
27
|
poolAddress: poolInfo.pool,
|
|
28
28
|
borrowerWalletAddress: account,
|
|
29
|
-
payerAddress,
|
|
30
|
-
superToken,
|
|
31
29
|
context: {
|
|
30
|
+
receivable: {
|
|
31
|
+
address: poolInfo.assetAddress!,
|
|
32
|
+
},
|
|
32
33
|
payerAddress,
|
|
33
34
|
superToken,
|
|
34
35
|
},
|
|
@@ -36,7 +37,14 @@ export function Evaluation({
|
|
|
36
37
|
WIDGET_STEP.ChooseAmount,
|
|
37
38
|
)
|
|
38
39
|
}
|
|
39
|
-
}, [
|
|
40
|
+
}, [
|
|
41
|
+
account,
|
|
42
|
+
checkingEA,
|
|
43
|
+
payerAddress,
|
|
44
|
+
poolInfo.assetAddress,
|
|
45
|
+
poolInfo.pool,
|
|
46
|
+
superToken,
|
|
47
|
+
])
|
|
40
48
|
|
|
41
49
|
return (
|
|
42
50
|
<LoadingModal
|
|
@@ -49,6 +49,9 @@ export function ChooseAmount({
|
|
|
49
49
|
if (borrowFlowrate.gte(currentFlowRateBN)) {
|
|
50
50
|
borrowFlowrate = currentFlowRateBN.sub(1)
|
|
51
51
|
}
|
|
52
|
+
if (borrowAmountBN.gte(approval!.terms.creditLimit)) {
|
|
53
|
+
borrowFlowrate = borrowFlowrate.sub(1)
|
|
54
|
+
}
|
|
52
55
|
|
|
53
56
|
// As borrowFlowrate adds 1, need to calculate the new accurate borrow amount
|
|
54
57
|
const newBorrowAmountBN = borrowFlowrate
|
|
@@ -111,7 +114,7 @@ export function ChooseAmount({
|
|
|
111
114
|
<ChooseAmountModal
|
|
112
115
|
title='Choose Amount'
|
|
113
116
|
description1='Access up to 100% of your stream flowrate'
|
|
114
|
-
sliderMax={Number(approval.terms.
|
|
117
|
+
sliderMax={Number(approval.terms.creditLimitFormatted)}
|
|
115
118
|
currentAmount={currentAmount}
|
|
116
119
|
tokenSymbol={approval.token.symbol}
|
|
117
120
|
topLeft='Fees'
|
|
@@ -1,104 +1,42 @@
|
|
|
1
|
-
import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos'
|
|
2
|
-
import { Box, Button, css, Typography, useTheme } from '@mui/material'
|
|
3
|
-
import { useWeb3React } from '@web3-react/core'
|
|
4
1
|
import { CHAINS, isEmpty } from '@huma-finance/shared'
|
|
5
|
-
import
|
|
2
|
+
import { useWeb3React } from '@web3-react/core'
|
|
3
|
+
import React, { useCallback } from 'react'
|
|
6
4
|
|
|
7
5
|
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
8
6
|
import { setStep } from '../../../store/widgets.reducers'
|
|
9
7
|
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
10
8
|
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
9
|
+
import { ConfirmTransferModal } from '../../ConfirmTransferModal'
|
|
11
10
|
|
|
12
11
|
export function ConfirmTransfer(): React.ReactElement | null {
|
|
13
|
-
const theme = useTheme()
|
|
14
12
|
const dispatch = useAppDispatch()
|
|
15
13
|
const { chainId } = useWeb3React()
|
|
16
14
|
const { borrowAmount, approval } = useAppSelector(selectWidgetState)
|
|
17
15
|
|
|
18
|
-
const
|
|
19
|
-
wrapper: css`
|
|
20
|
-
height: 518px;
|
|
21
|
-
position: relative;
|
|
22
|
-
${theme.cssMixins.colStretch};
|
|
23
|
-
`,
|
|
24
|
-
header: css`
|
|
25
|
-
${theme.cssMixins.rowHCentered};
|
|
26
|
-
margin-top: -5px;
|
|
27
|
-
`,
|
|
28
|
-
description: css`
|
|
29
|
-
font-weight: 500;
|
|
30
|
-
font-size: 16px;
|
|
31
|
-
color: #49505b;
|
|
32
|
-
margin-top: 30px;
|
|
33
|
-
`,
|
|
34
|
-
transferWrapper: css`
|
|
35
|
-
margin-top: 75px;
|
|
36
|
-
`,
|
|
37
|
-
transfer: css`
|
|
38
|
-
${theme.cssMixins.rowSpaceBetweened}
|
|
39
|
-
${theme.cssMixins.rowVCentered}
|
|
40
|
-
height: 72px;
|
|
41
|
-
background: #f9f8fa;
|
|
42
|
-
border-radius: 4px;
|
|
43
|
-
font-weight: 500;
|
|
44
|
-
font-size: 16px;
|
|
45
|
-
color: #49505b;
|
|
46
|
-
padding: 24px 32px;
|
|
47
|
-
margin-bottom: 9px;
|
|
48
|
-
position: relative;
|
|
49
|
-
`,
|
|
50
|
-
arrow: css`
|
|
51
|
-
color: #d2d0d6;
|
|
52
|
-
position: absolute;
|
|
53
|
-
margin: auto;
|
|
54
|
-
top: 0;
|
|
55
|
-
left: 0;
|
|
56
|
-
bottom: 0;
|
|
57
|
-
right: 0;
|
|
58
|
-
`,
|
|
59
|
-
okButton: css`
|
|
60
|
-
width: 100%;
|
|
61
|
-
position: absolute;
|
|
62
|
-
bottom: 0;
|
|
63
|
-
`,
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const handleAction = () => {
|
|
16
|
+
const handleAction = useCallback(() => {
|
|
67
17
|
const step = CHAINS[chainId!].isTestnet
|
|
68
18
|
? WIDGET_STEP.ApproveAllowance
|
|
69
19
|
: WIDGET_STEP.Permit
|
|
70
20
|
dispatch(setStep(step))
|
|
71
|
-
}
|
|
21
|
+
}, [chainId, dispatch])
|
|
72
22
|
|
|
73
23
|
if (isEmpty(borrowAmount) || isEmpty(approval)) {
|
|
74
24
|
return null
|
|
75
25
|
}
|
|
76
26
|
|
|
77
27
|
return (
|
|
78
|
-
<
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
<Box css={styles.transfer}>
|
|
92
|
-
<Box>
|
|
93
|
-
{borrowAmount!.toFixed(2)} {approval?.token.symbol}
|
|
94
|
-
</Box>
|
|
95
|
-
<ArrowForwardIosIcon css={styles.arrow} />
|
|
96
|
-
<Box>You</Box>
|
|
97
|
-
</Box>
|
|
98
|
-
</Box>
|
|
99
|
-
<Button variant='contained' css={styles.okButton} onClick={handleAction}>
|
|
100
|
-
Approve Transfer
|
|
101
|
-
</Button>
|
|
102
|
-
</Box>
|
|
28
|
+
<ConfirmTransferModal
|
|
29
|
+
title='Confirm transaction details'
|
|
30
|
+
description={`Huma keeps your Tradable Stream NFT as collateral until it's fully paid.`}
|
|
31
|
+
items={[
|
|
32
|
+
{ leftText: 'Tradable Stream', rightText: 'Huma' },
|
|
33
|
+
{
|
|
34
|
+
leftText: `${borrowAmount!.toFixed(2)} ${approval?.token.symbol}`,
|
|
35
|
+
rightText: 'You',
|
|
36
|
+
},
|
|
37
|
+
]}
|
|
38
|
+
actionText='Approve Transfer'
|
|
39
|
+
handleAction={handleAction}
|
|
40
|
+
/>
|
|
103
41
|
)
|
|
104
42
|
}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
PoolInfoType,
|
|
4
|
-
toBigNumber,
|
|
5
|
-
upScale,
|
|
6
|
-
usePoolAllowance,
|
|
7
|
-
} from '@huma-finance/shared'
|
|
1
|
+
import { PoolInfoType } from '@huma-finance/shared'
|
|
8
2
|
import React, { useCallback } from 'react'
|
|
9
3
|
import { useDispatch } from 'react-redux'
|
|
10
4
|
|
|
@@ -13,7 +7,6 @@ import { setStep } from '../../../store/widgets.reducers'
|
|
|
13
7
|
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
14
8
|
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
15
9
|
import { ApproveAllowanceModal } from '../../ApproveAllowanceModal'
|
|
16
|
-
import { LoadingModal } from '../../LoadingModal'
|
|
17
10
|
|
|
18
11
|
type Props = {
|
|
19
12
|
poolInfo: PoolInfoType
|
|
@@ -23,43 +16,18 @@ export function ApproveAllowance({
|
|
|
23
16
|
poolInfo,
|
|
24
17
|
}: Props): React.ReactElement | null {
|
|
25
18
|
const dispatch = useDispatch()
|
|
26
|
-
const {
|
|
27
|
-
const { borrowAmount, approval } = useAppSelector(selectWidgetState)
|
|
28
|
-
const { allowance, loaded } = usePoolAllowance(
|
|
29
|
-
poolInfo.poolName,
|
|
30
|
-
poolInfo.poolType,
|
|
31
|
-
account,
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
const getNewAllowance = () => {
|
|
35
|
-
if (!borrowAmount || !loaded) {
|
|
36
|
-
return null
|
|
37
|
-
}
|
|
38
|
-
return toBigNumber(
|
|
39
|
-
upScale(borrowAmount, poolInfo.poolUnderlyingToken.decimals),
|
|
40
|
-
).add(allowance)
|
|
41
|
-
}
|
|
19
|
+
const { borrowAmountBN } = useAppSelector(selectWidgetState)
|
|
42
20
|
|
|
43
21
|
const handleSuccess = useCallback(() => {
|
|
44
22
|
dispatch(setStep(WIDGET_STEP.Permit))
|
|
45
23
|
}, [dispatch])
|
|
46
24
|
|
|
47
|
-
const newAllowance = getNewAllowance()
|
|
48
|
-
|
|
49
|
-
if (!newAllowance) {
|
|
50
|
-
return (
|
|
51
|
-
<LoadingModal
|
|
52
|
-
title={`Approve ${approval?.token?.symbol}`}
|
|
53
|
-
description='Waiting for approval confirmation...'
|
|
54
|
-
/>
|
|
55
|
-
)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
25
|
return (
|
|
59
26
|
<ApproveAllowanceModal
|
|
60
27
|
poolInfo={poolInfo}
|
|
61
|
-
allowanceAmount={
|
|
28
|
+
allowanceAmount={borrowAmountBN!}
|
|
62
29
|
handleSuccess={handleSuccess}
|
|
30
|
+
spender={poolInfo.poolProcessor!}
|
|
63
31
|
/>
|
|
64
32
|
)
|
|
65
33
|
}
|