@@ -8,14 +8,22 @@ import type { IotaTransactionBlockKind, IotaTransactionBlockResponse } from '@io
88import { TableCellBase , TableCellText } from '@iota/apps-ui-kit' ;
99import type { ColumnDef } from '@tanstack/react-table' ;
1010import { AddressLink , TransactionLink } from '../../../components/ui' ;
11- import { CoinFormat , formatBalance , formatDigest , NANOS_PER_IOTA } from '@iota/iota-sdk/utils' ;
11+ import {
12+ CoinFormat ,
13+ formatBalance ,
14+ formatDigest ,
15+ IOTA_TYPE_ARG ,
16+ NANOS_PER_IOTA ,
17+ } from '@iota/iota-sdk/utils' ;
1218import { getElapsedTime } from '~/pages/epochs/utils' ;
1319
1420/**
1521 * Generate table columns renderers for the transactions data.
1622 */
17- export function generateTransactionsTableColumns ( ) : ColumnDef < IotaTransactionBlockResponse > [ ] {
18- return [
23+ export function generateTransactionsTableColumns (
24+ address ?: string ,
25+ ) : ColumnDef < IotaTransactionBlockResponse > [ ] {
26+ const columns : ColumnDef < IotaTransactionBlockResponse > [ ] = [
1927 {
2028 header : 'Digest' ,
2129 accessorKey : 'digest' ,
@@ -65,6 +73,53 @@ export function generateTransactionsTableColumns(): ColumnDef<IotaTransactionBlo
6573 ) ;
6674 } ,
6775 } ,
76+ ] ;
77+
78+ if ( address ) {
79+ columns . push ( {
80+ header : 'Balance Change' ,
81+ accessorKey : 'balanceChanges' ,
82+ cell : ( { getValue } ) => {
83+ const balanceChanges = getValue < IotaTransactionBlockResponse [ 'balanceChanges' ] > ( ) ;
84+ if ( ! balanceChanges ) {
85+ return (
86+ < TableCellBase >
87+ < TableCellText > --</ TableCellText >
88+ </ TableCellBase >
89+ ) ;
90+ }
91+ const balanceChange = balanceChanges . find (
92+ ( change ) =>
93+ change . owner &&
94+ typeof change . owner === 'object' &&
95+ 'AddressOwner' in change . owner &&
96+ change . owner . AddressOwner === address &&
97+ change . coinType === IOTA_TYPE_ARG ,
98+ ) ;
99+ if ( ! balanceChange ) {
100+ return (
101+ < TableCellBase >
102+ < TableCellText > --</ TableCellText >
103+ </ TableCellBase >
104+ ) ;
105+ }
106+ const amount = balanceChange . amount ;
107+ const formatted = formatBalance (
108+ Math . abs ( Number ( amount ) ) / Number ( NANOS_PER_IOTA ) ,
109+ 0 ,
110+ CoinFormat . Rounded ,
111+ ) ;
112+ const sign = Number ( amount ) >= 0 ? '+' : '-' ;
113+ return (
114+ < TableCellBase >
115+ < TableCellText supportingLabel = "IOTA" > { sign + formatted } </ TableCellText >
116+ </ TableCellBase >
117+ ) ;
118+ } ,
119+ } ) ;
120+ }
121+
122+ columns . push (
68123 {
69124 header : 'Gas' ,
70125 accessorKey : 'effects' ,
@@ -102,5 +157,7 @@ export function generateTransactionsTableColumns(): ColumnDef<IotaTransactionBlo
102157 ) ;
103158 } ,
104159 } ,
105- ] ;
160+ ) ;
161+
162+ return columns ;
106163}
0 commit comments