fix: skip MFA dialog when MFA is not enabled

This commit is contained in:
2026-04-19 22:00:16 +08:00
parent 0a62c7078b
commit ca427c7aac
2 changed files with 28 additions and 8 deletions
+24 -2
View File
@@ -1,4 +1,4 @@
import React, {useRef, useState} from 'react'; import React, {useEffect, useRef, useState} from 'react';
import {App, Collapse, Form, Input, InputNumber, Space, theme, TreeDataNode,} from "antd"; import {App, Collapse, Form, Input, InputNumber, Space, theme, TreeDataNode,} from "antd";
import { import {
ProForm, ProForm,
@@ -23,6 +23,7 @@ import MultiFactorAuthentication from "@/pages/account/MultiFactorAuthentication
import AssetLogo from "./components/AssetLogo"; import AssetLogo from "./components/AssetLogo";
import AccountTypeForm from "./components/AccountTypeForm"; import AccountTypeForm from "./components/AccountTypeForm";
import AssetAdvancedSettings from "./components/AssetAdvancedSettings"; import AssetAdvancedSettings from "./components/AssetAdvancedSettings";
import accountApi from "@/api/account-api";
const formItemLayout = { const formItemLayout = {
labelCol: {span: 4}, labelCol: {span: 4},
@@ -44,9 +45,30 @@ const AssetsPost = function ({assetId, groupId, copy, onClose}: AssetsInfoProps)
let [logo, setLogo] = useState<string>(); let [logo, setLogo] = useState<string>();
let [decrypted, setDecrypted] = useState(false); let [decrypted, setDecrypted] = useState(false);
let [mfaOpen, setMfaOpen] = useState(false); let [mfaOpen, setMfaOpen] = useState(false);
let [mfaSupported, setMfaSupported] = useState(false);
let {message} = App.useApp(); let {message} = App.useApp();
useEffect(() => {
accountApi.getSecurityTokenSupportTypes().then(types => {
setMfaSupported(types.length > 0);
});
}, []);
const handleViewSecret = async () => {
if (mfaSupported) {
setMfaOpen(true);
} else {
const res = await assetsApi.decrypt(assetId, '');
formRef.current?.setFieldsValue({
'password': res.password,
'privateKey': res.privateKey,
'passphrase': res.passphrase,
});
setDecrypted(true);
}
};
const get = async () => { const get = async () => {
if (assetId) { if (assetId) {
let asset = await assetsApi.getById(assetId); let asset = await assetsApi.getById(assetId);
@@ -135,7 +157,7 @@ const AssetsPost = function ({assetId, groupId, copy, onClose}: AssetsInfoProps)
copy={copy} copy={copy}
decrypted={decrypted} decrypted={decrypted}
setDecrypted={setDecrypted} setDecrypted={setDecrypted}
setMfaOpen={setMfaOpen} onViewSecret={handleViewSecret}
formRef={formRef} formRef={formRef}
/> />
)} )}
@@ -12,7 +12,7 @@ interface AccountTypeFormProps {
copy?: boolean; copy?: boolean;
decrypted: boolean; decrypted: boolean;
setDecrypted: (value: boolean) => void; setDecrypted: (value: boolean) => void;
setMfaOpen: (value: boolean) => void; onViewSecret: () => void;
formRef?: React.RefObject<ProFormInstance>; formRef?: React.RefObject<ProFormInstance>;
} }
@@ -23,7 +23,7 @@ const AccountTypeForm: React.FC<AccountTypeFormProps> = ({
copy, copy,
decrypted, decrypted,
setDecrypted, setDecrypted,
setMfaOpen, onViewSecret,
formRef formRef
}) => { }) => {
const {t} = useTranslation(); const {t} = useTranslation();
@@ -59,7 +59,7 @@ const AccountTypeForm: React.FC<AccountTypeFormProps> = ({
visibilityToggle: { visibilityToggle: {
onVisibleChange: (visible) => { onVisibleChange: (visible) => {
if (assetId && !copy && visible && !decrypted) { if (assetId && !copy && visible && !decrypted) {
setMfaOpen(true) onViewSecret()
} }
} }
}, },
@@ -98,9 +98,7 @@ const AccountTypeForm: React.FC<AccountTypeFormProps> = ({
<Button <Button
color={'purple'} color={'purple'}
variant={'filled'} variant={'filled'}
onClick={async () => { onClick={onViewSecret}
setMfaOpen(true)
}}
> >
{t('actions.view_private_key')} {t('actions.view_private_key')}
</Button> </Button>