Skip to content

Commit

Permalink
Added formatTime to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
macterra committed Oct 27, 2023
1 parent cc8593f commit c46617d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion frontend/src/AuditLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
TableHead,
Paper,
} from '@mui/material';
import utils from './utils';

const AuditLog = () => {
const [txnlog, setTxnLog] = useState([]);
Expand Down Expand Up @@ -37,7 +38,7 @@ const AuditLog = () => {
useEffect(() => {
const fetchInfo = async () => {
setMessage(`unknown type: ${record.type}`);
setTime(record.time);
setTime(utils.formatTime(record.time));

if (record.type === 'sale') {
const amount = record.invoice?.amount || record.charge?.amount;
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/TokenHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Paper,
} from '@mui/material';
import AgentBadge from './AgentBadge';
import utils from './utils';

const TokenHistory = ({ metadata, xid }) => {
const [history, setHistory] = useState([]);
Expand Down Expand Up @@ -37,7 +38,7 @@ const TokenHistory = ({ metadata, xid }) => {
useEffect(() => {
const fetchInfo = async () => {
setMessage(`unknown record type ${record.type}`);
setTime(record.time);
setTime(utils.formatTime(record.time));

if (record.type === 'mint') {
if (metadata.token) {
Expand Down
8 changes: 1 addition & 7 deletions frontend/src/TxnLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
TableHead,
Paper,
} from '@mui/material';
import { format } from 'date-fns';
import utils from './utils';

const TxnLog = ({ profile, refreshProfile }) => {
Expand Down Expand Up @@ -87,11 +86,6 @@ const TxnLog = ({ profile, refreshProfile }) => {
return getObject(xid, `/api/v1/profile/${xid}`);
}

function formatTime(timestamp) {
const date = new Date(timestamp);
return format(date, "yyyy-MM-dd HH:mm:ss");
}

function HistoryRow({ record }) {
const [time, setTime] = useState("");
const [message, setMessage] = useState(null);
Expand All @@ -101,7 +95,7 @@ const TxnLog = ({ profile, refreshProfile }) => {
useEffect(() => {
const fetchInfo = async () => {
setMessage(`Unknown record type ${record.type}`);
setTime(formatTime(record.time));
setTime(utils.formatTime(record.time));

if (record.type === 'credits') {
setMessage(`Traded sats for credits.`);
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { format } = require('date-fns');

function truncateTitle(title, max = 25) {
if (title.length > max) {
return title.substring(0, max - 3) + '...';
Expand All @@ -7,6 +9,12 @@ function truncateTitle(title, max = 25) {
}
}

function formatTime(timestamp) {
const date = new Date(timestamp);
return format(date, "yyyy-MM-dd HH:mm:ss");
}

module.exports = {
formatTime,
truncateTitle,
};

0 comments on commit c46617d

Please sign in to comment.