Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
fix(cancel_event): insensitive case on signer wallet
Browse files Browse the repository at this point in the history
Closes #45
  • Loading branch information
Mitsichury authored Aug 17, 2023
1 parent 01e948c commit a0f9862
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
6 changes: 2 additions & 4 deletions src/client/Web3SwapClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export class Web3SwapClient {

const provider = ethers.providers.InfuraProvider.getWebSocketProvider(chainId, this.apiKey);
const contract = Swap.getContract(provider, chainId);
contract.on("Swap", (nonce, signerWallet, signerAmount, signerId, signerToken, senderWallet, senderAmount, senderId,
senderToken, affiliateWallet, affiliateAmount) => {
contract.on("Swap", (nonce, signerWallet) => {
this.onEvent(nonce, signerWallet);
});
contract.on("Cancel", (nonce, signerWallet) => {
Expand All @@ -46,8 +45,7 @@ export class Web3SwapClient {
if (nonce && signerWallet) {
const decodedNonce = parseInt(nonce._hex, 16);
if (isNaN(decodedNonce)) return;

this.database.deleteOrder(decodedNonce, signerWallet);
this.database.deleteOrder(decodedNonce, signerWallet.toLocaleLowerCase());
}
}
}
2 changes: 1 addition & 1 deletion src/client/Web3SwapERC20Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class Web3SwapERC20Client {
const decodedNonce = parseInt(nonce._hex, 16);
if (isNaN(decodedNonce)) return;

this.database.deleteOrderERC20(decodedNonce, signerWallet);
this.database.deleteOrderERC20(decodedNonce, signerWallet.toLocaleLowerCase());
}
}
}
6 changes: 3 additions & 3 deletions src/client/__tests__/Web3SwapClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe("Web3SwapClient", () => {
it("Should remove order on event Swap", async () => {
const mockedOn = jest.fn((eventName, callback) => {
if (eventName === "Swap") {
callback({ _hex: "0xf5", _isBigNumber: true }, "a_wallet");
callback({ _hex: "0xf5", _isBigNumber: true }, "a_wAllet");
}
});

Expand All @@ -114,7 +114,7 @@ describe("Web3SwapClient", () => {
it("Should remove order on event Cancel", async () => {
const mockedOn = jest.fn((eventName, callback) => {
if (eventName === "Cancel") {
callback({ _hex: "0xf5", _isBigNumber: true }, "a_wallet");
callback({ _hex: "0xf5", _isBigNumber: true }, "a_waLl3t");
}
});
//@ts-ignore
Expand All @@ -133,7 +133,7 @@ describe("Web3SwapClient", () => {

expect(mockedOn).toHaveBeenCalledTimes(2);
expect(fakeDatabase.deleteOrder).toHaveBeenCalledTimes(1);
expect(fakeDatabase.deleteOrder).toHaveBeenCalledWith(245, "a_wallet");
expect(fakeDatabase.deleteOrder).toHaveBeenCalledWith(245, "a_wall3t");
});

describe("Do nothing", () => {
Expand Down
8 changes: 4 additions & 4 deletions src/client/__tests__/Web3SwapERC20Client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe("Web3SwapERC20Client", () => {
it("Should remove order on event SwapERC20", async () => {
const mockedOn = jest.fn((eventName, callback) => {
if (eventName === "SwapERC20") {
callback({ _hex: "0xf5", _isBigNumber: true }, "a_wallet");
callback({ _hex: "0xf5", _isBigNumber: true }, "a_wAll3t");
}
});

Expand All @@ -108,13 +108,13 @@ describe("Web3SwapERC20Client", () => {

expect(mockedOn).toHaveBeenCalledTimes(2);
expect(fakeDatabase.deleteOrderERC20).toHaveBeenCalledTimes(1);
expect(fakeDatabase.deleteOrderERC20).toHaveBeenCalledWith(245, "a_wallet");
expect(fakeDatabase.deleteOrderERC20).toHaveBeenCalledWith(245, "a_wall3t");
});

it("Should remove order on event Cancel", async () => {
const mockedOn = jest.fn((eventName, callback) => {
if (eventName === "Cancel") {
callback({ _hex: "0xf5", _isBigNumber: true }, "a_wallet");
callback({ _hex: "0xf5", _isBigNumber: true }, "a_waLLet");
}
});
//@ts-ignore
Expand Down Expand Up @@ -171,7 +171,7 @@ describe("Web3SwapERC20Client", () => {

it("nonce has no value", () => {
const mockedOn = jest.fn((eventName, callback) => {
callback({ _hex: undefined, _isBigNumber: true }, "a_wallet");
callback({ _hex: undefined, _isBigNumber: true }, "A_wallet");
});
//@ts-ignore
mockedEther.providers.InfuraProvider = {
Expand Down

0 comments on commit a0f9862

Please sign in to comment.