implement logger
MODIFY
src/constant.ts
src/constant.ts
import { MaticWeb3Client } from "./inherited";
+import { Logger } from "./utils";
export let Web3Client: typeof MaticWeb3Client;
@@ -7,3 +8,4 @@ export const setWeb3Client = (web3Client) => {
}
export const EXTRA_GAS_FOR_PROXY_CALL = 1000000
+export const LOGGER = new Logger();

MODIFY
src/inherited/eth_method.ts
src/inherited/eth_method.ts
@@ -2,16 +2,16 @@ import { BaseContractMethod } from "../abstracts";
import { ITransactionConfig } from "../interfaces";
import { TransactionObject } from "web3/eth/types";
import { doNothing } from "../helpers";
+import { LOGGER } from "../constant";
export class EthMethod extends BaseContractMethod {
constructor(private method: TransactionObject<any>) {
super();
- console.log("method args", method.arguments);
}
read<T>(tx: ITransactionConfig): Promise<T> {
- console.log("args", arguments);
+ LOGGER.log("sending tx with config", tx);
return this.method.call(tx as any);
}
@@ -22,7 +22,8 @@ export class EthMethod extends BaseContractMethod {
onError: doNothing
};
setTimeout(() => {
- console.log("sending tx", tx);
+ LOGGER.log("sending tx with config", tx);
+
// {
// chainId: tx.chainId,
// data: tx.data,
@@ -46,7 +47,6 @@ export class EthMethod extends BaseContractMethod {
}
estimateGas(tx: ITransactionConfig): Promise<number> {
- console.log("args", arguments);
return this.method.estimateGas(tx as any);
}

MODIFY
src/interfaces/plasma_client_config.ts
src/interfaces/plasma_client_config.ts
@@ -14,4 +14,5 @@ export interface IPlasmaClientConfig {
}
};
depositManager?: string;
+ log?: boolean;
}
\ No newline at end of file

MODIFY
src/plasma/erc20.ts
src/plasma/erc20.ts
@@ -30,7 +30,6 @@ export class ERC20 extends BaseToken {
txConfig: {},
defaultTxConfig: this.childDefaultConfig,
}).then(config => {
- console.log("config", config);
return method.read<string>(config);
});
}
@@ -42,7 +41,6 @@ export class ERC20 extends BaseToken {
this.depositManager.contract.address,
formatAmount(amount)
);
- console.log("arguments approve", arguments);
const result = eventBusPromise((res, rej) => {
// tslint:disable-next-line
this.createTransactionConfig(
@@ -52,7 +50,6 @@ export class ERC20 extends BaseToken {
method,
isParent: true
}).then(config => {
- console.log("config", config);
const methodResult = method.write(
config,
);
@@ -72,7 +69,6 @@ export class ERC20 extends BaseToken {
}) as IEventBusPromise<any>;
});
return result;
-
}
}
\ No newline at end of file

MODIFY
src/plasma/index.ts
src/plasma/index.ts
@@ -2,6 +2,7 @@ import { ERC20 } from "./erc20";
import { Web3SideChainClient } from "../model";
import { IPlasmaClientConfig } from "../interfaces";
import { DepositManager } from "./deposit_manager";
+import { LOGGER } from "../constant";
export class PlasmaClient {
@@ -39,6 +40,8 @@ export class PlasmaClient {
config.depositManager,
this.client_.getABI("DepositManager")
);
+
+ LOGGER.enableLog(config.log);
}
}
\ No newline at end of file

MODIFY
src/utils/index.ts
src/utils/index.ts
export * from "./use";
export * from "./format_amount";
export * from "./event_bus";
+export * from "./logger";
\ No newline at end of file

ADD
src/utils/logger.ts
+export class Logger {
+
+ private isEnabled: boolean;
+
+ enableLog(value) {
+ this.isEnabled = true;
+ }
+
+ log(...message) {
+ if (this.isEnabled) {
+ console.log(...message);
+ }
+ }
+}
\ No newline at end of file

implement logger