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 = (): 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 { basePath, onStatusChange, t } = this.props;
const { address, isAddressExisting, name, tags } = this.state;
const status = {
action: 'create'
} as ActionStatus;
try {
keyring.saveAddress(address, { name, tags });
status.account = address;
status.status = address ? 'success' : 'error';
status.message = isAddressExisting
? t('address edited')
: t('address created');
InputAddress.setLastValue('address', address);
} catch (error) {
status.status = 'error';
status.message = error.message;
}
onStatusChange(status);
if (status.status !== 'error') {
const _onCommit = (): void => {
const status = { action: 'create' } as ActionStatus;
if (!isValid) {
return;
}
try {
keyring.saveAddress(address, { name: name.trim(), genesisHash: keyring.genesisHash, tags: [] });
status.account = address;
status.status = address ? 'success' : 'error';
status.message = isAddressExisting
? t('address edited')
: t('address created');
InputAddress.setLastValue('address', address);
} catch (error) {
status.status = 'error';
status.message = error.message;
}
onStatusChange(status);
onClose();
};
const _saveTags = (): void => {
toggleEditTags();
const meta = { tags, whenEdited: Date.now() };
if (address) {
try {
const currentKeyring = keyring.getPair(address);
currentKeyring && keyring.saveAccountMeta(currentKeyring, meta);
} catch (error) {
keyring.saveAddress(address, meta);
}
}
};
const _onForget = (): void => {
const _onGenesisChange = (genesisHash: string | null): void => {
setGenesisHash(genesisHash);
const account = keyring.getAddress(address);
account && keyring.saveAddress(address, { ...account.meta, genesisHash });
setGenesisHash(genesisHash);
};
protected saveTags = () => {
const { address, tags } = this.state;
const meta = {
tags,
whenEdited: Date.now()
};
if (address) {
try {
const currentKeyring = keyring.getPair(address);
currentKeyring && keyring.saveAccountMeta(currentKeyring, meta);
} catch (error) {
keyring.saveAddress(address, meta);
}
this.setState({ isEditingTags: 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.saveAddress(current.address(), {
name: editedName,
tags,
whenEdited: Date.now()
});
status.status = current.getMeta().name === editedName ? 'success' : 'error';
status.message = t('address edited');
} catch (error) {
status.status = 'error';
status.message = error.message;
}
onStatusChange(status);
}