Skip to content

Commit

Permalink
feat: new import
Browse files Browse the repository at this point in the history
  • Loading branch information
cs1707 committed Nov 21, 2024
1 parent e3f5dd8 commit 97d59b3
Show file tree
Hide file tree
Showing 7 changed files with 317 additions and 236 deletions.
2 changes: 1 addition & 1 deletion _raw/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2314,7 +2314,7 @@
"label": "Password",
"placeholder": "8 characters min",
"required": "Please input Password",
"min": "8 characters min"
"min": "Password must be at least 8 characters long"
},
"confirmPassword": {
"label": "Confirm Password",
Expand Down
3 changes: 3 additions & 0 deletions src/ui/assets/icon-checked-success-cc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 13 additions & 6 deletions src/ui/views/MainRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import { ImportOrCreatedSuccess } from './NewUserImport/Success';
import { ReadyToUse } from './NewUserImport/ReadyToUse';
import { ImportSeedPhrase } from './NewUserImport/ImportSeedPhrase';
import { NewUserImportHardware } from './NewUserImport/ImportHardWare';
import { KEYRING_CLASS } from '@/constant';

declare global {
interface Window {
Expand Down Expand Up @@ -129,16 +130,22 @@ const Main = () => {
<NewUserImportGnosisAddress />
</Route>

<Route exact path="/new-user/import/ledger">
<NewUserImportLedger />
<Route exact path="/new-user/import/seed-phrase">
<ImportSeedPhrase />
</Route>

<Route exact path="/new-user/import/keystone">
<NewUserImportKeystone />
<Route
exact
path={`/new-user/import/hardware/${KEYRING_CLASS.HARDWARE.LEDGER}`}
>
<NewUserImportLedger />
</Route>

<Route exact path="/new-user/import/seed-phrase">
<ImportSeedPhrase />
<Route
exact
path={`/new-user/import/hardware/${KEYRING_CLASS.HARDWARE.KEYSTONE}`}
>
<NewUserImportKeystone />
</Route>

<Route exact path="/new-user/import/hardware/:type">
Expand Down
4 changes: 0 additions & 4 deletions src/ui/views/NewUserImport/ImportList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ export const ImportWalletList = () => {
history.push('/new-user/import/seed-phrase');
break;
case KEYRING_CLASS.HARDWARE.LEDGER:
history.push('/new-user/import/ledger/set-password');
break;
case KEYRING_CLASS.HARDWARE.KEYSTONE:
history.push('/new-user/import/keystone/set-password');
break;
case KEYRING_CLASS.HARDWARE.ONEKEY:
case KEYRING_CLASS.HARDWARE.TREZOR:
case KEYRING_CLASS.HARDWARE.GRIDPLUS:
Expand Down
159 changes: 98 additions & 61 deletions src/ui/views/NewUserImport/ImportPrivateKey.tsx
Original file line number Diff line number Diff line change
@@ -1,87 +1,124 @@
import { Card } from '@/ui/component/NewUserImport';
import { useMemoizedFn } from 'ahooks';
import { Button, Form, Input } from 'antd';
import { useMemoizedFn, useRequest } from 'ahooks';
import { Button, Form, Input, message } from 'antd';
import clsx from 'clsx';
import React from 'react';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useHistory } from 'react-router-dom';
import { useNewUserGuideStore } from './hooks/useNewUserGuideStore';
import { clearClipboard } from '@/ui/utils/clipboard';
import IconSuccess from 'ui/assets/success.svg';
import styled from 'styled-components';
import { useWallet } from '@/ui/utils';

const Container = styled.div`
.ant-input {
border-radius: 8px;
border: 1px solid var(--r-neutral-line, #e0e5ec);
}
.ant-input:focus,
.ant-input-focused {
border-color: var(--r-blue-default, #7084ff);
}
.ant-form-item-has-error .ant-input {
border: 1px solid var(--r-red-default, #e34935);
}
`;

export const NewUserImportPrivateKey = () => {
const { t } = useTranslation();
const { store, setStore, clearStore } = useNewUserGuideStore();
const { setStore, clearStore } = useNewUserGuideStore();
const [value, setValue] = useState('');

const history = useHistory();
const wallet = useWallet();

const [form] = Form.useForm<{
privateKey: string;
}>();

const handleSubmit = useMemoizedFn(() => {
// todo
const { privateKey } = form.getFieldsValue();
if (!privateKey) {
form.setFields([
{
name: 'privateKey',
errors: ['Please input your private key'],
},
]);
return;
}
const handleSubmit = useMemoizedFn(async () => {
const { privateKey } = await form.validateFields();
setStore({
privateKey: privateKey,
});
history.push('/new-user/import/private-key/set-password');
});

const { runAsync: privateKeyValidator, error, loading } = useRequest(
async (_, value: string) => {
if (!value) {
throw new Error('Please input Private key');
}
return wallet.validatePrivateKey(value);
},
{
manual: true,
}
);

return (
<Card
onBack={() => {
history.goBack();
clearStore();
}}
step={1}
className="flex flex-col"
>
<div className="flex-1 mt-[18px]">
<div className="text-r-neutral-title1 text-center text-[20px] font-semibold leading-[24px]">
{t('page.newUserImport.importPrivateKey.title')}
<Container>
<Card
onBack={() => {
history.goBack();
clearStore();
}}
step={1}
className="flex flex-col"
>
<div className="flex-1 mt-[18px]">
<div className="text-r-neutral-title1 text-center text-[20px] font-semibold leading-[24px]">
{t('page.newUserImport.importPrivateKey.title')}
</div>
<Form form={form} className="mt-[20px]">
<Form.Item
name="privateKey"
rules={[
{
validator: privateKeyValidator,
},
]}
>
<Input
className="h-[52px]"
type="password"
autoFocus
spellCheck={false}
placeholder="input private key"
onChange={(e) => {
setValue(e.target.value);
}}
onPaste={() => {
clearClipboard();
message.success({
icon: (
<img src={IconSuccess} className="icon icon-success" />
),
content: t('page.newAddress.seedPhrase.pastedAndClear'),
duration: 2,
});
}}
/>
</Form.Item>
</Form>
</div>
<Form
form={form}
className="mt-[20px]"
initialValues={{
privateKey: store.privateKey,
}}
>
<Form.Item
name="privateKey"
rules={[
{
required: true,
},
]}
>
<Input
className="h-[52px] border-[1px] border-rabby-blue-default border-solid"
type="password"
/>
</Form.Item>
</Form>
</div>

<Button
onClick={handleSubmit}
block
type="primary"
className={clsx(
'mt-[48px] h-[56px] shadow-none rounded-[8px]',
'text-[17px] font-medium'
)}
>
{t('global.Confirm')}
</Button>
</Card>
<Button
onClick={handleSubmit}
block
type="primary"
disabled={!!error || loading || !value}
className={clsx(
'mt-[48px] h-[56px] shadow-none rounded-[8px]',
'text-[17px] font-medium'
)}
>
{t('global.Confirm')}
</Button>
</Card>
</Container>
);
};
Loading

0 comments on commit 97d59b3

Please sign in to comment.