From 123570855a8e3ad5ac4114577727539595589491 Mon Sep 17 00:00:00 2001 From: devchenyan Date: Tue, 7 Jan 2025 10:48:15 +0800 Subject: [PATCH 1/4] feat: Optimize Sign/verify Message --- .../src/components/SignAndVerify/index.tsx | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/packages/neuron-ui/src/components/SignAndVerify/index.tsx b/packages/neuron-ui/src/components/SignAndVerify/index.tsx index b7fda6304b..7e4182dc31 100644 --- a/packages/neuron-ui/src/components/SignAndVerify/index.tsx +++ b/packages/neuron-ui/src/components/SignAndVerify/index.tsx @@ -1,9 +1,18 @@ -import React, { useState, useEffect, useCallback } from 'react' +import React, { useState, useEffect, useCallback, useMemo } from 'react' import { TFunction } from 'i18next' import { useTranslation } from 'react-i18next' import { showErrorMessage, signMessage, verifyMessage } from 'services/remote' import { ControllerResponse } from 'services/remote/remoteApiWrapper' -import { ErrorCode, isSuccessResponse, shannonToCKBFormatter, useExitOnWalletChange, useGoBack } from 'utils' +import { + ErrorCode, + isSuccessResponse, + shannonToCKBFormatter, + useExitOnWalletChange, + useGoBack, + validateAddress, + isMainnet as isMainnetUtil, +} from 'utils' +import { isErrorWithI18n } from 'exceptions' import { useState as useGlobalState } from 'states' import Button from 'widgets/Button' import Balance from 'widgets/Balance' @@ -130,8 +139,14 @@ const SignAndVerify = () => { const [message, setMessage] = useState('') const [signature, setSignature] = useState('') const [address, setAddress] = useState('') - const { wallet } = useGlobalState() + // const [addressError, setAddressError] = useState('') + const { + chain: { networkID }, + settings: { networks }, + wallet, + } = useGlobalState() const [isDropdownOpen, setIsDropdownOpen] = useState(false) + const isMainnet = isMainnetUtil(networks, networkID) useExitOnWalletChange() const handlePasswordDialogOpen = useCallback(() => { @@ -226,12 +241,26 @@ const SignAndVerify = () => { const onBack = useGoBack() + const addressError = useMemo(() => { + if (!address) { + return undefined + } + try { + validateAddress(address, isMainnet) + } catch (err) { + if (isErrorWithI18n(err)) { + return t(err.message, err.i18n) + } + } + return undefined + }, [t, address, isMainnet]) + return (
{
} width="100%" + error={addressError} /> {isDropdownOpen && wallet?.addresses ? ( @@ -311,7 +341,7 @@ const SignAndVerify = () => { {wallet?.isWatchOnly || (
- From 4169c537366c59d4b35bfbce52713df92ae808e9 Mon Sep 17 00:00:00 2001 From: devchenyan Date: Tue, 7 Jan 2025 10:49:59 +0800 Subject: [PATCH 2/4] fix: check --- .../src/utils/hooks/useGetCountDownAndFeeRateStats.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/neuron-ui/src/utils/hooks/useGetCountDownAndFeeRateStats.ts b/packages/neuron-ui/src/utils/hooks/useGetCountDownAndFeeRateStats.ts index fa6f181910..ac25ab7690 100644 --- a/packages/neuron-ui/src/utils/hooks/useGetCountDownAndFeeRateStats.ts +++ b/packages/neuron-ui/src/utils/hooks/useGetCountDownAndFeeRateStats.ts @@ -15,7 +15,7 @@ const useGetCountDownAndFeeRateStats = ({ seconds = 30, interval = 1000 }: Count suggestFeeRate: number }>({ suggestFeeRate: MEDIUM_FEE_RATE }) - const handleGetFeeRateStatis = useCallback(() => { + const handleGetFeeRateStatistics = useCallback(() => { getFeeRateStatistics() .then(res => { const { median } = res ?? {} @@ -50,7 +50,7 @@ const useGetCountDownAndFeeRateStats = ({ seconds = 30, interval = 1000 }: Count useEffect(() => { if (countDown === seconds) { - handleGetFeeRateStatis() + handleGetFeeRateStatistics() } }, [countDown, seconds]) From 63ced4a050c94199854c289c5916bbc3ede133bf Mon Sep 17 00:00:00 2001 From: devchenyan Date: Tue, 7 Jan 2025 18:54:54 +0800 Subject: [PATCH 3/4] fix --- packages/neuron-ui/src/components/SignAndVerify/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/neuron-ui/src/components/SignAndVerify/index.tsx b/packages/neuron-ui/src/components/SignAndVerify/index.tsx index 7e4182dc31..ca2760a35a 100644 --- a/packages/neuron-ui/src/components/SignAndVerify/index.tsx +++ b/packages/neuron-ui/src/components/SignAndVerify/index.tsx @@ -139,7 +139,6 @@ const SignAndVerify = () => { const [message, setMessage] = useState('') const [signature, setSignature] = useState('') const [address, setAddress] = useState('') - // const [addressError, setAddressError] = useState('') const { chain: { networkID }, settings: { networks }, From d68e0235c4076dea02526e0999c4ba391a6864f1 Mon Sep 17 00:00:00 2001 From: devchenyan Date: Sat, 11 Jan 2025 21:46:43 +0800 Subject: [PATCH 4/4] fix: comment --- packages/neuron-ui/src/components/SignAndVerify/index.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/neuron-ui/src/components/SignAndVerify/index.tsx b/packages/neuron-ui/src/components/SignAndVerify/index.tsx index ca2760a35a..610804eae4 100644 --- a/packages/neuron-ui/src/components/SignAndVerify/index.tsx +++ b/packages/neuron-ui/src/components/SignAndVerify/index.tsx @@ -251,8 +251,11 @@ const SignAndVerify = () => { return t(err.message, err.i18n) } } + if (wallet?.addresses && !wallet.addresses.find(item => item.address === address)) { + return t('sign-and-verify.address-not-found') + } return undefined - }, [t, address, isMainnet]) + }, [t, address, isMainnet, wallet.addresses]) return (