Skip to content
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
54 changes: 54 additions & 0 deletions actions/account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use server';

import { id } from '@instantdb/core';
import { sha256 } from '@noble/hashes/sha2.js';

import { db } from '@/config/database';

export async function addAccount(props: { name: string; email: string; pubkey: string }): Promise<string> {
const { name = null, email = null, pubkey = null } = props;

if (!email && !pubkey) {
// return {}
}

// TO-DO
// Format pubkey

// Find if customer exist
const query = {
customer: {
$: {
where: {
email: email || '',
pubkey: pubkey || '',
},
},
},
};

const { customer } = await db.query(query);

if (customer && customer.length > 0) {
// @ts-ignore
return customer[0]?.id;
}

// If not exist, create
const newId = id();

await db.transact(
// @ts-ignore
db.tx.customer[newId].update({
// Data
name,
email,
pubkey,

// Status
created_at: Date.now(),
}),
);

return newId;
}
53 changes: 53 additions & 0 deletions actions/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use server';

import { id } from '@instantdb/core';
import { sha256 } from '@noble/hashes/sha2.js';

import { db } from '@/config/database';

export async function addAccount(props: { id: string }): Promise<string> {
const { id } = props;

if (!id) {
// return {}
}

// TO-DO
// Format pubkey

// Find if customer exist
const query = {
store: {
$: {
where: {
id: id || '',
},
},
},
};

const { store } = await db.query(query);

if (store && store.length > 0) {
// @ts-ignore
return store[0]?.id;
}

// If not exist, create
const newId = id();

// await db.transact(
// // @ts-ignore
// db.tx.customer[newId].update({
// // Data
// name,
// email,
// pubkey,

// // Status
// created_at: Date.now(),
// }),
// );

return newId;
}
2 changes: 1 addition & 1 deletion app/paydesk/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function PaydeskPage() {
</header>

<div className='flex-1 flex flex-col'>
<div className='flex-1 flex flex-col justify-center items-center gap-2 bg-white border-b rounded-b-2xl'>
<div className='flex-1 flex flex-col justify-center items-center gap-2 bg-white border-b'>
<div className='text-3xl'>
{getCurrencySymbol()}
<b>{new Intl.NumberFormat().format(numpadData.intAmount[numpadData.usedCurrency])}</b> {settings.currency}
Expand Down
9 changes: 9 additions & 0 deletions app/settings/pin/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { Metadata } from 'next';

export const metadata: Metadata = {
title: 'PIN Settings',
};

export default function RootLayout({ children }: { children: React.ReactNode }) {
return <>{children}</>;
}
73 changes: 73 additions & 0 deletions app/settings/pin/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use client';

import Link from 'next/link';
import { useRouter } from 'next/navigation';
import { ChevronLeft, Settings } from 'lucide-react';

import { useNumpad } from '@/hooks/use-numpad';
import { useSettings } from '@/hooks/use-settings';
import { useCurrencyConverter } from '@/hooks/use-currency-converter';

import { Button } from '@/components/ui/button';
import { Keyboard } from '@/components/keyboard';
import { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot } from '@/components/ui/input-otp';
import { AvailableCurrencies } from '@/types/config';

export default function Page() {
const router = useRouter();

const { settings } = useSettings();
const numpadData = useNumpad('SAT');

const countLength = String(numpadData.intAmount['SAT']).length;
console.log('countLength', countLength);

return (
<div className='flex-1 flex flex-col w-full mx-auto h-full bg-[#0F0F0F]'>
<header className='py-4 flex bg-background border-b shadow-sm'>
<div className='flex items-center justify-between w-full max-w-md mx-auto px-4'>
<div className='flex items-center'>
<Button className='mr-2' variant='outline' size='icon' asChild>
<Link href='/app'>
<ChevronLeft className='h-4 w-4' />
<span className='sr-only'>Back</span>
</Link>
</Button>
<h1 className='text-xl font-medium'>{'Create PIN'}</h1>
</div>
{/* <Button size='icon' variant='outline' asChild>
<Link href='/settings'>
<Settings className='h-4 w-4' />
</Link>
</Button> */}
</div>
</header>

<div className='flex-1 flex flex-col'>
<div className='flex-1 flex flex-col justify-center items-center gap-2 bg-white border-b rounded-b-2xl'>
<div className='text-3xl'>
<InputOTP value={String(numpadData.intAmount['SAT'])} maxLength={6}>
<InputOTPGroup>
<InputOTPSlot index={0} />
<InputOTPSlot index={1} />
<InputOTPSlot index={2} />
</InputOTPGroup>
<InputOTPSeparator />
<InputOTPGroup>
<InputOTPSlot index={3} />
<InputOTPSlot index={4} />
<InputOTPSlot index={5} />
</InputOTPGroup>
</InputOTP>
</div>
</div>
<div className='flex flex-col gap-4 w-full max-w-md mx-auto px-4 py-8'>
<Button className='w-full' size='lg' variant='success' onClick={() => {}} disabled={countLength < 6}>
Confirm
</Button>
<Keyboard numpadData={numpadData} disabledDoubleZero={true} disabledNumbers={countLength > 5} />
</div>
</div>
</div>
);
}
34 changes: 20 additions & 14 deletions components/app-dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useEffect } from 'react';
import Link from 'next/link';
import { useRouter } from 'next/navigation';
import { Calculator, Store, Settings, X, User } from 'lucide-react';
import { sha256 } from '@noble/hashes/sha2.js';

import { useAuth } from '@/context/auth';

Expand All @@ -13,6 +14,8 @@ import { JoinCloud } from '@/components/join-cloud';
import { LoadingSpinner } from '@/components/ui/loading-spinner';
import { getLocal } from '@/lib/localStorage';

import { db } from '@/lib/database';

const dashboardCards = [
{
title: 'Shop',
Expand All @@ -34,17 +37,20 @@ const dashboardCards = [

export function AppDashboard() {
const router = useRouter();
const { logout, lightningAddress, isAuthenticated, isLoading, authMethod } = useAuth();

const waitlistEmail = getLocal('waitlist-email');
const user = db.useAuth();
console.log('user', user);
// const { logout, lightningAddress, isAuthenticated, isLoading, authMethod } = useAuth();

// const waitlistEmail = getLocal('waitlist-email');

useEffect(() => {
if (!isAuthenticated && !isLoading) {
router.push('/login');
}
}, [isAuthenticated, isLoading]);
// useEffect(() => {
// if (!isAuthenticated && !isLoading) {
// router.push('/login');
// }
// }, [isAuthenticated, isLoading]);

if (isLoading) {
if (user?.isLoading) {
return (
<div className='flex justify-center items-center w-screen h-screen text-white'>
<LoadingSpinner />
Expand All @@ -57,14 +63,14 @@ export function AppDashboard() {
{/* Header */}
<header className='w-full py-4 bg-[#0F0F0F] border-b shadow-sm'>
<div className='flex items-center justify-between w-full max-w-md mx-auto px-4'>
<Button variant='default' onClick={logout} className='mr-2'>
<Button variant='default' className='mr-2'>
<div className='flex gap-2 items-center justify-center min-w-0'>
<User className='h-4 w-4 flex-shrink-0' />
{authMethod === 'lnaddress' ? (
{/* {authMethod === 'lnaddress' ? (
<span className='truncate text-sm'>{lightningAddress}</span>
) : (
<span className='text-sm'>NWC Mode</span>
)}
)} */}
<X className='h-4 w-4 text-destructive flex-shrink-0' />
<span className='sr-only'>Log out</span>
</div>
Expand All @@ -78,20 +84,20 @@ export function AppDashboard() {
</header>

<div className='flex flex-col gap-4 w-full max-w-md mx-auto p-4'>
{!waitlistEmail && <JoinCloud />}
{/* {!waitlistEmail && <JoinCloud />} */}

{/* Main Content */}
<div className='flex-1 flex flex-col gap-4'>
<div className='flex flex-col gap-1'>
<h2 className='text-lg font-medium text-gray-900'>Control Panel</h2>
{!isAuthenticated && (
{/* {!isAuthenticated && (
<p className='text-sm text-gray-500'>
Running in guest mode.{' '}
<Link href='/' className='text-blue-600 hover:underline'>
Setup now
</Link>
</p>
)}
)} */}
</div>

<div className='flex flex-col gap-2'>
Expand Down
2 changes: 1 addition & 1 deletion components/app/app-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const AppContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<
ref={ref}
style={heightStyle}
className={cn(
'overflow-x-hidden overflow-y-scroll relative flex flex-col items-center w-full py-4 bg-background rounded-b-2xl',
'overflow-x-hidden overflow-y-scroll relative flex flex-col items-center w-full py-4 bg-background',
className,
isMobile ? 'mx-auto' : 'flex-grow flex-shrink-0',
)}
Expand Down
Loading