Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub attestation #13

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/components/AddAttestation.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useContext, useState } from 'react';
import { createAttestation } from './request';
import { Dispatch, SetStateAction, useContext, useState } from 'react';
import { createAttestation, createTestAttestation } from './request';
import Loading from './Loading';
import StarterKitContext from '../context/starterKit';
import GithubLoginButton from '../modules/Eas/Github/componens/LoginButton';
import { useSession } from 'next-auth/react';
import WakatimeButton from '../modules/Eas/Wakatime/WakatimeButton';
import WorldCoin from '../pages/worldcoin';
import { useSession } from 'next-auth/react';

function AddAttestation(props: any) {
const { user } = useContext(StarterKitContext);
Expand Down Expand Up @@ -48,6 +49,7 @@ function AddAttestation(props: any) {
<>
{loading && <Loading />}
<p className={messageClass}>{message}</p>
{props.type === 'wakatime' && <WakatimeButton />}
{props.type === 'github' && <GithubLoginButton />}
{props.type === 'worldcoin' && <WorldCoin />}
{props.type === 'github' && data && (
Expand Down Expand Up @@ -78,6 +80,20 @@ function AddAttestation(props: any) {
</div>
</>
)}
{props.type === 'wakatime' && data && (
<>
<hr />
<div className='flex align-middle justify-center align-middle'>
<button
onClick={() => handleAttestationCreation}
className='mt-3 block text-blue-600 bg-red-50 hover:bg-redpraha hover:text-white rounded-xl px-5 py-2.5 text-center'
type='button'
data-modal-toggle='defaultModal'>
Create Attestation
</button>
</div>
</>
)}
</>
);
}
Expand Down
22 changes: 21 additions & 1 deletion src/components/Form/ProfileForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { useChainId } from '../../hooks/useChainId';
import { useConfig } from '../../hooks/useConfig';
import { QuestionMarkCircle } from 'heroicons-react';
import AddAttestation from '../AddAttestation';
import { useSession } from 'next-auth/react';
import { createAttestation, createTestAttestation } from '../request';

interface IFormValues {
title?: string;
Expand All @@ -42,10 +44,28 @@ function ProfileForm({ callback }: { callback?: () => void }) {
const { data: signer } = useSigner({
chainId,
});
const { data } = useSession();

const [wakatimeHandle, setWakatimeHandle] = useState<string | null>(null);
const { isActiveDelegate } = useContext(StarterKitContext);
const [activeLvlUpMenu, setActiveLvlUpMenu] = useState(0);
const menuItems = [
{ label: 'Github', content: <AddAttestation type='github' /> },
{
label: 'Github',
content: <AddAttestation props={{ sharedState: setWakatimeHandle, type: 'github' }} />,
},
{
label: 'WakaTime',
content: <AddAttestation props={{ sharedState: setWakatimeHandle, type: 'wakatime' }} />,
},
{
label: 'Upwork',
content: <AddAttestation props={{ sharedState: setWakatimeHandle, type: 'upwork' }} />,
},
{
label: 'Malt',
content: <AddAttestation props={{ sharedState: setWakatimeHandle, type: 'malt' }} />,
},
{ label: 'WorldCoin', content: <AddAttestation type='worldcoin' /> },
{ label: 'LinkedIn', content: <AddAttestation type='linkedIn' /> },
{ label: 'Upwork', content: <AddAttestation type='upwork' /> },
Expand Down
21 changes: 21 additions & 0 deletions src/modules/Eas/Wakatime/WakatimeButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useSession, signIn, signOut } from 'next-auth/react';
import { useState } from 'react';
import Toggle from '../../../components/Toggle';

export default function WakatimeButton() {
const { data: session } = useSession();
// TODO: load initial state from chain
const [wakatimeHandle, setWakatimeHandle] = useState(null);

return (
<>
<h2>Tell us your wakatime handle!</h2>
<input
type='text'
onChange={e => {
setWakatimeHandle(e.target.value);
}}
/>
</>
);
}
2 changes: 1 addition & 1 deletion src/pages/api/eas/create-attestation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
console.log('accessToken', accessToken);
console.log('userId', userId);

const langStats = getGithubLangStats(userId, accessToken);
const langStats = await getGithubLangStats(userId, accessToken);

const githubdata = {
languageStats: langStats,
Expand Down
3 changes: 1 addition & 2 deletions src/pages/api/eas/create-test-attestation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const attestation = await getAttestation(uid);
console.log('attestation', attestation);

res.status(200).json({ recipient: recipient });
res.status(200).json({ uid: uid });
res.status(200).json({ recipient: recipient, uid: uid });
} catch (error) {
console.error('errorDebug', error);
res.status(500).json('certificate creation failed');
Expand Down