Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: website newaccount page #862

Open
wants to merge 5 commits into
base: mainnet
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 68 additions & 74 deletions website/src/tabs/account/NewAccount.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,91 +5,85 @@ import { useAleoWASM } from "../../aleo-wasm-hook";

export const NewAccount = () => {
const [account, setAccount] = useState(null);
const [loading, setLoading] = useState(false);
const [aleo] = useAleoWASM();
const [aleo, loading] = useAleoWASM();
const isExistAccount = account !== null;
const privateKey = isExistAccount ? account.to_string() : "";
const viewKey = isExistAccount ? account.to_view_key().to_string() : "";
const address = isExistAccount ? account.to_address().to_string() : "";

const generateAccount = async () => {
setLoading(true);
setTimeout(() => {
setAccount(new aleo.PrivateKey());
setLoading(false);
}, 25);
const layout = { labelCol: { span: 3 }, wrapperCol: { span: 21 } };

const generateAccount = () => {
// when user are able to see button, it means aleo is already loaded
setAccount(new aleo.PrivateKey());
};

const clear = () => {
setAccount(null);
};

const privateKey = () => (account !== null ? account.to_string() : "");
const viewKey = () =>
account !== null ? account.to_view_key().to_string() : "";
const address = () =>
account !== null ? account.to_address().to_string() : "";

const layout = { labelCol: { span: 3 }, wrapperCol: { span: 21 } };

if (aleo !== null) {
return (
<Card
title="Create a New Account"
style={{ width: "100%" }}
>
<Row justify="center">
<Col>
<Button
type="primary"
size="large"
onClick={generateAccount}
loading={!!loading}
>
Generate
</Button>
</Col>
<Col offset="1">
<Button size="large" onClick={clear}>
Clear
</Button>
</Col>
</Row>
{account && (
<Form {...layout}>
<Divider />
<Form.Item label="Private Key" colon={false}>
<Input
size="large"
placeholder="Private Key"
value={privateKey()}
addonAfter={<CopyButton data={privateKey()} />}
disabled
/>
</Form.Item>
<Form.Item label="View Key" colon={false}>
<Input
size="large"
placeholder="View Key"
value={viewKey()}
addonAfter={<CopyButton data={viewKey()} />}
disabled
/>
</Form.Item>
<Form.Item label="Address" colon={false}>
<Input
size="large"
placeholder="Address"
value={address()}
addonAfter={<CopyButton data={address()} />}
disabled
/>
</Form.Item>
</Form>
)}
</Card>
);
} else {
if (loading) {
return (
<h3>
<center>Loading...</center>
</h3>
);
}

return (
<Card
title="Create a New Account"
style={{ width: "100%" }}
>
<Row justify="center">
<Col>
<Button
type="primary"
size="large"
onClick={generateAccount}
loading={!!loading}
>
Generate
</Button>
</Col>
<Col offset="1">
<Button size="large" onClick={clear}>
Clear
</Button>
</Col>
</Row>
{account && (
<Form {...layout}>
<Divider />
<Form.Item label="Private Key" colon={false}>
<Input
size="large"
placeholder="Private Key"
value={privateKey}
addonAfter={<CopyButton data={privateKey} />}
disabled
/>
</Form.Item>
<Form.Item label="View Key" colon={false}>
<Input
size="large"
placeholder="View Key"
value={viewKey}
addonAfter={<CopyButton data={viewKey} />}
disabled
/>
</Form.Item>
<Form.Item label="Address" colon={false}>
<Input
size="large"
placeholder="Address"
value={address}
addonAfter={<CopyButton data={address} />}
disabled
/>
</Form.Item>
</Form>
)}
</Card>
);
};