return undefined if not address found

This commit is contained in:
Fabio Berger 2017-05-26 17:49:16 +02:00
parent a6da9cd073
commit 0aabade166

View File

@ -12,7 +12,7 @@ export class Web3Wrapper {
public isAddress(address: string): boolean { public isAddress(address: string): boolean {
return this.web3.isAddress(address); return this.web3.isAddress(address);
} }
public async getSenderAddressIfExistsAsync(): Promise<string> { public async getSenderAddressIfExistsAsync(): Promise<string|undefined> {
const defaultAccount = this.web3.eth.defaultAccount; const defaultAccount = this.web3.eth.defaultAccount;
if (!_.isUndefined(defaultAccount)) { if (!_.isUndefined(defaultAccount)) {
return defaultAccount; return defaultAccount;
@ -20,10 +20,10 @@ export class Web3Wrapper {
const firstAccount = await this.getFirstAddressIfExistsAsync(); const firstAccount = await this.getFirstAddressIfExistsAsync();
return firstAccount; return firstAccount;
} }
public async getFirstAddressIfExistsAsync(): Promise<string> { public async getFirstAddressIfExistsAsync(): Promise<string|undefined> {
const addresses = await promisify(this.web3.eth.getAccounts)(); const addresses = await promisify(this.web3.eth.getAccounts)();
if (_.isEmpty(addresses)) { if (_.isEmpty(addresses)) {
return ''; return undefined;
} }
return (addresses as string[])[0]; return (addresses as string[])[0];
} }