Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function valueToText (type: string, value: any, swallowError = true, contentShorten = true): React.ReactNode {
if (isNull(value) || isUndefined(value)) {
return div({}, '');
}
// FIXME dont' even ask, nested ?: ... really?
return div(
{},
['Bytes', 'Raw', 'Option', 'Keys'].includes(type)
? u8aToHex(value.toU8a(true), contentShorten ? 512 : -1)
: (
// HACK Handle Keys as hex-only (this should go away once the node value is
// consistently swapped to `Bytes`)
type === 'Vec<(ValidatorId,Keys)>'
? JSON.stringify(
(value as ([ValidatorId, Keys])[]).map(([validator, keys]): [string, string] => [
validator.toString(), keys.toHex()
])
private stopInformant (): void {
if (!isUndefined(this.informantId)) {
clearInterval(this.informantId);
}
this.informantId = undefined;
}
(defaultValue.value || []).forEach((value: RawParam, index: number): void => {
values.push(
isUndefined(value) || isUndefined(value.isValid)
? { isValid: !isUndefined(value), value }
: value
);
params.push(generateParam(subType, index));
});
private static decodeVote (registry: Registry, value?: InputTypes): Uint8Array {
if (isUndefined(value)) {
return Vote.decodeVoteBool(false);
} else if (value instanceof Boolean || isBoolean(value)) {
return Vote.decodeVoteBool(new Bool(registry, value).isTrue);
} else if (isNumber(value)) {
return Vote.decodeVoteBool(value < 0);
} else if (isU8a(value)) {
return Vote.decodeVoteU8a(value);
}
const vote = new Bool(registry, value.aye).isTrue ? AYE_BITS : NAY_BITS;
const conviction = createType(registry, 'Conviction', isUndefined(value.conviction) ? DEF_CONV : value.conviction);
return new Uint8Array([vote | conviction.index]);
}
(isValid: boolean, value): boolean => (
isValid &&
!isUndefined(value) &&
!isUndefined(value.value) &&
value.isValid),
true
private static createValue (def: TypesDef, index: number = 0, value?: any): Decoded {
const Clazz = Object.values(def)[index];
assert(!isUndefined(Clazz), `Unable to create Enum via index ${index}, in ${Object.keys(def).join(', ')}`);
return {
index,
value: new Clazz(value)
};
}
private getParams (props: any): Array {
const paramValue = props[paramName];
if (atProp) {
at = props[atProp];
}
return isUndefined(paramValue)
? params
: params.concat(
Array.isArray(paramValue)
? paramValue
: [paramValue]
);
}
function getTypeIdPrimitive (_project: InkProject, idPrim: MtTypeIdPrimitive): InterfaceTypes {
const primitive = PRIMITIVES[idPrim.index];
assert(!isUndefined(primitive), `getInkPrimitive:: Unable to convert ${idPrim} to primitive`);
return primitive;
}
export default function compareArray (a: any[], b?: any): boolean {
if (Array.isArray(b)) {
return (a.length === b.length) && isUndefined(
a.find((value, index): boolean =>
isFunction(value.eq)
? !value.eq(b[index])
: value !== b[index]
)
);
}
return false;
}
private _createEncoded (name: string, method: Partial & ContractABIMethodBase): ContractABIFn {
const args: Array = method.args.map(({ name, type }) => ({
name: stringCamelCase(name),
type: this._convertType(type)
}));
const Clazz = this._createClazz(args, isUndefined(method.selector) ? {} : { __selector: 'u32' });
const baseStruct: { [index: string]: any } = { __selector: method.selector };
const encoder = (...params: Array): Uint8Array => {
assert(params.length === args.length, `Expected ${args.length} arguments to contract ${name}, found ${params.length}`);
const u8a = new Clazz(
args.reduce((mapped, { name }, index) => {
mapped[name] = params[index];
return mapped;
}, { ...baseStruct })
).toU8a();
return Compact.addLengthPrefix(u8a);
};
const fn = (encoder as ContractABIFn);