Skip to content

Commit

Permalink
Merge pull request #37 from cardano2vn/develop
Browse files Browse the repository at this point in the history
Merge pull request #36 from cardano2vn/add-authencation
  • Loading branch information
independenceee authored Oct 11, 2024
2 parents 79324ce + b4a1624 commit 0eb6000
Show file tree
Hide file tree
Showing 29 changed files with 156 additions and 36 deletions.
5 changes: 5 additions & 0 deletions src/app/dashboard/(utilities)/collection/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import CollectionPage from '@/components/app/utilities/collection';

export default function page() {
return <CollectionPage />;
}
5 changes: 5 additions & 0 deletions src/app/dashboard/(utilities)/collection/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import CollectionPage from '@/components/app/utilities/collection';

export default function page() {
return <CollectionPage />;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MetadataPage from '@/components/app/utilities/metdata';
import MetadataPage from '@/components/app/utilities/metadata';

export default function Page() {
return <MetadataPage />;
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions src/app/dashboard/utilities/collection/page.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions src/app/dashboard/utilities/storage/create/page.tsx

This file was deleted.

41 changes: 41 additions & 0 deletions src/components/app/utilities/collection/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Button } from '@/components/ui/button';
import { SearchBar } from '../components/search-bar';
import ListFolderCard from '../components/list-folder';
import { CreateCollection } from '../components/create-collection-button';
export default function CollectionPage() {
return (
<div className="mt-5 rounded-lg bg-section p-2">
<h1 className="text-2xl font-semibold leading-7">Collection</h1>
<div className="mt-5">
<div className="flex flex-wrap items-center justify-between gap-2 rounded-lg p-2">
<div />
<div className="flex items-center space-x-2">
<div className="inline-flex rounded-md shadow-sm" role="group">
<Button variant="secondary" className="rounded-r-none">
Select All
</Button>
<Button
variant="secondary"
className="rounded-none border-x border-gray-600"
>
Format
</Button>
<Button
variant="secondary"
className="rounded-none border-r border-gray-600"
>
Download
</Button>
<Button variant="secondary" className="rounded-l-none">
Delete
</Button>
</div>
<CreateCollection />
</div>
</div>
<SearchBar />
<ListFolderCard />
</div>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Button } from '@/components/ui/button';
import { Dialog, DialogContent, DialogTrigger } from '@/components/ui/dialog';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';

export function CreateCollection() {
return (
<Dialog>
<DialogTrigger asChild>
<Button className="bg-orange-500 text-white hover:bg-orange-600">Create New</Button>
</DialogTrigger>
<DialogContent className="bg-card">
<div className="w-full max-w-md rounded-l p-6">
<form className="space-y-6">
<div className="space-y-2">
<Label htmlFor="name">Title</Label>
<Input id="name" required />
</div>
<div className="space-y-2">
<Label htmlFor="description">Description</Label>
<Textarea id="description" />
</div>
<div className="space-y-2">
<Label htmlFor="link">Link</Label>
<Input id="link" />
</div>
<Button type="submit" className="w-full">
Submit
</Button>
</form>
</div>
</DialogContent>
</Dialog>
);
}
17 changes: 17 additions & 0 deletions src/components/app/utilities/components/folder-card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { FolderIcon } from 'lucide-react';
import { Checkbox } from '@/components/ui/checkbox';
import { Card } from '@/components/ui/card';

export default function FolderCard() {
return (
<Card className="rounded-lg p-2">
<div className="flex items-center justify-between p-2">
<div className="flex items-center space-x-3">
<FolderIcon className="h-5 w-5 text-yellow-400" />
<span className="text-sm font-medium text-white">collection name</span>
</div>
<Checkbox className="h-4 w-4 rounded-full" />
</div>
</Card>
);
}
22 changes: 22 additions & 0 deletions src/components/app/utilities/components/list-folder.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import FolderCard from './folder-card';

export default function ListFolderCard() {
const file = {
name: 'VSDHBJCKJC.PNG',
size: '2.34 MB',
cid: 'QMBSCM6E6CR..VDDVMECRQT',
date: '10/30/2023',
};

return (
<div className="h-[60vh] w-full space-y-4 rounded-lg p-4">
<div className="overflow-x-auto">
<div className="md:grid-col-2 grid grid-cols-1 gap-4 lg:grid-cols-3 xl:grid-cols-4">
{Array.from({ length: 12 }, () => file).map((file, index) => (
<FolderCard key={index} />
))}
</div>
</div>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Icons } from '@/components/common/icons';
import { Button } from '@/components/ui/button';
import { Tabs, TabsContent, TabsTrigger } from '@/components/ui/tabs';
import { TabsList } from '@radix-ui/react-tabs';
import { SearchBar } from './components/search-bar';
import TableData from './components/table';
import ListFileCard from './components/list-file';
import { SearchBar } from '../components/search-bar';
import TableData from '../components/file-table';
import ListFileCard from '../components/list-file';
export default function MetadataPage() {
return (
<div className="mt-5 rounded-lg bg-section p-2">
Expand Down
4 changes: 2 additions & 2 deletions src/components/app/utilities/root/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function UtilitiesPage() {
<h1 className="text-2xl font-semibold leading-7">Utilities</h1>
<div className="mt-2 grid grid-cols-1 gap-4 p-4 md:grid-cols-3">
<Link
href="/dashboard/utilities/metadata"
href="/dashboard/collection"
className="rounded-lg shadow-none transition-shadow duration-300 hover:shadow-lg hover:shadow-teal-400"
>
<Card>
Expand All @@ -17,7 +17,7 @@ export default function UtilitiesPage() {
</AspectRatio>
<div className="flex flex-col items-center justify-start gap-3 self-stretch px-4 py-2">
<div className="font-semibol self-stretch text-center text-base">
Metadata Builder
Collection Metadata
</div>
<div className="font- self-stretch text-center text-sm text-secondary">
Have images but need JSON? We got you covered!
Expand Down
18 changes: 9 additions & 9 deletions src/hooks/use-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const useWallet = create<useWalletStore>((set, get) => ({

connect: async ({ name, image }: WalletType) => {
const browserWallet: BrowserWallet = await BrowserWallet.enable(name.toLowerCase());
const address = (await browserWallet.getRewardAddresses())[0];
const address = (await browserWallet.getUsedAddresses())[0];
const balance = await browserWallet.getLovelace();

set({
Expand All @@ -41,13 +41,13 @@ export const useWallet = create<useWalletStore>((set, get) => ({
if (!browserWallet) {
throw new Error('Failed to connect wallet');
}
const stakeAddress = (await browserWallet.getRewardAddresses())[0];
if (stakeAddress.length === 0) {
throw new Error('Cant get stake address');
const address = (await browserWallet.getUsedAddresses())[0];
if (address.length === 0) {
throw new Error('Cant get address');
}

if (isNil(session)) {
const nonce = await getNonceByAddress(stakeAddress);
const nonce = await getNonceByAddress(address);
if (isNil(nonce) || nonce === '') {
throw new Error('Cant get nonce');
}
Expand All @@ -58,14 +58,14 @@ export const useWallet = create<useWalletStore>((set, get) => ({
await signIn('credentials', {
data: JSON.stringify({
wallet: name,
stakeAddress: stakeAddress,
address: address,
signature,
}),
});
} else if (session.user?.stakeAddress !== stakeAddress) {
} else if (session.user?.address !== address) {
await signOut();
} else {
const address = (await browserWallet.getRewardAddresses())[0];
const address = (await browserWallet.getUsedAddresses())[0];
const balance = await browserWallet.getLovelace();
set({
browserWallet: browserWallet,
Expand All @@ -83,7 +83,7 @@ export const useWallet = create<useWalletStore>((set, get) => ({
const { browserWallet, wallet } = get();

const balance = await browserWallet.getLovelace();
const address = (await browserWallet.getRewardAddresses())[0];
const address = (await browserWallet.getUsedAddresses())[0];

set({
wallet: {
Expand Down
16 changes: 8 additions & 8 deletions src/lib/auth/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ const authConfig = {
async authorize(credentials) {
const {
wallet,
stakeAddress,
address,
signature,
}: {
wallet: string;
stakeAddress: string;
address: string;
signature: DataSignature;
} = JSON.parse(credentials.data as string);
if (isNil(wallet) || isNil(stakeAddress) || isNil(signature)) {
if (isNil(wallet) || isNil(address) || isNil(signature)) {
throw new Error('Invalid credentials');
}
const walletNonce = await prisma.walletNonce.findFirst({
where: {
stakeAddress: stakeAddress,
address,
},
});
if (isNil(walletNonce) || isNil(walletNonce.nonce)) {
Expand All @@ -40,16 +40,16 @@ const authConfig = {
}
const user = await prisma.user.upsert({
where: {
stakeAddress: stakeAddress,
address,
},
create: {
stakeAddress: stakeAddress,
address,
},
update: {},
});
return {
id: user.id,
stakeAddress: user.stakeAddress,
address: user.address,
wallet: wallet,
};
},
Expand All @@ -59,7 +59,7 @@ const authConfig = {
async signIn({ user }: any) {
await prisma.walletNonce.update({
where: {
stakeAddress: user.stakeAddress,
address: user.address,
},
data: {
nonce: generateNonce('signin to cip68 nft '),
Expand Down
12 changes: 6 additions & 6 deletions src/services/auth/get-nonce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import prisma from '@/lib/prisma';
import { generateNonce } from '@meshsdk/core';
import { isNil } from 'lodash';

export const getNonceByAddress = async (stakeAddress: string) => {
if (isNil(stakeAddress)) {
export const getNonceByAddress = async (address: string) => {
if (isNil(address)) {
throw new Error('Stake address is required');
}

if (!/^[a-z0-9_]+$/.test(stakeAddress)) {
throw new Error('Invalid stake address');
if (!/^[a-z0-9_]+$/.test(address)) {
throw new Error('Invalid address');
}

const nonce = generateNonce('signin to cip68 nft');
const walletNonce = await prisma.walletNonce.upsert({
where: {
stakeAddress: stakeAddress,
address: address,
},
create: {
stakeAddress: stakeAddress,
address: address,
nonce: nonce,
},
update: {
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { StaticImageData } from 'next/image';
export type CardanoNetwork = 'mainnet' | 'testnet' | 'preprod';
declare module 'next-auth' {
interface User {
stakeAddress?: string;
address?: string;
wallet?: string;
}
}
Expand Down

0 comments on commit 0eb6000

Please sign in to comment.