-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: account live transactions (#53)
* feat: add account live transactions * chore: refactoring based on changes in main --------- Co-authored-by: Neil Campbell <[email protected]>
- Loading branch information
1 parent
97be076
commit d06fd8a
Showing
19 changed files
with
154 additions
and
183 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
25 changes: 25 additions & 0 deletions
25
src/features/accounts/components/account-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,25 @@ | ||
import { LiveTransactionsTable } from '@/features/transactions/components/live-transactions-table' | ||
import { TransactionResult } from '@algorandfoundation/algokit-utils/types/indexer' | ||
import { useCallback } from 'react' | ||
import { Address } from '../data/types' | ||
import { getAddressesForTransaction } from '../utils/get-account-address-for-transactions' | ||
import { InnerTransaction, Transaction } from '@/features/transactions/models' | ||
import { getAccountTransactionsTableSubRows } from '../utils/get-account-transactions-table-sub-rows' | ||
import { transactionsTableColumns } from '@/features/transactions/components/transactions-table-columns' | ||
|
||
type Props = { | ||
address: Address | ||
} | ||
|
||
export function AccountLiveTransactions({ address }: Props) { | ||
const filter = useCallback( | ||
(transactionResult: TransactionResult) => { | ||
const addressesForTransaction = getAddressesForTransaction(transactionResult) | ||
return addressesForTransaction.includes(address) | ||
}, | ||
[address] | ||
) | ||
|
||
const getSubRows = useCallback((row: Transaction | InnerTransaction) => getAccountTransactionsTableSubRows(address, row), [address]) | ||
return <LiveTransactionsTable filter={filter} getSubRows={getSubRows} columns={transactionsTableColumns} /> | ||
} |
8 changes: 6 additions & 2 deletions
8
src/features/accounts/components/account-transaction-history.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,14 +1,18 @@ | ||
import { LazyLoadDataTable } from '@/features/common/components/lazy-load-data-table' | ||
import { Address } from '../data/types' | ||
import { useFetchNextAccountTransactionPage } from '../data/account-transaction-history' | ||
import { accountTransactionsTableColumns } from './account-transaction-table-columns' | ||
import { useCallback } from 'react' | ||
import { getAccountTransactionsTableSubRows } from '../utils/get-account-transactions-table-sub-rows' | ||
import { InnerTransaction, Transaction } from '@/features/transactions/models' | ||
import { transactionsTableColumns } from '@/features/transactions/components/transactions-table-columns' | ||
|
||
type Props = { | ||
address: Address | ||
} | ||
|
||
export function AccountTransactionHistory({ address }: Props) { | ||
const fetchNextPage = useFetchNextAccountTransactionPage(address) | ||
const getSubRows = useCallback((row: Transaction | InnerTransaction) => getAccountTransactionsTableSubRows(address, row), [address]) | ||
|
||
return <LazyLoadDataTable columns={accountTransactionsTableColumns} fetchNextPage={fetchNextPage} /> | ||
return <LazyLoadDataTable columns={transactionsTableColumns} getSubRows={getSubRows} fetchNextPage={fetchNextPage} /> | ||
} |
57 changes: 0 additions & 57 deletions
57
src/features/accounts/components/account-transaction-table-columns.tsx
This file was deleted.
Oops, something went wrong.
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
36 changes: 0 additions & 36 deletions
36
src/features/accounts/utils/extract-transaction-for-account.ts
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
src/features/accounts/utils/get-account-address-for-transactions.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,53 @@ | ||
import algosdk from 'algosdk' | ||
import { TransactionResult } from '@algorandfoundation/algokit-utils/types/indexer' | ||
import { invariant } from '@/utils/invariant' | ||
import { Address } from '../data/types' | ||
|
||
export const getAddressesForTransaction = (transaction: TransactionResult): Address[] => { | ||
const addresses = new Set<Address>() | ||
addresses.add(transaction.sender) | ||
if (transaction['tx-type'] === algosdk.TransactionType.pay) { | ||
invariant(transaction['payment-transaction'], 'payment-transaction is not set') | ||
|
||
addresses.add(transaction['payment-transaction']['receiver']) | ||
if (transaction['payment-transaction']['close-remainder-to']) { | ||
addresses.add(transaction['payment-transaction']['close-remainder-to']) | ||
} | ||
} else if (transaction['tx-type'] === algosdk.TransactionType.axfer) { | ||
invariant(transaction['asset-transfer-transaction'], 'asset-transfer-transaction is not set') | ||
|
||
addresses.add(transaction['asset-transfer-transaction']['receiver']) | ||
if (transaction['asset-transfer-transaction']['close-to']) { | ||
addresses.add(transaction['asset-transfer-transaction']['close-to']) | ||
} | ||
} else if (transaction['tx-type'] === algosdk.TransactionType.afrz) { | ||
invariant(transaction['asset-freeze-transaction'], 'asset-freeze-transaction is not set') | ||
|
||
addresses.add(transaction['asset-freeze-transaction']['address']) | ||
} else if (transaction['tx-type'] === algosdk.TransactionType.acfg) { | ||
invariant(transaction['asset-config-transaction'], 'asset-config-transaction is not set') | ||
if (transaction['asset-config-transaction'].params?.manager) { | ||
addresses.add(transaction['asset-config-transaction'].params?.manager) | ||
} | ||
if (transaction['asset-config-transaction'].params?.reserve) { | ||
addresses.add(transaction['asset-config-transaction'].params?.reserve) | ||
} | ||
if (transaction['asset-config-transaction'].params?.freeze) { | ||
addresses.add(transaction['asset-config-transaction'].params?.freeze) | ||
} | ||
if (transaction['asset-config-transaction'].params?.clawback) { | ||
addresses.add(transaction['asset-config-transaction'].params?.clawback) | ||
} | ||
} else if (transaction['tx-type'] === algosdk.TransactionType.appl) { | ||
invariant(transaction['application-transaction'], 'application-transaction is not set') | ||
|
||
const innerTransactions = transaction['inner-txns'] ?? [] | ||
for (const innerTxn of innerTransactions) { | ||
const innerAddresses = getAddressesForTransaction(innerTxn) | ||
for (const address of innerAddresses) { | ||
addresses.add(address) | ||
} | ||
} | ||
} | ||
return Array.from(addresses) | ||
} |
28 changes: 28 additions & 0 deletions
28
src/features/accounts/utils/get-account-transactions-table-sub-rows.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,28 @@ | ||
import { Transaction, InnerTransaction, TransactionType } from '@/features/transactions/models' | ||
import { flattenInnerTransactions } from '@/utils/flatten-inner-transactions' | ||
import { Address } from '../data/types' | ||
|
||
export const getAccountTransactionsTableSubRows = (address: Address, transaction: Transaction | InnerTransaction) => { | ||
if (transaction.type !== TransactionType.ApplicationCall || transaction.innerTransactions.length === 0) { | ||
return [] | ||
} | ||
|
||
return transaction.innerTransactions.filter((innerTransaction) => { | ||
const txns = flattenInnerTransactions(innerTransaction) | ||
return txns.some(({ transaction }) => { | ||
return ( | ||
transaction.sender === address || | ||
(transaction.type === TransactionType.Payment && | ||
(transaction.receiver === address || transaction.closeRemainder?.to === address)) || | ||
(transaction.type === TransactionType.AssetTransfer && | ||
(transaction.receiver === address || transaction.closeRemainder?.to === address || transaction.clawbackFrom === address)) || | ||
(transaction.type === TransactionType.AssetConfig && | ||
(transaction.manager === address || | ||
transaction.clawback === address || | ||
transaction.reserve === address || | ||
transaction.freeze === address)) || | ||
(transaction.type === TransactionType.AssetFreeze && transaction.address === address) | ||
) | ||
}) | ||
}) | ||
} |
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
Oops, something went wrong.