From 781e2df91f4ece389bab55c7b6831b7be14b02a2 Mon Sep 17 00:00:00 2001 From: qianzhu <36325249+syt-honey@users.noreply.github.com> Date: Thu, 17 Aug 2023 14:12:12 +0800 Subject: [PATCH] fix(flat-components): fix send code tip error --- .../LoginPage/LoginSendCode/index.tsx | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/packages/flat-components/src/components/LoginPage/LoginSendCode/index.tsx b/packages/flat-components/src/components/LoginPage/LoginSendCode/index.tsx index 9f0e1477134..5738528e85b 100644 --- a/packages/flat-components/src/components/LoginPage/LoginSendCode/index.tsx +++ b/packages/flat-components/src/components/LoginPage/LoginSendCode/index.tsx @@ -8,6 +8,7 @@ import { useIsUnMounted, useSafePromise } from "../../../utils/hooks"; import { PasswordLoginType, isPhone } from "../LoginAccount"; import checkedSVG from "../icons/checked.svg"; import { BindingPhoneSendCodeResult, RequestErrorCode } from "@netless/flat-server-api"; +import { errorTips } from "../../../utils/errorTip"; export interface LoginSendCodeProps { isAccountValidated: boolean; @@ -37,24 +38,32 @@ export const LoginSendCode: React.FC = ({ if (isAccountValidated) { try { setSendingCode(true); - await sp(sendVerificationCode()); - + const sent = await sp(sendVerificationCode()); setSendingCode(false); - void message.info( - t(isPhone(type) ? "sent-verify-code-to-phone" : "sent-verify-code-to-email"), - ); - let count = 60; - setCountdown(count); - const timer = setInterval(() => { - if (isUnMountRef.current) { - clearInterval(timer); - return; - } - setCountdown(--count); - if (count === 0) { - clearInterval(timer); - } - }, 1000); + + if (sent) { + void message.info( + t( + isPhone(type) + ? "sent-verify-code-to-phone" + : "sent-verify-code-to-email", + ), + ); + let count = 60; + setCountdown(count); + const timer = setInterval(() => { + if (isUnMountRef.current) { + clearInterval(timer); + return; + } + setCountdown(--count); + if (count === 0) { + clearInterval(timer); + } + }, 1000); + } else { + message.error(t("send-verify-code-failed")); + } } catch (error) { if (!isUnMountRef.current) { setSendingCode(false); @@ -70,7 +79,7 @@ export const LoginSendCode: React.FC = ({ return; } - message.error(t("send-verify-code-failed")); + errorTips(error); } } }, [