Skip to content

Commit

Permalink
fix(TransactionController): Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gantunesr committed Sep 8, 2021
1 parent 1af39dd commit 0f57c39
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/transaction/TransactionController.test.ts
Expand Up @@ -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 = {
Expand Down
7 changes: 6 additions & 1 deletion src/transaction/TransactionController.ts
Expand Up @@ -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) =>
Expand Down
4 changes: 3 additions & 1 deletion src/util.ts
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 0f57c39

Please sign in to comment.