Skip to content
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

Improvement/gas estimations #2083

Merged
merged 6 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 34 additions & 57 deletions app/components/UI/CustomGas/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ exports[`CustomGas should render correctly 1`] = `
Array [
Object {
"alignSelf": "center",
"height": "100%",
"paddingTop": 24,
"position": "absolute",
"width": "100%",
Expand Down Expand Up @@ -212,24 +211,17 @@ exports[`CustomGas should render correctly 1`] = `
</View>
<Text
style={
Object {
"color": "#000000",
"fontFamily": "EuclidCircularB-Bold",
"fontSize": 18,
"fontWeight": "600",
"marginVertical": 4,
"textTransform": "none",
}
}
/>
<Text
style={
Object {
"color": "#000000",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 10,
"fontWeight": "400",
}
Array [
Object {
"color": "#000000",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 10,
"fontWeight": "400",
},
Object {
"fontSize": 12,
},
]
}
>
0
Expand Down Expand Up @@ -308,24 +300,17 @@ exports[`CustomGas should render correctly 1`] = `
</View>
<Text
style={
Object {
"color": "#000000",
"fontFamily": "EuclidCircularB-Bold",
"fontSize": 18,
"fontWeight": "600",
"marginVertical": 4,
"textTransform": "none",
}
}
/>
<Text
style={
Object {
"color": "#000000",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 10,
"fontWeight": "400",
}
Array [
Object {
"color": "#000000",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 10,
"fontWeight": "400",
},
Object {
"fontSize": 12,
},
]
}
>
0
Expand Down Expand Up @@ -404,24 +389,17 @@ exports[`CustomGas should render correctly 1`] = `
</View>
<Text
style={
Object {
"color": "#000000",
"fontFamily": "EuclidCircularB-Bold",
"fontSize": 18,
"fontWeight": "600",
"marginVertical": 4,
"textTransform": "none",
}
}
/>
<Text
style={
Object {
"color": "#000000",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 10,
"fontWeight": "400",
}
Array [
Object {
"color": "#000000",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 10,
"fontWeight": "400",
},
Object {
"fontSize": 12,
},
]
}
>
0
Expand Down Expand Up @@ -449,11 +427,10 @@ exports[`CustomGas should render correctly 1`] = `
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 12,
"fontWeight": "400",
"paddingBottom": 20,
}
}
>
Select the network fee you are willing to pay. The higher the fee, the better chances and faster your transaction will go through.
The network fee covers the cost of processing your transaction on the Ethereum network. MetaMask does not profit from this fee. The higher the fee the better chances of your transaction getting processed.
</Text>
</ForwardRef(AnimatedComponentWrapper)>
<ForwardRef(AnimatedComponentWrapper)
Expand Down
26 changes: 8 additions & 18 deletions app/components/UI/CustomGas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,14 @@ const styles = StyleSheet.create({
message: {
...fontStyles.normal,
color: colors.black,
fontSize: 12,
paddingBottom: 20
fontSize: 12
},
warningWrapper: {
height: 50,
alignItems: 'center',
justifyContent: 'center',
alignSelf: 'center',
width: '100%',
// position: 'absolute',
marginVertical: 24
},
warningTextWrapper: {
Expand Down Expand Up @@ -103,7 +101,6 @@ const styles = StyleSheet.create({
position: 'absolute',
alignSelf: 'center',
width: '100%',
height: '100%',
paddingTop: 24
},
selectors: {
Expand Down Expand Up @@ -141,18 +138,14 @@ const styles = StyleSheet.create({
fontSize: 10,
color: colors.black
},
textGasFee: {
fontSize: 12
},
textTitle: {
...fontStyles.bold,
fontSize: 10,
color: colors.black
},
textTime: {
...fontStyles.bold,
color: colors.black,
marginVertical: 4,
fontSize: 18,
textTransform: 'none'
},
advancedOptionsContainer: {
flexDirection: 'column',
justifyContent: 'center',
Expand Down Expand Up @@ -481,7 +474,7 @@ class CustomGas extends PureComponent {
gas,
generateTransform,
hideGasSelectors,
basicGasEstimates: { averageGwei, fastGwei, safeLowGwei, averageWait, safeLowWait, fastWait }
basicGasEstimates: { averageGwei, fastGwei, safeLowGwei }
} = this.props;
const ticker = getTicker(this.props.ticker);
const topOffset = { top: headerHeight };
Expand Down Expand Up @@ -509,8 +502,7 @@ class CustomGas extends PureComponent {
<Radio selected={gasSlowSelected} />
</View>
</View>
<Text style={styles.textTime}>{safeLowWait}</Text>
<Text style={styles.text}>
<Text style={[styles.text, styles.textGasFee]}>
{getRenderableEthGasFee(safeLowGwei, gas)} {ticker}
</Text>
<Text style={styles.text}>
Expand All @@ -528,8 +520,7 @@ class CustomGas extends PureComponent {
<Radio selected={gasAverageSelected} />
</View>
</View>
<Text style={styles.textTime}>{averageWait}</Text>
<Text style={styles.text}>
<Text style={[styles.text, styles.textGasFee]}>
{getRenderableEthGasFee(averageGwei, gas)} {ticker}
</Text>
<Text style={styles.text}>
Expand All @@ -547,8 +538,7 @@ class CustomGas extends PureComponent {
<Radio selected={gasFastSelected} />
</View>
</View>
<Text style={styles.textTime}>{fastWait}</Text>
<Text style={styles.text}>
<Text style={[styles.text, styles.textGasFee]}>
{getRenderableEthGasFee(fastGwei, gas)} {ticker}
</Text>
<Text style={styles.text}>
Expand Down
55 changes: 12 additions & 43 deletions app/util/custom-gas.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function apiEstimateModifiedToWEI(estimate) {
* @returns {string} - The GWEI value as a string
*/
export function convertApiValueToGWEI(val) {
return (parseInt(val, 10) / 10).toString();
return parseInt(val, 10).toString();
}

/**
Expand Down Expand Up @@ -103,46 +103,22 @@ export function parseWaitTime(min) {
* @returns {Object} - Object containing basic estimates
*/
export async function fetchBasicGasEstimates() {
const apiKey = process.env.ETH_GAS_STATION_API_KEY ? `?api-key=${process.env.ETH_GAS_STATION_API_KEY}` : '';
return await fetch(`https://ethgasstation.info/api/ethgasAPI.json${apiKey}`, {
return await fetch(`https://api.metaswap.codefi.network/gasPrices`, {
headers: {},
referrer: 'http://ethgasstation.info/json/',
referrerPolicy: 'no-referrer-when-downgrade',
body: null,
method: 'GET',
mode: 'cors'
})
.then(r => r.json())
.then(
({
average,
avgWait,
block_time: blockTime,
blockNum,
fast,
fastest,
fastestWait,
fastWait,
safeLow,
safeLowWait,
speed
}) => {
const basicEstimates = {
average,
averageWait: avgWait,
blockTime,
blockNum,
fast,
fastest,
fastestWait,
fastWait,
safeLow,
safeLowWait,
speed
};
return basicEstimates;
}
);
.then(({ SafeGasPrice, ProposeGasPrice, FastGasPrice }) => {
const basicEstimates = {
average: ProposeGasPrice,
safeLow: SafeGasPrice,
fast: FastGasPrice
};
return basicEstimates;
});
}

/**
Expand All @@ -162,17 +138,13 @@ export async function getBasicGasEstimates() {
Logger.log('Error while trying to get gas limit estimates', error);
basicGasEstimates = {
average: AVERAGE_GAS,
averageWait: 2,
safeLow: LOW_GAS,
safeLowWait: 4,
fast: FAST_GAS,
fastWait: 1
fast: FAST_GAS
};
}

// Handle api failure returning same gas prices
let { average, fast, safeLow } = basicGasEstimates;
const { averageWait, fastWait, safeLowWait } = basicGasEstimates;

if (average === fast && average === safeLow) {
average = AVERAGE_GAS;
Expand All @@ -183,9 +155,6 @@ export async function getBasicGasEstimates() {
return {
averageGwei: convertApiValueToGWEI(average),
fastGwei: convertApiValueToGWEI(fast),
safeLowGwei: convertApiValueToGWEI(safeLow),
averageWait: parseWaitTime(averageWait),
fastWait: parseWaitTime(fastWait),
safeLowWait: parseWaitTime(safeLowWait)
safeLowGwei: convertApiValueToGWEI(safeLow)
};
}
2 changes: 1 addition & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@
"gas_price": "Gas Price: (GWEI)",
"save": "Save",
"warning_gas_limit": "Gas limit must be greater than 20999 and less than 7920027",
"cost_explanation": "Select the network fee you are willing to pay. The higher the fee, the better chances and faster your transaction will go through."
"cost_explanation": "The network fee covers the cost of processing your transaction on the Ethereum network. MetaMask does not profit from this fee. The higher the fee the better chances of your transaction getting processed."
},
"spend_limit_edition": {
"save": "Save",
Expand Down
2 changes: 1 addition & 1 deletion locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@
"gas_limit": "Límite de Gas:",
"gas_price": "Precio de Gas: (GWEI)",
"warning_gas_limit": "Límite de gas debe ser mayor a 20999 y menor que 7920027",
"cost_explanation": "Este es el costo por procesar este pago en la blockchain."
"cost_explanation": "La tarifa de la red cubre el costo de procesar tu transacción en la red Ethereum. MetaMask no se beneficia de esta tarifa. Cuanto mayor sea la tarifa, mayores serán las posibilidades de que se procese tu transacción."
},
"spend_limit_edition": {
"save": "Guardar",
Expand Down