@huma-finance/widgets 0.0.48-beta.187 → 0.0.48-beta.189

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.
Files changed (26) hide show
  1. package/API.md +0 -18
  2. package/dist/cjs/index.cjs +5488 -5814
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/index.d.ts +1 -33
  5. package/dist/index.js +5490 -5815
  6. package/dist/index.js.map +1 -1
  7. package/package.json +4 -7
  8. package/src/components/ApproveAllowanceModal.tsx +7 -0
  9. package/src/components/Lend/withdraw/2-ChooseAmount.tsx +7 -1
  10. package/src/components/Lend/withdraw/index.tsx +11 -4
  11. package/src/components/StreamFactoring/borrow/1-Evaluation.tsx +4 -3
  12. package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +21 -15
  13. package/src/components/StreamFactoring/borrow/3-ConfirmTransfer.tsx +3 -8
  14. package/src/components/StreamFactoring/borrow/5-Permit.tsx +2 -35
  15. package/src/components/StreamFactoring/borrow/index.tsx +2 -3
  16. package/src/components/SuperfluidFactoring/SuperfluidFactoredList.tsx +2 -2
  17. package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +3 -1
  18. package/src/index.tsx +11 -33
  19. package/src/components/RequestNetworkInvoiceFactoring/1-Evaluation.tsx +0 -58
  20. package/src/components/RequestNetworkInvoiceFactoring/2-ChooseAmount.tsx +0 -88
  21. package/src/components/RequestNetworkInvoiceFactoring/3-ConfirmTransfer.tsx +0 -37
  22. package/src/components/RequestNetworkInvoiceFactoring/4-ApproveNFT.tsx +0 -55
  23. package/src/components/RequestNetworkInvoiceFactoring/5-Transfer.tsx +0 -34
  24. package/src/components/RequestNetworkInvoiceFactoring/6-Success.tsx +0 -20
  25. package/src/components/RequestNetworkInvoiceFactoring/index.tsx +0 -137
  26. package/src/cosmos/RequestNetworkBorrow.fixture.tsx +0 -65
@@ -1,55 +0,0 @@
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
- }
@@ -1,34 +0,0 @@
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
- }
@@ -1,20 +0,0 @@
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, approval } =
12
- useAppSelector(selectWidgetState)
13
-
14
- const content = [
15
- `${borrowAmountNet} ${approval?.token.symbol} is now in your wallet.`,
16
- `The remaining ${remainder} ${approval?.token.symbol} will be sent to your wallet when the invoice is paid.`,
17
- ]
18
-
19
- return <TxDoneModal handleAction={handleAction} content={content} />
20
- }
@@ -1,137 +0,0 @@
1
- import { useWeb3React } from '@web3-react/core'
2
- import { RequestLogicTypes } from '@requestnetwork/types'
3
- import {
4
- POOL_NAME,
5
- POOL_TYPE,
6
- useAccountStats,
7
- usePoolInfo,
8
- } from '@huma-finance/shared'
9
- import React, { useEffect, useState } from 'react'
10
- import { useDispatch } from 'react-redux'
11
- import { RequestNetwork } from '@requestnetwork/request-client.js'
12
- import { getReceivableTokenIdForRequest } from '@requestnetwork/payment-processor'
13
- import { BigNumberish } from 'ethers'
14
-
15
- import { useAppSelector } from '../../hooks/useRedux'
16
- import { setStep } from '../../store/widgets.reducers'
17
- import { selectWidgetState } from '../../store/widgets.selectors'
18
- import { WIDGET_STEP } from '../../store/widgets.store'
19
- import { ErrorModal } from '../ErrorModal'
20
- import { WidgetWrapper } from '../WidgetWrapper'
21
- import { Evaluation } from './1-Evaluation'
22
- import { ChooseAmount } from './2-ChooseAmount'
23
- import { ConfirmTransfer } from './3-ConfirmTransfer'
24
- import { ApproveNFT } from './4-ApproveNFT'
25
- import { Transfer } from './5-Transfer'
26
- import { Success } from './6-Success'
27
-
28
- /**
29
- * Invoice factoring pool borrow props
30
- * @typedef {Object} RequestNetworkInvoiceFactoringBorrowProps
31
- * @property {POOL_NAME} poolName The name of the pool.
32
- * @property {POOL_TYPE} poolType The type of the pool.
33
- * @property {string|BigNumber} tokenId The NFT token id representing invoice.
34
- * @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
35
- * @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the invoice pool borrow action is successful.
36
- */
37
- export interface RequestNetworkInvoiceFactoringBorrowProps {
38
- poolName: keyof typeof POOL_NAME
39
- poolType: keyof typeof POOL_TYPE
40
- requestId: RequestLogicTypes.RequestId
41
- handleClose: () => void
42
- handleSuccess?: (blockNumber?: number) => void
43
- }
44
-
45
- export function RequestNetworkInvoiceFactoringBorrow({
46
- poolName: poolNameStr,
47
- poolType: poolTypeStr,
48
- requestId,
49
- handleClose,
50
- handleSuccess,
51
- }: RequestNetworkInvoiceFactoringBorrowProps): React.ReactElement | null {
52
- const dispatch = useDispatch()
53
- const { account, provider } = useWeb3React()
54
- const poolName = POOL_NAME[poolNameStr]
55
- const poolType = POOL_TYPE[poolTypeStr]
56
- const poolInfo = usePoolInfo(poolName, poolType)
57
- const { step, errorMessage } = useAppSelector(selectWidgetState)
58
- const [accountStats] = useAccountStats(poolName, poolType, account)
59
- const [tokenId, setTokenId] = useState<BigNumberish>()
60
- const [isLoading, setIsLoading] = useState<boolean>(true)
61
-
62
- useEffect(() => {
63
- dispatch(setStep(WIDGET_STEP.Evaluation))
64
- }, [dispatch])
65
-
66
- useEffect(() => {
67
- if (provider == null) {
68
- return () => {} // Return empty func to satisty consistent return lint rule
69
- }
70
-
71
- // Refetch every 5 seconds until requestData is non-null
72
- const interval = setInterval(() => {
73
- async function getInvoice() {
74
- if (provider == null) {
75
- return
76
- }
77
-
78
- const requestNetwork = new RequestNetwork({
79
- nodeConnectionConfig: {
80
- baseURL: `https://xdai.gateway.request.network/`,
81
- },
82
- })
83
- const request = await requestNetwork.fromRequestId(requestId)
84
- const requestData = request.getData()
85
- const tokenId = await getReceivableTokenIdForRequest(
86
- requestData,
87
- provider,
88
- )
89
-
90
- // Check if token ID exists yet for this request
91
- if (tokenId) {
92
- setTokenId(tokenId)
93
- setIsLoading(false)
94
- clearInterval(interval)
95
- }
96
- }
97
- getInvoice()
98
- }, 5000)
99
-
100
- return () => clearInterval(interval)
101
- }, [provider, requestId])
102
-
103
- if (!poolInfo) {
104
- return null
105
- }
106
-
107
- return (
108
- <WidgetWrapper
109
- isOpen
110
- isLoading={isLoading}
111
- handleClose={handleClose}
112
- handleSuccess={handleSuccess}
113
- >
114
- {step === WIDGET_STEP.Evaluation && (
115
- <Evaluation poolInfo={poolInfo} tokenId={tokenId!.toString()} />
116
- )}
117
- {step === WIDGET_STEP.ChooseAmount && (
118
- <ChooseAmount poolInfo={poolInfo} accountStats={accountStats} />
119
- )}
120
- {step === WIDGET_STEP.ConfirmTransfer && <ConfirmTransfer />}
121
- {step === WIDGET_STEP.ApproveNFT && (
122
- <ApproveNFT poolInfo={poolInfo} tokenId={tokenId!.toString()} />
123
- )}
124
- {step === WIDGET_STEP.Transfer && (
125
- <Transfer poolInfo={poolInfo} tokenId={tokenId!.toString()} />
126
- )}
127
- {step === WIDGET_STEP.Done && <Success handleAction={handleClose} />}
128
- {step === WIDGET_STEP.Error && (
129
- <ErrorModal
130
- title='Invoice Factoring'
131
- errorMessage={errorMessage}
132
- handleOk={handleClose}
133
- />
134
- )}
135
- </WidgetWrapper>
136
- )
137
- }
@@ -1,65 +0,0 @@
1
- import { POOL_NAME, POOL_TYPE } from '@huma-finance/shared'
2
- import { JsonRpcProvider } from '@ethersproject/providers'
3
- import { Button } from '@mui/material'
4
- import { Box } from '@mui/system'
5
- import { useState } from 'react'
6
- import { WalletWrapper } from './WalletWrapper'
7
- import { initEnv } from './utils/env'
8
- import { RequestNetworkInvoiceFactoringBorrowWidget } from '..'
9
-
10
- initEnv()
11
-
12
- function Fixture() {
13
- const poolName = POOL_NAME.RequestNetwork
14
- const poolType = POOL_TYPE.Invoice
15
- const [showModal, setShowModal] = useState(false)
16
- const [requestId, setRequestId] = useState(
17
- '01a84260baadbf9a46ea205d485b1a773f863c7531d19b6dd1d5073d82a5c414b7',
18
- )
19
-
20
- const handleClick = () => {
21
- setShowModal(true)
22
- }
23
-
24
- const handleClose = () => {
25
- setShowModal(false)
26
- }
27
-
28
- return (
29
- <>
30
- <Box>Pool: {poolName}</Box>
31
- <Box>Pool Type: {poolType}</Box>
32
- <input
33
- type='text'
34
- value={requestId}
35
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
- onChange={(event: any) => {
37
- setRequestId(event.target.value)
38
- }}
39
- />
40
- <Button variant='contained' onClick={handleClick}>
41
- Borrow
42
- </Button>
43
- {showModal && (
44
- <RequestNetworkInvoiceFactoringBorrowWidget
45
- poolName={poolName}
46
- poolType={poolType}
47
- requestId={requestId}
48
- handleClose={() => {
49
- handleClose()
50
- }}
51
- handleSuccess={() => {
52
- alert('Success')
53
- }}
54
- provider={new JsonRpcProvider()}
55
- />
56
- )}
57
- </>
58
- )
59
- }
60
-
61
- export default (
62
- <WalletWrapper>
63
- <Fixture />
64
- </WalletWrapper>
65
- )