implement transaction write result
MODIFY
package.json
package.json
{
"name": "@maticnetwork/maticjs",
- "version": "3.0.0-beta.14",
+ "version": "3.0.0-beta.15",
"description": "Javascript developer library for interacting with Matic Network",
"main": "dist/npm.export.js",
"types": "dist/ts/index.d.ts",

MODIFY
src/helpers/contract_write_result.ts
src/helpers/contract_write_result.ts
-import { ITransactionWriteResult, ITransactionReceipt } from "../interfaces";
+// import { ITransactionWriteResult, ITransactionReceipt } from "../interfaces";
-export class ContractWriteResult {
- private txHashPromise: Promise<string>;
- private receiptPromise: Promise<ITransactionReceipt>;
+// export class ContractWriteResult {
+// private txHashPromise: Promise<string>;
+// private receiptPromise: Promise<ITransactionReceipt>;
- constructor(private result_: ITransactionWriteResult) {
- if (!result_.getTransactionHash) {
- this.txHashPromise = new Promise((res, rej) => {
- result_.onTransactionHash = res;
- result_.onTxError = rej;
- });
- }
+// constructor(private result_: ITransactionWriteResult) {
+// if (!result_.getTransactionHash) {
+// this.txHashPromise = new Promise((res, rej) => {
+// result_.onTransactionHash = res;
+// result_.onTxError = rej;
+// });
+// }
- if (!result_.getReceipt) {
- this.receiptPromise = new Promise((res, rej) => {
- result_.onReceipt = res;
- result_.onReceiptError = rej;
- });
- }
- }
+// if (!result_.getReceipt) {
+// this.receiptPromise = new Promise((res, rej) => {
+// result_.onReceipt = res;
+// result_.onReceiptError = rej;
+// });
+// }
+// }
- getTransactionHash() {
- const fn = this.result_.getTransactionHash;
- if (fn) {
- return fn();
- }
- return this.txHashPromise;
- }
+// getTransactionHash() {
+// const fn = this.result_.getTransactionHash;
+// if (fn) {
+// return fn();
+// }
+// return this.txHashPromise;
+// }
- getReceipt() {
- const fn = this.result_.getReceipt;
- if (fn) {
- return fn();
- }
- return this.receiptPromise;
- }
+// getReceipt() {
+// const fn = this.result_.getReceipt;
+// if (fn) {
+// return fn();
+// }
+// return this.receiptPromise;
+// }
-}
\ No newline at end of file
+// }
\ No newline at end of file

MODIFY
src/helpers/index.ts
src/helpers/index.ts
export * from "./do_nothing";
-export * from "./contract_write_result";
\ No newline at end of file
+// export * from "./contract_write_result";
\ No newline at end of file

MODIFY
src/interfaces/transaction_write_result.ts
src/interfaces/transaction_write_result.ts
import { ITransactionReceipt } from "./tx_receipt";
export interface ITransactionWriteResult {
- onTransactionHash?: (txHash: string) => void;
- onReceipt?: Function;
- getTransactionHash?: () => Promise<string>;
- getReceipt?: () => Promise<ITransactionReceipt>;
- onReceiptError: Function;
- onTxError: Function;
+
+ getTransactionHash: () => Promise<string>;
+ getReceipt: () => Promise<ITransactionReceipt>;
}
\ No newline at end of file

MODIFY
src/utils/base_token.ts
src/utils/base_token.ts
import { Web3SideChainClient } from "./web3_side_chain_client";
-import { ITransactionRequestConfig, ITransactionOption, IContractInitParam, IPOSClientConfig, IBaseClientConfig } from "../interfaces";
+import { ITransactionRequestConfig, ITransactionOption, IContractInitParam, IPOSClientConfig, IBaseClientConfig, ITransactionWriteResult } from "../interfaces";
import { BaseContractMethod, BaseContract, BaseWeb3Client } from "../abstracts";
import { Converter, merge } from "../utils";
-import { ContractWriteResult } from "../helpers";
import { promiseResolve } from "./promise_resolve";
import { ERROR_TYPE } from "../enums";
import { TYPE_AMOUNT } from "../types";
@@ -44,7 +43,7 @@ export class BaseToken<T_CLIENT_CONFIG> {
});
}
- protected processWrite(method: BaseContractMethod, option: ITransactionOption = {}): Promise<ContractWriteResult> {
+ protected processWrite(method: BaseContractMethod, option: ITransactionOption = {}): Promise<ITransactionWriteResult> {
this.validateTxOption_(option);
this.client.logger.log("process write");
@@ -65,12 +64,11 @@ export class BaseToken<T_CLIENT_CONFIG> {
const methodResult = method.write(
config,
);
- return new ContractWriteResult(methodResult);
-
+ return methodResult;
});
}
- protected sendTransaction(option: ITransactionOption = {}): Promise<ContractWriteResult> {
+ protected sendTransaction(option: ITransactionOption = {}): Promise<ITransactionWriteResult> {
this.validateTxOption_(option);
const isParent = this.contractParam.isParent;
@@ -91,12 +89,11 @@ export class BaseToken<T_CLIENT_CONFIG> {
const methodResult = client.write(
config,
);
- return new ContractWriteResult(methodResult);
-
+ return methodResult;
});
}
- protected readTransaction(option: ITransactionOption = {}): Promise<ContractWriteResult> {
+ protected readTransaction(option: ITransactionOption = {}): Promise<ITransactionWriteResult> {
this.validateTxOption_(option);
const isParent = this.contractParam.isParent;
const client = this.getClient(isParent);

implement transaction write result