Skip to content

Commit

Permalink
feat(limit-order-protocol-facade): methods for parse remaining response
Browse files Browse the repository at this point in the history
  • Loading branch information
shoom3301 committed Apr 26, 2021
1 parent ff00a78 commit b3f9912
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/limit-order-protocol.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ export class LimitOrderProtocolFacade {
return this.providerConnector
.ethCall(this.contractAddress, callData)
.then((result) => {
if (result.length === 66) {
return BigNumber.from(result);
const response = this.parseRemainingResponse(result);

if (response !== null) {
return response;
}

// Parse error
Expand All @@ -118,6 +120,14 @@ export class LimitOrderProtocolFacade {
});
}

parseRemainingResponse(response: string): BigNumber | null {
if (response.length === 66) {
return BigNumber.from(response);
}

return null;
}

simulateTransferFroms(tokens: string[], data: unknown[]): Promise<boolean> {
const callData = this.getContractCallData(
LimitOrderProtocolMethods.simulateTransferFroms,
Expand All @@ -137,8 +147,8 @@ export class LimitOrderProtocolFacade {
});
}

parseSimulateTransferResponse(result: string): boolean | null {
const parsed = this.parseContractResponse(result);
parseSimulateTransferResponse(response: string): boolean | null {
const parsed = this.parseContractResponse(response);

if (parsed.startsWith(SIMULATE_TRANSFER_PREFIX)) {
const data = parsed.replace(SIMULATE_TRANSFER_PREFIX, '');
Expand All @@ -149,10 +159,10 @@ export class LimitOrderProtocolFacade {
return null;
}

parseContractResponse(callData: string): string {
parseContractResponse(response: string): string {
return this.providerConnector.decodeABIParameter<string>(
'string',
ZX + callData.slice(10)
ZX + response.slice(10)
);
}

Expand Down

0 comments on commit b3f9912

Please sign in to comment.