@@ -13,7 +13,7 @@ import { TextArea } from 'components/atoms/TextArea';
13
13
import { AO , ASSETS , GATEWAYS , TAGS } from 'helpers/config' ;
14
14
import { getTxEndpoint } from 'helpers/endpoints' ;
15
15
import { NotificationType } from 'helpers/types' ;
16
- import { checkAddress , getBase64Data , getDataURLContentType } from 'helpers/utils' ;
16
+ import { checkValidAddress , getBase64Data , getDataURLContentType } from 'helpers/utils' ;
17
17
import { useArweaveProvider } from 'providers/ArweaveProvider' ;
18
18
import { useLanguageProvider } from 'providers/LanguageProvider' ;
19
19
import { WalletBlock } from 'wallet/WalletBlock' ;
@@ -22,6 +22,7 @@ import * as S from './styles';
22
22
import { IProps } from './types' ;
23
23
24
24
const MAX_BIO_LENGTH = 500 ;
25
+ const MAX_IMAGE_SIZE = 100000 ;
25
26
const ALLOWED_BANNER_TYPES = 'image/png, image/jpeg, image/gif' ;
26
27
const ALLOWED_AVATAR_TYPES = 'image/png, image/jpeg, image/gif' ;
27
28
@@ -48,8 +49,8 @@ export default function ProfileManage(props: IProps) {
48
49
setUsername ( props . profile . username ?? '' ) ;
49
50
setName ( props . profile . displayName ?? '' ) ;
50
51
setBio ( props . profile . bio ?? '' ) ;
51
- setBanner ( props . profile . banner && checkAddress ( props . profile . banner ) ? props . profile . banner : null ) ;
52
- setAvatar ( props . profile . avatar && checkAddress ( props . profile . avatar ) ? props . profile . avatar : null ) ;
52
+ setBanner ( props . profile . banner && checkValidAddress ( props . profile . banner ) ? props . profile . banner : null ) ;
53
+ setAvatar ( props . profile . avatar && checkValidAddress ( props . profile . avatar ) ? props . profile . avatar : null ) ;
53
54
}
54
55
} , [ props . profile ] ) ;
55
56
@@ -70,7 +71,7 @@ export default function ProfileManage(props: IProps) {
70
71
71
72
let bannerTx : any = null ;
72
73
if ( banner ) {
73
- if ( checkAddress ( banner ) ) {
74
+ if ( checkValidAddress ( banner ) ) {
74
75
bannerTx = banner ;
75
76
} else {
76
77
try {
@@ -91,7 +92,7 @@ export default function ProfileManage(props: IProps) {
91
92
92
93
let avatarTx : any = null ;
93
94
if ( avatar ) {
94
- if ( checkAddress ( avatar ) ) {
95
+ if ( checkValidAddress ( avatar ) ) {
95
96
avatarTx = avatar ;
96
97
} else {
97
98
try {
@@ -251,6 +252,20 @@ export default function ProfileManage(props: IProps) {
251
252
}
252
253
}
253
254
255
+ function getImageSizeMessage ( ) {
256
+ if ( ! avatar && ! banner ) return null ;
257
+ if ( checkValidAddress ( avatar ) && checkValidAddress ( banner ) ) return null ;
258
+
259
+ const avatarSize = avatar ? ( avatar . length * 3 ) / 4 : 0 ;
260
+ const bannerSize = banner ? ( banner . length * 3 ) / 4 : 0 ;
261
+
262
+ console . log ( avatarSize ) ;
263
+
264
+ if ( avatarSize > MAX_IMAGE_SIZE || bannerSize > MAX_IMAGE_SIZE )
265
+ return < span > One or more images exceeds max size of 100KB</ span > ;
266
+ return null ;
267
+ }
268
+
254
269
function getInvalidBio ( ) {
255
270
if ( bio && bio . length > MAX_BIO_LENGTH ) {
256
271
return {
@@ -289,7 +304,7 @@ export default function ProfileManage(props: IProps) {
289
304
}
290
305
291
306
function getBannerWrapper ( ) {
292
- if ( banner ) return < img src = { checkAddress ( banner ) ? getTxEndpoint ( banner ) : banner } /> ;
307
+ if ( banner ) return < img src = { checkValidAddress ( banner ) ? getTxEndpoint ( banner ) : banner } /> ;
293
308
return (
294
309
< >
295
310
< ReactSVG src = { ASSETS . media } />
@@ -299,7 +314,7 @@ export default function ProfileManage(props: IProps) {
299
314
}
300
315
301
316
function getAvatarWrapper ( ) {
302
- if ( avatar ) return < img src = { checkAddress ( avatar ) ? getTxEndpoint ( avatar ) : avatar } /> ;
317
+ if ( avatar ) return < img src = { checkValidAddress ( avatar ) ? getTxEndpoint ( avatar ) : avatar } /> ;
303
318
return (
304
319
< >
305
320
< ReactSVG src = { ASSETS . user } />
@@ -360,9 +375,12 @@ export default function ProfileManage(props: IProps) {
360
375
disabled = { loading || ! banner }
361
376
/>
362
377
</ S . PActions >
378
+ < S . PInfoMessage >
379
+ < span > Images have a max size of 100KB</ span >
380
+ </ S . PInfoMessage >
363
381
</ S . PWrapper >
364
382
< S . Form >
365
- < S . TForm className = { 'border-wrapper-alt2' } >
383
+ < S . TForm >
366
384
< FormField
367
385
label = { language . name }
368
386
value = { name }
@@ -409,10 +427,11 @@ export default function ProfileManage(props: IProps) {
409
427
type = { 'alt1' }
410
428
label = { language . save }
411
429
handlePress = { handleSubmit }
412
- disabled = { ! username || ! name || loading }
430
+ disabled = { ! username || ! name || loading || getImageSizeMessage ( ) !== null }
413
431
loading = { loading }
414
432
/>
415
433
</ S . SAction >
434
+ { getImageSizeMessage ( ) && < S . MInfoWrapper > { getImageSizeMessage ( ) } </ S . MInfoWrapper > }
416
435
</ S . Body >
417
436
</ S . Wrapper >
418
437
{ profileResponse && (
0 commit comments