diff --git a/packages/abstract-signer/src.ts/index.ts b/packages/abstract-signer/src.ts/index.ts index 6f0cbba5e4..985070e387 100644 --- a/packages/abstract-signer/src.ts/index.ts +++ b/packages/abstract-signer/src.ts/index.ts @@ -66,30 +66,28 @@ export abstract class Signer { /////////////////// // Sub-classes MAY override these - getBalance(blockTag?: BlockTag): Promise { + async getBalance(blockTag?: BlockTag): Promise { this._checkProvider("getBalance"); - return this.provider.getBalance(this.getAddress(), blockTag); + return await this.provider.getBalance(this.getAddress(), blockTag); } - getTransactionCount(blockTag?: BlockTag): Promise { + async getTransactionCount(blockTag?: BlockTag): Promise { this._checkProvider("getTransactionCount"); - return this.provider.getTransactionCount(this.getAddress(), blockTag); + return await this.provider.getTransactionCount(this.getAddress(), blockTag); } // Populates "from" if unspecified, and estimates the gas for the transation - estimateGas(transaction: TransactionRequest): Promise { + async estimateGas(transaction: TransactionRequest): Promise { this._checkProvider("estimateGas"); - return resolveProperties(this.checkTransaction(transaction)).then((tx) => { - return this.provider.estimateGas(tx); - }); + const tx = await resolveProperties(this.checkTransaction(transaction)); + return await this.provider.estimateGas(tx); } // Populates "from" if unspecified, and calls with the transation - call(transaction: TransactionRequest, blockTag?: BlockTag): Promise { + async call(transaction: TransactionRequest, blockTag?: BlockTag): Promise { this._checkProvider("call"); - return resolveProperties(this.checkTransaction(transaction)).then((tx) => { - return this.provider.call(tx, blockTag); - }); + const tx = await resolveProperties(this.checkTransaction(transaction)); + return await this.provider.call(tx, blockTag); } // Populates all fields in a transaction, signs it and sends it to the network @@ -102,19 +100,20 @@ export abstract class Signer { }); } - getChainId(): Promise { + async getChainId(): Promise { this._checkProvider("getChainId"); - return this.provider.getNetwork().then((network) => network.chainId); + const network = await this.provider.getNetwork(); + return network.chainId; } - getGasPrice(): Promise { + async getGasPrice(): Promise { this._checkProvider("getGasPrice"); - return this.provider.getGasPrice(); + return await this.provider.getGasPrice(); } - resolveName(name: string): Promise { + async resolveName(name: string): Promise { this._checkProvider("resolveName"); - return this.provider.resolveName(name); + return await this.provider.resolveName(name); } @@ -161,6 +160,7 @@ export abstract class Signer { // By default called from: (overriding these prevents it) // - sendTransaction async populateTransaction(transaction: TransactionRequest): Promise { + const tx: TransactionRequest = await resolveProperties(this.checkTransaction(transaction)) if (tx.to != null) { tx.to = Promise.resolve(tx.to).then((to) => this.resolveName(to)); } diff --git a/packages/properties/src.ts/index.ts b/packages/properties/src.ts/index.ts index 7dd657d1f9..f77608750b 100644 --- a/packages/properties/src.ts/index.ts +++ b/packages/properties/src.ts/index.ts @@ -31,27 +31,19 @@ export type Resolvable = { } type Result = { key: string, value: any}; -export function resolveProperties(object: Resolvable): Promise> { +export async function resolveProperties(object: Readonly>): Promise> { const promises: Array> = Object.keys(object).map((key) => { - const value = (object)[key]; - - if (!(value instanceof Promise)) { - return Promise.resolve({ key: key, value: value }); - } - - return value.then((value) => { - return { key: key, value: value }; - }); + const value = object[>key]; + return Promise.resolve(value).then((v) => ({ key: key, value: v })); }); - return Promise.all(promises).then((results) => { - const result: any = { }; - return (>(results.reduce((accum, result) => { - accum[result.key] = result.value; - return accum; - }, result))); - }); + const results = await Promise.all(promises); + + return results.reduce((accum, result) => { + accum[>(result.key)] = result.value; + return accum; + }, >{ }); } export function checkProperties(object: any, properties: { [ name: string ]: boolean }): void { diff --git a/packages/providers/src.ts/fallback-provider.ts b/packages/providers/src.ts/fallback-provider.ts index 2112e2318f..c4acc79b60 100644 --- a/packages/providers/src.ts/fallback-provider.ts +++ b/packages/providers/src.ts/fallback-provider.ts @@ -387,7 +387,7 @@ export class FallbackProvider extends BaseProvider { } // They were all an error; pick the first error - return Promise.reject(results[0].error); + return Promise.reject(results[0]); }); }