diff --git a/package-lock.json b/package-lock.json index 8f3a5390..7854ebb7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.2", "license": "Apache-2.0", "dependencies": { - "@covalenthq/client-sdk": "^2.1.1", + "@covalenthq/client-sdk": "^2.1.2", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", @@ -955,9 +955,10 @@ "dev": true }, "node_modules/@covalenthq/client-sdk": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/@covalenthq/client-sdk/-/client-sdk-2.1.1.tgz", - "integrity": "sha512-wrtb6sn5cUOTOTD+GbE1Xi92b2Q2Wd76roK2wwUMdbOQ591ucahgSPfaJEgZY29nocLc3wDV2vhR11fNX8nZxA==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@covalenthq/client-sdk/-/client-sdk-2.1.2.tgz", + "integrity": "sha512-PoWCTm2gp7sq19KBoTmpI3hKS52HW0gbBlHn8TM9XbBedaDFOEZG3rf3Pzhl0njFqQ1ikrU3vGOBE2/s9INUkQ==", + "license": "Apache-2.0", "dependencies": { "big.js": "^6.2.1" } diff --git a/package.json b/package.json index c7b846ff..38e49295 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,7 @@ "vite-plugin-dts": "^3.8.2" }, "dependencies": { - "@covalenthq/client-sdk": "^2.1.1", + "@covalenthq/client-sdk": "^2.1.2", "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", diff --git a/src/components/Atoms/Timestamp/Timestamp.tsx b/src/components/Atoms/Timestamp/Timestamp.tsx index ebb6e8d8..64a4732e 100644 --- a/src/components/Atoms/Timestamp/Timestamp.tsx +++ b/src/components/Atoms/Timestamp/Timestamp.tsx @@ -1,5 +1,5 @@ -import { timestampParser } from "@/utils/functions"; import { type TimestampProps } from "@/utils/types/atoms.types"; +import { timestampParser } from "@covalenthq/client-sdk"; import { ClockIcon } from "@radix-ui/react-icons"; import { useCallback, useEffect, useState } from "react"; diff --git a/src/components/Molecules/Block/BlocksList/BlocksList.tsx b/src/components/Molecules/Block/BlocksList/BlocksList.tsx index 1ca44ebf..904bbce1 100644 --- a/src/components/Molecules/Block/BlocksList/BlocksList.tsx +++ b/src/components/Molecules/Block/BlocksList/BlocksList.tsx @@ -5,14 +5,15 @@ import { DEFAULT_ERROR_MESSAGE, FALLBACK_ERROR, } from "@/utils/constants/shared.constants"; -import { actionableWrapper, timestampParser } from "@/utils/functions"; +import { actionableWrapper } from "@/utils/functions"; import { None, Some, type Option } from "@/utils/option"; import { useGoldRush } from "@/utils/store"; import { type BlocksListProps } from "@/utils/types/molecules.types"; -import type { - Block, - Pagination, - GoldRushResponse, +import { + type Block, + type Pagination, + type GoldRushResponse, + timestampParser, } from "@covalenthq/client-sdk"; import { type ColumnDef } from "@tanstack/react-table"; import { useCallback, useEffect, useState } from "react"; diff --git a/src/components/Molecules/Block/LatestBlocks/LatestBlocks.tsx b/src/components/Molecules/Block/LatestBlocks/LatestBlocks.tsx index 019578e9..8aa1b779 100644 --- a/src/components/Molecules/Block/LatestBlocks/LatestBlocks.tsx +++ b/src/components/Molecules/Block/LatestBlocks/LatestBlocks.tsx @@ -7,11 +7,15 @@ import { DEFAULT_ERROR_MESSAGE, FALLBACK_ERROR, } from "@/utils/constants/shared.constants"; -import { actionableWrapper, timestampParser } from "@/utils/functions"; +import { actionableWrapper } from "@/utils/functions"; import { None, Some, type Option } from "@/utils/option"; import { useGoldRush } from "@/utils/store"; import { type LatestBlocksProps } from "@/utils/types/molecules.types"; -import type { GoldRushResponse, Block } from "@covalenthq/client-sdk"; +import { + type GoldRushResponse, + type Block, + timestampParser, +} from "@covalenthq/client-sdk"; import { useEffect, useState } from "react"; export const LatestBlocks: React.FC = ({ diff --git a/src/components/Molecules/Transaction/TransactionsList/TransactionsList.tsx b/src/components/Molecules/Transaction/TransactionsList/TransactionsList.tsx index 944ed1ca..497bc327 100644 --- a/src/components/Molecules/Transaction/TransactionsList/TransactionsList.tsx +++ b/src/components/Molecules/Transaction/TransactionsList/TransactionsList.tsx @@ -4,7 +4,7 @@ import { DEFAULT_ERROR_MESSAGE, FALLBACK_ERROR, } from "@/utils/constants/shared.constants"; -import { actionableWrapper, timestampParser } from "@/utils/functions"; +import { actionableWrapper } from "@/utils/functions"; import { None, Some, type Option } from "@/utils/option"; import { useGoldRush } from "@/utils/store"; import { type TransactionsListProps } from "@/utils/types/molecules.types"; @@ -12,6 +12,7 @@ import { calculatePrettyBalance, type Transaction, type GoldRushResponse, + timestampParser, } from "@covalenthq/client-sdk"; import { type ColumnDef } from "@tanstack/react-table"; import { useEffect, useState } from "react"; diff --git a/src/utils/functions/index.ts b/src/utils/functions/index.ts index 78704fd7..602a6efd 100644 --- a/src/utils/functions/index.ts +++ b/src/utils/functions/index.ts @@ -6,5 +6,4 @@ export { primaryShades } from "./primary-shades"; export { storyAction } from "./story-action"; export { stringToColor } from "./string-to-color"; export { themedSvg } from "./themed-svg"; -export { timestampParser } from "./timestamp-parser"; export { truncate } from "./truncate"; diff --git a/src/utils/functions/timestamp-parser.ts b/src/utils/functions/timestamp-parser.ts deleted file mode 100644 index a265f92f..00000000 --- a/src/utils/functions/timestamp-parser.ts +++ /dev/null @@ -1,104 +0,0 @@ -const months: string[] = [ - "January", - "February", - "March", - "April", - "May", - "June", - "July", - "August", - "September", - "October", - "November", - "December", -]; - -export const timestampParser = ( - timestamp: string | Date, - type: "descriptive" | "DD MMM YY" | "relative" | "YYYY MM DD", -): string => { - const _unix: Date = new Date(timestamp); - - switch (type) { - case "descriptive": { - const _minutes = _unix.getMinutes(); - const _hours = _unix.getHours(); - const _seconds = _unix.getSeconds(); - const _parsedSeconds: string = `${ - _seconds <= 9 ? "0" : "" - }${_seconds}`; - const _parsedMinutes: string = `${ - _minutes <= 9 ? "0" : "" - }${_minutes}`; - const _parsedHours: string = `${_hours <= 9 ? "0" : ""}${_hours}`; - - return `${ - months[_unix.getMonth()] - } ${_unix.getDate()} ${_unix.getFullYear()} at ${_parsedHours}:${_parsedMinutes}:${_parsedSeconds}`; - } - - case "DD MMM YY": { - const day = _unix.getDate().toString().padStart(2, "0"); - const month = months[_unix.getMonth()].substring(0, 3); - const year = _unix.getFullYear(); - return `${day} ${month} ${year}`; - } - - case "relative": { - const currentTime = new Date(); - - const yearsDifference = - currentTime.getFullYear() - _unix.getFullYear(); - const monthsDifference = currentTime.getMonth() - _unix.getMonth(); - const daysDifference = currentTime.getDate() - _unix.getDate(); - const hoursDifference = currentTime.getHours() - _unix.getHours(); - const minutesDifference = - currentTime.getMinutes() - _unix.getMinutes(); - const secondsDifference = - currentTime.getSeconds() - _unix.getSeconds(); - - if (yearsDifference > 0) { - return `${yearsDifference} year${ - yearsDifference > 1 ? "s" : "" - } ago`; - } else if (monthsDifference > 0) { - return `${monthsDifference} month${ - monthsDifference > 1 ? "s" : "" - } ago`; - } else if (daysDifference > 0) { - return `${daysDifference} day${daysDifference > 1 ? "s" : ""} ago`; - } else if (hoursDifference > 0) { - return `${hoursDifference} hour${ - hoursDifference > 1 ? "s" : "" - } ago`; - } else if (minutesDifference > 0) { - return `${minutesDifference} minute${ - minutesDifference > 1 ? "s" : "" - } ago`; - } else if (secondsDifference > 0) { - return `${secondsDifference} second${ - secondsDifference > 1 ? "s" : "" - } ago`; - } else { - return `just now`; - } - } - - case "YYYY MM DD": { - const offsetMinutes = _unix.getTimezoneOffset(); - const offsetMilliseconds = offsetMinutes * 60 * 1000; - const utcTime = _unix.getTime() + offsetMilliseconds; - const _utc_unix: Date = new Date(utcTime); - - const year = _utc_unix.getFullYear(); - const month = String(_utc_unix.getMonth() + 1).padStart(2, "0"); - const day = String(_utc_unix.getDate()).padStart(2, "0"); - - return `${year}-${month}-${day}`; - } - - default: { - return _unix.toISOString(); - } - } -};