-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: send and receive functionality (#465)
Co-authored-by: René Aaron <rene@twentyuno.net> Co-authored-by: Roland Bewick <roland.bewick@gmail.com>
- Loading branch information
1 parent
fa2e70f
commit 6a56ea4
Showing
26 changed files
with
1,142 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import dayjs from "dayjs"; | ||
import { ArrowDownIcon, ArrowUpIcon, Drum } from "lucide-react"; | ||
import EmptyState from "src/components/EmptyState"; | ||
|
||
import Loading from "src/components/Loading"; | ||
import { useTransactions } from "src/hooks/useTransactions"; | ||
|
||
function TransactionsList() { | ||
const { data: transactions, isLoading } = useTransactions(); | ||
|
||
if (isLoading) { | ||
return <Loading />; | ||
} | ||
|
||
return ( | ||
<div> | ||
{!transactions?.length ? ( | ||
<EmptyState | ||
icon={Drum} | ||
title="No transactions yet" | ||
description="Your most recent incoming and outgoing payments will show up here." | ||
buttonText="Receive Your First Payment" | ||
buttonLink="/wallet/receive" | ||
/> | ||
) : ( | ||
<> | ||
{transactions?.map((tx, i) => { | ||
const type = tx.type; | ||
|
||
return ( | ||
<div | ||
key={`tx-${i}`} | ||
className="p-3 mb-4 rounded-md" | ||
// TODO: Add modal onclick to show payment details | ||
> | ||
<div className="flex gap-3"> | ||
<div className="flex items-center"> | ||
{type == "outgoing" ? ( | ||
<div | ||
className={ | ||
"flex justify-center items-center bg-orange-100 dark:bg-orange-950 rounded-full w-10 h-10 md:w-14 md:h-14" | ||
} | ||
> | ||
<ArrowUpIcon | ||
strokeWidth={3} | ||
className="w-6 h-6 md:w-8 md:h-8 text-orange-400 dark:text-amber-600 stroke-orange-400 dark:stroke-amber-600" | ||
/> | ||
</div> | ||
) : ( | ||
<div className="flex justify-center items-center bg-green-100 dark:bg-emerald-950 rounded-full w-10 h-10 md:w-14 md:h-14"> | ||
<ArrowDownIcon | ||
strokeWidth={3} | ||
className="w-6 h-6 md:w-8 md:h-8 text-green-500 dark:text-emerald-500 stroke-green-400 dark:stroke-emerald-500" | ||
/> | ||
</div> | ||
)} | ||
</div> | ||
<div className="overflow-hidden mr-3"> | ||
<div className="flex items-center gap-2 truncate dark:text-white"> | ||
<p className="text-lg md:text-xl font-semibold"> | ||
{type == "incoming" ? "Received" : "Sent"} | ||
</p> | ||
<p className="text-sm md:text-base truncate text-muted-foreground"> | ||
{dayjs(tx.settled_at * 1000).fromNow()} | ||
</p> | ||
</div> | ||
<p className="text-sm md:text-base text-muted-foreground"> | ||
{tx.description || "Lightning invoice"} | ||
</p> | ||
</div> | ||
<div className="flex ml-auto text-right space-x-3 shrink-0 dark:text-white"> | ||
<div className="flex items-center gap-2 text-xl"> | ||
<p | ||
className={`font-semibold ${ | ||
type == "incoming" && | ||
"text-green-600 dark:color-green-400" | ||
}`} | ||
> | ||
{type == "outgoing" ? "-" : "+"}{" "} | ||
{Math.floor(tx.amount / 1000)} | ||
</p> | ||
<p className="text-muted-foreground">sats</p> | ||
|
||
{/* {!!tx.totalAmountFiat && ( | ||
<p className="text-xs text-gray-400 dark:text-neutral-600"> | ||
~{tx.totalAmountFiat} | ||
</p> | ||
)} */} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
})} | ||
{/* {transaction && ( | ||
<TransactionModal | ||
transaction={transaction} | ||
isOpen={modalOpen} | ||
onClose={() => { | ||
setModalOpen(false); | ||
}} | ||
/> | ||
)} */} | ||
</> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export default TransactionsList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import useSWR, { SWRConfiguration } from "swr"; | ||
|
||
import { Transaction } from "src/types"; | ||
import { swrFetcher } from "src/utils/swr"; | ||
|
||
const pollConfiguration: SWRConfiguration = { | ||
refreshInterval: 3000, | ||
}; | ||
|
||
export function useTransaction(paymentHash: string, poll = false) { | ||
return useSWR<Transaction>( | ||
paymentHash && `/api/transactions/${paymentHash}`, | ||
swrFetcher, | ||
poll ? pollConfiguration : undefined | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import useSWR, { SWRConfiguration } from "swr"; | ||
|
||
import { Transaction } from "src/types"; | ||
import { swrFetcher } from "src/utils/swr"; | ||
|
||
const pollConfiguration: SWRConfiguration = { | ||
refreshInterval: 3000, | ||
}; | ||
|
||
export function useTransactions(poll = false) { | ||
return useSWR<Transaction[]>( | ||
"/api/transactions", | ||
swrFetcher, | ||
poll ? pollConfiguration : undefined | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.