Warning if no default account for ens

This commit is contained in:
Anthony Laibe 2018-09-25 15:30:46 +01:00
parent e744a24557
commit 23d6b07467
1 changed files with 12 additions and 1 deletions

View File

@ -131,6 +131,7 @@ __embarkENS.resolverInterface = [
}
];
const defaultAccountNotSetError = 'web3.eth.defaultAccount not set';
const providerNotSetError = 'ENS provider not set';
const NoDecodeAddrError = 'Error: Couldn\'t decode address from ABI: 0x';
const NoDecodeStringError = 'ERROR: The returned value is not a convertible string: 0x0';
@ -151,7 +152,6 @@ __embarkENS.setProvider = function (config) {
const ERROR_MESSAGE = 'ENS is not available in this chain';
self.registration = config.registration;
self.env = config.env;
EmbarkJS.onReady(() => {
web3.eth.net.getId()
.then((id) => {
@ -176,6 +176,10 @@ __embarkENS.resolve = function (name, callback) {
if (!this.ens) {
return callback(providerNotSetError);
}
if (!web3.eth.defaultAccount) {
return callback(defaultAccountNotSetError);
}
let node = namehash.hash(name);
function cb(err, addr) {
@ -202,6 +206,9 @@ __embarkENS.lookup = function (address, callback) {
if (!this.ens) {
return callback(providerNotSetError);
}
if (!web3.eth.defaultAccount) {
return callback(defaultAccountNotSetError);
}
if (address.startsWith("0x")) {
address = address.slice(2);
}
@ -229,6 +236,10 @@ __embarkENS.lookup = function (address, callback) {
__embarkENS.registerSubDomain = function (name, address, callback) {
callback = callback || function () {};
if (!web3.eth.defaultAccount) {
return callback(defaultAccountNotSetError);
}
if (this.env !== 'development' && this.env !== 'privatenet') {
return callback('Sub-domain registration is only available in development or privatenet mode');
}