Cleanup AddContract with store (#3981)

* Splits (WIP)

* Expand getters & setters

* Initial abi type set

* Expand

* Don't rely on passed api

* Store tests in place

* Allow RadioButtons to accept MobX arrays

* Fixes for manual testing
This commit is contained in:
Jaco Greeff
2016-12-28 18:09:54 +01:00
committed by Gav Wood
parent 7e600b5a82
commit 8677c3b91f
9 changed files with 634 additions and 180 deletions

View File

@@ -16,6 +16,13 @@
import { PropTypes } from 'react';
export function arrayOrObjectProptype () {
return PropTypes.oneOfType([
PropTypes.array,
PropTypes.object
]);
}
export function nullableProptype (type) {
return PropTypes.oneOfType([
PropTypes.oneOf([ null ]),

View File

@@ -35,21 +35,21 @@ export const ERRORS = {
gasBlockLimit: 'the transaction execution will exceed the block gas limit'
};
export function validateAbi (abi, api) {
export function validateAbi (abi) {
let abiError = null;
let abiParsed = null;
try {
abiParsed = JSON.parse(abi);
if (!api.util.isArray(abiParsed)) {
if (!util.isArray(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) || isAbiFallback(o))
.map((o) => isValidAbiEvent(o) || isValidAbiFunction(o) || isAbiFallback(o))
.findIndex((valid) => !valid);
if (invalidIndex !== -1) {
@@ -70,13 +70,13 @@ export function validateAbi (abi, api) {
};
}
function isValidAbiFunction (object, api) {
function isValidAbiFunction (object) {
if (!object) {
return false;
}
return ((object.type === 'function' && object.name) || object.type === 'constructor') &&
(object.inputs && api.util.isArray(object.inputs));
(object.inputs && util.isArray(object.inputs));
}
function isAbiFallback (object) {
@@ -87,14 +87,14 @@ function isAbiFallback (object) {
return object.type === 'fallback';
}
function isValidAbiEvent (object, api) {
function isValidAbiEvent (object) {
if (!object) {
return false;
}
return (object.type === 'event') &&
(object.name) &&
(object.inputs && api.util.isArray(object.inputs));
(object.inputs && util.isArray(object.inputs));
}
export function validateAddress (address) {