on master help sign in
gas: replace deprecated TX wait estimate API

This resolves #1077. As of 12/12/2022, ETHGasStation is sunsetting: https://twitter.com/ETHGasStation/status/1597341610777317376 This change replaces the API call with another provider.

commit2cab26937c213291631b19f1a85324030aed7404 authortomholford <tomholford@users.noreply.github.com> dateMon 12 Dec 2022, 14:52 (4 years ago) parent85f8acf
2 files changed+20−19
src/components/L2/Dropdowns/FeeDropdown.tsx+2−1 src/lib/getSuggestedGasPrice.js+18−18
src/components/L2/Dropdowns/FeeDropdown.tsx+2−1
@@ -17,7 +17,8 @@ export interface GasPriceData {
1717 suggestedBaseFeePerGas: number;
1818}
1919
20−export const formatWait = (wait: number) => Math.round(wait * 100) / 100;
20+// Convert seconds to minutes prettily
21+export const formatWait = (wait: number) => Math.round((wait * 100) / 60) / 100;
2122export const formatDisplay = ({ price, wait }: GasPriceData) =>
2223 `${price} gwei (${wait} min)`;
2324
src/lib/getSuggestedGasPrice.js+18−18
@@ -40,7 +40,7 @@ export const defaultGasValues = value => ({
4040
4141const getGasForNetwork = async (providerUrl) => {
4242 try {
43− const [etherscanGas, ethgasstationGas] = await Promise.all([
43+ const [feeResponse, waitResponse] = await Promise.all([
4444 fetch(
4545 `${providerUrl}/api` +
4646 '?module=gastracker' +
@@ -52,7 +52,7 @@ const getGasForNetwork = async (providerUrl) => {
5252 }
5353 ),
5454 fetch(
55− 'https://ethgasstation.info/json/ethgasAPI.json',
55+ 'https://ethereum-api.xyz/gas-prices',
5656 {
5757 method: 'GET',
5858 cache: 'no-cache',
@@ -60,35 +60,35 @@ const getGasForNetwork = async (providerUrl) => {
6060 )
6161 ]);
6262
63− const [etherscanGasJson, ethgasstationGasJson] = await Promise.all([
64− etherscanGas.json(),
65− ethgasstationGas.json()
63+ const [feeJson, waitJson] = await Promise.all([
64+ feeResponse.json(),
65+ waitResponse.json()
6666 ])
6767
68− const suggestedBaseFeePerGas = Number(etherscanGasJson.result.suggestBaseFee);
68+ const suggestedBaseFeePerGas = Number(feeJson.result.suggestBaseFee);
6969
7070 // Calculations derived from:
7171 // https://www.blocknative.com/blog/eip-1559-fees
7272 return {
7373 fast: {
74− price: minGas(etherscanGasJson.result.FastGasPrice),
75− wait: formatWait(ethgasstationGasJson.fastWait),
76− maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, etherscanGasJson.result.FastGasPrice - suggestedBaseFeePerGas),
77− maxPriorityFeePerGas: feeToInt((etherscanGasJson.result.FastGasPrice - suggestedBaseFeePerGas)),
74+ price: minGas(feeJson.result.FastGasPrice),
75+ wait: formatWait(waitJson.result.fast.time),
76+ maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, feeJson.result.FastGasPrice - suggestedBaseFeePerGas),
77+ maxPriorityFeePerGas: feeToInt((feeJson.result.FastGasPrice - suggestedBaseFeePerGas)),
7878 suggestedBaseFeePerGas
7979 },
8080 average: {
81− price: minGas(etherscanGasJson.result.ProposeGasPrice),
82− wait: formatWait(ethgasstationGasJson.avgWait),
83− maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, etherscanGasJson.result.ProposeGasPrice - suggestedBaseFeePerGas),
84− maxPriorityFeePerGas: feeToInt((etherscanGasJson.result.ProposeGasPrice - suggestedBaseFeePerGas)),
81+ price: minGas(feeJson.result.ProposeGasPrice),
82+ wait: formatWait(waitJson.result.average.time),
83+ maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, feeJson.result.ProposeGasPrice - suggestedBaseFeePerGas),
84+ maxPriorityFeePerGas: feeToInt((feeJson.result.ProposeGasPrice - suggestedBaseFeePerGas)),
8585 suggestedBaseFeePerGas
8686 },
8787 low: {
88− price: minGas(etherscanGasJson.result.SafeGasPrice),
89− wait: formatWait(ethgasstationGasJson.safeLowWait),
90− maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, etherscanGasJson.result.SafeGasPrice - suggestedBaseFeePerGas),
91− maxPriorityFeePerGas: feeToInt((etherscanGasJson.result.SafeGasPrice - suggestedBaseFeePerGas)),
88+ price: minGas(feeJson.result.SafeGasPrice),
89+ wait: formatWait(waitJson.result.slow.time),
90+ maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, feeJson.result.SafeGasPrice - suggestedBaseFeePerGas),
91+ maxPriorityFeePerGas: feeToInt((feeJson.result.SafeGasPrice - suggestedBaseFeePerGas)),
9292 suggestedBaseFeePerGas
9393 },
9494 };