Adjust parems for Vec<KeyValue> & RuntimeSessionKeys (#6381)

This commit is contained in:
Jaco 2021-10-23 14:52:10 +02:00 committed by GitHub
parent 356237ec0d
commit 2b0a77a61f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 12 deletions

View File

@ -16,19 +16,18 @@ interface StateParam {
}
// eslint-disable-next-line @typescript-eslint/ban-types
export function createParam (hex: string | String, length = -1): StateParam {
export function createParam (hex: string | String, ignoreLength = false): StateParam {
let u8a;
let isValid = false;
try {
u8a = hexToU8a(hex.toString());
isValid = ignoreLength || u8a.length !== 0;
} catch (error) {
u8a = new Uint8Array([]);
}
const isValid = length !== -1
? u8a.length === length
: u8a.length !== 0;
return {
isValid,
u8a: compactAddLength(u8a)
@ -37,8 +36,8 @@ export function createParam (hex: string | String, length = -1): StateParam {
function KeyValue ({ className = '', isDisabled, label, onChange, onEnter, withLabel }: Props): React.ReactElement<Props> {
const [, setIsValid] = useState(false);
const [key, setKey] = useState<StateParam>({ isValid: false, u8a: new Uint8Array([]) });
const [value, setValue] = useState<StateParam>({ isValid: false, u8a: new Uint8Array([]) });
const [key, setKey] = useState<StateParam>(() => ({ isValid: false, u8a: new Uint8Array([]) }));
const [value, setValue] = useState<StateParam>(() => ({ isValid: false, u8a: new Uint8Array([]) }));
useEffect((): void => {
const isValid = key.isValid && value.isValid;
@ -58,7 +57,7 @@ function KeyValue ({ className = '', isDisabled, label, onChange, onEnter, withL
[]
);
const _onChangeValue = useCallback(
(value: string): void => setValue(createParam(value)),
(value: string): void => setValue(createParam(value, true)),
[]
);

View File

@ -37,7 +37,7 @@ function parseFile (raw: Uint8Array): Parsed {
assert(isHex(key) && isHex(value), `Non-hex key/value pair found in ${key.toString()} => ${value.toString()}`);
const encKey = createParam(key);
const encValue = createParam(value);
const encValue = createParam(value, true);
isValid = isValid && encKey.isValid && encValue.isValid;

View File

@ -42,7 +42,7 @@ interface TypeToComponent {
t: string[];
}
const SPECIAL_TYPES = ['AccountId', 'AccountId32', 'AccountIndex', 'Address', 'Balance', 'BalanceOf'];
const SPECIAL_TYPES = ['AccountId', 'AccountId32', 'AccountIndex', 'Address', 'Balance', 'BalanceOf', 'Vec<KeyValue>'];
const componentDef: TypeToComponent[] = [
{ c: Account, t: ['AccountId', 'AccountId32', 'Address', 'LookupSource'] },
@ -54,7 +54,7 @@ const componentDef: TypeToComponent[] = [
{ c: Code, t: ['Code'] },
{ c: DispatchError, t: ['DispatchError'] },
{ c: DispatchResult, t: ['DispatchResult'] },
{ c: Raw, t: ['Raw', 'Keys'] },
{ c: Raw, t: ['Raw', 'RuntimeSessionKeys', 'Keys'] },
{ c: Enum, t: ['Enum'] },
{ c: Hash256, t: ['Hash', 'H256'] },
{ c: Hash160, t: ['H160'] },
@ -90,6 +90,8 @@ function fromDef ({ displayName, info, lookupName, sub, type, typeName }: TypeDe
if (nameOverride && SPECIAL_TYPES.includes(nameOverride)) {
return nameOverride;
} else if (type.endsWith('RuntimeSessionKeys')) {
return 'RuntimeSessionKeys';
}
switch (info) {

View File

@ -90,7 +90,8 @@ function filterProxies (allAccounts: string[], tx: Call | SubmittableExtrinsic<'
return (section === 'sudo' && (method === 'sudo' && findCall(tx.args[0] as Call).section === 'balances')) ||
(section === 'utility' && (method === 'batch' && checkCalls(address, tx.args[0] as Vec<Call>)));
default:
return false;
// any unknown proxy types apply to all - leave it to the user to filter
return true;
}
})
.map(([address]) => address);