Skip to content

Commit

Permalink
fix(flat-components): fix send code tip error (#2002)
Browse files Browse the repository at this point in the history
  • Loading branch information
syt-honey authored Aug 17, 2023
1 parent df08bba commit 719cb00
Showing 1 changed file with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -37,24 +38,32 @@ export const LoginSendCode: React.FC<LoginSendCodeProps> = ({
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);
Expand All @@ -70,7 +79,7 @@ export const LoginSendCode: React.FC<LoginSendCodeProps> = ({
return;
}

message.error(t("send-verify-code-failed"));
errorTips(error);
}
}
}, [
Expand Down

0 comments on commit 719cb00

Please sign in to comment.