@@ -3,7 +3,7 @@ import React, { useCallback, useEffect, useState } from 'react';
3
3
4
4
// REDUX IMPORTS
5
5
import { useDispatch , useSelector } from 'react-redux' ;
6
- import { storeAddress , toggleRainbow } from '@redux/address' ;
6
+ import { storeAddress } from '@redux/address' ;
7
7
8
8
// LENS IMPORTS
9
9
import { Profile } from '@lens-protocol/api-bindings' ;
@@ -17,7 +17,6 @@ import Stack from '@mui/material/Stack';
17
17
import Button from '@mui/material/Button' ;
18
18
import Slider from '@mui/material/Slider' ;
19
19
import Tooltip from '@mui/material/Tooltip' ;
20
- import TextField from '@mui/material/TextField' ;
21
20
import Box from '@mui/material/Box' ;
22
21
import CardHeader from '@mui/material/CardHeader' ;
23
22
import { CardProps } from '@mui/material/Card' ;
@@ -30,13 +29,17 @@ import { InputAmount } from '@src/components/input-amount.tsx';
30
29
import FinanceQuickTransferModal from '@src/sections/finance/components/finance-quick-transfer-modal.tsx' ;
31
30
import FinanceSearchProfileModal from '@src/sections/finance/components/finance-search-profile-modal.tsx' ;
32
31
import AvatarProfile from "@src/components/avatar/avatar.tsx" ;
32
+ import FinanceNoFollowingsQuickTransfer
33
+ from "@src/sections/finance/components/finance-no-followings-quick-transfer" ;
34
+ import FinanceDisplayProfileInfo from "@src/sections/finance/components/finance-display-profile-info" ;
35
+ import { handleAmountConstraints } from "@src/utils/format-number.ts" ;
33
36
34
37
// ----------------------------------------------------------------------
35
38
36
39
const STEP = 50 ;
37
40
const MIN_AMOUNT = 0 ;
38
41
// A thousand millions allowed in the pool
39
- const MAX_POOL : number = 1000000000 ;
42
+ export const MAX_POOL : number = 1000000000 ;
40
43
41
44
interface Props extends CardProps {
42
45
title ?: string ;
@@ -67,7 +70,6 @@ export default function FinanceQuickTransfer({
67
70
68
71
// Local states
69
72
const [ walletAddress , setWalletAddress ] = useState ( storedAddress . address ?? '' ) ;
70
- const [ addressError , setAddressError ] = useState ( false ) ;
71
73
const [ currentIndex , setCurrentIndex ] = useState ( 0 ) ;
72
74
const [ addressFiltered , setAddressFiltered ] = useState < boolean > ( false ) ;
73
75
const [ initialized , setInitialized ] = useState ( false ) ;
@@ -182,27 +184,6 @@ export default function FinanceQuickTransfer({
182
184
}
183
185
} , [ initialList ] ) ;
184
186
185
- // Handle changes in the input field for the wallet address
186
- const handleInputChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
187
- const value = event . target . value ;
188
- setWalletAddress ( value ) ;
189
- dispatch ( storeAddress ( { address : value , profileId : getContactInfo ?. id ?? '' } ) ) ;
190
-
191
- // If it's a valid address, let the next effect handle searching in the list
192
- if ( isValidAddress ( value ) ) {
193
- setAddressFiltered ( true ) ; // We set a flag that we typed a valid address
194
- dispatch ( toggleRainbow ( ) ) ;
195
- setAddressError ( false ) ;
196
- } else {
197
- setAddressError ( true ) ;
198
- }
199
-
200
- // Rainbow effect trigger
201
- setTimeout ( ( ) => {
202
- dispatch ( toggleRainbow ( ) ) ;
203
- } , 1400 ) ;
204
- } ;
205
-
206
187
// Handle changes in the slider
207
188
const handleChangeSlider = useCallback ( ( _event : Event , newValue : number | number [ ] ) => {
208
189
setAmount ( newValue as number ) ;
@@ -211,31 +192,14 @@ export default function FinanceQuickTransfer({
211
192
}
212
193
} , [ MAX_AMOUNT ] ) ;
213
194
214
- // Helper function to handle amount constraints
215
- const handleAmountConstraints = ( value : number , MAX_AMOUNT : number ) => {
216
- if ( value > MAX_POOL ) {
217
- value = MAX_POOL ; // Truncate to a thousand millions
218
- }
219
- if ( value < 0 ) {
220
- value = 0 ; // Set amount to 0 if lower than 0
221
- }
222
- setAmount ( value ) ;
223
- setCanContinue ( value <= MAX_AMOUNT ) ;
224
-
225
- // If amount is greater than balance, allow input but setCanContinue to false
226
- if ( value > MAX_AMOUNT ) {
227
- setCanContinue ( false ) ;
228
- }
229
- } ;
230
-
231
195
const handleChangeInput = useCallback ( ( event : React . ChangeEvent < HTMLInputElement > ) => {
232
196
const value = Number ( event . target . value ) ;
233
- handleAmountConstraints ( value , MAX_AMOUNT ) ;
197
+ handleAmountConstraints ( { value, MAX_AMOUNT , MAX_POOL , setAmount , setCanContinue } ) ;
234
198
} , [ MAX_AMOUNT ] ) ;
235
199
236
200
237
201
const handleBlur = useCallback ( ( ) => {
238
- handleAmountConstraints ( amount , MAX_AMOUNT ) ;
202
+ handleAmountConstraints ( { value : amount , MAX_AMOUNT , MAX_POOL , setAmount , setCanContinue } ) ;
239
203
} , [ amount , MAX_AMOUNT ] ) ;
240
204
241
205
@@ -293,21 +257,6 @@ export default function FinanceQuickTransfer({
293
257
// We pick the contactInfo to pass to the modal. If currentIndex is -1, there's no matched profile
294
258
const contactInfoToPass = currentIndex === - 1 ? undefined : getContactInfo ;
295
259
296
- // Render the wallet address input
297
- const renderWalletInput = (
298
- < Box sx = { { mb : 3 } } >
299
- < TextField
300
- fullWidth
301
- label = "Wallet Address"
302
- value = { walletAddress }
303
- onChange = { handleInputChange }
304
- placeholder = "Enter wallet address"
305
- error = { addressError }
306
- helperText = { addressError ? 'Invalid wallet address' : '' }
307
- />
308
- </ Box >
309
- ) ;
310
-
311
260
// Render the carousel of profiles
312
261
const renderCarousel = (
313
262
< Box sx = { { position : 'relative' , mb : 3 } } >
@@ -418,13 +367,14 @@ export default function FinanceQuickTransfer({
418
367
disabled = { amount === 0 || ! isValidAddress ( walletAddress ) || ! canContinue }
419
368
onClick = { confirm . onTrue }
420
369
>
421
- Transfer Now
370
+ Quick transfer
422
371
</ Button >
423
372
</ Stack >
424
373
) ;
425
374
426
375
const Wrapper = showRainbow ? NeonPaper : Box ;
427
376
377
+ console . log ( list ) ;
428
378
return (
429
379
< >
430
380
< Wrapper
@@ -442,15 +392,17 @@ export default function FinanceQuickTransfer({
442
392
{ ...other }
443
393
>
444
394
< CardHeader
395
+ sx = { { p : '12px 16px 0 0' } }
445
396
title = { title }
446
397
subheader = { subheader }
447
398
action = { < FinanceSearchProfileModal onSelectProfile = { handleSelectProfile } /> }
448
399
/>
449
400
450
401
{ /* Content */ }
451
402
< Stack sx = { { p : 3 } } >
452
- { renderWalletInput }
453
- { ! ! list ?. length && renderCarousel }
403
+ < FinanceDisplayProfileInfo mode = { 'profile' } initialList = { initialList } carousel = { carousel } />
404
+ { list ?. length > 0 ? renderCarousel : < FinanceNoFollowingsQuickTransfer /> }
405
+ < FinanceDisplayProfileInfo mode = { 'wallet' } initialList = { initialList } carousel = { carousel } />
454
406
{ renderInput }
455
407
</ Stack >
456
408
</ Stack >
@@ -471,3 +423,4 @@ export default function FinanceQuickTransfer({
471
423
</ >
472
424
) ;
473
425
}
426
+
0 commit comments