@huma-finance/widgets 0.0.35 → 0.0.37
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/dist/cjs/index.cjs +1534 -1114
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.d.ts +42 -10
- package/dist/index.js +1536 -1117
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/components/Activity.tsx +1 -5
- package/src/components/ApproveAllowanceModal.tsx +24 -10
- package/src/components/CreditLine/approve/1-ApproveAllowance.tsx +34 -0
- package/src/components/CreditLine/approve/2-Success.tsx +43 -0
- package/src/components/CreditLine/approve/index.tsx +85 -0
- package/src/components/CreditLine/borrow/2-ChooseAmount.tsx +8 -2
- package/src/components/CreditLine/borrow/{4-ApproveAllowance.tsx → 3-ApproveAllowance.tsx} +1 -1
- package/src/components/CreditLine/borrow/{3-Transfer.tsx → 4-Transfer.tsx} +4 -14
- package/src/components/CreditLine/borrow/index.tsx +2 -2
- package/src/components/HumaTable.tsx +111 -66
- package/src/components/Lend/supply/1-Evaluation/EvaluationKYC.tsx +52 -19
- package/src/components/Notifi/NotifiSubscriptionModal.tsx +7 -3
- package/src/components/SuperfluidFactoring/SuperfluidFactoredList.tsx +0 -1
- package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +0 -1
- package/src/components/ViewOnExplorer.tsx +4 -7
- package/src/hooks/useElementDimensions.ts +30 -0
- package/src/index.tsx +40 -58
- package/src/utilTypes.d.ts +0 -1
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
timeUtil,
|
|
7
7
|
VerificationStatusResult,
|
|
8
8
|
CHAINS,
|
|
9
|
+
useParamsSearch,
|
|
9
10
|
} from '@huma-finance/shared'
|
|
10
11
|
import { Box, css, useTheme } from '@mui/material'
|
|
11
12
|
import { useWeb3React } from '@web3-react/core'
|
|
@@ -79,6 +80,7 @@ export function EvaluationKYC({
|
|
|
79
80
|
const dispatch = useAppDispatch()
|
|
80
81
|
const isDev = envUtil.checkIsDev()
|
|
81
82
|
const { account, chainId } = useWeb3React()
|
|
83
|
+
const { kycProvider, code, kycPool } = useParamsSearch()
|
|
82
84
|
const [loadingType, setLoadingType] = useState<
|
|
83
85
|
'verificationStatus' | 'sendDocSignatureLink'
|
|
84
86
|
>()
|
|
@@ -108,14 +110,17 @@ export function EvaluationKYC({
|
|
|
108
110
|
`,
|
|
109
111
|
}
|
|
110
112
|
|
|
111
|
-
const { envelopeKey, envelopeLastQueryTimeKey } =
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
envelopeKey
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
113
|
+
const { envelopeKey, envelopeLastQueryTimeKey, envelopeDocuSignStatusKey } =
|
|
114
|
+
useMemo(() => {
|
|
115
|
+
const envelopeKey = `${poolInfo.pool.toLowerCase()}-${account?.toLowerCase()}`
|
|
116
|
+
const envelopeLastQueryTimeKey = `${envelopeKey}-last-query-time`
|
|
117
|
+
const envelopeDocuSignStatusKey = `${envelopeKey}-docuSign-status`
|
|
118
|
+
return {
|
|
119
|
+
envelopeKey,
|
|
120
|
+
envelopeLastQueryTimeKey,
|
|
121
|
+
envelopeDocuSignStatusKey,
|
|
122
|
+
}
|
|
123
|
+
}, [account, poolInfo.pool])
|
|
119
124
|
|
|
120
125
|
// DocuSign GET requests to any specific URL can be called not more often than once every 15 minutes.
|
|
121
126
|
// https://developers.docusign.com/platform/api-guidelines/#:~:text=Polling,not%20once%20every%2010%20minutes
|
|
@@ -132,9 +137,32 @@ export function EvaluationKYC({
|
|
|
132
137
|
}, [envelopeLastQueryTimeKey])
|
|
133
138
|
|
|
134
139
|
useEffect(() => {
|
|
140
|
+
const docuSignStatus = localStorage.getItem(envelopeDocuSignStatusKey)
|
|
141
|
+
setDocSignatureStatus(docuSignStatus as DocSignatureStatus['status'])
|
|
142
|
+
if (docuSignStatus === 'completed') {
|
|
143
|
+
setKYCCopy(JiaPoolCopies.docUnderReview)
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
|
|
135
147
|
const fetchData = async () => {
|
|
136
|
-
|
|
137
|
-
|
|
148
|
+
try {
|
|
149
|
+
if (kycProvider && kycPool && account && chainId) {
|
|
150
|
+
setLoadingType('verificationStatus')
|
|
151
|
+
await IdentityService.onboard(
|
|
152
|
+
account,
|
|
153
|
+
code as string,
|
|
154
|
+
kycPool as string,
|
|
155
|
+
chainId,
|
|
156
|
+
isDev,
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
} catch (e) {
|
|
160
|
+
// The repeated call will throw an error of 401, so we can ignore it.
|
|
161
|
+
console.error(e)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
try {
|
|
165
|
+
if (account && chainId) {
|
|
138
166
|
setLoadingType('verificationStatus')
|
|
139
167
|
const verificationStatus =
|
|
140
168
|
await IdentityService.getVerificationStatus(
|
|
@@ -160,6 +188,7 @@ export function EvaluationKYC({
|
|
|
160
188
|
envelopeLastQueryTimeKey,
|
|
161
189
|
String(timeUtil.getUnixTimestamp()),
|
|
162
190
|
)
|
|
191
|
+
localStorage.setItem(envelopeDocuSignStatusKey, status)
|
|
163
192
|
setDocSignatureStatus(status)
|
|
164
193
|
if (status === 'completed') {
|
|
165
194
|
setKYCCopy(JiaPoolCopies.docUnderReview)
|
|
@@ -173,16 +202,16 @@ export function EvaluationKYC({
|
|
|
173
202
|
}
|
|
174
203
|
}
|
|
175
204
|
}
|
|
176
|
-
} catch (e: unknown) {
|
|
177
|
-
console.error(e)
|
|
178
|
-
dispatch(
|
|
179
|
-
setError({
|
|
180
|
-
errorMessage: 'Something went wrong, please try again later.',
|
|
181
|
-
}),
|
|
182
|
-
)
|
|
183
|
-
} finally {
|
|
184
|
-
setLoadingType(undefined)
|
|
185
205
|
}
|
|
206
|
+
} catch (e: unknown) {
|
|
207
|
+
console.error(e)
|
|
208
|
+
dispatch(
|
|
209
|
+
setError({
|
|
210
|
+
errorMessage: 'Something went wrong, please try again later.',
|
|
211
|
+
}),
|
|
212
|
+
)
|
|
213
|
+
} finally {
|
|
214
|
+
setLoadingType(undefined)
|
|
186
215
|
}
|
|
187
216
|
}
|
|
188
217
|
fetchData()
|
|
@@ -190,10 +219,14 @@ export function EvaluationKYC({
|
|
|
190
219
|
account,
|
|
191
220
|
chainId,
|
|
192
221
|
checkGetDocSignatureStatusIsAvailable,
|
|
222
|
+
code,
|
|
193
223
|
dispatch,
|
|
224
|
+
envelopeDocuSignStatusKey,
|
|
194
225
|
envelopeKey,
|
|
195
226
|
envelopeLastQueryTimeKey,
|
|
196
227
|
isDev,
|
|
228
|
+
kycPool,
|
|
229
|
+
kycProvider,
|
|
197
230
|
poolInfo.pool,
|
|
198
231
|
])
|
|
199
232
|
|
|
@@ -10,7 +10,11 @@ import {
|
|
|
10
10
|
EventTypeItem,
|
|
11
11
|
BroadcastEventTypeItem,
|
|
12
12
|
} from '@notifi-network/notifi-frontend-client'
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
getBlockchainConfigFromChain,
|
|
15
|
+
txAtom,
|
|
16
|
+
getNotifiDappId,
|
|
17
|
+
} from '@huma-finance/shared'
|
|
14
18
|
import { ethers } from 'ethers'
|
|
15
19
|
import {
|
|
16
20
|
Box,
|
|
@@ -99,7 +103,7 @@ export function NotifiSubscriptionModal({
|
|
|
99
103
|
const [notifiClient, setNotifiClient] = useState<NotifiFrontendClient>()
|
|
100
104
|
const [showSuccessScreen, setShowSuccessScreen] = useState<boolean>(false)
|
|
101
105
|
const [isLoading, setIsLoading] = useState<boolean>(false)
|
|
102
|
-
const [emailAddress, setEmailAddress] = useState<string>()
|
|
106
|
+
const [emailAddress, setEmailAddress] = useState<string>('')
|
|
103
107
|
const [emailValid, setEmailValid] = useState<boolean>()
|
|
104
108
|
|
|
105
109
|
useEffect(() => {
|
|
@@ -107,7 +111,7 @@ export function NotifiSubscriptionModal({
|
|
|
107
111
|
if (account != null && chainId != null) {
|
|
108
112
|
const client = newFrontendClient({
|
|
109
113
|
account: { publicKey: account },
|
|
110
|
-
tenantId:
|
|
114
|
+
tenantId: getNotifiDappId(envUtil.checkIsDev()),
|
|
111
115
|
env: envUtil.checkIsDev() ? 'Development' : 'Production',
|
|
112
116
|
walletBlockchain: getBlockchainConfigFromChain(chainId),
|
|
113
117
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Box, Button } from '@mui/material'
|
|
2
2
|
import { useWeb3React } from '@web3-react/core'
|
|
3
|
-
import {
|
|
3
|
+
import { getExplorerUrl, openInNewTab } from '@huma-finance/shared'
|
|
4
4
|
import React from 'react'
|
|
5
5
|
|
|
6
6
|
type Props = {
|
|
@@ -9,17 +9,14 @@ type Props = {
|
|
|
9
9
|
|
|
10
10
|
export function ViewOnExplorer({ txHash }: Props): React.ReactElement | null {
|
|
11
11
|
const { chainId } = useWeb3React()
|
|
12
|
-
const
|
|
12
|
+
const link = getExplorerUrl(chainId, txHash, 'tx')
|
|
13
13
|
|
|
14
|
-
if (!
|
|
14
|
+
if (!link) {
|
|
15
15
|
return null
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
return (
|
|
19
|
-
<Button
|
|
20
|
-
variant='outlined'
|
|
21
|
-
onClick={() => openInNewTab(`${chain.explorer}/tx/${txHash}`)}
|
|
22
|
-
>
|
|
19
|
+
<Button variant='outlined' onClick={() => openInNewTab(link)}>
|
|
23
20
|
<Box component='span'>VIEW ON EXPLORER</Box>
|
|
24
21
|
</Button>
|
|
25
22
|
)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MutableRefObject, useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
export const useElementDimensions = (
|
|
4
|
+
ref: MutableRefObject<HTMLDivElement | undefined>,
|
|
5
|
+
) => {
|
|
6
|
+
const [dimensions, setDimensions] = useState({ width: 0, height: 0 })
|
|
7
|
+
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const getDimensions = () => ({
|
|
10
|
+
width: ref?.current?.offsetWidth ?? 0,
|
|
11
|
+
height: ref?.current?.offsetHeight ?? 0,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const handleResize = () => {
|
|
15
|
+
setDimensions(getDimensions())
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (ref.current) {
|
|
19
|
+
setDimensions(getDimensions())
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
window.addEventListener('resize', handleResize)
|
|
23
|
+
|
|
24
|
+
return () => {
|
|
25
|
+
window.removeEventListener('resize', handleResize)
|
|
26
|
+
}
|
|
27
|
+
}, [ref])
|
|
28
|
+
|
|
29
|
+
return dimensions
|
|
30
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -12,7 +12,12 @@ import { Provider as AtomProvider } from 'jotai'
|
|
|
12
12
|
import { useCallback, useEffect, useState } from 'react'
|
|
13
13
|
import { Provider as ReduxProvider } from 'react-redux'
|
|
14
14
|
|
|
15
|
+
import { useWeb3React } from '@web3-react/core'
|
|
15
16
|
import { ChainNotSupportedModal } from './components/ChainNotSupportedModal'
|
|
17
|
+
import {
|
|
18
|
+
CreditLineApprove,
|
|
19
|
+
CreditLineApproveProps,
|
|
20
|
+
} from './components/CreditLine/approve'
|
|
16
21
|
import {
|
|
17
22
|
CreditLineBorrow,
|
|
18
23
|
CreditLineBorrowProps,
|
|
@@ -50,29 +55,21 @@ type JsonRpcConnectionMap = {
|
|
|
50
55
|
* @typedef {Object} WidgetProps
|
|
51
56
|
* @property {desiredChainId|undefined} desiredChainId Optional desired chain id, will trigger the switch network action if different from the current chain id
|
|
52
57
|
* @property {JsonRpcConnectionMap|undefined} jsonRpcUrlMap Optional mapping of your JSON-RPC connections indexed by chainId
|
|
53
|
-
* @property {Eip1193Provider|
|
|
58
|
+
* @property {Eip1193Provider|JsonRpcProviderl} provider EIP-1193 provider or JsonRpc Provider
|
|
54
59
|
*/
|
|
55
60
|
type WidgetProps = {
|
|
56
61
|
handleClose?: () => void
|
|
57
62
|
desiredChainId?: number
|
|
58
63
|
jsonRpcUrlMap?: JsonRpcConnectionMap
|
|
59
|
-
provider
|
|
64
|
+
provider: Eip1193Provider | JsonRpcProvider
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
function Widget(props: WCProps<WidgetProps>) {
|
|
63
|
-
const { children
|
|
64
|
-
const {
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
const netWorkVersion = ethereum?.networkVersion || ethereum?.chainId
|
|
67
|
-
const [currentChainId, setCurrentChainId] = useState<number | undefined>(
|
|
68
|
-
netWorkVersion ? Number(netWorkVersion) : undefined,
|
|
69
|
-
)
|
|
70
|
-
const chainSupported = !!supportedChainId(currentChainId)
|
|
71
|
-
const [chainNotSupportedOpen, setChainNotSupportedOpen] = useState(false)
|
|
68
|
+
const { children } = props
|
|
69
|
+
const { chainId } = useWeb3React()
|
|
72
70
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}, [netWorkVersion])
|
|
71
|
+
const chainSupported = !!supportedChainId(chainId)
|
|
72
|
+
const [chainNotSupportedOpen, setChainNotSupportedOpen] = useState(false)
|
|
76
73
|
|
|
77
74
|
useEffect(() => {
|
|
78
75
|
if (chainSupported) {
|
|
@@ -82,44 +79,6 @@ function Widget(props: WCProps<WidgetProps>) {
|
|
|
82
79
|
}
|
|
83
80
|
}, [chainSupported])
|
|
84
81
|
|
|
85
|
-
useEffect(() => {
|
|
86
|
-
const chainChangeListener = (chainId: number) => {
|
|
87
|
-
setCurrentChainId(chainId)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (window.ethereum) {
|
|
91
|
-
// @ts-ignore
|
|
92
|
-
window.ethereum?.on('chainChanged', chainChangeListener)
|
|
93
|
-
}
|
|
94
|
-
return () => {
|
|
95
|
-
if (window.ethereum) {
|
|
96
|
-
// @ts-ignore
|
|
97
|
-
window.ethereum?.removeListener('chainChanged', chainChangeListener)
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}, [])
|
|
101
|
-
|
|
102
|
-
useEffect(() => {
|
|
103
|
-
if (
|
|
104
|
-
window.ethereum &&
|
|
105
|
-
desiredChainId &&
|
|
106
|
-
currentChainId !== desiredChainId
|
|
107
|
-
) {
|
|
108
|
-
const changeNetwork = async () => {
|
|
109
|
-
try {
|
|
110
|
-
// @ts-ignore
|
|
111
|
-
await window.ethereum.request({
|
|
112
|
-
method: 'wallet_switchEthereumChain',
|
|
113
|
-
params: [{ chainId: `0x${Number(desiredChainId).toString(16)}` }],
|
|
114
|
-
})
|
|
115
|
-
} catch (error) {
|
|
116
|
-
console.error(error)
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
changeNetwork()
|
|
120
|
-
}
|
|
121
|
-
}, [currentChainId, desiredChainId])
|
|
122
|
-
|
|
123
82
|
const handleCloseCallback = useCallback(() => {
|
|
124
83
|
setChainNotSupportedOpen(false)
|
|
125
84
|
}, [])
|
|
@@ -160,7 +119,7 @@ type InvoiceFactoringBorrowWidgetProps = InvoiceFactoringBorrowProps &
|
|
|
160
119
|
/**
|
|
161
120
|
* Invoice factoring borrow widget
|
|
162
121
|
*
|
|
163
|
-
* @param {
|
|
122
|
+
* @param {InvoiceFactoringBorrowWidgetProps} props - The invoice factoring pool borrow widget props.
|
|
164
123
|
* @returns Invoice factoring pool borrow widget component
|
|
165
124
|
*/
|
|
166
125
|
export function InvoiceFactoringBorrowWidget(
|
|
@@ -185,7 +144,7 @@ type InvoiceFactoringPaymentWidgetProps = InvoiceFactoringPaymentProps &
|
|
|
185
144
|
/**
|
|
186
145
|
* Invoice factoring payment widget
|
|
187
146
|
*
|
|
188
|
-
* @param {
|
|
147
|
+
* @param {InvoiceFactoringPaymentWidgetProps} props - The invoice factoring pool payment widget props.
|
|
189
148
|
* @returns Invoice factoring pool payment widget component
|
|
190
149
|
*/
|
|
191
150
|
export function InvoiceFactoringPaymentWidget(
|
|
@@ -209,7 +168,7 @@ type CreditLineBorrowWidgetProps = CreditLineBorrowProps & WidgetProps
|
|
|
209
168
|
/**
|
|
210
169
|
* Credit line borrow widget
|
|
211
170
|
*
|
|
212
|
-
* @param {
|
|
171
|
+
* @param {CreditLineBorrowWidgetProps} props - The credit line pool borrow widget props.
|
|
213
172
|
* @returns Credit line pool borrow widget component
|
|
214
173
|
*/
|
|
215
174
|
export function CreditLineBorrowWidget(props: CreditLineBorrowWidgetProps) {
|
|
@@ -231,7 +190,7 @@ type CreditLinePaymentWidgetProps = CreditLinePaymentProps & WidgetProps
|
|
|
231
190
|
/**
|
|
232
191
|
* Credit line payment widget
|
|
233
192
|
*
|
|
234
|
-
* @param {
|
|
193
|
+
* @param {CreditLinePaymentWidgetProps} props - The credit line pool payment widget props.
|
|
235
194
|
* @returns Credit line pool payment widget component
|
|
236
195
|
*/
|
|
237
196
|
export function CreditLinePaymentWidget(props: CreditLinePaymentWidgetProps) {
|
|
@@ -242,6 +201,29 @@ export function CreditLinePaymentWidget(props: CreditLinePaymentWidgetProps) {
|
|
|
242
201
|
)
|
|
243
202
|
}
|
|
244
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Credit line allowance approval widget props
|
|
206
|
+
* @typedef {Object} CreditLinePaymentWidgetProps
|
|
207
|
+
* @property {CreditLineApproveProps} CreditLineApproveProps - Credit line allowance approve props.
|
|
208
|
+
* @property {WidgetProps} WidgetProps - Widget general props.
|
|
209
|
+
*/
|
|
210
|
+
type CreditLineApproveWidgetProps = CreditLineApproveProps & WidgetProps
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Credit line allowance approve widget to top up a pool's ERC20 token allowance.
|
|
214
|
+
* To be used when re-enabling autopay and other pool actions that require allowance.
|
|
215
|
+
*
|
|
216
|
+
* @param {CreditLineApproveWidgetProps} props - The credit line pool approve widget props.
|
|
217
|
+
* @returns Credit line pool approve widget component
|
|
218
|
+
*/
|
|
219
|
+
export function CreditLineApproveWidget(props: CreditLineApproveWidgetProps) {
|
|
220
|
+
return (
|
|
221
|
+
<Widget {...props}>
|
|
222
|
+
<CreditLineApprove {...props} />
|
|
223
|
+
</Widget>
|
|
224
|
+
)
|
|
225
|
+
}
|
|
226
|
+
|
|
245
227
|
/**
|
|
246
228
|
* Lend pool supply widget props
|
|
247
229
|
* @typedef {Object} LendSupplyWidgetProps
|
|
@@ -253,7 +235,7 @@ type LendSupplyWidgetProps = LendSupplyProps & WidgetProps
|
|
|
253
235
|
/**
|
|
254
236
|
* Lend supply widget
|
|
255
237
|
*
|
|
256
|
-
* @param {
|
|
238
|
+
* @param {LendSupplyWidgetProps} props - The lend pool supply widget props.
|
|
257
239
|
* @returns Lend pool supply widget component
|
|
258
240
|
*/
|
|
259
241
|
export function LendSupplyWidget(props: LendSupplyWidgetProps) {
|
|
@@ -275,7 +257,7 @@ type LendWithdrawWidgetProps = LendWithdrawProps & WidgetProps
|
|
|
275
257
|
/**
|
|
276
258
|
* Lend withdraw widget
|
|
277
259
|
*
|
|
278
|
-
* @param {
|
|
260
|
+
* @param {LendWithdrawWidgetProps} props The lend pool withdraw widget props
|
|
279
261
|
* @returns Lend pool withdraw widget component
|
|
280
262
|
*/
|
|
281
263
|
export function LendWithdrawWidget(props: LendWithdrawWidgetProps) {
|