@huma-finance/widgets 0.0.51-beta.225 → 0.0.51-beta.346

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 (95) hide show
  1. package/API.md +454 -0
  2. package/dist/cjs/index.cjs +6069 -3795
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/index.d.ts +280 -2
  5. package/dist/index.js +6061 -3797
  6. package/dist/index.js.map +1 -1
  7. package/package.json +5 -4
  8. package/src/components/ApproveAllowanceModal.tsx +3 -1
  9. package/src/components/ApproveAllowanceModalV2.tsx +141 -0
  10. package/src/components/CreditLine/approve/index.tsx +9 -3
  11. package/src/components/CreditLine/autoPaybackV2/1-ApproveAllowance.tsx +33 -0
  12. package/src/components/CreditLine/autoPaybackV2/2-Success.tsx +13 -0
  13. package/src/components/CreditLine/autoPaybackV2/index.tsx +87 -0
  14. package/src/components/CreditLine/borrow/2-ChooseAmount.tsx +12 -3
  15. package/src/components/CreditLine/borrow/5-Success.tsx +7 -2
  16. package/src/components/CreditLine/borrow/index.tsx +4 -2
  17. package/src/components/CreditLine/borrowV2/1-ChooseAmount.tsx +81 -0
  18. package/src/components/CreditLine/borrowV2/2-ApproveAllowance.tsx +33 -0
  19. package/src/components/CreditLine/borrowV2/3-Transfer.tsx +50 -0
  20. package/src/components/CreditLine/borrowV2/4-Success.tsx +42 -0
  21. package/src/components/CreditLine/borrowV2/5-Notifications.tsx +10 -0
  22. package/src/components/CreditLine/borrowV2/index.tsx +140 -0
  23. package/src/components/CreditLine/payment/1-ChooseAmount.tsx +7 -2
  24. package/src/components/CreditLine/payment/4-Success.tsx +2 -2
  25. package/src/components/CreditLine/payment/index.tsx +4 -2
  26. package/src/components/CreditLine/paymentV2/1-ChooseAmount.tsx +96 -0
  27. package/src/components/CreditLine/paymentV2/2-ApproveAllowance.tsx +33 -0
  28. package/src/components/CreditLine/paymentV2/3-Transfer.tsx +55 -0
  29. package/src/components/CreditLine/paymentV2/4-Success.tsx +42 -0
  30. package/src/components/CreditLine/paymentV2/index.tsx +111 -0
  31. package/src/components/CreditLine/supplyFLC/1-ApproveAllowance.tsx +40 -0
  32. package/src/components/CreditLine/supplyFLC/2-Transfer.tsx +53 -0
  33. package/src/components/CreditLine/supplyFLC/3-Success.tsx +26 -0
  34. package/src/components/CreditLine/supplyFLC/index.tsx +121 -0
  35. package/src/components/Factoring/FactoredList.tsx +2 -1
  36. package/src/components/InputAmountModal.tsx +156 -0
  37. package/src/components/InvoiceFactoring/borrow/2-ChooseAmount.tsx +8 -1
  38. package/src/components/InvoiceFactoring/borrow/4-ApproveNFT.tsx +6 -2
  39. package/src/components/InvoiceFactoring/borrow/6-Success.tsx +5 -1
  40. package/src/components/InvoiceFactoring/borrow/index.tsx +9 -3
  41. package/src/components/InvoiceFactoring/payment/1-ChooseAmount.tsx +7 -2
  42. package/src/components/InvoiceFactoring/payment/index.tsx +9 -3
  43. package/src/components/Lend/addRedemptionV2/1-ChooseTranche.tsx +114 -0
  44. package/src/components/Lend/addRedemptionV2/2-ChooseAmount.tsx +62 -0
  45. package/src/components/Lend/addRedemptionV2/3-Transfer.tsx +56 -0
  46. package/src/components/Lend/addRedemptionV2/4-Done.tsx +20 -0
  47. package/src/components/Lend/addRedemptionV2/index.tsx +172 -0
  48. package/src/components/Lend/cancelRedemptionV2 /1-Transfer.tsx +51 -0
  49. package/src/components/Lend/cancelRedemptionV2 /2-Done.tsx +29 -0
  50. package/src/components/Lend/cancelRedemptionV2 /index.tsx +120 -0
  51. package/src/components/Lend/supply/1-Evaluation/EvaluationKYC.tsx +19 -2
  52. package/src/components/Lend/supply/2-ChooseAmount.tsx +1 -0
  53. package/src/components/Lend/supply/index.tsx +17 -3
  54. package/src/components/Lend/supplyV2/1-ChooseTranche.tsx +116 -0
  55. package/src/components/Lend/supplyV2/2-Evaluation.tsx +345 -0
  56. package/src/components/Lend/supplyV2/3-ChooseAmount.tsx +77 -0
  57. package/src/components/Lend/supplyV2/4-ApproveAllowance.tsx +33 -0
  58. package/src/components/Lend/supplyV2/5-Transfer.tsx +59 -0
  59. package/src/components/Lend/supplyV2/6-Success.tsx +79 -0
  60. package/src/components/Lend/supplyV2/7-Notifications.tsx +10 -0
  61. package/src/components/Lend/supplyV2/index.tsx +175 -0
  62. package/src/components/Lend/withdraw/1-CheckWithdrawble.tsx +5 -1
  63. package/src/components/Lend/withdraw/index.tsx +10 -3
  64. package/src/components/Lend/withdrawV2/1-ConfirmTransfer.tsx +135 -0
  65. package/src/components/Lend/withdrawV2/2-Transfer.tsx +50 -0
  66. package/src/components/Lend/withdrawV2/3-Done.tsx +31 -0
  67. package/src/components/Lend/withdrawV2/index.tsx +177 -0
  68. package/src/components/Notifi/NotifiSubscriptionModal.tsx +26 -38
  69. package/src/components/NumericFormatCustom.tsx +33 -0
  70. package/src/components/ReceivableBackedCreditLine/borrow/1-ChooseAmount.tsx +101 -0
  71. package/src/components/ReceivableBackedCreditLine/borrow/2-ApproveAllowance.tsx +33 -0
  72. package/src/components/ReceivableBackedCreditLine/borrow/3-ApproveReceivable.tsx +64 -0
  73. package/src/components/ReceivableBackedCreditLine/borrow/4-Transfer.tsx +61 -0
  74. package/src/components/ReceivableBackedCreditLine/borrow/5-Success.tsx +42 -0
  75. package/src/components/ReceivableBackedCreditLine/borrow/6-Notifications.tsx +10 -0
  76. package/src/components/ReceivableBackedCreditLine/borrow/index.tsx +148 -0
  77. package/src/components/ReceivableBackedCreditLine/payment/1-ChoosePaymentType.tsx +115 -0
  78. package/src/components/ReceivableBackedCreditLine/payment/2-ChooseAmount.tsx +84 -0
  79. package/src/components/ReceivableBackedCreditLine/payment/3-ApproveAllowance.tsx +41 -0
  80. package/src/components/ReceivableBackedCreditLine/payment/4-CreateReceivable.tsx +107 -0
  81. package/src/components/ReceivableBackedCreditLine/payment/5-ApproveReceivable.tsx +64 -0
  82. package/src/components/ReceivableBackedCreditLine/payment/6-Transfer.tsx +107 -0
  83. package/src/components/ReceivableBackedCreditLine/payment/7-Success.tsx +49 -0
  84. package/src/components/ReceivableBackedCreditLine/payment/index.tsx +159 -0
  85. package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +8 -1
  86. package/src/components/StreamFactoring/borrow/6-Transfer.tsx +3 -1
  87. package/src/components/StreamFactoring/borrow/7-Success.tsx +3 -1
  88. package/src/components/StreamFactoring/borrow/index.tsx +2 -2
  89. package/src/components/TxDoneModal.tsx +1 -1
  90. package/src/components/TxSendModal.tsx +8 -2
  91. package/src/components/TxSendModalV2.tsx +51 -0
  92. package/src/hooks/useNotifi.ts +4 -6
  93. package/src/index.tsx +268 -1
  94. package/src/store/widgets.reducers.ts +15 -0
  95. package/src/store/widgets.store.ts +6 -0
@@ -0,0 +1,172 @@
1
+ import {
2
+ getTrancheAssetsAndShares,
3
+ POOL_NAME,
4
+ TrancheType,
5
+ usePoolInfoV2,
6
+ usePoolUnderlyingTokenInfoV2,
7
+ } from '@huma-finance/shared'
8
+ import { useWeb3React } from '@web3-react/core'
9
+ import { BigNumber } from 'ethers'
10
+ import React, { useCallback, 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 { ChooseTranche } from './1-ChooseTranche'
20
+ import { ChooseAmount } from './2-ChooseAmount'
21
+ import { Transfer } from './3-Transfer'
22
+ import { Done } from './4-Done'
23
+
24
+ export type TrancheInfo = {
25
+ tranche: TrancheType
26
+ assets: BigNumber
27
+ shares: BigNumber
28
+ }
29
+
30
+ /**
31
+ * Lend pool add redemption props
32
+ * @typedef {Object} AddRedemptionPropsV2
33
+ * @property {POOL_NAME} poolName The name of the pool.
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 lending pool withdraw action is successful.
36
+ */
37
+ export type AddRedemptionPropsV2 = {
38
+ poolName: keyof typeof POOL_NAME
39
+ handleClose: () => void
40
+ handleSuccess?: (blockNumber?: number) => void
41
+ }
42
+
43
+ export function AddRedemptionV2({
44
+ poolName: poolNameStr,
45
+ handleClose,
46
+ handleSuccess,
47
+ }: AddRedemptionPropsV2): React.ReactElement | null {
48
+ const title = 'Redemption'
49
+ const dispatch = useDispatch()
50
+ const { account, chainId, provider } = useWeb3React()
51
+ const poolName = POOL_NAME[poolNameStr]
52
+ const poolInfo = usePoolInfoV2(poolName, chainId)
53
+ const { step, errorMessage, errorReason } = useAppSelector(selectWidgetState)
54
+ const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
55
+ const [seniorTrancheInfo, setSeniorTrancheInfo] = useState<TrancheInfo>()
56
+ const [juniorTrancheInfo, setJuniorTrancheInfo] = useState<TrancheInfo>()
57
+ const [trancheInfo, setTrancheInfo] = useState<TrancheInfo>()
58
+ const trancheInfoFetched = seniorTrancheInfo && juniorTrancheInfo
59
+
60
+ useEffect(() => {
61
+ if (account) {
62
+ getTrancheAssetsAndShares(poolName, 'senior', account, provider).then(
63
+ (info) => {
64
+ if (info) {
65
+ setSeniorTrancheInfo({ ...info, tranche: 'senior' })
66
+ }
67
+ },
68
+ )
69
+ getTrancheAssetsAndShares(poolName, 'junior', account, provider).then(
70
+ (info) => {
71
+ if (info) {
72
+ setJuniorTrancheInfo({ ...info, tranche: 'junior' })
73
+ }
74
+ },
75
+ )
76
+ }
77
+ }, [account, poolName, provider])
78
+
79
+ useEffect(() => {
80
+ if (!step && trancheInfoFetched) {
81
+ if (juniorTrancheInfo.assets.gt(0) && seniorTrancheInfo.assets.lte(0)) {
82
+ setTrancheInfo(juniorTrancheInfo)
83
+ dispatch(setStep(WIDGET_STEP.ChooseAmount))
84
+ return
85
+ }
86
+
87
+ if (seniorTrancheInfo.assets.gt(0) && juniorTrancheInfo.assets.lte(0)) {
88
+ setTrancheInfo(seniorTrancheInfo)
89
+ dispatch(setStep(WIDGET_STEP.ChooseAmount))
90
+ return
91
+ }
92
+
93
+ if (juniorTrancheInfo.assets.gt(0) && seniorTrancheInfo.assets.gt(0)) {
94
+ dispatch(setStep(WIDGET_STEP.ChooseTranche))
95
+ }
96
+ }
97
+ }, [dispatch, juniorTrancheInfo, seniorTrancheInfo, step, trancheInfoFetched])
98
+
99
+ const handleRedeemSuccess = useCallback(
100
+ (blockNumber: number) => {
101
+ if (handleSuccess) {
102
+ handleSuccess(blockNumber)
103
+ }
104
+ },
105
+ [handleSuccess],
106
+ )
107
+
108
+ const handleChangeTranche = useCallback(
109
+ (tranche: TrancheType) => {
110
+ if (tranche === 'senior') {
111
+ setTrancheInfo(seniorTrancheInfo)
112
+ } else if (tranche === 'junior') {
113
+ setTrancheInfo(juniorTrancheInfo)
114
+ } else {
115
+ setTrancheInfo(undefined)
116
+ }
117
+ },
118
+ [juniorTrancheInfo, seniorTrancheInfo],
119
+ )
120
+
121
+ if (!poolInfo || !poolUnderlyingToken || !trancheInfoFetched) {
122
+ return (
123
+ <WidgetWrapper
124
+ isOpen
125
+ isLoading
126
+ loadingTitle={title}
127
+ handleClose={handleClose}
128
+ handleSuccess={handleSuccess}
129
+ />
130
+ )
131
+ }
132
+
133
+ return (
134
+ <WidgetWrapper
135
+ isOpen
136
+ loadingTitle={title}
137
+ handleClose={handleClose}
138
+ handleSuccess={handleRedeemSuccess}
139
+ >
140
+ {step === WIDGET_STEP.ChooseTranche && (
141
+ <ChooseTranche
142
+ selectedTranche={trancheInfo?.tranche}
143
+ changeTranche={handleChangeTranche}
144
+ />
145
+ )}
146
+ {step === WIDGET_STEP.ChooseAmount && trancheInfo && (
147
+ <ChooseAmount
148
+ poolUnderlyingToken={poolUnderlyingToken}
149
+ trancheInfo={trancheInfo}
150
+ />
151
+ )}
152
+ {step === WIDGET_STEP.Transfer && trancheInfo && (
153
+ <Transfer
154
+ poolInfo={poolInfo}
155
+ poolUnderlyingToken={poolUnderlyingToken}
156
+ trancheInfo={trancheInfo}
157
+ />
158
+ )}
159
+ {step === WIDGET_STEP.Done && trancheInfo && (
160
+ <Done handleAction={handleClose} />
161
+ )}
162
+ {step === WIDGET_STEP.Error && (
163
+ <ErrorModal
164
+ title={title}
165
+ errorReason={errorReason}
166
+ errorMessage={errorMessage}
167
+ handleOk={handleClose}
168
+ />
169
+ )}
170
+ </WidgetWrapper>
171
+ )
172
+ }
@@ -0,0 +1,51 @@
1
+ import {
2
+ PoolInfoV2,
3
+ TrancheType,
4
+ useTrancheVaultContractV2,
5
+ } from '@huma-finance/shared'
6
+ import { useWeb3React } from '@web3-react/core'
7
+ import React, { useCallback } from 'react'
8
+
9
+ import { RedemptionInfo } from '.'
10
+ import { useAppDispatch } from '../../../hooks/useRedux'
11
+ import { setStep } from '../../../store/widgets.reducers'
12
+ import { WIDGET_STEP } from '../../../store/widgets.store'
13
+ import { TxSendModalV2 } from '../../TxSendModalV2'
14
+
15
+ type Props = {
16
+ poolInfo: PoolInfoV2
17
+ trancheType: TrancheType
18
+ redemptionInfo: RedemptionInfo
19
+ }
20
+
21
+ export function Transfer({
22
+ poolInfo,
23
+ trancheType,
24
+ redemptionInfo,
25
+ }: Props): React.ReactElement | null {
26
+ const dispatch = useAppDispatch()
27
+ const { account, provider } = useWeb3React()
28
+ const trancheVaultContract = useTrancheVaultContractV2(
29
+ poolInfo.poolName,
30
+ trancheType,
31
+ provider,
32
+ account,
33
+ )
34
+
35
+ const handleSuccess = useCallback(() => {
36
+ dispatch(setStep(WIDGET_STEP.Done))
37
+ }, [dispatch])
38
+
39
+ if (!trancheVaultContract) {
40
+ return null
41
+ }
42
+
43
+ return (
44
+ <TxSendModalV2
45
+ contract={trancheVaultContract}
46
+ method='cancelRedemptionRequest'
47
+ params={[redemptionInfo.shares]}
48
+ handleSuccess={handleSuccess}
49
+ />
50
+ )
51
+ }
@@ -0,0 +1,29 @@
1
+ import { UnderlyingTokenInfo } from '@huma-finance/shared'
2
+ import { ethers } from 'ethers'
3
+ import React from 'react'
4
+
5
+ import { RedemptionInfo } from '.'
6
+ import { TxDoneModal } from '../../TxDoneModal'
7
+
8
+ type Props = {
9
+ poolUnderlyingToken: UnderlyingTokenInfo
10
+ redemptionInfo: RedemptionInfo
11
+ handleAction: () => void
12
+ }
13
+
14
+ export function Done({
15
+ poolUnderlyingToken,
16
+ redemptionInfo,
17
+ handleAction,
18
+ }: Props): React.ReactElement {
19
+ const shares = ethers.utils.formatUnits(
20
+ redemptionInfo.shares,
21
+ poolUnderlyingToken.decimals,
22
+ )
23
+
24
+ const content = [
25
+ `You successfully canceled ${shares} shares redemption request.`,
26
+ ]
27
+
28
+ return <TxDoneModal handleAction={handleAction} content={content} />
29
+ }
@@ -0,0 +1,120 @@
1
+ import {
2
+ POOL_NAME,
3
+ TrancheType,
4
+ useCancellableRedemptionInfoV2,
5
+ usePoolInfoV2,
6
+ usePoolUnderlyingTokenInfoV2,
7
+ } from '@huma-finance/shared'
8
+ import { useWeb3React } from '@web3-react/core'
9
+ import { BigNumber } from 'ethers'
10
+ import React, { useCallback, useEffect } 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 { Transfer } from './1-Transfer'
20
+ import { Done } from './2-Done'
21
+
22
+ export type RedemptionInfo = {
23
+ shares: BigNumber
24
+ amount: BigNumber
25
+ }
26
+
27
+ /**
28
+ * Lend pool cancel redemption request props
29
+ * @typedef {Object} CancelRedemptionPropsV2
30
+ * @property {POOL_NAME} poolName The name of the pool.
31
+ * @property {TrancheType} trancheType The type of the tranche.
32
+ * @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
33
+ * @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the lending pool withdraw action is successful.
34
+ */
35
+ export type CancelRedemptionPropsV2 = {
36
+ poolName: keyof typeof POOL_NAME
37
+ trancheType: TrancheType
38
+ handleClose: () => void
39
+ handleSuccess?: (blockNumber?: number) => void
40
+ }
41
+
42
+ export function CancelRedemptionV2({
43
+ poolName: poolNameStr,
44
+ trancheType,
45
+ handleClose,
46
+ handleSuccess,
47
+ }: CancelRedemptionPropsV2): React.ReactElement | null {
48
+ const title = 'Cancel redemption'
49
+ const dispatch = useDispatch()
50
+ const { account, chainId, provider } = useWeb3React()
51
+ const poolName = POOL_NAME[poolNameStr]
52
+ const poolInfo = usePoolInfoV2(poolName, chainId)
53
+ const { step, errorMessage, errorReason } = useAppSelector(selectWidgetState)
54
+ const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
55
+ const [redemptionInfo] = useCancellableRedemptionInfoV2(
56
+ poolName,
57
+ trancheType,
58
+ account,
59
+ provider,
60
+ )
61
+
62
+ useEffect(() => {
63
+ if (!step) {
64
+ dispatch(setStep(WIDGET_STEP.Transfer))
65
+ }
66
+ }, [dispatch, step])
67
+
68
+ const handleRedeemSuccess = useCallback(
69
+ (blockNumber: number) => {
70
+ if (handleSuccess) {
71
+ handleSuccess(blockNumber)
72
+ }
73
+ },
74
+ [handleSuccess],
75
+ )
76
+
77
+ if (!poolInfo || !poolUnderlyingToken || !redemptionInfo) {
78
+ return (
79
+ <WidgetWrapper
80
+ isOpen
81
+ isLoading
82
+ loadingTitle={title}
83
+ handleClose={handleClose}
84
+ handleSuccess={handleSuccess}
85
+ />
86
+ )
87
+ }
88
+
89
+ return (
90
+ <WidgetWrapper
91
+ isOpen
92
+ loadingTitle={title}
93
+ handleClose={handleClose}
94
+ handleSuccess={handleRedeemSuccess}
95
+ >
96
+ {step === WIDGET_STEP.Transfer && (
97
+ <Transfer
98
+ poolInfo={poolInfo}
99
+ trancheType={trancheType}
100
+ redemptionInfo={redemptionInfo}
101
+ />
102
+ )}
103
+ {step === WIDGET_STEP.Done && (
104
+ <Done
105
+ poolUnderlyingToken={poolUnderlyingToken}
106
+ handleAction={handleClose}
107
+ redemptionInfo={redemptionInfo}
108
+ />
109
+ )}
110
+ {step === WIDGET_STEP.Error && (
111
+ <ErrorModal
112
+ title={title}
113
+ errorReason={errorReason}
114
+ errorMessage={errorMessage}
115
+ handleOk={handleClose}
116
+ />
117
+ )}
118
+ </WidgetWrapper>
119
+ )
120
+ }
@@ -87,8 +87,11 @@ export function EvaluationKYC({
87
87
  const isDev = checkIsDev()
88
88
  const { account, chainId } = useWeb3React()
89
89
  const { kycProvider, code, kycPool } = useParamsSearch()
90
- const { isWalletOwnershipVerified, setError: setAuthError } =
91
- useAuthErrorHandling(isDev)
90
+ const {
91
+ isWalletOwnershipVerified,
92
+ setError: setAuthError,
93
+ error: authError,
94
+ } = useAuthErrorHandling(isDev)
92
95
  const [loadingType, setLoadingType] = useState<
93
96
  'verificationStatus' | 'sendDocSignatureLink'
94
97
  >()
@@ -250,6 +253,20 @@ export function EvaluationKYC({
250
253
  isWalletOwnershipVerified,
251
254
  ])
252
255
 
256
+ useEffect(() => {
257
+ if (
258
+ authError &&
259
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
260
+ [4001, 'ACTION_REJECTED'].includes((authError as any).code)
261
+ ) {
262
+ dispatch(
263
+ setError({
264
+ errorMessage: 'User has rejected the transaction.',
265
+ }),
266
+ )
267
+ }
268
+ }, [authError, dispatch])
269
+
253
270
  const approveLender = async () => {
254
271
  if (docSignatureCompleted) {
255
272
  handleClose()
@@ -48,6 +48,7 @@ export function ChooseAmount({
48
48
  : WIDGET_STEP.Transfer
49
49
  dispatch(setStep(step))
50
50
  }, [dispatch, needApprove])
51
+
51
52
  return (
52
53
  <ChooseAmountModal
53
54
  title={`Supply ${symbol}`}
@@ -52,33 +52,47 @@ export function LendSupply({
52
52
  handleSuccess,
53
53
  }: LendSupplyProps): React.ReactElement | null {
54
54
  const dispatch = useDispatch()
55
- const { account, chainId } = useWeb3React()
55
+ const { account, chainId, provider } = useWeb3React()
56
56
  const poolName = POOL_NAME[poolNameStr]
57
57
  const poolType = POOL_TYPE[poolTypeStr]
58
- const poolInfo = usePoolInfo(poolName, poolType)
58
+ const poolInfo = usePoolInfo(poolName, poolType, chainId)
59
59
  const { decimals } = poolInfo?.poolUnderlyingToken || {}
60
60
  const { step, errorMessage } = useAppSelector(selectWidgetState)
61
- const { allowance } = usePoolAllowance(poolName, poolType, account)
61
+ const { allowance } = usePoolAllowance(
62
+ poolName,
63
+ poolType,
64
+ chainId,
65
+ account,
66
+ provider,
67
+ )
62
68
  const { isFirstTimeNotifiUser } = useIsFirstTimeNotifiUser(account, chainId)
63
69
  const { notifiChainSupported } = useDoesChainSupportNotifi(account, chainId)
64
70
  const [lenderApproved, refreshLenderApproved] = useLenderApproved(
65
71
  poolName,
66
72
  poolType,
73
+ chainId,
67
74
  account,
75
+ provider,
68
76
  )
69
77
  const [, refreshLenderPosition] = useLenderPosition(
70
78
  poolName,
71
79
  poolType,
80
+ chainId,
72
81
  account,
82
+ provider,
73
83
  )
74
84
  const withdrawlLockoutSeconds = useWithdrawlLockoutInSeconds(
75
85
  poolName,
76
86
  poolType,
87
+ chainId,
88
+ provider,
77
89
  )
78
90
  const underlyingTokenBalance = usePoolUnderlyingTokenBalance(
79
91
  poolName,
80
92
  poolType,
93
+ chainId,
81
94
  account,
95
+ provider,
82
96
  )
83
97
  const balanceWithoutDecimals = downScale(underlyingTokenBalance, decimals)
84
98
 
@@ -0,0 +1,116 @@
1
+ import { TrancheType, UnderlyingTokenInfo } from '@huma-finance/shared'
2
+ import {
3
+ css,
4
+ FormControl,
5
+ FormControlLabel,
6
+ FormLabel,
7
+ Radio,
8
+ RadioGroup,
9
+ useTheme,
10
+ } from '@mui/material'
11
+ import React 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 { BottomButton } from '../../BottomButton'
17
+ import { WrapperModal } from '../../WrapperModal'
18
+
19
+ type Props = {
20
+ poolUnderlyingToken: UnderlyingTokenInfo
21
+ selectedTranche: TrancheType | undefined
22
+ changeTranche: (tranche: TrancheType) => void
23
+ }
24
+
25
+ export function ChooseTranche({
26
+ poolUnderlyingToken,
27
+ selectedTranche,
28
+ changeTranche,
29
+ }: Props): React.ReactElement | null {
30
+ const theme = useTheme()
31
+ const dispatch = useAppDispatch()
32
+
33
+ const styles = {
34
+ subTitle: css`
35
+ color: ${theme.palette.text.primary} !important;
36
+ font-family: 'Uni-Neue-Regular';
37
+ font-size: 16px;
38
+ line-height: 150%;
39
+ letter-spacing: 0.15px;
40
+ margin-top: ${theme.spacing(5)};
41
+ margin-left: ${theme.spacing(2)};
42
+ `,
43
+ radioGroup: css`
44
+ margin-left: ${theme.spacing(3)};
45
+ margin-top: ${theme.spacing(3)};
46
+ `,
47
+ formControl: css`
48
+ margin-bottom: ${theme.spacing(1)};
49
+
50
+ .MuiFormControlLabel-label {
51
+ color: ${theme.palette.text.primary};
52
+ font-family: 'Uni-Neue-Regular';
53
+ font-size: 16px;
54
+ line-height: 150%;
55
+ letter-spacing: 0.15px;
56
+ }
57
+ `,
58
+ }
59
+
60
+ const handleNext = () => {
61
+ dispatch(setStep(WIDGET_STEP.ChooseAmount))
62
+ }
63
+
64
+ const items: {
65
+ label: string
66
+ value: TrancheType
67
+ }[] = [
68
+ {
69
+ label: 'Senior',
70
+ value: 'senior',
71
+ },
72
+ {
73
+ label: 'Junior',
74
+ value: 'junior',
75
+ },
76
+ ]
77
+
78
+ return (
79
+ <WrapperModal title={`Supply ${poolUnderlyingToken.symbol}`}>
80
+ <FormControl>
81
+ <FormLabel css={styles.subTitle}>Select Tranche Type</FormLabel>
82
+ <RadioGroup
83
+ aria-labelledby='buttons-group-label'
84
+ name='radio-buttons-group'
85
+ css={styles.radioGroup}
86
+ onChange={(e) => changeTranche(e.target.value as TrancheType)}
87
+ >
88
+ {items.map((item) => (
89
+ <FormControlLabel
90
+ key={item.label}
91
+ value={item.value}
92
+ control={
93
+ <Radio
94
+ sx={{
95
+ '& .MuiSvgIcon-root': {
96
+ fontSize: 24,
97
+ },
98
+ }}
99
+ />
100
+ }
101
+ label={item.label}
102
+ css={styles.formControl}
103
+ />
104
+ ))}
105
+ </RadioGroup>
106
+ </FormControl>
107
+ <BottomButton
108
+ variant='contained'
109
+ disabled={!selectedTranche}
110
+ onClick={handleNext}
111
+ >
112
+ NEXT
113
+ </BottomButton>
114
+ </WrapperModal>
115
+ )
116
+ }