mirror of https://github.com/embarklabs/embark.git
Display error + lint
This commit is contained in:
parent
8cd3ccd5af
commit
788db99a0e
|
@ -143,7 +143,7 @@ export const ensRecord = {
|
|||
export const ENS_RECORDS = createRequestTypes('ENS_RECORDS');
|
||||
export const ensRecords = {
|
||||
post: (subdomain, address) => action(ENS_RECORDS[REQUEST], {subdomain, address}),
|
||||
success: (_record, payload) => action(ENS_RECORDS[SUCCESS], {ensRecords: [{subdomain: payload.subdomain, address: payload.address}]}),
|
||||
success: (record) => action(ENS_RECORDS[SUCCESS], {ensRecords: [record]}),
|
||||
failure: (error) => action(ENS_RECORDS[FAILURE], {error})
|
||||
};
|
||||
|
||||
|
|
|
@ -30,11 +30,10 @@ class EnsRegister extends Component {
|
|||
}
|
||||
|
||||
showResult() {
|
||||
let ensRecord = this.props.ensRecords.find((record) => record.address === this.state.address && record.subdomain === this.state.subdomain);
|
||||
if (ensRecord) {
|
||||
return <Alert type="success">Successfully registered</Alert>;
|
||||
if (this.props.ensErrors) {
|
||||
return <Alert type="danger">An error happened: {this.props.ensErrors}</Alert>;
|
||||
} else {
|
||||
return <Alert type="danger">An error happened</Alert>;
|
||||
return <Alert type="success">Successfully registered</Alert>;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,7 +64,8 @@ class EnsRegister extends Component {
|
|||
|
||||
EnsRegister.propTypes = {
|
||||
register: PropTypes.func,
|
||||
ensRecords: PropTypes.arrayOf(PropTypes.object)
|
||||
ensRecords: PropTypes.arrayOf(PropTypes.object),
|
||||
ensErrors: PropTypes.string
|
||||
};
|
||||
|
||||
export default EnsRegister;
|
||||
|
|
|
@ -6,7 +6,7 @@ import {ensRecord, ensRecords} from "../actions";
|
|||
import EnsRegister from "../components/EnsRegister";
|
||||
import EnsLookup from "../components/EnsLookup";
|
||||
import EnsResolve from "../components/EnsResolve";
|
||||
import {getEnsRecords, isEnsEnabled} from "../reducers/selectors";
|
||||
import {getEnsRecords, isEnsEnabled, getEnsErrors} from "../reducers/selectors";
|
||||
|
||||
class EnsContainer extends Component {
|
||||
|
||||
|
@ -15,7 +15,7 @@ class EnsContainer extends Component {
|
|||
<React.Fragment>
|
||||
<EnsLookup lookup={this.props.lookup} ensRecords={this.props.ensRecords}/>
|
||||
<EnsResolve resolve={this.props.resolve} ensRecords={this.props.ensRecords}/>
|
||||
<EnsRegister register={this.props.register} ensRecords={this.props.ensRecords}/>
|
||||
<EnsRegister register={this.props.register} ensRecords={this.props.ensRecords} ensErrors={this.props.ensErrors}/>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
@ -38,12 +38,14 @@ EnsContainer.propTypes = {
|
|||
resolve: PropTypes.func,
|
||||
lookup: PropTypes.func,
|
||||
register: PropTypes.func,
|
||||
isEnsEnabled: PropTypes.bool
|
||||
isEnsEnabled: PropTypes.bool,
|
||||
ensErrors: PropTypes.string
|
||||
};
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
ensRecords: getEnsRecords(state),
|
||||
ensErrors: getEnsErrors(state),
|
||||
isEnsEnabled: isEnsEnabled(state)
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {combineReducers} from 'redux';
|
||||
import {REQUEST} from "../actions";
|
||||
import {REQUEST, SUCCESS} from "../actions";
|
||||
|
||||
const BN_FACTOR = 10000;
|
||||
const voidAddress = '0x0000000000000000000000000000000000000000';
|
||||
|
@ -95,6 +95,20 @@ function errorMessage(state = null, action) {
|
|||
return action.error || state;
|
||||
}
|
||||
|
||||
/* eslint multiline-ternary: "off" */
|
||||
function errorEntities(state = {}, action) {
|
||||
if (!action.type.endsWith(SUCCESS)) {
|
||||
return state;
|
||||
}
|
||||
let newState = {};
|
||||
for (let name of Object.keys(entitiesDefaultState)) {
|
||||
if (action[name] && action[name].length > 0) {
|
||||
newState[name] = action[name][0].error;
|
||||
}
|
||||
}
|
||||
return {...state, ...newState};
|
||||
}
|
||||
|
||||
function loading(_state = false, action) {
|
||||
return action.type.endsWith(REQUEST);
|
||||
}
|
||||
|
@ -102,7 +116,8 @@ function loading(_state = false, action) {
|
|||
const rootReducer = combineReducers({
|
||||
entities,
|
||||
loading,
|
||||
errorMessage
|
||||
errorMessage,
|
||||
errorEntities
|
||||
});
|
||||
|
||||
export default rootReducer;
|
||||
|
|
|
@ -98,6 +98,10 @@ export function getEnsRecords(state) {
|
|||
return state.entities.ensRecords;
|
||||
}
|
||||
|
||||
export function getEnsErrors(state) {
|
||||
return state.errorEntities.ensRecords;
|
||||
}
|
||||
|
||||
export function isEnsEnabled(state) {
|
||||
return Boolean(state.entities.plugins.find((plugin) => plugin.name === 'ens'));
|
||||
}
|
||||
|
|
|
@ -104,4 +104,3 @@ if (typeof module !== 'undefined' && module.exports) {
|
|||
lookupAddress
|
||||
};
|
||||
}
|
||||
;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*global EmbarkJS, web3, lookupAddress, resolveName, registerSubDomain, namehash, reverseAddrSuffix*/
|
||||
/*global EmbarkJS, web3, lookupAddress, resolveName, registerSubDomain, reverseAddrSuffix*/
|
||||
|
||||
let __embarkENS = {};
|
||||
|
||||
|
|
Loading…
Reference in New Issue