From 0f57c39f5b8ca0e6502db03f978e9664da280f5d Mon Sep 17 00:00:00 2001 From: gantunesr Date: Wed, 8 Sep 2021 19:48:18 -0300 Subject: [PATCH] fix(TransactionController): Address review comments --- src/transaction/TransactionController.test.ts | 14 ++++++++------ src/transaction/TransactionController.ts | 7 ++++++- src/util.ts | 4 +++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/transaction/TransactionController.test.ts b/src/transaction/TransactionController.test.ts index 7d53c7bfde..a68429b765 100644 --- a/src/transaction/TransactionController.test.ts +++ b/src/transaction/TransactionController.test.ts @@ -205,12 +205,14 @@ const ETH_TX_HISTORY_DATA_ROPSTEN_NO_TRANSACTIONS_FOUND = { }; const MOCK_FETCH_TX_HISTORY_DATA_OK = { - 'https://api-ropsten.etherscan.io/api?module=account&address=0x6bf137f335ea1b8f193b8f6ea92561a60d23a207&limit=50&action=tokentx&tag=latest&page=1': ETH_TX_HISTORY_DATA_ROPSTEN_NO_TRANSACTIONS_FOUND, - 'https://api.etherscan.io/api?module=account&address=0x6bf137f335ea1b8f193b8f6ea92561a60d23a207&limit=50&action=tokentx&tag=latest&page=1': TOKEN_TX_HISTORY_DATA, - 'https://api.etherscan.io/api?module=account&address=0x6bf137f335ea1b8f193b8f6ea92561a60d23a207&startBlock=999&limit=50&action=tokentx&tag=latest&page=1': TOKEN_TX_HISTORY_DATA_FROM_BLOCK, - 'https://api.etherscan.io/api?module=account&address=0x6bf137f335ea1b8f193b8f6ea92561a60d23a207&limit=50&action=txlist&tag=latest&page=1': ETH_TX_HISTORY_DATA, - 'https://api-ropsten.etherscan.io/api?module=account&address=0x6bf137f335ea1b8f193b8f6ea92561a60d23a207&limit=50&action=txlist&tag=latest&page=1': ETH_TX_HISTORY_DATA, - 'https://api.etherscan.io/api?module=account&address=0x6bf137f335ea1b8f193b8f6ea92561a60d23a207&startBlock=999&limit=50&action=txlist&tag=latest&page=1': ETH_TX_HISTORY_DATA_FROM_BLOCK, + 'https://api-ropsten.etherscan.io/api?module=account&address=0x6bf137f335ea1b8f193b8f6ea92561a60d23a207&offset=40&order=desc&action=tokentx&tag=latest&page=1': ETH_TX_HISTORY_DATA_ROPSTEN_NO_TRANSACTIONS_FOUND, + 'https://api.etherscan.io/api?module=account&address=0x6bf137f335ea1b8f193b8f6ea92561a60d23a207&offset=40&order=desc&action=tokentx&tag=latest&page=1': TOKEN_TX_HISTORY_DATA, + 'https://api.etherscan.io/api?module=account&address=0x6bf137f335ea1b8f193b8f6ea92561a60d23a207&startBlock=999&offset=40&order=desc&action=tokentx&tag=latest&page=1': TOKEN_TX_HISTORY_DATA_FROM_BLOCK, + 'https://api.etherscan.io/api?module=account&address=0x6bf137f335ea1b8f193b8f6ea92561a60d23a207&offset=40&order=desc&action=txlist&tag=latest&page=1': ETH_TX_HISTORY_DATA, + 'https://api-ropsten.etherscan.io/api?module=account&address=0x6bf137f335ea1b8f193b8f6ea92561a60d23a207&offset=40&order=desc&action=txlist&tag=latest&page=1': ETH_TX_HISTORY_DATA, + 'https://api.etherscan.io/api?module=account&address=0x6bf137f335ea1b8f193b8f6ea92561a60d23a207&startBlock=999&offset=40&order=desc&action=txlist&tag=latest&page=1': ETH_TX_HISTORY_DATA_FROM_BLOCK, + 'https://api-ropsten.etherscan.io/api?module=account&address=0x6bf137f335ea1b8f193b8f6ea92561a60d23a207&offset=2&order=desc&action=tokentx&tag=latest&page=1': ETH_TX_HISTORY_DATA_ROPSTEN_NO_TRANSACTIONS_FOUND, + 'https://api-ropsten.etherscan.io/api?module=account&address=0x6bf137f335ea1b8f193b8f6ea92561a60d23a207&offset=2&order=desc&action=txlist&tag=latest&page=1': ETH_TX_HISTORY_DATA, }; const MOCK_FETCH_TX_HISTORY_DATA_ERROR = { diff --git a/src/transaction/TransactionController.ts b/src/transaction/TransactionController.ts index 86fb485ccc..124e3954ce 100644 --- a/src/transaction/TransactionController.ts +++ b/src/transaction/TransactionController.ts @@ -1133,7 +1133,12 @@ export class TransactionController extends BaseController< const [ etherscanTxResponse, etherscanTokenResponse, - ] = await handleTransactionFetch(networkType, address, opt); + ] = await handleTransactionFetch( + networkType, + address, + this.config.txHistoryLimit, + opt, + ); const normalizedTxs = etherscanTxResponse.result.map( (tx: EtherscanTransactionMeta) => diff --git a/src/util.ts b/src/util.ts index 4359c0f9b9..05ee2699ef 100644 --- a/src/util.ts +++ b/src/util.ts @@ -182,6 +182,7 @@ export function getEtherscanApiUrl( export async function handleTransactionFetch( networkType: string, address: string, + txHistoryLimit: number, opt?: FetchAllOptions, ): Promise<[{ [result: string]: [] }, { [result: string]: [] }]> { // transactions @@ -190,7 +191,8 @@ export async function handleTransactionFetch( address, startBlock: opt?.fromBlock, apikey: opt?.etherscanApiKey, - limit: '50', + offset: txHistoryLimit.toString(), + order: 'desc', }; const etherscanTxUrl = getEtherscanApiUrl(networkType, { ...urlParams,