forked from bitshares/bitshares-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bitshares#670: Display dates instead of block numbers in market h…
…istory
- Loading branch information
Showing
6 changed files
with
80 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from "react"; | ||
import counterpart from "counterpart"; | ||
import {connect} from "alt-react"; | ||
import BlockchainStore from "stores/BlockchainStore"; | ||
import BlockchainActions from "actions/BlockchainActions"; | ||
import ReactTooltip from "react-tooltip"; | ||
|
||
/** | ||
* @brief displays block's date and time based on block number | ||
* | ||
* properties: block - number | ||
* Note, it doesn't fetch block, just calculates time based on number alone. | ||
**/ | ||
|
||
class BlockDate extends React.Component { | ||
|
||
static defaultProps = { | ||
format: "market_history", | ||
tooltip: false, | ||
component: "span" | ||
} | ||
|
||
componentWillMount() { | ||
BlockchainActions.getBlock.defer(this.props.block_number); | ||
} | ||
|
||
shouldComponentUpdate(np) { | ||
if (np.block && !this.props.block) setTimeout(ReactTooltip.rebuild, 1000); | ||
return np.block !== this.props.block; | ||
} | ||
|
||
render() { | ||
const {block, tooltip, component, format} = this.props; | ||
|
||
if (!block) return React.createElement(component); | ||
return ( | ||
React.createElement(component, {className: tooltip ? "tooltip": "", "data-tip": tooltip ? block.timestamp : ""}, | ||
<span> | ||
{counterpart.localize(block.timestamp, {type: "date", format})} | ||
</span> | ||
) | ||
); | ||
} | ||
} | ||
|
||
BlockDate = connect(BlockDate, { | ||
listenTo() { | ||
return [BlockchainStore]; | ||
}, | ||
getProps(props) { | ||
return { | ||
block: BlockchainStore.getState().blocks.get(props.block_number) | ||
}; | ||
} | ||
}); | ||
|
||
export default BlockDate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters