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

feat: add toggle switch between time ago and utc time #366

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

<style>
.table-head-col {
@apply whitespace-nowrap px-2 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-700 first:pl-6 last:pr-6;
@apply whitespace-nowrap px-2 py-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-700 first:pl-6 last:pr-6;
}
</style>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="info-field-time" :title="utcStringFromISOString(isoString)">
<span class="time-ago">
{{ timeAgo }}
{{ isUtcDate ? localDateFromISOString(isoString) : timeAgo }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need it and not simply use showExactDate flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

showExactDate is used for showing the full date next to the "time ago", and it's set as false in all component except the transaction view, one example here: https://sepolia.explorer.zksync.io/tx/0x578366ab5db0538dcab887a1bdd6aeb82dc45e822acf280230d3c5e6dd64023f
Screenshot 2025-01-16 at 14 11 52

I could refactor it, or rename the variables to make it more clear? To rename it to something like "showBothDates" instead of just "showExactDate", and use that name instead of isUtcDate check?

</span>
<span v-if="showExactDate" class="full-date">{{ localDateFromISOString(isoString) }}</span>
</div>
Expand All @@ -28,6 +28,11 @@ const props = defineProps({
default: true,
required: false,
},
isUtcDate: {
type: Boolean,
default: false,
required: false,
},
});

const messages = ref({
Expand Down
21 changes: 18 additions & 3 deletions packages/app/src/components/transactions/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
<TableHeadColumn v-if="columns.includes('method')">
{{ t("transactions.table.method") }}
</TableHeadColumn>
<TableHeadColumn v-if="columns.includes('age')">
{{ t("transactions.table.age") }}
<TableHeadColumn
v-if="columns.includes('age')"
@click="toggleAgeTimestamp()"
class="hover:cursor-pointer text-blue-700"
>
{{ isTimeAgeView ? t("transactions.table.age") : t("transactions.table.dateTimeUTC") }}
</TableHeadColumn>
<TableHeadColumn v-if="columns.includes('from')" class="tablet-column-hidden">
{{ t("transactions.table.from") }}
Expand Down Expand Up @@ -71,7 +75,12 @@
:data-heading="t('transactions.table.age')"
>
<CopyButton :value="utcStringFromISOString(item.receivedAt)">
<TimeField :value="item.receivedAt" :show-exact-date="false" :data-testid="$testId.timestamp" />
<TimeField
:value="item.receivedAt"
:show-exact-date="false"
:data-testid="$testId.timestamp"
:is-utc-date="!isTimeAgeView"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need it and not simply use showExactDate flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Explained in the comment above

/>
</CopyButton>
</TableBodyColumn>
<TableBodyColumn
Expand Down Expand Up @@ -364,6 +373,12 @@ const isHighRowsSize = computed(() => props.columns.includes("fee"));
function getDirection(item: TransactionListItem): Direction {
return item.from === item.to ? "self" : item.to !== props.searchParams?.address ? "out" : "in";
}

const isTimeAgeView = ref(true);

const toggleAgeTimestamp = () => {
isTimeAgeView.value = !isTimeAgeView.value;
};
</script>

<style lang="scss">
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
"transferMethodName": "Transfer",
"timestamp": "Timestamp",
"age": "Age",
"dateTimeUTC": "Date Time (UTC)",
"tokenAddress": "Token address",
"tokenName": "Token name",
"tokenSymbol": "Token symbol",
Expand Down
Loading