handle no timestamp available for project age
This commit is contained in:
parent
4f5d825157
commit
89b305540e
|
@ -12,8 +12,12 @@ import { getDelegatePledgesByProfile } from '../../actions/delegates'
|
||||||
|
|
||||||
async function getProjectAge(id, events, setState){
|
async function getProjectAge(id, events, setState){
|
||||||
const event = events.find(e => e.returnValues.idProject === id)
|
const event = events.find(e => e.returnValues.idProject === id)
|
||||||
|
if (event) {
|
||||||
const { timestamp } = await web3.eth.getBlock(event.blockNumber)
|
const { timestamp } = await web3.eth.getBlock(event.blockNumber)
|
||||||
setState(timeSinceBlock(timestamp, 'days'))
|
setState(timeSinceBlock(timestamp, 'days'))
|
||||||
|
} else {
|
||||||
|
setState(timeSinceBlock(false, 'days'))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getProjectAssets(projectId, setState){
|
async function getProjectAssets(projectId, setState){
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
export function timeSinceBlock(date, interval) {
|
export function timeSinceBlock(date=false, interval) {
|
||||||
var second=1000, minute=second*60, hour=minute*60, day=hour*24, week=day*7;
|
var second=1000, minute=second*60, hour=minute*60, day=hour*24, week=day*7;
|
||||||
let date1 = new Date(date*1000);
|
let date1 = date ? new Date(date*1000) : new Date();
|
||||||
let date2 = new Date();
|
let date2 = new Date();
|
||||||
var timediff = date2 - date1;
|
var timediff = date2 - date1;
|
||||||
if (isNaN(timediff)) return NaN;
|
if (isNaN(timediff)) return NaN;
|
||||||
|
|
Loading…
Reference in New Issue