Skip to content

Commit

Permalink
fix: all warnings in the project (#48)
Browse files Browse the repository at this point in the history
* add husky precommit and configure linter

* fix all errors

* add linter workflow

* fix ci

* fix warnings

* fix ci

* feat: update lint script

* feat: fix errs and warnings

Co-authored-by: Arnau Espin <[email protected]>
  • Loading branch information
evavirseda and aspnxdd authored Jan 24, 2023
1 parent 2087bf5 commit 5f26b7b
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 119 deletions.
9 changes: 1 addition & 8 deletions components/Table/Row.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
7 changes: 4 additions & 3 deletions contexts/ConnectionContext.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 2 additions & 1 deletion contexts/HasMongoUri.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 2 additions & 1 deletion contexts/Refresh.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 4 additions & 2 deletions contexts/SiteMinting.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,7 +10,7 @@ type Success = {
};

export const SuccessContext = createContext<Success>({
message: "",
message: '',
setMessage: (message: string) => {
message = message;
},
Expand Down
10 changes: 5 additions & 5 deletions contexts/index.ts
Original file line number Diff line number Diff line change
@@ -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';
30 changes: 15 additions & 15 deletions db/lib.ts
Original file line number Diff line number Diff line change
@@ -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;
}

Expand All @@ -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 };
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions db/model.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Schema, model, models } from "mongoose";
import { Schema, model, models } from 'mongoose';

const tokenSchema = new Schema({
token: String,
owner: String,
keypair: String,
});

export const Token = models.Token || model("Token", tokenSchema);
export const Token = models.Token || model('Token', tokenSchema);
30 changes: 15 additions & 15 deletions fontana.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ interface Config {
token: string;
owner: string;
ticker?: string;
network: "Mainnet" | "Devnet";
network: 'Mainnet' | 'Devnet';
}

/**
Expand All @@ -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',
},
];

Expand Down
34 changes: 21 additions & 13 deletions hooks/useCreateToken.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
/* eslint-disable @typescript-eslint/unbound-method */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */

import {
createAssociatedTokenAccountInstruction,
createInitializeMintInstruction,
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();
Expand All @@ -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);
Expand All @@ -59,7 +67,7 @@ export default function useCreateToken() {
publicKey.toBase58()
);

let tx = new Transaction()
const tx = new Transaction()
.add(
SystemProgram.createAccount({
fromPubkey: publicKey,
Expand Down Expand Up @@ -106,6 +114,6 @@ export default function useCreateToken() {
return {
createToken,
minting,
triggerRefresh
}
triggerRefresh,
};
}
50 changes: 26 additions & 24 deletions hooks/useFetchTokens.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<typeof fontanaConfig>);
}, [network]);
const tokens = useMemo(
() =>
fontanaConfig.reduce((acc, token) => {
if (token.network === network) {
return [...acc, token];
}
return [...acc];
}, [] as Partial<typeof fontanaConfig>),
[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[];
};
Expand All @@ -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]);
Expand Down
11 changes: 5 additions & 6 deletions hooks/useHandleDestroyAnimated.ts
Original file line number Diff line number Diff line change
@@ -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<T extends HTMLElement>(
Expand All @@ -16,7 +16,6 @@ export default function useHandleDestroyAnimated<T extends HTMLElement>(
if (sendSuccess) {
handleDeletion(ref);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ref, sendSuccess]);

function handleDeletion<T extends HTMLElement>(
Expand All @@ -30,7 +29,7 @@ export default function useHandleDestroyAnimated<T extends HTMLElement>(
style.opacity = styles.opacity;
setTimeout(() => {
setSendSuccess(false);
setMessage("");
setMessage('');
}, 600);
}, 4000);
}
Expand Down
Loading

0 comments on commit 5f26b7b

Please sign in to comment.