add token type on token instructions + symbol on amount (#12398)

This commit is contained in:
Josh 2020-09-23 07:51:54 -07:00 committed by GitHub
parent 6563726f22
commit bb72cbe7ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 1 deletions

View File

@ -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(
<tr key={mintAddress}>
<td>Token</td>
<td className="text-lg-right">
<Address pubkey={new PublicKey(mintAddress)} alignRight link />
</td>
</tr>
);
}
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}</>;
}