@huma-finance/widgets 0.0.12 → 0.0.15

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 (47) hide show
  1. package/API.md +6 -5
  2. package/dist/cjs/index.cjs +5058 -5968
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/index.d.ts +9 -6
  5. package/dist/index.js +5059 -5969
  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 +33 -0
  10. package/src/components/ChooseAmountModal.tsx +322 -322
  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/index.tsx +4 -6
  14. package/src/components/Factoring/FactoredList.tsx +1 -1
  15. package/src/components/InvoiceFactoring/borrow/1-Evaluation.tsx +1 -4
  16. package/src/components/InvoiceFactoring/borrow/{3-ChooseAmount.tsx → 2-ChooseAmount.tsx} +5 -3
  17. package/src/components/InvoiceFactoring/borrow/3-ConfirmTransfer.tsx +37 -0
  18. package/src/components/InvoiceFactoring/borrow/index.tsx +5 -7
  19. package/src/components/StreamFactoring/borrow/1-Evaluation.tsx +12 -4
  20. package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +4 -1
  21. package/src/components/StreamFactoring/borrow/3-ConfirmTransfer.tsx +18 -80
  22. package/src/components/StreamFactoring/borrow/4-ApproveAllowance.tsx +4 -36
  23. package/src/components/StreamFactoring/borrow/5-Permit.tsx +14 -14
  24. package/src/components/SuperfluidFactoring/SuperfluidFactoredList.tsx +10 -1
  25. package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +4 -22
  26. package/src/cosmos/CreditLineBorrow.fixture.tsx +1 -0
  27. package/src/cosmos/CreditLinePayment.fixture.tsx +1 -0
  28. package/src/cosmos/SDKTesting.fixture.tsx +615 -615
  29. package/src/cosmos/SuperfluidFactoringBorrow.fixture.tsx +3 -0
  30. package/src/cosmos/utils/env.ts +6 -0
  31. package/src/hooks/useEA.ts +10 -29
  32. package/src/index.tsx +88 -7
  33. package/src/reportWebVitals.ts +9 -9
  34. package/src/store/widgets.store.ts +0 -1
  35. package/src/utilTypes.d.ts +2 -0
  36. package/webpack.cosmos.js +9 -9
  37. package/src/components/AllowListModal.tsx +0 -113
  38. package/src/components/CreditLine/borrow/2-AllowList.tsx +0 -34
  39. package/src/components/InvoiceFactoring/borrow/2-AllowList.tsx +0 -34
  40. package/src/components/InvoiceFactoring/borrow/4-ConfirmTransfer.tsx +0 -104
  41. /package/src/components/CreditLine/borrow/{3-ChooseAmount.tsx → 2-ChooseAmount.tsx} +0 -0
  42. /package/src/components/CreditLine/borrow/{4-Transfer.tsx → 3-Transfer.tsx} +0 -0
  43. /package/src/components/CreditLine/borrow/{5-ApproveAllowance.tsx → 4-ApproveAllowance.tsx} +0 -0
  44. /package/src/components/CreditLine/borrow/{6-Success.tsx → 5-Success.tsx} +0 -0
  45. /package/src/components/InvoiceFactoring/borrow/{5-ApproveNFT.tsx → 4-ApproveNFT.tsx} +0 -0
  46. /package/src/components/InvoiceFactoring/borrow/{6-Transfer.tsx → 5-Transfer.tsx} +0 -0
  47. /package/src/components/InvoiceFactoring/borrow/{7-Success.tsx → 6-Success.tsx} +0 -0
@@ -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
+ }