Skip to content

Commit

Permalink
Merge branch 'develop' into feat/handle-did-ethr-pkh
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudobun committed Jun 28, 2023
2 parents fef2599 + 3d1d456 commit 20455a2
Show file tree
Hide file tree
Showing 46 changed files with 1,494 additions and 476 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ nx-cloud.env
.yarn/install-state.gz
.pnp.*
.vscode
.vercel
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ apps
libs
packages
pnpm-lock.yaml
.vercel
3 changes: 3 additions & 0 deletions packages/dapp/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
NEXT_PUBLIC_DEMO_ISSUER=http://localhost:3003
NEXT_PUBLIC_DEMO_VERIFIER=http://localhost:3004

# Prisma
DATABASE_URL=
9 changes: 9 additions & 0 deletions packages/dapp/next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const StylelintPlugin = require('stylelint-webpack-plugin');
const path = require('path');

// Content-Security-Policy
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
Expand Down Expand Up @@ -31,6 +32,14 @@ const nextConfig = {
optimizeFonts: true,
experimental: {
appDir: true,
outputFileTracingRoot: path.join(__dirname, '../../'),
outputFileTracingExcludes: {
'*': [
'node_modules/@swc/core-linux-x64-gnu',
'node_modules/@swc/core-linux-x64-musl',
'node_modules/@esbuild/linux-x64',
],
},
},
env: {
USE_LOCAL: process.env.USE_LOCAL || 'false',
Expand Down
6 changes: 6 additions & 0 deletions packages/dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build:docker": "pnpm build",
"dev": "cross-env USE_LOCAL='true' next dev",
"docker:build": "docker build . -t blockchain-lab-um/dapp:latest",
"postinstall": "pnpm prisma generate --schema=./prisma/schema.prisma",
"lint": "pnpm lint:next && pnpm lint:tsc && pnpm lint:prettier && pnpm lint:stylelint",
"lint:fix": "next lint . --fix && prettier . --write",
"lint:next": "next lint",
Expand All @@ -26,6 +27,7 @@
"@heroicons/react": "^2.0.18",
"@metamask/detect-provider": "^2.0.0",
"@metamask/providers": "^10.2.0",
"@prisma/client": "^4.16.1",
"@radix-ui/react-toast": "^1.1.4",
"@tanstack/react-table": "^8.9.2",
"@veramo/core": "5.2.0",
Expand All @@ -34,6 +36,7 @@
"clsx": "^1.2.1",
"did-jwt-vc": "^3.2.4",
"ethers": "^6.5.1",
"html5-qrcode": "^2.3.8",
"lint-staged": "^13.2.2",
"luxon": "^3.3.0",
"next": "13.4.6",
Expand All @@ -42,9 +45,11 @@
"next-themes": "^0.2.1",
"prettier-plugin-tailwindcss": "^0.3.0",
"prop-types": "^15.8.1",
"qrcode.react": "^3.1.0",
"qs": "^6.11.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"swr": "^2.2.0",
"tailwind-scrollbar": "^3.0.4",
"zustand": "^4.3.8"
},
Expand All @@ -67,6 +72,7 @@
"postcss": "^8.4.24",
"prettier": "^2.8.4",
"prettier-plugin-packagejson": "^2.4.3",
"prisma": "^4.16.1",
"rimraf": "^5.0.1",
"sass": "^1.63.4",
"stylelint": "^15.8.0",
Expand Down
15 changes: 15 additions & 0 deletions packages/dapp/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}

model sessions {
id String @id @default(uuid())
data String? @db.VarChar(512)
iv String? @db.VarChar(128)
}
14 changes: 14 additions & 0 deletions packages/dapp/src/app/[locale]/app/(protected)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import ConnectedProvider from '@/components/ConnectedProvider';
import MetaMaskProvider from '@/components/MetaMaskProvider';

export default async function ProtectedLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<MetaMaskProvider>
<ConnectedProvider>{children}</ConnectedProvider>
</MetaMaskProvider>
);
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Metadata } from 'next';

import CreateConnectionCard from '@/components/CreateConnectionCard';
import ScanConnectionCard from '@/components/ScanConnectionCard';

export const metadata: Metadata = {
title: 'Dashboard',
description: 'Dashboard for Masca Dapp.',
};

export default function Page() {
return (
<div className="flex flex-1 flex-col space-y-4 md:flex-row md:space-x-8 md:space-y-0">
<div className="dark:bg-navy-blue-800 flex flex-1 rounded-3xl bg-white p-4 shadow-lg">
<CreateConnectionCard />
</div>
<div className="dark:bg-navy-blue-800 flex flex-1 rounded-3xl bg-white p-4 shadow-lg">
<ScanConnectionCard />
</div>
</div>
);
}
10 changes: 5 additions & 5 deletions packages/dapp/src/app/[locale]/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AppBottomBar from '@/components/AppBottomBar';
import AppNavbar from '@/components/AppNavbar';
import ConnectedProvider from '@/components/ConnectedProvider';
import MetaMaskProvider from '@/components/MetaMaskProvider';
import CheckMetaMaskCompatibility from '@/components/CheckMetaMaskCompatibility';
import QRCodeSessionProvider from '@/components/QRCodeSessionProvider';
import ToastWrapper from '@/components/ToastWrapper';

export default async function AppLayout({
Expand All @@ -14,9 +14,9 @@ export default async function AppLayout({
<AppNavbar />
<div className="flex min-h-screen pb-14 pt-24 md:pb-0">
<div className="flex flex-1 pb-4 pt-4 sm:pb-10 sm:pt-10 md:pb-16 md:pt-16 lg:pb-20 lg:pt-20">
<MetaMaskProvider>
<ConnectedProvider>{children}</ConnectedProvider>
</MetaMaskProvider>
<CheckMetaMaskCompatibility />
<QRCodeSessionProvider />
{children}
</div>
</div>
<AppBottomBar />
Expand Down
2 changes: 1 addition & 1 deletion packages/dapp/src/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const metadata: Metadata = {
verification: {
google: 'snsvYv9eAKOZ7FrIjpUSnUtqgoFiSXQWROVrStPBc8I',
},
manifest: '/manifest.json',
manifest: null,
};

export function generateStaticParams() {
Expand Down
118 changes: 118 additions & 0 deletions packages/dapp/src/app/api/qr-code-session/[id]/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { NextResponse } from 'next/server';

import { prisma } from '@/utils/prisma';

export async function GET(
_: Request,
{ params: { id } }: { params: { id: string } }
) {
if (!id) {
return NextResponse.json(
{ error_description: 'Missing sessionId parameter' },
{ status: 400 }
);
}

// Get session from database
const session = await prisma.sessions.findUnique({
where: {
id,
},
});

if (!session) {
return NextResponse.json(
{ error_description: 'Session not found' },
{ status: 404 }
);
}

await prisma.sessions.delete({
where: {
id,
},
});

// Get session data
return NextResponse.json(
{ data: session.data, iv: session.iv },
{ status: 200 }
);
}

export async function POST(
request: Request,
{ params: { id } }: { params: { id: string } }
) {
try {
const jsonData = await request.json();

const { data, iv } = jsonData;

if (!id) {
return NextResponse.json(
{ error_description: 'Missing sessionId' },
{
status: 400,
}
);
}

if (!data) {
return NextResponse.json(
{ error_description: "Missing 'data' parameter" },
{
status: 400,
}
);
}

if (!iv) {
return NextResponse.json(
{ error_description: "Missing 'iv' parameter" },
{
status: 400,
}
);
}

// Put session data in database
await prisma.sessions.upsert({
where: {
id,
},
update: {
data,
iv,
},
create: {
id,
data,
iv,
},
});

return new NextResponse(null, {
status: 200,
});
} catch (e) {
console.log(e);
return NextResponse.json(
{ error_description: 'Bad request' },
{
status: 400,
}
);
}
}

export async function OPTIONS(_: Request) {
return new NextResponse(null, {
status: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type',
},
});
}
14 changes: 10 additions & 4 deletions packages/dapp/src/components/AppBottomBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import { useState } from 'react';
import Link from 'next/link';
import { EllipsisHorizontalIcon } from '@heroicons/react/24/solid';
import clsx from 'clsx';
import { useTranslations } from 'next-intl';

const MAIN_LINKS = [
Expand All @@ -24,6 +26,10 @@ const OTHER_LINKS = [
name: 'authorization-request',
href: '/app/authorization-request',
},
{
name: 'qr-code-session',
href: '/app/qr-code-session',
},
];

const AppBottomBar = () => {
Expand Down Expand Up @@ -51,15 +57,15 @@ const AppBottomBar = () => {
</Link>
))}
</div>
{/* <button
<button
onClick={toggleMenu}
className="animated-transition dark:bg-navy-blue-700 dark:hover:bg-navy-blue-600 rounded-lg bg-pink-100 p-2 text-pink-600 hover:bg-pink-50 dark:text-white"
>
<EllipsisHorizontalIcon className="h-6 w-6" />
</button> */}
</button>
</div>
</div>
{/* <div
<div
className={clsx(
'fixed bottom-14 left-0 z-10 mb-1 w-screen rounded-lg px-1 transition-transform duration-300 md:hidden',
isMenuOpen ? 'translate-y-0' : 'translate-y-40'
Expand All @@ -77,7 +83,7 @@ const AppBottomBar = () => {
</Link>
))}
</div>
</div> */}
</div>
</>
);
};
Expand Down
8 changes: 6 additions & 2 deletions packages/dapp/src/components/AppNavbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const EXTRA_LINKS = [
name: 'authorization-request',
href: '/app/authorization-request',
},
{
name: 'qr-code-session',
href: '/app/qr-code-session',
},
];

export default function AppNavbar() {
Expand Down Expand Up @@ -62,7 +66,7 @@ export default function AppNavbar() {
{t(`menu.${name}`)}
</Link>
))}
{/* {EXTRA_LINKS.map(({ name, href }) => (
{EXTRA_LINKS.map(({ name, href }) => (
<Link
className={clsx(
'nav-btn',
Expand All @@ -76,7 +80,7 @@ export default function AppNavbar() {
>
{t(`menu.${name}`)}
</Link>
))} */}
))}
<MenuPopover />
</div>
<div className="flex-1 md:flex-none">
Expand Down
Loading

0 comments on commit 20455a2

Please sign in to comment.