diff --git a/src/app/api/getwallets/route.ts b/src/app/api/getwallets/route.ts new file mode 100644 index 000000000..032fa5dd9 --- /dev/null +++ b/src/app/api/getwallets/route.ts @@ -0,0 +1,32 @@ +import prisma from '@/db'; +import { authOptions } from '@/lib/auth'; +import { getServerSession } from 'next-auth'; +import { NextResponse } from 'next/server'; + +export async function GET() { + const session = await getServerSession(authOptions); + + if (!session || !session.user) { + return NextResponse.json( + { + message: 'Unauthorized!', + }, + { status: 403 }, + ); + } + + const wallets = await prisma.user.findFirst({ + where: { + id: session.user.id, + }, + select: { + upis: true, + solanaAddresses: true, + }, + }); + + return NextResponse.json({ + upiWallets: wallets?.upis, + solanaWallets: wallets?.solanaAddresses, + }); +} diff --git a/src/app/payout-methods/page.tsx b/src/app/payouts/page.tsx similarity index 51% rename from src/app/payout-methods/page.tsx rename to src/app/payouts/page.tsx index 503ab35f5..0b3e6b25d 100644 --- a/src/app/payout-methods/page.tsx +++ b/src/app/payouts/page.tsx @@ -1,9 +1,11 @@ import { AddPayout } from '@/components/AddNewPayout'; +import { Wallets } from '@/components/WalletDialog'; export default async function Payout() { return ( -
+
+
); } diff --git a/src/components/AddNewPayout.tsx b/src/components/AddNewPayout.tsx index fba878484..33254f4b5 100644 --- a/src/components/AddNewPayout.tsx +++ b/src/components/AddNewPayout.tsx @@ -24,9 +24,9 @@ export const AddPayout = () => { }; return ( -
+
diff --git a/src/components/Address.tsx b/src/components/Address.tsx new file mode 100644 index 000000000..3937e61c0 --- /dev/null +++ b/src/components/Address.tsx @@ -0,0 +1,18 @@ +import { Card, CardContent } from '@/components/ui/card'; +import { Button } from '@/components/ui/button'; +import React from 'react'; + +export function WalletAddress({ children }: { children: React.ReactNode }) { + return ( + + +
+
{children}
+
+
+ +
+
+
+ ); +} diff --git a/src/components/WalletDialog.tsx b/src/components/WalletDialog.tsx new file mode 100644 index 000000000..fc2bbb31f --- /dev/null +++ b/src/components/WalletDialog.tsx @@ -0,0 +1,44 @@ +'use client'; + +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, + DialogTrigger, +} from '@/components/ui/dialog'; +import { useWallets } from '@/hooks/useWallets'; +import { WalletAddress } from './Address'; +import { Button } from './ui/button'; + +export const Wallets = () => { + const { upiWallets, solanaWallets } = useWallets(); + return ( + + + + + + +
+ UPI wallets + + {upiWallets?.map((wallet) => ( + {wallet.address} + ))} + +
+
+ Solana wallets + + {solanaWallets?.map((wallet) => ( + {wallet.address} + ))} + +
+
+
+
+ ); +}; diff --git a/src/components/profile-menu/ProfileDropdown.tsx b/src/components/profile-menu/ProfileDropdown.tsx index 9a4bebf9b..b95ca55c9 100644 --- a/src/components/profile-menu/ProfileDropdown.tsx +++ b/src/components/profile-menu/ProfileDropdown.tsx @@ -39,9 +39,9 @@ const ProfileDropdown = () => { label: 'Questions', }, { - href: 'payout-methods', + href: 'payouts', icon: , - label: 'Payout methods', + label: 'Payouts', }, ]; diff --git a/src/components/ui/dialog.tsx b/src/components/ui/dialog.tsx new file mode 100644 index 000000000..2ca04ecbf --- /dev/null +++ b/src/components/ui/dialog.tsx @@ -0,0 +1,122 @@ +'use client'; + +import * as React from 'react'; +import * as DialogPrimitive from '@radix-ui/react-dialog'; +import { X } from 'lucide-react'; + +import { cn } from '@/lib/utils'; + +const Dialog = DialogPrimitive.Root; + +const DialogTrigger = DialogPrimitive.Trigger; + +const DialogPortal = DialogPrimitive.Portal; + +const DialogClose = DialogPrimitive.Close; + +const DialogOverlay = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)); +DialogOverlay.displayName = DialogPrimitive.Overlay.displayName; + +const DialogContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, ...props }, ref) => ( + + + + {children} + + + Close + + + +)); +DialogContent.displayName = DialogPrimitive.Content.displayName; + +const DialogHeader = ({ + className, + ...props +}: React.HTMLAttributes) => ( +
+); +DialogHeader.displayName = 'DialogHeader'; + +const DialogFooter = ({ + className, + ...props +}: React.HTMLAttributes) => ( +
+); +DialogFooter.displayName = 'DialogFooter'; + +const DialogTitle = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)); +DialogTitle.displayName = DialogPrimitive.Title.displayName; + +const DialogDescription = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)); +DialogDescription.displayName = DialogPrimitive.Description.displayName; + +export { + Dialog, + DialogPortal, + DialogOverlay, + DialogClose, + DialogTrigger, + DialogContent, + DialogHeader, + DialogFooter, + DialogTitle, + DialogDescription, +}; diff --git a/src/hooks/useWallets.tsx b/src/hooks/useWallets.tsx new file mode 100644 index 000000000..b51a3e0ef --- /dev/null +++ b/src/hooks/useWallets.tsx @@ -0,0 +1,29 @@ +import axios from 'axios'; +import { useEffect, useState } from 'react'; + +type Wallets = { + id: number; + parentId: string; + address: string; + addedAt: Date; +}; +export const useWallets = () => { + const [upiWallets, setUpiWallets] = useState(); + const [solanaWallets, setSolanaWallets] = useState(); + + useEffect(() => { + const fetchData = () => { + axios.get('api/getwallets').then((res) => { + setUpiWallets(res.data.upiWallets); + setSolanaWallets(res.data.solanaWallets); + }); + }; + + fetchData(); + }, []); + + return { + upiWallets, + solanaWallets, + }; +};