Skip to content

Commit

Permalink
Merge pull request #60 from marcelooblan2016/hotfix/swap_hang_on_failed
Browse files Browse the repository at this point in the history
fix hangs on swap unsuccessful
  • Loading branch information
marcelooblan2016 authored Aug 1, 2022
2 parents 6a0127d + 9de9e46 commit 5a72228
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions dist/Metamask/Libs/addNewNetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function addNewNetwork(params) {
const [inputExplorerXpath] = yield page.$x(C.elements.add_new_network.input_explorer_xpath);
yield inputExplorerXpath.type(String(params.explorer));
yield page.waitForTimeout(2000);
yield page.waitForXPath(C.elements.add_new_network.button_save_xpath + "[not(@disabled)]");
const [buttonSaveXpath] = yield page.$x(C.elements.add_new_network.button_save_xpath);
yield buttonSaveXpath.click();
return true;
Expand Down
9 changes: 7 additions & 2 deletions dist/Metamask/Libs/swapToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,13 @@ function swapToken(params) {
catch (error) {
logger_1.default.write({ content: "Swapping token: failed" });
logger_1.default.screenshot(page);
const [buttonSwapCancel] = yield page.$x(C.elements.swap_token.button_swap_cancel_xpath);
yield buttonSwapCancel.click();
logger_1.default.write({ content: "Redirecting to home..." });
let baseUrl = [
C.urls.prefix,
(currentUrl.match(/\/\/(.*?)\//i))[1],
`/home.html`
].join("");
yield page.goto(baseUrl, { waitUntil: 'domcontentloaded' });
}
return false;
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "crypto-bot-trader",
"description": "swapping of ERC-20 Tokens (buy/sell) based on the market health with bot strategy (condition) - by utilizing metamask & pupeteer",
"version": "2.3.5",
"version": "2.3.6",
"main": "./dist/index.js",
"repository": {
"type": "git",
Expand Down
3 changes: 2 additions & 1 deletion src/Metamask/Libs/addNewNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ async function addNewNetwork(params: addNewNetworkParameters): Promise<boolean>
// Type Explorer
const [inputExplorerXpath] = await page!.$x(C.elements.add_new_network.input_explorer_xpath);
await inputExplorerXpath.type(String(params.explorer));
await page!.waitForTimeout(2000)
await page!.waitForTimeout(2000);
await page!.waitForXPath(C.elements.add_new_network.button_save_xpath + "[not(@disabled)]");
const [buttonSaveXpath]: any = await page!.$x(C.elements.add_new_network.button_save_xpath);
await buttonSaveXpath.click();

Expand Down
11 changes: 8 additions & 3 deletions src/Metamask/Libs/swapToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ async function swapToken(params: SwapTokenParameters): Promise<boolean> {
const [buttonSwapOverview]: any = await page!.$x(C.elements.swap_token.button_swap_overview_xpath);
await buttonSwapOverview.click();
await page!.waitForTimeout(1000);

// click swap from overview

// **** TokenFrom
Expand Down Expand Up @@ -207,9 +208,13 @@ async function swapToken(params: SwapTokenParameters): Promise<boolean> {
} catch (error) {
logger.write({content: "Swapping token: failed"});
logger.screenshot(page!);

const [buttonSwapCancel]: any = await page!.$x(C.elements.swap_token.button_swap_cancel_xpath);
await buttonSwapCancel.click();
logger.write({content: "Redirecting to home..."});
let baseUrl: string = [
C.urls.prefix,
(currentUrl.match(/\/\/(.*?)\//i))![1],
`/home.html`
].join("");
await page!.goto(baseUrl, { waitUntil: 'domcontentloaded' });
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion test/swapToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ const {metaMask} = require('../dist/index');
"Earned: 5 usd",
].join(" ");

await metaMask.swapToken("matic", "usdc", 1, 0, description);
await metaMask.swapToken("matic", "usdc", 3, 0, description);
})();

0 comments on commit 5a72228

Please sign in to comment.