@huma-finance/widgets 0.0.48-beta.202 → 0.0.48-beta.280
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,159 @@
|
|
|
1
|
+
import {
|
|
2
|
+
POOL_NAME,
|
|
3
|
+
useCreditStatsV2,
|
|
4
|
+
usePoolInfoV2,
|
|
5
|
+
usePoolUnderlyingTokenInfoV2,
|
|
6
|
+
useReceivableInfoV2,
|
|
7
|
+
} from '@huma-finance/shared'
|
|
8
|
+
import { useWeb3React } from '@web3-react/core'
|
|
9
|
+
import { BigNumber, ethers } from 'ethers'
|
|
10
|
+
import React, { useEffect, useState } from 'react'
|
|
11
|
+
import { useDispatch } from 'react-redux'
|
|
12
|
+
|
|
13
|
+
import { useAppSelector } from '../../../hooks/useRedux'
|
|
14
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
15
|
+
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
16
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
17
|
+
import { ErrorModal } from '../../ErrorModal'
|
|
18
|
+
import { WidgetWrapper } from '../../WidgetWrapper'
|
|
19
|
+
import { ChoosePaymentType } from './1-ChoosePaymentType'
|
|
20
|
+
import { ChooseAmount } from './2-ChooseAmount'
|
|
21
|
+
import { ApproveAllowance } from './3-ApproveAllowance'
|
|
22
|
+
import { CreateReceivable } from './4-CreateReceivable'
|
|
23
|
+
import { ApproveReceivable } from './5-ApproveReceivable'
|
|
24
|
+
import { Transfer } from './6-Transfer'
|
|
25
|
+
import { Success } from './7-Success'
|
|
26
|
+
|
|
27
|
+
export enum PaymentType {
|
|
28
|
+
PaymentWithReceivable = 1,
|
|
29
|
+
PaymentWithReceivableAndDrawdown = 2,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Credit line pool payment props V2
|
|
34
|
+
* @typedef {Object} CreditLinePaymentPropsV2
|
|
35
|
+
* @property {POOL_NAME} poolName The name of the pool.
|
|
36
|
+
* @property {tokenId} tokenID The receivable token id.
|
|
37
|
+
* @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
|
|
38
|
+
* @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the credit line pool payment action is successful.
|
|
39
|
+
*/
|
|
40
|
+
export type ReceivableBackedCreditLinePaymentPropsV2 = {
|
|
41
|
+
poolName: keyof typeof POOL_NAME
|
|
42
|
+
tokenId: string
|
|
43
|
+
handleClose: () => void
|
|
44
|
+
handleSuccess?: (blockNumber?: number) => void
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function ReceivableBackedCreditLinePaymentV2({
|
|
48
|
+
poolName: poolNameStr,
|
|
49
|
+
tokenId,
|
|
50
|
+
handleClose,
|
|
51
|
+
handleSuccess,
|
|
52
|
+
}: ReceivableBackedCreditLinePaymentPropsV2): React.ReactElement | null {
|
|
53
|
+
const dispatch = useDispatch()
|
|
54
|
+
const { account, chainId, provider } = useWeb3React()
|
|
55
|
+
const poolName = POOL_NAME[poolNameStr]
|
|
56
|
+
const poolInfo = usePoolInfoV2(poolName, chainId)
|
|
57
|
+
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
58
|
+
const [{ creditRecord }] = useCreditStatsV2(poolName, account, provider)
|
|
59
|
+
const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
|
|
60
|
+
const [paymentType, setPaymentType] = useState<PaymentType>()
|
|
61
|
+
|
|
62
|
+
const [borrowTokenId, setBorrowTokenId] = useState<string>()
|
|
63
|
+
const paymentReceivableInfo = useReceivableInfoV2(poolName, tokenId, provider)
|
|
64
|
+
const payoffAmount = paymentReceivableInfo
|
|
65
|
+
? BigNumber.from(paymentReceivableInfo.receivableAmount).sub(
|
|
66
|
+
paymentReceivableInfo.paidAmount,
|
|
67
|
+
)
|
|
68
|
+
: BigNumber.from(0)
|
|
69
|
+
const [successTxReceipt, setSuccessTxReceipt] =
|
|
70
|
+
useState<ethers.ContractReceipt>()
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
dispatch(setStep(WIDGET_STEP.ChoosePaymentType))
|
|
74
|
+
}, [dispatch])
|
|
75
|
+
|
|
76
|
+
if (
|
|
77
|
+
!poolInfo ||
|
|
78
|
+
!creditRecord ||
|
|
79
|
+
!poolUnderlyingToken ||
|
|
80
|
+
!paymentReceivableInfo
|
|
81
|
+
) {
|
|
82
|
+
return (
|
|
83
|
+
<WidgetWrapper
|
|
84
|
+
isOpen
|
|
85
|
+
isLoading
|
|
86
|
+
loadingTitle='Pay'
|
|
87
|
+
handleClose={handleClose}
|
|
88
|
+
handleSuccess={handleSuccess}
|
|
89
|
+
/>
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<WidgetWrapper
|
|
95
|
+
isOpen
|
|
96
|
+
isLoading={!creditRecord}
|
|
97
|
+
loadingTitle='Pay'
|
|
98
|
+
handleClose={handleClose}
|
|
99
|
+
handleSuccess={handleSuccess}
|
|
100
|
+
>
|
|
101
|
+
{step === WIDGET_STEP.ChoosePaymentType && (
|
|
102
|
+
<ChoosePaymentType
|
|
103
|
+
paymentType={paymentType}
|
|
104
|
+
changePaymentType={setPaymentType}
|
|
105
|
+
/>
|
|
106
|
+
)}
|
|
107
|
+
{step === WIDGET_STEP.ChooseAmount && paymentType && (
|
|
108
|
+
<ChooseAmount
|
|
109
|
+
poolInfo={poolInfo}
|
|
110
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
111
|
+
payoffAmount={payoffAmount}
|
|
112
|
+
paymentType={paymentType}
|
|
113
|
+
/>
|
|
114
|
+
)}
|
|
115
|
+
{step === WIDGET_STEP.ApproveAllowance && paymentType && (
|
|
116
|
+
<ApproveAllowance
|
|
117
|
+
poolInfo={poolInfo}
|
|
118
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
119
|
+
paymentType={paymentType}
|
|
120
|
+
/>
|
|
121
|
+
)}
|
|
122
|
+
{step === WIDGET_STEP.MintNFT && (
|
|
123
|
+
<CreateReceivable
|
|
124
|
+
poolInfo={poolInfo}
|
|
125
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
126
|
+
setTokenId={setBorrowTokenId}
|
|
127
|
+
/>
|
|
128
|
+
)}
|
|
129
|
+
{step === WIDGET_STEP.ApproveNFT && borrowTokenId && (
|
|
130
|
+
<ApproveReceivable poolInfo={poolInfo} tokenId={borrowTokenId} />
|
|
131
|
+
)}
|
|
132
|
+
{step === WIDGET_STEP.Transfer && paymentType && (
|
|
133
|
+
<Transfer
|
|
134
|
+
poolInfo={poolInfo}
|
|
135
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
136
|
+
paymentType={paymentType}
|
|
137
|
+
paymentTokenId={tokenId}
|
|
138
|
+
borrowTokenId={borrowTokenId}
|
|
139
|
+
setSuccessTxReceipt={setSuccessTxReceipt}
|
|
140
|
+
/>
|
|
141
|
+
)}
|
|
142
|
+
{step === WIDGET_STEP.Done && paymentType && successTxReceipt && (
|
|
143
|
+
<Success
|
|
144
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
145
|
+
paymentType={paymentType}
|
|
146
|
+
handleAction={handleClose}
|
|
147
|
+
successTxReceipt={successTxReceipt}
|
|
148
|
+
/>
|
|
149
|
+
)}
|
|
150
|
+
{step === WIDGET_STEP.Error && (
|
|
151
|
+
<ErrorModal
|
|
152
|
+
title='Pay'
|
|
153
|
+
errorMessage={errorMessage}
|
|
154
|
+
handleOk={handleClose}
|
|
155
|
+
/>
|
|
156
|
+
)}
|
|
157
|
+
</WidgetWrapper>
|
|
158
|
+
)
|
|
159
|
+
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { getAddress } from '@ethersproject/address'
|
|
2
|
-
import { PoolInfoType } from '@huma-finance/shared'
|
|
3
1
|
import { useWeb3React } from '@web3-react/core'
|
|
2
|
+
import { PoolInfoType } from '@huma-finance/shared'
|
|
4
3
|
import React, { useEffect } from 'react'
|
|
5
4
|
|
|
6
5
|
import useEA from '../../../hooks/useEA'
|
|
7
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
8
6
|
import { LoadingModal } from '../../LoadingModal'
|
|
7
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
9
8
|
import { SignIn } from '../../SignIn'
|
|
10
9
|
|
|
11
10
|
type Props = {
|
|
@@ -36,7 +35,7 @@ export function Evaluation({
|
|
|
36
35
|
receivable: {
|
|
37
36
|
address: poolInfo.assetAddress!,
|
|
38
37
|
},
|
|
39
|
-
payerWalletAddress:
|
|
38
|
+
payerWalletAddress: payerAddress,
|
|
40
39
|
superToken,
|
|
41
40
|
},
|
|
42
41
|
},
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
} from '@huma-finance/shared'
|
|
8
8
|
import React, { useCallback, useState } from 'react'
|
|
9
9
|
|
|
10
|
+
import { useWeb3React } from '@web3-react/core'
|
|
10
11
|
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
11
12
|
import { setBorrowInfo, setStream } from '../../../store/widgets.reducers'
|
|
12
13
|
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
@@ -23,29 +24,31 @@ export function ChooseAmount({
|
|
|
23
24
|
currentFlowRate,
|
|
24
25
|
}: Props): React.ReactElement | null {
|
|
25
26
|
const dispatch = useAppDispatch()
|
|
27
|
+
const { chainId, provider } = useWeb3React()
|
|
26
28
|
const { approval } = useAppSelector(selectWidgetState)
|
|
27
|
-
const { getFeesCharged } = useFeeManager(
|
|
29
|
+
const { getFeesCharged } = useFeeManager(
|
|
30
|
+
poolInfo.poolName,
|
|
31
|
+
poolInfo.poolType,
|
|
32
|
+
chainId,
|
|
33
|
+
provider,
|
|
34
|
+
)
|
|
28
35
|
const [chargedFees, setChargedFees] = useState(0)
|
|
29
36
|
const [currentAmount, setCurrentAmount] = useState(0)
|
|
30
37
|
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
|
|
35
38
|
|
|
36
39
|
const getBorrowFlowrateAndAmount = useCallback(
|
|
37
40
|
(borrowAmount: number) => {
|
|
38
41
|
const currentFlowRateBN = toBigNumber(currentFlowRate)
|
|
39
|
-
const
|
|
40
|
-
upScale(borrowAmount,
|
|
42
|
+
const borrowAmountBN = toBigNumber(
|
|
43
|
+
upScale(borrowAmount, approval!.token.decimal),
|
|
41
44
|
)
|
|
42
45
|
|
|
43
|
-
const
|
|
46
|
+
const totalAmountInBorrowPeriod = currentFlowRateBN.mul(
|
|
44
47
|
borrowPeriodInSeconds,
|
|
45
48
|
)
|
|
46
|
-
let borrowFlowrate =
|
|
49
|
+
let borrowFlowrate = borrowAmountBN
|
|
47
50
|
.mul(currentFlowRateBN)
|
|
48
|
-
.div(
|
|
51
|
+
.div(totalAmountInBorrowPeriod)
|
|
49
52
|
// To ensure enough flowRate due to round down when convert to string
|
|
50
53
|
.add(1)
|
|
51
54
|
|
|
@@ -53,28 +56,26 @@ export function ChooseAmount({
|
|
|
53
56
|
if (borrowFlowrate.gte(currentFlowRateBN)) {
|
|
54
57
|
borrowFlowrate = currentFlowRateBN.sub(1)
|
|
55
58
|
}
|
|
59
|
+
if (borrowAmountBN.gte(approval!.terms.creditLimit)) {
|
|
60
|
+
borrowFlowrate = borrowFlowrate.sub(1)
|
|
61
|
+
}
|
|
56
62
|
|
|
57
63
|
// As borrowFlowrate adds 1, need to calculate the new accurate borrow amount
|
|
58
64
|
const newBorrowAmountBN = borrowFlowrate
|
|
59
|
-
.mul(
|
|
65
|
+
.mul(totalAmountInBorrowPeriod)
|
|
60
66
|
.div(currentFlowRateBN)
|
|
61
|
-
const newBorrowAmount = downScale(
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
const newBorrowAmount = downScale(
|
|
68
|
+
newBorrowAmountBN,
|
|
69
|
+
approval!.token.decimal,
|
|
64
70
|
)
|
|
65
71
|
|
|
66
72
|
return {
|
|
67
73
|
borrowFlowrate: borrowFlowrate.toString(),
|
|
68
74
|
borrowAmount: Number(newBorrowAmount),
|
|
69
|
-
borrowAmountBN:
|
|
75
|
+
borrowAmountBN: newBorrowAmountBN,
|
|
70
76
|
}
|
|
71
77
|
},
|
|
72
|
-
[
|
|
73
|
-
borrowPeriodInSeconds,
|
|
74
|
-
currentFlowRate,
|
|
75
|
-
superTokenDecimals,
|
|
76
|
-
underlyingTokenDecimals,
|
|
77
|
-
],
|
|
78
|
+
[approval, borrowPeriodInSeconds, currentFlowRate],
|
|
78
79
|
)
|
|
79
80
|
|
|
80
81
|
const handleChangeAmount = useCallback(
|
|
@@ -120,7 +121,7 @@ export function ChooseAmount({
|
|
|
120
121
|
<ChooseAmountModal
|
|
121
122
|
title='Choose Amount'
|
|
122
123
|
description1='Access up to 100% of your stream flowrate'
|
|
123
|
-
sliderMax={
|
|
124
|
+
sliderMax={Number(approval.terms.creditLimitFormatted)}
|
|
124
125
|
currentAmount={currentAmount}
|
|
125
126
|
tokenSymbol={approval.token.symbol}
|
|
126
127
|
topLeft='Fees'
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { isEmpty } from '@huma-finance/shared'
|
|
1
|
+
import { CHAINS, isEmpty } from '@huma-finance/shared'
|
|
2
|
+
import { useWeb3React } from '@web3-react/core'
|
|
2
3
|
import React, { useCallback } from 'react'
|
|
3
4
|
|
|
4
5
|
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
@@ -9,11 +10,15 @@ import { ConfirmTransferModal } from '../../ConfirmTransferModal'
|
|
|
9
10
|
|
|
10
11
|
export function ConfirmTransfer(): React.ReactElement | null {
|
|
11
12
|
const dispatch = useAppDispatch()
|
|
13
|
+
const { chainId } = useWeb3React()
|
|
12
14
|
const { borrowAmount, approval } = useAppSelector(selectWidgetState)
|
|
13
15
|
|
|
14
16
|
const handleAction = useCallback(() => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
const step = CHAINS[chainId!].isTestnet
|
|
18
|
+
? WIDGET_STEP.ApproveAllowance
|
|
19
|
+
: WIDGET_STEP.Permit
|
|
20
|
+
dispatch(setStep(step))
|
|
21
|
+
}, [chainId, dispatch])
|
|
17
22
|
|
|
18
23
|
if (isEmpty(borrowAmount) || isEmpty(approval)) {
|
|
19
24
|
return null
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
+
CHAINS,
|
|
3
|
+
Erc2612,
|
|
2
4
|
PoolInfoType,
|
|
3
5
|
SuperfluidPoolProcessor,
|
|
4
|
-
SuperfluidPoolProcessor_ABI,
|
|
5
6
|
useERC2612Permit,
|
|
6
7
|
useMount,
|
|
8
|
+
ERC2612_ABI,
|
|
9
|
+
SuperfluidPoolProcessor_ABI,
|
|
7
10
|
} from '@huma-finance/shared'
|
|
8
11
|
import { BigNumber, Contract, ethers } from 'ethers'
|
|
9
12
|
import React from 'react'
|
|
@@ -22,6 +25,7 @@ import { LoadingModal } from '../../LoadingModal'
|
|
|
22
25
|
type Props = {
|
|
23
26
|
poolInfo: PoolInfoType
|
|
24
27
|
payerAddress: string
|
|
28
|
+
chainId: number
|
|
25
29
|
borrower: string
|
|
26
30
|
superToken: string
|
|
27
31
|
}
|
|
@@ -29,15 +33,36 @@ type Props = {
|
|
|
29
33
|
export function Permit({
|
|
30
34
|
poolInfo,
|
|
31
35
|
payerAddress,
|
|
36
|
+
chainId,
|
|
32
37
|
borrower,
|
|
33
38
|
superToken,
|
|
34
39
|
}: Props): React.ReactElement | null {
|
|
35
40
|
const dispatch = useDispatch()
|
|
41
|
+
const { address: tokenAddress } = poolInfo.poolUnderlyingToken
|
|
36
42
|
const { borrowAmountBN: borrowAmountBNJson, stream } =
|
|
37
43
|
useAppSelector(selectWidgetState)
|
|
38
|
-
const { getTradableStreamPermitMessage } =
|
|
44
|
+
const { getERC2612PermitMessage, getTradableStreamPermitMessage } =
|
|
45
|
+
useERC2612Permit()
|
|
39
46
|
const borrowAmountBN = BigNumber.from(borrowAmountBNJson)
|
|
40
47
|
|
|
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
|
+
|
|
41
66
|
const getDrawdownCallData = async () => {
|
|
42
67
|
const NFTPermitResult = await getTradableStreamPermitMessage(
|
|
43
68
|
poolInfo.assetAddress!,
|
|
@@ -88,6 +113,14 @@ export function Permit({
|
|
|
88
113
|
try {
|
|
89
114
|
const callData = []
|
|
90
115
|
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
|
+
|
|
91
124
|
const drawdownCalldata = await getDrawdownCallData()
|
|
92
125
|
addresses.push(poolInfo.poolProcessor!)
|
|
93
126
|
callData.push(drawdownCalldata)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PoolInfoType, useMultiSendContract } from '@huma-finance/shared'
|
|
2
2
|
import React, { useCallback } from 'react'
|
|
3
3
|
|
|
4
|
+
import { useWeb3React } from '@web3-react/core'
|
|
4
5
|
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
5
6
|
import { setStep } from '../../../store/widgets.reducers'
|
|
6
7
|
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
@@ -13,8 +14,9 @@ type Props = {
|
|
|
13
14
|
|
|
14
15
|
export function Transfer({ poolInfo }: Props): React.ReactElement | null {
|
|
15
16
|
const dispatch = useAppDispatch()
|
|
16
|
-
const
|
|
17
|
+
const { chainId, provider } = useWeb3React()
|
|
17
18
|
const { multisend } = useAppSelector(selectWidgetState)
|
|
19
|
+
const multiSendContract = useMultiSendContract(chainId, provider)
|
|
18
20
|
|
|
19
21
|
const handleSuccess = useCallback(() => {
|
|
20
22
|
dispatch(setStep(WIDGET_STEP.Done))
|
|
@@ -39,8 +39,8 @@ export function StreamFactoringBorrow({
|
|
|
39
39
|
handleSuccess,
|
|
40
40
|
}: StreamFactoringBorrowProps): React.ReactElement | null {
|
|
41
41
|
const dispatch = useDispatch()
|
|
42
|
-
const { account } = useWeb3React()
|
|
43
|
-
const poolInfo = usePoolInfo(poolName, poolType)
|
|
42
|
+
const { account, chainId } = useWeb3React()
|
|
43
|
+
const poolInfo = usePoolInfo(poolName, poolType, chainId)
|
|
44
44
|
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
45
45
|
|
|
46
46
|
useEffect(() => {
|
|
@@ -71,10 +71,11 @@ 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 && chainId && (
|
|
75
75
|
<Permit
|
|
76
76
|
poolInfo={poolInfo}
|
|
77
77
|
payerAddress={payerAddress}
|
|
78
|
+
chainId={chainId}
|
|
78
79
|
borrower={account}
|
|
79
80
|
superToken={superToken}
|
|
80
81
|
/>
|
|
@@ -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?.superTokens?.[0].symbol ?? '',
|
|
54
54
|
}),
|
|
55
|
-
[poolInfo?.extra?.
|
|
55
|
+
[poolInfo?.extra?.superTokens],
|
|
56
56
|
)
|
|
57
57
|
|
|
58
58
|
return (
|
|
@@ -106,9 +106,7 @@ 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?.
|
|
110
|
-
? [poolInfo.extra.superToken.id]
|
|
111
|
-
: [],
|
|
109
|
+
tokenIds: poolInfo?.extra?.superTokens?.map((item) => item.id) ?? [],
|
|
112
110
|
},
|
|
113
111
|
})
|
|
114
112
|
|
|
@@ -32,8 +32,14 @@ export function TxSendModal({
|
|
|
32
32
|
handleSuccess,
|
|
33
33
|
}: Props): React.ReactElement {
|
|
34
34
|
const dispatch = useAppDispatch()
|
|
35
|
-
const { provider } = useWeb3React()
|
|
36
|
-
const poolContract = usePoolContract(
|
|
35
|
+
const { provider, chainId, account } = useWeb3React()
|
|
36
|
+
const poolContract = usePoolContract(
|
|
37
|
+
poolInfo.poolName,
|
|
38
|
+
poolInfo.poolType,
|
|
39
|
+
chainId,
|
|
40
|
+
provider,
|
|
41
|
+
account,
|
|
42
|
+
)
|
|
37
43
|
const [{ state, txHash }, send] = useAtom(sendTxAtom)
|
|
38
44
|
|
|
39
45
|
useEffect(() => {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { sendTxAtom, TxStateType, useMount } from '@huma-finance/shared'
|
|
2
|
+
import { useWeb3React } from '@web3-react/core'
|
|
3
|
+
import { Contract } from 'ethers'
|
|
4
|
+
import { useAtom } from 'jotai'
|
|
5
|
+
import React, { useEffect } from 'react'
|
|
6
|
+
|
|
7
|
+
import { useAppDispatch } from '../hooks/useRedux'
|
|
8
|
+
import { LoadingModal } from './LoadingModal'
|
|
9
|
+
import { ViewOnExplorer } from './ViewOnExplorer'
|
|
10
|
+
|
|
11
|
+
type Props = {
|
|
12
|
+
method: string
|
|
13
|
+
params: unknown[]
|
|
14
|
+
title?: string
|
|
15
|
+
contract: Contract
|
|
16
|
+
handleSuccess?: () => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function TxSendModalV2({
|
|
20
|
+
title,
|
|
21
|
+
method,
|
|
22
|
+
params,
|
|
23
|
+
contract,
|
|
24
|
+
handleSuccess,
|
|
25
|
+
}: Props): React.ReactElement {
|
|
26
|
+
const dispatch = useAppDispatch()
|
|
27
|
+
const { provider } = useWeb3React()
|
|
28
|
+
|
|
29
|
+
const [{ state, txHash }, send] = useAtom(sendTxAtom)
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (state === TxStateType.Success) {
|
|
33
|
+
if (handleSuccess) {
|
|
34
|
+
handleSuccess()
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}, [dispatch, handleSuccess, state])
|
|
38
|
+
|
|
39
|
+
useMount(() => {
|
|
40
|
+
send({ contract, method, params, provider })
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<LoadingModal
|
|
45
|
+
title={title ?? 'Transaction Pending'}
|
|
46
|
+
description='Waiting for confirmation...'
|
|
47
|
+
>
|
|
48
|
+
<ViewOnExplorer txHash={txHash} />
|
|
49
|
+
</LoadingModal>
|
|
50
|
+
)
|
|
51
|
+
}
|