ghost-portal/packages/ui-react-app/src/InputAddress/options.js
Jaco Greeff e02b971998
Allow external address input (#34)
* Allow external address input

* Remove hold-over debug log
2018-05-09 17:54:17 +02:00

34 lines
978 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 { KeyringInstance } from '@polkadot/util-keyring/types';
import type { KeyringOptions } from './types';
import testKeyring from '../keyring';
import createItem from './optionItem';
const cached: { [string]: ?KeyringOptions } = {
addresses: null,
accounts: null
};
export default function createOptions (isAddress?: boolean = false, keyring?: KeyringInstance = testKeyring, forceReload: boolean = false): KeyringOptions {
const map = isAddress ? 'addresses' : 'accounts';
if (forceReload || !cached[map]) {
cached[map] = keyring
.getPairs()
.map((pair) => {
const address = pair.address();
const { name } = pair.getMeta();
return createItem(address, name);
});
}
// $FlowFixMe we have checked and set just above
return cached[map];
}