From 060704e55bc755f76b5c866b4fecf4015c89c6f3 Mon Sep 17 00:00:00 2001 From: Griko Nibras Date: Sat, 16 Dec 2023 02:50:00 +0700 Subject: [PATCH 01/16] chore: remove redundant state persisting --- src/context/tx-history.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/context/tx-history.ts b/src/context/tx-history.ts index be9d07b6..9ebbfafd 100644 --- a/src/context/tx-history.ts +++ b/src/context/tx-history.ts @@ -39,10 +39,7 @@ export const addTxHistory = (input: TxHistoryItemInput) => { ...input, }; - useTxHistory.setState((state) => ({ - ...state, - [id]: newItem, - })); + useTxHistory.setState({ [id]: newItem }); return [id, newItem] as const; }; @@ -57,7 +54,7 @@ export const successTxHistory = (id: string) => { status: "success", }; - return { ...state, [id]: latest }; + return { [id]: latest }; }); }; @@ -71,7 +68,7 @@ export const failTxHistory = (id: string) => { status: "failed", }; - return { ...state, [id]: latest }; + return { [id]: latest }; }); }; @@ -95,7 +92,7 @@ export const addTxStatus = (id: string, txStatus: TxStatus) => { txStatus: newTxStatus, }; - return { ...state, [id]: latest }; + return { [id]: latest }; }); }; @@ -116,7 +113,7 @@ export const updateTxStatus = (id: string, txStatus: TxStatus) => { txStatus: newTxStatus, }; - return { ...state, [id]: latest }; + return { [id]: latest }; }); }; From 861862e6eb391338c10fc23c4279791b5b1700cc Mon Sep 17 00:00:00 2001 From: Griko Nibras Date: Sat, 16 Dec 2023 02:50:23 +0700 Subject: [PATCH 02/16] fix: update asset input usd diff logic [FRE-454] --- src/components/AssetInput.tsx | 6 ++++-- src/components/SwapWidget/SwapWidget.tsx | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/AssetInput.tsx b/src/components/AssetInput.tsx index cec49719..3d434935 100644 --- a/src/components/AssetInput.tsx +++ b/src/components/AssetInput.tsx @@ -27,6 +27,7 @@ interface Props { chains: Chain[]; showBalance?: boolean; showSlippage?: boolean; + context?: "src" | "dest"; } const AssetInput: FC = ({ @@ -39,6 +40,7 @@ const AssetInput: FC = ({ onChainChange, showBalance, showSlippage, + context, }) => { const [isError, setIsError] = useState(false); @@ -188,11 +190,11 @@ const AssetInput: FC = ({ denom={asset.originDenom} coingeckoID={asset.coingeckoID} value={amount} - context={onAmountChange ? "src" : "dest"} + context={context} /> )} - {!onAmountChange && ( + {context === "dest" && ( {({ isLoading, percentage }) => (
{ onAssetChange={onSourceAssetChange} onChainChange={onSourceChainChange} showBalance + context="src" />
@@ -182,6 +183,7 @@ export const SwapWidget: FC = () => { onAssetChange={onDestinationAssetChange} onChainChange={onDestinationChainChange} showSlippage={!isSwapDetailsOpen} + context="dest" />
{route && ( From 27a35968fd3524540aac14f340dda9c360cf054f Mon Sep 17 00:00:00 2001 From: Griko Nibras Date: Sat, 16 Dec 2023 02:50:39 +0700 Subject: [PATCH 03/16] fix: fail tx instead or remove tx [FRE-454] --- src/components/TransactionDialog/TransactionDialogContent.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/TransactionDialog/TransactionDialogContent.tsx b/src/components/TransactionDialog/TransactionDialogContent.tsx index 66047273..32ebb33e 100644 --- a/src/components/TransactionDialog/TransactionDialogContent.tsx +++ b/src/components/TransactionDialog/TransactionDialogContent.tsx @@ -11,7 +11,7 @@ import { useToast } from "@/context/toast"; import { addTxHistory, addTxStatus, - removeTxHistory, + failTxHistory, successTxHistory, } from "@/context/tx-history"; import Toast from "@/elements/Toast"; @@ -219,7 +219,7 @@ const TransactionDialogContent: FC = ({ setTxError(err.message); setIsError(true); } - removeTxHistory(historyId); + failTxHistory(historyId); setTxStatuses((statuses) => { const newStatuses = [...statuses]; return newStatuses.map((status) => { From 04986fde289463711ae0501c3a64674fb1c7c1bd Mon Sep 17 00:00:00 2001 From: Griko Nibras Date: Sat, 16 Dec 2023 03:56:34 +0700 Subject: [PATCH 04/16] chore: improve tx history styling --- src/components/AssetValue.tsx | 7 ++++--- src/components/HistoryDialog/HistoryList.tsx | 14 +++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/components/AssetValue.tsx b/src/components/AssetValue.tsx index f5fd8476..1c36b1c1 100644 --- a/src/components/AssetValue.tsx +++ b/src/components/AssetValue.tsx @@ -19,9 +19,8 @@ export const AssetValue = ({ chainId, denom, value }: Props) => { }, [chainId, denom, getAsset]); const formattedValue = useMemo(() => { - const v = formatUnits(value, decimals); - const w = 9; - if (v.length > w) return v.slice(0, w) + "…"; + let v = formatUnits(value, decimals); + v = format(parseFloat(v)); return v; }, [decimals, value]); @@ -31,3 +30,5 @@ export const AssetValue = ({ chainId, denom, value }: Props) => { ); }; + +const { format } = new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 }); diff --git a/src/components/HistoryDialog/HistoryList.tsx b/src/components/HistoryDialog/HistoryList.tsx index 7488acbc..3d4de4c3 100644 --- a/src/components/HistoryDialog/HistoryList.tsx +++ b/src/components/HistoryDialog/HistoryList.tsx @@ -91,22 +91,22 @@ export const Item = forwardRef( ref={headingRef} >
-