mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-09 13:36:14 +00:00
Display error + lint
This commit is contained in:
parent
f7bdbb68a2
commit
d82c5f93fc
@ -143,7 +143,7 @@ export const ensRecord = {
|
|||||||
export const ENS_RECORDS = createRequestTypes('ENS_RECORDS');
|
export const ENS_RECORDS = createRequestTypes('ENS_RECORDS');
|
||||||
export const ensRecords = {
|
export const ensRecords = {
|
||||||
post: (subdomain, address) => action(ENS_RECORDS[REQUEST], {subdomain, address}),
|
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})
|
failure: (error) => action(ENS_RECORDS[FAILURE], {error})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,11 +30,10 @@ class EnsRegister extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
showResult() {
|
showResult() {
|
||||||
let ensRecord = this.props.ensRecords.find((record) => record.address === this.state.address && record.subdomain === this.state.subdomain);
|
if (this.props.ensErrors) {
|
||||||
if (ensRecord) {
|
return <Alert type="danger">An error happened: {this.props.ensErrors}</Alert>;
|
||||||
return <Alert type="success">Successfully registered</Alert>;
|
|
||||||
} else {
|
} 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 = {
|
EnsRegister.propTypes = {
|
||||||
register: PropTypes.func,
|
register: PropTypes.func,
|
||||||
ensRecords: PropTypes.arrayOf(PropTypes.object)
|
ensRecords: PropTypes.arrayOf(PropTypes.object),
|
||||||
|
ensErrors: PropTypes.string
|
||||||
};
|
};
|
||||||
|
|
||||||
export default EnsRegister;
|
export default EnsRegister;
|
||||||
|
@ -6,7 +6,7 @@ import {ensRecord, ensRecords} from "../actions";
|
|||||||
import EnsRegister from "../components/EnsRegister";
|
import EnsRegister from "../components/EnsRegister";
|
||||||
import EnsLookup from "../components/EnsLookup";
|
import EnsLookup from "../components/EnsLookup";
|
||||||
import EnsResolve from "../components/EnsResolve";
|
import EnsResolve from "../components/EnsResolve";
|
||||||
import {getEnsRecords, isEnsEnabled} from "../reducers/selectors";
|
import {getEnsRecords, isEnsEnabled, getEnsErrors} from "../reducers/selectors";
|
||||||
|
|
||||||
class EnsContainer extends Component {
|
class EnsContainer extends Component {
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ class EnsContainer extends Component {
|
|||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<EnsLookup lookup={this.props.lookup} ensRecords={this.props.ensRecords}/>
|
<EnsLookup lookup={this.props.lookup} ensRecords={this.props.ensRecords}/>
|
||||||
<EnsResolve resolve={this.props.resolve} 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>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -38,12 +38,14 @@ EnsContainer.propTypes = {
|
|||||||
resolve: PropTypes.func,
|
resolve: PropTypes.func,
|
||||||
lookup: PropTypes.func,
|
lookup: PropTypes.func,
|
||||||
register: PropTypes.func,
|
register: PropTypes.func,
|
||||||
isEnsEnabled: PropTypes.bool
|
isEnsEnabled: PropTypes.bool,
|
||||||
|
ensErrors: PropTypes.string
|
||||||
};
|
};
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
function mapStateToProps(state) {
|
||||||
return {
|
return {
|
||||||
ensRecords: getEnsRecords(state),
|
ensRecords: getEnsRecords(state),
|
||||||
|
ensErrors: getEnsErrors(state),
|
||||||
isEnsEnabled: isEnsEnabled(state)
|
isEnsEnabled: isEnsEnabled(state)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {combineReducers} from 'redux';
|
import {combineReducers} from 'redux';
|
||||||
import {REQUEST} from "../actions";
|
import {REQUEST, SUCCESS} from "../actions";
|
||||||
|
|
||||||
const BN_FACTOR = 10000;
|
const BN_FACTOR = 10000;
|
||||||
const voidAddress = '0x0000000000000000000000000000000000000000';
|
const voidAddress = '0x0000000000000000000000000000000000000000';
|
||||||
@ -95,6 +95,20 @@ function errorMessage(state = null, action) {
|
|||||||
return action.error || state;
|
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) {
|
function loading(_state = false, action) {
|
||||||
return action.type.endsWith(REQUEST);
|
return action.type.endsWith(REQUEST);
|
||||||
}
|
}
|
||||||
@ -102,7 +116,8 @@ function loading(_state = false, action) {
|
|||||||
const rootReducer = combineReducers({
|
const rootReducer = combineReducers({
|
||||||
entities,
|
entities,
|
||||||
loading,
|
loading,
|
||||||
errorMessage
|
errorMessage,
|
||||||
|
errorEntities
|
||||||
});
|
});
|
||||||
|
|
||||||
export default rootReducer;
|
export default rootReducer;
|
||||||
|
@ -98,6 +98,10 @@ export function getEnsRecords(state) {
|
|||||||
return state.entities.ensRecords;
|
return state.entities.ensRecords;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getEnsErrors(state) {
|
||||||
|
return state.errorEntities.ensRecords;
|
||||||
|
}
|
||||||
|
|
||||||
export function isEnsEnabled(state) {
|
export function isEnsEnabled(state) {
|
||||||
return Boolean(state.entities.plugins.find((plugin) => plugin.name === 'ens'));
|
return Boolean(state.entities.plugins.find((plugin) => plugin.name === 'ens'));
|
||||||
}
|
}
|
||||||
|
@ -104,4 +104,3 @@ if (typeof module !== 'undefined' && module.exports) {
|
|||||||
lookupAddress
|
lookupAddress
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
;
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*global EmbarkJS, web3, lookupAddress, resolveName, registerSubDomain, namehash, reverseAddrSuffix*/
|
/*global EmbarkJS, web3, lookupAddress, resolveName, registerSubDomain, reverseAddrSuffix*/
|
||||||
|
|
||||||
let __embarkENS = {};
|
let __embarkENS = {};
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ class ENS {
|
|||||||
let self = this;
|
let self = this;
|
||||||
|
|
||||||
const createInternalResolverContract = function(resolverAddress, callback) {
|
const createInternalResolverContract = function(resolverAddress, callback) {
|
||||||
this.createResolverContract({resolverAbi: config.resolverAbi, resolverAddress}, callback)
|
this.createResolverContract({resolverAbi: config.resolverAbi, resolverAddress}, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
self.embark.registerAPICall(
|
self.embark.registerAPICall(
|
||||||
@ -233,7 +233,7 @@ class ENS {
|
|||||||
}
|
}
|
||||||
], function(error, name) {
|
], function(error, name) {
|
||||||
if (error) {
|
if (error) {
|
||||||
return res.send({error: error.message});
|
return res.send({error: error || error.message});
|
||||||
}
|
}
|
||||||
res.send({name});
|
res.send({name});
|
||||||
});
|
});
|
||||||
@ -244,18 +244,40 @@ class ENS {
|
|||||||
'post',
|
'post',
|
||||||
'/embark-api/ens/register',
|
'/embark-api/ens/register',
|
||||||
(req, res) => {
|
(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) {
|
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) {
|
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) {
|
registerSubdomains(subdomains, config, callback) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user