From 3f85e0e767cb62a0c8da97d4e2f953ea4f0eb331 Mon Sep 17 00:00:00 2001 From: Ted Ian Osias Date: Thu, 21 Dec 2023 21:06:01 +0800 Subject: [PATCH 1/2] refactor(bridge): remove v1 code and unused imports --- .eslintrc.json | 8 +- components/Admin/ConnectAdmin.tsx | 3 +- components/Admin/Provider.tsx | 3 - .../AddLogModals/AddBurnSysTransaction.tsx | 5 - .../AddLogModals/AddNEVMTransactionModal.tsx | 2 - components/Admin/Transfer/Filters.tsx | 4 +- components/Bridge/Stepper.tsx | 2 - .../Transfer/StepSwitch/PaliSwitchNetwork.tsx | 2 - .../Transfer/StepSwitch/WaitNEVMSign.tsx | 1 - components/Bridge/WalletInfo.tsx | 137 ------------------ components/Bridge/WalletSwitch.tsx | 68 --------- components/Bridge/v3/Stepper.tsx | 1 - .../v3/Steps/ConfirmNEVMTransaction.tsx | 2 +- .../v3/Steps/ConfirmUTXOTransaction.tsx | 2 +- .../Bridge/v3/Steps/ConnectValidate.tsx | 1 - .../v3/Steps/ConnectValidate/AmountField.tsx | 2 - .../ConnectValidate/StartTransferButton.tsx | 2 +- components/Bridge/v3/Steps/SubmitProofs.tsx | 2 +- components/Bridge/v3/hooks/useBurnSysx.tsx | 1 - .../v3/hooks/useSyscoinSubmitProofs.tsx | 1 - components/Home/FAQ.tsx | 1 - components/Navigation/Navigation.tsx | 1 - package.json | 1 + pages/admin/login.tsx | 2 +- pages/bridge/[id].tsx | 98 ------------- pages/transfers/index.tsx | 5 +- yarn.lock | 12 ++ 27 files changed, 30 insertions(+), 339 deletions(-) delete mode 100644 components/Bridge/WalletInfo.tsx delete mode 100644 components/Bridge/WalletSwitch.tsx delete mode 100644 pages/bridge/[id].tsx diff --git a/.eslintrc.json b/.eslintrc.json index bffb357a..e93dde1e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,3 +1,9 @@ { - "extends": "next/core-web-vitals" + "extends": "next/core-web-vitals", + "plugins": ["unused-imports"], + "rules": { + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": "off", + "unused-imports/no-unused-imports": "error" + } } diff --git a/components/Admin/ConnectAdmin.tsx b/components/Admin/ConnectAdmin.tsx index b2b46d99..5cd564b2 100644 --- a/components/Admin/ConnectAdmin.tsx +++ b/components/Admin/ConnectAdmin.tsx @@ -1,7 +1,6 @@ import { useNEVM } from "@contexts/ConnectedWallet/NEVMProvider"; import { usePaliWalletV2 } from "@contexts/PaliWallet/usePaliWallet"; -import { Button, Typography } from "@mui/material"; -import { useAdmin } from "./Provider"; +import { Button } from "@mui/material"; const ConnectAdmin = () => { const { account, connect } = useNEVM(); diff --git a/components/Admin/Provider.tsx b/components/Admin/Provider.tsx index 607744e7..eb8b46cf 100644 --- a/components/Admin/Provider.tsx +++ b/components/Admin/Provider.tsx @@ -1,8 +1,5 @@ import { useNEVM } from "@contexts/ConnectedWallet/NEVMProvider"; -import { usePaliWalletV2 } from "@contexts/PaliWallet/usePaliWallet"; -import { Button, Container, Typography } from "@mui/material"; import { IAdmin } from "models/admin"; -import { NextPage } from "next"; import { createContext, useContext, useMemo } from "react"; import { useQuery } from "react-query"; diff --git a/components/Admin/Transfer/AddLogModals/AddBurnSysTransaction.tsx b/components/Admin/Transfer/AddLogModals/AddBurnSysTransaction.tsx index 84e32096..1dd6767d 100644 --- a/components/Admin/Transfer/AddLogModals/AddBurnSysTransaction.tsx +++ b/components/Admin/Transfer/AddLogModals/AddBurnSysTransaction.tsx @@ -5,11 +5,6 @@ type Props = { transferId: string; }; -type FormValues = { - txId: string; - clearAll: boolean; -}; - const AddBurnSysTransaction: React.FC = ({ onClose, transferId }) => { return ( { const { get } = useSearchParams(); diff --git a/components/Bridge/Stepper.tsx b/components/Bridge/Stepper.tsx index 98c564f7..5de92267 100644 --- a/components/Bridge/Stepper.tsx +++ b/components/Bridge/Stepper.tsx @@ -1,7 +1,5 @@ import { Alert, Step, StepLabel, Stepper } from "@mui/material"; -import { TransferStatus } from "contexts/Transfer/types"; import { useTransfer } from "contexts/Transfer/useTransfer"; -import { useMemo } from "react"; const BridgeTransferStepper: React.FC = () => { const { diff --git a/components/Bridge/Transfer/StepSwitch/PaliSwitchNetwork.tsx b/components/Bridge/Transfer/StepSwitch/PaliSwitchNetwork.tsx index bd73668a..5a30e6e0 100644 --- a/components/Bridge/Transfer/StepSwitch/PaliSwitchNetwork.tsx +++ b/components/Bridge/Transfer/StepSwitch/PaliSwitchNetwork.tsx @@ -1,7 +1,5 @@ import { useNEVM } from "@contexts/ConnectedWallet/NEVMProvider"; -import { IPaliWalletV2Context } from "@contexts/PaliWallet/V2Provider"; import { - usePaliWallet, usePaliWalletV2, } from "@contexts/PaliWallet/usePaliWallet"; import { useTransfer } from "@contexts/Transfer/useTransfer"; diff --git a/components/Bridge/Transfer/StepSwitch/WaitNEVMSign.tsx b/components/Bridge/Transfer/StepSwitch/WaitNEVMSign.tsx index 7bc87af1..1cd56f33 100644 --- a/components/Bridge/Transfer/StepSwitch/WaitNEVMSign.tsx +++ b/components/Bridge/Transfer/StepSwitch/WaitNEVMSign.tsx @@ -1,5 +1,4 @@ import { useConnectedWallet } from "@contexts/ConnectedWallet/useConnectedWallet"; -import { usePaliWalletV2 } from "@contexts/PaliWallet/usePaliWallet"; import { useTransfer } from "@contexts/Transfer/useTransfer"; import { Alert, AlertColor, Button } from "@mui/material"; diff --git a/components/Bridge/WalletInfo.tsx b/components/Bridge/WalletInfo.tsx deleted file mode 100644 index 1f514f2e..00000000 --- a/components/Bridge/WalletInfo.tsx +++ /dev/null @@ -1,137 +0,0 @@ -import { UTXOInfo } from "@contexts/ConnectedWallet/types"; -import { TransferType } from "@contexts/Transfer/types"; -import { useTransfer } from "@contexts/Transfer/useTransfer"; -import { - Alert, - Box, - Button, - Card, - CardContent, - Link, - Tooltip, - Typography, -} from "@mui/material"; -import Image from "next/image"; -import { useConnectedWallet } from "../../contexts/ConnectedWallet/useConnectedWallet"; -import SyscoinLogo from "../Icons/syscoin"; - -type WalletType = "utxo" | "nevm" | string; - -interface IProps { - label: string; - walletType: WalletType; - account: string | undefined; - network: { - name: string; - symbol: string; - }; -} - -const UTXOAddress: React.FC<{ - type: TransferType; - utxo: Partial; -}> = ({ type, utxo }) => { - return ( - - - {utxo.account} - - - ); -}; - -const BridgeWalletInfo: React.FC = ({ label, network, walletType }) => { - const { nevm, utxo, connectUTXO, connectNEVM } = useConnectedWallet(); - const { transfer } = useTransfer(); - - const balance = parseFloat( - (walletType === "utxo" ? `${utxo.balance}` : nevm.balance) ?? "0" - ).toFixed(4); - const balanceLabel = `${label} Balance: ${balance}`; - - return ( - - - - - - - {network.name} - - - {balanceLabel} - - - - - {walletType === "utxo" && utxo.type === "pali-wallet" && ( - - PaliWallet logo - {transfer.status === "initialize" ? ( - utxo.xpub ? ( - - ) : ( - - ) - ) : utxo.account ? ( - utxo.account === transfer.utxoAddress ? ( - - ) : ( - - Change to {transfer.utxoAddress} - - ) - ) : ( - - )} - - )} - {walletType === "nevm" && nevm.type === "metamask" && ( - <> - - Metamask logo - {transfer.status === "initialize" ? ( - nevm.account ? ( - {nevm.account} - ) : ( - - ) - ) : ( - {transfer.nevmAddress} - )} - - {(parseFloat(nevm.balance!) ?? 0) < 0.001 && ( - - - It seems your wallet does not have any balance. In order to - complete a transaction you need to have SYS in your wallet. - - - Please go to{" "} - - https://faucet.syscoin.org/ - - - - )} - - )} - - ); -}; - -export default BridgeWalletInfo; diff --git a/components/Bridge/WalletSwitch.tsx b/components/Bridge/WalletSwitch.tsx deleted file mode 100644 index b6e3346d..00000000 --- a/components/Bridge/WalletSwitch.tsx +++ /dev/null @@ -1,68 +0,0 @@ -import { useTransfer } from "@contexts/Transfer/useTransfer"; -import { CompareArrows, ArrowForward } from "@mui/icons-material"; -import { Grid, IconButton, Typography, Box, Button } from "@mui/material"; -import BridgeWalletInfo from "./WalletInfo"; - -const BridgeWalletSwitch: React.FC = () => { - const { - transfer: { type, status, amount }, - setTransferType, - } = useTransfer(); - - const utxoWalletInfo = { - walletType: "utxo", - account: "0x0", - network: { name: "Syscoin Network", symbol: "SYS" }, - }; - - const nevmWalletInfo = { - walletType: "nevm", - account: "0x0", - network: { name: "NEVM Network", symbol: "NEVM" }, - }; - - return ( - - - - - - - {status !== "initialize" && ( - - {amount} SYS - - )} - {status === "initialize" ? ( - - ) : ( - - - - )} - - - - - - - ); -}; - -export default BridgeWalletSwitch; diff --git a/components/Bridge/v3/Stepper.tsx b/components/Bridge/v3/Stepper.tsx index 0929ff27..9b63000b 100644 --- a/components/Bridge/v3/Stepper.tsx +++ b/components/Bridge/v3/Stepper.tsx @@ -5,7 +5,6 @@ import { ETH_TO_SYS_TRANSFER_STATUS, SYS_TO_ETH_TRANSFER_STATUS, } from "@contexts/Transfer/types"; -import { Close } from "@mui/icons-material"; const NEVMToSYSStepper: React.FC<{ activeStep: number }> = ({ activeStep }) => ( diff --git a/components/Bridge/v3/Steps/ConfirmNEVMTransaction.tsx b/components/Bridge/v3/Steps/ConfirmNEVMTransaction.tsx index f692b394..a7c64ef1 100644 --- a/components/Bridge/v3/Steps/ConfirmNEVMTransaction.tsx +++ b/components/Bridge/v3/Steps/ConfirmNEVMTransaction.tsx @@ -1,6 +1,6 @@ import { ITransferLog, TransferStatus } from "@contexts/Transfer/types"; import { useTransfer } from "../context/TransferContext"; -import { Alert, CircularProgress, Link, Typography } from "@mui/material"; +import { Alert, CircularProgress, Link } from "@mui/material"; import { useNevmTransaction } from "../hooks/useNevmTransaction"; import { useEffect } from "react"; import { NEVM_TX_BLOCKCHAIN_URL } from "@constants"; diff --git a/components/Bridge/v3/Steps/ConfirmUTXOTransaction.tsx b/components/Bridge/v3/Steps/ConfirmUTXOTransaction.tsx index c9317669..02a2daa1 100644 --- a/components/Bridge/v3/Steps/ConfirmUTXOTransaction.tsx +++ b/components/Bridge/v3/Steps/ConfirmUTXOTransaction.tsx @@ -1,4 +1,4 @@ -import { Alert, Box, CircularProgress, Link } from "@mui/material"; +import { Alert, CircularProgress, Link } from "@mui/material"; import { useTransfer } from "../context/TransferContext"; import { useUtxoTransaction } from "components/Bridge/v3/hooks/useUtxoTransaction"; import { ITransferLog, TransferStatus } from "@contexts/Transfer/types"; diff --git a/components/Bridge/v3/Steps/ConnectValidate.tsx b/components/Bridge/v3/Steps/ConnectValidate.tsx index ec3a4a89..f2cb38f5 100644 --- a/components/Bridge/v3/Steps/ConnectValidate.tsx +++ b/components/Bridge/v3/Steps/ConnectValidate.tsx @@ -17,7 +17,6 @@ import { SYS_TO_ETH_TRANSFER_STATUS, TransferStatus, } from "@contexts/Transfer/types"; -import { CloseOutlined } from "@mui/icons-material"; import { Box, Typography } from "@mui/material"; import { useTransfer } from "../context/TransferContext"; diff --git a/components/Bridge/v3/Steps/ConnectValidate/AmountField.tsx b/components/Bridge/v3/Steps/ConnectValidate/AmountField.tsx index 1a4e05cd..ed551b62 100644 --- a/components/Bridge/v3/Steps/ConnectValidate/AmountField.tsx +++ b/components/Bridge/v3/Steps/ConnectValidate/AmountField.tsx @@ -1,11 +1,9 @@ import { ITransfer } from "@contexts/Transfer/types"; -import { QuestionMarkOutlined } from "@mui/icons-material"; import { Alert, Box, InputAdornment, TextField, - Tooltip, Typography, } from "@mui/material"; import { useFormContext } from "react-hook-form"; diff --git a/components/Bridge/v3/Steps/ConnectValidate/StartTransferButton.tsx b/components/Bridge/v3/Steps/ConnectValidate/StartTransferButton.tsx index 100048fb..ddeb14d5 100644 --- a/components/Bridge/v3/Steps/ConnectValidate/StartTransferButton.tsx +++ b/components/Bridge/v3/Steps/ConnectValidate/StartTransferButton.tsx @@ -1,7 +1,7 @@ import { MIN_AMOUNT } from "@constants"; import { SYSX_ASSET_GUID } from "@contexts/Transfer/constants"; import { ITransfer } from "@contexts/Transfer/types"; -import { CheckCircleOutline, CloseOutlined } from "@mui/icons-material"; +import { CheckCircleOutline } from "@mui/icons-material"; import { Box, Button, Typography } from "@mui/material"; import { isValidEthereumAddress, diff --git a/components/Bridge/v3/Steps/SubmitProofs.tsx b/components/Bridge/v3/Steps/SubmitProofs.tsx index bac87049..292a5010 100644 --- a/components/Bridge/v3/Steps/SubmitProofs.tsx +++ b/components/Bridge/v3/Steps/SubmitProofs.tsx @@ -1,4 +1,4 @@ -import { Alert, Box, Button, Divider, Typography } from "@mui/material"; +import { Alert, Box, Button, Typography } from "@mui/material"; import { useTransfer } from "../context/TransferContext"; import { ITransferLog, diff --git a/components/Bridge/v3/hooks/useBurnSysx.tsx b/components/Bridge/v3/hooks/useBurnSysx.tsx index 9012b67e..e1938cb0 100644 --- a/components/Bridge/v3/hooks/useBurnSysx.tsx +++ b/components/Bridge/v3/hooks/useBurnSysx.tsx @@ -1,4 +1,3 @@ -import burnSysToSysx from "@contexts/Transfer/functions/burnSysToSysx"; import { ITransfer } from "@contexts/Transfer/types"; import { useMutation } from "react-query"; import { useSyscoin } from "../context/Syscoin"; diff --git a/components/Bridge/v3/hooks/useSyscoinSubmitProofs.tsx b/components/Bridge/v3/hooks/useSyscoinSubmitProofs.tsx index df730b68..4dca35fc 100644 --- a/components/Bridge/v3/hooks/useSyscoinSubmitProofs.tsx +++ b/components/Bridge/v3/hooks/useSyscoinSubmitProofs.tsx @@ -2,7 +2,6 @@ import { ITransfer } from "@contexts/Transfer/types"; import { useMutation } from "react-query"; import { useWeb3 } from "../context/Web"; import { ISponsorWalletTransaction } from "models/sponsor-wallet-transactions"; -import { rejects } from "assert"; const useSyscoinSubmitProofs = ( transfer: ITransfer, diff --git a/components/Home/FAQ.tsx b/components/Home/FAQ.tsx index 2b63ae57..72eb445b 100644 --- a/components/Home/FAQ.tsx +++ b/components/Home/FAQ.tsx @@ -2,7 +2,6 @@ import { Accordion, AccordionDetails, AccordionSummary, - Box, Container, Link, Typography, diff --git a/components/Navigation/Navigation.tsx b/components/Navigation/Navigation.tsx index 466e0169..3619176e 100644 --- a/components/Navigation/Navigation.tsx +++ b/components/Navigation/Navigation.tsx @@ -1,4 +1,3 @@ -import { useConnectedWallet } from "@contexts/ConnectedWallet/useConnectedWallet"; import { List } from "@mui/material"; import NavigationItem, { INavigationItem } from "./Item"; diff --git a/package.json b/package.json index 027ffbf9..e8cdecae 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "bitcoin-proof": "^2.0.0", "bitcoinjs-lib": "^6.0.1", "date-fns": "^2.30.0", + "eslint-plugin-unused-imports": "^3.0.0", "firebase": "^9.22.1", "firebase-admin": "^10.2.0", "iron-session": "^6.3.1", diff --git a/pages/admin/login.tsx b/pages/admin/login.tsx index 62a139df..7e569e7a 100644 --- a/pages/admin/login.tsx +++ b/pages/admin/login.tsx @@ -1,6 +1,6 @@ import { ADMIN_LOGIN_MESSAGE } from "@constants"; import { useNEVM } from "@contexts/ConnectedWallet/NEVMProvider"; -import { Button, Container, Typography } from "@mui/material"; +import { Button, Container } from "@mui/material"; import ConnectAdmin from "components/Admin/ConnectAdmin"; import { GetServerSideProps, NextPage } from "next"; import { useRouter } from "next/router"; diff --git a/pages/bridge/[id].tsx b/pages/bridge/[id].tsx deleted file mode 100644 index 142c43c2..00000000 --- a/pages/bridge/[id].tsx +++ /dev/null @@ -1,98 +0,0 @@ -import { - Alert, - Button, - CircularProgress, - Container, - Grid, - Typography, -} from "@mui/material"; -import { NextPage } from "next"; -import DrawerPage from "../../components/DrawerPage"; -import TransferProvider from "../../contexts/Transfer/Provider"; -import BridgeTransferStepSwitch from "components/Bridge/Transfer/StepSwitch"; -import BridgeTransferStepper from "components/Bridge/Stepper"; -import { useRouter } from "next/router"; -import { ITransfer } from "contexts/Transfer/types"; -import BridgeWalletSwitch from "components/Bridge/WalletSwitch"; -import { usePaliWallet } from "@contexts/PaliWallet/usePaliWallet"; -import BlocktimeDisclaimer from "components/BlocktimeDisclaimer"; -import TransferTitle from "components/Bridge/Transfer/Title"; -import { useNEVM } from "@contexts/ConnectedWallet/NEVMProvider"; -import { INavigationItem } from "components/Navigation/Item"; -import { useConnectedWallet } from "@contexts/ConnectedWallet/useConnectedWallet"; - -interface Props { - transfer: ITransfer; -} - -const Bridge: NextPage = ({ transfer }) => { - const router = useRouter(); - const paliWallet = usePaliWallet(); - const metamask = useNEVM(); - const { nevm, utxo } = useConnectedWallet(); - const { id } = router.query; - - const routes: INavigationItem[] = [ - { - label: "New Transfer", - path: `/bridge/${utxo.type === nevm.type ? "v2/" : ""}${Date.now()}`, - }, - { - label: "My Transfers", - path: "/transfers", - }, - { - label: "FAQ", - path: "/#faq", - }, - ]; - - if (!id) { - return ; - } - - return ( - - - - - {paliWallet.isTestnet && ( - - Your Pali Wallet is not set to SYS Main Network. - - )} - {metamask.isTestnet && ( - metamask.switchToMainnet()}> - Switch - - } - sx={{ mb: 2 }} - > - Your Metamask is not set to NEVM Main Network. - - )} - - Bridge Your SYS - - - Trustlessly transfer SYS back and forth between the Syscoin Base and - Syscoin NEVM blockchains without middlemen! - - - - - - - - - - - - - ); -}; - -export default Bridge; diff --git a/pages/transfers/index.tsx b/pages/transfers/index.tsx index d8c7f52b..2cb27de1 100644 --- a/pages/transfers/index.tsx +++ b/pages/transfers/index.tsx @@ -1,5 +1,5 @@ import { usePaliWalletV2 } from "@contexts/PaliWallet/usePaliWallet"; -import { Alert, Box, Button, Container, Typography } from "@mui/material"; +import { Alert, Container, Typography } from "@mui/material"; import DrawerPage from "components/DrawerPage"; import { INavigationItem } from "components/Navigation/Item"; import TransferDataGrid from "components/Transfer/DataGrid"; @@ -7,7 +7,6 @@ import WalletList from "components/WalletList"; import { useConnectedWallet } from "contexts/ConnectedWallet/useConnectedWallet"; import { ITransfer } from "contexts/Transfer/types"; import { NextPage } from "next"; -import NextLink from "next/link"; import { useEffect, useState } from "react"; const TransfersPage: NextPage = () => { @@ -44,7 +43,7 @@ const TransfersPage: NextPage = () => { setItems( Object.entries(localStorage) .filter(([key]) => key.startsWith("transfer-")) - .map(([key, value]) => JSON.parse(value)) + .map(([_, value]) => JSON.parse(value)) ); }, []); diff --git a/yarn.lock b/yarn.lock index 820d8482..aa0801b7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5154,6 +5154,18 @@ eslint-plugin-react@^7.29.4: semver "^6.3.0" string.prototype.matchall "^4.0.8" +eslint-plugin-unused-imports@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-3.0.0.tgz#d25175b0072ff16a91892c3aa72a09ca3a9e69e7" + integrity sha512-sduiswLJfZHeeBJ+MQaG+xYzSWdRXoSw61DpU13mzWumCkR0ufD0HmO4kdNokjrkluMHpj/7PJeN35pgbhW3kw== + dependencies: + eslint-rule-composer "^0.3.0" + +eslint-rule-composer@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/eslint-rule-composer/-/eslint-rule-composer-0.3.0.tgz#79320c927b0c5c0d3d3d2b76c8b4a488f25bbaf9" + integrity sha512-bt+Sh8CtDmn2OajxvNO+BX7Wn4CIWMpTRm3MaiKPCQcnnlm0CS2mhui6QaoeQugs+3Kj2ESKEEGJUdVafwhiCg== + eslint-scope@^7.1.1: version "7.1.1" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-7.1.1.tgz#fff34894c2f65e5226d3041ac480b4513a163642" From 442fd97b244d3470cfaba226d96abe78ab550343 Mon Sep 17 00:00:00 2001 From: Ted Ian Osias Date: Thu, 21 Dec 2023 21:06:48 +0800 Subject: [PATCH 2/2] ci: add lint check --- .github/workflows/ci-checks.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-checks.yaml b/.github/workflows/ci-checks.yaml index 832ba8b9..bdf1336b 100644 --- a/.github/workflows/ci-checks.yaml +++ b/.github/workflows/ci-checks.yaml @@ -27,6 +27,8 @@ jobs: - name: Install Yarn run: npm install -g yarn - name: Install Dependencies - run: yarn + run: yarn + - name: Lint Code + run: yarn lint - name: Build Application run: yarn build