fix: skip MFA dialog when MFA is not enabled
This commit is contained in:
@@ -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 {
|
||||
ProForm,
|
||||
@@ -23,6 +23,7 @@ import MultiFactorAuthentication from "@/pages/account/MultiFactorAuthentication
|
||||
import AssetLogo from "./components/AssetLogo";
|
||||
import AccountTypeForm from "./components/AccountTypeForm";
|
||||
import AssetAdvancedSettings from "./components/AssetAdvancedSettings";
|
||||
import accountApi from "@/api/account-api";
|
||||
|
||||
const formItemLayout = {
|
||||
labelCol: {span: 4},
|
||||
@@ -44,9 +45,30 @@ const AssetsPost = function ({assetId, groupId, copy, onClose}: AssetsInfoProps)
|
||||
let [logo, setLogo] = useState<string>();
|
||||
let [decrypted, setDecrypted] = useState(false);
|
||||
let [mfaOpen, setMfaOpen] = useState(false);
|
||||
let [mfaSupported, setMfaSupported] = useState(false);
|
||||
|
||||
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 () => {
|
||||
if (assetId) {
|
||||
let asset = await assetsApi.getById(assetId);
|
||||
@@ -135,7 +157,7 @@ const AssetsPost = function ({assetId, groupId, copy, onClose}: AssetsInfoProps)
|
||||
copy={copy}
|
||||
decrypted={decrypted}
|
||||
setDecrypted={setDecrypted}
|
||||
setMfaOpen={setMfaOpen}
|
||||
onViewSecret={handleViewSecret}
|
||||
formRef={formRef}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -12,7 +12,7 @@ interface AccountTypeFormProps {
|
||||
copy?: boolean;
|
||||
decrypted: boolean;
|
||||
setDecrypted: (value: boolean) => void;
|
||||
setMfaOpen: (value: boolean) => void;
|
||||
onViewSecret: () => void;
|
||||
formRef?: React.RefObject<ProFormInstance>;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ const AccountTypeForm: React.FC<AccountTypeFormProps> = ({
|
||||
copy,
|
||||
decrypted,
|
||||
setDecrypted,
|
||||
setMfaOpen,
|
||||
onViewSecret,
|
||||
formRef
|
||||
}) => {
|
||||
const {t} = useTranslation();
|
||||
@@ -59,7 +59,7 @@ const AccountTypeForm: React.FC<AccountTypeFormProps> = ({
|
||||
visibilityToggle: {
|
||||
onVisibleChange: (visible) => {
|
||||
if (assetId && !copy && visible && !decrypted) {
|
||||
setMfaOpen(true)
|
||||
onViewSecret()
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -98,9 +98,7 @@ const AccountTypeForm: React.FC<AccountTypeFormProps> = ({
|
||||
<Button
|
||||
color={'purple'}
|
||||
variant={'filled'}
|
||||
onClick={async () => {
|
||||
setMfaOpen(true)
|
||||
}}
|
||||
onClick={onViewSecret}
|
||||
>
|
||||
{t('actions.view_private_key')}
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user