@huma-finance/widgets 0.0.11 → 0.0.13

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 (46) hide show
  1. package/API.md +6 -5
  2. package/dist/cjs/index.cjs +5058 -5959
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/index.d.ts +9 -6
  5. package/dist/index.js +5059 -5960
  6. package/dist/index.js.map +1 -1
  7. package/package.json +16 -16
  8. package/src/components/ApproveAllowanceModal.tsx +5 -2
  9. package/src/components/ChainNotSupportedModal.tsx +31 -0
  10. package/src/components/ChooseAmountModal.tsx +322 -315
  11. package/src/components/ConfirmTransferModal.tsx +153 -0
  12. package/src/components/CreditLine/borrow/1-Evaluation.tsx +1 -2
  13. package/src/components/CreditLine/borrow/{3-ChooseAmount.tsx → 2-ChooseAmount.tsx} +2 -8
  14. package/src/components/CreditLine/borrow/{5-Transfer.tsx → 3-Transfer.tsx} +17 -3
  15. package/src/components/CreditLine/borrow/4-ApproveAllowance.tsx +1 -1
  16. package/src/components/CreditLine/borrow/index.tsx +3 -5
  17. package/src/components/Factoring/FactoredList.tsx +1 -1
  18. package/src/components/InvoiceFactoring/borrow/1-Evaluation.tsx +1 -4
  19. package/src/components/InvoiceFactoring/borrow/{3-ChooseAmount.tsx → 2-ChooseAmount.tsx} +5 -3
  20. package/src/components/InvoiceFactoring/borrow/3-ConfirmTransfer.tsx +37 -0
  21. package/src/components/InvoiceFactoring/borrow/index.tsx +5 -7
  22. package/src/components/StreamFactoring/borrow/1-Evaluation.tsx +11 -3
  23. package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +4 -1
  24. package/src/components/StreamFactoring/borrow/3-ConfirmTransfer.tsx +18 -80
  25. package/src/components/StreamFactoring/borrow/4-ApproveAllowance.tsx +4 -36
  26. package/src/components/StreamFactoring/borrow/5-Permit.tsx +14 -14
  27. package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +1 -1
  28. package/src/cosmos/CreditLineBorrow.fixture.tsx +1 -0
  29. package/src/cosmos/CreditLinePayment.fixture.tsx +1 -0
  30. package/src/cosmos/SDKTesting.fixture.tsx +615 -557
  31. package/src/cosmos/SuperfluidFactoringBorrow.fixture.tsx +3 -0
  32. package/src/cosmos/utils/env.ts +6 -0
  33. package/src/hooks/useEA.ts +10 -29
  34. package/src/index.tsx +75 -7
  35. package/src/reportWebVitals.ts +9 -9
  36. package/src/store/widgets.store.ts +0 -1
  37. package/src/utilTypes.d.ts +2 -0
  38. package/webpack.cosmos.js +9 -9
  39. package/src/components/AllowListModal.tsx +0 -113
  40. package/src/components/CreditLine/borrow/2-AllowList.tsx +0 -34
  41. package/src/components/InvoiceFactoring/borrow/2-AllowList.tsx +0 -34
  42. package/src/components/InvoiceFactoring/borrow/4-ConfirmTransfer.tsx +0 -104
  43. /package/src/components/CreditLine/borrow/{6-Success.tsx → 5-Success.tsx} +0 -0
  44. /package/src/components/InvoiceFactoring/borrow/{5-ApproveNFT.tsx → 4-ApproveNFT.tsx} +0 -0
  45. /package/src/components/InvoiceFactoring/borrow/{6-Transfer.tsx → 5-Transfer.tsx} +0 -0
  46. /package/src/components/InvoiceFactoring/borrow/{7-Success.tsx → 6-Success.tsx} +0 -0
@@ -1,315 +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 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
-
60
- const styles = {
61
- subTitle: css`
62
- font-family: 'Uni-Neue-Regular';
63
- `,
64
- description2: css`
65
- ${theme.cssMixins.rowCentered};
66
- font-family: 'Uni-Neue-Regular';
67
- font-size: 16px;
68
- color: #a8a1b2;
69
- margin-top: 16px;
70
- `,
71
- chosenAmountWrapper: css`
72
- ${theme.cssMixins.rowCentered};
73
- background: linear-gradient(232.71deg, #a363f4 4.17%, #ff6a8a 178.69%);
74
- background-clip: text;
75
- -webkit-text-fill-color: transparent;
76
- font-weight: 700;
77
- font-size: 32px;
78
- margin-bottom: 10px;
79
- margin-top: 30px;
80
- `,
81
- chosenAmount: css`
82
- font-family: 'Inter-Bold';
83
- font-size: 32px;
84
- `,
85
- chosenAmountSymbol: css`
86
- font-size: 75%;
87
- margin-left: 5px;
88
- letter-spacing: 0.1px;
89
- `,
90
- inputAmountWrapper: css`
91
- margin-bottom: 10px;
92
- margin-top: 30px;
93
- `,
94
- inputAmount: css`
95
- ${theme.cssMixins.rowSpaceBetweened};
96
- `,
97
- inputField: css`
98
- width: 100%;
99
- `,
100
- maxButton: css`
101
- width: 80px;
102
- `,
103
- amountAvailable: css`
104
- ${theme.cssMixins.rowVCentered};
105
- margin-top: 5px;
106
- margin-bottom: 100px;
107
- font-size: 16px;
108
- & > svg {
109
- margin-right: 5px;
110
- }
111
- `,
112
- tokenIcon: {
113
- width: '16px',
114
- height: '16px',
115
- },
116
- editIcon: css`
117
- color: ${theme.palette.primary.main};
118
- cursor: pointer;
119
- display: inline-grid;
120
- vertical-align: middle;
121
- & > svg {
122
- font-size: 24px;
123
- }
124
- & > svg:first-of-type {
125
- margin-bottom: -10px;
126
- }
127
- `,
128
- input: css`
129
- font-size: 18px;
130
- -webkit-text-fill-color: ${theme.palette.primary.main};
131
- `,
132
- slider: css`
133
- margin-bottom: 54px;
134
- &.MuiSlider-root {
135
- height: 8px !important;
136
- color: #e9e9e9;
137
- }
138
- & .MuiSlider-track {
139
- height: 8px !important;
140
- background: linear-gradient(232.71deg, #a363f4 4.17%, #ff6a8a 178.69%);
141
- border-radius: 8px;
142
- }
143
- & .MuiSlider-thumb::before {
144
- background: #ffffff;
145
- border: 1px solid #f9f9f9;
146
- box-shadow: 1px 1px 12px 2px rgba(163, 100, 244, 0.6);
147
- border-radius: 50px;
148
- width: 24px;
149
- height: 24px;
150
- }
151
- `,
152
- info: css`
153
- font-family: 'Uni-Neue-Regular';
154
- ${theme.cssMixins.rowSpaceBetweened};
155
- font-weight: 400;
156
- font-size: 16px;
157
- color: #423b46;
158
- `,
159
- divider: css`
160
- margin: 16px 0;
161
- background: #49505b;
162
- border-color: #e9e3f1;
163
- `,
164
- okButton: css`
165
- font-family: 'Uni-Neue-Bold';
166
- width: 100%;
167
- position: absolute;
168
- bottom: ${isXsSize ? 20 : 0}px;
169
- `,
170
- terms: css`
171
- ${theme.cssMixins.rowHCentered};
172
- font-weight: 400;
173
- font-size: 12px;
174
- color: #a8a1b2;
175
- margin-top: 8px;
176
- letter-spacing: 0px;
177
- width: 100%;
178
- position: absolute;
179
- bottom: -22px;
180
- `,
181
- }
182
-
183
- const handleSliderChange = (event: Event, newValue: number | number[]) => {
184
- handleChangeAmount(newValue as number)
185
- }
186
-
187
- const handleInputChange = (
188
- event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>,
189
- ) => {
190
- // @ts-ignore
191
- handleChangeAmount(event.target.value)
192
- }
193
-
194
- const handleSetMax = () => {
195
- handleChangeAmount(sliderMax)
196
- }
197
-
198
- const handleIncrement = () => {
199
- const newAmount = currentAmount + 1
200
- if (newAmount <= sliderMax) {
201
- handleChangeAmount(newAmount)
202
- }
203
- }
204
-
205
- const handleDecrement = () => {
206
- const newAmount = currentAmount - 1
207
- if (newAmount >= 0) {
208
- handleChangeAmount(newAmount)
209
- }
210
- }
211
-
212
- const handlePayoff = () => {
213
- if (payoffAmount) {
214
- handleChangeAmount(payoffAmount)
215
- }
216
- }
217
-
218
- const subTitle = (
219
- <Box component='span'>
220
- <Box component='span' css={styles.subTitle}>
221
- {description1}
222
- </Box>
223
- {payoffAmount && (
224
- <Button
225
- sx={{ fontSize: '12px' }}
226
- variant='text'
227
- size='small'
228
- onClick={handlePayoff}
229
- className='choose-amount-modal-select-payoff-btn'
230
- >
231
- Pay Off
232
- </Button>
233
- )}
234
- </Box>
235
- )
236
-
237
- return (
238
- <WrapperModal title={title} subTitle={subTitle}>
239
- {type === 'slider' && (
240
- <>
241
- <Box css={styles.chosenAmountWrapper}>
242
- <Box css={styles.chosenAmount}>
243
- {Number(currentAmount).toFixed(2)}
244
- <Box component='span' css={styles.chosenAmountSymbol}>
245
- {tokenSymbol}
246
- </Box>
247
- <Box component='span' css={styles.editIcon}>
248
- <ArrowDropUpIcon
249
- onClick={handleIncrement}
250
- className='choose-amount-modal-increment-icon'
251
- />
252
- <ArrowDropDownIcon onClick={handleDecrement} />
253
- </Box>
254
- </Box>
255
- </Box>
256
- <Slider
257
- max={sliderMax}
258
- min={0}
259
- css={styles.slider}
260
- aria-label='Amount'
261
- value={currentAmount}
262
- onChange={handleSliderChange}
263
- />
264
- </>
265
- )}
266
- {type === 'input' && (
267
- <Box css={styles.inputAmountWrapper}>
268
- <Box css={styles.inputAmount}>
269
- <Input
270
- css={styles.inputField}
271
- type='number'
272
- value={currentAmount}
273
- onChange={handleInputChange}
274
- />
275
- <Button
276
- variant='contained'
277
- css={styles.maxButton}
278
- onClick={handleSetMax}
279
- >
280
- Max
281
- </Button>
282
- </Box>
283
- <Box css={styles.amountAvailable}>
284
- {tokenIcon && React.createElement(tokenIcon, styles.tokenIcon)}
285
- <Box>{Number(sliderMax).toFixed(2)} Available</Box>
286
- </Box>
287
- </Box>
288
- )}
289
- <Box css={styles.info}>
290
- <Box>{topLeft}</Box>
291
- <Box>{topRight}</Box>
292
- </Box>
293
- {topLeft && downLeft && <Divider css={styles.divider} />}
294
- <Box css={styles.info}>
295
- <Box>{downLeft}</Box>
296
- <Box>{downRight}</Box>
297
- </Box>
298
- <Box css={styles.description2}>{description2}</Box>
299
- <Button
300
- className='choose-amount-modal-action-btn'
301
- variant='contained'
302
- css={styles.okButton}
303
- onClick={handleAction}
304
- disabled={currentAmount === 0 || currentAmount > sliderMax}
305
- >
306
- {actionText.toUpperCase()}
307
- </Button>
308
- {!hideTerms && (
309
- <Box css={styles.terms}>
310
- By clicking {actionText}, you agree to Huma’s Terms of Service.
311
- </Box>
312
- )}
313
- </WrapperModal>
314
- )
315
- }
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
+ }