Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function getAddressMeta (address: string, type: KeyringItemType | null = null): KeyringJson$Meta {
let meta: KeyringJson$Meta | undefined;
try {
const pair = keyring.getAddress(address, type);
meta = pair && pair.meta;
} catch (error) {
// we could pass invalid addresses, so it may throw
}
return meta || {};
}
export function findNameByAddress (address: string): string | undefined {
try {
return keyring.getAccount(address).getMeta().name;
} catch (error) {
try {
return keyring.getAddress(address).getMeta().name;
} catch (error) {
// ok, we don't have account or address
return undefined;
}
}
}
function createOption (address: string): Option {
let isRecent: boolean | undefined;
const pair = keyring.getAccount(address);
let name: string | undefined;
if (pair) {
name = pair.meta.name;
} else {
const addr = keyring.getAddress(address);
if (addr) {
name = addr.meta.name;
isRecent = addr.meta.isRecent;
} else {
isRecent = true;
}
}
return createItem(createKeyringItem(address, name), !isRecent);
}
(prevState: State): State => {
let { address = prevState.address, name = prevState.name, tags = prevState.tags } = newState;
let isAddressValid = true;
let isAddressExisting = false;
let newAddress = address;
try {
newAddress = keyring.encodeAddress(
keyring.decodeAddress(address)
);
isAddressValid = keyring.isAvailable(newAddress);
if (!isAddressValid) {
const old = keyring.getAddress(newAddress);
if (old.isValid) {
if (!allowEdit) {
name = old.getMeta().name || name;
}
isAddressExisting = true;
isAddressValid = true;
}
}
} catch (error) {
isAddressValid = false;
}
const isNameValid = !!name;
const _onChangeAddress = (input: string): void => {
let address = '';
let isAddressValid = true;
let isAddressExisting = false;
try {
address = keyring.encodeAddress(
keyring.decodeAddress(input)
);
isAddressValid = keyring.isAvailable(address);
if (!isAddressValid) {
const old = keyring.getAddress(address);
if (old) {
const newName = old.meta.name || name;
isAddressExisting = true;
isAddressValid = true;
setName({ isNameValid: !!(newName || '').trim(), name: newName });
}
}
} catch (error) {
isAddressValid = false;
}
setAddress({ address: address || input, isAddressExisting, isAddressValid });
};
onChangeAddress = (accountId: string): void => {
const current = accountId && keyring.decodeAddress(accountId)
? (keyring.getAddress(accountId) || null)
: null;
this.nextState({ current } as State);
}
useEffect((): void => {
const current = keyring.getAddress(address);
setCurrent(current || null);
setGenesisHash((current && current.meta.genesisHash) || null);
}, []);
const _onGenesisChange = (genesisHash: string | null): void => {
setGenesisHash(genesisHash);
const account = keyring.getAddress(address);
account && keyring.saveAddress(address, { ...account.meta, genesisHash });
setGenesisHash(genesisHash);
};