diff --git a/js/.eslintrc.json b/js/.eslintrc.json index 198750580..686745982 100644 --- a/js/.eslintrc.json +++ b/js/.eslintrc.json @@ -11,11 +11,12 @@ "FileReader": true }, "rules": { - "object-curly-spacing": ["error", "always"], - "no-debugger": "error", - "no-alert": "error", + "curly": ["error", "all"], "jsx-quotes": ["error", "prefer-single"], - "react/jsx-curly-spacing": ["error", "always"], - "object-property-newline": 0 + "no-alert": "error", + "no-debugger": "error", + "object-curly-spacing": ["error", "always"], + "object-property-newline": 0, + "react/jsx-curly-spacing": ["error", "always"] } } diff --git a/js/src/contracts/badgereg.js b/js/src/contracts/badgereg.js index 8075f456e..b3d949fed 100644 --- a/js/src/contracts/badgereg.js +++ b/js/src/contracts/badgereg.js @@ -32,7 +32,8 @@ export default class BadgeReg { } certifierCount () { - return this._registry.getContract('badgereg') + return this._registry + .getContract('badgereg') .then((badgeReg) => { return badgeReg.instance.badgeCount.call({}, []) .then((count) => count.valueOf()); @@ -43,7 +44,9 @@ export default class BadgeReg { if (this.certifiers[id]) { return Promise.resolve(this.certifiers[id]); } - return this._registry.getContract('badgereg') + + return this._registry + .getContract('badgereg') .then((badgeReg) => { return badgeReg.instance.badge.call({}, [ id ]); }) @@ -56,6 +59,7 @@ export default class BadgeReg { name = name === ZERO32 ? null : hex2Ascii(name); + return this.fetchMeta(id) .then(({ title, icon }) => { const data = { address, id, name, title, icon }; @@ -66,7 +70,8 @@ export default class BadgeReg { } fetchMeta (id) { - return this._registry.getContract('badgereg') + return this._registry + .getContract('badgereg') .then((badgeReg) => { return Promise.all([ badgeReg.instance.meta.call({}, [id, 'TITLE']), @@ -76,7 +81,11 @@ export default class BadgeReg { .then(([ title, icon ]) => { title = bytesToHex(title); title = title === ZERO32 ? null : hex2Ascii(title); - if (bytesToHex(icon) === ZERO32) icon = null; + + if (bytesToHex(icon) === ZERO32) { + icon = null; + } + return { title, icon }; }); } @@ -85,6 +94,7 @@ export default class BadgeReg { if (!this.contracts[certifier]) { this.contracts[certifier] = this._api.newContract(ABI, certifier); } + const contract = this.contracts[certifier]; return contract.instance.certified.call({}, [address]); diff --git a/js/src/dapps/registry/Events/actions.js b/js/src/dapps/registry/Events/actions.js index aa48947e8..38a61bf12 100644 --- a/js/src/dapps/registry/Events/actions.js +++ b/js/src/dapps/registry/Events/actions.js @@ -25,7 +25,11 @@ export const event = (name, event) => ({ type: 'events event', name, event }); export const subscribe = (name, from = 0, to = 'pending') => (dispatch, getState) => { const { contract } = getState(); - if (!contract) return; + + if (!contract) { + return; + } + const opt = { fromBlock: from, toBlock: to, limit: 50 }; dispatch(start(name, from, to)); @@ -70,9 +74,16 @@ export const subscribe = (name, from = 0, to = 'pending') => export const unsubscribe = (name) => (dispatch, getState) => { const state = getState(); - if (!state.contract) return; + + if (!state.contract) { + return; + } + const subscriptions = state.events.subscriptions; - if (!(name in subscriptions) || subscriptions[name] === null) return; + + if (!(name in subscriptions) || subscriptions[name] === null) { + return; + } state.contract .unsubscribe(subscriptions[name]) diff --git a/js/src/dapps/registry/Events/reducers.js b/js/src/dapps/registry/Events/reducers.js index 8bca205ac..70d332fb7 100644 --- a/js/src/dapps/registry/Events/reducers.js +++ b/js/src/dapps/registry/Events/reducers.js @@ -29,10 +29,18 @@ const initialState = { }; const sortEvents = (a, b) => { - if (a.state === 'pending' && b.state !== 'pending') return -1; - if (a.state !== 'pending' && b.state === 'pending') return 1; + if (a.state === 'pending' && b.state !== 'pending') { + return -1; + } else if (a.state !== 'pending' && b.state === 'pending') { + return 1; + } + const d = b.block.minus(a.block).toFixed(0); - if (d === 0) return b.index.minus(a.index).toFixed(0); + + if (d === 0) { + return b.index.minus(a.index).toFixed(0); + } + return d; }; diff --git a/js/src/dapps/registry/Lookup/actions.js b/js/src/dapps/registry/Lookup/actions.js index 7cd1ee57a..8c8434cab 100644 --- a/js/src/dapps/registry/Lookup/actions.js +++ b/js/src/dapps/registry/Lookup/actions.js @@ -26,7 +26,11 @@ export const fail = () => ({ type: 'lookup error' }); export const lookup = (name, key) => (dispatch, getState) => { const { contract } = getState(); - if (!contract) return; + + if (!contract) { + return; + } + const getAddress = contract.functions .find((f) => f.name === 'getAddress'); @@ -36,7 +40,11 @@ export const lookup = (name, key) => (dispatch, getState) => { .then((address) => dispatch(success(address))) .catch((err) => { console.error(`could not lookup ${key} for ${name}`); - if (err) console.error(err.stack); + + if (err) { + console.error(err.stack); + } + dispatch(fail()); }); }; diff --git a/js/src/dapps/registry/Names/actions.js b/js/src/dapps/registry/Names/actions.js index f6ffec729..448f710b1 100644 --- a/js/src/dapps/registry/Names/actions.js +++ b/js/src/dapps/registry/Names/actions.js @@ -31,8 +31,14 @@ export const reserve = (name) => (dispatch, getState) => { const contract = state.contract; const fee = state.fee; - if (!contract || !account) return; - if (alreadyQueued(state.names.queue, 'reserve', name)) return; + if (!contract || !account) { + return; + } + + if (alreadyQueued(state.names.queue, 'reserve', name)) { + return; + } + const reserve = contract.functions.find((f) => f.name === 'reserve'); name = name.toLowerCase(); @@ -61,7 +67,11 @@ export const reserve = (name) => (dispatch, getState) => { } console.error(`could not reserve ${name}`); - if (err) console.error(err.stack); + + if (err) { + console.error(err.stack); + } + dispatch(reserveFail(name)); }); }; @@ -76,8 +86,15 @@ export const drop = (name) => (dispatch, getState) => { const state = getState(); const account = state.accounts.selected; const contract = state.contract; - if (!contract || !account) return; - if (alreadyQueued(state.names.queue, 'drop', name)) return; + + if (!contract || !account) { + return; + } + + if (alreadyQueued(state.names.queue, 'drop', name)) { + return; + } + const drop = contract.functions.find((f) => f.name === 'drop'); name = name.toLowerCase(); @@ -102,7 +119,11 @@ export const drop = (name) => (dispatch, getState) => { } console.error(`could not drop ${name}`); - if (err) console.error(err.stack); + + if (err) { + console.error(err.stack); + } + dispatch(reserveFail(name)); }); }; diff --git a/js/src/dapps/registry/Records/actions.js b/js/src/dapps/registry/Records/actions.js index 8b1407211..cff54d94d 100644 --- a/js/src/dapps/registry/Records/actions.js +++ b/js/src/dapps/registry/Records/actions.js @@ -32,7 +32,11 @@ export const update = (name, key, value) => (dispatch, getState) => { dispatch(success()); }).catch((err) => { console.error(`could not update ${key} record of ${name}`); - if (err) console.error(err.stack); + + if (err) { + console.error(err.stack); + } + dispatch(fail()); }); }; diff --git a/js/src/dapps/registry/actions.js b/js/src/dapps/registry/actions.js index 0526802b9..391953c22 100644 --- a/js/src/dapps/registry/actions.js +++ b/js/src/dapps/registry/actions.js @@ -38,19 +38,29 @@ export const fetchContract = () => (dispatch) => }) .catch((err) => { console.error('could not fetch contract'); - if (err) console.error(err.stack); + + if (err) { + console.error(err.stack); + } }); export const setFee = (fee) => ({ type: 'set fee', fee }); const fetchFee = () => (dispatch, getState) => { const { contract } = getState(); - if (!contract) return; + + if (!contract) { + return; + } + contract.instance.fee.call() .then((fee) => dispatch(setFee(fee))) .catch((err) => { console.error('could not fetch fee'); - if (err) console.error(err.stack); + + if (err) { + console.error(err.stack); + } }); }; @@ -58,11 +68,18 @@ export const setOwner = (owner) => ({ type: 'set owner', owner }); export const fetchOwner = () => (dispatch, getState) => { const { contract } = getState(); - if (!contract) return; + + if (!contract) { + return; + } + contract.instance.owner.call() .then((owner) => dispatch(setOwner(owner))) .catch((err) => { console.error('could not fetch owner'); - if (err) console.error(err.stack); + + if (err) { + console.error(err.stack); + } }); }; diff --git a/js/src/dapps/tokenreg/Actions/Query/query.js b/js/src/dapps/tokenreg/Actions/Query/query.js index fd680769c..452b387a5 100644 --- a/js/src/dapps/tokenreg/Actions/Query/query.js +++ b/js/src/dapps/tokenreg/Actions/Query/query.js @@ -173,20 +173,26 @@ export default class QueryAction extends Component { onQueryKeyChange = (event, index, queryKey) => { this.setState({ queryKey, - form: { valid: false, value: '' } + form: { + valid: false, + value: '' + } }); } onChange = (valid, value) => { this.setState({ form: { - valid, value + valid, + value } }); } onQuery = () => { - if (!this.state.form.valid) return; + if (!this.state.form.valid) { + return; + } const { queryKey, form } = this.state; diff --git a/js/src/dapps/tokenreg/Actions/Register/register.js b/js/src/dapps/tokenreg/Actions/Register/register.js index 54df411c7..ec1199f3d 100644 --- a/js/src/dapps/tokenreg/Actions/Register/register.js +++ b/js/src/dapps/tokenreg/Actions/Register/register.js @@ -128,8 +128,12 @@ export default class RegisterAction extends Component { renderContent () { const { error, complete } = this.props; - if (error) return this.renderError(); - if (complete) return this.renderComplete(); + if (error) { + return this.renderError(); + } else if (complete) { + return this.renderComplete(); + } + return this.renderForm(); } diff --git a/js/src/dapps/tokenreg/Chip/chip.js b/js/src/dapps/tokenreg/Chip/chip.js index f26f9a0c6..b5407af11 100644 --- a/js/src/dapps/tokenreg/Chip/chip.js +++ b/js/src/dapps/tokenreg/Chip/chip.js @@ -57,7 +57,9 @@ export default class CustomChip extends Component { } renderIcon (isAddress, address) { - if (!isAddress) return; + if (!isAddress) { + return; + } return ( @@ -83,7 +85,9 @@ export default class InputText extends Component { } renderIsValid () { - if (this.state.loading || !this.state.valid) return; + if (this.state.loading || !this.state.valid) { + return; + } return (
@@ -120,8 +124,13 @@ export default class InputText extends Component { } onKeyDown = (event) => { - if (!this.props.onEnter) return; - if (event.keyCode !== 13) return; + if (!this.props.onEnter) { + return; + } + + if (event.keyCode !== 13) { + return; + } this.props.onEnter(); } diff --git a/js/src/dapps/tokenreg/Inputs/validation.js b/js/src/dapps/tokenreg/Inputs/validation.js index 3b14bd0a4..cbc4e2a89 100644 --- a/js/src/dapps/tokenreg/Inputs/validation.js +++ b/js/src/dapps/tokenreg/Inputs/validation.js @@ -71,9 +71,14 @@ const validateAddress = (address) => { const validateTokenAddress = (address, contract, simple) => { const addressValidation = validateAddress(address); - if (!addressValidation.valid) return addressValidation; - if (simple) return addressValidation; + if (!addressValidation.valid) { + return addressValidation; + } + + if (simple) { + return addressValidation; + } return getTokenTotalSupply(address) .then(balance => { @@ -96,7 +101,10 @@ const validateTokenAddress = (address, contract, simple) => { }); }) .then((result) => { - if (result) return result; + if (result) { + return result; + } + return addressValidation; }); }; @@ -130,7 +138,10 @@ const validateTLA = (tla, contract, simple) => { } }) .then((result) => { - if (result) return result; + if (result) { + return result; + } + return { value: fTLA, error: null, @@ -215,16 +226,28 @@ const validateURL = (string) => { }; export const validate = (value, type, contract) => { - if (type === ADDRESS_TYPE) return validateAddress(value); - if (type === TOKEN_ADDRESS_TYPE) return validateTokenAddress(value, contract); - if (type === SIMPLE_TOKEN_ADDRESS_TYPE) return validateTokenAddress(value, contract, true); - if (type === TLA_TYPE) return validateTLA(value, contract); - if (type === SIMPLE_TLA_TYPE) return validateTLA(value, contract, true); - if (type === UINT_TYPE) return validateUint(value); - if (type === DECIMAL_TYPE) return validateDecimal(value); - if (type === STRING_TYPE) return validateString(value); - if (type === HEX_TYPE) return validateHex(value); - if (type === URL_TYPE) return validateURL(value); - - return { valid: true, error: null }; + switch (type) { + case ADDRESS_TYPE: + return validateAddress(value); + case TOKEN_ADDRESS_TYPE: + return validateTokenAddress(value, contract); + case SIMPLE_TOKEN_ADDRESS_TYPE: + return validateTokenAddress(value, contract, true); + case TLA_TYPE: + return validateTLA(value, contract); + case SIMPLE_TLA_TYPE: + return validateTLA(value, contract, true); + case UINT_TYPE: + return validateUint(value); + case DECIMAL_TYPE: + return validateDecimal(value); + case STRING_TYPE: + return validateString(value); + case HEX_TYPE: + return validateHex(value); + case URL_TYPE: + return validateURL(value); + default: + return { valid: true, error: null }; + } }; diff --git a/js/src/dapps/tokenreg/Status/actions.js b/js/src/dapps/tokenreg/Status/actions.js index 057a44e65..e23afbbc1 100644 --- a/js/src/dapps/tokenreg/Status/actions.js +++ b/js/src/dapps/tokenreg/Status/actions.js @@ -119,7 +119,9 @@ export const subscribeEvents = () => (dispatch, getState) => { return; } - if (!logs || logs.length === 0) return; + if (!logs || logs.length === 0) { + return; + } logs.forEach(log => { const event = log.event; diff --git a/js/src/dapps/tokenreg/Tokens/Token/add-meta.js b/js/src/dapps/tokenreg/Tokens/Token/add-meta.js index 60be410e9..3dc4bdbe1 100644 --- a/js/src/dapps/tokenreg/Tokens/Token/add-meta.js +++ b/js/src/dapps/tokenreg/Tokens/Token/add-meta.js @@ -46,7 +46,9 @@ export default class AddMeta extends Component { state = initState; render () { - if (!this.props.isTokenOwner) return null; + if (!this.props.isTokenOwner) { + return null; + } return (
- -
); + return ( +
+ +
+ ); } - if (!meta) return; + if (!meta) { + return null; + } const metaData = metaDataKeys.find(m => m.value === meta.query); if (!meta.value) { - return (
-

- No - { metaData.label.toLowerCase() } - meta-data... -

-
); + return ( +
+

+ No + { metaData.label.toLowerCase() } + meta-data... +

+
+ ); } if (meta.query === 'IMG') { const imageHash = meta.value.replace(/^0x/, ''); - return (
-

- - { metaData.label } - meta-data: -

-
- + return ( +
+

+ + { metaData.label } + meta-data: +

+
+ +
-
); + ); } if (meta.query === 'A') { const address = meta.value.slice(0, 42); - return (
+ return ( +
+

+ + { metaData.label } + meta-data: +

+

+ { api.util.toChecksumAddress(address) } +

+
+ ); + } + + return ( +

{ metaData.label } meta-data:

-

- { api.util.toChecksumAddress(address) } -

-
); - } - - return (
-

- - { metaData.label } - meta-data: -

-

{ meta.value }

-
); +

{ meta.value }

+
+ ); } renderMetaPending () { const isMetaPending = this.props.metaPending; - if (!isMetaPending) return; - return (
-

- Meta-Data pending... -

-
); + if (!isMetaPending) { + return null; + } + + return ( +
+

+ Meta-Data pending... +

+
+ ); } renderMetaMined () { const isMetaMined = this.props.metaMined; - if (!isMetaMined) return; - return (
-

- Meta-Data saved on the blockchain! -

-
); + if (!isMetaMined) { + return null; + } + + return ( +
+

+ Meta-Data saved on the blockchain! +

+
+ ); } onUnregister = () => { diff --git a/js/src/modals/Verification/store.js b/js/src/modals/Verification/store.js index 692fc58a3..9d6680231 100644 --- a/js/src/modals/Verification/store.js +++ b/js/src/modals/Verification/store.js @@ -113,7 +113,10 @@ export default class VerificationStore { @action setCode = (code) => { const { contract, account } = this; - if (!contract || !account || code.length === 0) return; + + if (!contract || !account || code.length === 0) { + return; + } const confirm = contract.functions.find((fn) => fn.name === 'confirm'); const options = { from: account }; diff --git a/js/src/redux/providers/certifications/middleware.js b/js/src/redux/providers/certifications/middleware.js index 0bd2e5157..010611274 100644 --- a/js/src/redux/providers/certifications/middleware.js +++ b/js/src/redux/providers/certifications/middleware.js @@ -94,8 +94,12 @@ export default class CertificationsMiddleware { console.error('Failed to fetch new certifier events:', err); }); }, 10 * 1000, true); + api.subscribe('eth_blockNumber', (err) => { - if (err) return; + if (err) { + return; + } + fetchChanges(); }); diff --git a/js/src/views/Accounts/List/list.js b/js/src/views/Accounts/List/list.js index d5bdd9662..2bd7fadc1 100644 --- a/js/src/views/Accounts/List/list.js +++ b/js/src/views/Accounts/List/list.js @@ -134,16 +134,24 @@ class List extends Component { const balanceA = balances[accountA.address]; const balanceB = balances[accountB.address]; - if (!balanceA && !balanceB) return 0; - if (balanceA && !balanceB) return -1; - if (!balanceA && balanceB) return 1; + if (!balanceA && !balanceB) { + return 0; + } else if (balanceA && !balanceB) { + return -1; + } else if (!balanceA && balanceB) { + return 1; + } const ethA = balanceA.tokens.find(token => token.token.tag.toLowerCase() === 'eth'); const ethB = balanceB.tokens.find(token => token.token.tag.toLowerCase() === 'eth'); - if (!ethA && !ethB) return 0; - if (ethA && !ethB) return -1; - if (!ethA && ethB) return 1; + if (!ethA && !ethB) { + return 0; + } else if (ethA && !ethB) { + return -1; + } else if (!ethA && ethB) { + return 1; + } return -1 * ethA.value.comparedTo(ethB.value); } @@ -159,9 +167,13 @@ class List extends Component { .sort() .join(''); - if (!tagsA && !tagsB) return 0; - if (tagsA && !tagsB) return -1; - if (!tagsA && tagsB) return 1; + if (!tagsA && !tagsB) { + return 0; + } else if (tagsA && !tagsB) { + return -1; + } else if (!tagsA && tagsB) { + return 1; + } return tagsA.localeCompare(tagsB); } diff --git a/js/src/views/Contract/Queries/inputQuery.js b/js/src/views/Contract/Queries/inputQuery.js index 9d3cf279d..f1be803ae 100644 --- a/js/src/views/Contract/Queries/inputQuery.js +++ b/js/src/views/Contract/Queries/inputQuery.js @@ -95,7 +95,10 @@ export default class InputQuery extends Component { return (); } - if (!results || results.length < 1) return null; + if (!results || results.length < 1) { + return null; + } + return outputs .map((out, index) => ({ name: out.name, @@ -181,7 +184,9 @@ export default class InputQuery extends Component { } renderValue (value) { - if (!value) return 'no data'; + if (!value) { + return 'no data'; + } const { api } = this.context;