-
-
Notifications
You must be signed in to change notification settings - Fork 268
Backfill types for some dependencies #733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ export class AccountTrackerController extends BaseController< | |
| AccountTrackerConfig, | ||
| AccountTrackerState | ||
| > { | ||
| private ethQuery: any; | ||
| private ethQuery: EthQuery | null; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This property can be |
||
|
|
||
| private mutex = new Mutex(); | ||
|
|
||
|
|
@@ -98,6 +98,7 @@ export class AccountTrackerController extends BaseController< | |
| state?: Partial<AccountTrackerState>, | ||
| ) { | ||
| super(config, state); | ||
| this.ethQuery = null; | ||
| this.defaultConfig = { | ||
| interval: 10000, | ||
| }; | ||
|
|
@@ -145,11 +146,17 @@ export class AccountTrackerController extends BaseController< | |
| * Refreshes all accounts in the current keychain. | ||
| */ | ||
| refresh = async () => { | ||
| const { ethQuery } = this; | ||
|
|
||
| if (ethQuery === null) { | ||
| return; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a change in behavior. It now returns nothing instead of throwing an error. The same goes for |
||
| } | ||
|
|
||
| this.syncAccounts(); | ||
| const accounts = { ...this.state.accounts }; | ||
| for (const address in accounts) { | ||
| await safelyExecuteWithTimeout(async () => { | ||
| const balance = await query(this.ethQuery, 'getBalance', [address]); | ||
| const balance = await query<string>(ethQuery, 'getBalance', [address]); | ||
| accounts[address] = { balance: BNToHex(balance) }; | ||
| }); | ||
| } | ||
|
|
@@ -165,11 +172,19 @@ export class AccountTrackerController extends BaseController< | |
| async syncBalanceWithAddresses( | ||
| addresses: string[], | ||
| ): Promise<Record<string, { balance: string }>> { | ||
| const { ethQuery } = this; | ||
|
|
||
| if (ethQuery === null) { | ||
| return {}; | ||
| } | ||
|
|
||
| return await Promise.all( | ||
| addresses.map( | ||
| (address): Promise<[string, string] | undefined> => { | ||
| return safelyExecuteWithTimeout(async () => { | ||
| const balance = await query(this.ethQuery, 'getBalance', [address]); | ||
| const balance = await query<string>(ethQuery, 'getBalance', [ | ||
| address, | ||
| ]); | ||
| return [address, balance]; | ||
| }); | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,6 @@ import { | |
| TokenListStateChange, | ||
| GetTokenListState, | ||
| TokenListMap, | ||
| ContractMap, | ||
| } from './TokenListController'; | ||
|
|
||
| const name = 'TokenListController'; | ||
|
|
@@ -21,9 +20,7 @@ const timestamp = Date.now(); | |
|
|
||
| const staticTokenList: TokenListMap = {}; | ||
| for (const tokenAddress in contractMap) { | ||
| const { erc20, logo: filePath, ...token } = (contractMap as ContractMap)[ | ||
| tokenAddress | ||
| ]; | ||
| const { erc20, logo: filePath, ...token } = contractMap[tokenAddress]; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Types were added in this PR for |
||
| if (erc20) { | ||
| staticTokenList[tokenAddress] = { | ||
| ...token, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| import { BN } from 'ethereumjs-util'; | ||
| import { mocked } from 'ts-jest/utils'; | ||
| import { when } from 'jest-when'; | ||
| import { buildFakeEthQuery } from '../../tests/util'; | ||
| import { query, fromHex, toHex } from '../util'; | ||
| import fetchBlockFeeHistory from './fetchBlockFeeHistory'; | ||
|
|
||
| jest.mock('../util', () => { | ||
| return { | ||
| ...jest.requireActual('../util'), | ||
| __esModule: true, | ||
| query: jest.fn(), | ||
| }; | ||
| }); | ||
|
|
@@ -30,7 +30,7 @@ function times<T>(n: number, fn: (n: number) => T): T[] { | |
| } | ||
|
|
||
| describe('fetchBlockFeeHistory', () => { | ||
| const ethQuery = { eth: 'query' }; | ||
| const ethQuery = buildFakeEthQuery(); | ||
|
|
||
| describe('with a minimal set of arguments', () => { | ||
| const latestBlockNumber = 3; | ||
|
|
@@ -333,6 +333,12 @@ describe('fetchBlockFeeHistory', () => { | |
| const latestBlockNumber = 3; | ||
| const numberOfRequestedBlocks = 3; | ||
|
|
||
| beforeEach(() => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should have been there all along and for some reason it was not causing the test to fail. |
||
| when(mockedQuery) | ||
| .calledWith(ethQuery, 'blockNumber') | ||
| .mockResolvedValue(new BN(latestBlockNumber)); | ||
| }); | ||
|
|
||
| it('includes an extra block with an estimated baseFeePerGas', async () => { | ||
| when(mockedQuery) | ||
| .calledWith(ethQuery, 'eth_feeHistory', [ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| import { BN } from 'ethereumjs-util'; | ||
| import { query, fromHex, toHex } from '../util'; | ||
|
|
||
| type EthQuery = any; | ||
| import { query, fromHex, toHex, EthQueryish } from '../util'; | ||
|
|
||
| /** | ||
| * @type RequestChunkSpecifier | ||
|
|
@@ -111,7 +109,7 @@ const MAX_NUMBER_OF_BLOCKS_PER_ETH_FEE_HISTORY_CALL = 1024; | |
| * - <https://gas-api.metaswap.codefi.network/testFeeHistory> | ||
| * | ||
| * @param args - The arguments to this function. | ||
| * @param args.ethQuery - An EthQuery instance that wraps a provider for the network in question. | ||
| * @param args.ethQuery - An object that {@link query} takes which wraps a provider for the network in question. | ||
| * @param args.endBlock - The desired end of the requested block range. Can be "latest" if you want | ||
| * to start from the latest successful block or the number of a known past block. | ||
| * @param args.numberOfBlocks - How many total blocks to fetch. Note that if this is more than 1024, | ||
|
|
@@ -138,7 +136,7 @@ export default async function fetchBlockFeeHistory<Percentile extends number>({ | |
| percentiles: givenPercentiles = [], | ||
| includeNextBlock = false, | ||
| }: { | ||
| ethQuery: EthQuery; | ||
| ethQuery: EthQueryish; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An "EthQueryish" is an object that looks like an EthQuery without the full gamut of methods that EthQuery supports. It's the type of the argument that |
||
| numberOfBlocks: number; | ||
| endBlock?: 'latest' | BN; | ||
| percentiles?: readonly Percentile[]; | ||
|
|
@@ -149,10 +147,13 @@ export default async function fetchBlockFeeHistory<Percentile extends number>({ | |
| ? Array.from(new Set(givenPercentiles)).sort((a, b) => a - b) | ||
| : []; | ||
|
|
||
| const finalEndBlockNumber = | ||
| givenEndBlock === 'latest' | ||
| ? fromHex(await query(ethQuery, 'blockNumber')) | ||
| : givenEndBlock; | ||
| let finalEndBlockNumber: BN; | ||
| if (givenEndBlock === 'latest') { | ||
| const latestBlockNumber = await query<string>(ethQuery, 'blockNumber'); | ||
| finalEndBlockNumber = fromHex(latestBlockNumber); | ||
| } else { | ||
| finalEndBlockNumber = givenEndBlock; | ||
| } | ||
|
|
||
| const requestChunkSpecifiers = determineRequestChunkSpecifiers( | ||
| finalEndBlockNumber, | ||
|
|
@@ -275,13 +276,13 @@ async function makeRequestForChunk<Percentile extends number>({ | |
| percentiles, | ||
| includeNextBlock, | ||
| }: { | ||
| ethQuery: EthQuery; | ||
| ethQuery: EthQueryish; | ||
| numberOfBlocks: number; | ||
| endBlockNumber: BN; | ||
| percentiles: readonly Percentile[]; | ||
| includeNextBlock: boolean; | ||
| }): Promise<FeeHistoryBlock<Percentile>[]> { | ||
| const response: EthFeeHistoryResponse = await query( | ||
| const response = await query<EthFeeHistoryResponse>( | ||
| ethQuery, | ||
| 'eth_feeHistory', | ||
| [toHex(numberOfBlocks), toHex(endBlockNumber), percentiles], | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My changes to this file resulted in the coverage percentage falling below our threshold, so I've disabled this file for the time being. I logged an issue to backfill these tests here: #734