@huma-finance/widgets 0.0.31 → 0.0.33
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/.env.example +2 -2
- package/.eslintignore +2 -2
- package/.eslintrc.js +64 -64
- package/.prettierignore +4 -4
- package/.prettierrc.js +16 -16
- package/API.md +332 -332
- package/LICENSE +660 -660
- package/README.md +48 -48
- package/babel.config.js +15 -15
- package/config-overrides.js +9 -9
- package/cosmos.config.json +7 -7
- package/cypress/e2e/01-invoice-factoring-borrow.test.ts +62 -62
- package/cypress/support/e2e.ts +76 -76
- package/cypress/support/ethereum.ts +142 -142
- package/cypress/tsconfig.json +9 -9
- package/cypress/utils/index.ts +54 -54
- package/cypress.config.ts +20 -20
- package/dist/cjs/index.cjs +1026 -296
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.d.ts +193 -193
- package/dist/index.js +1028 -299
- package/dist/index.js.map +1 -1
- package/jsdoc2md.json +20 -20
- package/package.json +4 -4
- package/public/index.html +40 -40
- package/public/manifest.json +25 -25
- package/public/robots.txt +3 -3
- package/rollup.config.js +81 -81
- package/src/components/Activity.tsx +132 -132
- package/src/components/ApolloWrapper.tsx +15 -15
- package/src/components/ApproveAllowanceModal.tsx +121 -121
- package/src/components/BottomButton.tsx +33 -33
- package/src/components/ChainNotSupportedModal.tsx +33 -33
- package/src/components/ChooseAmountModal.tsx +322 -322
- package/src/components/ConfirmTransferModal.tsx +153 -153
- package/src/components/CreditLine/borrow/1-Evaluation.tsx +157 -157
- package/src/components/CreditLine/borrow/2-ChooseAmount.tsx +68 -68
- package/src/components/CreditLine/borrow/3-Transfer.tsx +44 -44
- package/src/components/CreditLine/borrow/4-ApproveAllowance.tsx +29 -29
- package/src/components/CreditLine/borrow/5-Success.tsx +38 -30
- package/src/components/CreditLine/borrow/6-Notifications.tsx +10 -0
- package/src/components/CreditLine/borrow/index.tsx +136 -117
- package/src/components/CreditLine/payment/1-ChooseAmount.tsx +67 -67
- package/src/components/CreditLine/payment/2-ApproveAllowance.tsx +23 -23
- package/src/components/CreditLine/payment/3-Transfer.tsx +34 -34
- package/src/components/CreditLine/payment/4-Success.tsx +39 -39
- package/src/components/CreditLine/payment/index.tsx +94 -94
- package/src/components/ErrorModal.tsx +132 -132
- package/src/components/Factoring/FactoredList.tsx +143 -143
- package/src/components/Factoring/UpcomingList.tsx +90 -90
- package/src/components/Factoring/index.ts +2 -2
- package/src/components/HumaLoading.tsx +68 -68
- package/src/components/HumaSnackBar.tsx +60 -0
- package/src/components/HumaTable.tsx +158 -158
- package/src/components/InvoiceFactoring/borrow/1-Evaluation.tsx +49 -49
- package/src/components/InvoiceFactoring/borrow/2-ChooseAmount.tsx +88 -88
- package/src/components/InvoiceFactoring/borrow/3-ConfirmTransfer.tsx +37 -37
- package/src/components/InvoiceFactoring/borrow/4-ApproveNFT.tsx +55 -55
- package/src/components/InvoiceFactoring/borrow/5-Transfer.tsx +34 -34
- package/src/components/InvoiceFactoring/borrow/6-Success.tsx +20 -20
- package/src/components/InvoiceFactoring/borrow/index.tsx +94 -94
- package/src/components/InvoiceFactoring/payment/1-ChooseAmount.tsx +67 -67
- package/src/components/InvoiceFactoring/payment/2-ApproveAllowance.tsx +23 -23
- package/src/components/InvoiceFactoring/payment/3-Transfer.tsx +34 -34
- package/src/components/InvoiceFactoring/payment/4-Success.tsx +23 -23
- package/src/components/InvoiceFactoring/payment/index.tsx +86 -86
- package/src/components/Lend/supply/1-Evaluation/EvaluationEA.tsx +86 -0
- package/src/components/Lend/supply/1-Evaluation/EvaluationKYC.tsx +287 -0
- package/src/components/Lend/supply/1-Evaluation/index.tsx +31 -0
- package/src/components/Lend/supply/2-ChooseAmount.tsx +69 -70
- package/src/components/Lend/supply/3-ApproveAllowance.tsx +25 -25
- package/src/components/Lend/supply/{6-Transfer.tsx → 4-Transfer.tsx} +32 -32
- package/src/components/Lend/supply/{7-Success.tsx → 5-Success.tsx} +60 -49
- package/src/components/Lend/supply/6-Notifications.tsx +10 -0
- package/src/components/Lend/supply/index.tsx +167 -144
- package/src/components/Lend/withdraw/1-CheckWithdrawble.tsx +73 -73
- package/src/components/Lend/withdraw/2-ChooseAmount.tsx +50 -50
- package/src/components/Lend/withdraw/3-Transfer.tsx +32 -32
- package/src/components/Lend/withdraw/4-Success.tsx +49 -49
- package/src/components/Lend/withdraw/index.tsx +101 -101
- package/src/components/LoadingModal.tsx +49 -49
- package/src/components/Notifi/NotifiSubscriptionModal.tsx +264 -0
- package/src/components/StreamFactoring/borrow/1-Evaluation.tsx +55 -55
- package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +127 -127
- package/src/components/StreamFactoring/borrow/3-ConfirmTransfer.tsx +42 -42
- package/src/components/StreamFactoring/borrow/4-ApproveAllowance.tsx +33 -33
- package/src/components/StreamFactoring/borrow/5-Permit.tsx +144 -144
- package/src/components/StreamFactoring/borrow/6-Transfer.tsx +37 -37
- package/src/components/StreamFactoring/borrow/7-Success.tsx +20 -20
- package/src/components/StreamFactoring/borrow/index.tsx +94 -94
- package/src/components/StreamFactoring/payment/ChooseAmount.tsx +54 -54
- package/src/components/StreamFactoring/payment/Success.tsx +23 -23
- package/src/components/StreamFactoring/payment/Transfer.tsx +34 -34
- package/src/components/StreamFactoring/payment/index.tsx +66 -66
- package/src/components/SuperfluidFactoring/SuperfluidFactoredList.tsx +70 -70
- package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +167 -167
- package/src/components/SuperfluidFactoring/index.tsx +85 -85
- package/src/components/TxDoneModal.tsx +85 -83
- package/src/components/TxSendModal.tsx +59 -59
- package/src/components/ViewOnExplorer.tsx +26 -26
- package/src/components/WidgetWrapper.tsx +74 -74
- package/src/components/WrapperModal.tsx +54 -54
- package/src/components/buttons/TableActionButton.tsx +36 -36
- package/src/components/buttons/index.ts +1 -1
- package/src/components/humaModal/HumaModal.tsx +68 -68
- package/src/components/humaModal/HumaModalHeader.tsx +70 -70
- package/src/components/humaModal/index.tsx +2 -2
- package/src/components/icons/approve-lender.svg +30 -30
- package/src/components/icons/auto-payback.svg +40 -40
- package/src/components/icons/check-circle.svg +3 -3
- package/src/components/icons/check-green.svg +3 -3
- package/src/components/icons/check.svg +10 -10
- package/src/components/icons/donut.svg +904 -904
- package/src/components/icons/ellipse.svg +3 -3
- package/src/components/icons/huma-full.svg +22 -22
- package/src/components/icons/huma.svg +15 -15
- package/src/components/icons/index.tsx +93 -93
- package/src/components/icons/loader.svg +229 -229
- package/src/components/icons/metamask.svg +31 -31
- package/src/components/icons/polygon.svg +16 -16
- package/src/components/icons/receipt.svg +3 -3
- package/src/components/icons/separator.svg +3 -3
- package/src/components/icons/sorry.svg +31 -31
- package/src/components/icons/usdc.svg +5 -5
- package/src/components/icons/wallet-connect.svg +11 -11
- package/src/cosmos/CreditLineBorrow.fixture.tsx +86 -86
- package/src/cosmos/CreditLinePayment.fixture.tsx +50 -50
- package/src/cosmos/InvoiceFactoringBorrow.fixture.tsx +111 -111
- package/src/cosmos/InvoiceFactoringPayment.fixture.tsx +67 -67
- package/src/cosmos/LendSupply.fixture.tsx +75 -75
- package/src/cosmos/LendWithdraw.fixture.tsx +43 -43
- package/src/cosmos/SDKTesting.fixture.tsx +616 -616
- package/src/cosmos/SuperfluidFactoringBorrow.fixture.tsx +15 -15
- package/src/cosmos/WalletWrapper.tsx +52 -52
- package/src/cosmos/abis/InvoiceNFT.json +644 -644
- package/src/cosmos/abis/ReceivableFactoringPool.json +1529 -1529
- package/src/cosmos/utils/env.ts +6 -6
- package/src/cosmos/utils/index.ts +169 -169
- package/src/fonts/Recoleta/Recoleta-Black.otf +0 -0
- package/src/fonts/Recoleta/Recoleta-Bold.otf +0 -0
- package/src/fonts/Recoleta/Recoleta-Light.otf +0 -0
- package/src/fonts/Recoleta/Recoleta-Medium.otf +0 -0
- package/src/fonts/Recoleta/Recoleta-Regular.otf +0 -0
- package/src/fonts/Recoleta/Recoleta-RegularDEMO.otf +0 -0
- package/src/fonts/Recoleta/Recoleta-SemiBold.otf +0 -0
- package/src/fonts/Recoleta/Recoleta-Thin.otf +0 -0
- package/src/hooks/useEA.ts +53 -53
- package/src/hooks/useNotifi.ts +71 -0
- package/src/hooks/useRedux.ts +6 -6
- package/src/index.css +61 -61
- package/src/index.tsx +301 -301
- package/src/react-app-env.d.ts +1 -1
- package/src/reportWebVitals.ts +15 -15
- package/src/setupTests.ts +6 -6
- package/src/store/index.ts +27 -27
- package/src/store/widgets.reducers.ts +120 -120
- package/src/store/widgets.selectors.ts +3 -3
- package/src/store/widgets.store.ts +55 -54
- package/src/theme/breakpoints.ts +10 -10
- package/src/theme/components.ts +70 -70
- package/src/theme/coreThemeConstants.ts +29 -29
- package/src/theme/cssMixins.ts +92 -92
- package/src/theme/hooks/useGetSizes.ts +31 -31
- package/src/theme/index.ts +24 -24
- package/src/theme/palette.ts +150 -150
- package/src/theme/shape.ts +7 -7
- package/src/theme/theme.types.ts +80 -80
- package/src/theme/typography.ts +117 -117
- package/src/utilTypes.d.ts +31 -31
- package/src/utils/env.ts +10 -10
- package/tsconfig.build.json +7 -7
- package/tsconfig.json +32 -32
- package/webpack.cosmos.js +54 -54
- package/src/components/Lend/supply/1-Evaluation.tsx +0 -175
- package/src/components/Lend/supply/4-ConfirmTransfer.tsx +0 -104
- package/src/components/NotifiSubscriptionModal.tsx +0 -84
|
@@ -1,322 +1,322 @@
|
|
|
1
|
-
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown'
|
|
2
|
-
import ArrowDropUpIcon from '@mui/icons-material/ArrowDropUp'
|
|
3
|
-
import {
|
|
4
|
-
Box,
|
|
5
|
-
Button,
|
|
6
|
-
css,
|
|
7
|
-
Divider,
|
|
8
|
-
Input,
|
|
9
|
-
Slider,
|
|
10
|
-
useTheme,
|
|
11
|
-
} from '@mui/material'
|
|
12
|
-
import { useMQ } from '@huma-finance/shared'
|
|
13
|
-
import React, { useState } from 'react'
|
|
14
|
-
|
|
15
|
-
import { IconType } from '../utilTypes'
|
|
16
|
-
import { WrapperModal } from './WrapperModal'
|
|
17
|
-
|
|
18
|
-
type Props = {
|
|
19
|
-
title: string
|
|
20
|
-
tokenIcon?: IconType
|
|
21
|
-
description1?: string
|
|
22
|
-
description2?: string
|
|
23
|
-
currentAmount: number
|
|
24
|
-
sliderMax: number
|
|
25
|
-
tokenSymbol: string
|
|
26
|
-
topLeft?: string
|
|
27
|
-
topRight?: string
|
|
28
|
-
downLeft?: string
|
|
29
|
-
downRight?: string
|
|
30
|
-
actionText?: string
|
|
31
|
-
hideTerms?: boolean
|
|
32
|
-
payoffAmount?: number
|
|
33
|
-
type?: 'slider' | 'input'
|
|
34
|
-
handleChangeAmount: (amount: number) => void
|
|
35
|
-
handleAction: () => void
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function ChooseAmountModal({
|
|
39
|
-
title,
|
|
40
|
-
tokenIcon,
|
|
41
|
-
description1,
|
|
42
|
-
description2,
|
|
43
|
-
currentAmount,
|
|
44
|
-
sliderMax,
|
|
45
|
-
tokenSymbol,
|
|
46
|
-
topLeft,
|
|
47
|
-
topRight,
|
|
48
|
-
downLeft,
|
|
49
|
-
downRight,
|
|
50
|
-
actionText = 'accept terms',
|
|
51
|
-
payoffAmount,
|
|
52
|
-
hideTerms = false,
|
|
53
|
-
type = 'slider',
|
|
54
|
-
handleChangeAmount,
|
|
55
|
-
handleAction,
|
|
56
|
-
}: Props): React.ReactElement {
|
|
57
|
-
const theme = useTheme()
|
|
58
|
-
const { isXsSize } = useMQ()
|
|
59
|
-
const [inputTouched, setInputTouched] = useState(false)
|
|
60
|
-
|
|
61
|
-
const styles = {
|
|
62
|
-
subTitle: css`
|
|
63
|
-
font-family: 'Uni-Neue-Regular';
|
|
64
|
-
`,
|
|
65
|
-
description2: css`
|
|
66
|
-
${theme.cssMixins.rowCentered};
|
|
67
|
-
font-family: 'Uni-Neue-Regular';
|
|
68
|
-
font-size: 16px;
|
|
69
|
-
color: #a8a1b2;
|
|
70
|
-
margin-top: 16px;
|
|
71
|
-
`,
|
|
72
|
-
chosenAmountWrapper: css`
|
|
73
|
-
${theme.cssMixins.rowCentered};
|
|
74
|
-
background: linear-gradient(232.71deg, #a363f4 4.17%, #ff6a8a 178.69%);
|
|
75
|
-
background-clip: text;
|
|
76
|
-
-webkit-text-fill-color: transparent;
|
|
77
|
-
font-weight: 700;
|
|
78
|
-
font-size: 32px;
|
|
79
|
-
margin-bottom: 10px;
|
|
80
|
-
margin-top: 30px;
|
|
81
|
-
`,
|
|
82
|
-
chosenAmount: css`
|
|
83
|
-
font-family: 'Inter-Bold';
|
|
84
|
-
font-size: 32px;
|
|
85
|
-
`,
|
|
86
|
-
chosenAmountSymbol: css`
|
|
87
|
-
font-size: 75%;
|
|
88
|
-
margin-left: 5px;
|
|
89
|
-
letter-spacing: 0.1px;
|
|
90
|
-
`,
|
|
91
|
-
inputAmountWrapper: css`
|
|
92
|
-
margin-bottom: 10px;
|
|
93
|
-
margin-top: 30px;
|
|
94
|
-
`,
|
|
95
|
-
inputAmount: css`
|
|
96
|
-
${theme.cssMixins.rowSpaceBetweened};
|
|
97
|
-
`,
|
|
98
|
-
inputField: css`
|
|
99
|
-
width: 100%;
|
|
100
|
-
`,
|
|
101
|
-
maxButton: css`
|
|
102
|
-
width: 80px;
|
|
103
|
-
`,
|
|
104
|
-
amountAvailable: css`
|
|
105
|
-
${theme.cssMixins.rowVCentered};
|
|
106
|
-
margin-top: 5px;
|
|
107
|
-
margin-bottom: 100px;
|
|
108
|
-
font-size: 16px;
|
|
109
|
-
& > svg {
|
|
110
|
-
margin-right: 5px;
|
|
111
|
-
}
|
|
112
|
-
`,
|
|
113
|
-
tokenIcon: {
|
|
114
|
-
width: '16px',
|
|
115
|
-
height: '16px',
|
|
116
|
-
},
|
|
117
|
-
editIcon: css`
|
|
118
|
-
color: ${theme.palette.primary.main};
|
|
119
|
-
cursor: pointer;
|
|
120
|
-
display: inline-grid;
|
|
121
|
-
vertical-align: middle;
|
|
122
|
-
& > svg {
|
|
123
|
-
font-size: 24px;
|
|
124
|
-
}
|
|
125
|
-
& > svg:first-of-type {
|
|
126
|
-
margin-bottom: -10px;
|
|
127
|
-
}
|
|
128
|
-
`,
|
|
129
|
-
input: css`
|
|
130
|
-
font-size: 18px;
|
|
131
|
-
-webkit-text-fill-color: ${theme.palette.primary.main};
|
|
132
|
-
`,
|
|
133
|
-
slider: css`
|
|
134
|
-
margin-bottom: 54px;
|
|
135
|
-
&.MuiSlider-root {
|
|
136
|
-
height: 8px !important;
|
|
137
|
-
color: #e9e9e9;
|
|
138
|
-
}
|
|
139
|
-
& .MuiSlider-track {
|
|
140
|
-
height: 8px !important;
|
|
141
|
-
background: linear-gradient(232.71deg, #a363f4 4.17%, #ff6a8a 178.69%);
|
|
142
|
-
border-radius: 8px;
|
|
143
|
-
}
|
|
144
|
-
& .MuiSlider-thumb::before {
|
|
145
|
-
background: #ffffff;
|
|
146
|
-
border: 1px solid #f9f9f9;
|
|
147
|
-
box-shadow: 1px 1px 12px 2px rgba(163, 100, 244, 0.6);
|
|
148
|
-
border-radius: 50px;
|
|
149
|
-
width: 24px;
|
|
150
|
-
height: 24px;
|
|
151
|
-
}
|
|
152
|
-
`,
|
|
153
|
-
info: css`
|
|
154
|
-
font-family: 'Uni-Neue-Regular';
|
|
155
|
-
${theme.cssMixins.rowSpaceBetweened};
|
|
156
|
-
font-weight: 400;
|
|
157
|
-
font-size: 16px;
|
|
158
|
-
color: #423b46;
|
|
159
|
-
`,
|
|
160
|
-
divider: css`
|
|
161
|
-
margin: 16px 0;
|
|
162
|
-
background: #49505b;
|
|
163
|
-
border-color: #e9e3f1;
|
|
164
|
-
`,
|
|
165
|
-
okButton: css`
|
|
166
|
-
font-family: 'Uni-Neue-Bold';
|
|
167
|
-
width: 100%;
|
|
168
|
-
position: absolute;
|
|
169
|
-
bottom: ${isXsSize ? 20 : 0}px;
|
|
170
|
-
`,
|
|
171
|
-
terms: css`
|
|
172
|
-
${theme.cssMixins.rowHCentered};
|
|
173
|
-
font-weight: 400;
|
|
174
|
-
font-size: 12px;
|
|
175
|
-
color: #a8a1b2;
|
|
176
|
-
margin-top: 8px;
|
|
177
|
-
letter-spacing: 0px;
|
|
178
|
-
width: 100%;
|
|
179
|
-
position: absolute;
|
|
180
|
-
bottom: -22px;
|
|
181
|
-
`,
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const handleSliderChange = (event: Event, newValue: number | number[]) => {
|
|
185
|
-
handleChangeAmount(newValue as number)
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const handleInputChange = (
|
|
189
|
-
event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>,
|
|
190
|
-
) => {
|
|
191
|
-
setInputTouched(true)
|
|
192
|
-
// @ts-ignore
|
|
193
|
-
handleChangeAmount(event.target.value)
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const handleSetMax = () => {
|
|
197
|
-
handleChangeAmount(sliderMax)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const handleIncrement = () => {
|
|
201
|
-
const newAmount = currentAmount + 1
|
|
202
|
-
if (newAmount <= sliderMax) {
|
|
203
|
-
handleChangeAmount(newAmount)
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const handleDecrement = () => {
|
|
208
|
-
const newAmount = currentAmount - 1
|
|
209
|
-
if (newAmount >= 0) {
|
|
210
|
-
handleChangeAmount(newAmount)
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const handlePayoff = () => {
|
|
215
|
-
if (payoffAmount) {
|
|
216
|
-
handleChangeAmount(payoffAmount)
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
const subTitle = (
|
|
221
|
-
<Box component='span'>
|
|
222
|
-
<Box component='span' css={styles.subTitle}>
|
|
223
|
-
{description1}
|
|
224
|
-
</Box>
|
|
225
|
-
{payoffAmount && (
|
|
226
|
-
<Button
|
|
227
|
-
sx={{ fontSize: '12px' }}
|
|
228
|
-
variant='text'
|
|
229
|
-
size='small'
|
|
230
|
-
onClick={handlePayoff}
|
|
231
|
-
className='choose-amount-modal-select-payoff-btn'
|
|
232
|
-
>
|
|
233
|
-
Pay Off
|
|
234
|
-
</Button>
|
|
235
|
-
)}
|
|
236
|
-
</Box>
|
|
237
|
-
)
|
|
238
|
-
|
|
239
|
-
return (
|
|
240
|
-
<WrapperModal title={title} subTitle={subTitle}>
|
|
241
|
-
{type === 'slider' && (
|
|
242
|
-
<>
|
|
243
|
-
<Box css={styles.chosenAmountWrapper}>
|
|
244
|
-
<Box css={styles.chosenAmount}>
|
|
245
|
-
{Number(currentAmount).toFixed(2)}
|
|
246
|
-
<Box component='span' css={styles.chosenAmountSymbol}>
|
|
247
|
-
{tokenSymbol}
|
|
248
|
-
</Box>
|
|
249
|
-
<Box component='span' css={styles.editIcon}>
|
|
250
|
-
<ArrowDropUpIcon
|
|
251
|
-
onClick={handleIncrement}
|
|
252
|
-
className='choose-amount-modal-increment-icon'
|
|
253
|
-
/>
|
|
254
|
-
<ArrowDropDownIcon onClick={handleDecrement} />
|
|
255
|
-
</Box>
|
|
256
|
-
</Box>
|
|
257
|
-
</Box>
|
|
258
|
-
<Slider
|
|
259
|
-
max={Number(sliderMax)}
|
|
260
|
-
min={0}
|
|
261
|
-
css={styles.slider}
|
|
262
|
-
aria-label='Amount'
|
|
263
|
-
value={currentAmount}
|
|
264
|
-
onChange={handleSliderChange}
|
|
265
|
-
/>
|
|
266
|
-
</>
|
|
267
|
-
)}
|
|
268
|
-
{type === 'input' && (
|
|
269
|
-
<Box css={styles.inputAmountWrapper}>
|
|
270
|
-
<Box css={styles.inputAmount}>
|
|
271
|
-
<Input
|
|
272
|
-
css={styles.inputField}
|
|
273
|
-
type='number'
|
|
274
|
-
value={!inputTouched && currentAmount === 0 ? '' : currentAmount}
|
|
275
|
-
onChange={handleInputChange}
|
|
276
|
-
placeholder='0'
|
|
277
|
-
/>
|
|
278
|
-
<Button
|
|
279
|
-
variant='contained'
|
|
280
|
-
css={styles.maxButton}
|
|
281
|
-
onClick={handleSetMax}
|
|
282
|
-
>
|
|
283
|
-
Max
|
|
284
|
-
</Button>
|
|
285
|
-
</Box>
|
|
286
|
-
<Box css={styles.amountAvailable}>
|
|
287
|
-
{tokenIcon && React.createElement(tokenIcon, styles.tokenIcon)}
|
|
288
|
-
<Box>{Number(sliderMax).toFixed(2)} Available</Box>
|
|
289
|
-
</Box>
|
|
290
|
-
</Box>
|
|
291
|
-
)}
|
|
292
|
-
<Box css={styles.info}>
|
|
293
|
-
<Box>{topLeft}</Box>
|
|
294
|
-
<Box>{topRight}</Box>
|
|
295
|
-
</Box>
|
|
296
|
-
{topLeft && downLeft && <Divider css={styles.divider} />}
|
|
297
|
-
<Box css={styles.info}>
|
|
298
|
-
<Box>{downLeft}</Box>
|
|
299
|
-
<Box>{downRight}</Box>
|
|
300
|
-
</Box>
|
|
301
|
-
<Box css={styles.description2}>{description2}</Box>
|
|
302
|
-
<Button
|
|
303
|
-
className='choose-amount-modal-action-btn'
|
|
304
|
-
variant='contained'
|
|
305
|
-
css={styles.okButton}
|
|
306
|
-
onClick={handleAction}
|
|
307
|
-
disabled={
|
|
308
|
-
!currentAmount ||
|
|
309
|
-
Number(currentAmount) <= 0 ||
|
|
310
|
-
Number(currentAmount) > Number(sliderMax)
|
|
311
|
-
}
|
|
312
|
-
>
|
|
313
|
-
{actionText.toUpperCase()}
|
|
314
|
-
</Button>
|
|
315
|
-
{!hideTerms && (
|
|
316
|
-
<Box css={styles.terms}>
|
|
317
|
-
By clicking {actionText}, you agree to Huma’s Terms of Service.
|
|
318
|
-
</Box>
|
|
319
|
-
)}
|
|
320
|
-
</WrapperModal>
|
|
321
|
-
)
|
|
322
|
-
}
|
|
1
|
+
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown'
|
|
2
|
+
import ArrowDropUpIcon from '@mui/icons-material/ArrowDropUp'
|
|
3
|
+
import {
|
|
4
|
+
Box,
|
|
5
|
+
Button,
|
|
6
|
+
css,
|
|
7
|
+
Divider,
|
|
8
|
+
Input,
|
|
9
|
+
Slider,
|
|
10
|
+
useTheme,
|
|
11
|
+
} from '@mui/material'
|
|
12
|
+
import { useMQ } from '@huma-finance/shared'
|
|
13
|
+
import React, { useState } from 'react'
|
|
14
|
+
|
|
15
|
+
import { IconType } from '../utilTypes'
|
|
16
|
+
import { WrapperModal } from './WrapperModal'
|
|
17
|
+
|
|
18
|
+
type Props = {
|
|
19
|
+
title: string
|
|
20
|
+
tokenIcon?: IconType
|
|
21
|
+
description1?: string
|
|
22
|
+
description2?: string
|
|
23
|
+
currentAmount: number
|
|
24
|
+
sliderMax: number
|
|
25
|
+
tokenSymbol: string
|
|
26
|
+
topLeft?: string
|
|
27
|
+
topRight?: string
|
|
28
|
+
downLeft?: string
|
|
29
|
+
downRight?: string
|
|
30
|
+
actionText?: string
|
|
31
|
+
hideTerms?: boolean
|
|
32
|
+
payoffAmount?: number
|
|
33
|
+
type?: 'slider' | 'input'
|
|
34
|
+
handleChangeAmount: (amount: number) => void
|
|
35
|
+
handleAction: () => void
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function ChooseAmountModal({
|
|
39
|
+
title,
|
|
40
|
+
tokenIcon,
|
|
41
|
+
description1,
|
|
42
|
+
description2,
|
|
43
|
+
currentAmount,
|
|
44
|
+
sliderMax,
|
|
45
|
+
tokenSymbol,
|
|
46
|
+
topLeft,
|
|
47
|
+
topRight,
|
|
48
|
+
downLeft,
|
|
49
|
+
downRight,
|
|
50
|
+
actionText = 'accept terms',
|
|
51
|
+
payoffAmount,
|
|
52
|
+
hideTerms = false,
|
|
53
|
+
type = 'slider',
|
|
54
|
+
handleChangeAmount,
|
|
55
|
+
handleAction,
|
|
56
|
+
}: Props): React.ReactElement {
|
|
57
|
+
const theme = useTheme()
|
|
58
|
+
const { isXsSize } = useMQ()
|
|
59
|
+
const [inputTouched, setInputTouched] = useState(false)
|
|
60
|
+
|
|
61
|
+
const styles = {
|
|
62
|
+
subTitle: css`
|
|
63
|
+
font-family: 'Uni-Neue-Regular';
|
|
64
|
+
`,
|
|
65
|
+
description2: css`
|
|
66
|
+
${theme.cssMixins.rowCentered};
|
|
67
|
+
font-family: 'Uni-Neue-Regular';
|
|
68
|
+
font-size: 16px;
|
|
69
|
+
color: #a8a1b2;
|
|
70
|
+
margin-top: 16px;
|
|
71
|
+
`,
|
|
72
|
+
chosenAmountWrapper: css`
|
|
73
|
+
${theme.cssMixins.rowCentered};
|
|
74
|
+
background: linear-gradient(232.71deg, #a363f4 4.17%, #ff6a8a 178.69%);
|
|
75
|
+
background-clip: text;
|
|
76
|
+
-webkit-text-fill-color: transparent;
|
|
77
|
+
font-weight: 700;
|
|
78
|
+
font-size: 32px;
|
|
79
|
+
margin-bottom: 10px;
|
|
80
|
+
margin-top: 30px;
|
|
81
|
+
`,
|
|
82
|
+
chosenAmount: css`
|
|
83
|
+
font-family: 'Inter-Bold';
|
|
84
|
+
font-size: 32px;
|
|
85
|
+
`,
|
|
86
|
+
chosenAmountSymbol: css`
|
|
87
|
+
font-size: 75%;
|
|
88
|
+
margin-left: 5px;
|
|
89
|
+
letter-spacing: 0.1px;
|
|
90
|
+
`,
|
|
91
|
+
inputAmountWrapper: css`
|
|
92
|
+
margin-bottom: 10px;
|
|
93
|
+
margin-top: 30px;
|
|
94
|
+
`,
|
|
95
|
+
inputAmount: css`
|
|
96
|
+
${theme.cssMixins.rowSpaceBetweened};
|
|
97
|
+
`,
|
|
98
|
+
inputField: css`
|
|
99
|
+
width: 100%;
|
|
100
|
+
`,
|
|
101
|
+
maxButton: css`
|
|
102
|
+
width: 80px;
|
|
103
|
+
`,
|
|
104
|
+
amountAvailable: css`
|
|
105
|
+
${theme.cssMixins.rowVCentered};
|
|
106
|
+
margin-top: 5px;
|
|
107
|
+
margin-bottom: 100px;
|
|
108
|
+
font-size: 16px;
|
|
109
|
+
& > svg {
|
|
110
|
+
margin-right: 5px;
|
|
111
|
+
}
|
|
112
|
+
`,
|
|
113
|
+
tokenIcon: {
|
|
114
|
+
width: '16px',
|
|
115
|
+
height: '16px',
|
|
116
|
+
},
|
|
117
|
+
editIcon: css`
|
|
118
|
+
color: ${theme.palette.primary.main};
|
|
119
|
+
cursor: pointer;
|
|
120
|
+
display: inline-grid;
|
|
121
|
+
vertical-align: middle;
|
|
122
|
+
& > svg {
|
|
123
|
+
font-size: 24px;
|
|
124
|
+
}
|
|
125
|
+
& > svg:first-of-type {
|
|
126
|
+
margin-bottom: -10px;
|
|
127
|
+
}
|
|
128
|
+
`,
|
|
129
|
+
input: css`
|
|
130
|
+
font-size: 18px;
|
|
131
|
+
-webkit-text-fill-color: ${theme.palette.primary.main};
|
|
132
|
+
`,
|
|
133
|
+
slider: css`
|
|
134
|
+
margin-bottom: 54px;
|
|
135
|
+
&.MuiSlider-root {
|
|
136
|
+
height: 8px !important;
|
|
137
|
+
color: #e9e9e9;
|
|
138
|
+
}
|
|
139
|
+
& .MuiSlider-track {
|
|
140
|
+
height: 8px !important;
|
|
141
|
+
background: linear-gradient(232.71deg, #a363f4 4.17%, #ff6a8a 178.69%);
|
|
142
|
+
border-radius: 8px;
|
|
143
|
+
}
|
|
144
|
+
& .MuiSlider-thumb::before {
|
|
145
|
+
background: #ffffff;
|
|
146
|
+
border: 1px solid #f9f9f9;
|
|
147
|
+
box-shadow: 1px 1px 12px 2px rgba(163, 100, 244, 0.6);
|
|
148
|
+
border-radius: 50px;
|
|
149
|
+
width: 24px;
|
|
150
|
+
height: 24px;
|
|
151
|
+
}
|
|
152
|
+
`,
|
|
153
|
+
info: css`
|
|
154
|
+
font-family: 'Uni-Neue-Regular';
|
|
155
|
+
${theme.cssMixins.rowSpaceBetweened};
|
|
156
|
+
font-weight: 400;
|
|
157
|
+
font-size: 16px;
|
|
158
|
+
color: #423b46;
|
|
159
|
+
`,
|
|
160
|
+
divider: css`
|
|
161
|
+
margin: 16px 0;
|
|
162
|
+
background: #49505b;
|
|
163
|
+
border-color: #e9e3f1;
|
|
164
|
+
`,
|
|
165
|
+
okButton: css`
|
|
166
|
+
font-family: 'Uni-Neue-Bold';
|
|
167
|
+
width: 100%;
|
|
168
|
+
position: absolute;
|
|
169
|
+
bottom: ${isXsSize ? 20 : 0}px;
|
|
170
|
+
`,
|
|
171
|
+
terms: css`
|
|
172
|
+
${theme.cssMixins.rowHCentered};
|
|
173
|
+
font-weight: 400;
|
|
174
|
+
font-size: 12px;
|
|
175
|
+
color: #a8a1b2;
|
|
176
|
+
margin-top: 8px;
|
|
177
|
+
letter-spacing: 0px;
|
|
178
|
+
width: 100%;
|
|
179
|
+
position: absolute;
|
|
180
|
+
bottom: -22px;
|
|
181
|
+
`,
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const handleSliderChange = (event: Event, newValue: number | number[]) => {
|
|
185
|
+
handleChangeAmount(newValue as number)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const handleInputChange = (
|
|
189
|
+
event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>,
|
|
190
|
+
) => {
|
|
191
|
+
setInputTouched(true)
|
|
192
|
+
// @ts-ignore
|
|
193
|
+
handleChangeAmount(event.target.value)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const handleSetMax = () => {
|
|
197
|
+
handleChangeAmount(sliderMax)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const handleIncrement = () => {
|
|
201
|
+
const newAmount = currentAmount + 1
|
|
202
|
+
if (newAmount <= sliderMax) {
|
|
203
|
+
handleChangeAmount(newAmount)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const handleDecrement = () => {
|
|
208
|
+
const newAmount = currentAmount - 1
|
|
209
|
+
if (newAmount >= 0) {
|
|
210
|
+
handleChangeAmount(newAmount)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const handlePayoff = () => {
|
|
215
|
+
if (payoffAmount) {
|
|
216
|
+
handleChangeAmount(payoffAmount)
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const subTitle = (
|
|
221
|
+
<Box component='span'>
|
|
222
|
+
<Box component='span' css={styles.subTitle}>
|
|
223
|
+
{description1}
|
|
224
|
+
</Box>
|
|
225
|
+
{payoffAmount && (
|
|
226
|
+
<Button
|
|
227
|
+
sx={{ fontSize: '12px' }}
|
|
228
|
+
variant='text'
|
|
229
|
+
size='small'
|
|
230
|
+
onClick={handlePayoff}
|
|
231
|
+
className='choose-amount-modal-select-payoff-btn'
|
|
232
|
+
>
|
|
233
|
+
Pay Off
|
|
234
|
+
</Button>
|
|
235
|
+
)}
|
|
236
|
+
</Box>
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
return (
|
|
240
|
+
<WrapperModal title={title} subTitle={subTitle}>
|
|
241
|
+
{type === 'slider' && (
|
|
242
|
+
<>
|
|
243
|
+
<Box css={styles.chosenAmountWrapper}>
|
|
244
|
+
<Box css={styles.chosenAmount}>
|
|
245
|
+
{Number(currentAmount).toFixed(2)}
|
|
246
|
+
<Box component='span' css={styles.chosenAmountSymbol}>
|
|
247
|
+
{tokenSymbol}
|
|
248
|
+
</Box>
|
|
249
|
+
<Box component='span' css={styles.editIcon}>
|
|
250
|
+
<ArrowDropUpIcon
|
|
251
|
+
onClick={handleIncrement}
|
|
252
|
+
className='choose-amount-modal-increment-icon'
|
|
253
|
+
/>
|
|
254
|
+
<ArrowDropDownIcon onClick={handleDecrement} />
|
|
255
|
+
</Box>
|
|
256
|
+
</Box>
|
|
257
|
+
</Box>
|
|
258
|
+
<Slider
|
|
259
|
+
max={Number(sliderMax)}
|
|
260
|
+
min={0}
|
|
261
|
+
css={styles.slider}
|
|
262
|
+
aria-label='Amount'
|
|
263
|
+
value={currentAmount}
|
|
264
|
+
onChange={handleSliderChange}
|
|
265
|
+
/>
|
|
266
|
+
</>
|
|
267
|
+
)}
|
|
268
|
+
{type === 'input' && (
|
|
269
|
+
<Box css={styles.inputAmountWrapper}>
|
|
270
|
+
<Box css={styles.inputAmount}>
|
|
271
|
+
<Input
|
|
272
|
+
css={styles.inputField}
|
|
273
|
+
type='number'
|
|
274
|
+
value={!inputTouched && currentAmount === 0 ? '' : currentAmount}
|
|
275
|
+
onChange={handleInputChange}
|
|
276
|
+
placeholder='0'
|
|
277
|
+
/>
|
|
278
|
+
<Button
|
|
279
|
+
variant='contained'
|
|
280
|
+
css={styles.maxButton}
|
|
281
|
+
onClick={handleSetMax}
|
|
282
|
+
>
|
|
283
|
+
Max
|
|
284
|
+
</Button>
|
|
285
|
+
</Box>
|
|
286
|
+
<Box css={styles.amountAvailable}>
|
|
287
|
+
{tokenIcon && React.createElement(tokenIcon, styles.tokenIcon)}
|
|
288
|
+
<Box>{Number(sliderMax).toFixed(2)} Available</Box>
|
|
289
|
+
</Box>
|
|
290
|
+
</Box>
|
|
291
|
+
)}
|
|
292
|
+
<Box css={styles.info}>
|
|
293
|
+
<Box>{topLeft}</Box>
|
|
294
|
+
<Box>{topRight}</Box>
|
|
295
|
+
</Box>
|
|
296
|
+
{topLeft && downLeft && <Divider css={styles.divider} />}
|
|
297
|
+
<Box css={styles.info}>
|
|
298
|
+
<Box>{downLeft}</Box>
|
|
299
|
+
<Box>{downRight}</Box>
|
|
300
|
+
</Box>
|
|
301
|
+
<Box css={styles.description2}>{description2}</Box>
|
|
302
|
+
<Button
|
|
303
|
+
className='choose-amount-modal-action-btn'
|
|
304
|
+
variant='contained'
|
|
305
|
+
css={styles.okButton}
|
|
306
|
+
onClick={handleAction}
|
|
307
|
+
disabled={
|
|
308
|
+
!currentAmount ||
|
|
309
|
+
Number(currentAmount) <= 0 ||
|
|
310
|
+
Number(currentAmount) > Number(sliderMax)
|
|
311
|
+
}
|
|
312
|
+
>
|
|
313
|
+
{actionText.toUpperCase()}
|
|
314
|
+
</Button>
|
|
315
|
+
{!hideTerms && (
|
|
316
|
+
<Box css={styles.terms}>
|
|
317
|
+
By clicking {actionText}, you agree to Huma’s Terms of Service.
|
|
318
|
+
</Box>
|
|
319
|
+
)}
|
|
320
|
+
</WrapperModal>
|
|
321
|
+
)
|
|
322
|
+
}
|