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

Fix custom gas price #566

Merged
merged 6 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 10 additions & 9 deletions app/components/UI/CustomGas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
getRenderableEthGasFee,
getRenderableFiatGasFee,
apiEstimateModifiedToWEI,
fetchBasicGasEstimates
fetchBasicGasEstimates,
convertApiValueToGWEI
} from '../../../util/custom-gas';
import { BN } from 'ethereumjs-util';
import { fromWei } from '../../../util/number';
Expand Down Expand Up @@ -120,7 +121,7 @@ class CustomGas extends Component {
selected: 'average',
ready: false,
advancedCustomGas: false,
customGasPrice: '20',
customGasPrice: '10',
customGasLimit: this.props.gas.toNumber().toString(),
warningGasLimit: '',
warningGasPrice: ''
Expand All @@ -134,7 +135,7 @@ class CustomGas extends Component {
gasAverageSelected: false,
gasSlowSelected: false,
selected: 'fast',
customGasPrice: fastGwei.toString()
customGasPrice: fastGwei
});
this.props.handleGasFeeSelection(gas, apiEstimateModifiedToWEI(fastGwei));
};
Expand All @@ -147,7 +148,7 @@ class CustomGas extends Component {
gasAverageSelected: true,
gasSlowSelected: false,
selected: 'average',
customGasPrice: averageGwei.toString()
customGasPrice: averageGwei
});
this.props.handleGasFeeSelection(gas, apiEstimateModifiedToWEI(averageGwei));
};
Expand All @@ -160,7 +161,7 @@ class CustomGas extends Component {
gasAverageSelected: false,
gasSlowSelected: true,
selected: 'slow',
customGasPrice: safeLowGwei.toString()
customGasPrice: safeLowGwei
});
this.props.handleGasFeeSelection(gas, apiEstimateModifiedToWEI(safeLowGwei));
};
Expand Down Expand Up @@ -197,9 +198,9 @@ class CustomGas extends Component {
const basicGasEstimates = await fetchBasicGasEstimates();
const { average, fast, safeLow } = basicGasEstimates;
this.setState({
averageGwei: average,
fastGwei: fast,
safeLowGwei: safeLow,
averageGwei: convertApiValueToGWEI(average),
fastGwei: convertApiValueToGWEI(fast),
safeLowGwei: convertApiValueToGWEI(safeLow),
ready: true
});
};
Expand Down Expand Up @@ -306,7 +307,7 @@ class CustomGas extends Component {
keyboardType="numeric"
style={styles.gasInput}
onChangeText={this.onGasPriceChange}
value={customGasPrice}
value={customGasPrice.toString()}
/>
<Text style={styles.text}>{warningGasPrice}</Text>
</View>
Expand Down
12 changes: 11 additions & 1 deletion app/util/custom-gas.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@ import { renderFromWei, weiToFiat } from './number';
*/
export function apiEstimateModifiedToWEI(estimate) {
const GWEIRate = 1000000000;
return new BN(((estimate * GWEIRate) / 10).toString(), 10);
return new BN((estimate * GWEIRate).toString(), 10);
}

/**
* Calculates GWEI value of estimate gas price from ethgasstation.info
*
* @param {number} val - Number corresponding to api gas price estimation
* @returns {string} - The GWEI value as a string
*/
export function convertApiValueToGWEI(val) {
return (parseInt(val, 10) / 10).toString();
}

/**
Expand Down