Display error + lint
This commit is contained in:
parent
fcba6285e7
commit
49463992ba
|
@ -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 = {};
|
||||
|
||||
|
|
|
@ -195,7 +195,7 @@ class ENS {
|
|||
let self = this;
|
||||
|
||||
const createInternalResolverContract = function(resolverAddress, callback) {
|
||||
this.createResolverContract({resolverAbi: config.resolverAbi, resolverAddress}, callback)
|
||||
this.createResolverContract({resolverAbi: config.resolverAbi, resolverAddress}, callback);
|
||||
};
|
||||
|
||||
self.embark.registerAPICall(
|
||||
|
@ -227,7 +227,7 @@ class ENS {
|
|||
}
|
||||
], function(error, name) {
|
||||
if (error) {
|
||||
return res.send({error: error.message});
|
||||
return res.send({error: error || error.message});
|
||||
}
|
||||
res.send({name});
|
||||
});
|
||||
|
@ -238,18 +238,40 @@ class ENS {
|
|||
'post',
|
||||
'/embark-api/ens/register',
|
||||
(req, res) => {
|
||||
self.registerSubdomains({[req.body.subdomain]: req.body.address}, config, (error, transaction) => {
|
||||
self.registerSubdomain(req.body.subdomain, req.body.address, config, (error) => {
|
||||
if (error) {
|
||||
return res.send({error: error.message});
|
||||
return res.send({error: error || error.message});
|
||||
}
|
||||
res.send({transaction});
|
||||
res.send({name: `${req.body.subdomain}.${self.registration.rootDomain}`, address: req.body.address});
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
registerConfigSubdomains(config, callback) {
|
||||
this.registerSubdomains(this.registration.subdomains, config, callback);
|
||||
async.each(Object.keys(this.registration.subdomains), (subdomain, eachCb) => {
|
||||
this.registerSubdomain(subdomain, this.registration.subdomains[subdomain], config, eachCb);
|
||||
}, callback);
|
||||
}
|
||||
|
||||
registerSubdomain(subdomain, address, config, callback) {
|
||||
const self = this;
|
||||
self.events.request("blockchain:defaultAccount:get", (defaultAccount) => {
|
||||
async.parallel({
|
||||
ens: self.createRegistryContract.bind(this, config),
|
||||
registrar: self.createRegistrarContract.bind(this, config),
|
||||
resolver: self.createResolverContract.bind(this, config)
|
||||
}, function (err, contracts) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
const {ens, registrar, resolver} = contracts;
|
||||
|
||||
const reverseNode = utils.soliditySha3(address.toLowerCase().substr(2) + reverseAddrSuffix);
|
||||
ENSFunctions.registerSubDomain(ens, registrar, resolver, defaultAccount, subdomain,
|
||||
self.registration.rootDomain, reverseNode, address, self.logger, callback);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
registerSubdomains(subdomains, config, callback) {
|
||||
|
|
Loading…
Reference in New Issue