diff --git a/src/components/projects/hooks.js b/src/components/projects/hooks.js index b3ccf4b..fede98f 100644 --- a/src/components/projects/hooks.js +++ b/src/components/projects/hooks.js @@ -12,8 +12,12 @@ import { getDelegatePledgesByProfile } from '../../actions/delegates' async function getProjectAge(id, events, setState){ const event = events.find(e => e.returnValues.idProject === id) - const { timestamp } = await web3.eth.getBlock(event.blockNumber) - setState(timeSinceBlock(timestamp, 'days')) + if (event) { + const { timestamp } = await web3.eth.getBlock(event.blockNumber) + setState(timeSinceBlock(timestamp, 'days')) + } else { + setState(timeSinceBlock(false, 'days')) + } } async function getProjectAssets(projectId, setState){ diff --git a/src/utils/dates.js b/src/utils/dates.js index 73a4571..0b2c6ce 100644 --- a/src/utils/dates.js +++ b/src/utils/dates.js @@ -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; - let date1 = new Date(date*1000); + let date1 = date ? new Date(date*1000) : new Date(); let date2 = new Date(); var timediff = date2 - date1; if (isNaN(timediff)) return NaN;