Skip to content

Commit

Permalink
Apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Siegrift committed Apr 3, 2024
1 parent e331ed7 commit b312b1f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
9 changes: 5 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ module.exports = {
extends: ['./node_modules/@api3/commons/dist/eslint/universal', './node_modules/@api3/commons/dist/eslint/jest'],
plugins: ['@typescript-eslint', 'import', 'jest'],
rules: {
'unicorn/prefer-top-level-await': 'off',
'unicorn/no-process-exit': 'off',
'@typescript-eslint/max-params': 'off',
'unicorn/prefer-top-level-await': 'off',

// Typescript
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-dynamic-delete': 'off',
'@typescript-eslint/consistent-return': 'off', // Does not play with no useless undefined when function return type is "T | undefined" and does not have a fixer.
'@typescript-eslint/max-params': 'off',
'@typescript-eslint/no-dynamic-delete': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/use-unknown-in-catch-callback-variable': 'off',

// Lodash
'lodash/prefer-immutable-method': 'off',
'lodash/prop-shorthand': 'off',

// Jest
'jest/no-hooks': 'off',
Expand Down
9 changes: 3 additions & 6 deletions src/gas-price/gas-price.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { go } from '@api3/promise-utils';
import type { ethers } from 'ethers';
import { remove } from 'lodash';
import { maxBy, remove } from 'lodash';

import { logger } from '../logger';
import { getState, updateState } from '../state';
Expand Down Expand Up @@ -117,7 +117,7 @@ export const fetchAndStoreGasPrice = async (
});
const gasPrice = goGasPrice.data;
if (!goGasPrice.success) {
if (!goGasPrice.success) logger.error('Failed to fetch gas price from RPC provider.', goGasPrice.error);
logger.error('Failed to fetch gas price from RPC provider.', goGasPrice.error);
return null;
}
if (!gasPrice) {
Expand Down Expand Up @@ -158,10 +158,7 @@ export const getRecommendedGasPrice = (chainId: string, providerName: string, sp
let latestGasPrice: bigint | undefined;
// Use the latest gas price that is stored in the state. We assume that the gas price is fetched frequently and has
// been fetched immediately before making this call. In case it fails, we fallback to the previously stored gas price.
if (gasPrices.length > 0) {
const lastSavedTimestamp = Math.max(...gasPrices.map((gasPrice) => gasPrice.timestamp));
latestGasPrice = gasPrices.find((gasPrice) => gasPrice.timestamp === lastSavedTimestamp)!.price;
}
if (gasPrices.length > 0) latestGasPrice = maxBy(gasPrices, (x) => x.timestamp)!.price;
if (!latestGasPrice) {
logger.warn('There is no gas price stored.');
return null;
Expand Down

0 comments on commit b312b1f

Please sign in to comment.