diff --git a/.env.local.sample b/.env.local.sample index bb1a700..149f0ea 100644 --- a/.env.local.sample +++ b/.env.local.sample @@ -1,3 +1,3 @@ GITHUB_CALLBACK_BASE_URL=http://localhost:3000 -GITHUB_CLIENT_ID= +GITHUB_CLIENT_ID=a01fc1f8afba1c7b4be9 GITHUB_CLIENT_SECRET= diff --git a/src/components/PassportStatus.tsx b/src/components/PassportStatus.tsx new file mode 100644 index 0000000..618dbb5 --- /dev/null +++ b/src/components/PassportStatus.tsx @@ -0,0 +1,51 @@ +import { useContractRead } from "wagmi" +import LoadingIndicator from "./LoadingIndicator" +import VotingEscrow from "../../abis/VotingEscrow.json" +import { useIsMounted } from "@/hooks/useIsMounted" +import Link from "next/link" +import { formatEther } from "viem" + +export default function PassportStatus({ citizen }: any) { + console.info('PassportStatus') + + const { data, isError, isLoading } = useContractRead({ + address: '0xf7def1d2fbda6b74bee7452fdf7894da9201065d', + abi: VotingEscrow.abi, + functionName: 'balanceOf', + args: [ citizen.ownerAddress ] + }) + console.info('data:', data) + console.info('isError:', isError) + console.info('isLoading:', isLoading) + + if (!useIsMounted() || isLoading) { + return + } else { + let veNationBalance: any = null + if (data) { + veNationBalance = data + } + console.info('veNationBalance:', veNationBalance) + const veNationBalanceNumber: number = Number(formatEther(veNationBalance)) + console.info('veNationBalanceNumber:', veNationBalanceNumber) + if (veNationBalanceNumber < 1.5) { + return ( + <> + Passport status: + + EXPIRED ⌛ + + + ) + } else { + return ( + <> + Passport status: + + ACTIVE 🥳 + + + ) + } + } +} diff --git a/src/components/ProfileDetailsGitHub.tsx b/src/components/ProfileDetailsGitHub.tsx index f2477eb..02e91f0 100644 --- a/src/components/ProfileDetailsGitHub.tsx +++ b/src/components/ProfileDetailsGitHub.tsx @@ -29,8 +29,7 @@ export default function ProfileDetailsGitHub({ citizen }: any) { return ( <> Not linked - - {/* */} + Link my GitHub account 🔗 diff --git a/src/pages/[passportId].tsx b/src/pages/[passportId].tsx index 5604ea3..54ec159 100644 --- a/src/pages/[passportId].tsx +++ b/src/pages/[passportId].tsx @@ -15,6 +15,7 @@ import VeNationLockDetails from '@/components/VeNationLockDetails' import ProfileDetailsGitHub from '@/components/ProfileDetailsGitHub' import Link from 'next/link' import Head from 'next/head' +import PassportStatus from '@/components/PassportStatus' const Chart = dynamic(() => import('react-apexcharts'), { ssr: false }) export default function ProfilePage({ citizen, nationCred, veNation, dework, sourceCred }: any) { @@ -115,6 +116,27 @@ export default function ProfilePage({ citizen, nationCred, veNation, dework, sou +
+

🗳️ Voting Escrow

+
+ {router.isFallback ? ( + + ) : ( + <> +
+ + + )} +
+
+ {router.isFallback ? ( + + ) : ( + + )} +
+
+

🎗️ NationCred

@@ -169,24 +191,6 @@ export default function ProfilePage({ citizen, nationCred, veNation, dework, sou )}
- -
-

🗳️ Voting Escrow

-
- {router.isFallback ? ( - - ) : ( - - )} -
-
- {router.isFallback ? ( - - ) : ( - - )} -
-
diff --git a/src/pages/api/[passportId]/auth/github-callback.ts b/src/pages/api/[passportId]/auth/github-callback.ts new file mode 100644 index 0000000..d39f6ff --- /dev/null +++ b/src/pages/api/[passportId]/auth/github-callback.ts @@ -0,0 +1,27 @@ +import nc from "next-connect" +const passport = require('passport') + +const failurePath = `/233/auth/github` // TODO: get [passportId] +console.info('failurePath:', failurePath) + +// Handle GitHub response +const handler = nc() + .get( + passport.authenticate('github', { + session: false, + failureRedirect: failurePath + }), + (req: any, res: any) => { + // Successful authentication + console.info('Successful authentication') + + // Get GitHub username + const username: string = req.user.username + console.info('username', username) + + // Redirect to /[passportId]/auth/github-success + res.redirect(`/233/auth/github-success?username=${username}`) + } + ) + +export default handler diff --git a/src/pages/api/[passportId]/auth/github.ts b/src/pages/api/[passportId]/auth/github.ts index be9e6aa..478467e 100644 --- a/src/pages/api/[passportId]/auth/github.ts +++ b/src/pages/api/[passportId]/auth/github.ts @@ -1,7 +1,12 @@ import nc from "next-connect" +import { useRouter } from "next/router" const passport = require('passport') const GitHubStrategy = require('passport-github2').Strategy +// const router = useRouter() +// const passportId = router.query.passportId +// console.info('passportId:', passportId) + // Configure strategy const callbackBaseUrl = process.env['GITHUB_CALLBACK_BASE_URL'] console.info('callbackBaseUrl:', callbackBaseUrl) @@ -16,9 +21,7 @@ passport.use(new GitHubStrategy( function(accessToken: any, refreshToken: any, profile: any, done: any) { console.info('accessToken:', accessToken) console.info('refreshToken:', refreshToken) - console.info('profile:', profile) console.info('profile.username:', profile.username) - console.info('done:', done) return done(null, profile) } )) @@ -26,9 +29,7 @@ passport.use(new GitHubStrategy( // Redirect to GitHub authentication const handler = nc() .get( - passport.authenticate('github', { - scope: ['user:email'] - }) + passport.authenticate('github', {}) ) export default handler