Skip to content

Commit

Permalink
cleaned up search and send pages, added keypad component
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen-Gordon committed Mar 13, 2024
1 parent 379f003 commit cf3f0ca
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 128 deletions.
35 changes: 15 additions & 20 deletions src/app/@auth/(.)payee/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@
// Next
import { useRouter, useSearchParams } from 'next/navigation';
// drawer
import { DrawerFooter, DrawerHeader, DrawerTitle } from '@/app/components/ui/drawer';
import {
DrawerFooter,
DrawerHeader,
DrawerTitle,
} from '@/app/components/ui/drawer';
//avatar
import { Avatar } from '@/app/components/ui/avatar';
// truc address
import truncateEthAddress from 'truncate-eth-address';
// backbutton
import BackButton from '@/app/components/Navigation/BackButton/BackButton';
// react
import { useEffect, useRef, useState } from "react";
import { useEffect, useRef, useState } from 'react';
// hooks
import useGetRecentTransactions from '@/app/hooks/useGetRecentTransactions';
import useGetAddress from '@/app/hooks/useGetAddress';

// motion
import {motion} from 'framer-motion';
import { motion } from 'framer-motion';
// redux
import { useDispatch } from 'react-redux';
import { setSheet } from '@/GlobalRedux/Features/sheet/sheetSlice';
Expand All @@ -30,37 +34,34 @@ import Link from 'next/link';

// date
//import { format, parseISO } from 'date-fns';
import { format, parseISO, set } from 'date-fns';
import { format, parseISO, set } from 'date-fns';
interface Transaction {
to: string;
from: string;
value: string;
metadata: {
blockTimestamp: string;
};

}


export default function Page() {
const searchParams = useSearchParams();
let payeeAddress = searchParams.get('payeeAddress');

// hooks
const dispatch = useDispatch();
const address = useGetAddress();
const router = useRouter();

// state
const [ transactions, setTransactions ] = useState<Transaction[]>([]);
const [transactions, setTransactions] = useState<Transaction[]>([]);
const [groupedTransactions, setGroupedTransactions] = useState<any[]>([]);

const end = useRef<any>(null);


// effect
useEffect(() => {
end.current.scrollIntoView({})
end.current.scrollIntoView({});
const fetchRecentTransactions = async () => {
const recentTransactions = await useGetRecentTransactions(address);

Expand Down Expand Up @@ -100,18 +101,12 @@ export default function Page() {
);
setGroupedTransactions(arrayOfMonthArrays);
console.log('groupedTransactionsByMonth', arrayOfMonthArrays);

}


};

fetchRecentTransactions();
}, [payeeAddress]);




return (
<>
<DrawerHeader>
Expand All @@ -135,7 +130,10 @@ export default function Page() {
<div className='overflow-auto p-4'>
{groupedTransactions.map((month, i) => (
<div key={i} className='grid'>
<div style={{marginBottom: '32px'}} className='w-full flex justify-center'>
<div
style={{ marginBottom: '32px' }}
className='flex w-full justify-center'
>
<p className='bg-card text-card-foreground h-9 w-fit rounded-xl border px-4 py-2 text-sm shadow'>
{month.monthName}
</p>
Expand Down Expand Up @@ -177,9 +175,6 @@ export default function Page() {
<DrawerFooter>
<div>
<Link
onClick={() => {
dispatch(setSheet(true));
}}
href={{
pathname: '/send',
query: { payee: payeeAddress },
Expand Down
81 changes: 54 additions & 27 deletions src/app/@auth/(.)search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import { DrawerHeader, DrawerTitle } from '@/app/components/ui/drawer';
import { isAddress } from 'viem';

// icons
import { QrCode } from 'lucide-react';
import { X } from 'lucide-react';
import { QrCode, X, Send } from 'lucide-react';

import RecentPayee from '@/app/components/RecentPayee.tsx/RecentPayee';
// motion
Expand Down Expand Up @@ -76,27 +75,29 @@ export default function Page() {

<div className='flex px-4'>
<form className='w-full'>
<div className='relative flex w-full content-center'>
<div className='relative grid w-full content-center'>
<Input
onChange={(e) => setPayee(e.target.value)}
value={payee}
id='search-input'
id='search-input relative'
className='h-9 w-full'
placeholder='Search an Address'
type='text'
/>
<div className='pointer-events-none absolute right-0 top-0 flex w-full items-center justify-end '>
<div className=' absolute right-0 z-50 flex w-auto justify-end '>
<AnimatePresence>
{payee !== '' && (
<motion.div
key='clear'
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
onClick={() => setPayee('')}
className=''
className='pr-4 '
>
<X className='h-8' />
<X
className='pointer-events-auto grid h-8 w-8 content-center items-center'
onClick={() => setPayee('')}
/>
</motion.div>
)}
</AnimatePresence>
Expand All @@ -108,28 +109,54 @@ export default function Page() {
<div className='mt-4 space-y-8 px-4'>
{isTrue ? (
<>
{/* <div className='w-full p-4'>
<Link
href={{
pathname: '/send',
query: { payee: payee },
}}
<AnimatePresence>
<motion.div
key='send-button'
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
className='w-full'
>
<button className='bg-purple w-full rounded p-4'>Go</button>
</Link>
</div> */}
<Link
href={{
pathname: '/send',
query: { payee: payee },
}}
>
<Button className='text-xl' size={'lg'} variant={'default'}>
<div className='flex grid-cols-3 content-center items-center'>
<div className='text-xl'>
<div>Send</div>
</div>
<div className='px-2'></div>
<div>
<Send size={20} />
</div>
</div>
</Button>
</Link>
</motion.div>
</AnimatePresence>
</>
) : (
<>
<AnimatePresence>
{payee != '' && (
<div
key='valid-address'
className='text-muted-foreground text-sm'
>
Please enter a valid address
</div>
)}
<motion.div
key='vaild-address'
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
className='w-full'
>
{payee != '' && (
<div
key='valid-address'
className='text-muted-foreground text-sm'
>
Please enter a valid address
</div>
)}
</motion.div>
</AnimatePresence>
</>
)}
Expand All @@ -145,7 +172,7 @@ export default function Page() {
exit={{ opacity: 0 }}
className='w-full'
>
<div className='w-full p-4'>
{/* <div className='w-full p-4'>
<Link
href={{
pathname: '/send',
Expand All @@ -154,7 +181,7 @@ export default function Page() {
>
<button className='bg-purple w-full rounded p-4'>Go</button>
</Link>
</div>
</div> */}
{/* Scan a Qr code */}
<div
onClick={() => {
Expand Down
7 changes: 5 additions & 2 deletions src/app/@auth/(.)send/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ export default function Page() {
</div>
<p className='text-center'>{payee && truncateEthAddress(payee)}</p>
<div className='ml-auto'>
<Link className="w-auto h-auto" href={{ pathname: `/send`, query: { payee: payee } }}>
<Link
className='h-auto w-auto'
href={{ pathname: `/send`, query: { payee: payee } }}
>
<Avatar className='h-9 w-9 bg-white'></Avatar>
</Link>
</div>
</DrawerTitle>
</DrawerHeader>
</div>

<div className='mt-10'>
<div className=''>
<SendUsdc />
</div>
</>
Expand Down
100 changes: 100 additions & 0 deletions src/app/components/KeyPad/KeyPad.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { useButton } from '@react-aria/button';
import { FocusRing } from '@react-aria/focus';
import { motion, useAnimation } from 'framer-motion';
import { ArrowLeft } from 'lucide-react';
import { useEffect, useRef, useState } from 'react';

interface KeyPadProps {
setUsdcAmount: (usdcAmount: string) => void;
usdcAmount: string;
}

export default function KeyPad({ setUsdcAmount, usdcAmount }: KeyPadProps) {
let [nums, setNums] = useState<any>([]);

function handleClick(num: any) {
setNums([...nums, num]);
}

useEffect(() => {
setUsdcAmount(nums.join(''));
}, [nums]);

return (
<div className='mx-auto flex max-w-xs flex-col items-center justify-end p-6 md:justify-center'>
<div className='m-auto text-center text-8xl font-extralight tabular-nums text-white'>
${usdcAmount || 0}
</div>
<div className='mt-9 flex flex-wrap justify-between gap-4'>
<Button onClick={() => handleClick('7')}>7</Button>
<Button onClick={() => handleClick('8')}>8</Button>
<Button onClick={() => handleClick('9')}>9</Button>
<Button onClick={() => handleClick('4')}>4</Button>
<Button onClick={() => handleClick('5')}>5</Button>
<Button onClick={() => handleClick('6')}>6</Button>
<Button onClick={() => handleClick('1')}>1</Button>
<Button onClick={() => handleClick('2')}>2</Button>
<Button onClick={() => handleClick('3')}>3</Button>
<Button onClick={() => handleClick('.')}>.</Button>
<Button onClick={() => handleClick('0')}>0</Button>
<Button
onClick={() => {
setNums(nums.slice(0, -1));
}}
>
<ArrowLeft size={40} className='m-auto text-center' />
</Button>
</div>
</div>
);
}

function Button({
onClick = () => {},
children,
}: {
onClick: () => void;
children: React.ReactNode;
}) {
let ref = useRef();
let controls = useAnimation();

let { buttonProps } = useButton(
{
onPressStart: () => {
controls.stop();
controls.set({ background: '#757376' });
},
onPressEnd: () => {
controls.start({
background: '#353336',
transition: { duration: 0.4 },
});
},
onPress: () => {
onClick();
controls.start({
background: [null, '#353336'],
transition: { duration: 0.4 },
});
},
},
ref
);

return (
<FocusRing focusRingClass='ring ring-offset-2 ring-offset-black'>
<motion.button
{...buttonProps}
ref={ref}
animate={controls}
className='h-20 w-20 touch-none select-none rounded-full bg-[#353336] text-center text-[40px] text-white focus:outline-none'
style={{
WebkitTapHighlightColor: 'transparent',
}}
>
{children}
</motion.button>
</FocusRing>
);
}
3 changes: 2 additions & 1 deletion src/app/components/Navigation/BackButton/BackButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { Undo2 } from 'lucide-react';

interface BackButtonProps {
routehome?: boolean;
onClick?: () => void;
}

export default function BackButton({ routehome }: BackButtonProps) {
export default function BackButton({ routehome, onClick }: BackButtonProps) {
return (
<div className='w-fit rounded-full p-4 hover:bg-slate-300'>
<Undo2 size={20} color='#cbd5e1' />
Expand Down
Loading

0 comments on commit cf3f0ca

Please sign in to comment.