From 4947a3121970b7f815f7d1ba34056c566ad56be1 Mon Sep 17 00:00:00 2001 From: J M Rossy Date: Fri, 9 Sep 2022 12:01:23 -0400 Subject: [PATCH] Add more info to message details screen DRY up details markup --- src/components/icons/ChainIcon.tsx | 2 + src/features/search/MessageDetails.tsx | 325 +++++++++++++------------ src/utils/chains.ts | 3 +- src/utils/time.ts | 5 + 4 files changed, 182 insertions(+), 153 deletions(-) diff --git a/src/components/icons/ChainIcon.tsx b/src/components/icons/ChainIcon.tsx index c201b88..7b885d2 100644 --- a/src/components/icons/ChainIcon.tsx +++ b/src/components/icons/ChainIcon.tsx @@ -15,6 +15,7 @@ import Celo from '../../images/logos/celo.svg'; import EthMainnet from '../../images/logos/eth-mainnet.svg'; import Optimism from '../../images/logos/optimism.svg'; import Polygon from '../../images/logos/polygon.svg'; +import { getChainName } from '../../utils/chains'; const CHAIN_TO_ICON = { [chain.arbitrum.id]: Arbitrum, @@ -38,6 +39,7 @@ function _ChainIcon({
{ @@ -113,22 +107,103 @@ export function MessageDetails({ messageId }: { messageId: string }) { )}
- -
-
- -
-
-

- Origin Transaction -

- -
+ + + +
+ + ); +} + +function StatusHeader({ + text, + fetching, + children, +}: PropsWithChildren<{ text: string; fetching: boolean }>) { + return ( +
+

{text}

+ {fetching || !children ? ( +
+
+
+
+ ) : ( + children + )} +
+ ); +} + +interface TransactionCardProps { + title: string; + chainId: number; + status: MessageStatus; + transaction?: PartialTransactionReceipt; + help: string; + shouldBlur: boolean; +} + +function TransactionCard({ + title, + chainId, + status, + transaction, + help, + shouldBlur, +}: TransactionCardProps) { + const txExplorerLink = getTxExplorerLink( + chainId, + transaction?.transactionHash, + ); + return ( + +
+
+ +
+
+

{title}

+ +
+
+ {transaction ? ( + <> + - {originTxExplorerLink && ( + {txExplorerLink && ( View in block explorer )} -
- -
-
- -
-
-

- Destination Transaction -

- -
-
- {destinationTransaction ? ( - <> - - - - {destinationTxExplorerLink && ( - - View in block explorer - - )} - - ) : ( -
-
- {status === MessageStatus.Failing - ? 'Destination chain transaction currently failing' - : 'Destination chain transaction still in progress'} -
- -
- )} -
-
- -
-
- -
-
-

- Message Details -

- -
-
- - -
- -
- {body} - + + ) : ( +
+
+ {status === MessageStatus.Failing + ? 'Destination chain transaction currently failing' + : 'Destination chain transaction still in progress'}
+
- - + )} + ); } -function StatusHeader({ - text, - fetching, - children, -}: PropsWithChildren<{ text: string; fetching: boolean }>) { +interface DetailsCardProps { + originChainId: number; + destinationChainId: number; + sender: string; + recipient: string; + body: string; + shouldBlur: boolean; +} + +function DetailsCard({ + originChainId, + destinationChainId, + sender, + recipient, + body, + shouldBlur, +}: DetailsCardProps) { return ( -
-

{text}

- {fetching || !children ? ( -
-
- -
+ +
+
+
- ) : ( - children - )} -
+
+

+ Message Details +

+ +
+
+ + +
+ +
+ {body} + +
+
+ ); } diff --git a/src/utils/chains.ts b/src/utils/chains.ts index ccf4450..2f77262 100644 --- a/src/utils/chains.ts +++ b/src/utils/chains.ts @@ -1,5 +1,6 @@ import { allChains } from '../consts/networksConfig'; -export function getChainName(chainId: number) { +export function getChainName(chainId?: number) { + if (!chainId) return 'unknown'; return allChains.find((c) => c.id === chainId)?.name || 'unknown'; } diff --git a/src/utils/time.ts b/src/utils/time.ts index 7791efd..224e2ec 100644 --- a/src/utils/time.ts +++ b/src/utils/time.ts @@ -26,3 +26,8 @@ export function getHumanReadableTimeString(timestamp: number) { const date = new Date(timestamp); return date.toLocaleDateString(); } + +export function getDateTimeString(timestamp: number) { + const date = new Date(timestamp); + return `${date.toLocaleTimeString()} ${date.toLocaleDateString()}`; +}