Skip to content

Commit 936f1b4

Browse files
committed
refactor: remove requester contract filter
Remove fetching tasks only from contracts requester has interacted with in the past N days.
1 parent 808dffc commit 936f1b4

File tree

1 file changed

+3
-58
lines changed

1 file changed

+3
-58
lines changed

src/features/linguo/api/createApiFacade.js

+3-58
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import IArbitrator from '@kleros/erc-792/build/contracts/IArbitrator.json';
22
import Linguo from '@kleros/linguo-contracts/artifacts/contracts/0.7.x/Linguo.sol/Linguo.json';
3-
import { subtract } from '~/adapters/big-number';
43
import { combination } from '~/adapters/js-combinatorics';
54
import { withProvider } from '~/app/archon';
65
import {
@@ -9,7 +8,6 @@ import {
98
compose,
109
filter,
1110
flatten,
12-
indexBy,
1311
map,
1412
mapValues,
1513
omit,
@@ -134,7 +132,7 @@ export default async function createApiFacade({ web3, chainId }) {
134132

135133
const addresses = uniq([
136134
...hintedAddresses,
137-
...(await getContractAddressesForRequester({ web3, chainId, account, apiInstancesByAddress })),
135+
...(await getContractAddressesForRequester({ account, apiInstancesByAddress })),
138136
]);
139137

140138
const instances = Object.values(pick(addresses, apiInstancesByAddress));
@@ -296,63 +294,10 @@ export function getContractInstancesForTranslator({ skills, addressesByLanguageG
296294
return compose(Object.values, pick(addresses))(apiInstancesByAddress);
297295
}
298296

299-
/**
300-
* Considers 1 block each 13.25 seconds on average.
301-
*/
302-
const BLOCK_INTERVAL_SIZE = Math.round(60 * 24 * 60 * 60 * 4.53);
303-
304-
const chainIdToMakeExplorerUrl = {
305-
1: ({ account, startBlock, endBlock, apiKey }) =>
306-
`https://api.etherscan.io/api?module=account&action=txlist&address=${account}&startblock=${startBlock}&endblock=${endBlock}&sort=desc&apikey=${apiKey}`,
307-
42: ({ account, startBlock, endBlock, apiKey }) =>
308-
`https://api-kovan.etherscan.io/api?module=account&action=txlist&address=${account}&startblock=${startBlock}&endblock=${endBlock}&sort=desc&apikey=${apiKey}`,
309-
77: ({ account, startBlock, endBlock }) =>
310-
`https://blockscout.com/poa/sokol/api?module=account&action=txlist&address=${account}&startblock=${startBlock}&endblock=${endBlock}&sort=desc`,
311-
100: ({ account, startBlock, endBlock }) =>
312-
`https://blockscout.com/xdai/mainnet/api?module=account&action=txlist&address=${account}&startblock=${startBlock}&endblock=${endBlock}&sort=desc`,
313-
};
314-
315-
async function getContractAddressesForRequester({ chainId, account, web3, apiInstancesByAddress }) {
297+
async function getContractAddressesForRequester({ account, apiInstancesByAddress }) {
316298
if (!account) {
317299
return [];
318300
}
319301

320-
const endBlock = await web3.eth.getBlockNumber();
321-
const startBlock = subtract(endBlock, BLOCK_INTERVAL_SIZE);
322-
323-
const url = chainIdToMakeExplorerUrl[chainId]({
324-
account,
325-
startBlock,
326-
endBlock,
327-
apiKey: process.env.ETHERSCAN_API_KEY,
328-
});
329-
330-
let response;
331-
try {
332-
response = await fetch(url, { mode: 'cors' });
333-
334-
if (![200, 304].includes(response.status)) {
335-
console.warn(`Failed to fetch Linguo contracts account ${account} interacted with.`);
336-
return Object.keys(apiInstancesByAddress);
337-
}
338-
} catch (err) {
339-
console.warn(`Failed to fetch Linguo contracts account ${account} interacted with:`, err);
340-
return Object.keys(apiInstancesByAddress);
341-
}
342-
343-
const { result } = await response.json();
344-
345-
/**
346-
* Etherscan API returns addresses converted all to lowercase.
347-
* To actually be able to compare them, we need to convert everything to lowercase
348-
* and then back when returning.
349-
*/
350-
const addressesLowercaseKey = indexBy(addr => String(addr).toLowerCase(), Object.keys(apiInstancesByAddress));
351-
352-
return compose(
353-
map(lowercaseAddr => addressesLowercaseKey[lowercaseAddr]),
354-
uniq,
355-
map(prop('to')),
356-
filter(compose(to => prop(to, addressesLowercaseKey), prop('to')))
357-
)(result);
302+
return Object.keys(apiInstancesByAddress);
358303
}

0 commit comments

Comments
 (0)