add maxapprove - erc20
MODIFY
src/abstracts/contract_method.ts
src/abstracts/contract_method.ts
@@ -4,4 +4,5 @@ export abstract class BaseContractMethod {
abstract read<T>(tx: ITransactionConfig,): Promise<T>;
abstract write(tx: ITransactionConfig,): ISendResult;
abstract estimateGas(tx: ITransactionConfig,): Promise<number>;
+ abstract encodeABI(): any;
}
\ No newline at end of file

MODIFY
src/inherited/eth_method.ts
src/inherited/eth_method.ts
@@ -50,4 +50,8 @@ export class EthMethod extends BaseContractMethod {
return this.method.estimateGas(tx as any);
}
+ encodeABI() {
+ return this.encodeABI();
+ }
+
}
\ No newline at end of file

MODIFY
src/plasma/erc20.ts
src/plasma/erc20.ts
import { BaseToken, Web3SideChainClient } from "../model";
import BN from "bn.js";
import { ITransactionConfig, ITransactionOption } from "../interfaces";
-import { formatAmount, IEventBusPromise, eventBusPromise } from "../utils";
+import { formatAmount, IEventBusPromise, eventBusPromise, merge } from "../utils";
import { createTransactionConfig } from "../utils/create_tx_config";
import { DepositManager } from "./deposit_manager";
@@ -50,6 +50,14 @@ export class ERC20 extends BaseToken {
method,
isParent: true
}).then(config => {
+ if (option.returnTransaction) {
+ return res(
+ merge(config, {
+ data: method.encodeABI(),
+ to: this.contract.address
+ } as ITransactionConfig)
+ );
+ }
const methodResult = method.write(
config,
);
@@ -65,10 +73,20 @@ export class ERC20 extends BaseToken {
methodResult.onReceipt = (receipt) => {
result.emit("receipt", receipt);
res(receipt);
+ result.destroy();
};
}) as IEventBusPromise<any>;
});
return result;
}
+ approveMax(option: ITransactionOption = {}) {
+ return this.approve(
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
+ , option
+ );
+ }
+
+
+
}
\ No newline at end of file

MODIFY
src/utils/event_bus.ts
src/utils/event_bus.ts
-// Create a constructor that uses `Promise` as its super and does the `super` call
-// via `Reflect.construct`
-const myPromise = function (executor) {
- return Reflect.construct(Promise, [executor], myPromise);
-};
-// Assign the statics (`resolve`, `reject`, etc.) to the new constructor
-Object.assign(
- myPromise,
- (Object as any).fromEntries(
- Reflect.ownKeys(Promise)
- .filter(key => key !== "length" && key !== "name")
- .map(key => [key, Promise[key]])
- )
-);
-
-// Create the prototype, add methods to it
-myPromise.prototype = Object.create(Promise.prototype);
-myPromise.prototype.constructor = myPromise;
-
export interface IEventBusPromise<T> extends Promise<T> {
on(event: string, cb: Function);
emit(event: string, ...args);
+ destroy();
}
export const eventBusPromise = function <T>(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void) {

MODIFY
src/utils/index.ts
src/utils/index.ts
@@ -2,3 +2,4 @@ export * from "./use";
export * from "./format_amount";
export * from "./event_bus";
export * from "./logger";
+export * from "./merge";
\ No newline at end of file

ADD
src/utils/merge.ts
+export const merge = (...obj) => {
+ return Object.assign({}, ...obj);
+};
\ No newline at end of file

add maxapprove - erc20