Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected saveName = () => {
const { address, name } = this.state;
const trimmedName = name.trim();
const meta = {
name: trimmedName,
whenEdited: Date.now()
};
// Save only if the name was changed or if it's no empty.
if (trimmedName && address) {
try {
const currentKeyring = keyring.getPair(address);
currentKeyring && keyring.saveAccountMeta(currentKeyring, meta);
} catch (error) {
keyring.saveAddress(address, meta);
}
this.setState({ isEditingName: false });
}
}
protected saveName = (): void => {
const { address, name } = this.state;
const trimmedName = name.trim();
const meta = {
name: trimmedName,
whenEdited: Date.now()
};
// Save only if the name was changed or if it's no empty.
if (trimmedName && address) {
try {
const currentKeyring = keyring.getPair(address);
currentKeyring && keyring.saveAccountMeta(currentKeyring, meta);
} catch (error) {
keyring.saveAddress(address, meta);
}
}
this.setState({ isEditingName: false });
}
onCommit = (): void => {
const { onStatusChange, t } = this.props;
const { current, editedName, tags } = this.state;
if (!current) {
return;
}
const status = {
account: current.address(),
action: 'edit'
} as ActionStatus;
try {
keyring.saveAccountMeta(current, {
name: editedName,
tags,
whenEdited: Date.now()
});
status.status = current.getMeta().name === editedName ? 'success' : 'error';
status.message = t('account edited');
} catch (error) {
status.status = 'error';
status.message = error.message;
console.error(error);
}
onStatusChange(status);
const _onGenesisChange = (genesisHash: string | null): void => {
const account = keyring.getPair(address);
account && keyring.saveAccountMeta(account, { ...account.meta, genesisHash });
setGenesisHash(genesisHash);
};
const _onFavorite = (): void => toggleFavorite(address);
const _saveName = (): void => {
toggleEditName();
const meta = { name: accName, whenEdited: Date.now() };
if (address) {
try {
const currentKeyring = keyring.getPair(address);
currentKeyring && keyring.saveAccountMeta(currentKeyring, meta);
} catch (error) {
keyring.saveAddress(address, meta);
}
}
};
const _saveTags = (): void => {
private accountsEdit ({ address, name }: RequestAccountEdit): boolean {
const pair = keyring.getPair(address);
assert(pair, 'Unable to find pair');
keyring.saveAccountMeta(pair, { ...pair.meta, name });
return true;
}