Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
PR grumble // Gas Price Selector (#2898)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngotchac committed Nov 1, 2016
1 parent 1fdcf70 commit 43dc939
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
6 changes: 2 additions & 4 deletions js/src/modals/Transfer/Extras/extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,9 @@ export default class Extras extends Component {
</div>

<div>
<p>
<p className={ styles.gasPriceDesc }>
You can choose the gas price based on the
distribution of recent <b>included</b> transactions' gas prices.
</p>
<p>
distribution of recent included transactions' gas prices.
The lower the gas price is, the cheaper the transaction will
be. The higher the gas price is, the faster it should
get mined by the network.
Expand Down
28 changes: 17 additions & 11 deletions js/src/modals/Transfer/GasPriceSelector/gasPriceSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ const COLORS = {
intersection: '#fff'
};

const countModifier = (count) => {
const val = count.toNumber ? count.toNumber() : count;
return Math.log10(val + 1) + 0.1;
};

class CustomCursor extends Component {
static propTypes = {
x: PropTypes.number,
Expand All @@ -64,7 +69,7 @@ class CustomCursor extends Component {
return null;
}

const count = counts[index].toNumber() + 1;
const count = countModifier(counts[index]);
const barHeight = (count / yDomain[1]) * (y + height);

return (
Expand Down Expand Up @@ -307,9 +312,9 @@ export default class GasPriceSelector extends Component {
return null;
}

const height = 350;
const height = 300;
const countIndex = Math.max(0, Math.min(selectedIndex, gasPriceHistogram.counts.length - 1));
const selectedCount = gasPriceHistogram.counts[countIndex];
const selectedCount = countModifier(gasPriceHistogram.counts[countIndex]);

return (<div className={ styles.columns }>
<div style={ { flex: 1, height } }>
Expand All @@ -323,10 +328,10 @@ export default class GasPriceSelector extends Component {
<Scatter
data={ [
{ x: sliderValue, y: 0 },
{ x: sliderValue, y: selectedCount.toNumber() + 1 },
{ x: sliderValue, y: selectedCount },
{ x: sliderValue, y: chartData.yDomain[1] }
] }
shape={ <CustomizedShape showValue={ selectedCount.toNumber() + 1 } /> }
shape={ <CustomizedShape showValue={ selectedCount } /> }
line
isAnimationActive={ false }
/>
Expand Down Expand Up @@ -424,13 +429,14 @@ export default class GasPriceSelector extends Component {
.map((value, index) => ({ value, index }));

const N = values.length - 1;
const maxGasCounts = gasPriceHistogram
.counts
.reduce((max, count) => count.greaterThan(max) ? count : max, 0)
.toNumber();
const maxGasCounts = countModifier(
gasPriceHistogram
.counts
.reduce((max, count) => count.greaterThan(max) ? count : max, 0)
);

const xDomain = [0, N];
const yDomain = [0, (maxGasCounts + 1) * 1.2];
const yDomain = [0, maxGasCounts * 1.1];

const chartData = {
values, N,
Expand All @@ -447,7 +453,7 @@ export default class GasPriceSelector extends Component {

const gasPriceChartData = gasPriceHistogram
.counts
.map(count => count.toNumber() + 1);
.map(count => countModifier(count));

this.setState(
{ gasPriceChartData },
Expand Down
4 changes: 4 additions & 0 deletions js/src/modals/Transfer/transfer.css
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,7 @@
position: absolute;
width: 100%;
}

.gasPriceDesc {
font-size: 0.9em;
}

0 comments on commit 43dc939

Please sign in to comment.