Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private loadAddress (json: KeyringJson, key: string): void {
const { isRecent, whenCreated = 0 } = json.meta;
if (isRecent && (Date.now() - whenCreated) > RECENT_EXPIRY) {
this._store.remove(key);
return;
}
const address = this.encodeAddress(
isHex(json.address)
? hexToU8a(json.address)
// FIXME Just for the transition period (ignoreChecksum)
: this.decodeAddress(json.address, true)
);
const [, hexAddr] = key.split(':');
this.addresses.add(this._store, address, json);
this.rewriteKey(json, key, hexAddr, addressKey);
}
private loadAddress(json: KeyringJson, key: string): void {
const { isRecent, whenCreated = 0 } = json.meta;
if (isRecent && (Date.now() - whenCreated) > RECENT_EXPIRY) {
this._store.remove(key);
return;
}
const address = this.encodeAddress(
isHex(json.address)
? hexToU8a(json.address)
// FIXME Just for the transition period (ignoreChecksum)
: this.decodeAddress(json.address, true)
);
const [, hexAddr] = key.split(':');
this.addresses.add(this._store, address, json);
this.rewriteKey(json, key, hexAddr, addressKey);
}
private static decodeViaValue (def: TypesDef, value?: any): Decoded {
if (value instanceof Enum) {
return Enum.createValue(def, value._index, value.raw);
} else if (isU8a(value)) {
return Enum.createValue(def, value[0], value.subarray(1));
} else if (isNumber(value)) {
return Enum.createValue(def, value);
} else if (isString(value)) {
const _str = value.toString();
return isHex(_str)
? Enum.decodeViaValue(def, hexToU8a(_str))
: Enum.createViaJSON(def, _str);
} else if (isObject(value)) {
const key = Object.keys(value)[0];
return Enum.createViaJSON(def, key, value[key]);
}
// Worst-case scenario, return the first with default
return Enum.createValue(def, 0);
}
function convertResult (result: ArrayBuffer, convertHex?: boolean): Uint8Array {
const data = new Uint8Array(result);
// this converts the input (if detected as hex), vai the hex conversion route
if (convertHex && data[0] === BYTE_STR_0 && data[1] === BYTE_STR_X) {
const hex = u8aToString(data);
if (isHex(hex)) {
return hexToU8a(hex);
}
}
return data;
}
function stateFromValue (value: string): State {
const isValidHex = isHex(value, 256);
const isNumber = !isValidHex && /^\d+$/.test(value);
return {
value,
isValid: isValidHex || isNumber
};
}
function isHexSeed (seed: string): boolean {
return isHex(seed) && seed.length === 66;
}
function isHexSeed (seed: string): boolean {
return isHex(seed) && seed.length === 66;
}
const isValidAddressPolkadotAddress = () => {
try {
encodeAddress(isHex(address) ? hexToU8a(address) : decodeAddress(address));
return true;
} catch (error) {
return false;
}
};
const _onChangeData = (data: string): void => {
const isHexData = isHex(data);
setState({
data,
hash: blake2AsHex(
isHexData
? hexToU8a(data)
: stringToU8a(data),
256
),
isHexData
});
};
const { value } = useParams();
const [stateValue, setStateValue] = useState(value);
useEffect((): void => {
if (value && value !== stateValue) {
setStateValue(value);
} else if (!stateValue && bestNumber) {
setStateValue(bestNumber.toString());
}
}, [bestNumber, value]);
if (!stateValue) {
return null;
}
const Component = isHex(stateValue)
? BlockByHash
: BlockByNumber;
return (
<>
);
}