-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
317 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
Oops, something went wrong.