Added eslint for promises. (#189)

This commit is contained in:
Richard Moore 2018-07-03 16:44:05 -04:00
parent 7ac8cb63c8
commit 4514229f27
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295
20 changed files with 183 additions and 140 deletions

31
.eslintrc.js Normal file

@ -0,0 +1,31 @@
module.exports = {
"env": {
"browser": true,
"commonjs": true,
"node": true
},
"extends": [
// "eslint:recommended",
// "plugin:promise/recommended"
],
"parserOptions": {
"ecmaVersion": 5
},
"plugins": [
"promise"
],
"rules": {
"promise/always-return": "error",
"promise/no-return-wrap": "error",
"promise/param-names": "error",
"promise/catch-or-return": "error",
"promise/no-native": "off",
// "promise/no-nesting": "warn",
"promise/no-promise-in-callback": "warn",
"promise/no-callback-in-promise": "warn",
// "promise/avoid-new": "warn",
"promise/no-new-statics": "error",
"promise/no-return-in-finally": "warn",
"promise/valid-params": "warn"
}
};

@ -187,7 +187,15 @@ var Contract = /** @class */ (function () {
return; return;
} }
properties_1.defineReadOnly(this, 'address', addressOrName); properties_1.defineReadOnly(this, 'address', addressOrName);
properties_1.defineReadOnly(this, 'addressPromise', this.provider.resolveName(addressOrName)); properties_1.defineReadOnly(this, 'addressPromise', this.provider.resolveName(addressOrName).then(function (address) {
if (address == null) {
throw new Error('name not found');
}
return address;
}).catch(function (error) {
console.log('ERROR: Cannot find Contract - ' + addressOrName);
throw error;
}));
Object.keys(this.interface.functions).forEach(function (name) { Object.keys(this.interface.functions).forEach(function (name) {
var run = runMethod(_this, name, false); var run = runMethod(_this, name, false);
if (_this[name] == null) { if (_this[name] == null) {
@ -209,7 +217,7 @@ var Contract = /** @class */ (function () {
contract.addressPromise.then(function (address) { contract.addressPromise.then(function (address) {
// Not meant for us (the topics just has the same name) // Not meant for us (the topics just has the same name)
if (address != log.address) { if (address != log.address) {
return; return null;
} }
try { try {
var result = eventInfo.decode(log.data, log.topics); var result = eventInfo.decode(log.data, log.topics);
@ -233,7 +241,8 @@ var Contract = /** @class */ (function () {
setTimeout(function () { onerror_1(error); }); setTimeout(function () { onerror_1(error); });
} }
} }
}); return null;
}).catch(function (error) { });
} }
var property = { var property = {
enumerable: true, enumerable: true,

76
dist/ethers.js vendored

@ -9039,7 +9039,15 @@ var Contract = /** @class */ (function () {
return; return;
} }
properties_1.defineReadOnly(this, 'address', addressOrName); properties_1.defineReadOnly(this, 'address', addressOrName);
properties_1.defineReadOnly(this, 'addressPromise', this.provider.resolveName(addressOrName)); properties_1.defineReadOnly(this, 'addressPromise', this.provider.resolveName(addressOrName).then(function (address) {
if (address == null) {
throw new Error('name not found');
}
return address;
}).catch(function (error) {
console.log('ERROR: Cannot find Contract - ' + addressOrName);
throw error;
}));
Object.keys(this.interface.functions).forEach(function (name) { Object.keys(this.interface.functions).forEach(function (name) {
var run = runMethod(_this, name, false); var run = runMethod(_this, name, false);
if (_this[name] == null) { if (_this[name] == null) {
@ -9061,7 +9069,7 @@ var Contract = /** @class */ (function () {
contract.addressPromise.then(function (address) { contract.addressPromise.then(function (address) {
// Not meant for us (the topics just has the same name) // Not meant for us (the topics just has the same name)
if (address != log.address) { if (address != log.address) {
return; return null;
} }
try { try {
var result = eventInfo.decode(log.data, log.topics); var result = eventInfo.decode(log.data, log.topics);
@ -9085,7 +9093,8 @@ var Contract = /** @class */ (function () {
setTimeout(function () { onerror_1(error); }); setTimeout(function () { onerror_1(error); });
} }
} }
}); return null;
}).catch(function (error) { });
} }
var property = { var property = {
enumerable: true, enumerable: true,
@ -9796,6 +9805,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
return self.getTransaction(log.transactionHash).then(function (tx) { return self.getTransaction(log.transactionHash).then(function (tx) {
txs[log.transactionHash] = tx.blockHash; txs[log.transactionHash] = tx.blockHash;
log.blockHash = tx.blockHash; log.blockHash = tx.blockHash;
return null;
}); });
} }
return null; return null;
@ -9959,12 +9969,12 @@ var FallbackProvider = /** @class */ (function (_super) {
} }
var provider = providers.shift(); var provider = providers.shift();
provider.perform(method, params).then(function (result) { provider.perform(method, params).then(function (result) {
resolve(result); return resolve(result);
}, function (error) { }).catch(function (error) {
if (!firstError) { if (!firstError) {
firstError = error; firstError = error;
} }
next(); setTimeout(next, 0);
}); });
} }
next(); next();
@ -10260,8 +10270,9 @@ var JsonRpcProvider = /** @class */ (function (_super) {
var ready = new Promise(function (resolve, reject) { var ready = new Promise(function (resolve, reject) {
setTimeout(function () { setTimeout(function () {
_this.send('net_version', []).then(function (result) { _this.send('net_version', []).then(function (result) {
var chainId = parseInt(result); return resolve(networks_1.getNetwork(parseInt(result)));
resolve(networks_1.getNetwork(chainId)); }).catch(function (error) {
reject(error);
}); });
}); });
}); });
@ -10361,6 +10372,7 @@ var JsonRpcProvider = /** @class */ (function (_super) {
seq = seq.then(function () { seq = seq.then(function () {
return self.getTransaction(hash).then(function (tx) { return self.getTransaction(hash).then(function (tx) {
self.emit('pending', tx); self.emit('pending', tx);
return null;
}); });
}); });
}); });
@ -10373,11 +10385,12 @@ var JsonRpcProvider = /** @class */ (function (_super) {
return; return;
} }
setTimeout(function () { poll(); }, 0); setTimeout(function () { poll(); }, 0);
}); return null;
}).catch(function (error) { });
} }
poll(); poll();
return filterId; return filterId;
}); }).catch(function (error) { });
}; };
JsonRpcProvider.prototype._stopPending = function () { JsonRpcProvider.prototype._stopPending = function () {
this._pendingFilter = null; this._pendingFilter = null;
@ -11064,7 +11077,8 @@ var Provider = /** @class */ (function () {
} }
_this._emitted['t:' + event.hash.toLowerCase()] = receipt.blockNumber; _this._emitted['t:' + event.hash.toLowerCase()] = receipt.blockNumber;
_this.emit(event.hash, receipt); _this.emit(event.hash, receipt);
}); return null;
}).catch(function (error) { });
} }
else if (event.type === 'address') { else if (event.type === 'address') {
if (_this._balances[event.address]) { if (_this._balances[event.address]) {
@ -11077,7 +11091,8 @@ var Provider = /** @class */ (function () {
} }
this._balances[event.address] = balance; this._balances[event.address] = balance;
this.emit(event.address, balance); this.emit(event.address, balance);
}); return null;
}).catch(function (error) { });
} }
else if (event.type === 'topic') { else if (event.type === 'topic') {
_this.getLogs({ _this.getLogs({
@ -11093,12 +11108,14 @@ var Provider = /** @class */ (function () {
_this._emitted['t:' + log.transactionHash.toLowerCase()] = log.blockNumber; _this._emitted['t:' + log.transactionHash.toLowerCase()] = log.blockNumber;
_this.emit(event.topic, log); _this.emit(event.topic, log);
}); });
}); return null;
}).catch(function (error) { });
} }
}); });
_this._lastBlockNumber = blockNumber; _this._lastBlockNumber = blockNumber;
_this._balances = newBalances; _this._balances = newBalances;
}); return null;
}).catch(function (error) { });
this.doPoll(); this.doPoll();
}; };
Provider.prototype.resetEventsBlock = function (blockNumber) { Provider.prototype.resetEventsBlock = function (blockNumber) {
@ -11449,6 +11466,7 @@ var Provider = /** @class */ (function () {
} }
promises.push(this.resolveName(result[key]).then(function (address) { promises.push(this.resolveName(result[key]).then(function (address) {
result[key] = address; result[key] = address;
return;
})); }));
}, this); }, this);
return Promise.all(promises).then(function () { return result; }); return Promise.all(promises).then(function () { return result; });
@ -13490,6 +13508,7 @@ function resolveProperties(object) {
if (value instanceof Promise) { if (value instanceof Promise) {
promises.push(value.then(function (value) { promises.push(value.then(function (value) {
result[key] = value; result[key] = value;
return null;
})); }));
} }
else { else {
@ -14378,7 +14397,7 @@ function poll(func, options) {
} }
var attempt = 0; var attempt = 0;
function check() { function check() {
func().then(function (result) { return func().then(function (result) {
// If we have a result, or are allowed null then we're done // If we have a result, or are allowed null then we're done
if (result !== undefined) { if (result !== undefined) {
if (cancel()) { if (cancel()) {
@ -14400,6 +14419,7 @@ function poll(func, options) {
} }
setTimeout(check, timeout); setTimeout(check, timeout);
} }
return null;
}, function (error) { }, function (error) {
if (cancel()) { if (cancel()) {
reject(error); reject(error);
@ -15315,37 +15335,21 @@ var Wallet = /** @class */ (function (_super) {
return Wallet.fromMnemonic(mnemonic, options.path, options.locale); return Wallet.fromMnemonic(mnemonic, options.path, options.locale);
}; };
Wallet.fromEncryptedJson = function (json, password, progressCallback) { Wallet.fromEncryptedJson = function (json, password, progressCallback) {
if (progressCallback && typeof (progressCallback) !== 'function') {
throw new Error('invalid callback');
}
return new Promise(function (resolve, reject) {
if (secretStorage.isCrowdsaleWallet(json)) { if (secretStorage.isCrowdsaleWallet(json)) {
try { try {
var privateKey = secretStorage.decryptCrowdsale(json, password); var privateKey = secretStorage.decryptCrowdsale(json, password);
resolve(new Wallet(privateKey)); return Promise.resolve(new Wallet(privateKey));
} }
catch (error) { catch (error) {
reject(error); return Promise.reject(error);
} }
} }
else if (secretStorage.isValidWallet(json)) { else if (secretStorage.isValidWallet(json)) {
secretStorage.decrypt(json, password, progressCallback).then(function (signingKey) { return secretStorage.decrypt(json, password, progressCallback).then(function (signingKey) {
var wallet = new Wallet(signingKey); return new Wallet(signingKey);
/*
if (signingKey.mnemonic && signingKey.path) {
wallet.mnemonic = signingKey.mnemonic;
wallet.path = signingKey.path;
}
*/
resolve(wallet);
}, function (error) {
reject(error);
}); });
} }
else { return Promise.reject('invalid wallet JSON');
reject('invalid wallet JSON');
}
});
}; };
Wallet.fromMnemonic = function (mnemonic, path, wordlist) { Wallet.fromMnemonic = function (mnemonic, path, wordlist) {
if (!path) { if (!path) {

2
dist/ethers.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -220,6 +220,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
return self.getTransaction(log.transactionHash).then(function (tx) { return self.getTransaction(log.transactionHash).then(function (tx) {
txs[log.transactionHash] = tx.blockHash; txs[log.transactionHash] = tx.blockHash;
log.blockHash = tx.blockHash; log.blockHash = tx.blockHash;
return null;
}); });
} }
return null; return null;

@ -94,12 +94,12 @@ var FallbackProvider = /** @class */ (function (_super) {
} }
var provider = providers.shift(); var provider = providers.shift();
provider.perform(method, params).then(function (result) { provider.perform(method, params).then(function (result) {
resolve(result); return resolve(result);
}, function (error) { }).catch(function (error) {
if (!firstError) { if (!firstError) {
firstError = error; firstError = error;
} }
next(); setTimeout(next, 0);
}); });
} }
next(); next();

@ -181,8 +181,9 @@ var JsonRpcProvider = /** @class */ (function (_super) {
var ready = new Promise(function (resolve, reject) { var ready = new Promise(function (resolve, reject) {
setTimeout(function () { setTimeout(function () {
_this.send('net_version', []).then(function (result) { _this.send('net_version', []).then(function (result) {
var chainId = parseInt(result); return resolve(networks_1.getNetwork(parseInt(result)));
resolve(networks_1.getNetwork(chainId)); }).catch(function (error) {
reject(error);
}); });
}); });
}); });
@ -282,6 +283,7 @@ var JsonRpcProvider = /** @class */ (function (_super) {
seq = seq.then(function () { seq = seq.then(function () {
return self.getTransaction(hash).then(function (tx) { return self.getTransaction(hash).then(function (tx) {
self.emit('pending', tx); self.emit('pending', tx);
return null;
}); });
}); });
}); });
@ -294,11 +296,12 @@ var JsonRpcProvider = /** @class */ (function (_super) {
return; return;
} }
setTimeout(function () { poll(); }, 0); setTimeout(function () { poll(); }, 0);
}); return null;
}).catch(function (error) { });
} }
poll(); poll();
return filterId; return filterId;
}); }).catch(function (error) { });
}; };
JsonRpcProvider.prototype._stopPending = function () { JsonRpcProvider.prototype._stopPending = function () {
this._pendingFilter = null; this._pendingFilter = null;

@ -573,7 +573,8 @@ var Provider = /** @class */ (function () {
} }
_this._emitted['t:' + event.hash.toLowerCase()] = receipt.blockNumber; _this._emitted['t:' + event.hash.toLowerCase()] = receipt.blockNumber;
_this.emit(event.hash, receipt); _this.emit(event.hash, receipt);
}); return null;
}).catch(function (error) { });
} }
else if (event.type === 'address') { else if (event.type === 'address') {
if (_this._balances[event.address]) { if (_this._balances[event.address]) {
@ -586,7 +587,8 @@ var Provider = /** @class */ (function () {
} }
this._balances[event.address] = balance; this._balances[event.address] = balance;
this.emit(event.address, balance); this.emit(event.address, balance);
}); return null;
}).catch(function (error) { });
} }
else if (event.type === 'topic') { else if (event.type === 'topic') {
_this.getLogs({ _this.getLogs({
@ -602,12 +604,14 @@ var Provider = /** @class */ (function () {
_this._emitted['t:' + log.transactionHash.toLowerCase()] = log.blockNumber; _this._emitted['t:' + log.transactionHash.toLowerCase()] = log.blockNumber;
_this.emit(event.topic, log); _this.emit(event.topic, log);
}); });
}); return null;
}).catch(function (error) { });
} }
}); });
_this._lastBlockNumber = blockNumber; _this._lastBlockNumber = blockNumber;
_this._balances = newBalances; _this._balances = newBalances;
}); return null;
}).catch(function (error) { });
this.doPoll(); this.doPoll();
}; };
Provider.prototype.resetEventsBlock = function (blockNumber) { Provider.prototype.resetEventsBlock = function (blockNumber) {
@ -958,6 +962,7 @@ var Provider = /** @class */ (function () {
} }
promises.push(this.resolveName(result[key]).then(function (address) { promises.push(this.resolveName(result[key]).then(function (address) {
result[key] = address; result[key] = address;
return;
})); }));
}, this); }, this);
return Promise.all(promises).then(function () { return result; }); return Promise.all(promises).then(function () { return result; });

@ -238,7 +238,13 @@ export class Contract {
} }
defineReadOnly(this, 'address', addressOrName); defineReadOnly(this, 'address', addressOrName);
defineReadOnly(this, 'addressPromise', this.provider.resolveName(addressOrName)); defineReadOnly(this, 'addressPromise', this.provider.resolveName(addressOrName).then((address) => {
if (address == null) { throw new Error('name not found'); }
return address;
}).catch((error: Error) => {
console.log('ERROR: Cannot find Contract - ' + addressOrName);
throw error;
}));
Object.keys(this.interface.functions).forEach((name) => { Object.keys(this.interface.functions).forEach((name) => {
var run = runMethod(this, name, false); var run = runMethod(this, name, false);
@ -265,7 +271,7 @@ export class Contract {
function handleEvent(log: any): void { function handleEvent(log: any): void {
contract.addressPromise.then((address) => { contract.addressPromise.then((address) => {
// Not meant for us (the topics just has the same name) // Not meant for us (the topics just has the same name)
if (address != log.address) { return; } if (address != log.address) { return null; }
try { try {
let result = eventInfo.decode(log.data, log.topics); let result = eventInfo.decode(log.data, log.topics);
@ -289,7 +295,9 @@ export class Contract {
let onerror = contract._onerror; let onerror = contract._onerror;
if (onerror) { setTimeout(() => { onerror(error); }); } if (onerror) { setTimeout(() => { onerror(error); }); }
} }
});
return null;
}).catch((error) => { });
} }
var property = { var property = {

@ -225,6 +225,7 @@ export class EtherscanProvider extends Provider{
return self.getTransaction(log.transactionHash).then(function(tx) { return self.getTransaction(log.transactionHash).then(function(tx) {
txs[log.transactionHash] = tx.blockHash; txs[log.transactionHash] = tx.blockHash;
log.blockHash = tx.blockHash; log.blockHash = tx.blockHash;
return null;
}); });
} }
return null; return null;

@ -89,11 +89,11 @@ export class FallbackProvider extends Provider {
} }
var provider = providers.shift(); var provider = providers.shift();
provider.perform(method, params).then(function(result) { provider.perform(method, params).then((result) => {
resolve(result); return resolve(result);
}, function (error) { }).catch((error) => {
if (!firstError) { firstError = error; } if (!firstError) { firstError = error; }
next(); setTimeout(next, 0);
}); });
} }
next(); next();

@ -177,9 +177,9 @@ export class JsonRpcProvider extends Provider {
let ready: Promise<Network> = new Promise((resolve, reject) => { let ready: Promise<Network> = new Promise((resolve, reject) => {
setTimeout(() => { setTimeout(() => {
this.send('net_version', [ ]).then((result) => { this.send('net_version', [ ]).then((result) => {
let chainId = parseInt(result); return resolve(getNetwork(parseInt(result)));
}).catch((error) => {
resolve(getNetwork(chainId)); reject(error);
}); });
}); });
}); });
@ -297,6 +297,7 @@ export class JsonRpcProvider extends Provider {
seq = seq.then(function() { seq = seq.then(function() {
return self.getTransaction(hash).then(function(tx) { return self.getTransaction(hash).then(function(tx) {
self.emit('pending', tx); self.emit('pending', tx);
return null;
}); });
}); });
}); });
@ -310,12 +311,14 @@ export class JsonRpcProvider extends Provider {
return; return;
} }
setTimeout(function() { poll(); }, 0); setTimeout(function() { poll(); }, 0);
});
return null;
}).catch((error: Error) => { });
} }
poll(); poll();
return filterId; return filterId;
}); }).catch((error: Error) => { });
} }
_stopPending(): void { _stopPending(): void {

@ -749,7 +749,8 @@ export class Provider {
if (!receipt || receipt.blockNumber == null) { return; } if (!receipt || receipt.blockNumber == null) { return; }
this._emitted['t:' + event.hash.toLowerCase()] = receipt.blockNumber; this._emitted['t:' + event.hash.toLowerCase()] = receipt.blockNumber;
this.emit(event.hash, receipt); this.emit(event.hash, receipt);
}); return null;
}).catch((error: Error) => { });
} else if (event.type === 'address') { } else if (event.type === 'address') {
if (this._balances[event.address]) { if (this._balances[event.address]) {
@ -760,7 +761,8 @@ export class Provider {
if (lastBalance && balance.eq(lastBalance)) { return; } if (lastBalance && balance.eq(lastBalance)) { return; }
this._balances[event.address] = balance; this._balances[event.address] = balance;
this.emit(event.address, balance); this.emit(event.address, balance);
}); return null;
}).catch((error: Error) => { });
} else if (event.type === 'topic') { } else if (event.type === 'topic') {
this.getLogs({ this.getLogs({
@ -774,14 +776,17 @@ export class Provider {
this._emitted['t:' + log.transactionHash.toLowerCase()] = log.blockNumber; this._emitted['t:' + log.transactionHash.toLowerCase()] = log.blockNumber;
this.emit(event.topic, log); this.emit(event.topic, log);
}); });
}); return null;
}).catch((error: Error) => { });
} }
}); });
this._lastBlockNumber = blockNumber; this._lastBlockNumber = blockNumber;
this._balances = newBalances; this._balances = newBalances;
});
return null;
}).catch((error: Error) => { });
this.doPoll(); this.doPoll();
} }
@ -1126,6 +1131,7 @@ export class Provider {
if (result[key] == null) { return; } if (result[key] == null) { return; }
promises.push(this.resolveName(result[key]).then((address: string) => { promises.push(this.resolveName(result[key]).then((address: string) => {
result[key] = address; result[key] = address;
return;
})); }));
}, this); }, this);

@ -26,6 +26,7 @@ export function resolveProperties(object: any): Promise<any> {
promises.push( promises.push(
value.then((value) => { value.then((value) => {
result[key] = value; result[key] = value;
return null;
}) })
); );
} else { } else {

@ -159,7 +159,7 @@ export function poll(func: () => Promise<any>, options?: PollOptions): Promise<a
let attempt = 0; let attempt = 0;
function check() { function check() {
func().then(function(result) { return func().then(function(result) {
// If we have a result, or are allowed null then we're done // If we have a result, or are allowed null then we're done
if (result !== undefined) { if (result !== undefined) {
@ -178,6 +178,8 @@ export function poll(func: () => Promise<any>, options?: PollOptions): Promise<a
setTimeout(check, timeout); setTimeout(check, timeout);
} }
return null;
}, function(error) { }, function(error) {
if (cancel()) { reject(error); } if (cancel()) { reject(error); }
}); });

@ -167,39 +167,22 @@ export class Wallet extends Signer {
} }
static fromEncryptedJson(json: string, password: Arrayish, progressCallback: ProgressCallback): Promise<Wallet> { static fromEncryptedJson(json: string, password: Arrayish, progressCallback: ProgressCallback): Promise<Wallet> {
if (progressCallback && typeof(progressCallback) !== 'function') {
throw new Error('invalid callback');
}
return new Promise(function(resolve, reject) {
if (secretStorage.isCrowdsaleWallet(json)) { if (secretStorage.isCrowdsaleWallet(json)) {
try { try {
var privateKey = secretStorage.decryptCrowdsale(json, password); let privateKey = secretStorage.decryptCrowdsale(json, password);
resolve(new Wallet(privateKey)); return Promise.resolve(new Wallet(privateKey));
} catch (error) { } catch (error) {
reject(error); return Promise.reject(error);
} }
} else if (secretStorage.isValidWallet(json)) { } else if (secretStorage.isValidWallet(json)) {
secretStorage.decrypt(json, password, progressCallback).then(function(signingKey) { return secretStorage.decrypt(json, password, progressCallback).then(function(signingKey) {
var wallet = new Wallet(signingKey); return new Wallet(signingKey);
/*
if (signingKey.mnemonic && signingKey.path) {
wallet.mnemonic = signingKey.mnemonic;
wallet.path = signingKey.path;
}
*/
resolve(wallet);
}, function(error) {
reject(error);
}); });
}
} else { return Promise.reject('invalid wallet JSON');
reject('invalid wallet JSON');
}
});
} }
static fromMnemonic(mnemonic: string, path?: string, wordlist?: Wordlist): Wallet { static fromMnemonic(mnemonic: string, path?: string, wordlist?: Wordlist): Wallet {

@ -24,6 +24,7 @@ function resolveProperties(object) {
if (value instanceof Promise) { if (value instanceof Promise) {
promises.push(value.then(function (value) { promises.push(value.then(function (value) {
result[key] = value; result[key] = value;
return null;
})); }));
} }
else { else {

@ -138,7 +138,7 @@ function poll(func, options) {
} }
var attempt = 0; var attempt = 0;
function check() { function check() {
func().then(function (result) { return func().then(function (result) {
// If we have a result, or are allowed null then we're done // If we have a result, or are allowed null then we're done
if (result !== undefined) { if (result !== undefined) {
if (cancel()) { if (cancel()) {
@ -160,6 +160,7 @@ function poll(func, options) {
} }
setTimeout(check, timeout); setTimeout(check, timeout);
} }
return null;
}, function (error) { }, function (error) {
if (cancel()) { if (cancel()) {
reject(error); reject(error);

@ -163,37 +163,21 @@ var Wallet = /** @class */ (function (_super) {
return Wallet.fromMnemonic(mnemonic, options.path, options.locale); return Wallet.fromMnemonic(mnemonic, options.path, options.locale);
}; };
Wallet.fromEncryptedJson = function (json, password, progressCallback) { Wallet.fromEncryptedJson = function (json, password, progressCallback) {
if (progressCallback && typeof (progressCallback) !== 'function') {
throw new Error('invalid callback');
}
return new Promise(function (resolve, reject) {
if (secretStorage.isCrowdsaleWallet(json)) { if (secretStorage.isCrowdsaleWallet(json)) {
try { try {
var privateKey = secretStorage.decryptCrowdsale(json, password); var privateKey = secretStorage.decryptCrowdsale(json, password);
resolve(new Wallet(privateKey)); return Promise.resolve(new Wallet(privateKey));
} }
catch (error) { catch (error) {
reject(error); return Promise.reject(error);
} }
} }
else if (secretStorage.isValidWallet(json)) { else if (secretStorage.isValidWallet(json)) {
secretStorage.decrypt(json, password, progressCallback).then(function (signingKey) { return secretStorage.decrypt(json, password, progressCallback).then(function (signingKey) {
var wallet = new Wallet(signingKey); return new Wallet(signingKey);
/*
if (signingKey.mnemonic && signingKey.path) {
wallet.mnemonic = signingKey.mnemonic;
wallet.path = signingKey.path;
}
*/
resolve(wallet);
}, function (error) {
reject(error);
}); });
} }
else { return Promise.reject('invalid wallet JSON');
reject('invalid wallet JSON');
}
});
}; };
Wallet.fromMnemonic = function (mnemonic, path, wordlist) { Wallet.fromMnemonic = function (mnemonic, path, wordlist) {
if (!path) { if (!path) {