Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: time ago refresh #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/components/TransactionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function getDirection(walletId: string, details?: ITransactionDetails) {

export const TransactionRow: React.FC<IProps> = ({ tx }) => {
const { walletId, cancelTransaction, signTransaction } = useAppStore();
const [ time, setTime ] = React.useState(Date.now());
const isMountedRef = React.useRef<boolean>(false);
const [inProgress, setInProgress] = React.useState<boolean>(false);
const [isSdkCompletedSigning, setSdkCompletedSigning] = React.useState<boolean>(false);
Expand All @@ -138,6 +139,14 @@ export const TransactionRow: React.FC<IProps> = ({ tx }) => {
};
}, []);

// update "time ago" every 5 secs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this useEffect?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without it, the state doesn't get updated and there's no re-render of the row, maybe it needs to be 1 level outside in the container and not per row?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so maybe create a TimeAgo component that gets a timestamp and does the useEffect internally. or install https://www.npmjs.com/package/react-time-ago

React.useEffect(() => {
const interval = setInterval(() => setTime(Date.now()), 5_000);
return () => {
clearInterval(interval);
}
}, [])

const onSignTransactionClicked = async (txId: string) => {
setInProgress(true);
try {
Expand Down Expand Up @@ -182,7 +191,7 @@ export const TransactionRow: React.FC<IProps> = ({ tx }) => {
<Copyable value={tx.id} />
</>
</td>
<td className="px-1">{formatTimeAgo(new Date(tx.createdAt!))}</td>
<td className="px-1">{formatTimeAgo(new Date(tx.lastUpdated!))}</td>
<td className="px-1">{tx.details?.assetId}</td>
<td className="px-1">
<div className="flex gap-1 items-center">
Expand Down