Skip to content

Commit

Permalink
Updating style.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed May 1, 2020
1 parent 83fba3d commit 1e21eb0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 36 deletions.
36 changes: 18 additions & 18 deletions packages/abstract-signer/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,28 @@ export abstract class Signer {
///////////////////
// Sub-classes MAY override these

getBalance(blockTag?: BlockTag): Promise<BigNumber> {
async getBalance(blockTag?: BlockTag): Promise<BigNumber> {
this._checkProvider("getBalance");
return this.provider.getBalance(this.getAddress(), blockTag);
return await this.provider.getBalance(this.getAddress(), blockTag);
}

getTransactionCount(blockTag?: BlockTag): Promise<number> {
async getTransactionCount(blockTag?: BlockTag): Promise<number> {
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<BigNumber> {
async estimateGas(transaction: TransactionRequest): Promise<BigNumber> {
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<string> {
async call(transaction: TransactionRequest, blockTag?: BlockTag): Promise<string> {
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
Expand All @@ -102,19 +100,20 @@ export abstract class Signer {
});
}

getChainId(): Promise<number> {
async getChainId(): Promise<number> {
this._checkProvider("getChainId");
return this.provider.getNetwork().then((network) => network.chainId);
const network = await this.provider.getNetwork();
return network.chainId;
}

getGasPrice(): Promise<BigNumber> {
async getGasPrice(): Promise<BigNumber> {
this._checkProvider("getGasPrice");
return this.provider.getGasPrice();
return await this.provider.getGasPrice();
}

resolveName(name: string): Promise<string> {
async resolveName(name: string): Promise<string> {
this._checkProvider("resolveName");
return this.provider.resolveName(name);
return await this.provider.resolveName(name);
}


Expand Down Expand Up @@ -161,6 +160,7 @@ export abstract class Signer {
// By default called from: (overriding these prevents it)
// - sendTransaction
async populateTransaction(transaction: TransactionRequest): Promise<TransactionRequest> {

const tx: TransactionRequest = await resolveProperties(this.checkTransaction(transaction))

if (tx.to != null) { tx.to = Promise.resolve(tx.to).then((to) => this.resolveName(to)); }
Expand Down
26 changes: 9 additions & 17 deletions packages/properties/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,19 @@ export type Resolvable<T> = {
}

type Result = { key: string, value: any};
export function resolveProperties<T>(object: Resolvable<T>): Promise<Similar<T>> {

export async function resolveProperties<T>(object: Readonly<Resolvable<T>>): Promise<Similar<T>> {
const promises: Array<Promise<Result>> = Object.keys(object).map((key) => {
const value = (<any>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[<keyof Resolvable<T>>key];
return Promise.resolve(value).then((v) => ({ key: key, value: v }));
});

return Promise.all(promises).then((results) => {
const result: any = { };
return (<Similar<T>>(results.reduce((accum, result) => {
accum[result.key] = result.value;
return accum;
}, result)));
});
const results = await Promise.all(promises);

return results.reduce((accum, result) => {
accum[<keyof Similar<T>>(result.key)] = result.value;
return accum;
}, <Similar<T>>{ });
}

export function checkProperties(object: any, properties: { [ name: string ]: boolean }): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/providers/src.ts/fallback-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
}

Expand Down

0 comments on commit 1e21eb0

Please sign in to comment.