watch oracle changes

This commit is contained in:
Jonathan Rainville 2018-08-31 13:16:02 -04:00 committed by Iuri Matias
parent 3c046187a9
commit bfe17e1ad1
5 changed files with 35 additions and 21 deletions

View File

@ -22,6 +22,7 @@ class GasStation extends Component {
this.state = {
gasSliderIndex: 0,
gasOracleSliderIndex: 0,
copied: false
};
this.formattedGasStats = GasStation.formatGasStats(props.gasStats);
@ -51,9 +52,22 @@ class GasStation extends Component {
};
}
gasSliderChange(e) {
getGasOracleFormatted() {
const gasPrices = Object.keys(this.props.gasOracleStats);
if (!gasPrices.length) {
return [];
}
return gasPrices.map(gasPrice => {
return {
gasPrice: gasPrice,
wait: this.props.gasOracleStats[gasPrice].averageWait
};
});
}
gasSliderChange(e, name) {
this.setState({
gasSliderIndex: e.target.value
[name]: e.target.value
});
}
@ -79,6 +93,7 @@ class GasStation extends Component {
render() {
const currentGasStep = this.formattedGasStats.gasSteps[this.state.gasSliderIndex];
const formattedGasOracleStats = this.getGasOracleFormatted();
return <Grid.Row>
<Grid.Col>
<Card>
@ -114,10 +129,18 @@ class GasStation extends Component {
min={0}
step={1}
value={this.state.gasSliderIndex}
onChange={(e) => this.gasSliderChange(e)}
onChange={(e) => this.gasSliderChange(e, 'gasSliderIndex')}
/>
</Form.Group>
{formattedGasOracleStats.length > 0 &&
<input type="range" className="slider"
max={formattedGasOracleStats.length - 1}
min={0}
step={1}
value={this.state.gasOracleSliderIndex}
onChange={(e) => this.gasSliderChange(e, 'gasOracleSliderIndex')}
/>}
</Form.Group>
<Grid.Row cards={true}>
<Grid.Col lg={4} md={6} sm={12}>

View File

@ -89,7 +89,10 @@ export function getGasStats(state) {
}
export function getOracleGasStats(state) {
return state.entities.gasOracleStats;
if (!state.entities.gasOracleStats.length) {
return {};
}
return state.entities.gasOracleStats[0];
}
export function isWeb3Enabled(state) {

View File

@ -96,7 +96,6 @@ class BlockchainConnector {
self.isWeb3Ready = true;
self.events.emit(WEB3_READY);
self.registerWeb3Object();
self.subscribeToNewBlockHeaders();
});
});
});
@ -265,7 +264,7 @@ class BlockchainConnector {
'ws',
'/embark-api/blockchain/blockHeader',
(ws) => {
self.events.on('blockchain:newBlockHeaders', (block) => {
self.events.on('block:header', (block) => {
ws.send(JSON.stringify({block: block}), () => {});
});
}
@ -394,18 +393,6 @@ class BlockchainConnector {
});
}
subscribeToNewBlockHeaders() {
let self = this;
self.web3.eth.subscribe("newBlockHeaders", (err) => {
if (err) {
self.logger.error(err.message);
}
}).on("data", (block) => {
self.events.emit("blockchain:newBlockHeaders", block);
});
}
defaultAccount() {
return this.web3.eth.defaultAccount;
}

View File

@ -10,8 +10,8 @@ class TransactionTracker {
this.registerAPICalls();
}
onPendingTransaction(pendingTransaction) {
this.transactions[pendingTransaction] = {
onPendingTransaction(pendingTransactionHash) {
this.transactions[pendingTransactionHash] = {
startTimestamp: Date.now() / 1000
};
}

View File

@ -7,6 +7,7 @@ const AccountParser = require('../utils/accountParser');
// TODO: breaks module isolation; tests need to be refactored to use the engine and avoid this
const Provider = require('../modules/blockchain_connector/provider.js');
const utils = require('../utils/utils');
const cloneDeep = require('clone-deep');
const EmbarkJS = require('embarkjs');