@@ -98,6 +98,32 @@ export class TransactionService {
9898 return await this . indexerService . getTransactionCount ( filter , address ) ;
9999 }
100100
101+ public reorderAccountSentTransactionsByNonce ( transactions : TransactionDetailed [ ] , accountAddress : string ) : TransactionDetailed [ ] {
102+ const sentPositions : number [ ] = [ ] ;
103+ const sentTransactions : TransactionDetailed [ ] = [ ] ;
104+
105+ transactions . forEach ( ( tx , index ) => {
106+ if ( tx . sender === accountAddress ) {
107+ sentPositions . push ( index ) ;
108+ sentTransactions . push ( tx ) ;
109+ }
110+ } ) ;
111+
112+ sentTransactions . sort ( ( a , b ) => {
113+ const nonceA = a . nonce ?? 0 ;
114+ const nonceB = b . nonce ?? 0 ;
115+ return nonceB - nonceA ;
116+ } ) ;
117+
118+ const result = [ ...transactions ] ;
119+
120+ sentPositions . forEach ( ( position , index ) => {
121+ result [ position ] = sentTransactions [ index ] ;
122+ } ) ;
123+
124+ return result ;
125+ }
126+
101127 private getDistinctUserAddressesFromTransactions ( transactions : Transaction [ ] ) : string [ ] {
102128 const allAddresses = [ ] ;
103129 for ( const transaction of transactions ) {
@@ -171,6 +197,13 @@ export class TransactionService {
171197 let transactions : TransactionDetailed [ ] = [ ] ;
172198 transactions = elasticTransactions . map ( x => ApiUtils . mergeObjects ( new TransactionDetailed ( ) , x ) ) ;
173199
200+ const hasSenderFilter = filter . sender || ( filter . senders && filter . senders . length > 0 ) ;
201+ const hasReceiverFilter = filter . receivers && filter . receivers . length > 0 ;
202+
203+ if ( address && ! hasSenderFilter && ! hasReceiverFilter ) {
204+ transactions = this . reorderAccountSentTransactionsByNonce ( transactions , address ) ;
205+ }
206+
174207 if ( filter . hashes ) {
175208 const txHashes : string [ ] = filter . hashes ;
176209 const elasticHashes = elasticTransactions . map ( ( { txHash } : any ) => txHash ) ;
0 commit comments