From 8060c184b155f63bdc8a682586f449e22e1b06c1 Mon Sep 17 00:00:00 2001 From: phamphong9981 Date: Wed, 24 Jul 2024 10:31:25 +0700 Subject: [PATCH] refactor: review --- src/services/evm/erc20_handler.ts | 12 ++---------- test/unit/services/evm/erc20_handler.spec.ts | 6 +++--- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/services/evm/erc20_handler.ts b/src/services/evm/erc20_handler.ts index 10bb1bd30..6fc01444b 100644 --- a/src/services/evm/erc20_handler.ts +++ b/src/services/evm/erc20_handler.ts @@ -207,18 +207,10 @@ export class Erc20Handler { logger ); if (activity) { - const index = erc20Activities.findIndex( - (e) => e.height > activity.height - ); - // sort activity - if (index === -1) { - erc20Activities.splice(erc20Activities.length, 0, activity); - } else { - erc20Activities.splice(index, 0, activity); - } + erc20Activities.push(activity); } }); - return erc20Activities; + return _.sortBy(erc20Activities, 'cosmos_tx_id'); } static async getErc20Activities( diff --git a/test/unit/services/evm/erc20_handler.spec.ts b/test/unit/services/evm/erc20_handler.spec.ts index 1490827f9..43919ee24 100644 --- a/test/unit/services/evm/erc20_handler.spec.ts +++ b/test/unit/services/evm/erc20_handler.spec.ts @@ -322,7 +322,7 @@ export default class Erc20HandlerTest { gas_wanted: '2456353', hash: '1406F9DDCE529F0E6EB32E07A88E5BC4EE220D3A2AB6D57E89DD12EB1945CC19', height: blockHeight, - id: 505671, + id: evmTransaction.id, index: 0, memo: 'memo', timestamp: '2024-07-15T17:08:43.386+07:00', @@ -432,7 +432,7 @@ export default class Erc20HandlerTest { tx_hash: '0x8a82a0c8848487d716f10a91f0aefb0526d35bd0f489166cc5141718a4d8aa64', topic3: null, - tx_id: evmTransaction.id, + tx_id: evmTransaction.id - 1, tx_index: 0, }), // transfer event @@ -454,7 +454,7 @@ export default class Erc20HandlerTest { tx_hash: '0x8a82a0c8848487d716f10a91f0aefb0526d35bd0f489166cc5141718a4d8aa64', topic3: null, - tx_id: evmTransaction.id, + tx_id: evmTransaction.id + 1, tx_index: 0, }), ];