From 03a6359b0c8369713ca3d6cf3d0169382fde04fb Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Sat, 13 Jul 2024 01:52:59 +0100 Subject: [PATCH] fix(ci): cspell and eslint fixes --- .cspell.json | 1 + README.md | 25 ++++++++++--------- cypress.config.ts | 2 +- cypress/e2e/claim-portal-non-web3.cy.ts | 13 +++++----- cypress/e2e/claim-portal-success.cy.ts | 3 ++- static/scripts/rewards/web3/connect-wallet.ts | 16 +++++++++--- static/scripts/rewards/web3/erc20-permit.ts | 3 +-- 7 files changed, 37 insertions(+), 26 deletions(-) diff --git a/.cspell.json b/.cspell.json index b0185233..90e5b353 100644 --- a/.cspell.json +++ b/.cspell.json @@ -5,6 +5,7 @@ "useGitignore": true, "language": "en", "words": [ + "blockscan", "funder", "Funder", "binkey", diff --git a/README.md b/README.md index 261afa9a..6fc48aed 100644 --- a/README.md +++ b/README.md @@ -6,20 +6,21 @@ A vanilla Typescript dApp for claiming Ubiquity Rewards. It also includes tools 1. Install [Foundry](https://book.getfoundry.sh/getting-started/installation). 2. Create a `.env` file in the project root with the following settings: + - These are the suggested default test environment variables that allow for local setup using the supplied yarn commands. If you want to produce or invalidate real on-chain permits you must change the below values to reflect the real permit information such as address, chain ID, private key and so on. - ```env - # Common variables - CHAIN_ID="31337" - FRONTEND_URL="http://localhost:8080" - UBIQUIBOT_PRIVATE_KEY="0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d" - RPC_PROVIDER_URL="http://127.0.0.1:8545" - PAYMENT_TOKEN_ADDRESS="0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d" - - # Variables depending on spender (bounty hunter) - AMOUNT_IN_ETH="1" - BENEFICIARY_ADDRESS="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" - ``` + ```env + # Common variables + CHAIN_ID="31337" + FRONTEND_URL="http://localhost:8080" + UBIQUIBOT_PRIVATE_KEY="0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d" + RPC_PROVIDER_URL="http://127.0.0.1:8545" + PAYMENT_TOKEN_ADDRESS="0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d" + + # Variables depending on spender (bounty hunter) + AMOUNT_IN_ETH="1" + BENEFICIARY_ADDRESS="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" + ``` ## Local Testing diff --git a/cypress.config.ts b/cypress.config.ts index 9beb79b1..8eee7a78 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -5,7 +5,7 @@ config(); export default defineConfig({ e2e: { - setupNodeEvents() { }, + setupNodeEvents() {}, baseUrl: "http://localhost:8080", experimentalStudio: true, }, diff --git a/cypress/e2e/claim-portal-non-web3.cy.ts b/cypress/e2e/claim-portal-non-web3.cy.ts index 09e26dd2..c1a51c50 100644 --- a/cypress/e2e/claim-portal-non-web3.cy.ts +++ b/cypress/e2e/claim-portal-non-web3.cy.ts @@ -1,4 +1,5 @@ /* eslint-disable sonarjs/no-duplicate-string */ +// cspell:disable describe("Claims Portal Non-Web3", () => { beforeEach(() => { cy.clearAllCookies(); @@ -6,12 +7,11 @@ describe("Claims Portal Non-Web3", () => { cy.clearAllSessionStorage(); setupIntercepts(); - }); describe("No window.ethereum", () => { it("Should toast and hide buttons in a non-web3 env", () => { - cy.visit(`/${claimUrl}`) + cy.visit(`/${claimUrl}`); cy.wait(2000); cy.get("#invalidator").should("not.be.visible"); @@ -31,8 +31,8 @@ describe("Claims Portal Non-Web3", () => { "Mozilla/5.0 (Linux; Android 10; SM-A505FN) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Mobile Safari/537.36 WebView MetaMaskMobile", "Mozilla/5.0 (Linux; U; Android 8.1.0; en-us; Redmi Note 5 Pro) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/68.0.3440.91 Mobile Safari/537.36", "Mozilla/5.0 (Linux; Android 9; SM-G960F Build/PPR1.180610.011) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Mobile Safari/537.36", - "Mozilla/5.0 (Linux; Android 11; Pixel 4 XL) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.93 Mobile Safari/537.36" - ] + "Mozilla/5.0 (Linux; Android 11; Pixel 4 XL) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.93 Mobile Safari/537.36", + ]; it("UserAgent 0", () => { testUserAgent(userAgents[0]); @@ -71,9 +71,9 @@ describe("Claims Portal Non-Web3", () => { function testUserAgent(userAgent: string) { cy.visit(`/${claimUrl}`, { onBeforeLoad: (win) => { - Object.defineProperty(win.navigator, 'userAgent', { + Object.defineProperty(win.navigator, "userAgent", { value: userAgent, - configurable: true + configurable: true, }); }, }); @@ -87,7 +87,6 @@ function testUserAgent(userAgent: string) { } function setupIntercepts() { - cy.intercept("POST", "*", (req) => { // return a 404 for rpc optimization meaning no successful RPC // to return our balanceOf and allowance calls diff --git a/cypress/e2e/claim-portal-success.cy.ts b/cypress/e2e/claim-portal-success.cy.ts index 7c70dd28..1f715b3e 100644 --- a/cypress/e2e/claim-portal-success.cy.ts +++ b/cypress/e2e/claim-portal-success.cy.ts @@ -41,7 +41,8 @@ describe("Claims Portal Success", () => { win.open = cy.stub().as("open"); }); - cy.get("#view-claim").invoke("click") + cy.get("#view-claim") + .invoke("click") .then(() => { cy.get("@open").should("be.calledWithMatch", /https:\/\/blockscan.com\/tx/); }); diff --git a/static/scripts/rewards/web3/connect-wallet.ts b/static/scripts/rewards/web3/connect-wallet.ts index 202da02a..8fdc2dd7 100644 --- a/static/scripts/rewards/web3/connect-wallet.ts +++ b/static/scripts/rewards/web3/connect-wallet.ts @@ -4,14 +4,24 @@ import { buttonController, toaster } from "../toaster"; import { app } from "../app-state"; import { useHandler } from "../web3/use-rpc-handler"; -function _mobileCheck(a: string) { - if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) { +function checkMobile(a: string) { + // cspell:disable + if ( + // eslint-disable-next-line no-useless-escape + /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test( + a + ) || // eslint-disable-next-line no-useless-escape + /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test( + a.substring(0, 4) + ) + ) { + // cspell:enable return true; } } function mobileCheck() { - return _mobileCheck(navigator.userAgent || navigator.vendor || (window as any).opera); + return checkMobile(navigator.userAgent || navigator.vendor || (window as unknown as { opera: string }).opera); } export async function connectWallet(): Promise { diff --git a/static/scripts/rewards/web3/erc20-permit.ts b/static/scripts/rewards/web3/erc20-permit.ts index cf0560ff..9e1fe826 100644 --- a/static/scripts/rewards/web3/erc20-permit.ts +++ b/static/scripts/rewards/web3/erc20-permit.ts @@ -102,7 +102,7 @@ async function waitForTransaction(tx: TransactionResponse) { const receipt = await tx.wait(); viewClaimButton.onclick = () => { window.open(`https://blockscan.com/tx/${receipt.transactionHash}`, "_blank"); - } + }; toaster.create("success", `Claim Complete.`); buttonController.showViewClaim(); @@ -110,7 +110,6 @@ async function waitForTransaction(tx: TransactionResponse) { buttonController.hideMakeClaim(); console.log(receipt.transactionHash); - return receipt; } catch (error: unknown) { if (error instanceof Error) {