Skip to content

Commit

Permalink
Update linter to be more consistent across packages
Browse files Browse the repository at this point in the history
  • Loading branch information
venables committed Feb 3, 2022
1 parent 9f64d9f commit a9551b8
Show file tree
Hide file tree
Showing 122 changed files with 263 additions and 152 deletions.
19 changes: 16 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { resolve } = require("path")

module.exports = {
env: {
browser: true,
Expand All @@ -9,20 +7,35 @@ module.exports = {
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"prettier"
],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
rules: {
"import/order": [
"error",
{
"newlines-between": "always",
groups: [
["builtin", "external", "internal"],
["sibling", "parent"],
"index",
"object",
"type"
],
alphabetize: {
order: "asc"
}
}
],
"no-empty": ["error", { allowEmptyCatch: true }],
"no-warning-comments": "warn"
"no-warning-comments": "warn",
"@typescript-eslint/no-unused-vars": [
"warn",
{ varsIgnorePattern: "^_", argsIgnorePattern: "^_" }
]
},
settings: {
"import/parsers": {
Expand Down
1 change: 0 additions & 1 deletion packages/demo-issuer/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
root: true,
extends: ["next"],
settings: {
react: {
Expand Down
2 changes: 1 addition & 1 deletion packages/demo-issuer/pages/api/challenges/[token].ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { buildKycAmlManifest, buildCredentialOffer } from "verite"
import { NextApiRequest, NextApiResponse } from "next"
import { v4 as uuidv4 } from "uuid"
import { buildKycAmlManifest, buildCredentialOffer } from "verite"

export default async function challenges(
req: NextApiRequest,
Expand Down
6 changes: 3 additions & 3 deletions packages/demo-issuer/pages/api/credentials/[token].ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import jwt from "jsonwebtoken"
import { NextApiRequest, NextApiResponse } from "next"
import {
buildAndSignFulfillment,
decodeCredentialApplication,
KYCAMLAttestation,
CreditScoreAttestation,
buildIssuer
} from "verite"
import { NextApiRequest, NextApiResponse } from "next"
import jwt from "jsonwebtoken"

export default async function credentials(
req: NextApiRequest,
Expand Down Expand Up @@ -38,7 +38,7 @@ export default async function credentials(
* the requirements. The demo extracts the user id, but for demo purposes
* we assume the user meets the requirements.
*/
const user = jwt.decode(req.query.token as string).sub
const _user = jwt.decode(req.query.token as string).sub

/**
* Generate the attestation.
Expand Down
16 changes: 6 additions & 10 deletions packages/demo-issuer/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import jwt from "jsonwebtoken"
import Head from "next/head"
import QRCode from "qrcode.react"
import { useState } from "react"
import {
randomDidKey,
buildCredentialApplication,
Expand All @@ -9,16 +13,8 @@ import {
decodeCredentialApplication,
DecodedCredentialApplication
} from "verite"
import type {
CredentialManifest,
RevocablePresentation,
Verifiable,
W3CPresentation
} from "verite"
import Head from "next/head"
import QRCode from "qrcode.react"
import { useState } from "react"
import jwt from "jsonwebtoken"

import type { RevocablePresentation, Verifiable, W3CPresentation } from "verite"

type Presentation = Verifiable<W3CPresentation | RevocablePresentation>

Expand Down
1 change: 0 additions & 1 deletion packages/demo-revocation/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
root: true,
extends: ["next"],
settings: {
react: {
Expand Down
19 changes: 8 additions & 11 deletions packages/demo-revocation/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import Head from "next/head"
import { useState } from "react"
import useSWR from "swr"
import useSWRImmutable from "swr/immutable"
import {
buildAndSignVerifiableCredential,
buildIssuer,
Expand All @@ -10,16 +14,13 @@ import {
revokeCredential,
unrevokeCredential
} from "verite"

import type {
KYCAMLAttestation,
Verifiable,
W3CCredential,
Issuer
} from "verite"
import Head from "next/head"
import useSWRImmutable from "swr/immutable"
import useSWR from "swr"
import { useState } from "react"

// In a production environment, these values would be secured by the issuer
const issuer = buildIssuer(
Expand Down Expand Up @@ -127,20 +128,16 @@ export default function Home(): JSX.Element {
)
}

// Component to render the issued credentail
// Component to render the issued credential
const Credential = ({
credential,
revocationList
credential
}: {
credential:
| Verifiable<W3CCredential>
| RevocationListCredential
| RevocableCredential
revocationList: RevocationListCredential
}) => {
const { data } = useSWR("revoked", async () =>
isRevoked(credential, revocationList)
)
return (
<>
<div className="prose" style={{ maxWidth: "100%" }}>
Expand Down Expand Up @@ -241,7 +238,7 @@ export default function Home(): JSX.Element {
</p>
<p>
To simplify the demo, everything is performed within the browser. In
a produciton envrionment:
a production environment:
</p>
<ul>
<li>
Expand Down
1 change: 0 additions & 1 deletion packages/demo-verifier/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
root: true,
extends: ["next"],
settings: {
react: {
Expand Down
2 changes: 1 addition & 1 deletion packages/demo-verifier/pages/api/job.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { challengeTokenUrlWrapper, PresentationDefinition } from "verite"
import jwt from "jsonwebtoken"
import { NextApiRequest, NextApiResponse } from "next"
import { challengeTokenUrlWrapper } from "verite"

export default async function job(
req: NextApiRequest,
Expand Down
6 changes: 3 additions & 3 deletions packages/demo-verifier/pages/api/verifications/[token].ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import jwt from "jsonwebtoken"
import { NextApiRequest, NextApiResponse } from "next"
import { v4 as uuidv4 } from "uuid"
import {
kycPresentationDefinition,
buildKycVerificationOffer,
validateVerificationSubmission,
verificationResult
} from "verite"
import { NextApiRequest, NextApiResponse } from "next"
import jwt from "jsonwebtoken"
import { v4 as uuidv4 } from "uuid"

export default async function verifications(
req: NextApiRequest,
Expand Down
13 changes: 7 additions & 6 deletions packages/demo-verifier/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import { CheckIcon, XIcon } from "@heroicons/react/solid"
import { W3CCredential } from "did-jwt-vc"
import Head from "next/head"
import QRCode from "qrcode.react"
import { useState } from "react"
import useSWRImmutable from "swr/immutable"
import {
randomDidKey,
buildAndSignVerifiableCredential,
Expand All @@ -9,13 +15,8 @@ import {
VerificationOffer,
ChallengeTokenUrlWrapper
} from "verite"

import type { Verifiable } from "verite"
import Head from "next/head"
import QRCode from "qrcode.react"
import { useState } from "react"
import useSWRImmutable from "swr/immutable"
import { W3CCredential } from "did-jwt-vc"
import { CheckIcon, XIcon } from "@heroicons/react/solid"

const holder = randomDidKey()

Expand Down
9 changes: 5 additions & 4 deletions packages/docs/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from "react"
import clsx from "clsx"
import Layout from "@theme/Layout"
import Link from "@docusaurus/Link"
import useDocusaurusContext from "@docusaurus/useDocusaurusContext"
import styles from "./index.module.css"
import Layout from "@theme/Layout"
import clsx from "clsx"
import React from "react"

import HomepageFeatures from "../components/HomepageFeatures"
import RequirePassword from "../components/RequirePassword"
import styles from "./index.module.css"

function HomepageHeader() {
const { siteConfig } = useDocusaurusContext()
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-demo/components/auth/SignInForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { signIn } from "next-auth/client"
import { FC, useState } from "react"

import { LoadingButton } from "../shared/LoadingButton"

type Props = {
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-demo/components/demos/cefi/HistoryItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CashIcon } from "@heroicons/react/solid"
import { formatDistanceToNow } from "date-fns"
import { useSession } from "next-auth/client"

import { History } from "../../../lib/database/prisma"

type Props = {
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-demo/components/demos/cefi/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useSession } from "next-auth/client"
import { FC } from "react"

import Layout from "../../shared/Layout"
import Navigation from "./Navigation"

Expand Down
1 change: 1 addition & 0 deletions packages/e2e-demo/components/demos/cefi/Navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useSession, signout } from "next-auth/client"
import Image from "next/image"
import { FC } from "react"

import { useBalance } from "../../../hooks/useBalance"

const logoForSession = (session): JSX.Element => {
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-demo/components/demos/cefi/PickupPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useSession } from "next-auth/client"

import { PendingReceive } from "../../../lib/database"
import { LoadingButton } from "../../shared/LoadingButton"

Expand Down
1 change: 1 addition & 0 deletions packages/e2e-demo/components/demos/cefi/SignInFormCeFi.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { signIn } from "next-auth/client"
import { FC, useState } from "react"

import { LoadingButton } from "../../shared/LoadingButton"

type SampleUser = {
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-demo/components/demos/dapp/ConnectWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Web3Provider } from "@ethersproject/providers"
import { PlusIcon } from "@heroicons/react/solid"
import { useWeb3React } from "@web3-react/core"
import { FC } from "react"

import { injectedConnector } from "../../../lib/eth-fns"

const ConnectWallet: FC = () => {
Expand Down
32 changes: 13 additions & 19 deletions packages/e2e-demo/components/demos/dapp/Dapp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,22 @@ import { useWeb3React } from "@web3-react/core"
import { Contract } from "ethers"
import React, { FC, useEffect, useState } from "react"
import useSWR from "swr"
import type { VerificationResultResponse } from "verite"

// import the contract's artifacts and address
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import TokenArtifact from "../../../contracts/ThresholdToken.json"
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import contractAddressJSON from "../../../contracts/threshold-token-address.json"
import { contractFetcher } from "../../../lib/eth-fns"
import {
contractFetcher,
thresholdTokenContractAddress,
thresholdTokenContractArtifact
} from "../../../lib/eth-fns"
import { fullURL } from "../../../lib/utils"
import type { VerificationRequestResponse } from "../../../lib/verification-request"

// All the logic of this dapp is contained in the Dapp component.
// These other components are just presentational ones: they don't have any
// logic. They just render HTML.
import DappLayout from "./Layout"
import Loading from "./Loading"
import NoTokensMessage from "./NoTokensMessage"
import TransactionErrorMessage from "./TransactionErrorMessage"
import Transfer from "./Transfer"
import WaitingForTransactionMessage from "./WaitingForTransactionMessage"

const contractAddress: string =
process.env.NEXT_PUBLIC_ETH_CONTRACT_ADDRESS ||
contractAddressJSON.ThresholdToken
import type { VerificationRequestResponse } from "../../../lib/verification-request"
import type { VerificationResultResponse } from "verite"

// This is an error code that indicates that the user canceled a transaction
const ERROR_CODE_TX_REJECTED_BY_USER = 4001
Expand All @@ -50,12 +40,16 @@ const ERROR_CODE_TX_REJECTED_BY_USER = 4001
* transaction.
*/
const Dapp: FC = () => {
const contractAddress: string =
process.env.NEXT_PUBLIC_ETH_CONTRACT_ADDRESS ??
thresholdTokenContractAddress()

const { account, library } = useWeb3React<Web3Provider>()
// Refresh the user's contract balance every 1 second
const { data: balance, mutate } = useSWR(
[contractAddress, "balanceOf", account],
{
fetcher: contractFetcher(library, TokenArtifact.abi),
fetcher: contractFetcher(library, thresholdTokenContractArtifact().abi),
refreshInterval: 1000
}
)
Expand All @@ -81,7 +75,7 @@ const Dapp: FC = () => {

const token = new Contract(
contractAddress,
TokenArtifact.abi,
thresholdTokenContractArtifact().abi,
library.getSigner(0)
)

Expand Down
1 change: 1 addition & 0 deletions packages/e2e-demo/components/demos/dapp/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Web3Provider } from "@ethersproject/providers"
import { useWeb3React } from "@web3-react/core"
import { BigNumber } from "ethers"
import { FC } from "react"

import { formatEthAddress, getEthErrorMessage } from "../../../lib/eth-fns"
import Layout from "../../shared/Layout"

Expand Down
1 change: 1 addition & 0 deletions packages/e2e-demo/components/demos/dapp/Loading.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FC } from "react"

import Spinner from "../../shared/Spinner"

const Loading: FC = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PlusIcon } from "@heroicons/react/outline"
import { FC, useState } from "react"

import { classNames } from "../../../lib/react-fns"
import { LoadingButton } from "../../shared/LoadingButton"

Expand Down
6 changes: 4 additions & 2 deletions packages/e2e-demo/components/demos/dapp/Transfer.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { PaperAirplaneIcon } from "@heroicons/react/solid"
import { FC, useState } from "react"
import type { VerificationResultResponse } from "verite"

import { classNames } from "../../../lib/react-fns"
import type { VerificationRequestResponse } from "../../../lib/verification-request"
import { LoadingButton } from "../../shared/LoadingButton"
import TransferStatus from "./TransferStatus"

import type { VerificationRequestResponse } from "../../../lib/verification-request"
import type { VerificationResultResponse } from "verite"

type TransferProps = {
transferTokens: (to: string, amount: string) => Promise<void>
tokenSymbol: string
Expand Down
Loading

0 comments on commit a9551b8

Please sign in to comment.