-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b134b9e
commit e48655c
Showing
27 changed files
with
351 additions
and
106 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
30 changes: 30 additions & 0 deletions
30
src/features/assets/components/asset-live-transactions.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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { AssetId } from '../data/types' | ||
import { useCallback } from 'react' | ||
import { LiveTransactionsTable } from '@/features/transactions/components/live-transactions-table' | ||
import { assetTransactionsTableColumns } from '../utils/asset-transactions-table-columns' | ||
import { TransactionResult } from '@algorandfoundation/algokit-utils/types/indexer' | ||
import { JotaiStore } from '@/features/common/data/types' | ||
import { createTransactionAtom } from '@/features/transactions/data' | ||
import { atom } from 'jotai' | ||
import { getAssetIdsForTransaction } from '@/features/transactions/utils/get-asset-ids-for-transaction' | ||
import { extractTransactionsForAsset } from '../utils/extract-transactions-for-asset' | ||
|
||
type Props = { | ||
assetId: AssetId | ||
} | ||
|
||
export function AssetLiveTransactions({ assetId }: Props) { | ||
const mapper = useCallback( | ||
(store: JotaiStore, transactionResult: TransactionResult) => { | ||
return atom(async (get) => { | ||
const assetIdsForTransaction = getAssetIdsForTransaction(transactionResult) | ||
if (!assetIdsForTransaction.includes(assetId)) return [] | ||
|
||
const transaction = await get(createTransactionAtom(store, transactionResult)) | ||
return extractTransactionsForAsset(transaction, assetId) | ||
}) | ||
}, | ||
[assetId] | ||
) | ||
return <LiveTransactionsTable mapper={mapper} columns={assetTransactionsTableColumns} /> | ||
} |
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
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
57 changes: 57 additions & 0 deletions
57
src/features/assets/utils/asset-transactions-table-columns.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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { InnerTransaction, Transaction, TransactionType } from '@/features/transactions/models' | ||
import { cn } from '@/features/common/utils' | ||
import { ellipseAddress } from '@/utils/ellipse-address' | ||
import { ColumnDef } from '@tanstack/react-table' | ||
import { DisplayAlgo } from '@/features/common/components/display-algo' | ||
import { DisplayAssetAmount } from '@/features/common/components/display-asset-amount' | ||
import { TransactionLink } from '@/features/transactions/components/transaction-link' | ||
import { ellipseId } from '@/utils/ellipse-id' | ||
import { asTo } from '@/features/common/mappers/to' | ||
|
||
export const assetTransactionsTableColumns: ColumnDef<Transaction | InnerTransaction>[] = [ | ||
{ | ||
header: 'Transaction Id', | ||
accessorFn: (transaction) => transaction, | ||
cell: (c) => { | ||
const transaction = c.getValue<Transaction | InnerTransaction>() | ||
return 'innerId' in transaction ? ( | ||
<TransactionLink | ||
className={cn('text-primary underline cursor-pointer grid gap-2')} | ||
transactionId={transaction.networkTransactionId} | ||
> | ||
<span>{ellipseId(transaction.id)}</span> | ||
<span>(Inner)</span> | ||
</TransactionLink> | ||
) : ( | ||
<TransactionLink transactionId={transaction.id} short={true} /> | ||
) | ||
}, | ||
}, | ||
{ | ||
header: 'Round', | ||
accessorKey: 'confirmedRound', | ||
}, | ||
{ | ||
accessorKey: 'sender', | ||
header: 'From', | ||
cell: (c) => ellipseAddress(c.getValue<string>()), | ||
}, | ||
{ | ||
header: 'To', | ||
accessorFn: asTo, | ||
}, | ||
{ | ||
accessorKey: 'type', | ||
header: 'Type', | ||
}, | ||
{ | ||
header: 'Amount', | ||
accessorFn: (transaction) => transaction, | ||
cell: (c) => { | ||
const transaction = c.getValue<Transaction>() | ||
if (transaction.type === TransactionType.Payment) return <DisplayAlgo className={cn('justify-center')} amount={transaction.amount} /> | ||
if (transaction.type === TransactionType.AssetTransfer) | ||
return <DisplayAssetAmount amount={transaction.amount} asset={transaction.asset} /> | ||
}, | ||
}, | ||
] |
20 changes: 20 additions & 0 deletions
20
src/features/assets/utils/extract-transactions-for-asset.ts
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,20 @@ | ||
import { Transaction, TransactionType } from '@/features/transactions/models' | ||
import { flattenInnerTransactions } from '@/utils/flatten-inner-transactions' | ||
|
||
export const extractTransactionsForAsset = (transaction: Transaction, assetIndex: number) => { | ||
const flattenedTransactions = flattenInnerTransactions(transaction) | ||
const results = [] | ||
|
||
for (const { transaction } of flattenedTransactions) { | ||
if (transaction.type === TransactionType.AssetConfig && transaction.assetId === assetIndex) { | ||
results.push(transaction) | ||
} | ||
if (transaction.type === TransactionType.AssetTransfer && transaction.asset.id === assetIndex) { | ||
results.push(transaction) | ||
} | ||
if (transaction.type === TransactionType.AssetFreeze && transaction.assetId === assetIndex) { | ||
results.push(transaction) | ||
} | ||
} | ||
return results | ||
} |
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.