-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #253 from Outblock/dev
[Release] 2.6.1
- Loading branch information
Showing
5 changed files
with
110 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import { | |
} from '@mui/material'; | ||
import { makeStyles } from '@mui/styles'; | ||
import { Box } from '@mui/system'; | ||
import React, { useCallback, useEffect, useState } from 'react'; | ||
import React, { useCallback, useEffect, useMemo, useState } from 'react'; | ||
|
||
import SlideRelative from '@/ui/FRWComponent/SlideRelative'; | ||
import { useWallet } from 'ui/utils'; | ||
|
@@ -39,87 +39,77 @@ const useStyles = makeStyles((_theme) => ({ | |
}, | ||
})); | ||
|
||
const UsernameError = (errorMsg) => ( | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<CancelIcon size={24} color="#E54040" style={{ margin: '8px' }} /> | ||
<Typography variant="body1" color="error.main"> | ||
{errorMsg} | ||
{errorMsg.startsWith('This username is reserved') && ( | ||
<span> | ||
<a href="mailto: [email protected]">[email protected]</a> | ||
{chrome.i18n.getMessage('for__any__inquiry')} | ||
</span> | ||
)} | ||
</Typography> | ||
</Box> | ||
); | ||
const UsernameCorrect = ( | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<CheckCircleIcon size={24} color="#41CC5D" style={{ margin: '8px' }} /> | ||
<Typography variant="body1" color="success.main"> | ||
{chrome.i18n.getMessage('Sounds_good')} | ||
</Typography> | ||
</Box> | ||
); | ||
const UsernameLoading = () => ( | ||
<Typography variant="body1" color="text.secondary" sx={{ display: 'flex', alignItems: 'center' }}> | ||
<CircularProgress color="primary" size={22} style={{ fontSize: '22px', margin: '8px' }} /> | ||
{chrome.i18n.getMessage('Checking')} | ||
</Typography> | ||
); | ||
|
||
const PickUsername = ({ handleClick, savedUsername, getUsername }) => { | ||
const classes = useStyles(); | ||
const wallet = useWallet(); | ||
const [isLoading, setLoading] = useState(false); | ||
const [usernameValid, setUsernameValid] = useState(false); | ||
|
||
const usernameError = (errorMsg) => ( | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<CancelIcon size={24} color="#E54040" style={{ margin: '8px' }} /> | ||
<Typography variant="body1" color="error.main"> | ||
{errorMsg} | ||
{errorMsg.startsWith('This username is reserved') && ( | ||
<span> | ||
<a href="mailto: [email protected]">[email protected]</a> | ||
{chrome.i18n.getMessage('for__any__inquiry')} | ||
</span> | ||
)} | ||
</Typography> | ||
</Box> | ||
); | ||
const usernameCorrect = useMemo( | ||
() => ( | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<CheckCircleIcon size={24} color="#41CC5D" style={{ margin: '8px' }} /> | ||
<Typography variant="body1" color="success.main"> | ||
{chrome.i18n.getMessage('Sounds_good')} | ||
</Typography> | ||
</Box> | ||
), | ||
[] | ||
); | ||
const usernameLoading = useMemo( | ||
() => ( | ||
<Typography | ||
variant="body1" | ||
color="text.secondary" | ||
sx={{ display: 'flex', alignItems: 'center' }} | ||
> | ||
<CircularProgress color="primary" size={22} style={{ fontSize: '22px', margin: '8px' }} /> | ||
{chrome.i18n.getMessage('Checking')} | ||
</Typography> | ||
), | ||
[] | ||
); | ||
|
||
const [username, setUsername] = useState(savedUsername || ''); | ||
const [helperText, setHelperText] = useState(<div />); | ||
|
||
const setErrorMessage = useCallback( | ||
(message: string) => { | ||
setLoading(false); | ||
setUsernameValid(false); | ||
setHelperText(UsernameError(message)); | ||
setHelperText(usernameError(message)); | ||
}, | ||
[setLoading, setUsernameValid, setHelperText] | ||
); | ||
|
||
useEffect(() => { | ||
setUsernameValid(false); | ||
setHelperText(UsernameLoading); | ||
setLoading(true); | ||
const delayDebounceFn = setTimeout(() => { | ||
if (username.length < 3) { | ||
setErrorMessage(chrome.i18n.getMessage('Too__short')); | ||
return; | ||
} | ||
|
||
if (username.length > 15) { | ||
setErrorMessage(chrome.i18n.getMessage('Too__long')); | ||
return; | ||
} | ||
const regex = /^[A-Za-z0-9]{3,15}$/; | ||
|
||
if (!regex.test(username)) { | ||
setErrorMessage( | ||
chrome.i18n.getMessage('Your__username__can__only__contain__letters__and__numbers') | ||
); | ||
return; | ||
} | ||
const runCheckUsername = useCallback( | ||
(username) => { | ||
wallet.openapi | ||
.checkUsername(username.toLowerCase()) | ||
.then((response) => { | ||
|
@@ -130,7 +120,7 @@ const PickUsername = ({ handleClick, savedUsername, getUsername }) => { | |
} | ||
if (response.data.unique) { | ||
setUsernameValid(true); | ||
setHelperText(UsernameCorrect); | ||
setHelperText(usernameCorrect); | ||
} else { | ||
if (response.message === 'Username is reserved') { | ||
setErrorMessage( | ||
|
@@ -141,20 +131,51 @@ const PickUsername = ({ handleClick, savedUsername, getUsername }) => { | |
} | ||
} | ||
}) | ||
.catch((error) => { | ||
.catch(() => { | ||
setErrorMessage(chrome.i18n.getMessage('Oops__unexpected__error')); | ||
}); | ||
}, | ||
[setErrorMessage, setUsernameValid, setHelperText, usernameCorrect, wallet.openapi] | ||
); | ||
|
||
useEffect(() => { | ||
setUsernameValid(false); | ||
setHelperText(usernameLoading); | ||
setLoading(true); | ||
const delayDebounceFn = setTimeout(() => { | ||
if (username.length < 3) { | ||
setErrorMessage(chrome.i18n.getMessage('Too__short')); | ||
setLoading(false); | ||
return; | ||
} | ||
|
||
if (username.length > 15) { | ||
setErrorMessage(chrome.i18n.getMessage('Too__long')); | ||
setLoading(false); | ||
return; | ||
} | ||
|
||
const regex = /^[A-Za-z0-9]{3,15}$/; | ||
if (!regex.test(username)) { | ||
setErrorMessage( | ||
chrome.i18n.getMessage('Your__username__can__only__contain__letters__and__numbers') | ||
); | ||
setLoading(false); | ||
return; | ||
} | ||
|
||
runCheckUsername(username); | ||
}, 500); | ||
|
||
return () => clearTimeout(delayDebounceFn); | ||
}, [setErrorMessage, username, wallet.openapi]); | ||
}, [username]); | ||
|
||
const msgBgColor = () => { | ||
const msgBgColor = useCallback(() => { | ||
if (isLoading) { | ||
return 'neutral.light'; | ||
} | ||
return usernameValid ? 'success.light' : 'error.light'; | ||
}; | ||
}, [isLoading, usernameValid]); | ||
|
||
return ( | ||
<> | ||
|
@@ -201,7 +222,7 @@ const PickUsername = ({ handleClick, savedUsername, getUsername }) => { | |
</InputAdornment> | ||
} | ||
/> | ||
<SlideRelative direction="down" show={username}> | ||
<SlideRelative direction="down" show={!!username}> | ||
<Box | ||
sx={{ | ||
width: '95%', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters