From c399eee6b2cdbbe66a0f6602886f55dd633547c2 Mon Sep 17 00:00:00 2001 From: "Michael D. Norman" Date: Wed, 11 May 2022 09:13:49 -0500 Subject: [PATCH] chore: [#3] added linting and prettier to checkin, plus additional typescript check --- .eslintrc.json | 3 -- .eslintrc.yml | 13 ++++++ package.json | 13 +++++- pages/index.tsx | 110 +++++++++++++++++------------------------------- yarn.lock | 108 +++++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 167 insertions(+), 80 deletions(-) delete mode 100644 .eslintrc.json create mode 100644 .eslintrc.yml diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index bffb357..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "next/core-web-vitals" -} diff --git a/.eslintrc.yml b/.eslintrc.yml new file mode 100644 index 0000000..102c85d --- /dev/null +++ b/.eslintrc.yml @@ -0,0 +1,13 @@ +extends: "next/core-web-vitals" +env: + browser: true + es2021: true +parser: '@typescript-eslint/parser' +parserOptions: + ecmaVersion: 12 + sourceType: module +plugins: + - '@typescript-eslint' + - prettier +rules: + 'prettier/prettier': warn diff --git a/package.json b/package.json index 42e1eac..65cfeb7 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,16 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint && tsc --noemit" + }, + "husky": { + "hooks": { + "pre-commit": "pretty-quick --staged", + "pre-push": "npm run lint" + } }, "dependencies": { "@citydao/parcel-contracts": "^0.0.4", - "@types/styled-components": "^5.1.25", "@walletconnect/web3-provider": "^1.7.8", "ethers": "^5.5.1", "joi": "^17.4.2", @@ -24,10 +29,14 @@ "devDependencies": { "@types/node": "16.11.10", "@types/react": "18.0.1", + "@types/styled-components": "^5.1.25", + "@typescript-eslint/eslint-plugin": "^5.23.0", + "@typescript-eslint/parser": "^5.23.0", "babel-plugin-styled-components": "^2.0.7", "eslint": "7.32.0", "eslint-config-next": "12.0.4", "eslint-plugin-prettier": "^4.0.0", + "husky": "^8.0.1", "prettier": "^2.6.2", "pretty-quick": "^3.1.3", "styled-components": "^5.3.5", diff --git a/pages/index.tsx b/pages/index.tsx index 829ff3b..9f18de8 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,21 +1,20 @@ /* eslint-disable @next/next/no-img-element */ -import { useState, FC, useEffect } from "react"; -import { NextPage } from "next"; -import { ethers } from "ethers"; -import { Iframe } from "../components/Iframe"; -import { ParcelProperties } from "../containers/ParcelProperties"; -import useWallet from "../hooks/useWallet"; -import { ParcelNFT__factory } from "@citydao/parcel-contracts/dist/types/contracts/factories/ParcelNFT__factory"; +import { useState, FC, useEffect } from 'react'; +import { NextPage } from 'next'; +import { ethers } from 'ethers'; +import { Iframe } from '../components/Iframe'; +import { ParcelProperties } from '../containers/ParcelProperties'; +import useWallet from '../hooks/useWallet'; +import { ParcelNFT__factory } from '@citydao/parcel-contracts/dist/types/contracts/factories/ParcelNFT__factory'; -import { getParcelProperties } from "../parcel-properties"; -import keccak256 from "keccak256"; -import MerkleTree from "merkletreejs"; -import { addresses, Addresses } from "../data/whiteListedAddresses"; -import { shortenWalletAddress } from "../utils"; -import { MAX_NFT_TO_MINT } from "../contants"; -import { MintedNftsView } from "../components/MintedNftsView"; -const PARCEL0_NFT_CONTRACT_ADDRESS = - "0x209723a65844093Ad769d557a22742e0f661959d"; +import { getParcelProperties } from '../parcel-properties'; +import keccak256 from 'keccak256'; +import MerkleTree from 'merkletreejs'; +import { addresses, Addresses } from '../data/whiteListedAddresses'; +import { shortenWalletAddress } from '../utils'; +import { MAX_NFT_TO_MINT } from '../contants'; +import { MintedNftsView } from '../components/MintedNftsView'; +const PARCEL0_NFT_CONTRACT_ADDRESS = '0x209723a65844093Ad769d557a22742e0f661959d'; const numberOfMintedNFTsSoFar = 1; // TODO trkaplan calculate this value interface ConnectButtonProps { enabled?: boolean; @@ -24,30 +23,21 @@ interface ConnectButtonProps { text?: string; } enum VIEWS { - "INITIAL_VIEW", - "MINTED_NFTS", + 'INITIAL_VIEW', + 'MINTED_NFTS', } -const ConnectButton: FC = ({ - enabled, - onClick, - address, -}) => { +const ConnectButton: FC = ({ enabled, onClick, address }) => { // TODO trkaplan disable if wallet is not installed return ( ); }; // https://docs.ethers.io/v5/api/utils/hashing/#utils-solidityKeccak256 function hashToken(address: keyof Addresses, allowance: number) { - return Buffer.from( - ethers.utils - .solidityKeccak256(["address", "uint256"], [address, allowance]) - .slice(2), - "hex" - ); + return Buffer.from(ethers.utils.solidityKeccak256(['address', 'uint256'], [address, allowance]).slice(2), 'hex'); } const Home: NextPage = () => { const [numberOfMintedNfts, setNumberOfMintedNfts] = useState(0); @@ -67,11 +57,9 @@ const Home: NextPage = () => { setNumberOfMintedNfts(0); } const tree = new MerkleTree( - Object.entries(addresses).map(([address, allowance]) => - hashToken(address, allowance) - ), + Object.entries(addresses).map(([address, allowance]) => hashToken(address, allowance)), keccak256, - { sortPairs: true } + { sortPairs: true }, ); const handleLoad = () => { @@ -84,13 +72,10 @@ const Home: NextPage = () => { function showMintedNfts() { setCurrentView(VIEWS.MINTED_NFTS); } - function getClaimButtonText( - numberOfMintedNfts: number, - eligibleNftCount: number - ) { - let text = ""; + function getClaimButtonText(numberOfMintedNfts: number, eligibleNftCount: number) { + let text = ''; if (numberOfMintedNfts === 0 && eligibleNftCount === 0) { - text = "CLAIM PLOTS"; + text = 'CLAIM PLOTS'; } else if (numberOfMintedNfts > 0) { text = `${numberOfMintedNfts} PLOTS CLAIMED`; } else if (eligibleNftCount > 0) { @@ -100,12 +85,8 @@ const Home: NextPage = () => { } async function claim() { const signer = provider.getSigner(); - const parcel0Contract = new ParcelNFT__factory().attach( - PARCEL0_NFT_CONTRACT_ADDRESS - ); - const allowance: number = Number( - addresses[address?.toLowerCase() as keyof Addresses] - ); + const parcel0Contract = new ParcelNFT__factory().attach(PARCEL0_NFT_CONTRACT_ADDRESS); + const allowance: number = Number(addresses[address?.toLowerCase() as keyof Addresses]); const proof = tree.getHexProof(hashToken(address!, allowance)); const numberOfMinted = await parcel0Contract .connect(signer) @@ -116,10 +97,10 @@ const Home: NextPage = () => { .connect(signer) .allowListMint(eligibleNftCount, allowance, proof) .then((res: any) => { - console.log("response", res); + console.log('response', res); }); } else { - console.log("Already claimed!"); + console.log('Already claimed!'); } } @@ -128,6 +109,7 @@ const Home: NextPage = () => { useEffect(() => { if (address) { + // noinspection JSIgnoredPromiseFromCall checkEligibility(address); } }, [address]); @@ -135,11 +117,8 @@ const Home: NextPage = () => { const checkEligibility = async (address: string) => { try { const signer = provider.getSigner(); - const parcel0Contract = new ParcelNFT__factory().attach( - PARCEL0_NFT_CONTRACT_ADDRESS - ); - const allowance: number = - addresses[address.toLowerCase() as keyof Addresses]; + const parcel0Contract = new ParcelNFT__factory().attach(PARCEL0_NFT_CONTRACT_ADDRESS); + const allowance: number = addresses[address.toLowerCase() as keyof Addresses]; //const proof = tree.getHexProof(hashToken(address, allowance)); // TODO trkaplan disable the claim button add loading indicator until eligibility check is complete @@ -161,21 +140,14 @@ const Home: NextPage = () => { } }; - const parcelProperties = getParcelProperties( - numberOfMintedNFTsSoFar, - MAX_NFT_TO_MINT - ); + const parcelProperties = getParcelProperties(numberOfMintedNFTsSoFar, MAX_NFT_TO_MINT); return ( <>
CityDAO
- +
@@ -188,8 +160,7 @@ const Home: NextPage = () => {
70 HAIL BASIN RD, POWELL, WYOMING
- Claim ends in{" "} - 45 Days 00 Hours{" "} + Claim ends in 45 Days 00 Hours{' '} {/* TODO trkaplan use countdown component */}
{address && ( @@ -202,7 +173,7 @@ const Home: NextPage = () => { )} {!address && ( - To claim{" "} + To claim{' '} connect your wallet @@ -213,10 +184,7 @@ const Home: NextPage = () => { {currentView === VIEWS.INITIAL_VIEW ? ( Parcel Zero NFT ) : ( - + )}
@@ -224,9 +192,7 @@ const Home: NextPage = () => { diff --git a/yarn.lock b/yarn.lock index 6aecc6a..06f6023 100644 --- a/yarn.lock +++ b/yarn.lock @@ -883,6 +883,11 @@ "@types/react" "*" hoist-non-react-statics "^3.3.0" +"@types/json-schema@^7.0.9": + version "7.0.11" + resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3" + integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ== + "@types/json5@^0.0.29": version "0.0.29" resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" @@ -954,6 +959,21 @@ "@types/react" "*" csstype "^3.0.2" +"@typescript-eslint/eslint-plugin@^5.23.0": + version "5.23.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.23.0.tgz#bc4cbcf91fbbcc2e47e534774781b82ae25cc3d8" + integrity sha512-hEcSmG4XodSLiAp1uxv/OQSGsDY6QN3TcRU32gANp+19wGE1QQZLRS8/GV58VRUoXhnkuJ3ZxNQ3T6Z6zM59DA== + dependencies: + "@typescript-eslint/scope-manager" "5.23.0" + "@typescript-eslint/type-utils" "5.23.0" + "@typescript-eslint/utils" "5.23.0" + debug "^4.3.2" + functional-red-black-tree "^1.0.1" + ignore "^5.1.8" + regexpp "^3.2.0" + semver "^7.3.5" + tsutils "^3.21.0" + "@typescript-eslint/parser@^4.20.0": version "4.33.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.33.0.tgz#dfe797570d9694e560528d18eecad86c8c744899" @@ -964,6 +984,16 @@ "@typescript-eslint/typescript-estree" "4.33.0" debug "^4.3.1" +"@typescript-eslint/parser@^5.23.0": + version "5.23.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.23.0.tgz#443778e1afc9a8ff180f91b5e260ac3bec5e2de1" + integrity sha512-V06cYUkqcGqpFjb8ttVgzNF53tgbB/KoQT/iB++DOIExKmzI9vBJKjZKt/6FuV9c+zrDsvJKbJ2DOCYwX91cbw== + dependencies: + "@typescript-eslint/scope-manager" "5.23.0" + "@typescript-eslint/types" "5.23.0" + "@typescript-eslint/typescript-estree" "5.23.0" + debug "^4.3.2" + "@typescript-eslint/scope-manager@4.33.0": version "4.33.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.33.0.tgz#d38e49280d983e8772e29121cf8c6e9221f280a3" @@ -972,11 +1002,33 @@ "@typescript-eslint/types" "4.33.0" "@typescript-eslint/visitor-keys" "4.33.0" +"@typescript-eslint/scope-manager@5.23.0": + version "5.23.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.23.0.tgz#4305e61c2c8e3cfa3787d30f54e79430cc17ce1b" + integrity sha512-EhjaFELQHCRb5wTwlGsNMvzK9b8Oco4aYNleeDlNuL6qXWDF47ch4EhVNPh8Rdhf9tmqbN4sWDk/8g+Z/J8JVw== + dependencies: + "@typescript-eslint/types" "5.23.0" + "@typescript-eslint/visitor-keys" "5.23.0" + +"@typescript-eslint/type-utils@5.23.0": + version "5.23.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.23.0.tgz#f852252f2fc27620d5bb279d8fed2a13d2e3685e" + integrity sha512-iuI05JsJl/SUnOTXA9f4oI+/4qS/Zcgk+s2ir+lRmXI+80D8GaGwoUqs4p+X+4AxDolPpEpVUdlEH4ADxFy4gw== + dependencies: + "@typescript-eslint/utils" "5.23.0" + debug "^4.3.2" + tsutils "^3.21.0" + "@typescript-eslint/types@4.33.0": version "4.33.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.33.0.tgz#a1e59036a3b53ae8430ceebf2a919dc7f9af6d72" integrity sha512-zKp7CjQzLQImXEpLt2BUw1tvOMPfNoTAfb8l51evhYbOEEzdWyQNmHWWGPR6hwKJDAi+1VXSBmnhL9kyVTTOuQ== +"@typescript-eslint/types@5.23.0": + version "5.23.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.23.0.tgz#8733de0f58ae0ed318dbdd8f09868cdbf9f9ad09" + integrity sha512-NfBsV/h4dir/8mJwdZz7JFibaKC3E/QdeMEDJhiAE3/eMkoniZ7MjbEMCGXw6MZnZDMN3G9S0mH/6WUIj91dmw== + "@typescript-eslint/typescript-estree@4.33.0": version "4.33.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.33.0.tgz#0dfb51c2908f68c5c08d82aefeaf166a17c24609" @@ -990,6 +1042,31 @@ semver "^7.3.5" tsutils "^3.21.0" +"@typescript-eslint/typescript-estree@5.23.0": + version "5.23.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.23.0.tgz#dca5f10a0a85226db0796e8ad86addc9aee52065" + integrity sha512-xE9e0lrHhI647SlGMl+m+3E3CKPF1wzvvOEWnuE3CCjjT7UiRnDGJxmAcVKJIlFgK6DY9RB98eLr1OPigPEOGg== + dependencies: + "@typescript-eslint/types" "5.23.0" + "@typescript-eslint/visitor-keys" "5.23.0" + debug "^4.3.2" + globby "^11.0.4" + is-glob "^4.0.3" + semver "^7.3.5" + tsutils "^3.21.0" + +"@typescript-eslint/utils@5.23.0": + version "5.23.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.23.0.tgz#4691c3d1b414da2c53d8943310df36ab1c50648a" + integrity sha512-dbgaKN21drqpkbbedGMNPCtRPZo1IOUr5EI9Jrrh99r5UW5Q0dz46RKXeSBoPV+56R6dFKpbrdhgUNSJsDDRZA== + dependencies: + "@types/json-schema" "^7.0.9" + "@typescript-eslint/scope-manager" "5.23.0" + "@typescript-eslint/types" "5.23.0" + "@typescript-eslint/typescript-estree" "5.23.0" + eslint-scope "^5.1.1" + eslint-utils "^3.0.0" + "@typescript-eslint/visitor-keys@4.33.0": version "4.33.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.33.0.tgz#2a22f77a41604289b7a186586e9ec48ca92ef1dd" @@ -998,6 +1075,14 @@ "@typescript-eslint/types" "4.33.0" eslint-visitor-keys "^2.0.0" +"@typescript-eslint/visitor-keys@5.23.0": + version "5.23.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.23.0.tgz#057c60a7ca64667a39f991473059377a8067c87b" + integrity sha512-Vd4mFNchU62sJB8pX19ZSPog05B0Y0CE2UxAZPT5k4iqhRYjPnqyY3woMxCd0++t9OTqkgjST+1ydLBi7e2Fvg== + dependencies: + "@typescript-eslint/types" "5.23.0" + eslint-visitor-keys "^3.0.0" + "@walletconnect/browser-utils@^1.7.8": version "1.7.8" resolved "https://registry.yarnpkg.com/@walletconnect/browser-utils/-/browser-utils-1.7.8.tgz#c9e27f69d838442d69ccf53cb38ffc3c554baee2" @@ -2467,6 +2552,13 @@ eslint-utils@^2.1.0: dependencies: eslint-visitor-keys "^1.1.0" +eslint-utils@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-3.0.0.tgz#8aebaface7345bb33559db0a1f13a1d2d48c3672" + integrity sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA== + dependencies: + eslint-visitor-keys "^2.0.0" + eslint-visitor-keys@^1.1.0, eslint-visitor-keys@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e" @@ -2477,6 +2569,11 @@ eslint-visitor-keys@^2.0.0: resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303" integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw== +eslint-visitor-keys@^3.0.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz#f6480fa6b1f30efe2d1968aa8ac745b862469826" + integrity sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA== + eslint@7.32.0: version "7.32.0" resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.32.0.tgz#c6d328a14be3fb08c8d1d21e12c02fdb7a2a812d" @@ -3200,7 +3297,7 @@ globals@^13.6.0, globals@^13.9.0: dependencies: type-fest "^0.20.2" -globby@^11.0.3: +globby@^11.0.3, globby@^11.0.4: version "11.1.0" resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b" integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g== @@ -3339,6 +3436,11 @@ human-signals@^1.1.1: resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3" integrity sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw== +husky@^8.0.1: + version "8.0.1" + resolved "https://registry.yarnpkg.com/husky/-/husky-8.0.1.tgz#511cb3e57de3e3190514ae49ed50f6bc3f50b3e9" + integrity sha512-xs7/chUH/CKdOCs7Zy0Aev9e/dKOMZf3K1Az1nar3tzlv0jfqnYtu235bstsWTmXOR0EfINrPa97yy4Lz6RiKw== + iconv-lite@0.4.24: version "0.4.24" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" @@ -3363,7 +3465,7 @@ ignore@^4.0.6: resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc" integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg== -ignore@^5.1.4, ignore@^5.2.0: +ignore@^5.1.4, ignore@^5.1.8, ignore@^5.2.0: version "5.2.0" resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a" integrity sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ== @@ -4797,7 +4899,7 @@ regexp.prototype.flags@^1.4.1: define-properties "^1.1.3" functions-have-names "^1.2.2" -regexpp@^3.1.0: +regexpp@^3.1.0, regexpp@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.2.0.tgz#0425a2768d8f23bad70ca4b90461fa2f1213e1b2" integrity sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==