fix(crypto address setting): default description didn't appear, clicking 'check' with address already set would result in error

This commit is contained in:
Tom (plebeius.eth)
2024-10-15 12:56:18 +02:00
parent 44a09f9e5b
commit ff3f5f618d
@@ -10,8 +10,8 @@ const CryptoAddressSetting = () => {
const [cryptoState, setCryptoState] = useState({ const [cryptoState, setCryptoState] = useState({
cryptoAddress: '', cryptoAddress: '',
checkingCryptoAddress: false, checkingCryptoAddress: false,
showResolvingMessage: false, showResolvingMessage: true,
resolveString: '', resolveString: t('crypto_address_verification'),
resolveClass: '', resolveClass: '',
}); });
@@ -20,8 +20,11 @@ const CryptoAddressSetting = () => {
const author = { ...account?.author, address: cryptoState.cryptoAddress }; const author = { ...account?.author, address: cryptoState.cryptoAddress };
const { resolvedAddress, state, error, chainProvider } = useResolvedAuthorAddress({ author, cache: false }); const { resolvedAddress, state, error, chainProvider } = useResolvedAuthorAddress({ author, cache: false });
const [inputValue, setInputValue] = useState(account?.author?.shortAddress.includes('.') ? account.author.shortAddress : '');
const checkCryptoAddress = () => { const checkCryptoAddress = () => {
if (!cryptoState.cryptoAddress || !cryptoState.cryptoAddress.includes('.')) { const addressToCheck = inputValue || cryptoState.cryptoAddress;
if (!addressToCheck || !addressToCheck.includes('.')) {
alert(t('enter_crypto_address')); alert(t('enter_crypto_address'));
return; return;
} }
@@ -48,6 +51,7 @@ const CryptoAddressSetting = () => {
setCryptoState((prevState) => ({ setCryptoState((prevState) => ({
...prevState, ...prevState,
cryptoAddress: addressToCheck,
showResolvingMessage: true, showResolvingMessage: true,
resolveString, resolveString,
resolveClass, resolveClass,
@@ -106,8 +110,11 @@ const CryptoAddressSetting = () => {
<input <input
type='text' type='text'
placeholder='address.eth/.sol' placeholder='address.eth/.sol'
defaultValue={cryptoState.cryptoAddress || (account?.author?.shortAddress.includes('.') ? account.author.shortAddress : '')} value={inputValue}
onChange={(e) => setCryptoState((prevState) => ({ ...prevState, cryptoAddress: e.target.value }))} onChange={(e) => {
setInputValue(e.target.value);
setCryptoState((prevState) => ({ ...prevState, cryptoAddress: e.target.value }));
}}
/> />
<button className={styles.saveButton} onClick={saveCryptoAddress}> <button className={styles.saveButton} onClick={saveCryptoAddress}>
{t('save')} {t('save')}