ghost-keychain/packages/extension-ui/src/Popup/Accounts/Account.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
1.7 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 { AccountJson } from '@polkadot/extension/background/types';
import React, { useContext, useState } from 'react';
import styled from 'styled-components';
import { ActionBar, ActionContext, Address, Link } from '../../components';
import { editAccount } from '../../messaging';
import { Name } from '../../partials';
interface Props extends AccountJson {
address: string;
className?: string;
}
function Account ({ address, className }: Props): React.ReactElement<Props> {
const onAction = useContext(ActionContext);
const [isEditing, setEditing] = useState(false);
const [editedName, setName] = useState<string | null>(null);
const _toggleEdit = (): void => setEditing(!isEditing);
const _saveChanges = (): void => {
if (editedName && editedName !== name) {
editAccount(address, editedName)
.then((): void => onAction())
.catch((error: Error) => console.error(error));
}
_toggleEdit();
};
return (
<Address
address={address}
className={className}
name={editedName}
>
{isEditing && (
<Name
address={address}
className='edit-name'
isFocussed
label={null}
onBlur={_saveChanges}
onChange={setName}
/>
)}
<ActionBar>
<Link onClick={_toggleEdit}>Edit</Link>
<Link to={`/account/forget/${address}`}>Forget</Link>
</ActionBar>
</Address>
);
}
export default styled(Account)`
.edit-name {
left: 3rem;
position: absolute;
right: 0.75rem;
top: -0.5rem;
}
`;