Added eslint for promises. (#189)
This commit is contained in:
parent
7ac8cb63c8
commit
4514229f27
31
.eslintrc.js
Normal file
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;
|
||||
}
|
||||
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) {
|
||||
var run = runMethod(_this, name, false);
|
||||
if (_this[name] == null) {
|
||||
@ -209,7 +217,7 @@ var Contract = /** @class */ (function () {
|
||||
contract.addressPromise.then(function (address) {
|
||||
// Not meant for us (the topics just has the same name)
|
||||
if (address != log.address) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
var result = eventInfo.decode(log.data, log.topics);
|
||||
@ -233,7 +241,8 @@ var Contract = /** @class */ (function () {
|
||||
setTimeout(function () { onerror_1(error); });
|
||||
}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}).catch(function (error) { });
|
||||
}
|
||||
var property = {
|
||||
enumerable: true,
|
||||
|
94
dist/ethers.js
vendored
94
dist/ethers.js
vendored
@ -9039,7 +9039,15 @@ var Contract = /** @class */ (function () {
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
var run = runMethod(_this, name, false);
|
||||
if (_this[name] == null) {
|
||||
@ -9061,7 +9069,7 @@ var Contract = /** @class */ (function () {
|
||||
contract.addressPromise.then(function (address) {
|
||||
// Not meant for us (the topics just has the same name)
|
||||
if (address != log.address) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
var result = eventInfo.decode(log.data, log.topics);
|
||||
@ -9085,7 +9093,8 @@ var Contract = /** @class */ (function () {
|
||||
setTimeout(function () { onerror_1(error); });
|
||||
}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}).catch(function (error) { });
|
||||
}
|
||||
var property = {
|
||||
enumerable: true,
|
||||
@ -9796,6 +9805,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
return self.getTransaction(log.transactionHash).then(function (tx) {
|
||||
txs[log.transactionHash] = tx.blockHash;
|
||||
log.blockHash = tx.blockHash;
|
||||
return null;
|
||||
});
|
||||
}
|
||||
return null;
|
||||
@ -9959,12 +9969,12 @@ var FallbackProvider = /** @class */ (function (_super) {
|
||||
}
|
||||
var provider = providers.shift();
|
||||
provider.perform(method, params).then(function (result) {
|
||||
resolve(result);
|
||||
}, function (error) {
|
||||
return resolve(result);
|
||||
}).catch(function (error) {
|
||||
if (!firstError) {
|
||||
firstError = error;
|
||||
}
|
||||
next();
|
||||
setTimeout(next, 0);
|
||||
});
|
||||
}
|
||||
next();
|
||||
@ -10260,8 +10270,9 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
||||
var ready = new Promise(function (resolve, reject) {
|
||||
setTimeout(function () {
|
||||
_this.send('net_version', []).then(function (result) {
|
||||
var chainId = parseInt(result);
|
||||
resolve(networks_1.getNetwork(chainId));
|
||||
return resolve(networks_1.getNetwork(parseInt(result)));
|
||||
}).catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -10361,6 +10372,7 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
||||
seq = seq.then(function () {
|
||||
return self.getTransaction(hash).then(function (tx) {
|
||||
self.emit('pending', tx);
|
||||
return null;
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -10373,11 +10385,12 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
||||
return;
|
||||
}
|
||||
setTimeout(function () { poll(); }, 0);
|
||||
});
|
||||
return null;
|
||||
}).catch(function (error) { });
|
||||
}
|
||||
poll();
|
||||
return filterId;
|
||||
});
|
||||
}).catch(function (error) { });
|
||||
};
|
||||
JsonRpcProvider.prototype._stopPending = function () {
|
||||
this._pendingFilter = null;
|
||||
@ -11064,7 +11077,8 @@ var Provider = /** @class */ (function () {
|
||||
}
|
||||
_this._emitted['t:' + event.hash.toLowerCase()] = receipt.blockNumber;
|
||||
_this.emit(event.hash, receipt);
|
||||
});
|
||||
return null;
|
||||
}).catch(function (error) { });
|
||||
}
|
||||
else if (event.type === 'address') {
|
||||
if (_this._balances[event.address]) {
|
||||
@ -11077,7 +11091,8 @@ var Provider = /** @class */ (function () {
|
||||
}
|
||||
this._balances[event.address] = balance;
|
||||
this.emit(event.address, balance);
|
||||
});
|
||||
return null;
|
||||
}).catch(function (error) { });
|
||||
}
|
||||
else if (event.type === 'topic') {
|
||||
_this.getLogs({
|
||||
@ -11093,12 +11108,14 @@ var Provider = /** @class */ (function () {
|
||||
_this._emitted['t:' + log.transactionHash.toLowerCase()] = log.blockNumber;
|
||||
_this.emit(event.topic, log);
|
||||
});
|
||||
});
|
||||
return null;
|
||||
}).catch(function (error) { });
|
||||
}
|
||||
});
|
||||
_this._lastBlockNumber = blockNumber;
|
||||
_this._balances = newBalances;
|
||||
});
|
||||
return null;
|
||||
}).catch(function (error) { });
|
||||
this.doPoll();
|
||||
};
|
||||
Provider.prototype.resetEventsBlock = function (blockNumber) {
|
||||
@ -11449,6 +11466,7 @@ var Provider = /** @class */ (function () {
|
||||
}
|
||||
promises.push(this.resolveName(result[key]).then(function (address) {
|
||||
result[key] = address;
|
||||
return;
|
||||
}));
|
||||
}, this);
|
||||
return Promise.all(promises).then(function () { return result; });
|
||||
@ -13490,6 +13508,7 @@ function resolveProperties(object) {
|
||||
if (value instanceof Promise) {
|
||||
promises.push(value.then(function (value) {
|
||||
result[key] = value;
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
else {
|
||||
@ -14378,7 +14397,7 @@ function poll(func, options) {
|
||||
}
|
||||
var attempt = 0;
|
||||
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 (result !== undefined) {
|
||||
if (cancel()) {
|
||||
@ -14400,6 +14419,7 @@ function poll(func, options) {
|
||||
}
|
||||
setTimeout(check, timeout);
|
||||
}
|
||||
return null;
|
||||
}, function (error) {
|
||||
if (cancel()) {
|
||||
reject(error);
|
||||
@ -15315,37 +15335,21 @@ var Wallet = /** @class */ (function (_super) {
|
||||
return Wallet.fromMnemonic(mnemonic, options.path, options.locale);
|
||||
};
|
||||
Wallet.fromEncryptedJson = function (json, password, progressCallback) {
|
||||
if (progressCallback && typeof (progressCallback) !== 'function') {
|
||||
throw new Error('invalid callback');
|
||||
if (secretStorage.isCrowdsaleWallet(json)) {
|
||||
try {
|
||||
var privateKey = secretStorage.decryptCrowdsale(json, password);
|
||||
return Promise.resolve(new Wallet(privateKey));
|
||||
}
|
||||
catch (error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
}
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (secretStorage.isCrowdsaleWallet(json)) {
|
||||
try {
|
||||
var privateKey = secretStorage.decryptCrowdsale(json, password);
|
||||
resolve(new Wallet(privateKey));
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}
|
||||
else if (secretStorage.isValidWallet(json)) {
|
||||
secretStorage.decrypt(json, password, progressCallback).then(function (signingKey) {
|
||||
var wallet = new Wallet(signingKey);
|
||||
/*
|
||||
if (signingKey.mnemonic && signingKey.path) {
|
||||
wallet.mnemonic = signingKey.mnemonic;
|
||||
wallet.path = signingKey.path;
|
||||
}
|
||||
*/
|
||||
resolve(wallet);
|
||||
}, function (error) {
|
||||
reject(error);
|
||||
});
|
||||
}
|
||||
else {
|
||||
reject('invalid wallet JSON');
|
||||
}
|
||||
});
|
||||
else if (secretStorage.isValidWallet(json)) {
|
||||
return secretStorage.decrypt(json, password, progressCallback).then(function (signingKey) {
|
||||
return new Wallet(signingKey);
|
||||
});
|
||||
}
|
||||
return Promise.reject('invalid wallet JSON');
|
||||
};
|
||||
Wallet.fromMnemonic = function (mnemonic, path, wordlist) {
|
||||
if (!path) {
|
||||
|
2
dist/ethers.min.js
vendored
2
dist/ethers.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/ethers.min.js.map
vendored
2
dist/ethers.min.js.map
vendored
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) {
|
||||
txs[log.transactionHash] = tx.blockHash;
|
||||
log.blockHash = tx.blockHash;
|
||||
return null;
|
||||
});
|
||||
}
|
||||
return null;
|
||||
|
@ -94,12 +94,12 @@ var FallbackProvider = /** @class */ (function (_super) {
|
||||
}
|
||||
var provider = providers.shift();
|
||||
provider.perform(method, params).then(function (result) {
|
||||
resolve(result);
|
||||
}, function (error) {
|
||||
return resolve(result);
|
||||
}).catch(function (error) {
|
||||
if (!firstError) {
|
||||
firstError = error;
|
||||
}
|
||||
next();
|
||||
setTimeout(next, 0);
|
||||
});
|
||||
}
|
||||
next();
|
||||
|
@ -181,8 +181,9 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
||||
var ready = new Promise(function (resolve, reject) {
|
||||
setTimeout(function () {
|
||||
_this.send('net_version', []).then(function (result) {
|
||||
var chainId = parseInt(result);
|
||||
resolve(networks_1.getNetwork(chainId));
|
||||
return resolve(networks_1.getNetwork(parseInt(result)));
|
||||
}).catch(function (error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -282,6 +283,7 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
||||
seq = seq.then(function () {
|
||||
return self.getTransaction(hash).then(function (tx) {
|
||||
self.emit('pending', tx);
|
||||
return null;
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -294,11 +296,12 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
||||
return;
|
||||
}
|
||||
setTimeout(function () { poll(); }, 0);
|
||||
});
|
||||
return null;
|
||||
}).catch(function (error) { });
|
||||
}
|
||||
poll();
|
||||
return filterId;
|
||||
});
|
||||
}).catch(function (error) { });
|
||||
};
|
||||
JsonRpcProvider.prototype._stopPending = function () {
|
||||
this._pendingFilter = null;
|
||||
|
@ -573,7 +573,8 @@ var Provider = /** @class */ (function () {
|
||||
}
|
||||
_this._emitted['t:' + event.hash.toLowerCase()] = receipt.blockNumber;
|
||||
_this.emit(event.hash, receipt);
|
||||
});
|
||||
return null;
|
||||
}).catch(function (error) { });
|
||||
}
|
||||
else if (event.type === 'address') {
|
||||
if (_this._balances[event.address]) {
|
||||
@ -586,7 +587,8 @@ var Provider = /** @class */ (function () {
|
||||
}
|
||||
this._balances[event.address] = balance;
|
||||
this.emit(event.address, balance);
|
||||
});
|
||||
return null;
|
||||
}).catch(function (error) { });
|
||||
}
|
||||
else if (event.type === 'topic') {
|
||||
_this.getLogs({
|
||||
@ -602,12 +604,14 @@ var Provider = /** @class */ (function () {
|
||||
_this._emitted['t:' + log.transactionHash.toLowerCase()] = log.blockNumber;
|
||||
_this.emit(event.topic, log);
|
||||
});
|
||||
});
|
||||
return null;
|
||||
}).catch(function (error) { });
|
||||
}
|
||||
});
|
||||
_this._lastBlockNumber = blockNumber;
|
||||
_this._balances = newBalances;
|
||||
});
|
||||
return null;
|
||||
}).catch(function (error) { });
|
||||
this.doPoll();
|
||||
};
|
||||
Provider.prototype.resetEventsBlock = function (blockNumber) {
|
||||
@ -958,6 +962,7 @@ var Provider = /** @class */ (function () {
|
||||
}
|
||||
promises.push(this.resolveName(result[key]).then(function (address) {
|
||||
result[key] = address;
|
||||
return;
|
||||
}));
|
||||
}, this);
|
||||
return Promise.all(promises).then(function () { return result; });
|
||||
|
@ -238,7 +238,13 @@ export class Contract {
|
||||
}
|
||||
|
||||
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) => {
|
||||
var run = runMethod(this, name, false);
|
||||
@ -265,7 +271,7 @@ export class Contract {
|
||||
function handleEvent(log: any): void {
|
||||
contract.addressPromise.then((address) => {
|
||||
// Not meant for us (the topics just has the same name)
|
||||
if (address != log.address) { return; }
|
||||
if (address != log.address) { return null; }
|
||||
|
||||
try {
|
||||
let result = eventInfo.decode(log.data, log.topics);
|
||||
@ -289,7 +295,9 @@ export class Contract {
|
||||
let onerror = contract._onerror;
|
||||
if (onerror) { setTimeout(() => { onerror(error); }); }
|
||||
}
|
||||
});
|
||||
|
||||
return null;
|
||||
}).catch((error) => { });
|
||||
}
|
||||
|
||||
var property = {
|
||||
|
@ -225,6 +225,7 @@ export class EtherscanProvider extends Provider{
|
||||
return self.getTransaction(log.transactionHash).then(function(tx) {
|
||||
txs[log.transactionHash] = tx.blockHash;
|
||||
log.blockHash = tx.blockHash;
|
||||
return null;
|
||||
});
|
||||
}
|
||||
return null;
|
||||
|
@ -89,11 +89,11 @@ export class FallbackProvider extends Provider {
|
||||
}
|
||||
|
||||
var provider = providers.shift();
|
||||
provider.perform(method, params).then(function(result) {
|
||||
resolve(result);
|
||||
}, function (error) {
|
||||
provider.perform(method, params).then((result) => {
|
||||
return resolve(result);
|
||||
}).catch((error) => {
|
||||
if (!firstError) { firstError = error; }
|
||||
next();
|
||||
setTimeout(next, 0);
|
||||
});
|
||||
}
|
||||
next();
|
||||
|
@ -177,9 +177,9 @@ export class JsonRpcProvider extends Provider {
|
||||
let ready: Promise<Network> = new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
this.send('net_version', [ ]).then((result) => {
|
||||
let chainId = parseInt(result);
|
||||
|
||||
resolve(getNetwork(chainId));
|
||||
return resolve(getNetwork(parseInt(result)));
|
||||
}).catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -297,6 +297,7 @@ export class JsonRpcProvider extends Provider {
|
||||
seq = seq.then(function() {
|
||||
return self.getTransaction(hash).then(function(tx) {
|
||||
self.emit('pending', tx);
|
||||
return null;
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -310,12 +311,14 @@ export class JsonRpcProvider extends Provider {
|
||||
return;
|
||||
}
|
||||
setTimeout(function() { poll(); }, 0);
|
||||
});
|
||||
|
||||
return null;
|
||||
}).catch((error: Error) => { });
|
||||
}
|
||||
poll();
|
||||
|
||||
return filterId;
|
||||
});
|
||||
}).catch((error: Error) => { });
|
||||
}
|
||||
|
||||
_stopPending(): void {
|
||||
|
@ -749,7 +749,8 @@ export class Provider {
|
||||
if (!receipt || receipt.blockNumber == null) { return; }
|
||||
this._emitted['t:' + event.hash.toLowerCase()] = receipt.blockNumber;
|
||||
this.emit(event.hash, receipt);
|
||||
});
|
||||
return null;
|
||||
}).catch((error: Error) => { });
|
||||
|
||||
} else if (event.type === 'address') {
|
||||
if (this._balances[event.address]) {
|
||||
@ -760,7 +761,8 @@ export class Provider {
|
||||
if (lastBalance && balance.eq(lastBalance)) { return; }
|
||||
this._balances[event.address] = balance;
|
||||
this.emit(event.address, balance);
|
||||
});
|
||||
return null;
|
||||
}).catch((error: Error) => { });
|
||||
|
||||
} else if (event.type === 'topic') {
|
||||
this.getLogs({
|
||||
@ -774,14 +776,17 @@ export class Provider {
|
||||
this._emitted['t:' + log.transactionHash.toLowerCase()] = log.blockNumber;
|
||||
this.emit(event.topic, log);
|
||||
});
|
||||
});
|
||||
return null;
|
||||
}).catch((error: Error) => { });
|
||||
}
|
||||
});
|
||||
|
||||
this._lastBlockNumber = blockNumber;
|
||||
|
||||
this._balances = newBalances;
|
||||
});
|
||||
|
||||
return null;
|
||||
}).catch((error: Error) => { });
|
||||
this.doPoll();
|
||||
}
|
||||
|
||||
@ -1126,6 +1131,7 @@ export class Provider {
|
||||
if (result[key] == null) { return; }
|
||||
promises.push(this.resolveName(result[key]).then((address: string) => {
|
||||
result[key] = address;
|
||||
return;
|
||||
}));
|
||||
}, this);
|
||||
|
||||
|
@ -26,6 +26,7 @@ export function resolveProperties(object: any): Promise<any> {
|
||||
promises.push(
|
||||
value.then((value) => {
|
||||
result[key] = value;
|
||||
return null;
|
||||
})
|
||||
);
|
||||
} else {
|
||||
|
@ -159,7 +159,7 @@ export function poll(func: () => Promise<any>, options?: PollOptions): Promise<a
|
||||
|
||||
let attempt = 0;
|
||||
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 (result !== undefined) {
|
||||
@ -178,6 +178,8 @@ export function poll(func: () => Promise<any>, options?: PollOptions): Promise<a
|
||||
|
||||
setTimeout(check, timeout);
|
||||
}
|
||||
|
||||
return null;
|
||||
}, function(error) {
|
||||
if (cancel()) { reject(error); }
|
||||
});
|
||||
|
@ -167,39 +167,22 @@ export class Wallet extends Signer {
|
||||
}
|
||||
|
||||
static fromEncryptedJson(json: string, password: Arrayish, progressCallback: ProgressCallback): Promise<Wallet> {
|
||||
if (progressCallback && typeof(progressCallback) !== 'function') {
|
||||
throw new Error('invalid callback');
|
||||
if (secretStorage.isCrowdsaleWallet(json)) {
|
||||
try {
|
||||
let privateKey = secretStorage.decryptCrowdsale(json, password);
|
||||
return Promise.resolve(new Wallet(privateKey));
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
} else if (secretStorage.isValidWallet(json)) {
|
||||
|
||||
return secretStorage.decrypt(json, password, progressCallback).then(function(signingKey) {
|
||||
return new Wallet(signingKey);
|
||||
});
|
||||
}
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
|
||||
if (secretStorage.isCrowdsaleWallet(json)) {
|
||||
try {
|
||||
var privateKey = secretStorage.decryptCrowdsale(json, password);
|
||||
resolve(new Wallet(privateKey));
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
|
||||
} else if (secretStorage.isValidWallet(json)) {
|
||||
|
||||
secretStorage.decrypt(json, password, progressCallback).then(function(signingKey) {
|
||||
var wallet = new Wallet(signingKey);
|
||||
/*
|
||||
if (signingKey.mnemonic && signingKey.path) {
|
||||
wallet.mnemonic = signingKey.mnemonic;
|
||||
wallet.path = signingKey.path;
|
||||
}
|
||||
*/
|
||||
resolve(wallet);
|
||||
}, function(error) {
|
||||
reject(error);
|
||||
});
|
||||
|
||||
} else {
|
||||
reject('invalid wallet JSON');
|
||||
}
|
||||
});
|
||||
return Promise.reject('invalid wallet JSON');
|
||||
}
|
||||
|
||||
static fromMnemonic(mnemonic: string, path?: string, wordlist?: Wordlist): Wallet {
|
||||
|
@ -24,6 +24,7 @@ function resolveProperties(object) {
|
||||
if (value instanceof Promise) {
|
||||
promises.push(value.then(function (value) {
|
||||
result[key] = value;
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
else {
|
||||
|
@ -138,7 +138,7 @@ function poll(func, options) {
|
||||
}
|
||||
var attempt = 0;
|
||||
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 (result !== undefined) {
|
||||
if (cancel()) {
|
||||
@ -160,6 +160,7 @@ function poll(func, options) {
|
||||
}
|
||||
setTimeout(check, timeout);
|
||||
}
|
||||
return null;
|
||||
}, function (error) {
|
||||
if (cancel()) {
|
||||
reject(error);
|
||||
|
@ -163,37 +163,21 @@ var Wallet = /** @class */ (function (_super) {
|
||||
return Wallet.fromMnemonic(mnemonic, options.path, options.locale);
|
||||
};
|
||||
Wallet.fromEncryptedJson = function (json, password, progressCallback) {
|
||||
if (progressCallback && typeof (progressCallback) !== 'function') {
|
||||
throw new Error('invalid callback');
|
||||
if (secretStorage.isCrowdsaleWallet(json)) {
|
||||
try {
|
||||
var privateKey = secretStorage.decryptCrowdsale(json, password);
|
||||
return Promise.resolve(new Wallet(privateKey));
|
||||
}
|
||||
catch (error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
}
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (secretStorage.isCrowdsaleWallet(json)) {
|
||||
try {
|
||||
var privateKey = secretStorage.decryptCrowdsale(json, password);
|
||||
resolve(new Wallet(privateKey));
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}
|
||||
else if (secretStorage.isValidWallet(json)) {
|
||||
secretStorage.decrypt(json, password, progressCallback).then(function (signingKey) {
|
||||
var wallet = new Wallet(signingKey);
|
||||
/*
|
||||
if (signingKey.mnemonic && signingKey.path) {
|
||||
wallet.mnemonic = signingKey.mnemonic;
|
||||
wallet.path = signingKey.path;
|
||||
}
|
||||
*/
|
||||
resolve(wallet);
|
||||
}, function (error) {
|
||||
reject(error);
|
||||
});
|
||||
}
|
||||
else {
|
||||
reject('invalid wallet JSON');
|
||||
}
|
||||
});
|
||||
else if (secretStorage.isValidWallet(json)) {
|
||||
return secretStorage.decrypt(json, password, progressCallback).then(function (signingKey) {
|
||||
return new Wallet(signingKey);
|
||||
});
|
||||
}
|
||||
return Promise.reject('invalid wallet JSON');
|
||||
};
|
||||
Wallet.fromMnemonic = function (mnemonic, path, wordlist) {
|
||||
if (!path) {
|
||||
|
Loading…
Reference in New Issue
Block a user