Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function extractExternal (accountId?: AccountId | string | null): { isExternal: boolean; isHardware: boolean; hardwareType?: string } {
if (!accountId) {
return { isExternal: false, isHardware: false };
}
let publicKey;
try {
publicKey = keyring.decodeAddress(accountId);
} catch (error) {
console.error(error);
return { isExternal: false, isHardware: false };
}
const pair = keyring.getPair(publicKey);
return {
isExternal: !!pair.meta.isExternal,
isHardware: !!pair.meta.isHardware,
hardwareType: pair.meta.hardwareType
};
}
private unlockAccount (accountId: string, password?: string): string | null {
let publicKey;
try {
publicKey = keyring.decodeAddress(accountId);
} catch (error) {
console.error(error);
return 'unable to decode address';
}
const pair = keyring.getPair(publicKey);
if (!pair.isLocked || pair.meta.isInjected || pair.meta.isExternal) {
return null;
}
try {
pair.decodePkcs8(password);
} catch (error) {
console.error(error);
return (value?: string | null): void => {
let isValid = false;
if (value) {
try {
keyring.decodeAddress(value);
isValid = true;
} catch (err) {
console.error(err);
}
}
onChange && onChange({
isValid,
value
});
};
}
private renderAddress (accountId: string | null, media: 'large' | 'medium') {
if (!accountId) {
return null;
}
try {
keyring.decodeAddress(accountId);
} catch (err) {
return null;
}
return (
<div>
</div>
);
}
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) {
(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) {