if (props.now) { return "now"; } const keyPath = props.keyPath; let blockHeight = props.blockHeight ? parseInt(props.blockHeight) : undefined; if (blockHeight === undefined && keyPath) { blockHeight = Social.keys(keyPath, undefined, { return_type: "BlockHeight", }); if (blockHeight === null) { return "Loading"; } keyPath.split("/").forEach((key) => { blockHeight = blockHeight[key]; }); } if (!blockHeight) { return "unknown"; } const res = fetch(`https://api.near.social/time?blockHeight=${blockHeight}`); if (!res) { return "Loading"; } if (!res.ok || res.body === "null") { return "unknown"; } const timeMs = parseFloat(res.body); const timeAgo = (diffSec) => diffSec < 60000 ? `${(diffSec / 1000) | 0} seconds ago` : diffSec < 3600000 ? `${(diffSec / 60000) | 0} minutes ago` : diffSec < 86400000 ? `${(diffSec / 3600000) | 0} hours ago` : `${(diffSec / 86400000) | 0} days ago`; return timeAgo(Date.now() - timeMs);