From 308848a4fcba43d1a1afd9d273de17e519feb102 Mon Sep 17 00:00:00 2001 From: Kris Urbas <605420+krzysu@users.noreply.github.com> Date: Fri, 13 Dec 2024 17:07:44 +0100 Subject: [PATCH] feat: improve transaction rendering --- .../TransactionTableHead.stories.ts | 20 +++++++++ .../TransactionTableHead.tsx | 13 ++++++ .../components/TransactionTableHead/index.ts | 1 + .../TransactionTableRow.stories.ts | 45 +++++++++++++++++++ .../TransactionTableRow.tsx | 40 +++++++++++++++++ .../components/TransactionTableRow/index.ts | 1 + .../app/routes/wallet.$id/route.tsx | 19 +++++--- 7 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 packages/circle-demo-webapp/app/components/TransactionTableHead/TransactionTableHead.stories.ts create mode 100644 packages/circle-demo-webapp/app/components/TransactionTableHead/TransactionTableHead.tsx create mode 100644 packages/circle-demo-webapp/app/components/TransactionTableHead/index.ts create mode 100644 packages/circle-demo-webapp/app/components/TransactionTableRow/TransactionTableRow.stories.ts create mode 100644 packages/circle-demo-webapp/app/components/TransactionTableRow/TransactionTableRow.tsx create mode 100644 packages/circle-demo-webapp/app/components/TransactionTableRow/index.ts diff --git a/packages/circle-demo-webapp/app/components/TransactionTableHead/TransactionTableHead.stories.ts b/packages/circle-demo-webapp/app/components/TransactionTableHead/TransactionTableHead.stories.ts new file mode 100644 index 0000000..3ff955e --- /dev/null +++ b/packages/circle-demo-webapp/app/components/TransactionTableHead/TransactionTableHead.stories.ts @@ -0,0 +1,20 @@ +import type { Meta, StoryObj } from '@storybook/react'; + +import { TransactionTableHead } from './TransactionTableHead'; + +const meta = { + title: 'TransactionTableHead', + component: TransactionTableHead, + parameters: { + layout: 'centered', + }, + tags: ['autodocs'], +} satisfies Meta; + +export default meta; + +type Story = StoryObj; + +export const Default: Story = { + args: {}, +}; diff --git a/packages/circle-demo-webapp/app/components/TransactionTableHead/TransactionTableHead.tsx b/packages/circle-demo-webapp/app/components/TransactionTableHead/TransactionTableHead.tsx new file mode 100644 index 0000000..2301317 --- /dev/null +++ b/packages/circle-demo-webapp/app/components/TransactionTableHead/TransactionTableHead.tsx @@ -0,0 +1,13 @@ +export function TransactionTableHead() { + return ( + + + Event + From + To + Amount + Date + + + ); +} diff --git a/packages/circle-demo-webapp/app/components/TransactionTableHead/index.ts b/packages/circle-demo-webapp/app/components/TransactionTableHead/index.ts new file mode 100644 index 0000000..cd87977 --- /dev/null +++ b/packages/circle-demo-webapp/app/components/TransactionTableHead/index.ts @@ -0,0 +1 @@ +export * from './TransactionTableHead'; diff --git a/packages/circle-demo-webapp/app/components/TransactionTableRow/TransactionTableRow.stories.ts b/packages/circle-demo-webapp/app/components/TransactionTableRow/TransactionTableRow.stories.ts new file mode 100644 index 0000000..b88b83a --- /dev/null +++ b/packages/circle-demo-webapp/app/components/TransactionTableRow/TransactionTableRow.stories.ts @@ -0,0 +1,45 @@ +import type { Meta, StoryObj } from '@storybook/react'; +import type { BLOCKCHAIN, TRANSACTION_STATE } from 'web3-circle-sdk'; + +import { TransactionTableRow } from './TransactionTableRow'; + +const meta = { + title: 'TransactionTableRow', + component: TransactionTableRow, + parameters: { + layout: 'centered', + }, + tags: ['autodocs'], +} satisfies Meta; + +export default meta; + +type Story = StoryObj; + +export const Default: Story = { + args: { + transaction: { + id: 'c0d471be-f36f-5e26-8962-9ebd38ec8a62', + blockchain: 'MATIC-AMOY' as BLOCKCHAIN, + tokenId: '36b6931a-873a-56a8-8a27-b706b17104ee', + walletId: '24d1ad14-cf0c-5d7d-96d1-aca6447d0fdc', + sourceAddress: '0x2da2bf0a07b015ffa80821df8b2203d473964d95', + destinationAddress: '0xf6c9efc84080217ccd13ef6d4a7f26a680f2c713', + transactionType: 'INBOUND', + custodyType: 'DEVELOPER', + state: 'COMPLETE' as TRANSACTION_STATE, + transactionScreeningEvaluation: { screeningDate: '2024-12-10T13:52:57Z' }, + amounts: ['30'], + nfts: null, + txHash: '0x1aac3dd232d02797fb6c340cbda7d118fce0561aa7f78049f32ba167b0eaf225', + blockHash: '0x3bd9054deae68d0d5087da188f119eab2160c12c8a255668e6190c60ffed9ff6', + blockHeight: 15439404, + networkFee: '0.005164650002582325', + firstConfirmDate: '2024-12-10T13:52:57Z', + operation: 'TRANSFER', + abiParameters: null, + createDate: '2024-12-10T13:52:57Z', + updateDate: '2024-12-10T13:54:43Z', + }, + }, +}; diff --git a/packages/circle-demo-webapp/app/components/TransactionTableRow/TransactionTableRow.tsx b/packages/circle-demo-webapp/app/components/TransactionTableRow/TransactionTableRow.tsx new file mode 100644 index 0000000..22f6067 --- /dev/null +++ b/packages/circle-demo-webapp/app/components/TransactionTableRow/TransactionTableRow.tsx @@ -0,0 +1,40 @@ +import type { Transaction } from 'web3-circle-sdk'; + +import { Badge } from '~/components/ui/badge'; +import { formatDate, shortenAddress } from '~/lib/format'; + +export interface TransactionTableRowProps { + transaction: Transaction; +} + +export function TransactionTableRow({ transaction }: TransactionTableRowProps) { + const isInbound = transaction.transactionType === 'INBOUND'; + + return ( + + + {transaction.operation} + + + + {shortenAddress(transaction.sourceAddress)} + + + + {shortenAddress(transaction.destinationAddress)} + + + + {isInbound ? '+' : '-'} {transaction.amounts?.[0] ?? '0.00'} + + + + {formatDate(transaction.firstConfirmDate ?? transaction.createDate)} + + + ); +} diff --git a/packages/circle-demo-webapp/app/components/TransactionTableRow/index.ts b/packages/circle-demo-webapp/app/components/TransactionTableRow/index.ts new file mode 100644 index 0000000..f3818e7 --- /dev/null +++ b/packages/circle-demo-webapp/app/components/TransactionTableRow/index.ts @@ -0,0 +1 @@ +export * from './TransactionTableRow'; diff --git a/packages/circle-demo-webapp/app/routes/wallet.$id/route.tsx b/packages/circle-demo-webapp/app/routes/wallet.$id/route.tsx index a6482cc..a372747 100644 --- a/packages/circle-demo-webapp/app/routes/wallet.$id/route.tsx +++ b/packages/circle-demo-webapp/app/routes/wallet.$id/route.tsx @@ -2,7 +2,8 @@ import { LoaderFunctionArgs } from '@remix-run/node'; import { useLoaderData, useParams } from '@remix-run/react'; import { ArrowUp } from 'lucide-react'; -import { TransactionDetails } from '~/components/TransactionDetails'; +import { TransactionTableHead } from '~/components/TransactionTableHead'; +import { TransactionTableRow } from '~/components/TransactionTableRow'; import { Button } from '~/components/ui/button'; import { Card } from '~/components/ui/card'; import { WalletBalance } from '~/components/WalletBalance'; @@ -84,11 +85,19 @@ export default function WalletBalancePage() {
{transactions.length === 0 &&

No transactions

} - {transactions.map((tx) => ( -
- + {transactions.length > 0 && ( +
+ + + + + {transactions.map((tx) => ( + + ))} + +
- ))} + )}