diff --git a/components/Table/Row.tsx b/components/Table/Row.tsx index bdd53d1..3edf728 100644 --- a/components/Table/Row.tsx +++ b/components/Table/Row.tsx @@ -1,12 +1,5 @@ /* eslint-disable @typescript-eslint/no-misused-promises */ -import { - Header, - Text, - Button, - Box, - StyledOcticon, - TextInput, -} from '@primer/react'; +import { Header, Button, StyledOcticon } from '@primer/react'; import { IssueOpenedIcon, HourglassIcon } from '@primer/octicons-react'; import { useWallet } from '@solana/wallet-adapter-react'; import { useMintAndTransfer } from 'hooks'; diff --git a/contexts/ConnectionContext.ts b/contexts/ConnectionContext.ts index cf74497..e1b704d 100644 --- a/contexts/ConnectionContext.ts +++ b/contexts/ConnectionContext.ts @@ -1,6 +1,7 @@ -import { createContext, useContext } from "react"; -import { WalletAdapterNetwork } from "@solana/wallet-adapter-base"; -import { Connection } from "@solana/web3.js"; +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +import { createContext, useContext } from 'react'; +import { WalletAdapterNetwork } from '@solana/wallet-adapter-base'; +import { Connection } from '@solana/web3.js'; export type Network = keyof typeof WalletAdapterNetwork; type TConnection = { connection: Connection | null; diff --git a/contexts/HasMongoUri.ts b/contexts/HasMongoUri.ts index 8bf6d4e..5263b47 100644 --- a/contexts/HasMongoUri.ts +++ b/contexts/HasMongoUri.ts @@ -1,4 +1,5 @@ -import { createContext, useContext } from "react"; +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +import { createContext, useContext } from 'react'; type HasMongoUri = { hasMongoUri: boolean; diff --git a/contexts/Refresh.ts b/contexts/Refresh.ts index 3b6e1ec..56239b0 100644 --- a/contexts/Refresh.ts +++ b/contexts/Refresh.ts @@ -1,4 +1,5 @@ -import { createContext, useContext } from "react"; +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +import { createContext, useContext } from 'react'; type Refresh = { r: boolean; diff --git a/contexts/SiteMinting.ts b/contexts/SiteMinting.ts index ab4b89f..73f3c77 100644 --- a/contexts/SiteMinting.ts +++ b/contexts/SiteMinting.ts @@ -1,4 +1,6 @@ -import { createContext, useContext } from "react"; +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +/* eslint-disable no-self-assign */ +import { createContext, useContext } from 'react'; type Success = { message: string; @@ -8,7 +10,7 @@ type Success = { }; export const SuccessContext = createContext({ - message: "", + message: '', setMessage: (message: string) => { message = message; }, diff --git a/contexts/index.ts b/contexts/index.ts index 2df7df0..9f9c6f8 100644 --- a/contexts/index.ts +++ b/contexts/index.ts @@ -1,5 +1,5 @@ -export * from "./ConnectionContext" -export * from "./SiteMinting" -export * from "./Refresh" -export * from "./HasMongoUri" -export * from "./ConnectionContext" +export * from './ConnectionContext'; +export * from './SiteMinting'; +export * from './Refresh'; +export * from './HasMongoUri'; +export * from './ConnectionContext'; diff --git a/db/lib.ts b/db/lib.ts index cc23e5c..460300f 100644 --- a/db/lib.ts +++ b/db/lib.ts @@ -1,9 +1,13 @@ -import { connect } from "mongoose"; -import { Token } from "./model"; -import { NewToken } from "types"; -import type { Network } from "contexts"; +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/no-namespace */ +/* eslint-disable no-var */ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +import { connect } from 'mongoose'; +import { Token } from './model'; +import { NewToken } from 'types'; +import type { Network } from 'contexts'; -declare module globalThis { +declare namespace globalThis { var mongoose: any; } @@ -22,7 +26,7 @@ export class Database implements Mongo { private async dbconnect() { try { const MONGO_URI = process.env.NEXT_PUBLIC_DATABASE_URL; - if (!MONGO_URI) throw new Error("Database url not found"); + if (!MONGO_URI) throw new Error('Database url not found'); let cached = globalThis.mongoose; if (!cached) { cached = globalThis.mongoose = { conn: null, promise: null }; @@ -32,9 +36,7 @@ export class Database implements Mongo { bufferCommands: false, }; - cached.promise = connect(MONGO_URI, opts).then((mongoose) => { - return mongoose; - }); + cached.promise = connect(MONGO_URI, opts).then((mongoose) => mongoose); } cached.conn = await cached.promise; return cached.conn; @@ -52,12 +54,10 @@ export class Database implements Mongo { async queryTokens() { await this.dbconnect(); const queryResults: Query[] = (await Token.find()).map( - ({ token, owner }) => { - return { - token, - owner, - }; - } + ({ token, owner }) => ({ + token, + owner, + }) ); return queryResults; } diff --git a/db/model.ts b/db/model.ts index f135c12..11e9632 100644 --- a/db/model.ts +++ b/db/model.ts @@ -1,4 +1,4 @@ -import { Schema, model, models } from "mongoose"; +import { Schema, model, models } from 'mongoose'; const tokenSchema = new Schema({ token: String, @@ -6,4 +6,4 @@ const tokenSchema = new Schema({ keypair: String, }); -export const Token = models.Token || model("Token", tokenSchema); +export const Token = models.Token || model('Token', tokenSchema); diff --git a/fontana.config.ts b/fontana.config.ts index 67305ad..da9daaa 100644 --- a/fontana.config.ts +++ b/fontana.config.ts @@ -3,7 +3,7 @@ interface Config { token: string; owner: string; ticker?: string; - network: "Mainnet" | "Devnet"; + network: 'Mainnet' | 'Devnet'; } /** @@ -13,24 +13,24 @@ interface Config { */ const config: Config[] = [ { - keypair: "WALLET_1", - owner: "BoX451MZzydoVdZE4NFfmMT3J5Ztqo7YgUNbwwMfjPFu", - token: "Gqv2ULNwn7DpU2FRfDwagwNifX4WKPaduah43d5xJGU9", - ticker: "test", - network: "Devnet", + keypair: 'WALLET_1', + owner: 'BoX451MZzydoVdZE4NFfmMT3J5Ztqo7YgUNbwwMfjPFu', + token: 'Gqv2ULNwn7DpU2FRfDwagwNifX4WKPaduah43d5xJGU9', + ticker: 'test', + network: 'Devnet', }, { - keypair: "WALLET_2", - owner: "BoX451MZzydoVdZE4NFfmMT3J5Ztqo7YgUNbwwMfjPFu", - token: "3ji7s3pT4j6EVx4HKFq2PUe2vw7kzzfWCSLdqsQdvk6T", - network: "Devnet", + keypair: 'WALLET_2', + owner: 'BoX451MZzydoVdZE4NFfmMT3J5Ztqo7YgUNbwwMfjPFu', + token: '3ji7s3pT4j6EVx4HKFq2PUe2vw7kzzfWCSLdqsQdvk6T', + network: 'Devnet', }, { - keypair: "WALLET_1", - owner: "BoX451MZzydoVdZE4NFfmMT3J5Ztqo7YgUNbwwMfjPFu", - token: "7efhjQucjgVCgijLewbJZrE16GHba9vdUzmFUdi6vwyc", - ticker: "lol", - network: "Devnet", + keypair: 'WALLET_1', + owner: 'BoX451MZzydoVdZE4NFfmMT3J5Ztqo7YgUNbwwMfjPFu', + token: '7efhjQucjgVCgijLewbJZrE16GHba9vdUzmFUdi6vwyc', + ticker: 'lol', + network: 'Devnet', }, ]; diff --git a/hooks/useCreateToken.ts b/hooks/useCreateToken.ts index 19b59a6..2930e32 100644 --- a/hooks/useCreateToken.ts +++ b/hooks/useCreateToken.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/unbound-method */ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { createAssociatedTokenAccountInstruction, @@ -5,13 +7,18 @@ import { getMinimumBalanceForRentExemptMint, MINT_SIZE, TOKEN_PROGRAM_ID, -} from "@solana/spl-token"; -import { useWallet } from "@solana/wallet-adapter-react"; -import { Keypair, SystemProgram, Transaction } from "@solana/web3.js"; -import { RpcMethods } from "lib/spl"; -import { useRefresh, useSuccess, useHasMongoUri, useConnection } from "contexts"; -import { useState } from "react"; -import { createMint } from "lib/create-token"; +} from '@solana/spl-token'; +import { useWallet } from '@solana/wallet-adapter-react'; +import { Keypair, SystemProgram, Transaction } from '@solana/web3.js'; +import { RpcMethods } from 'lib/spl'; +import { + useRefresh, + useSuccess, + useHasMongoUri, + useConnection, +} from 'contexts'; +import { useState } from 'react'; +import { createMint } from 'lib/create-token'; export default function useCreateToken() { const { r, refresh } = useRefresh(); @@ -26,13 +33,14 @@ export default function useCreateToken() { async function createToken() { if (!publicKey && hasMongoUri && url) { try { - if(network==="Mainnet") throw new Error("Cannot create token in mainnet"); + if (network === 'Mainnet') + throw new Error('Cannot create token in mainnet'); setMinting(true); const tokenData = await createMint(url); if (!tokenData) return; - await fetch("api/mongo-new-token", { - method: "POST", + await fetch('api/mongo-new-token', { + method: 'POST', body: JSON.stringify(tokenData), }); setMinting(false); @@ -59,7 +67,7 @@ export default function useCreateToken() { publicKey.toBase58() ); - let tx = new Transaction() + const tx = new Transaction() .add( SystemProgram.createAccount({ fromPubkey: publicKey, @@ -106,6 +114,6 @@ export default function useCreateToken() { return { createToken, minting, - triggerRefresh - } + triggerRefresh, + }; } diff --git a/hooks/useFetchTokens.ts b/hooks/useFetchTokens.ts index 244ed1f..b0ca486 100644 --- a/hooks/useFetchTokens.ts +++ b/hooks/useFetchTokens.ts @@ -1,8 +1,10 @@ -import { useWallet } from "@solana/wallet-adapter-react"; -import { RpcMethods } from "lib/spl"; -import { useHasMongoUri, useConnection } from "contexts"; -import { useEffect, useMemo, useState } from "react"; -import fontanaConfig from "fontana.config"; +/* eslint-disable @typescript-eslint/no-floating-promises */ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +import { useWallet } from '@solana/wallet-adapter-react'; +import { RpcMethods } from 'lib/spl'; +import { useHasMongoUri, useConnection } from 'contexts'; +import { useEffect, useMemo, useState } from 'react'; +import fontanaConfig from 'fontana.config'; interface Token { token: string; @@ -17,22 +19,25 @@ export default function useFetchTokens() { const [r, refresh] = useState(false); const { hasMongoUri } = useHasMongoUri(); - const tokens = useMemo(() => { - return fontanaConfig.reduce((acc, token) => { - if (token.network === network) { - return [...acc, token]; - } - return [...acc]; - }, [] as Partial); - }, [network]); + const tokens = useMemo( + () => + fontanaConfig.reduce((acc, token) => { + if (token.network === network) { + return [...acc, token]; + } + return [...acc]; + }, [] as Partial), + [network] + ); useEffect(() => { - if (!hasMongoUri || publicKey || network!=="Devnet") return setMongoTokens([]); + if (!hasMongoUri || publicKey || network !== 'Devnet') + return setMongoTokens([]); (async () => { - const res = await fetch("api/mongo-get", { - method: "GET", + const res = await fetch('api/mongo-get', { + method: 'GET', }); - + const { queryResults } = (await res.json()) as { queryResults: Token[]; }; @@ -41,18 +46,15 @@ export default function useFetchTokens() { }, [hasMongoUri, publicKey, r, network]); useEffect(() => { - if (!publicKey || !connection) return setWalletTokens([]); (async () => { const rpc = new RpcMethods(connection); const queryResults = ( await rpc.queryTokenByAuthority(publicKey.toBase58()) - ).map((token) => { - return { - token: token.tokenMint, - owner: publicKey.toBase58(), - }; - }); + ).map((token) => ({ + token: token.tokenMint, + owner: publicKey.toBase58(), + })); setWalletTokens(queryResults); })(); }, [connection, publicKey, r]); diff --git a/hooks/useHandleDestroyAnimated.ts b/hooks/useHandleDestroyAnimated.ts index a731ce1..821cdfa 100644 --- a/hooks/useHandleDestroyAnimated.ts +++ b/hooks/useHandleDestroyAnimated.ts @@ -1,9 +1,9 @@ -import { MutableRefObject, useEffect, useState } from "react"; +import { MutableRefObject, useEffect, useState } from 'react'; const styles = Object.freeze({ - opacity: "0", - transform: "translateY(-50%)", - transition: "all 0.5s", + opacity: '0', + transform: 'translateY(-50%)', + transition: 'all 0.5s', }); export default function useHandleDestroyAnimated( @@ -16,7 +16,6 @@ export default function useHandleDestroyAnimated( if (sendSuccess) { handleDeletion(ref); } - // eslint-disable-next-line react-hooks/exhaustive-deps }, [ref, sendSuccess]); function handleDeletion( @@ -30,7 +29,7 @@ export default function useHandleDestroyAnimated( style.opacity = styles.opacity; setTimeout(() => { setSendSuccess(false); - setMessage(""); + setMessage(''); }, 600); }, 4000); } diff --git a/hooks/useMintAndTransfer.ts b/hooks/useMintAndTransfer.ts index 2c8df44..c92ab64 100644 --- a/hooks/useMintAndTransfer.ts +++ b/hooks/useMintAndTransfer.ts @@ -1,26 +1,30 @@ +/* eslint-disable @typescript-eslint/no-floating-promises */ +/* eslint-disable @typescript-eslint/no-unsafe-argument */ +/* eslint-disable @typescript-eslint/unbound-method */ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { createAssociatedTokenAccountInstruction, createTransferInstruction, -} from "@solana/spl-token"; -import { useWallet } from "@solana/wallet-adapter-react"; -import { PublicKey } from "@solana/web3.js"; -import { RpcMethods } from "lib/spl"; -import { useCallback, useState } from "react"; -import { Actions, RowProps, Sources } from "types"; -import { useSuccess, useConnection } from "contexts"; +} from '@solana/spl-token'; +import { useWallet } from '@solana/wallet-adapter-react'; +import { PublicKey } from '@solana/web3.js'; +import { RpcMethods } from 'lib/spl'; +import { useCallback, useState } from 'react'; +import { Actions, RowProps, Sources } from 'types'; +import { useSuccess, useConnection } from 'contexts'; export default function useMintAndTransfer({ source, tokenOwner, tokenName, tokenKeypair, -}: Exclude) { +}: Exclude) { const { connection, network } = useConnection(); const { publicKey, sendTransaction } = useWallet(); const [transferAmount, setTransferAmount] = useState(1); const [mintedAmount, setMintedAmount] = useState(null); const [walletAmount, setWalletAmount] = useState(null); - const [destinationAddress, setDestinationAddress] = useState(""); + const [destinationAddress, setDestinationAddress] = useState(''); const [mintError, setMintError] = useState(null); const [sendError, setSendError] = useState(null); const [action, setAction] = useState(null); @@ -60,28 +64,28 @@ export default function useMintAndTransfer({ const tx = RpcMethods.createTx(await ix); const signature = await sendTransaction(tx, connection); await rpc.confirmTransaction(signature); - setMessage("Success!"); + setMessage('Success!'); } catch (e) { console.error(e); } } else { try { - const res = await fetch("api/mint/", { - method: "POST", + const res = await fetch('api/mint/', { + method: 'POST', body: JSON.stringify({ owner: tokenOwner, token: tokenName, keypair: tokenKeypair, amount: mintAmount, mongo: source === Sources.Db, - network + network, }), }); const data = await res.json(); - if ("err" in data) { + if ('err' in data) { setMintError(data.err); } else { - setMessage("Success!"); + setMessage('Success!'); } } catch (err) { console.error(err); @@ -101,7 +105,6 @@ export default function useMintAndTransfer({ if (source === Sources.Wallet && publicKey) { // mint and sign from wallet try { - const rpc = new RpcMethods(connection); const ata = await RpcMethods.getAssociatedTokenAccount( tokenName, @@ -141,14 +144,14 @@ export default function useMintAndTransfer({ const tx = RpcMethods.createTx(ix); const signature = await sendTransaction(tx, connection); await rpc.confirmTransaction(signature); - setMessage("Success!"); + setMessage('Success!'); } catch (e) { console.error(e); } } else { try { - const res = await fetch("api/transfer/", { - method: "POST", + const res = await fetch('api/transfer/', { + method: 'POST', body: JSON.stringify({ owner: tokenOwner, token: tokenName, @@ -159,10 +162,10 @@ export default function useMintAndTransfer({ }), }); const data = await res.json(); - if ("err" in data) { + if ('err' in data) { setSendError(data.err); } else { - setMessage("Success!"); + setMessage('Success!'); } } catch (err) { console.error(err); diff --git a/next-env.d.ts b/next-env.d.ts index 4f11a03..22ef223 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -1,5 +1,5 @@ -/// -/// +// / +// / // NOTE: This file should not be edited // see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/package.json b/package.json index bd66975..3d80b43 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dev": "node git-tags.js && next dev", "build": "node git-tags.js && next build", "start": "next start", - "lint": "next lint", + "lint": "npx eslint . --ext .ts,.tsx", "format": "prettier --write \"./**/*.{tsx,ts,js}\"", "prepare": "husky install" },