@huma-finance/widgets 0.0.48-beta.202 → 0.0.48-beta.279
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 +407 -0
- package/dist/cjs/index.cjs +6063 -3827
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.d.ts +248 -1
- package/dist/index.js +6056 -3829
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/components/ApproveAllowanceModal.tsx +3 -8
- package/src/components/ApproveAllowanceModalV2.tsx +141 -0
- package/src/components/CreditLine/approve/index.tsx +9 -3
- package/src/components/CreditLine/autoPaybackV2/1-ApproveAllowance.tsx +33 -0
- package/src/components/CreditLine/autoPaybackV2/2-Success.tsx +13 -0
- package/src/components/CreditLine/autoPaybackV2/index.tsx +87 -0
- package/src/components/CreditLine/borrow/2-ChooseAmount.tsx +12 -3
- package/src/components/CreditLine/borrow/index.tsx +4 -2
- package/src/components/CreditLine/borrowV2/1-ChooseAmount.tsx +79 -0
- package/src/components/CreditLine/borrowV2/2-ApproveAllowance.tsx +33 -0
- package/src/components/CreditLine/borrowV2/3-Transfer.tsx +50 -0
- package/src/components/CreditLine/borrowV2/4-Success.tsx +41 -0
- package/src/components/CreditLine/borrowV2/5-Notifications.tsx +10 -0
- package/src/components/CreditLine/borrowV2/index.tsx +140 -0
- package/src/components/CreditLine/payment/1-ChooseAmount.tsx +7 -2
- package/src/components/CreditLine/payment/index.tsx +4 -2
- package/src/components/CreditLine/paymentV2/1-ChooseAmount.tsx +86 -0
- package/src/components/CreditLine/paymentV2/2-ApproveAllowance.tsx +33 -0
- package/src/components/CreditLine/paymentV2/3-Transfer.tsx +55 -0
- package/src/components/CreditLine/paymentV2/4-Success.tsx +42 -0
- package/src/components/CreditLine/paymentV2/index.tsx +111 -0
- package/src/components/CreditLine/supplyFLC/1-ApproveAllowance.tsx +40 -0
- package/src/components/CreditLine/supplyFLC/2-Transfer.tsx +53 -0
- package/src/components/CreditLine/supplyFLC/3-Success.tsx +26 -0
- package/src/components/CreditLine/supplyFLC/index.tsx +121 -0
- package/src/components/Factoring/FactoredList.tsx +2 -1
- package/src/components/InvoiceFactoring/borrow/2-ChooseAmount.tsx +8 -1
- package/src/components/InvoiceFactoring/borrow/4-ApproveNFT.tsx +6 -2
- package/src/components/InvoiceFactoring/borrow/index.tsx +9 -3
- package/src/components/InvoiceFactoring/payment/1-ChooseAmount.tsx +7 -2
- package/src/components/InvoiceFactoring/payment/index.tsx +9 -3
- package/src/components/Lend/redeemV2/1-ChooseAction.tsx +236 -0
- package/src/components/Lend/redeemV2/2-ChooseAmount.tsx +162 -0
- package/src/components/Lend/redeemV2/3-Transfer.tsx +61 -0
- package/src/components/Lend/redeemV2/4-Done.tsx +33 -0
- package/src/components/Lend/redeemV2/index.tsx +207 -0
- package/src/components/Lend/supply/1-Evaluation/EvaluationKYC.tsx +19 -2
- package/src/components/Lend/supply/index.tsx +17 -3
- package/src/components/Lend/supplyV2/1-ChooseTranche.tsx +155 -0
- package/src/components/Lend/supplyV2/2-Evaluation.tsx +345 -0
- package/src/components/Lend/supplyV2/3-ChooseAmount.tsx +122 -0
- package/src/components/Lend/supplyV2/4-ApproveAllowance.tsx +33 -0
- package/src/components/Lend/supplyV2/5-Transfer.tsx +59 -0
- package/src/components/Lend/supplyV2/6-Success.tsx +79 -0
- package/src/components/Lend/supplyV2/7-Notifications.tsx +10 -0
- package/src/components/Lend/supplyV2/index.tsx +127 -0
- package/src/components/Lend/withdraw/1-CheckWithdrawble.tsx +5 -1
- package/src/components/Lend/withdraw/2-ChooseAmount.tsx +1 -7
- package/src/components/Lend/withdraw/index.tsx +8 -13
- package/src/components/Lend/withdrawV2/1-ChooseTranche.tsx +201 -0
- package/src/components/Lend/withdrawV2/2-Transfer.tsx +48 -0
- package/src/components/Lend/withdrawV2/3-Done.tsx +31 -0
- package/src/components/Lend/withdrawV2/index.tsx +129 -0
- package/src/components/Notifi/NotifiSubscriptionModal.tsx +29 -37
- package/src/components/NumericFormatCustom.tsx +31 -0
- package/src/components/ReceivableBackedCreditLine/borrow/1-ChooseAmount.tsx +101 -0
- package/src/components/ReceivableBackedCreditLine/borrow/2-ApproveAllowance.tsx +33 -0
- package/src/components/ReceivableBackedCreditLine/borrow/3-ApproveReceivable.tsx +64 -0
- package/src/components/ReceivableBackedCreditLine/borrow/4-Transfer.tsx +61 -0
- package/src/components/ReceivableBackedCreditLine/borrow/5-Success.tsx +41 -0
- package/src/components/ReceivableBackedCreditLine/borrow/6-Notifications.tsx +10 -0
- package/src/components/ReceivableBackedCreditLine/borrow/index.tsx +148 -0
- package/src/components/ReceivableBackedCreditLine/payment/1-ChoosePaymentType.tsx +115 -0
- package/src/components/ReceivableBackedCreditLine/payment/2-ChooseAmount.tsx +84 -0
- package/src/components/ReceivableBackedCreditLine/payment/3-ApproveAllowance.tsx +41 -0
- package/src/components/ReceivableBackedCreditLine/payment/4-CreateReceivable.tsx +107 -0
- package/src/components/ReceivableBackedCreditLine/payment/5-ApproveReceivable.tsx +64 -0
- package/src/components/ReceivableBackedCreditLine/payment/6-Transfer.tsx +107 -0
- package/src/components/ReceivableBackedCreditLine/payment/7-Success.tsx +49 -0
- package/src/components/ReceivableBackedCreditLine/payment/index.tsx +159 -0
- package/src/components/StreamFactoring/borrow/1-Evaluation.tsx +3 -4
- package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +23 -22
- package/src/components/StreamFactoring/borrow/3-ConfirmTransfer.tsx +8 -3
- package/src/components/StreamFactoring/borrow/5-Permit.tsx +35 -2
- package/src/components/StreamFactoring/borrow/6-Transfer.tsx +3 -1
- package/src/components/StreamFactoring/borrow/index.tsx +4 -3
- package/src/components/SuperfluidFactoring/SuperfluidFactoredList.tsx +2 -2
- package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +1 -3
- package/src/components/TxDoneModal.tsx +1 -1
- package/src/components/TxSendModal.tsx +8 -2
- package/src/components/TxSendModalV2.tsx +51 -0
- package/src/index.tsx +239 -1
- package/src/store/widgets.reducers.ts +15 -0
- package/src/store/widgets.store.ts +6 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {
|
|
2
|
+
css,
|
|
3
|
+
FormControl,
|
|
4
|
+
FormControlLabel,
|
|
5
|
+
FormLabel,
|
|
6
|
+
Radio,
|
|
7
|
+
RadioGroup,
|
|
8
|
+
useTheme,
|
|
9
|
+
} from '@mui/material'
|
|
10
|
+
import React from 'react'
|
|
11
|
+
|
|
12
|
+
import { PaymentType } from '.'
|
|
13
|
+
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
14
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
15
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
16
|
+
import { BottomButton } from '../../BottomButton'
|
|
17
|
+
import { WrapperModal } from '../../WrapperModal'
|
|
18
|
+
|
|
19
|
+
type Props = {
|
|
20
|
+
paymentType: PaymentType | undefined
|
|
21
|
+
changePaymentType: (paymentType: PaymentType) => void
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function ChoosePaymentType({
|
|
25
|
+
paymentType,
|
|
26
|
+
changePaymentType,
|
|
27
|
+
}: Props): React.ReactElement | null {
|
|
28
|
+
const theme = useTheme()
|
|
29
|
+
const dispatch = useAppDispatch()
|
|
30
|
+
|
|
31
|
+
const styles = {
|
|
32
|
+
subTitle: css`
|
|
33
|
+
color: ${theme.palette.text.primary} !important;
|
|
34
|
+
font-family: 'Uni-Neue-Regular';
|
|
35
|
+
font-size: 16px;
|
|
36
|
+
line-height: 150%;
|
|
37
|
+
letter-spacing: 0.15px;
|
|
38
|
+
margin-top: ${theme.spacing(5)};
|
|
39
|
+
margin-left: ${theme.spacing(2)};
|
|
40
|
+
`,
|
|
41
|
+
radioGroup: css`
|
|
42
|
+
margin-left: ${theme.spacing(3)};
|
|
43
|
+
margin-top: ${theme.spacing(3)};
|
|
44
|
+
`,
|
|
45
|
+
formControl: css`
|
|
46
|
+
margin-bottom: ${theme.spacing(1)};
|
|
47
|
+
.MuiFormControlLabel-label {
|
|
48
|
+
color: ${theme.palette.text.primary};
|
|
49
|
+
font-family: 'Uni-Neue-Regular';
|
|
50
|
+
font-size: 16px;
|
|
51
|
+
line-height: 150%;
|
|
52
|
+
letter-spacing: 0.15px;
|
|
53
|
+
}
|
|
54
|
+
`,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const handleNext = () => {
|
|
58
|
+
dispatch(setStep(WIDGET_STEP.ChooseAmount))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const items: {
|
|
62
|
+
label: string
|
|
63
|
+
value: PaymentType
|
|
64
|
+
}[] = [
|
|
65
|
+
{
|
|
66
|
+
label: 'Payment with Receivable',
|
|
67
|
+
value: PaymentType.PaymentWithReceivable,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
label: 'Payment with Receivable and Drawdown',
|
|
71
|
+
value: PaymentType.PaymentWithReceivableAndDrawdown,
|
|
72
|
+
},
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<WrapperModal title='Pay'>
|
|
77
|
+
<FormControl>
|
|
78
|
+
<FormLabel css={styles.subTitle}>Select Payment Type</FormLabel>
|
|
79
|
+
<RadioGroup
|
|
80
|
+
aria-labelledby='buttons-group-label'
|
|
81
|
+
name='radio-buttons-group'
|
|
82
|
+
css={styles.radioGroup}
|
|
83
|
+
onChange={(e) =>
|
|
84
|
+
changePaymentType(Number(e.target.value) as PaymentType)
|
|
85
|
+
}
|
|
86
|
+
>
|
|
87
|
+
{items.map((item) => (
|
|
88
|
+
<FormControlLabel
|
|
89
|
+
key={item.label}
|
|
90
|
+
value={item.value}
|
|
91
|
+
control={
|
|
92
|
+
<Radio
|
|
93
|
+
sx={{
|
|
94
|
+
'& .MuiSvgIcon-root': {
|
|
95
|
+
fontSize: 24,
|
|
96
|
+
},
|
|
97
|
+
}}
|
|
98
|
+
/>
|
|
99
|
+
}
|
|
100
|
+
label={item.label}
|
|
101
|
+
css={styles.formControl}
|
|
102
|
+
/>
|
|
103
|
+
))}
|
|
104
|
+
</RadioGroup>
|
|
105
|
+
</FormControl>
|
|
106
|
+
<BottomButton
|
|
107
|
+
variant='contained'
|
|
108
|
+
disabled={paymentType === undefined}
|
|
109
|
+
onClick={handleNext}
|
|
110
|
+
>
|
|
111
|
+
NEXT
|
|
112
|
+
</BottomButton>
|
|
113
|
+
</WrapperModal>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PoolInfoV2,
|
|
3
|
+
toBigNumber,
|
|
4
|
+
UnderlyingTokenInfo,
|
|
5
|
+
upScale,
|
|
6
|
+
usePoolSafeAllowanceV2,
|
|
7
|
+
} from '@huma-finance/shared'
|
|
8
|
+
import { useWeb3React } from '@web3-react/core'
|
|
9
|
+
import { BigNumber, ethers } from 'ethers'
|
|
10
|
+
import React, { useCallback, useState } from 'react'
|
|
11
|
+
|
|
12
|
+
import { PaymentType } from '.'
|
|
13
|
+
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
14
|
+
import { setPaymentAmount, setStep } from '../../../store/widgets.reducers'
|
|
15
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
16
|
+
import { ChooseAmountModal } from '../../ChooseAmountModal'
|
|
17
|
+
import { LoadingModal } from '../../LoadingModal'
|
|
18
|
+
|
|
19
|
+
type Props = {
|
|
20
|
+
payoffAmount: BigNumber
|
|
21
|
+
poolInfo: PoolInfoV2
|
|
22
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
23
|
+
paymentType: PaymentType
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function ChooseAmount({
|
|
27
|
+
payoffAmount: payoffAmountBN,
|
|
28
|
+
poolInfo,
|
|
29
|
+
poolUnderlyingToken,
|
|
30
|
+
paymentType,
|
|
31
|
+
}: Props): React.ReactElement | null {
|
|
32
|
+
const dispatch = useAppDispatch()
|
|
33
|
+
const { account, provider } = useWeb3React()
|
|
34
|
+
const { symbol, decimals } = poolUnderlyingToken
|
|
35
|
+
const [currentAmount, setCurrentAmount] = useState(0)
|
|
36
|
+
const { allowance } = usePoolSafeAllowanceV2(
|
|
37
|
+
poolInfo.poolName,
|
|
38
|
+
account,
|
|
39
|
+
provider,
|
|
40
|
+
)
|
|
41
|
+
const payoffAmount = Number(
|
|
42
|
+
ethers.utils.formatUnits(payoffAmountBN, decimals),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
const handleChangeAmount = useCallback(
|
|
46
|
+
(newAmount: number) => {
|
|
47
|
+
setCurrentAmount(newAmount)
|
|
48
|
+
dispatch(setPaymentAmount({ paymentAmount: newAmount }))
|
|
49
|
+
},
|
|
50
|
+
[dispatch],
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
const handleAction = useCallback(() => {
|
|
54
|
+
const payAmount = upScale(currentAmount, decimals)
|
|
55
|
+
if (toBigNumber(payAmount).gt(allowance!)) {
|
|
56
|
+
dispatch(setStep(WIDGET_STEP.ApproveAllowance))
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const step =
|
|
61
|
+
paymentType === PaymentType.PaymentWithReceivable
|
|
62
|
+
? WIDGET_STEP.Transfer
|
|
63
|
+
: WIDGET_STEP.MintNFT
|
|
64
|
+
dispatch(setStep(step))
|
|
65
|
+
}, [allowance, currentAmount, decimals, dispatch, paymentType])
|
|
66
|
+
|
|
67
|
+
if (!allowance) {
|
|
68
|
+
return <LoadingModal title='Pay' />
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<ChooseAmountModal
|
|
73
|
+
title='Pay'
|
|
74
|
+
description1='Choose amount'
|
|
75
|
+
sliderMax={payoffAmount}
|
|
76
|
+
currentAmount={currentAmount}
|
|
77
|
+
tokenSymbol={symbol}
|
|
78
|
+
handleChangeAmount={handleChangeAmount}
|
|
79
|
+
handleAction={handleAction}
|
|
80
|
+
actionText='pay'
|
|
81
|
+
hideTerms
|
|
82
|
+
/>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { PoolInfoV2, UnderlyingTokenInfo } from '@huma-finance/shared'
|
|
2
|
+
import React, { useCallback } from 'react'
|
|
3
|
+
|
|
4
|
+
import { PaymentType } from '.'
|
|
5
|
+
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
6
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
7
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
8
|
+
import { ApproveAllowanceModalV2 } from '../../ApproveAllowanceModalV2'
|
|
9
|
+
|
|
10
|
+
type Props = {
|
|
11
|
+
poolInfo: PoolInfoV2
|
|
12
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
13
|
+
paymentType: PaymentType
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function ApproveAllowance({
|
|
17
|
+
poolInfo,
|
|
18
|
+
poolUnderlyingToken,
|
|
19
|
+
paymentType,
|
|
20
|
+
}: Props): React.ReactElement {
|
|
21
|
+
const dispatch = useAppDispatch()
|
|
22
|
+
|
|
23
|
+
const handleSuccess = useCallback(() => {
|
|
24
|
+
const step =
|
|
25
|
+
paymentType === PaymentType.PaymentWithReceivable
|
|
26
|
+
? WIDGET_STEP.Transfer
|
|
27
|
+
: WIDGET_STEP.MintNFT
|
|
28
|
+
|
|
29
|
+
dispatch(setStep(step))
|
|
30
|
+
}, [dispatch, paymentType])
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<ApproveAllowanceModalV2
|
|
34
|
+
poolInfo={poolInfo}
|
|
35
|
+
spender={poolInfo.poolSafe}
|
|
36
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
37
|
+
handleSuccess={handleSuccess}
|
|
38
|
+
showAutoPayback
|
|
39
|
+
/>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { HumaContext, HumaReceivableFactory } from '@huma-finance/sdk'
|
|
2
|
+
import {
|
|
3
|
+
CURRENCY_CODE,
|
|
4
|
+
PoolInfoV2,
|
|
5
|
+
UnderlyingTokenInfo,
|
|
6
|
+
} from '@huma-finance/shared'
|
|
7
|
+
import { useWeb3React } from '@web3-react/core'
|
|
8
|
+
import { ContractReceipt, ethers } from 'ethers'
|
|
9
|
+
import moment from 'moment'
|
|
10
|
+
import React, { useCallback, useEffect, useState } from 'react'
|
|
11
|
+
|
|
12
|
+
import { useAppDispatch, 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 { LoadingModal } from '../../LoadingModal'
|
|
17
|
+
import { ViewOnExplorer } from '../../ViewOnExplorer'
|
|
18
|
+
|
|
19
|
+
type Props = {
|
|
20
|
+
poolInfo: PoolInfoV2
|
|
21
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
22
|
+
setTokenId: (tokenId: string) => void
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function CreateReceivable({
|
|
26
|
+
poolInfo,
|
|
27
|
+
poolUnderlyingToken,
|
|
28
|
+
setTokenId,
|
|
29
|
+
}: Props): React.ReactElement {
|
|
30
|
+
const dispatch = useAppDispatch()
|
|
31
|
+
const { provider, chainId } = useWeb3React()
|
|
32
|
+
const { paymentAmount } = useAppSelector(selectWidgetState)
|
|
33
|
+
const [txHash, setTxHash] = useState('')
|
|
34
|
+
|
|
35
|
+
const getTokenIdFromReceipt = useCallback((txReceipt: ContractReceipt) => {
|
|
36
|
+
if (!Array.isArray(txReceipt.events)) {
|
|
37
|
+
return undefined
|
|
38
|
+
}
|
|
39
|
+
const event = txReceipt.events.find(
|
|
40
|
+
(event) => event.event === 'ReceivableCreated',
|
|
41
|
+
)
|
|
42
|
+
if (!event || !event.args!! || !event.args?.tokenId) {
|
|
43
|
+
return undefined
|
|
44
|
+
}
|
|
45
|
+
return event.args.tokenId.toString() as string
|
|
46
|
+
}, [])
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
const sendTx = async () => {
|
|
50
|
+
if (provider && chainId) {
|
|
51
|
+
try {
|
|
52
|
+
const humaContext = new HumaContext({
|
|
53
|
+
signer: provider.getSigner(),
|
|
54
|
+
provider,
|
|
55
|
+
chainId,
|
|
56
|
+
poolName: poolInfo.poolName,
|
|
57
|
+
poolType: poolInfo.poolType,
|
|
58
|
+
})
|
|
59
|
+
const receivableFactory = new HumaReceivableFactory({
|
|
60
|
+
humaContext,
|
|
61
|
+
})
|
|
62
|
+
const receivableAmountBN = ethers.utils.parseUnits(
|
|
63
|
+
String(paymentAmount),
|
|
64
|
+
poolUnderlyingToken.decimals,
|
|
65
|
+
)
|
|
66
|
+
const maturityDate = moment().add(1, 'months').unix()
|
|
67
|
+
const tx = await receivableFactory.createReceivable(
|
|
68
|
+
CURRENCY_CODE.USD,
|
|
69
|
+
receivableAmountBN,
|
|
70
|
+
maturityDate,
|
|
71
|
+
'',
|
|
72
|
+
)
|
|
73
|
+
setTxHash(tx.hash)
|
|
74
|
+
const txReceipt = await tx.wait()
|
|
75
|
+
const tokenId = getTokenIdFromReceipt(txReceipt)
|
|
76
|
+
if (tokenId) {
|
|
77
|
+
setTokenId(tokenId)
|
|
78
|
+
}
|
|
79
|
+
dispatch(setStep(WIDGET_STEP.ApproveNFT))
|
|
80
|
+
} catch (e) {
|
|
81
|
+
console.log(e)
|
|
82
|
+
dispatch(setStep(WIDGET_STEP.Error))
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
sendTx()
|
|
87
|
+
}, [
|
|
88
|
+
chainId,
|
|
89
|
+
dispatch,
|
|
90
|
+
getTokenIdFromReceipt,
|
|
91
|
+
paymentAmount,
|
|
92
|
+
poolInfo.poolName,
|
|
93
|
+
poolInfo.poolType,
|
|
94
|
+
poolUnderlyingToken.decimals,
|
|
95
|
+
provider,
|
|
96
|
+
setTokenId,
|
|
97
|
+
])
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<LoadingModal
|
|
101
|
+
title='Create Receivable'
|
|
102
|
+
description='Waiting for confirmation...'
|
|
103
|
+
>
|
|
104
|
+
<ViewOnExplorer txHash={txHash} />
|
|
105
|
+
</LoadingModal>
|
|
106
|
+
)
|
|
107
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PoolInfoV2,
|
|
3
|
+
sendTxAtom,
|
|
4
|
+
txAtom,
|
|
5
|
+
TxStateType,
|
|
6
|
+
useReceivableContractV2,
|
|
7
|
+
} from '@huma-finance/shared'
|
|
8
|
+
import { useWeb3React } from '@web3-react/core'
|
|
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: PoolInfoV2
|
|
21
|
+
tokenId: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function ApproveReceivable({
|
|
25
|
+
poolInfo,
|
|
26
|
+
tokenId,
|
|
27
|
+
}: Props): React.ReactElement {
|
|
28
|
+
const dispatch = useAppDispatch()
|
|
29
|
+
const { provider, account } = useWeb3React()
|
|
30
|
+
const [{ state, txHash }, send] = useAtom(sendTxAtom)
|
|
31
|
+
const reset = useResetAtom(txAtom)
|
|
32
|
+
const receivableContract = useReceivableContractV2(
|
|
33
|
+
poolInfo.poolName,
|
|
34
|
+
provider,
|
|
35
|
+
account,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (state === TxStateType.Success) {
|
|
40
|
+
reset()
|
|
41
|
+
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
42
|
+
}
|
|
43
|
+
}, [dispatch, reset, state])
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (receivableContract) {
|
|
47
|
+
send({
|
|
48
|
+
contract: receivableContract,
|
|
49
|
+
method: 'approve',
|
|
50
|
+
params: [poolInfo.poolCredit, tokenId],
|
|
51
|
+
provider,
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
}, [poolInfo.poolCredit, provider, receivableContract, send, tokenId])
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<LoadingModal
|
|
58
|
+
title='Approve Receivable'
|
|
59
|
+
description='Waiting for approval confirmation...'
|
|
60
|
+
>
|
|
61
|
+
<ViewOnExplorer txHash={txHash} />
|
|
62
|
+
</LoadingModal>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { TransactionResponse } from '@ethersproject/providers'
|
|
2
|
+
import {
|
|
3
|
+
makePaymentWithReceivable,
|
|
4
|
+
makePrincipalPaymentAndDrawdownWithReceivable,
|
|
5
|
+
} from '@huma-finance/sdk'
|
|
6
|
+
import {
|
|
7
|
+
PoolInfoV2,
|
|
8
|
+
toBigNumber,
|
|
9
|
+
UnderlyingTokenInfo,
|
|
10
|
+
upScale,
|
|
11
|
+
} from '@huma-finance/shared'
|
|
12
|
+
import { useWeb3React } from '@web3-react/core'
|
|
13
|
+
import { ethers } from 'ethers'
|
|
14
|
+
import React, { useEffect, useState } from 'react'
|
|
15
|
+
|
|
16
|
+
import { PaymentType } from '.'
|
|
17
|
+
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
18
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
19
|
+
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
20
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
21
|
+
import { LoadingModal } from '../../LoadingModal'
|
|
22
|
+
import { ViewOnExplorer } from '../../ViewOnExplorer'
|
|
23
|
+
|
|
24
|
+
type Props = {
|
|
25
|
+
poolInfo: PoolInfoV2
|
|
26
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
27
|
+
paymentType: PaymentType
|
|
28
|
+
paymentTokenId: string
|
|
29
|
+
borrowTokenId?: string
|
|
30
|
+
setSuccessTxReceipt: (txReceipt: ethers.ContractReceipt) => void
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function Transfer({
|
|
34
|
+
poolInfo,
|
|
35
|
+
poolUnderlyingToken,
|
|
36
|
+
paymentType,
|
|
37
|
+
paymentTokenId,
|
|
38
|
+
borrowTokenId,
|
|
39
|
+
setSuccessTxReceipt,
|
|
40
|
+
}: Props): React.ReactElement {
|
|
41
|
+
const dispatch = useAppDispatch()
|
|
42
|
+
const { account, provider } = useWeb3React()
|
|
43
|
+
const { paymentAmount } = useAppSelector(selectWidgetState)
|
|
44
|
+
const { decimals } = poolUnderlyingToken
|
|
45
|
+
const paymentAmountBN = toBigNumber(
|
|
46
|
+
upScale(paymentAmount!, decimals),
|
|
47
|
+
).toString()
|
|
48
|
+
const [txHash, setTxHash] = useState('')
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
const sendTx = async () => {
|
|
52
|
+
if (provider) {
|
|
53
|
+
try {
|
|
54
|
+
let tx: TransactionResponse
|
|
55
|
+
if (paymentType === PaymentType.PaymentWithReceivable) {
|
|
56
|
+
tx = await makePaymentWithReceivable(
|
|
57
|
+
provider.getSigner(),
|
|
58
|
+
poolInfo.poolName,
|
|
59
|
+
paymentTokenId,
|
|
60
|
+
paymentAmountBN,
|
|
61
|
+
false,
|
|
62
|
+
)
|
|
63
|
+
} else {
|
|
64
|
+
tx = await makePrincipalPaymentAndDrawdownWithReceivable(
|
|
65
|
+
provider.getSigner(),
|
|
66
|
+
poolInfo.poolName,
|
|
67
|
+
paymentTokenId,
|
|
68
|
+
paymentAmountBN,
|
|
69
|
+
borrowTokenId!,
|
|
70
|
+
paymentAmountBN,
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
setTxHash(tx.hash)
|
|
74
|
+
const txReceipt = await tx.wait()
|
|
75
|
+
setSuccessTxReceipt(txReceipt)
|
|
76
|
+
dispatch(setStep(WIDGET_STEP.Done))
|
|
77
|
+
} catch (e) {
|
|
78
|
+
console.error(e)
|
|
79
|
+
dispatch(setStep(WIDGET_STEP.Error))
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
sendTx()
|
|
84
|
+
}, [
|
|
85
|
+
borrowTokenId,
|
|
86
|
+
dispatch,
|
|
87
|
+
paymentAmountBN,
|
|
88
|
+
paymentTokenId,
|
|
89
|
+
paymentType,
|
|
90
|
+
poolInfo.poolName,
|
|
91
|
+
provider,
|
|
92
|
+
setSuccessTxReceipt,
|
|
93
|
+
])
|
|
94
|
+
|
|
95
|
+
if (!account) {
|
|
96
|
+
return <LoadingModal title='Pay' />
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<LoadingModal
|
|
101
|
+
title='Transaction Pending'
|
|
102
|
+
description='Waiting for confirmation...'
|
|
103
|
+
>
|
|
104
|
+
<ViewOnExplorer txHash={txHash} />
|
|
105
|
+
</LoadingModal>
|
|
106
|
+
)
|
|
107
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decodeLogs,
|
|
3
|
+
downScale,
|
|
4
|
+
formatMoney,
|
|
5
|
+
TRANSFER_ABI,
|
|
6
|
+
UnderlyingTokenInfo,
|
|
7
|
+
} from '@huma-finance/shared'
|
|
8
|
+
import { ethers } from 'ethers'
|
|
9
|
+
import React, { useEffect, useState } from 'react'
|
|
10
|
+
|
|
11
|
+
import { PaymentType } from '.'
|
|
12
|
+
import { TxDoneModal } from '../../TxDoneModal'
|
|
13
|
+
|
|
14
|
+
type Props = {
|
|
15
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
16
|
+
paymentType: PaymentType
|
|
17
|
+
successTxReceipt: ethers.ContractReceipt
|
|
18
|
+
handleAction: () => void
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function Success({
|
|
22
|
+
poolUnderlyingToken,
|
|
23
|
+
paymentType,
|
|
24
|
+
successTxReceipt,
|
|
25
|
+
handleAction,
|
|
26
|
+
}: Props): React.ReactElement {
|
|
27
|
+
const { symbol, decimals } = poolUnderlyingToken
|
|
28
|
+
const [paidAmount, setPaidAmount] = useState<string | undefined>()
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (successTxReceipt) {
|
|
32
|
+
const [event] = decodeLogs(successTxReceipt.logs, TRANSFER_ABI)
|
|
33
|
+
if (event) {
|
|
34
|
+
const paidAmount = downScale(event.args.value.toString(), decimals)
|
|
35
|
+
setPaidAmount(paidAmount)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}, [decimals, successTxReceipt])
|
|
39
|
+
|
|
40
|
+
const amoutFormatted = formatMoney(paidAmount)
|
|
41
|
+
const content =
|
|
42
|
+
paymentType === PaymentType.PaymentWithReceivable
|
|
43
|
+
? [`You successfully paid ${amoutFormatted} ${symbol}.`]
|
|
44
|
+
: [
|
|
45
|
+
`You successfully paid ${amoutFormatted} ${symbol} and borrowed ${amoutFormatted} ${symbol}.`,
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
return <TxDoneModal handleAction={handleAction} content={content} />
|
|
49
|
+
}
|