@huma-finance/widgets 0.0.6-alpha.0
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/.env.example +3 -0
- package/.eslintignore +2 -0
- package/.eslintrc.js +64 -0
- package/.prettierignore +4 -0
- package/.prettierrc.js +16 -0
- package/API.md +331 -0
- package/LICENSE +661 -0
- package/README.md +48 -0
- package/babel.config.js +15 -0
- package/config-overrides.js +9 -0
- package/cosmos.config.json +7 -0
- package/cypress/e2e/01-invoice-factoring-borrow.test.ts +62 -0
- package/cypress/support/e2e.ts +76 -0
- package/cypress/support/ethereum.ts +142 -0
- package/cypress/tsconfig.json +9 -0
- package/cypress/utils/index.ts +54 -0
- package/cypress.config.ts +20 -0
- package/dist/assets/output-15e10f9f.css +44 -0
- package/dist/cjs/assets/output-15e10f9f.css +44 -0
- package/dist/cjs/index.cjs +17576 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/index.d.ts +211 -0
- package/dist/index.js +17529 -0
- package/dist/index.js.map +1 -0
- package/jsdoc2md.json +20 -0
- package/package.json +193 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +40 -0
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +25 -0
- package/public/robots.txt +3 -0
- package/rollup.config.js +81 -0
- package/src/components/Activity.tsx +123 -0
- package/src/components/AllowListModal.tsx +113 -0
- package/src/components/ApolloWrapper.tsx +15 -0
- package/src/components/ApproveAllowanceModal.tsx +118 -0
- package/src/components/BottomButton.tsx +31 -0
- package/src/components/ChooseAmountModal.tsx +315 -0
- package/src/components/CreditLine/borrow/1-Evaluation.tsx +159 -0
- package/src/components/CreditLine/borrow/2-AllowList.tsx +34 -0
- package/src/components/CreditLine/borrow/3-ChooseAmount.tsx +74 -0
- package/src/components/CreditLine/borrow/4-ApproveAllowance.tsx +29 -0
- package/src/components/CreditLine/borrow/5-Transfer.tsx +30 -0
- package/src/components/CreditLine/borrow/6-Success.tsx +30 -0
- package/src/components/CreditLine/borrow/index.tsx +119 -0
- package/src/components/CreditLine/payment/1-ChooseAmount.tsx +67 -0
- package/src/components/CreditLine/payment/2-ApproveAllowance.tsx +23 -0
- package/src/components/CreditLine/payment/3-Transfer.tsx +34 -0
- package/src/components/CreditLine/payment/4-Success.tsx +39 -0
- package/src/components/CreditLine/payment/index.tsx +94 -0
- package/src/components/ErrorModal.tsx +132 -0
- package/src/components/Factoring/FactoredList.tsx +143 -0
- package/src/components/Factoring/UpcomingList.tsx +90 -0
- package/src/components/Factoring/index.ts +2 -0
- package/src/components/HumaLoading.tsx +68 -0
- package/src/components/HumaTable.tsx +158 -0
- package/src/components/InvoiceFactoring/borrow/1-Evaluation.tsx +46 -0
- package/src/components/InvoiceFactoring/borrow/2-AllowList.tsx +34 -0
- package/src/components/InvoiceFactoring/borrow/3-ChooseAmount.tsx +92 -0
- package/src/components/InvoiceFactoring/borrow/4-ConfirmTransfer.tsx +104 -0
- package/src/components/InvoiceFactoring/borrow/5-ApproveNFT.tsx +55 -0
- package/src/components/InvoiceFactoring/borrow/6-Transfer.tsx +34 -0
- package/src/components/InvoiceFactoring/borrow/7-Success.tsx +20 -0
- package/src/components/InvoiceFactoring/borrow/index.tsx +96 -0
- package/src/components/InvoiceFactoring/payment/1-ChooseAmount.tsx +67 -0
- package/src/components/InvoiceFactoring/payment/2-ApproveAllowance.tsx +23 -0
- package/src/components/InvoiceFactoring/payment/3-Transfer.tsx +34 -0
- package/src/components/InvoiceFactoring/payment/4-Success.tsx +23 -0
- package/src/components/InvoiceFactoring/payment/index.tsx +86 -0
- package/src/components/Lend/supply/1-Evaluation.tsx +86 -0
- package/src/components/Lend/supply/2-ChooseAmount.tsx +70 -0
- package/src/components/Lend/supply/3-ApproveAllowance.tsx +25 -0
- package/src/components/Lend/supply/4-ConfirmTransfer.tsx +104 -0
- package/src/components/Lend/supply/6-Transfer.tsx +32 -0
- package/src/components/Lend/supply/7-Success.tsx +49 -0
- package/src/components/Lend/supply/index.tsx +144 -0
- package/src/components/Lend/withdraw/1-CheckWithdrawble.tsx +73 -0
- package/src/components/Lend/withdraw/2-ChooseAmount.tsx +50 -0
- package/src/components/Lend/withdraw/3-Transfer.tsx +32 -0
- package/src/components/Lend/withdraw/4-Success.tsx +49 -0
- package/src/components/Lend/withdraw/index.tsx +101 -0
- package/src/components/LoadingModal.tsx +49 -0
- package/src/components/StreamFactoring/borrow/1-Evaluation.tsx +57 -0
- package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +124 -0
- package/src/components/StreamFactoring/borrow/3-ConfirmTransfer.tsx +104 -0
- package/src/components/StreamFactoring/borrow/4-ApproveAllowance.tsx +65 -0
- package/src/components/StreamFactoring/borrow/5-Permit.tsx +144 -0
- package/src/components/StreamFactoring/borrow/6-Transfer.tsx +37 -0
- package/src/components/StreamFactoring/borrow/7-Success.tsx +20 -0
- package/src/components/StreamFactoring/borrow/index.tsx +95 -0
- package/src/components/StreamFactoring/payment/ChooseAmount.tsx +54 -0
- package/src/components/StreamFactoring/payment/Success.tsx +23 -0
- package/src/components/StreamFactoring/payment/Transfer.tsx +34 -0
- package/src/components/StreamFactoring/payment/index.tsx +66 -0
- package/src/components/SuperfluidFactoring/SuperfluidFactoredList.tsx +61 -0
- package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +185 -0
- package/src/components/SuperfluidFactoring/index.tsx +85 -0
- package/src/components/TxDoneModal.tsx +83 -0
- package/src/components/TxSendModal.tsx +59 -0
- package/src/components/ViewOnExplorer.tsx +26 -0
- package/src/components/WidgetWrapper.tsx +74 -0
- package/src/components/WrapperModal.tsx +54 -0
- package/src/components/buttons/TableActionButton.tsx +36 -0
- package/src/components/buttons/index.ts +1 -0
- package/src/components/humaModal/HumaModal.tsx +68 -0
- package/src/components/humaModal/HumaModalHeader.tsx +70 -0
- package/src/components/humaModal/index.tsx +2 -0
- package/src/components/icons/approve-lender.svg +30 -0
- package/src/components/icons/auto-payback.svg +40 -0
- package/src/components/icons/check-circle.svg +3 -0
- package/src/components/icons/check-green.svg +3 -0
- package/src/components/icons/check.svg +10 -0
- package/src/components/icons/donut.svg +904 -0
- package/src/components/icons/ellipse.svg +3 -0
- package/src/components/icons/ethereum.svg +1 -0
- package/src/components/icons/huma-full.svg +22 -0
- package/src/components/icons/huma.svg +15 -0
- package/src/components/icons/index.tsx +93 -0
- package/src/components/icons/loader.svg +229 -0
- package/src/components/icons/metamask.svg +31 -0
- package/src/components/icons/polygon.svg +16 -0
- package/src/components/icons/receipt.svg +3 -0
- package/src/components/icons/separator.svg +3 -0
- package/src/components/icons/sorry.svg +31 -0
- package/src/components/icons/spinner.gif +0 -0
- package/src/components/icons/usdc.svg +5 -0
- package/src/components/icons/wallet-connect.svg +12 -0
- package/src/cosmos/CreditLineBorrow.fixture.tsx +85 -0
- package/src/cosmos/CreditLinePayment.fixture.tsx +49 -0
- package/src/cosmos/InvoiceFactoringBorrow.fixture.tsx +111 -0
- package/src/cosmos/InvoiceFactoringPayment.fixture.tsx +67 -0
- package/src/cosmos/LendSupply.fixture.tsx +75 -0
- package/src/cosmos/LendWithdraw.fixture.tsx +43 -0
- package/src/cosmos/SDKTesting.fixture.tsx +507 -0
- package/src/cosmos/SuperfluidFactoringBorrow.fixture.tsx +12 -0
- package/src/cosmos/WalletWrapper.tsx +52 -0
- package/src/cosmos/abis/InvoiceNFT.json +644 -0
- package/src/cosmos/abis/ReceivableFactoringPool.json +1529 -0
- package/src/cosmos/utils/index.ts +169 -0
- package/src/fonts/Inter/Inter-Black.ttf +0 -0
- package/src/fonts/Inter/Inter-Bold.ttf +0 -0
- package/src/fonts/Inter/Inter-ExtraBold.ttf +0 -0
- package/src/fonts/Inter/Inter-ExtraLight.ttf +0 -0
- package/src/fonts/Inter/Inter-Light.ttf +0 -0
- package/src/fonts/Inter/Inter-Medium.ttf +0 -0
- package/src/fonts/Inter/Inter-Regular.ttf +0 -0
- package/src/fonts/Inter/Inter-SemiBold.ttf +0 -0
- package/src/fonts/Inter/Inter-Thin.ttf +0 -0
- package/src/fonts/Recoleta/Recoleta-Black.otf +0 -0
- package/src/fonts/Recoleta/Recoleta-Bold.otf +0 -0
- package/src/fonts/Recoleta/Recoleta-Light.otf +0 -0
- package/src/fonts/Recoleta/Recoleta-Medium.otf +0 -0
- package/src/fonts/Recoleta/Recoleta-Regular.otf +0 -0
- package/src/fonts/Recoleta/Recoleta-RegularDEMO.otf +0 -0
- package/src/fonts/Recoleta/Recoleta-SemiBold.otf +0 -0
- package/src/fonts/Recoleta/Recoleta-Thin.otf +0 -0
- package/src/fonts/Roboto/LICENSE.txt +202 -0
- package/src/fonts/Roboto/Roboto-Black.ttf +0 -0
- package/src/fonts/Roboto/Roboto-BlackItalic.ttf +0 -0
- package/src/fonts/Roboto/Roboto-Bold.ttf +0 -0
- package/src/fonts/Roboto/Roboto-BoldItalic.ttf +0 -0
- package/src/fonts/Roboto/Roboto-Italic.ttf +0 -0
- package/src/fonts/Roboto/Roboto-Light.ttf +0 -0
- package/src/fonts/Roboto/Roboto-LightItalic.ttf +0 -0
- package/src/fonts/Roboto/Roboto-Medium.ttf +0 -0
- package/src/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
- package/src/fonts/Roboto/Roboto-Regular.ttf +0 -0
- package/src/fonts/Roboto/Roboto-Thin.ttf +0 -0
- package/src/fonts/Roboto/Roboto-ThinItalic.ttf +0 -0
- package/src/fonts/UniNeue/UniNeue-Black.ttf +0 -0
- package/src/fonts/UniNeue/UniNeue-Bold.ttf +0 -0
- package/src/fonts/UniNeue/UniNeue-Book.ttf +0 -0
- package/src/fonts/UniNeue/UniNeue-Heavy.ttf +0 -0
- package/src/fonts/UniNeue/UniNeue-Light.ttf +0 -0
- package/src/fonts/UniNeue/UniNeue-Regular.ttf +0 -0
- package/src/fonts/UniNeue/UniNeue-Thin.ttf +0 -0
- package/src/hooks/useEA.ts +70 -0
- package/src/hooks/useRedux.ts +6 -0
- package/src/index.css +61 -0
- package/src/index.tsx +219 -0
- package/src/react-app-env.d.ts +1 -0
- package/src/reportWebVitals.ts +15 -0
- package/src/setupTests.ts +6 -0
- package/src/store/index.ts +27 -0
- package/src/store/widgets.reducers.ts +120 -0
- package/src/store/widgets.selectors.ts +3 -0
- package/src/store/widgets.store.ts +55 -0
- package/src/theme/breakpoints.ts +10 -0
- package/src/theme/components.ts +70 -0
- package/src/theme/coreThemeConstants.ts +29 -0
- package/src/theme/cssMixins.ts +92 -0
- package/src/theme/hooks/useGetSizes.ts +34 -0
- package/src/theme/index.ts +24 -0
- package/src/theme/palette.ts +150 -0
- package/src/theme/shape.ts +7 -0
- package/src/theme/theme.types.ts +80 -0
- package/src/theme/typography.ts +117 -0
- package/src/utilTypes.d.ts +29 -0
- package/src/utils/env.ts +9 -0
- package/tsconfig.build.json +7 -0
- package/tsconfig.json +32 -0
- package/webpack.cosmos.js +54 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos'
|
|
2
|
+
import { Box, Button, css, Typography, useTheme } from '@mui/material'
|
|
3
|
+
import { isEmpty } from '@huma-finance/shared'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
|
|
6
|
+
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
7
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
8
|
+
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
9
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
10
|
+
|
|
11
|
+
export function ConfirmTransfer(): React.ReactElement | null {
|
|
12
|
+
const theme = useTheme()
|
|
13
|
+
const dispatch = useAppDispatch()
|
|
14
|
+
const { borrowAmountNet, approveInfo } = useAppSelector(selectWidgetState)
|
|
15
|
+
|
|
16
|
+
const styles = {
|
|
17
|
+
wrapper: css`
|
|
18
|
+
height: 518px;
|
|
19
|
+
position: relative;
|
|
20
|
+
${theme.cssMixins.colStretch};
|
|
21
|
+
`,
|
|
22
|
+
header: css`
|
|
23
|
+
font-family: 'Uni-Neue-Bold';
|
|
24
|
+
${theme.cssMixins.rowHCentered};
|
|
25
|
+
margin-top: -5px;
|
|
26
|
+
`,
|
|
27
|
+
description: css`
|
|
28
|
+
font-family: 'Uni-Neue-Regular';
|
|
29
|
+
font-weight: 500;
|
|
30
|
+
font-size: 16px;
|
|
31
|
+
color: #49505b;
|
|
32
|
+
margin-top: 30px;
|
|
33
|
+
text-align: center;
|
|
34
|
+
`,
|
|
35
|
+
transferWrapper: css`
|
|
36
|
+
margin-top: 75px;
|
|
37
|
+
`,
|
|
38
|
+
transfer: css`
|
|
39
|
+
font-family: 'Uni-Neue-Regular';
|
|
40
|
+
${theme.cssMixins.rowSpaceBetweened}
|
|
41
|
+
${theme.cssMixins.rowVCentered}
|
|
42
|
+
height: 72px;
|
|
43
|
+
background: #f9f8fa;
|
|
44
|
+
border-radius: 4px;
|
|
45
|
+
font-weight: 500;
|
|
46
|
+
font-size: 16px;
|
|
47
|
+
color: #49505b;
|
|
48
|
+
padding: 24px 32px;
|
|
49
|
+
margin-bottom: 9px;
|
|
50
|
+
position: relative;
|
|
51
|
+
box-sizing: border-box;
|
|
52
|
+
`,
|
|
53
|
+
arrow: css`
|
|
54
|
+
color: #d2d0d6;
|
|
55
|
+
position: absolute;
|
|
56
|
+
margin: auto;
|
|
57
|
+
top: 0;
|
|
58
|
+
left: 0;
|
|
59
|
+
bottom: 0;
|
|
60
|
+
right: 0;
|
|
61
|
+
`,
|
|
62
|
+
okButton: css`
|
|
63
|
+
width: 100%;
|
|
64
|
+
position: absolute;
|
|
65
|
+
bottom: 0;
|
|
66
|
+
`,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const handleAction = () => {
|
|
70
|
+
dispatch(setStep(WIDGET_STEP.ApproveNFT))
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (isEmpty(borrowAmountNet) || isEmpty(approveInfo)) {
|
|
74
|
+
return null
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<Box css={styles.wrapper}>
|
|
79
|
+
<Typography variant='h6' css={styles.header}>
|
|
80
|
+
Confirm transaction details
|
|
81
|
+
</Typography>
|
|
82
|
+
<Box css={styles.description}>
|
|
83
|
+
Huma keeps your Invoice NFT as collateral until it's fully paid.
|
|
84
|
+
</Box>
|
|
85
|
+
<Box css={styles.transferWrapper}>
|
|
86
|
+
<Box css={styles.transfer}>
|
|
87
|
+
<Box>Invoice NFT</Box>
|
|
88
|
+
<ArrowForwardIosIcon css={styles.arrow} />
|
|
89
|
+
<Box>Huma</Box>
|
|
90
|
+
</Box>
|
|
91
|
+
<Box css={styles.transfer}>
|
|
92
|
+
<Box>
|
|
93
|
+
{borrowAmountNet!} {approveInfo?.tokenSymbol}
|
|
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>
|
|
103
|
+
)
|
|
104
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useWeb3React } from '@web3-react/core'
|
|
2
|
+
import {
|
|
3
|
+
PoolInfoType,
|
|
4
|
+
sendTxAtom,
|
|
5
|
+
txAtom,
|
|
6
|
+
TxStateType,
|
|
7
|
+
useInvoiceNFTContract,
|
|
8
|
+
} from '@huma-finance/shared'
|
|
9
|
+
import { useAtom } from 'jotai'
|
|
10
|
+
import { useResetAtom } from 'jotai/utils'
|
|
11
|
+
import React, { useEffect } from 'react'
|
|
12
|
+
|
|
13
|
+
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
14
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
15
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
16
|
+
import { LoadingModal } from '../../LoadingModal'
|
|
17
|
+
import { ViewOnExplorer } from '../../ViewOnExplorer'
|
|
18
|
+
|
|
19
|
+
type Props = {
|
|
20
|
+
poolInfo: PoolInfoType
|
|
21
|
+
tokenId: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function ApproveNFT({ poolInfo, tokenId }: Props): React.ReactElement {
|
|
25
|
+
const dispatch = useAppDispatch()
|
|
26
|
+
const { provider } = useWeb3React()
|
|
27
|
+
const [{ state, txHash }, send] = useAtom(sendTxAtom)
|
|
28
|
+
const reset = useResetAtom(txAtom)
|
|
29
|
+
const invoiceNFTContract = useInvoiceNFTContract(poolInfo.poolName)
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (state === TxStateType.Success) {
|
|
33
|
+
reset()
|
|
34
|
+
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
35
|
+
}
|
|
36
|
+
}, [dispatch, reset, state])
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
send({
|
|
40
|
+
contract: invoiceNFTContract!,
|
|
41
|
+
method: 'approve',
|
|
42
|
+
params: [poolInfo.pool, tokenId],
|
|
43
|
+
provider,
|
|
44
|
+
})
|
|
45
|
+
}, [invoiceNFTContract, poolInfo.pool, provider, send, tokenId])
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<LoadingModal
|
|
49
|
+
title='Approve Invoice Transfer'
|
|
50
|
+
description='Waiting for approval confirmation...'
|
|
51
|
+
>
|
|
52
|
+
<ViewOnExplorer txHash={txHash} />
|
|
53
|
+
</LoadingModal>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { PoolInfoType, toBigNumber, upScale } from '@huma-finance/shared'
|
|
2
|
+
import React, { useCallback } 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 { TxSendModal } from '../../TxSendModal'
|
|
9
|
+
|
|
10
|
+
type Props = {
|
|
11
|
+
poolInfo: PoolInfoType
|
|
12
|
+
tokenId: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function Transfer({ poolInfo, tokenId }: Props): React.ReactElement {
|
|
16
|
+
const dispatch = useAppDispatch()
|
|
17
|
+
const { decimals } = poolInfo.poolUnderlyingToken
|
|
18
|
+
const { borrowAmount } = useAppSelector(selectWidgetState)
|
|
19
|
+
const requestLoanBigNumber = toBigNumber(upScale(borrowAmount!, decimals))
|
|
20
|
+
|
|
21
|
+
const handleSuccess = useCallback(() => {
|
|
22
|
+
dispatch(setStep(WIDGET_STEP.Done))
|
|
23
|
+
}, [dispatch])
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<TxSendModal
|
|
27
|
+
poolInfo={poolInfo}
|
|
28
|
+
title='Transfer Invoice and Money'
|
|
29
|
+
method='drawdownWithReceivable'
|
|
30
|
+
params={[requestLoanBigNumber, poolInfo.assetAddress, tokenId]}
|
|
31
|
+
handleSuccess={handleSuccess}
|
|
32
|
+
/>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { useAppSelector } from '../../../hooks/useRedux'
|
|
3
|
+
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
4
|
+
import { TxDoneModal } from '../../TxDoneModal'
|
|
5
|
+
|
|
6
|
+
type Props = {
|
|
7
|
+
handleAction: () => void
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function Success({ handleAction }: Props): React.ReactElement {
|
|
11
|
+
const { borrowAmountNet, remainder, approveInfo } =
|
|
12
|
+
useAppSelector(selectWidgetState)
|
|
13
|
+
|
|
14
|
+
const content = [
|
|
15
|
+
`${borrowAmountNet} ${approveInfo?.tokenSymbol} is now in your wallet.`,
|
|
16
|
+
`The remaining ${remainder} ${approveInfo?.tokenSymbol} will be sent to your wallet when the invoice is paid.`,
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
return <TxDoneModal handleAction={handleAction} content={content} />
|
|
20
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Box, css, useTheme } from '@mui/material'
|
|
2
|
+
import { useWeb3React } from '@web3-react/core'
|
|
3
|
+
import { EAService, PoolInfoType } from '@huma-finance/shared'
|
|
4
|
+
import React, { useState } from 'react'
|
|
5
|
+
|
|
6
|
+
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
7
|
+
import { setError, setStep } from '../../../store/widgets.reducers'
|
|
8
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
9
|
+
import { CustomError } from '../../../utilTypes'
|
|
10
|
+
import { BottomButton } from '../../BottomButton'
|
|
11
|
+
import { ApproveLenderIcon } from '../../icons'
|
|
12
|
+
import { LoadingModal } from '../../LoadingModal'
|
|
13
|
+
import { WrapperModal } from '../../WrapperModal'
|
|
14
|
+
|
|
15
|
+
type Props = {
|
|
16
|
+
poolInfo: PoolInfoType
|
|
17
|
+
handleApproveSuccess: () => void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function Evaluation({
|
|
21
|
+
poolInfo,
|
|
22
|
+
handleApproveSuccess,
|
|
23
|
+
}: Props): React.ReactElement | null {
|
|
24
|
+
const theme = useTheme()
|
|
25
|
+
const dispatch = useAppDispatch()
|
|
26
|
+
const { account, chainId } = useWeb3React()
|
|
27
|
+
const [loading, setLoading] = useState(false)
|
|
28
|
+
|
|
29
|
+
const styles = {
|
|
30
|
+
iconWrapper: css`
|
|
31
|
+
${theme.cssMixins.rowCentered};
|
|
32
|
+
margin-top: 30px;
|
|
33
|
+
`,
|
|
34
|
+
description: css`
|
|
35
|
+
${theme.cssMixins.rowCentered};
|
|
36
|
+
margin-top: 50px;
|
|
37
|
+
font-family: 'Uni-Neue-Regular';
|
|
38
|
+
font-size: 16px;
|
|
39
|
+
color: #a8a1b2;
|
|
40
|
+
`,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const approveLender = async () => {
|
|
44
|
+
if (account) {
|
|
45
|
+
try {
|
|
46
|
+
setLoading(true)
|
|
47
|
+
const payload = {
|
|
48
|
+
poolAddress: poolInfo.pool,
|
|
49
|
+
lenderWalletAddress: account,
|
|
50
|
+
}
|
|
51
|
+
await EAService.approveLender(payload, chainId!)
|
|
52
|
+
handleApproveSuccess()
|
|
53
|
+
setLoading(false)
|
|
54
|
+
dispatch(setStep(WIDGET_STEP.ChooseAmount))
|
|
55
|
+
} catch (e: unknown) {
|
|
56
|
+
const error = e as CustomError
|
|
57
|
+
setLoading(false)
|
|
58
|
+
dispatch(setError({ errorMessage: error.message }))
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!loading) {
|
|
64
|
+
return (
|
|
65
|
+
<WrapperModal
|
|
66
|
+
title='Lender Approval'
|
|
67
|
+
subTitle='This pool requires lender approval'
|
|
68
|
+
>
|
|
69
|
+
<Box css={styles.iconWrapper}>
|
|
70
|
+
<ApproveLenderIcon />
|
|
71
|
+
</Box>
|
|
72
|
+
<Box css={styles.description} />
|
|
73
|
+
<BottomButton variant='contained' onClick={approveLender}>
|
|
74
|
+
GET APPROVED
|
|
75
|
+
</BottomButton>
|
|
76
|
+
</WrapperModal>
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<LoadingModal
|
|
82
|
+
title='Approval Pending'
|
|
83
|
+
description='Waiting for approval confirmation...'
|
|
84
|
+
/>
|
|
85
|
+
)
|
|
86
|
+
}
|