Skip to content

Commit

Permalink
Merge pull request #432 from JoinColony/fix/430-add-verbose-mode
Browse files Browse the repository at this point in the history
Add verbse option to ContractClient
  • Loading branch information
ryanchristo committed Jul 10, 2019
2 parents d22322f + 12cb19b commit 34e086e
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## next

**New Features**

* Add `verbose` option to `ContractClient` (`@colony/colony-js-contract-client`)
* Add `verbose` option to `getColonyClient` method (`@colony/colony-js-client`)
* Add `verbose` option to `getNetworkClient` method (`@colony/colony-js-client`)

**Bug Fixes**

* Fix parameters in `makeExecuteTaskRoleChange` (`@colony/colony-js-client`)
Expand Down
4 changes: 3 additions & 1 deletion packages/colony-js-client/src/ColonyClient/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1918,12 +1918,13 @@ export default class ColonyClient extends ContractClient {
query,
tokenClient,
tokenLockingClient,
verbose,
}: {
networkClient?: ColonyNetworkClient,
tokenClient?: TokenClient,
tokenLockingClient?: TokenLockingClient,
} & ContractClientConstructorArgs) {
super({ adapter, query });
super({ adapter, query, verbose });

if (!(networkClient instanceof ColonyNetworkClient))
throw new Error(
Expand Down Expand Up @@ -1980,6 +1981,7 @@ export default class ColonyClient extends ContractClient {
const tokenClient = new this.constructor.TokenClient({
adapter: this.adapter,
query: { contractAddress: tokenAddress },
verbose: this.verbose,
});
await tokenClient.init();
return tokenClient;
Expand Down
3 changes: 3 additions & 0 deletions packages/colony-js-client/src/ColonyNetworkClient/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,7 @@ export default class ColonyNetworkClient extends ContractClient {
networkClient: this,
query: { contractAddress },
tokenLockingClient,
verbose: this.verbose,
});
await colonyClient.init();
return colonyClient;
Expand Down Expand Up @@ -1048,6 +1049,7 @@ export default class ColonyNetworkClient extends ContractClient {
networkClient: this,
query: { contractAddress, contractName: 'IMetaColony' },
tokenLockingClient,
verbose: this.verbose,
});
await metaColonyClient.init();
return metaColonyClient;
Expand All @@ -1073,6 +1075,7 @@ export default class ColonyNetworkClient extends ContractClient {
adapter: this.adapter,
networkClient: this,
query: { contractAddress },
verbose: this.verbose,
});
await tokenLockingClient.init();
return tokenLockingClient;
Expand Down
2 changes: 2 additions & 0 deletions packages/colony-js-client/src/getColonyClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ const getColonyClient = async (
network: string,
wallet: WalletObjectType,
infuraProjectId?: string,
verbose?: boolean,
) => {
const networkClient = await getNetworkClient(
network,
wallet,
infuraProjectId,
verbose,
);
return networkClient.getColonyClientByAddress(address);
};
Expand Down
7 changes: 6 additions & 1 deletion packages/colony-js-client/src/getNetworkClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const getNetworkClient = async (
network: string,
wallet: WalletObjectType,
infuraProjectId?: string,
verbose?: boolean,
) => {
let loader;
let provider;
Expand Down Expand Up @@ -82,7 +83,11 @@ const getNetworkClient = async (
});

// Initialize network client using ethers adapter and default query
const networkClient = new ColonyNetworkClient({ adapter, query: {} });
const networkClient = new ColonyNetworkClient({
adapter,
query: {},
verbose,
});
await networkClient.init();

return networkClient;
Expand Down
13 changes: 10 additions & 3 deletions packages/colony-js-contract-client/src/classes/ContractClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export default class ContractClient {
// Mapping of event topics to ContractEvents
eventSignatures = {};

// Show additional logs
verbose: ?boolean;

// Static getters used in lieu of named exports; this package only has
// one export.
static get Caller(): typeof ContractMethodCaller {
Expand Down Expand Up @@ -68,9 +71,10 @@ export default class ContractClient {
return {};
}

constructor({ adapter, query }: ContractClientConstructorArgs) {
constructor({ adapter, query, verbose }: ContractClientConstructorArgs) {
this.adapter = adapter;
this._query = Object.assign({}, this.constructor.defaultQuery, query);
this.verbose = verbose;
}

get contract() {
Expand Down Expand Up @@ -269,7 +273,8 @@ export default class ContractClient {
}

// Allow initialising of clients where some events may be missing in the
// ABI, due to changing of events on the contract.
// ABI, due to changing of events on the contract and then log the error
// as a warning if the client is initialized in verbose mode.
try {
const event = new ContractEvent({
eventName,
Expand All @@ -285,7 +290,9 @@ export default class ContractClient {
[event.interface.topics[0]]: event,
});
} catch (error) {
console.info(error);
if (this.verbose) {
console.warn(`WARNING: ${error.message}`);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class ContractEvent<ParamTypes: Object> {
this.argsDef = argsDef;

if (!this.interface)
throw new Error(`No such event "${eventName}" on this contract`);
throw new Error(`No such event "${eventName}" in loaded ABI`);

this._wrappedHandlers = new Map();
this.assertValid = makeAssert(`Validation failed for event ${eventName}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type ContractResponse<EventData> = {
export type ContractClientConstructorArgs = {
adapter: IAdapter,
query: ?Query,
verbose: ?boolean,
};

export type ValidateEmpty = (
Expand Down

0 comments on commit 34e086e

Please sign in to comment.