@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,32 +1,32 @@
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
- }
13
-
14
- export function Transfer({ poolInfo }: Props): React.ReactElement {
15
- const dispatch = useAppDispatch()
16
- const { decimals } = poolInfo.poolUnderlyingToken
17
- const { withdrawAmount } = useAppSelector(selectWidgetState)
18
- const withdrawBigNumber = toBigNumber(upScale(withdrawAmount!, decimals))
19
-
20
- const handleSuccess = useCallback(() => {
21
- dispatch(setStep(WIDGET_STEP.Done))
22
- }, [dispatch])
23
-
24
- return (
25
- <TxSendModal
26
- poolInfo={poolInfo}
27
- method='withdraw'
28
- params={[withdrawBigNumber]}
29
- handleSuccess={handleSuccess}
30
- />
31
- )
32
- }
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
+ }
13
+
14
+ export function Transfer({ poolInfo }: Props): React.ReactElement {
15
+ const dispatch = useAppDispatch()
16
+ const { decimals } = poolInfo.poolUnderlyingToken
17
+ const { withdrawAmount } = useAppSelector(selectWidgetState)
18
+ const withdrawBigNumber = toBigNumber(upScale(withdrawAmount!, decimals))
19
+
20
+ const handleSuccess = useCallback(() => {
21
+ dispatch(setStep(WIDGET_STEP.Done))
22
+ }, [dispatch])
23
+
24
+ return (
25
+ <TxSendModal
26
+ poolInfo={poolInfo}
27
+ method='withdraw'
28
+ params={[withdrawBigNumber]}
29
+ handleSuccess={handleSuccess}
30
+ />
31
+ )
32
+ }
@@ -1,49 +1,49 @@
1
- import { useWeb3React } from '@web3-react/core'
2
- import {
3
- decodeLogs,
4
- downScale,
5
- formatMoney,
6
- PoolInfoType,
7
- sendTxAtom,
8
- } from '@huma-finance/shared'
9
- import transferAbi from '@huma-finance/shared/dist/abis/Transfer.json'
10
- import { useAtom } from 'jotai'
11
- import React, { useEffect, useState } from 'react'
12
-
13
- import { TxDoneModal } from '../../TxDoneModal'
14
-
15
- type Props = {
16
- poolInfo: PoolInfoType
17
- handleAction: () => void
18
- }
19
-
20
- export function Success({ poolInfo, handleAction }: Props): React.ReactElement {
21
- const { account } = useWeb3React()
22
- const { poolUnderlyingToken } = poolInfo
23
- const [{ txReceipt }] = useAtom(sendTxAtom)
24
- const { symbol, decimals, address } = poolUnderlyingToken
25
- const [withdrawAmount, setWithdrawAmount] = useState<string | undefined>()
26
-
27
- useEffect(() => {
28
- if (txReceipt) {
29
- const events = decodeLogs(txReceipt.logs, transferAbi)
30
- if (events) {
31
- events.forEach((event) => {
32
- const { from, to, value } = event.args
33
- if (
34
- from.toLowerCase() === poolInfo.pool.toLowerCase() &&
35
- to.toLowerCase() === account?.toLowerCase()
36
- ) {
37
- setWithdrawAmount(downScale(value.toString(), decimals))
38
- }
39
- })
40
- }
41
- }
42
- }, [account, address, decimals, poolInfo.pool, txReceipt])
43
-
44
- const content = [
45
- `You successfully withdrawn ${formatMoney(withdrawAmount)} ${symbol}.`,
46
- ]
47
-
48
- return <TxDoneModal handleAction={handleAction} content={content} />
49
- }
1
+ import { useWeb3React } from '@web3-react/core'
2
+ import {
3
+ decodeLogs,
4
+ downScale,
5
+ formatMoney,
6
+ PoolInfoType,
7
+ sendTxAtom,
8
+ } from '@huma-finance/shared'
9
+ import transferAbi from '@huma-finance/shared/dist/abis/Transfer.json'
10
+ import { useAtom } from 'jotai'
11
+ import React, { useEffect, useState } from 'react'
12
+
13
+ import { TxDoneModal } from '../../TxDoneModal'
14
+
15
+ type Props = {
16
+ poolInfo: PoolInfoType
17
+ handleAction: () => void
18
+ }
19
+
20
+ export function Success({ poolInfo, handleAction }: Props): React.ReactElement {
21
+ const { account } = useWeb3React()
22
+ const { poolUnderlyingToken } = poolInfo
23
+ const [{ txReceipt }] = useAtom(sendTxAtom)
24
+ const { symbol, decimals, address } = poolUnderlyingToken
25
+ const [withdrawAmount, setWithdrawAmount] = useState<string | undefined>()
26
+
27
+ useEffect(() => {
28
+ if (txReceipt) {
29
+ const events = decodeLogs(txReceipt.logs, transferAbi)
30
+ if (events) {
31
+ events.forEach((event) => {
32
+ const { from, to, value } = event.args
33
+ if (
34
+ from.toLowerCase() === poolInfo.pool.toLowerCase() &&
35
+ to.toLowerCase() === account?.toLowerCase()
36
+ ) {
37
+ setWithdrawAmount(downScale(value.toString(), decimals))
38
+ }
39
+ })
40
+ }
41
+ }
42
+ }, [account, address, decimals, poolInfo.pool, txReceipt])
43
+
44
+ const content = [
45
+ `You successfully withdrawn ${formatMoney(withdrawAmount)} ${symbol}.`,
46
+ ]
47
+
48
+ return <TxDoneModal handleAction={handleAction} content={content} />
49
+ }
@@ -1,101 +1,101 @@
1
- import { useWeb3React } from '@web3-react/core'
2
- import {
3
- POOL_NAME,
4
- POOL_TYPE,
5
- useLenderPosition,
6
- usePoolInfo,
7
- } from '@huma-finance/shared'
8
- import React, { useCallback, useEffect } from 'react'
9
- import { useDispatch } from 'react-redux'
10
-
11
- import { useAppSelector } from '../../../hooks/useRedux'
12
- import { setStep } from '../../../store/widgets.reducers'
13
- import { selectWidgetState } from '../../../store/widgets.selectors'
14
- import { WIDGET_STEP } from '../../../store/widgets.store'
15
- import { ErrorModal } from '../../ErrorModal'
16
- import { WidgetWrapper } from '../../WidgetWrapper'
17
- import { CheckWithdrawable } from './1-CheckWithdrawble'
18
- import { ChooseAmount } from './2-ChooseAmount'
19
- import { Transfer } from './3-Transfer'
20
- import { Success } from './4-Success'
21
-
22
- /**
23
- * Lend pool withdraw props
24
- * @typedef {Object} LendWithdrawProps
25
- * @property {POOL_NAME} poolName The name of the pool.
26
- * @property {POOL_TYPE} poolType The type of the pool.
27
- * @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
28
- * @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the lending pool withdraw action is successful.
29
- */
30
- export type LendWithdrawProps = {
31
- poolName: keyof typeof POOL_NAME
32
- poolType: keyof typeof POOL_TYPE
33
- handleClose: () => void
34
- handleSuccess?: (blockNumber?: number) => void
35
- }
36
-
37
- export function LendWithdraw({
38
- poolName: poolNameStr,
39
- poolType: poolTypeStr,
40
- handleClose,
41
- handleSuccess,
42
- }: LendWithdrawProps): React.ReactElement | null {
43
- const dispatch = useDispatch()
44
- const { account } = useWeb3React()
45
- const poolName = POOL_NAME[poolNameStr]
46
- const poolType = POOL_TYPE[poolTypeStr]
47
- const poolInfo = usePoolInfo(poolName, poolType)
48
- const { step, errorMessage } = useAppSelector(selectWidgetState)
49
- const [lenderPosition, refreshLenderPosition] = useLenderPosition(
50
- poolName,
51
- poolType,
52
- account,
53
- )
54
-
55
- useEffect(() => {
56
- if (!step && lenderPosition) {
57
- dispatch(setStep(WIDGET_STEP.CheckWithdrawable))
58
- }
59
- }, [dispatch, lenderPosition, step])
60
-
61
- const handleWithdrawSuccess = useCallback(
62
- (blockNumber: number) => {
63
- refreshLenderPosition()
64
- if (handleSuccess) {
65
- handleSuccess(blockNumber)
66
- }
67
- },
68
- [handleSuccess, refreshLenderPosition],
69
- )
70
-
71
- if (!poolInfo) {
72
- return null
73
- }
74
-
75
- return (
76
- <WidgetWrapper
77
- isOpen
78
- handleClose={handleClose}
79
- handleSuccess={handleWithdrawSuccess}
80
- >
81
- {(!step || step === WIDGET_STEP.CheckWithdrawable) && (
82
- <CheckWithdrawable poolInfo={poolInfo} handleClose={handleClose} />
83
- )}
84
- {step === WIDGET_STEP.ChooseAmount && (
85
- <ChooseAmount poolInfo={poolInfo} lenderPosition={lenderPosition!} />
86
- )}
87
- {step === WIDGET_STEP.Transfer && <Transfer poolInfo={poolInfo} />}
88
- {step === WIDGET_STEP.Done && (
89
- <Success poolInfo={poolInfo} handleAction={handleClose} />
90
- )}
91
- {step === WIDGET_STEP.Error && (
92
- <ErrorModal
93
- title='Withdraw'
94
- errorReason='Sorry there was an error'
95
- errorMessage={errorMessage}
96
- handleOk={handleClose}
97
- />
98
- )}
99
- </WidgetWrapper>
100
- )
101
- }
1
+ import { useWeb3React } from '@web3-react/core'
2
+ import {
3
+ POOL_NAME,
4
+ POOL_TYPE,
5
+ useLenderPosition,
6
+ usePoolInfo,
7
+ } from '@huma-finance/shared'
8
+ import React, { useCallback, useEffect } from 'react'
9
+ import { useDispatch } from 'react-redux'
10
+
11
+ import { useAppSelector } from '../../../hooks/useRedux'
12
+ import { setStep } from '../../../store/widgets.reducers'
13
+ import { selectWidgetState } from '../../../store/widgets.selectors'
14
+ import { WIDGET_STEP } from '../../../store/widgets.store'
15
+ import { ErrorModal } from '../../ErrorModal'
16
+ import { WidgetWrapper } from '../../WidgetWrapper'
17
+ import { CheckWithdrawable } from './1-CheckWithdrawble'
18
+ import { ChooseAmount } from './2-ChooseAmount'
19
+ import { Transfer } from './3-Transfer'
20
+ import { Success } from './4-Success'
21
+
22
+ /**
23
+ * Lend pool withdraw props
24
+ * @typedef {Object} LendWithdrawProps
25
+ * @property {POOL_NAME} poolName The name of the pool.
26
+ * @property {POOL_TYPE} poolType The type of the pool.
27
+ * @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
28
+ * @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the lending pool withdraw action is successful.
29
+ */
30
+ export type LendWithdrawProps = {
31
+ poolName: keyof typeof POOL_NAME
32
+ poolType: keyof typeof POOL_TYPE
33
+ handleClose: () => void
34
+ handleSuccess?: (blockNumber?: number) => void
35
+ }
36
+
37
+ export function LendWithdraw({
38
+ poolName: poolNameStr,
39
+ poolType: poolTypeStr,
40
+ handleClose,
41
+ handleSuccess,
42
+ }: LendWithdrawProps): React.ReactElement | null {
43
+ const dispatch = useDispatch()
44
+ const { account } = useWeb3React()
45
+ const poolName = POOL_NAME[poolNameStr]
46
+ const poolType = POOL_TYPE[poolTypeStr]
47
+ const poolInfo = usePoolInfo(poolName, poolType)
48
+ const { step, errorMessage } = useAppSelector(selectWidgetState)
49
+ const [lenderPosition, refreshLenderPosition] = useLenderPosition(
50
+ poolName,
51
+ poolType,
52
+ account,
53
+ )
54
+
55
+ useEffect(() => {
56
+ if (!step && lenderPosition) {
57
+ dispatch(setStep(WIDGET_STEP.CheckWithdrawable))
58
+ }
59
+ }, [dispatch, lenderPosition, step])
60
+
61
+ const handleWithdrawSuccess = useCallback(
62
+ (blockNumber: number) => {
63
+ refreshLenderPosition()
64
+ if (handleSuccess) {
65
+ handleSuccess(blockNumber)
66
+ }
67
+ },
68
+ [handleSuccess, refreshLenderPosition],
69
+ )
70
+
71
+ if (!poolInfo) {
72
+ return null
73
+ }
74
+
75
+ return (
76
+ <WidgetWrapper
77
+ isOpen
78
+ handleClose={handleClose}
79
+ handleSuccess={handleWithdrawSuccess}
80
+ >
81
+ {(!step || step === WIDGET_STEP.CheckWithdrawable) && (
82
+ <CheckWithdrawable poolInfo={poolInfo} handleClose={handleClose} />
83
+ )}
84
+ {step === WIDGET_STEP.ChooseAmount && (
85
+ <ChooseAmount poolInfo={poolInfo} lenderPosition={lenderPosition!} />
86
+ )}
87
+ {step === WIDGET_STEP.Transfer && <Transfer poolInfo={poolInfo} />}
88
+ {step === WIDGET_STEP.Done && (
89
+ <Success poolInfo={poolInfo} handleAction={handleClose} />
90
+ )}
91
+ {step === WIDGET_STEP.Error && (
92
+ <ErrorModal
93
+ title='Withdraw'
94
+ errorReason='Sorry there was an error'
95
+ errorMessage={errorMessage}
96
+ handleOk={handleClose}
97
+ />
98
+ )}
99
+ </WidgetWrapper>
100
+ )
101
+ }
@@ -1,57 +1,47 @@
1
- import { useWeb3React } from '@web3-react/core'
2
- import { PoolInfoType, toBigNumber } from '@huma-finance/shared'
3
- import React, { useEffect } from 'react'
4
-
5
- import useEA from '../../../hooks/useEA'
6
- import { LoadingModal } from '../../LoadingModal'
7
- import { WIDGET_STEP } from '../../../store/widgets.store'
8
-
9
- type Props = {
10
- poolInfo: PoolInfoType
11
- payerAddress: string
12
- superToken: string
13
- currentFlowRate: string
14
- }
15
-
16
- export function Evaluation({
17
- poolInfo,
18
- payerAddress,
19
- superToken,
20
- currentFlowRate,
21
- }: Props): React.ReactElement {
22
- const { account } = useWeb3React()
23
- const { checkingEA } = useEA()
24
- const ONE_MONTH_SECONDS = 30 * 24 * 60 * 60
25
- const creditLimit = toBigNumber(currentFlowRate)
26
- .mul(ONE_MONTH_SECONDS)
27
- .toString()
28
-
29
- useEffect(() => {
30
- if (account) {
31
- checkingEA(
32
- {
33
- creditLimit,
34
- poolAddress: poolInfo.pool,
35
- borrowerWalletAddress: account,
36
- payerAddress,
37
- superToken,
38
- },
39
- WIDGET_STEP.ChooseAmount,
40
- )
41
- }
42
- }, [
43
- account,
44
- checkingEA,
45
- creditLimit,
46
- payerAddress,
47
- poolInfo.pool,
48
- superToken,
49
- ])
50
-
51
- return (
52
- <LoadingModal
53
- title='Checking Stream'
54
- description='Checking if the stream qualifies for factoring...'
55
- />
56
- )
57
- }
1
+ import { useWeb3React } from '@web3-react/core'
2
+ import { PoolInfoType } from '@huma-finance/shared'
3
+ import React, { useEffect } from 'react'
4
+
5
+ import useEA from '../../../hooks/useEA'
6
+ import { LoadingModal } from '../../LoadingModal'
7
+ import { WIDGET_STEP } from '../../../store/widgets.store'
8
+
9
+ type Props = {
10
+ poolInfo: PoolInfoType
11
+ payerAddress: string
12
+ superToken: string
13
+ }
14
+
15
+ export function Evaluation({
16
+ poolInfo,
17
+ payerAddress,
18
+ superToken,
19
+ }: Props): React.ReactElement {
20
+ const { account } = useWeb3React()
21
+ const { checkingEA } = useEA()
22
+
23
+ useEffect(() => {
24
+ if (account) {
25
+ checkingEA(
26
+ {
27
+ poolAddress: poolInfo.pool,
28
+ borrowerWalletAddress: account,
29
+ payerAddress,
30
+ superToken,
31
+ context: {
32
+ payerAddress,
33
+ superToken,
34
+ },
35
+ },
36
+ WIDGET_STEP.ChooseAmount,
37
+ )
38
+ }
39
+ }, [account, checkingEA, payerAddress, poolInfo.pool, superToken])
40
+
41
+ return (
42
+ <LoadingModal
43
+ title='Checking Stream'
44
+ description='Checking if the stream qualifies for factoring...'
45
+ />
46
+ )
47
+ }