ghost-keychain/packages/extension-ui/src/Popup/Create.tsx
Jaco Greeff 4945417982
Mobile signer support (via Qr) (#134)
* Add typings to messages

* Fix eslint (after merge)

* Mobile signer support (via Qr)

* Bump common

* Pass through genesisHash

* Ok, well, it does something... not recognized

* Bump ui

* Exclude build from lint

* **

* Display accounts with prefix from genesisHash

* Adapth for object via scan interface

* Bump deps

* Split address recoding

* Cleanup decoding readability

* Display chain affinity overlay

* -1 prefix dropdown description

* Add generator command

* Fix TypeScript error

* Lint

* Consistent naming

* Better promise error handling

* Small consistency updates

* Constraint handle typings as much as tsc will allow

* State naming

* Typo in cheain descriptions

* Add signature handler (unused)

* e2e roundtrip

* remove (useless) dev 0.5.1 chain

* Insert ActionBar

* Revert to empty Props interfaces

* SeedLengths type

* Add type to transport subscription message

* nit

* Typecheck passing callback to sendMessage when none expected

* Bump api

* Small lint fixes

* Bump  api

* Not sure it works... but linting passes

* Split public/private

* Alphabetical

* Don't show button on no media

* Remove unneeded resolve - NOT hacking around linting

* Pass edited name through to accounts component

* genesisHash alignments

* Remove KeyringJson

* SignRequest with account

* Align with master naming

* Some manual merges

* Manual (small) conflict resolution

* Fixup extension account mapping

* Remove ununsed messages (less code = better)

* Update comment around generation

* Add copy-to-apps script (debugging)
2019-09-06 13:03:55 +02:00

67 lines
2.0 KiB
TypeScript

// Copyright 2019 @polkadot/extension-ui authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import React, { useContext, useEffect, useState } from 'react';
import { ActionContext, Address, Button, Header, Loading, TextArea } from '../components';
import { createAccountSuri, createSeed } from '../messaging';
import { Back, Name, Password } from '../partials';
type Props = {}
export default function Create (): React.ReactElement<Props> {
const onAction = useContext(ActionContext);
const [account, setAccount] = useState<null | { address: string; seed: string }>(null);
const [name, setName] = useState<string | null>(null);
const [password, setPassword] = useState<string | null>(null);
useEffect((): void => {
createSeed()
.then(setAccount)
.catch((error: Error) => console.error(error));
}, []);
// FIXME Duplicated between here and Import.tsx
const _onCreate = (): void => {
// this should always be the case
if (name && password && account) {
createAccountSuri(name, password, account.seed)
.then((): void => onAction('/'))
.catch((error: Error) => console.error(error));
}
};
return (
<div>
<Header label='create account' />
<Back />
<Loading>{account && (
<>
<TextArea
isReadOnly
label='generated 12-word mnemonic seed'
value={account.seed}
/>
<Name
isFocussed
onChange={setName}
/>
{name && <Password onChange={setPassword} />}
{name && password && (
<Address
address={account.address}
name={name}
>
<Button
label='Add the account with the generated seed'
onClick={_onCreate}
/>
</Address>
)}
</>
)}</Loading>
</div>
);
}