diff options
author | Fabio Berger <me@fabioberger.com> | 2017-06-02 22:06:26 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-06-02 22:06:26 +0800 |
commit | 844f138908a30fa6daa904beafab85823c6d47d7 (patch) | |
tree | be2402e849e6c67acd27ccb323cd39a08ea103d8 /src/web3_wrapper.ts | |
parent | b8ff2468776e1c784ff50e5ada1c633ee0d3aeda (diff) | |
download | dexon-0x-contracts-844f138908a30fa6daa904beafab85823c6d47d7.tar.gz dexon-0x-contracts-844f138908a30fa6daa904beafab85823c6d47d7.tar.zst dexon-0x-contracts-844f138908a30fa6daa904beafab85823c6d47d7.zip |
Add setAllowanceAsync, getAllowanceAsync and transferFrom to tokenWrapper
Diffstat (limited to 'src/web3_wrapper.ts')
-rw-r--r-- | src/web3_wrapper.ts | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index e65f29b56..93203ff38 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -24,11 +24,15 @@ export class Web3Wrapper { return firstAccount; } public async getFirstAddressIfExistsAsync(): Promise<string|undefined> { - const addresses = await promisify(this.web3.eth.getAccounts)(); + const addresses = await this.getAvailableSenderAddressesAsync(); if (_.isEmpty(addresses)) { return undefined; } - return (addresses as string[])[0]; + return addresses[0]; + } + public async isSenderAddressAvailable(senderAddress: string): Promise<boolean> { + const addresses = await this.getAvailableSenderAddressesAsync(); + return _.includes(addresses, senderAddress); } public async getNodeVersionAsync(): Promise<string> { const nodeVersion = await promisify(this.web3.version.getNode)(); @@ -64,6 +68,10 @@ export class Web3Wrapper { const {timestamp} = await promisify(this.web3.eth.getBlock)(blockHash); return timestamp; } + private async getAvailableSenderAddressesAsync(): Promise<string[]> { + const addresses: string[] = await promisify(this.web3.eth.getAccounts)(); + return addresses; + } private async getNetworkAsync(): Promise<number> { const networkId = await promisify(this.web3.version.getNetwork)(); return networkId; |