Skip to content

Commit

Permalink
Clean up formatter (#3829)
Browse files Browse the repository at this point in the history
* Clean up formatter

* Remove log

* update no price data
  • Loading branch information
mattupham authored Sep 5, 2024
1 parent 6657409 commit e71f1f1
Show file tree
Hide file tree
Showing 22 changed files with 11 additions and 58 deletions.
5 changes: 3 additions & 2 deletions packages/web/components/complex/portfolio/allocation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { FunctionComponent, useEffect, useState } from "react";
import { Icon } from "~/components/assets";
import { AllocationTabs } from "~/components/complex/portfolio/allocation-tabs";
import { AllocationOptions } from "~/components/complex/portfolio/types";
import { displayFiatPrice } from "~/components/transactions/transaction-utils";
import { EventName } from "~/config";
import {
Breakpoint,
Expand All @@ -15,6 +14,7 @@ import {
useTranslation,
useWindowSize,
} from "~/hooks";
import { formatFiatPrice } from "~/utils/formatter";

const COLORS: Record<AllocationOptions, string[]> = {
all: [
Expand Down Expand Up @@ -133,6 +133,7 @@ export const Allocation: FunctionComponent<{
{selectedList.map(({ key, percentage, fiatValue }, index) => {
const colorClass =
COLORS[selectedOption][index % COLORS[selectedOption].length];

return (
<div key={key} className="body2 flex w-full justify-between">
<div className="flex items-center space-x-1">
Expand All @@ -147,7 +148,7 @@ export const Allocation: FunctionComponent<{
{percentage.maxDecimals(0).toString()}
</span>
</div>
<div>{displayFiatPrice(fiatValue, "", t)}</div>
<div>{formatFiatPrice(fiatValue)}</div>
</div>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { FunctionComponent } from "react";

import { FallbackImg, Icon } from "~/components/assets";
import { TransactionRow } from "~/components/transactions/transaction-row";
import { displayFiatPrice } from "~/components/transactions/transaction-utils";
import { useTranslation } from "~/hooks";

import { formatFiatPrice } from "~/utils/formatter";
export type TransactionStatus = "pending" | "success" | "failed";

export const RecentActivityRow: FunctionComponent<{
Expand All @@ -26,13 +24,11 @@ export const SwapRow: FunctionComponent<TransactionRow> = ({
title,
tokenConversion,
}) => {
const { t } = useTranslation();

const leftComponent = tokenConversion ? (
<div className="flex flex-col gap-0.5">
<p className="body2 text-white-full">{title[status]}</p>
<div className="caption flex items-center gap-1 text-osmoverse-300">
{displayFiatPrice(tokenConversion.tokenIn?.value, "", t)}{" "}
{formatFiatPrice(tokenConversion.tokenIn?.value)}{" "}
{tokenConversion.tokenIn.amount.denom}{" "}
<Icon id="arrow-right" width={14} height={14} />{" "}
{tokenConversion.tokenOut.amount.denom}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Icon } from "~/components/assets";
import { FallbackImg } from "~/components/assets";
import { CopyIconButton } from "~/components/buttons/copy-icon-button";
import { IconButton } from "~/components/buttons/icon-button";
import { displayFiatPrice } from "~/components/transactions/transaction-utils";
import { Button } from "~/components/ui/button";
import { EventName } from "~/config";
import {
Expand All @@ -18,6 +17,7 @@ import {
} from "~/hooks";
import { theme } from "~/tailwind.config";
import { formatPretty } from "~/utils/formatter";
import { formatFiatPrice } from "~/utils/formatter";

export const TransactionDetailsContent = ({
onRequestClose,
Expand Down Expand Up @@ -142,7 +142,7 @@ export const TransactionDetailsContent = ({
{formatPretty(tokenIn.token, { maxDecimals: 6 }).split(" ")[0]}
</div>
<div className="body1 text-osmoverse-300">
{displayFiatPrice(tokenIn?.usd, "", t)}
{formatFiatPrice(tokenIn?.usd, "", t)}
</div>
</div>
</div>
Expand Down Expand Up @@ -179,7 +179,7 @@ export const TransactionDetailsContent = ({
{formatPretty(tokenOut.token, { maxDecimals: 6 }).split(" ")[0]}
</div>
<div className="body1 text-osmoverse-300">
{displayFiatPrice(tokenOut?.usd, "", t)}
{formatFiatPrice(tokenOut?.usd)}
</div>
</div>
</div>
Expand Down
7 changes: 3 additions & 4 deletions packages/web/components/transactions/transaction-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import classNames from "classnames";
import { FunctionComponent } from "react";

import { FallbackImg, Icon } from "~/components/assets";
import { displayFiatPrice } from "~/components/transactions/transaction-utils";
import { useTranslation } from "~/hooks";
import { theme } from "~/tailwind.config";
import { formatPretty } from "~/utils/formatter";
import { formatFiatPrice, formatPretty } from "~/utils/formatter";

import { Spinner } from "../loaders";

Expand Down Expand Up @@ -150,7 +149,7 @@ const TokenConversion: FunctionComponent<
</div>
)}
<div className="body2 text-osmoverse-400">
{displayFiatPrice(tokenIn?.value, "-", t)}
{tokenIn.value && `- ${formatFiatPrice(tokenIn.value)}`}
</div>
</div>
<FallbackImg
Expand Down Expand Up @@ -190,7 +189,7 @@ const TokenConversion: FunctionComponent<
</div>
)}
<div className="md:caption body2 mt-0 md:mt-1">
{displayFiatPrice(tokenOut?.value, "+", t)}
{tokenOut.value && `+ ${formatFiatPrice(tokenOut.value)}`}
</div>
</div>
</div>
Expand Down
26 changes: 0 additions & 26 deletions packages/web/components/transactions/transaction-utils.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { PricePretty } from "@keplr-wallet/unit";
import { Dec } from "@keplr-wallet/unit";
import { FormattedTransaction } from "@osmosis-labs/server";
import dayjs from "dayjs";
import isToday from "dayjs/plugin/isToday";
import isYesterday from "dayjs/plugin/isYesterday";
import relativeTime from "dayjs/plugin/relativeTime";
import { useTranslation } from "hooks";

import { MultiLanguageT } from "~/hooks";

dayjs.extend(relativeTime);
dayjs.extend(isToday);
dayjs.extend(isYesterday);
Expand Down Expand Up @@ -47,25 +43,3 @@ export const useFormatDate = () => {

return formatDate;
};

export const displayFiatPrice = (
value: PricePretty | undefined,
prefix: "-" | "+" | "",
t: MultiLanguageT
): string => {
if (value === undefined) return t("transactions.noPriceData");

const decValue = value.toDec();
const symbol = value.symbol;

if (decValue.lt(new Dec(0.01))) {
return `${prefix} <${symbol}0.01`;
}

// Convert displayValue to a fixed 2-decimal place string
const formattedDisplayValue = `${prefix} ${symbol}${Number(
decValue.toString()
).toFixed(2)}`;

return formattedDisplayValue;
};
1 change: 0 additions & 1 deletion packages/web/localizations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@
"transactionHash": "Transaktions-Hash",
"viewOnExplorer": "Im Explorer anzeigen",
"launchAlert": "Derzeit wird nur der Handelsverlauf angezeigt. Unterstützung für weitere Transaktionstypen folgt in Kürze.",
"noPriceData": "Preisdaten nicht verfügbar",
"viewAll": "Alle ansehen",
"history": "Geschichte",
"orders": "Aufträge"
Expand Down
1 change: 0 additions & 1 deletion packages/web/localizations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@
"transactionHash": "Transaction Hash",
"viewOnExplorer": "View on explorer",
"launchAlert": "Currently only trade history is displayed. Support for more transaction types coming soon.",
"noPriceData": "Price data unavailable",
"viewAll": "View all",
"history": "History",
"orders": "Orders"
Expand Down
1 change: 0 additions & 1 deletion packages/web/localizations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@
"transactionHash": "Hash de transacción",
"viewOnExplorer": "Ver en el explorador",
"launchAlert": "Actualmente solo se muestra el historial comercial. Próximamente soporte para más tipos de transacciones.",
"noPriceData": "Datos de precios no disponibles",
"viewAll": "Ver todo",
"history": "Historia",
"orders": "Pedidos"
Expand Down
1 change: 0 additions & 1 deletion packages/web/localizations/fa.json
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@
"transactionHash": "هش تراکنش",
"viewOnExplorer": "مشاهده در اکسپلورر",
"launchAlert": "در حال حاضر فقط سابقه تجارت نمایش داده می شود. پشتیبانی از انواع تراکنش های بیشتر به زودی.",
"noPriceData": "اطلاعات قیمت در دسترس نیست",
"viewAll": "مشاهده همه",
"history": "تاریخ",
"orders": "سفارشات"
Expand Down
1 change: 0 additions & 1 deletion packages/web/localizations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@
"transactionHash": "Hachage des transactions",
"viewOnExplorer": "Afficher sur l'explorateur",
"launchAlert": "Actuellement, seul l'historique des échanges est affiché. Prise en charge d'autres types de transactions à venir.",
"noPriceData": "Données de prix indisponibles",
"viewAll": "Voir tout",
"history": "Histoire",
"orders": "Ordres"
Expand Down
1 change: 0 additions & 1 deletion packages/web/localizations/gu.json
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@
"transactionHash": "ટ્રાન્ઝેક્શન હેશ",
"viewOnExplorer": "એક્સપ્લોરર પર જુઓ",
"launchAlert": "હાલમાં માત્ર વેપાર ઇતિહાસ પ્રદર્શિત થાય છે. વધુ વ્યવહાર પ્રકારો માટે સમર્થન ટૂંક સમયમાં આવી રહ્યું છે.",
"noPriceData": "કિંમત ડેટા ઉપલબ્ધ નથી",
"viewAll": "બધુજ જુઓ",
"history": "ઇતિહાસ",
"orders": "ઓર્ડર"
Expand Down
1 change: 0 additions & 1 deletion packages/web/localizations/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@
"transactionHash": "लेनदेन हैश",
"viewOnExplorer": "एक्सप्लोरर पर देखें",
"launchAlert": "वर्तमान में केवल व्यापार इतिहास प्रदर्शित किया जाता है। जल्द ही अधिक लेनदेन प्रकारों के लिए सहायता उपलब्ध होगी।",
"noPriceData": "मूल्य डेटा उपलब्ध नहीं है",
"viewAll": "सभी को देखें",
"history": "इतिहास",
"orders": "आदेश"
Expand Down
1 change: 0 additions & 1 deletion packages/web/localizations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@
"transactionHash": "トランザクションハッシュ",
"viewOnExplorer": "エクスプローラーで見る",
"launchAlert": "現在は取引履歴のみが表示されます。他の取引タイプも近日中にサポートされる予定です。",
"noPriceData": "価格データは利用できません",
"viewAll": "すべて表示",
"history": "歴史",
"orders": "注文"
Expand Down
1 change: 0 additions & 1 deletion packages/web/localizations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@
"transactionHash": "거래 해시",
"viewOnExplorer": "탐색기에서 보기",
"launchAlert": "현재는 거래 내역만 표시됩니다. 더 많은 거래 유형이 곧 지원될 예정입니다.",
"noPriceData": "가격 데이터를 사용할 수 없습니다.",
"viewAll": "모두보기",
"history": "역사",
"orders": "명령"
Expand Down
1 change: 0 additions & 1 deletion packages/web/localizations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@
"transactionHash": "Hash transakcji",
"viewOnExplorer": "Zobacz w eksploratorze",
"launchAlert": "Obecnie wyświetlana jest tylko historia transakcji. Wkrótce obsługa większej liczby typów transakcji.",
"noPriceData": "Dane cenowe niedostępne",
"viewAll": "Pokaż wszystkie",
"history": "Historia",
"orders": "Zamówienia"
Expand Down
1 change: 0 additions & 1 deletion packages/web/localizations/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@
"transactionHash": "Hash de transação",
"viewOnExplorer": "Ver no explorador",
"launchAlert": "Atualmente apenas o histórico de negociações é exibido. Suporte para mais tipos de transação em breve.",
"noPriceData": "Dados de preço indisponíveis",
"viewAll": "Ver tudo",
"history": "História",
"orders": "Pedidos"
Expand Down
1 change: 0 additions & 1 deletion packages/web/localizations/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@
"transactionHash": "Hash de tranzacție",
"viewOnExplorer": "Vizualizare pe explorer",
"launchAlert": "Momentan este afișat doar istoricul comerțului. Asistență pentru mai multe tipuri de tranzacții în curând.",
"noPriceData": "Datele de preț nu sunt disponibile",
"viewAll": "A vedea tot",
"history": "Istorie",
"orders": "Comenzi"
Expand Down
1 change: 0 additions & 1 deletion packages/web/localizations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@
"transactionHash": "Хэш транзакции",
"viewOnExplorer": "Посмотреть в проводнике",
"launchAlert": "В настоящее время отображается только история торговли. Скоро появится поддержка большего количества типов транзакций.",
"noPriceData": "Данные о ценах недоступны.",
"viewAll": "Посмотреть все",
"history": "История",
"orders": "Заказы"
Expand Down
1 change: 0 additions & 1 deletion packages/web/localizations/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@
"transactionHash": "İşlem Karması",
"viewOnExplorer": "Explorer'da görüntüle",
"launchAlert": "Şu anda yalnızca ticaret geçmişi görüntüleniyor. Yakında daha fazla işlem türü için destek sunulacak.",
"noPriceData": "Fiyat verileri mevcut değil",
"viewAll": "Hepsini gör",
"history": "Tarih",
"orders": "Emirler"
Expand Down
1 change: 0 additions & 1 deletion packages/web/localizations/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@
"transactionHash": "交易哈希",
"viewOnExplorer": "在资源管理器中查看",
"launchAlert": "目前仅显示交易历史。即将支持更多交易类型。",
"noPriceData": "价格数据不可用",
"viewAll": "查看全部",
"history": "历史",
"orders": "命令"
Expand Down
1 change: 0 additions & 1 deletion packages/web/localizations/zh-hk.json
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@
"transactionHash": "交易哈希",
"viewOnExplorer": "在資源管理器上查看",
"launchAlert": "目前僅顯示交易歷史記錄。即將支援更多交易類型。",
"noPriceData": "價格數據不可用",
"viewAll": "看全部",
"history": "歷史",
"orders": "命令"
Expand Down
1 change: 0 additions & 1 deletion packages/web/localizations/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@
"transactionHash": "交易哈希",
"viewOnExplorer": "在資源管理器上查看",
"launchAlert": "目前僅顯示交易歷史記錄。即將支援更多交易類型。",
"noPriceData": "價格數據不可用",
"viewAll": "看全部",
"history": "歷史",
"orders": "命令"
Expand Down

0 comments on commit e71f1f1

Please sign in to comment.