Skip to content

Commit

Permalink
feat: vc campaign (#553)
Browse files Browse the repository at this point in the history
Signed-off-by: Urban Vidovič <urbanfoundit@gmail.com>
Co-authored-by: tadejpodrekar <tadej.podrekar@gmail.com>
Co-authored-by: andyv09 <andraz.vrecko@gmail.com>
Co-authored-by: martines3000 <domajnko.martin@gmail.com>
  • Loading branch information
4 people committed Mar 20, 2024
1 parent 9335784 commit 1d11e8d
Show file tree
Hide file tree
Showing 84 changed files with 2,729 additions and 757 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-bags-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blockchain-lab-um/masca": patch
---

Sets default network to mainnet.
5 changes: 5 additions & 0 deletions .changeset/late-needles-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blockchain-lab-um/extended-verification": patch
---

Adds public JSON RPC providers.
5 changes: 5 additions & 0 deletions .changeset/shiny-meals-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blockchain-lab-um/dapp": minor
---

Adds campaigns feature.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ export type Agent = TAgent<

export const createVeramoAgent = async () => {
const networks: any = [
{
name: '',
provider: new JsonRpcProvider('https://eth.llamarpc.com'),
},
{
name: 'mainnet',
provider: new JsonRpcProvider('https://eth.llamarpc.com '),
provider: new JsonRpcProvider('https://eth.llamarpc.com'),
},
{
name: 'sepolia',
Expand Down
5 changes: 5 additions & 0 deletions libs/extended-verification/src/createVeramoAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export const createVeramoAgent = async (props?: CreateVeramoAgentProps) => {
// from `ethr-did-resolver` and `ens-did-resolver` package uses Ethers v5 still with a
// different `Provider` type
const networks: any = [
{
name: '',
provider:
providers?.mainnet ?? new JsonRpcProvider('https://eth.llamarpc.com'),
},
{
name: 'mainnet',
provider:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"nx-cloud": "^18.0.0",
"rimraf": "^5.0.5",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
"typescript": "^5.4.2"
},
"packageManager": "pnpm@8.11.0",
"engines": {
Expand Down
11 changes: 7 additions & 4 deletions packages/dapp/.example
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
# OIDC Issuer and Verifier
NEXT_PUBLIC_DEMO_ISSUER=http://localhost:3003
NEXT_PUBLIC_DEMO_VERIFIER=http://localhost:3004

# Google Drive Backup
NEXT_PUBLIC_GOOGLE_CLIENT_ID=
NEXT_PUBLIC_GOOGLE_SCOPES=https://www.googleapis.com/auth/drive.appdata
GOOGLE_DRIVE_FILE_NAME=masca-backup-

# Networks endpoints

MAINNET_RPC_URL=
SEPOLIA_RPC_URL=
IPFS_GATEWAY=
POLYGON_RPC_URL=
POLYGON_MUMBAI_RPC_URL=

# Masca version
# Campaign Issuer
CAMPAIGN_ISSUER_DID=did:ens:mainnet:masca.eth
CAMPAIGN_PRIVATE_KEY=

# Masca version
NEXT_PUBLIC_MASCA_VERSION=

# SupaBase Public

NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_ANON_KEY=

# SupaBase Private

SUPABASE_SECRET_KEY=
SUPABASE_JWT_SECRET=
1 change: 1 addition & 0 deletions packages/dapp/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const nextConfig = {
},
env: {
USE_LOCAL: process.env.USE_LOCAL || 'false',
// Supabase
NEXT_PUBLIC_SUPABASE_URL:
process.env.NEXT_PUBLIC_SUPABASE_URL ||
'https://vfxyvzkprpeegheyapzg.supabase.co',
Expand Down
36 changes: 13 additions & 23 deletions packages/dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"lint": "biome check .",
"lint:fix": "biome check --apply .",
"start": "next start",
"start:local": "infisical run --env=dev --path=/packages/dapp -- next start",
"supabase:generate": "supabase gen types typescript --project-id vfxyvzkprpeegheyapzg --schema public > src/utils/supabase/database.types.ts"
"supabase:generate": "supabase gen types typescript --project-id nqgexdszsnrliuzuobul --schema public > src/utils/supabase/database.types.ts",
"start:local": "infisical run --env=dev --path=/packages/dapp -- next start"
},
"dependencies": {
"@blockchain-lab-um/did-provider-key": "1.0.8-beta.1",
Expand All @@ -28,17 +28,20 @@
"@radix-ui/react-toast": "^1.1.5",
"@react-oauth/google": "^0.12.1",
"@supabase/supabase-js": "^2.39.7",
"@tanstack/react-query": "^5.25.0",
"@tanstack/react-query": "^5.28.4",
"@tanstack/react-table": "^8.13.2",
"@types/dompurify": "^3.0.5",
"@types/js-cookie": "^3.0.6",
"@types/jsdom": "^21.1.6",
"@veramo/core": "5.6.1-next.57",
"@veramo/credential-eip712": "5.6.1-next.57",
"@veramo/credential-w3c": "5.6.1-next.57",
"@veramo/did-manager": "5.6.1-next.57",
"@veramo/did-provider-ethr": "5.6.1-next.57",
"@veramo/did-provider-pkh": "5.6.1-next.57",
"@veramo/did-resolver": "5.6.1-next.57",
"@veramo/key-manager": "5.6.1-next.57",
"@veramo/kms-local": "5.6.1-next.57",
"@veramo/utils": "5.6.1-next.57",
"@vercel/analytics": "^1.2.2",
"@vercel/og": "^0.6.2",
Expand Down Expand Up @@ -81,6 +84,7 @@
},
"devDependencies": {
"@svgr/webpack": "^8.1.0",
"@tanstack/react-query-devtools": "^5.28.4",
"@types/file-saver": "^2.0.7",
"@types/jsonwebtoken": "^9.0.6",
"@types/luxon": "^3.4.2",
Expand All @@ -94,9 +98,7 @@
},
"nx": {
"namedInputs": {
"default": [
"{projectRoot}/**/*"
],
"default": ["{projectRoot}/**/*"],
"production": [
"default",
"!{projectRoot}/sonar-project.properties",
Expand All @@ -108,25 +110,13 @@
},
"targets": {
"build": {
"inputs": [
"production",
"^production"
],
"dependsOn": [
"^build"
],
"outputs": [
"{projectRoot}/.next"
]
"inputs": ["production", "^production"],
"dependsOn": ["^build"],
"outputs": ["{projectRoot}/.next"]
},
"start": {
"inputs": [
"production",
"^production"
],
"dependsOn": [
"build"
],
"inputs": ["production", "^production"],
"dependsOn": ["build"],
"outputs": []
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,17 @@ import {
import clsx from 'clsx';
import { useTranslations } from 'next-intl';
import { useRouter } from 'next/navigation';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useCallback, useMemo, useState } from 'react';

import { DeleteSharedPresentationModal } from '@/components/DeleteSharedPresentationModal';
import { ShareCredentialModal } from '@/components/ShareCredentialModal';
import { useAuthStore } from '@/stores/authStore';
import { useShareModalStore } from '@/stores/shareModalStore';
import { createClient } from '@/utils/supabase/client';
import { useAuthStore, useShareModalStore } from '@/stores';
import { Tables } from '@/utils/supabase/helper.types';

const ITEMS_PER_PAGE = 10;

const getFromAndTo = (page: number) => {
const from = page === 0 ? 0 : (page - 1) * ITEMS_PER_PAGE;
const to = from + ITEMS_PER_PAGE - 1;

return { from, to };
};

const queryPresentations = async (token: string, page: number) => {
const supabase = createClient(token);
const { from, to } = getFromAndTo(page);

const { data, error } = await supabase
.from('presentations')
.select('*')
.range(from, to);

if (error) throw new Error('Failed to fetch presentations');

return data;
};

const totalPresentations = async (token: string) => {
const supabase = createClient(token);

const { count, error } = await supabase.from('presentations').select('id', {
count: 'exact',
});

if (error) throw new Error('Failed to fetch presentations');

return count;
};
import {
useTotalPresentations,
usePresentations,
ITEMS_PER_PAGE,
} from '@/hooks';

export const SharedPresentations = () => {
const t = useTranslations('SharedPresentations');
Expand All @@ -81,22 +49,12 @@ export const SharedPresentations = () => {
}));

// Local state
const [presentations, setPresentations] = useState<Tables<'presentations'>[]>(
[]
);
const [total, setTotal] = useState<number | null>(null);
const [loading, setLoading] = useState(false);
const [isDeleteModalOpen, setDeleteModalOpen] = useState(false);
const [selectedPresentationId, setSelectedPresentationId] = useState<
string | null
>(null);
const [page, setPage] = useState(1);

const pages = useMemo(() => {
if (!total) return 1;
return Math.ceil(total / ITEMS_PER_PAGE);
}, [total]);

const columns = [
{
key: 'title',
Expand Down Expand Up @@ -137,7 +95,7 @@ export const SharedPresentations = () => {
<button
type="button"
className={clsx(
' dark:text-navy-blue-50 group flex',
'dark:text-navy-blue-50 group flex',
'items-center justify-center rounded-full text-gray-700 outline-none focus:outline-none'
)}
onClick={() => {
Expand Down Expand Up @@ -188,31 +146,22 @@ export const SharedPresentations = () => {
[]
);

useEffect(() => {
if (!token) return;
totalPresentations(token)
.then((data) => setTotal(data))
.catch((error) => {
console.error(error);
});
}, [token]);
if (!token) return null;

useEffect(() => {
if (!token) return;
// Total presentations
const {
data: { total },
} = useTotalPresentations(token);

setLoading(true);
queryPresentations(token, page)
.then((data) => {
setPresentations(data);
setLoading(false);
})
.catch((error) => {
console.error(error);
setLoading(false);
});
}, [token, page]);
// Calculate number of pages
const pages = Math.ceil(total / ITEMS_PER_PAGE);

if (!token) return null;
// Presentations
const { data: presentationsData, status } = usePresentations(token, page);
const presentations = useMemo(
() => (presentationsData ? presentationsData.presentations : []),
[presentationsData]
);

return (
<>
Expand Down Expand Up @@ -255,7 +204,7 @@ export const SharedPresentations = () => {
</TableHeader>
<TableBody
items={presentations}
isLoading={loading}
isLoading={status === 'pending'}
loadingContent={<Spinner />}
>
{(item) => (
Expand Down Expand Up @@ -296,7 +245,7 @@ export const SharedPresentations = () => {
isModalOpen={isDeleteModalOpen}
presentationId={selectedPresentationId!}
setModalOpen={setDeleteModalOpen}
setPresentations={setPresentations}
page={page}
/>
<ShareCredentialModal />
</>
Expand Down
15 changes: 15 additions & 0 deletions packages/dapp/src/app/[locale]/app/(public)/campaigns/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { CampaignsDisplay } from '@/components/CampaignsDisplay';
import { Metadata } from 'next';

export const metadata: Metadata = {
title: 'Campaigns',
description: 'Browse campaigns, claim credentials, and earn rewards',
};

export default function Page() {
return (
<div className="flex h-full flex-1 justify-center">
<CampaignsDisplay />
</div>
);
}
Loading

0 comments on commit 1d11e8d

Please sign in to comment.