-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get transaction details (request) (#101)
- Loading branch information
Showing
28 changed files
with
511 additions
and
499 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
105 changes: 62 additions & 43 deletions
105
packages/circle-demo-webapp/app/components/TransactionDetails/TransactionDetails.tsx
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 |
---|---|---|
@@ -1,62 +1,81 @@ | ||
import { ReactNode, useMemo } from 'react'; | ||
|
||
import { ChainLabel } from '~/components/ChainLabel'; | ||
import { Badge } from '~/components/ui/badge'; | ||
import { TokenItem } from '~/components/TokenItem'; | ||
import { TransactionStateText } from '~/components/TransactionStatusText'; | ||
import { useGetTransaction } from '~/hooks/useGetTransaction'; | ||
import { TransactionType } from '~/lib/constants'; | ||
import { formatDate, shortenAddress, shortenHash } from '~/lib/format'; | ||
import { Transaction } from '~/lib/types'; | ||
import { formatDate, shortenHash } from '~/lib/format'; | ||
import { TransactionWithToken } from '~/lib/types'; | ||
|
||
export interface TransactionDetailsProps { | ||
/** The on-chain transaction */ | ||
transaction: Transaction; | ||
transaction: TransactionWithToken; | ||
} | ||
|
||
const OneLine = ({ label, value }: { label: string; value: ReactNode | string }) => ( | ||
<div className="flex space-x-4 justify-between border-t py-2"> | ||
<div className="flex-1">{label}</div> | ||
<div className="text-sm text-muted-foreground">{value}</div> | ||
</div> | ||
); | ||
|
||
/** The details of an on-chain transaction */ | ||
export function TransactionDetails({ transaction }: TransactionDetailsProps) { | ||
export function TransactionDetails(props: TransactionDetailsProps) { | ||
const getTransactionFilter = useMemo( | ||
() => ({ id: props.transaction?.id }), | ||
[props.transaction], | ||
); | ||
const { data: transaction, reFetch } = useGetTransaction( | ||
getTransactionFilter, | ||
props.transaction, | ||
); | ||
const shortHash = useMemo( | ||
() => (transaction?.txHash ? shortenHash(transaction.txHash) : ''), | ||
[transaction], | ||
); | ||
if (!transaction) { | ||
return null; | ||
} | ||
|
||
const isInbound = transaction.transactionType === TransactionType.Inbound; | ||
|
||
return ( | ||
<div> | ||
<div className="flex items-center gap-6 justify-between"> | ||
<Badge variant="outline">{transaction.operation}</Badge> | ||
|
||
<div className="flex flex-col"> | ||
<p className="text-sm text-muted-foreground"> | ||
<strong>From:</strong> {shortenAddress(transaction.sourceAddress)} | ||
</p> | ||
<OneLine label="Hash" value={shortHash} /> | ||
<OneLine | ||
label="Status" | ||
value={ | ||
<TransactionStateText state={transaction.state} getTransaction={reFetch} /> | ||
} | ||
/> | ||
<OneLine label="From" value={transaction.sourceAddress} /> | ||
<OneLine label="To" value={transaction.destinationAddress} /> | ||
{transaction.token && ( | ||
<OneLine label="Token" value={<TokenItem token={transaction.token} />} /> | ||
)} | ||
|
||
<p className="text-sm text-muted-foreground"> | ||
<strong>To:</strong> {shortenAddress(transaction.destinationAddress)} | ||
</p> | ||
</div> | ||
|
||
<p className="text-sm text-muted-foreground"> | ||
<strong>Amount:</strong>{' '} | ||
<OneLine | ||
label="Amount" | ||
value={ | ||
<span | ||
className={`font-medium ${isInbound ? 'text-green-600' : 'text-destructive'}`} | ||
className={`text-right font-medium ${ | ||
isInbound ? 'text-green-600' : 'text-destructive' | ||
}`} | ||
> | ||
{isInbound ? '+' : '-'} | ||
{transaction.amounts?.[0] ?? '0.00'} | ||
{isInbound ? '+' : '-'} {transaction.amounts?.[0] ?? '0.00'} | ||
</span> | ||
</p> | ||
|
||
{/* <p className="text-sm text-muted-foreground"> | ||
<strong>Fee:</strong> {transaction.networkFee} | ||
</p> */} | ||
|
||
<Badge variant="secondary">{transaction.state}</Badge> | ||
</div> | ||
|
||
<div className="flex items-center gap-6 justify-between"> | ||
<ChainLabel blockchain={transaction.blockchain} /> | ||
|
||
<p className="text-sm text-muted-foreground"> | ||
<strong>Date:</strong>{' '} | ||
{formatDate(transaction.firstConfirmDate ?? transaction.createDate)} | ||
</p> | ||
|
||
<p className="text-sm text-muted-foreground" title={transaction.txHash}> | ||
<strong>Hash:</strong> {shortenHash(transaction.txHash ?? '')} | ||
</p> | ||
</div> | ||
} | ||
/> | ||
<OneLine | ||
label="Date" | ||
value={formatDate(transaction.firstConfirmDate ?? transaction.createDate)} | ||
/> | ||
<OneLine | ||
label="Blockchain" | ||
value={<ChainLabel blockchain={transaction.blockchain} />} | ||
/> | ||
<OneLine label="Note" value={transaction.refId} /> | ||
</div> | ||
); | ||
} |
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
Oops, something went wrong.