Default contract type on UI (#3310)

* Added Token and Wallet ABI in Watch Contract #3126

* Improved ABI Validator #3281

* Select contract type on first screen #3126

* Added types decsription

* Add ABI type to Contract metadata // Custom as default type #3310
This commit is contained in:
Nicolas Gotchac
2016-11-10 11:27:35 +01:00
committed by Gav Wood
parent 2f98169539
commit 67ac05ef39
6 changed files with 227 additions and 33 deletions

View File

@@ -38,10 +38,22 @@ export function validateAbi (abi, api) {
abiParsed = JSON.parse(abi);
if (!api.util.isArray(abiParsed) || !abiParsed.length) {
abiError = ERRORS.inavlidAbi;
} else {
abi = JSON.stringify(abiParsed);
abiError = ERRORS.invalidAbi;
return { abi, abiError, abiParsed };
}
// Validate each elements of the Array
const invalidIndex = abiParsed
.map((o) => isValidAbiEvent(o, api) || isValidAbiFunction(o, api))
.findIndex((valid) => !valid);
if (invalidIndex !== -1) {
const invalid = abiParsed[invalidIndex];
abiError = `${ERRORS.invalidAbi} (#${invalidIndex}: ${invalid.name || invalid.type})`;
return { abi, abiError, abiParsed };
}
abi = JSON.stringify(abiParsed);
} catch (error) {
abiError = ERRORS.invalidAbi;
}
@@ -53,6 +65,25 @@ export function validateAbi (abi, api) {
};
}
function isValidAbiFunction (object, api) {
if (!object) {
return false;
}
return ((object.type === 'function' && object.name) || object.type === 'constructor') &&
(object.inputs && api.util.isArray(object.inputs));
}
function isValidAbiEvent (object, api) {
if (!object) {
return false;
}
return (object.type === 'event') &&
(object.name) &&
(object.inputs && api.util.isArray(object.inputs));
}
export function validateAddress (address) {
let addressError = null;