fix: password Demo into gallery (#3853)

* fix: password Demo into gallery

Signed-off-by: 王山栋 <jelly@onekey.so>

* fix: lint

Signed-off-by: 王山栋 <jelly@onekey.so>

---------

Signed-off-by: 王山栋 <jelly@onekey.so>
Co-authored-by: loatheb <zhangzhao@onekey.so>
This commit is contained in:
JellyWang
2023-11-23 17:10:32 +08:00
committed by GitHub
parent 236d6f1dc6
commit 6b406b16e4
4 changed files with 146 additions and 111 deletions

View File

@@ -34,6 +34,7 @@ import JotaiContextGallery from '../../../../../views/Components/stories/JotaiCo
import JotaiGlobalGallery from '../../../../../views/Components/stories/JotaiGlobalGallery';
import ListViewGallery from '../../../../../views/Components/stories/ListView';
import LocalDBGallery from '../../../../../views/Components/stories/LocalDBGallery';
import PasswordDemoGallery from '../../../../../views/Components/stories/PasswordDemo';
import QRCodeGallery from '../../../../../views/Components/stories/QRCode';
import ScrollViewGallery from '../../../../../views/Components/stories/ScrollView';
import SectionListGallery from '../../../../../views/Components/stories/SectionList';
@@ -73,6 +74,10 @@ export const galleryScreenList: {
{ name: EGalleryRoutes.ComponentActionList, component: ActionListGallery },
{ name: EGalleryRoutes.ComponentPopover, component: PopoverGallery },
{ name: EGalleryRoutes.ComponentProgress, component: ProgressGallery },
{
name: EGalleryRoutes.ComponentPasswordDemo,
component: PasswordDemoGallery,
},
{
name: EGalleryRoutes.ComponentIconButton,
component: IconButtonGallery,

View File

@@ -39,4 +39,5 @@ export enum EGalleryRoutes {
ComponentListView = 'component/ListView',
ComponentSectionList = 'component/SectionList',
ComponentListItem = 'component/ListItem',
ComponentPasswordDemo = 'component/passwordDemo',
}

View File

@@ -0,0 +1,137 @@
import { Suspense } from 'react';
import { useTheme } from 'tamagui';
import {
Button,
Dialog,
Spinner,
Text,
Toast,
XStack,
YStack,
} from '@onekeyhq/components';
import type { IPasswordRes } from '@onekeyhq/kit-bg/src/services/ServicePassword';
import { EPasswordResStatus } from '@onekeyhq/kit-bg/src/services/ServicePassword';
import backgroundApiProxy from '../../../background/instance/backgroundApiProxy';
import BiologyAuthSwitchContainer from '../../../components/BiologyAuthComponent/container/BiologyAuthSwitchContainer';
import WebAuthSwitchContainer from '../../../components/BiologyAuthComponent/container/WebAuthSwitchContainer';
import PasswordSetupContainer from '../../../components/Password/container/PasswordSetupContainer';
import PasswordUpdateContainer from '../../../components/Password/container/PasswordUpdateContainer';
import { Layout } from './utils/Layout';
const PasswordDemoGallery = () => {
const theme = useTheme();
console.log(theme);
const handlePasswordVerify = async () => {
try {
const { status, data } =
await (backgroundApiProxy.servicePassword.promptPasswordVerify() as Promise<IPasswordRes>);
console.log('data', data);
if (status === EPasswordResStatus.PASS_STATUS) {
Toast.success({ title: '验证成功' });
}
} catch (e: any) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const errorMessage = e?.message;
if (errorMessage) {
Toast.error({ title: errorMessage });
}
}
};
return (
<Layout
description=""
suggestions={['']}
boundaryConditions={['']}
elements={[
{
title: 'Native',
element: (
<YStack space="$2" justifyContent="center">
<Button
onPress={async () => {
const checkPasswordSet =
await backgroundApiProxy.servicePassword.checkPasswordSet();
if (checkPasswordSet) {
await handlePasswordVerify();
} else {
const dialog = Dialog.confirm({
title: 'SetupPassword',
renderContent: (
<PasswordSetupContainer
onSetupRes={(data) => {
console.log('setup data', data);
if (data) {
Toast.success({ title: '设置成功' });
dialog.close();
}
}}
/>
),
showFooter: false,
});
}
// setOpen(!open);
}}
>
</Button>
<Button
onPress={async () => {
const dialog = Dialog.confirm({
title: 'UpdatePassword',
renderContent: (
<PasswordUpdateContainer
onUpdateRes={(data) => {
console.log('update data', data);
if (data) {
Toast.success({ title: '修改成功' });
dialog.close();
}
}}
/>
),
showFooter: false,
});
}}
>
</Button>
<Button onPress={handlePasswordVerify}></Button>
<XStack justifyContent="space-between">
<Text></Text>
<Suspense fallback={<Spinner size="large" />}>
<BiologyAuthSwitchContainer />
</Suspense>
</XStack>
<XStack justifyContent="space-between">
<Text>Chrome生物识别</Text>
<Suspense fallback={<Spinner size="large" />}>
<WebAuthSwitchContainer />
</Suspense>
</XStack>
<Button
onPress={async () => {
try {
const res =
await backgroundApiProxy.servicePassword.verifyWebAuth();
Toast.success({ title: res ? '解锁成功' : '请输入密码' });
} catch (e) {
console.log('e', e);
}
}}
>
Chrome生物识别
</Button>
</YStack>
),
},
]}
/>
);
};
export default PasswordDemoGallery;

View File

@@ -1,122 +1,14 @@
import { Suspense, memo } from 'react';
import { memo } from 'react';
import {
Button,
Dialog,
Page,
Spinner,
Text,
Toast,
XStack,
} from '@onekeyhq/components';
import {
EPasswordResStatus,
type IPasswordRes,
} from '@onekeyhq/kit-bg/src/services/ServicePassword';
import backgroundApiProxy from '../../background/instance/backgroundApiProxy';
import BiologyAuthSwitchContainer from '../../components/BiologyAuthComponent/container/BiologyAuthSwitchContainer';
import WebAuthSwitchContainer from '../../components/BiologyAuthComponent/container/WebAuthSwitchContainer';
import PasswordSetupContainer from '../../components/Password/container/PasswordSetupContainer';
import PasswordUpdateContainer from '../../components/Password/container/PasswordUpdateContainer';
import { Page, Text } from '@onekeyhq/components';
const Swap = () => {
console.log('swap');
const handlePasswordVerify = async () => {
try {
const { status, data } =
await (backgroundApiProxy.servicePassword.promptPasswordVerify() as Promise<IPasswordRes>);
console.log('data', data);
if (status === EPasswordResStatus.PASS_STATUS) {
Toast.success({ title: '验证成功' });
}
} catch (e: any) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const errorMessage = e?.message;
if (errorMessage) {
Toast.error({ title: errorMessage });
}
}
};
return (
<Page>
<Page.Body space="$4">
<Text>Swap</Text>
<Button
onPress={async () => {
const checkPasswordSet =
await backgroundApiProxy.servicePassword.checkPasswordSet();
if (checkPasswordSet) {
await handlePasswordVerify();
} else {
const dialog = Dialog.confirm({
title: 'SetupPassword',
renderContent: (
<PasswordSetupContainer
onSetupRes={(data) => {
console.log('setup data', data);
if (data) {
Toast.success({ title: '设置成功' });
dialog.close();
}
}}
/>
),
showFooter: false,
});
}
// setOpen(!open);
}}
>
</Button>
<Button
onPress={async () => {
const dialog = Dialog.confirm({
title: 'UpdatePassword',
renderContent: (
<PasswordUpdateContainer
onUpdateRes={(data) => {
console.log('update data', data);
if (data) {
Toast.success({ title: '修改成功' });
dialog.close();
}
}}
/>
),
showFooter: false,
});
}}
>
</Button>
<Button onPress={handlePasswordVerify}></Button>
<XStack justifyContent="space-between">
<Text></Text>
<Suspense fallback={<Spinner size="large" />}>
<BiologyAuthSwitchContainer />
</Suspense>
</XStack>
<XStack justifyContent="space-between">
<Text>Chrome生物识别</Text>
<Suspense fallback={<Spinner size="large" />}>
<WebAuthSwitchContainer />
</Suspense>
</XStack>
<Button
onPress={async () => {
try {
const res =
await backgroundApiProxy.servicePassword.verifyWebAuth();
Toast.success({ title: res ? '解锁成功' : '请输入密码' });
} catch (e) {
console.log('e', e);
}
}}
>
Chrome生物识别
</Button>
</Page.Body>
</Page>
);