From bb72cbe7aeb84bdbe8ad86539cc87f5597bcf9a5 Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 23 Sep 2020 07:51:54 -0700 Subject: [PATCH] add token type on token instructions + symbol on amount (#12398) --- .../instruction/token/TokenDetailsCard.tsx | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/explorer/src/components/instruction/token/TokenDetailsCard.tsx b/explorer/src/components/instruction/token/TokenDetailsCard.tsx index 4677a445e8..487f95d16c 100644 --- a/explorer/src/components/instruction/token/TokenDetailsCard.tsx +++ b/explorer/src/components/instruction/token/TokenDetailsCard.tsx @@ -19,6 +19,8 @@ import { } from "providers/accounts"; import { normalizeTokenAmount } from "utils"; import { reportError } from "utils/sentry"; +import { useCluster } from "providers/cluster"; +import { TokenRegistry } from "tokenRegistry"; type DetailsProps = { tx: ParsedTransaction; @@ -81,6 +83,7 @@ function TokenInstruction(props: InfoProps) { const tokenInfo = useTokenAccountInfo(tokenAddress); const mintAddress = infoMintAddress || tokenInfo?.mint.toBase58(); const mintInfo = useMintAccountInfo(mintAddress); + const { cluster } = useCluster(); const fetchAccountInfo = useFetchAccountInfo(); React.useEffect(() => { @@ -97,6 +100,26 @@ function TokenInstruction(props: InfoProps) { const decimals = mintInfo?.decimals; const attributes = []; + + let tokenSymbol = ""; + + if (mintAddress) { + const tokenDetails = TokenRegistry.get(mintAddress, cluster); + + if (tokenDetails && "symbol" in tokenDetails) { + tokenSymbol = tokenDetails.symbol; + } + + attributes.push( + + Token + +
+ + + ); + } + for (let key in props.info) { const value = props.info[key]; if (value === undefined) continue; @@ -116,7 +139,11 @@ function TokenInstruction(props: InfoProps) { maximumFractionDigits: decimals, }).format(normalizeTokenAmount(value, decimals)); } - tag = <>{amount}; + tag = ( + <> + {amount} {tokenSymbol} + + ); } else { tag = <>{value}; }