ghost-portal/packages/ui-keyring/src/address/get.js
Jaco Greeff b11a6981a2
Optimise components (#39)
* ui-react-app -> ui-app

* CopyButton, Input & Password components

* Convert all to use ui-app/{Input, Label}

* Change to PureComponent where we have onChange listeners

* Cleanup layouts

* Swap dropdown components, remove uselexx constructors

* Allow address/account forget

* Bump

* Searching with headers operational

* flex grow/shrink for icon + account add

* Fix balance & transaction display (account/address management)

* Adjust balance layout

* Equalise padding
2018-05-11 18:08:10 +02:00

30 lines
966 B
JavaScript

// Copyright 2017-2018 Jaco Greeff
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
// @flow
import type { KeyringAddress, KeyringJson$Meta, State } from '../types';
import isString from '@polkadot/util/is/string';
import addressDecode from '@polkadot/util-keyring/address/decode';
import addressEncode from '@polkadot/util-keyring/address/encode';
export default function get (state: State, _address: string | Uint8Array): KeyringAddress {
const address = isString(_address)
// flowlint-next-line unclear-type:off
? ((_address: any): string)
: addressEncode(_address);
const publicKey = addressDecode(address);
return {
address: (): string =>
address,
isValid: (): boolean =>
!!state.available.address[address],
publicKey: (): Uint8Array =>
publicKey,
getMeta: (): KeyringJson$Meta =>
state.available.address[address].meta
};
}