Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemaster committed Sep 18, 2015
2 parents 28e0082 + f00b431 commit e3c22ec
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
3 changes: 3 additions & 0 deletions web/app/components/Blockchain/LinkToAccountById.jsx
Expand Up @@ -10,6 +10,9 @@ class LinkToAccountById extends React.Component {
}
render() {
let account_name = this.props.account.get("name");
if (!account_name) {
return null;
}
return <Link to="account-overview" params={{account_name}}>{account_name}</Link>
}
}
Expand Down
31 changes: 26 additions & 5 deletions web/app/components/Utility/ChainTypes.js
@@ -1,5 +1,6 @@
import utils from "common/utils";
import Immutable from "immutable";
import {object_type} from "chain/chain_types";

function createChainableTypeChecker(validate) {
function checkType(isRequired, props, propName, componentName, location) {
Expand Down Expand Up @@ -46,7 +47,7 @@ function keyChecker(props, propName, componentName, location) {
if (typeof value === "string") {
// TODO: check if it's valid key
// PublicKey.fromPublicKeyString(value)
return null
return null;
} else {
return new Error(`${propName} in ${componentName} should be a key string`);
}
Expand All @@ -60,8 +61,9 @@ function assetChecker(props, propName, componentName, location) {
if (props[propName]) {
let value = props[propName];
if (typeof value === "string") {
// TODO: check if it's valid asset symbol or id
return null
return null;
} else if (typeof value === "object") {
// TODO: check object type (probably we should require an object to be a tcomb structure)
} else {
return new Error(`${propName} of ${value} in ${componentName} should be an asset symbol or id`);
}
Expand All @@ -70,6 +72,26 @@ function assetChecker(props, propName, componentName, location) {
return null;
}

function accountChecker(props, propName, componentName, location) {
componentName = componentName || "ANONYMOUS";
if (props[propName]) {
let value = props[propName];
if (typeof value === "string") {
if (utils.is_object_id(value) && value.split(".")[1] === object_type.account) {
return null;
} else {
return new Error(`${propName} of ${value} in ${componentName} should be an account id`);
}
} else if (typeof value === "object") {
// TODO: check object type (probably we should require an object to be a tcomb structure)
} else {
return new Error(`${propName} of ${value} in ${componentName} should be an account id`);
}
}
// assume all ok
return null;
}

function objectsListChecker(props, propName, componentName, location) {
componentName = componentName || "ANONYMOUS";
if (props[propName]) {
Expand Down Expand Up @@ -98,9 +120,8 @@ function accountsListChecker(props, propName, componentName, location) {
return null;
}


let ChainObject = createChainableTypeChecker(objectIdChecker);
let ChainAccount = createChainableTypeChecker(objectIdChecker);
let ChainAccount = createChainableTypeChecker(accountChecker);
let ChainKeyRefs = createChainableTypeChecker(keyChecker);
let ChainAddressBalances = createChainableTypeChecker(keyChecker);
let ChainAsset = createChainableTypeChecker(assetChecker);
Expand Down

0 comments on commit e3c22ec

Please sign in to comment.