@huma-finance/widgets 0.0.8 → 0.0.11

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 (76) hide show
  1. package/dist/cjs/index.cjs +139 -131
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/index.js +139 -131
  4. package/dist/index.js.map +1 -1
  5. package/package.json +4 -4
  6. package/src/components/Activity.tsx +123 -123
  7. package/src/components/AllowListModal.tsx +113 -113
  8. package/src/components/ApproveAllowanceModal.tsx +118 -118
  9. package/src/components/ChooseAmountModal.tsx +315 -315
  10. package/src/components/CreditLine/borrow/1-Evaluation.tsx +158 -159
  11. package/src/components/CreditLine/borrow/2-AllowList.tsx +34 -34
  12. package/src/components/CreditLine/borrow/3-ChooseAmount.tsx +74 -74
  13. package/src/components/CreditLine/borrow/4-ApproveAllowance.tsx +29 -29
  14. package/src/components/CreditLine/borrow/5-Transfer.tsx +30 -30
  15. package/src/components/CreditLine/borrow/6-Success.tsx +30 -30
  16. package/src/components/CreditLine/borrow/index.tsx +119 -119
  17. package/src/components/CreditLine/payment/1-ChooseAmount.tsx +67 -67
  18. package/src/components/CreditLine/payment/2-ApproveAllowance.tsx +23 -23
  19. package/src/components/CreditLine/payment/3-Transfer.tsx +34 -34
  20. package/src/components/CreditLine/payment/4-Success.tsx +39 -39
  21. package/src/components/CreditLine/payment/index.tsx +94 -94
  22. package/src/components/ErrorModal.tsx +132 -132
  23. package/src/components/Factoring/FactoredList.tsx +143 -143
  24. package/src/components/Factoring/UpcomingList.tsx +90 -90
  25. package/src/components/InvoiceFactoring/borrow/1-Evaluation.tsx +52 -46
  26. package/src/components/InvoiceFactoring/borrow/2-AllowList.tsx +34 -34
  27. package/src/components/InvoiceFactoring/borrow/3-ChooseAmount.tsx +86 -92
  28. package/src/components/InvoiceFactoring/borrow/4-ConfirmTransfer.tsx +104 -104
  29. package/src/components/InvoiceFactoring/borrow/5-ApproveNFT.tsx +55 -55
  30. package/src/components/InvoiceFactoring/borrow/6-Transfer.tsx +34 -34
  31. package/src/components/InvoiceFactoring/borrow/7-Success.tsx +3 -3
  32. package/src/components/InvoiceFactoring/borrow/index.tsx +96 -96
  33. package/src/components/InvoiceFactoring/payment/1-ChooseAmount.tsx +67 -67
  34. package/src/components/InvoiceFactoring/payment/2-ApproveAllowance.tsx +23 -23
  35. package/src/components/InvoiceFactoring/payment/3-Transfer.tsx +34 -34
  36. package/src/components/InvoiceFactoring/payment/4-Success.tsx +23 -23
  37. package/src/components/InvoiceFactoring/payment/index.tsx +86 -86
  38. package/src/components/Lend/supply/1-Evaluation.tsx +86 -86
  39. package/src/components/Lend/supply/2-ChooseAmount.tsx +70 -70
  40. package/src/components/Lend/supply/3-ApproveAllowance.tsx +25 -25
  41. package/src/components/Lend/supply/4-ConfirmTransfer.tsx +104 -104
  42. package/src/components/Lend/supply/6-Transfer.tsx +32 -32
  43. package/src/components/Lend/supply/7-Success.tsx +49 -49
  44. package/src/components/Lend/supply/index.tsx +144 -144
  45. package/src/components/Lend/withdraw/1-CheckWithdrawble.tsx +73 -73
  46. package/src/components/Lend/withdraw/2-ChooseAmount.tsx +50 -50
  47. package/src/components/Lend/withdraw/3-Transfer.tsx +32 -32
  48. package/src/components/Lend/withdraw/4-Success.tsx +49 -49
  49. package/src/components/Lend/withdraw/index.tsx +101 -101
  50. package/src/components/StreamFactoring/borrow/1-Evaluation.tsx +47 -57
  51. package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +124 -124
  52. package/src/components/StreamFactoring/borrow/3-ConfirmTransfer.tsx +104 -104
  53. package/src/components/StreamFactoring/borrow/4-ApproveAllowance.tsx +65 -65
  54. package/src/components/StreamFactoring/borrow/5-Permit.tsx +144 -144
  55. package/src/components/StreamFactoring/borrow/6-Transfer.tsx +37 -37
  56. package/src/components/StreamFactoring/borrow/7-Success.tsx +2 -2
  57. package/src/components/StreamFactoring/borrow/index.tsx +94 -95
  58. package/src/components/StreamFactoring/payment/ChooseAmount.tsx +54 -54
  59. package/src/components/StreamFactoring/payment/Success.tsx +23 -23
  60. package/src/components/StreamFactoring/payment/Transfer.tsx +34 -34
  61. package/src/components/StreamFactoring/payment/index.tsx +66 -66
  62. package/src/components/SuperfluidFactoring/SuperfluidFactoredList.tsx +61 -61
  63. package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +185 -185
  64. package/src/components/SuperfluidFactoring/index.tsx +85 -85
  65. package/src/components/TxDoneModal.tsx +83 -83
  66. package/src/components/TxSendModal.tsx +59 -59
  67. package/src/components/ViewOnExplorer.tsx +26 -26
  68. package/src/components/WidgetWrapper.tsx +74 -74
  69. package/src/components/humaModal/HumaModal.tsx +68 -68
  70. package/src/cosmos/SDKTesting.fixture.tsx +557 -515
  71. package/src/hooks/useEA.ts +72 -70
  72. package/src/index.tsx +219 -219
  73. package/src/store/widgets.reducers.ts +120 -120
  74. package/src/store/widgets.store.ts +55 -55
  75. package/src/theme/components.ts +1 -1
  76. package/src/theme/hooks/useGetSizes.ts +0 -3
@@ -1,144 +1,144 @@
1
- import { Contract, ethers } from 'ethers'
2
- import {
3
- CHAINS,
4
- Erc2612,
5
- PoolInfoType,
6
- StreamFactoringPool,
7
- useERC2612Permit,
8
- useMount,
9
- } from '@huma-finance/shared'
10
- import ERC2612Abi from '@huma-finance/shared/dist/abis/erc2612.json'
11
- import PoolAbi from '@huma-finance/shared/dist/abis/StreamFactoringPool.json'
12
- import React from 'react'
13
- import { useDispatch } from 'react-redux'
14
-
15
- import { useAppSelector } from '../../../hooks/useRedux'
16
- import {
17
- setError,
18
- setMultisend,
19
- setStep,
20
- } from '../../../store/widgets.reducers'
21
- import { selectWidgetState } from '../../../store/widgets.selectors'
22
- import { WIDGET_STEP } from '../../../store/widgets.store'
23
- import { LoadingModal } from '../../LoadingModal'
24
-
25
- type Props = {
26
- poolInfo: PoolInfoType
27
- payerAddress: string
28
- chainId: number
29
- borrower: string
30
- superToken: string
31
- }
32
-
33
- export function Permit({
34
- poolInfo,
35
- payerAddress,
36
- chainId,
37
- borrower,
38
- superToken,
39
- }: Props): React.ReactElement | null {
40
- const dispatch = useDispatch()
41
- const { address: tokenAddress } = poolInfo.poolUnderlyingToken
42
- const { borrowAmountBN, stream } = useAppSelector(selectWidgetState)
43
- const { getERC2612PermitMessage, getTradableStreamPermitMessage } =
44
- useERC2612Permit()
45
-
46
- const getApproveAllowanceCallData = async () => {
47
- const erc2612PermitResult = await getERC2612PermitMessage(
48
- tokenAddress,
49
- poolInfo.pool,
50
- borrowAmountBN!,
51
- )
52
- const tokenContract = new Contract(tokenAddress, ERC2612Abi) as Erc2612
53
- return tokenContract.interface.encodeFunctionData('permit', [
54
- poolInfo.pool,
55
- borrowAmountBN!,
56
- erc2612PermitResult.nonce,
57
- erc2612PermitResult.deadline,
58
- erc2612PermitResult.v,
59
- erc2612PermitResult.r,
60
- erc2612PermitResult.s,
61
- ])
62
- }
63
-
64
- const getDrawdownCallData = async () => {
65
- const NFTPermitResult = await getTradableStreamPermitMessage(
66
- poolInfo.assetAddress!,
67
- borrower,
68
- superToken,
69
- payerAddress,
70
- poolInfo.pool,
71
- stream!.borrowFlowrate!,
72
- stream!.durationInSeconds!,
73
- )
74
-
75
- const drawdownEncodedData = ethers.utils.defaultAbiCoder.encode(
76
- [
77
- 'address',
78
- 'address',
79
- 'address',
80
- 'int96',
81
- 'uint256',
82
- 'uint256',
83
- 'uint8',
84
- 'bytes32',
85
- 'bytes32',
86
- ],
87
- [
88
- borrower,
89
- superToken,
90
- payerAddress,
91
- stream?.borrowFlowrate,
92
- stream?.durationInSeconds,
93
- NFTPermitResult.expiry,
94
- NFTPermitResult.v,
95
- NFTPermitResult.r,
96
- NFTPermitResult.s,
97
- ],
98
- )
99
- const poolContract = new Contract(
100
- poolInfo.pool,
101
- PoolAbi,
102
- ) as StreamFactoringPool
103
-
104
- return poolContract.interface.encodeFunctionData(
105
- 'drawdownWithAuthorization',
106
- [borrowAmountBN!, poolInfo.assetAddress!, drawdownEncodedData],
107
- )
108
- }
109
-
110
- useMount(async () => {
111
- try {
112
- const callData = []
113
- const addresses: string[] = []
114
-
115
- // The token in Goerli hasn't integrated ERC-2612
116
- if (!CHAINS[chainId].isTestnet) {
117
- const approveAllowanceCallData = await getApproveAllowanceCallData()
118
- addresses.push(tokenAddress)
119
- callData.push(approveAllowanceCallData)
120
- }
121
-
122
- const drawdownCalldata = await getDrawdownCallData()
123
- addresses.push(poolInfo.pool)
124
- callData.push(drawdownCalldata)
125
-
126
- dispatch(setMultisend({ addresses, callData }))
127
- dispatch(setStep(WIDGET_STEP.Transfer))
128
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
129
- } catch (e: any) {
130
- let errorMessage = e.reason || `Sign permit failed`
131
- if (e.code === 4001 || e.code === 'ACTION_REJECTED') {
132
- errorMessage = 'User has rejected the permit sign'
133
- }
134
- dispatch(setError({ errorMessage, errorReason: errorMessage }))
135
- }
136
- })
137
-
138
- return (
139
- <LoadingModal
140
- title='Sign Token and NFT'
141
- description='Waiting for signing...'
142
- />
143
- )
144
- }
1
+ import { Contract, ethers } from 'ethers'
2
+ import {
3
+ CHAINS,
4
+ Erc2612,
5
+ PoolInfoType,
6
+ StreamFactoringPool,
7
+ useERC2612Permit,
8
+ useMount,
9
+ } from '@huma-finance/shared'
10
+ import ERC2612Abi from '@huma-finance/shared/dist/abis/erc2612.json'
11
+ import PoolAbi from '@huma-finance/shared/dist/abis/StreamFactoringPool.json'
12
+ import React from 'react'
13
+ import { useDispatch } from 'react-redux'
14
+
15
+ import { useAppSelector } from '../../../hooks/useRedux'
16
+ import {
17
+ setError,
18
+ setMultisend,
19
+ setStep,
20
+ } from '../../../store/widgets.reducers'
21
+ import { selectWidgetState } from '../../../store/widgets.selectors'
22
+ import { WIDGET_STEP } from '../../../store/widgets.store'
23
+ import { LoadingModal } from '../../LoadingModal'
24
+
25
+ type Props = {
26
+ poolInfo: PoolInfoType
27
+ payerAddress: string
28
+ chainId: number
29
+ borrower: string
30
+ superToken: string
31
+ }
32
+
33
+ export function Permit({
34
+ poolInfo,
35
+ payerAddress,
36
+ chainId,
37
+ borrower,
38
+ superToken,
39
+ }: Props): React.ReactElement | null {
40
+ const dispatch = useDispatch()
41
+ const { address: tokenAddress } = poolInfo.poolUnderlyingToken
42
+ const { borrowAmountBN, stream } = useAppSelector(selectWidgetState)
43
+ const { getERC2612PermitMessage, getTradableStreamPermitMessage } =
44
+ useERC2612Permit()
45
+
46
+ const getApproveAllowanceCallData = async () => {
47
+ const erc2612PermitResult = await getERC2612PermitMessage(
48
+ tokenAddress,
49
+ poolInfo.pool,
50
+ borrowAmountBN!,
51
+ )
52
+ const tokenContract = new Contract(tokenAddress, ERC2612Abi) as Erc2612
53
+ return tokenContract.interface.encodeFunctionData('permit', [
54
+ poolInfo.pool,
55
+ borrowAmountBN!,
56
+ erc2612PermitResult.nonce,
57
+ erc2612PermitResult.deadline,
58
+ erc2612PermitResult.v,
59
+ erc2612PermitResult.r,
60
+ erc2612PermitResult.s,
61
+ ])
62
+ }
63
+
64
+ const getDrawdownCallData = async () => {
65
+ const NFTPermitResult = await getTradableStreamPermitMessage(
66
+ poolInfo.assetAddress!,
67
+ borrower,
68
+ superToken,
69
+ payerAddress,
70
+ poolInfo.pool,
71
+ stream!.borrowFlowrate!,
72
+ stream!.durationInSeconds!,
73
+ )
74
+
75
+ const drawdownEncodedData = ethers.utils.defaultAbiCoder.encode(
76
+ [
77
+ 'address',
78
+ 'address',
79
+ 'address',
80
+ 'int96',
81
+ 'uint256',
82
+ 'uint256',
83
+ 'uint8',
84
+ 'bytes32',
85
+ 'bytes32',
86
+ ],
87
+ [
88
+ borrower,
89
+ superToken,
90
+ payerAddress,
91
+ stream?.borrowFlowrate,
92
+ stream?.durationInSeconds,
93
+ NFTPermitResult.expiry,
94
+ NFTPermitResult.v,
95
+ NFTPermitResult.r,
96
+ NFTPermitResult.s,
97
+ ],
98
+ )
99
+ const poolContract = new Contract(
100
+ poolInfo.pool,
101
+ PoolAbi,
102
+ ) as StreamFactoringPool
103
+
104
+ return poolContract.interface.encodeFunctionData(
105
+ 'drawdownWithAuthorization',
106
+ [borrowAmountBN!, poolInfo.assetAddress!, drawdownEncodedData],
107
+ )
108
+ }
109
+
110
+ useMount(async () => {
111
+ try {
112
+ const callData = []
113
+ const addresses: string[] = []
114
+
115
+ // The token in Goerli hasn't integrated ERC-2612
116
+ if (!CHAINS[chainId].isTestnet) {
117
+ const approveAllowanceCallData = await getApproveAllowanceCallData()
118
+ addresses.push(tokenAddress)
119
+ callData.push(approveAllowanceCallData)
120
+ }
121
+
122
+ const drawdownCalldata = await getDrawdownCallData()
123
+ addresses.push(poolInfo.pool)
124
+ callData.push(drawdownCalldata)
125
+
126
+ dispatch(setMultisend({ addresses, callData }))
127
+ dispatch(setStep(WIDGET_STEP.Transfer))
128
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
129
+ } catch (e: any) {
130
+ let errorMessage = e.reason || `Sign permit failed`
131
+ if (e.code === 4001 || e.code === 'ACTION_REJECTED') {
132
+ errorMessage = 'User has rejected the permit sign'
133
+ }
134
+ dispatch(setError({ errorMessage, errorReason: errorMessage }))
135
+ }
136
+ })
137
+
138
+ return (
139
+ <LoadingModal
140
+ title='Sign Token and NFT'
141
+ description='Waiting for signing...'
142
+ />
143
+ )
144
+ }
@@ -1,37 +1,37 @@
1
- import { PoolInfoType, useMultiSendContract } 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
- }
13
-
14
- export function Transfer({ poolInfo }: Props): React.ReactElement | null {
15
- const dispatch = useAppDispatch()
16
- const multiSendContract = useMultiSendContract()
17
- const { multisend } = useAppSelector(selectWidgetState)
18
-
19
- const handleSuccess = useCallback(() => {
20
- dispatch(setStep(WIDGET_STEP.Done))
21
- }, [dispatch])
22
-
23
- if (!multisend || !multiSendContract) {
24
- return null
25
- }
26
-
27
- return (
28
- <TxSendModal
29
- poolInfo={poolInfo}
30
- contract={multiSendContract}
31
- title='Transfer Tradable Stream and Money'
32
- method='multisend'
33
- params={[multisend.addresses, multisend.callData]}
34
- handleSuccess={handleSuccess}
35
- />
36
- )
37
- }
1
+ import { PoolInfoType, useMultiSendContract } 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
+ }
13
+
14
+ export function Transfer({ poolInfo }: Props): React.ReactElement | null {
15
+ const dispatch = useAppDispatch()
16
+ const multiSendContract = useMultiSendContract()
17
+ const { multisend } = useAppSelector(selectWidgetState)
18
+
19
+ const handleSuccess = useCallback(() => {
20
+ dispatch(setStep(WIDGET_STEP.Done))
21
+ }, [dispatch])
22
+
23
+ if (!multisend || !multiSendContract) {
24
+ return null
25
+ }
26
+
27
+ return (
28
+ <TxSendModal
29
+ poolInfo={poolInfo}
30
+ contract={multiSendContract}
31
+ title='Transfer Tradable Stream and Money'
32
+ method='multisend'
33
+ params={[multisend.addresses, multisend.callData]}
34
+ handleSuccess={handleSuccess}
35
+ />
36
+ )
37
+ }
@@ -8,11 +8,11 @@ type Props = {
8
8
  }
9
9
 
10
10
  export function Success({ handleAction }: Props): React.ReactElement {
11
- const { borrowAmount, approveInfo } = useAppSelector(selectWidgetState)
11
+ const { borrowAmount, approval } = useAppSelector(selectWidgetState)
12
12
 
13
13
  const content = [
14
14
  `${borrowAmount?.toFixed(2)} ${
15
- approveInfo?.tokenSymbol
15
+ approval?.token.symbol
16
16
  } is now in your wallet.`,
17
17
  ]
18
18
 
@@ -1,95 +1,94 @@
1
- import { useWeb3React } from '@web3-react/core'
2
- import { POOL_NAME, POOL_TYPE, usePoolInfo } from '@huma-finance/shared'
3
- import React, { useEffect } from 'react'
4
- import { useDispatch } from 'react-redux'
5
-
6
- import { 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
- import { ErrorModal } from '../../ErrorModal'
11
- import { WidgetWrapper } from '../../WidgetWrapper'
12
- import { Evaluation } from './1-Evaluation'
13
- import { ChooseAmount } from './2-ChooseAmount'
14
- import { ConfirmTransfer } from './3-ConfirmTransfer'
15
- import { ApproveAllowance } from './4-ApproveAllowance'
16
- import { Permit } from './5-Permit'
17
- import { Transfer } from './6-Transfer'
18
- import { Success } from './7-Success'
19
-
20
- export type StreamFactoringBorrowProps = {
21
- poolName: POOL_NAME
22
- poolType: POOL_TYPE
23
- payerAddress: string
24
- superToken: string
25
- currentFlowRate: string
26
- isOpen: boolean
27
- handleClose: () => void
28
- handleSuccess: (blockNumber: number) => void
29
- }
30
-
31
- export function StreamFactoringBorrow({
32
- poolName,
33
- poolType,
34
- payerAddress,
35
- superToken,
36
- currentFlowRate,
37
- isOpen,
38
- handleClose,
39
- handleSuccess,
40
- }: StreamFactoringBorrowProps): React.ReactElement | null {
41
- const dispatch = useDispatch()
42
- const { account, chainId } = useWeb3React()
43
- const poolInfo = usePoolInfo(poolName, poolType)
44
- const { step, errorMessage } = useAppSelector(selectWidgetState)
45
-
46
- useEffect(() => {
47
- dispatch(setStep(WIDGET_STEP.Evaluation))
48
- }, [dispatch])
49
-
50
- if (!poolInfo) {
51
- return null
52
- }
53
-
54
- return (
55
- <WidgetWrapper
56
- isOpen={isOpen}
57
- handleClose={handleClose}
58
- handleSuccess={handleSuccess}
59
- >
60
- {step === WIDGET_STEP.Evaluation && (
61
- <Evaluation
62
- poolInfo={poolInfo}
63
- payerAddress={payerAddress}
64
- superToken={superToken}
65
- currentFlowRate={currentFlowRate}
66
- />
67
- )}
68
- {step === WIDGET_STEP.ChooseAmount && (
69
- <ChooseAmount poolInfo={poolInfo} currentFlowRate={currentFlowRate} />
70
- )}
71
- {step === WIDGET_STEP.ConfirmTransfer && <ConfirmTransfer />}
72
- {step === WIDGET_STEP.ApproveAllowance && (
73
- <ApproveAllowance poolInfo={poolInfo} />
74
- )}
75
- {step === WIDGET_STEP.Permit && account && chainId && (
76
- <Permit
77
- poolInfo={poolInfo}
78
- payerAddress={payerAddress}
79
- chainId={chainId}
80
- borrower={account}
81
- superToken={superToken}
82
- />
83
- )}
84
- {step === WIDGET_STEP.Transfer && <Transfer poolInfo={poolInfo} />}
85
- {step === WIDGET_STEP.Done && <Success handleAction={handleClose} />}
86
- {step === WIDGET_STEP.Error && (
87
- <ErrorModal
88
- title='Stream Borrowing'
89
- errorMessage={errorMessage}
90
- handleOk={handleClose}
91
- />
92
- )}
93
- </WidgetWrapper>
94
- )
95
- }
1
+ import { useWeb3React } from '@web3-react/core'
2
+ import { POOL_NAME, POOL_TYPE, usePoolInfo } from '@huma-finance/shared'
3
+ import React, { useEffect } from 'react'
4
+ import { useDispatch } from 'react-redux'
5
+
6
+ import { 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
+ import { ErrorModal } from '../../ErrorModal'
11
+ import { WidgetWrapper } from '../../WidgetWrapper'
12
+ import { Evaluation } from './1-Evaluation'
13
+ import { ChooseAmount } from './2-ChooseAmount'
14
+ import { ConfirmTransfer } from './3-ConfirmTransfer'
15
+ import { ApproveAllowance } from './4-ApproveAllowance'
16
+ import { Permit } from './5-Permit'
17
+ import { Transfer } from './6-Transfer'
18
+ import { Success } from './7-Success'
19
+
20
+ export type StreamFactoringBorrowProps = {
21
+ poolName: POOL_NAME
22
+ poolType: POOL_TYPE
23
+ payerAddress: string
24
+ superToken: string
25
+ currentFlowRate: string
26
+ isOpen: boolean
27
+ handleClose: () => void
28
+ handleSuccess: (blockNumber: number) => void
29
+ }
30
+
31
+ export function StreamFactoringBorrow({
32
+ poolName,
33
+ poolType,
34
+ payerAddress,
35
+ superToken,
36
+ currentFlowRate,
37
+ isOpen,
38
+ handleClose,
39
+ handleSuccess,
40
+ }: StreamFactoringBorrowProps): React.ReactElement | null {
41
+ const dispatch = useDispatch()
42
+ const { account, chainId } = useWeb3React()
43
+ const poolInfo = usePoolInfo(poolName, poolType)
44
+ const { step, errorMessage } = useAppSelector(selectWidgetState)
45
+
46
+ useEffect(() => {
47
+ dispatch(setStep(WIDGET_STEP.Evaluation))
48
+ }, [dispatch])
49
+
50
+ if (!poolInfo) {
51
+ return null
52
+ }
53
+
54
+ return (
55
+ <WidgetWrapper
56
+ isOpen={isOpen}
57
+ handleClose={handleClose}
58
+ handleSuccess={handleSuccess}
59
+ >
60
+ {step === WIDGET_STEP.Evaluation && (
61
+ <Evaluation
62
+ poolInfo={poolInfo}
63
+ payerAddress={payerAddress}
64
+ superToken={superToken}
65
+ />
66
+ )}
67
+ {step === WIDGET_STEP.ChooseAmount && (
68
+ <ChooseAmount poolInfo={poolInfo} currentFlowRate={currentFlowRate} />
69
+ )}
70
+ {step === WIDGET_STEP.ConfirmTransfer && <ConfirmTransfer />}
71
+ {step === WIDGET_STEP.ApproveAllowance && (
72
+ <ApproveAllowance poolInfo={poolInfo} />
73
+ )}
74
+ {step === WIDGET_STEP.Permit && account && chainId && (
75
+ <Permit
76
+ poolInfo={poolInfo}
77
+ payerAddress={payerAddress}
78
+ chainId={chainId}
79
+ borrower={account}
80
+ superToken={superToken}
81
+ />
82
+ )}
83
+ {step === WIDGET_STEP.Transfer && <Transfer poolInfo={poolInfo} />}
84
+ {step === WIDGET_STEP.Done && <Success handleAction={handleClose} />}
85
+ {step === WIDGET_STEP.Error && (
86
+ <ErrorModal
87
+ title='Stream Borrowing'
88
+ errorMessage={errorMessage}
89
+ handleOk={handleClose}
90
+ />
91
+ )}
92
+ </WidgetWrapper>
93
+ )
94
+ }