From 67fdf593a24d6af14bf36fed2d77282aa1e5f014 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Sat, 8 Aug 2020 00:38:20 +0800 Subject: [PATCH] Split explorer account details page into tabs (#11450) --- explorer/src/App.tsx | 26 ++++-- explorer/src/components/AccountDetails.tsx | 68 +++++++++++++-- explorer/src/components/common/Address.tsx | 2 +- explorer/src/providers/accounts/history.tsx | 94 +++++++++------------ explorer/src/providers/accounts/index.tsx | 23 ++--- explorer/src/providers/accounts/tokens.tsx | 61 +++++++------ 6 files changed, 164 insertions(+), 110 deletions(-) diff --git a/explorer/src/App.tsx b/explorer/src/App.tsx index 4c8da5c76e..1b700ce35c 100644 --- a/explorer/src/App.tsx +++ b/explorer/src/App.tsx @@ -5,7 +5,6 @@ import AccountDetails from "./components/AccountDetails"; import TransactionDetails from "./components/TransactionDetails"; import ClusterModal from "./components/ClusterModal"; import { TX_ALIASES } from "./providers/transactions"; -import { ACCOUNT_ALIASES, ACCOUNT_ALIASES_PLURAL } from "./providers/accounts"; import TopAccountsCard from "components/TopAccountsCard"; import SupplyCard from "components/SupplyCard"; import StatsCard from "components/StatsCard"; @@ -14,6 +13,8 @@ import Navbar from "components/Navbar"; import { ClusterStatusBanner } from "components/ClusterStatusButton"; import { SearchBar } from "components/SearchBar"; +const ACCOUNT_ALIASES = ["account", "accounts", "addresses"]; + function App() { return ( <> @@ -41,11 +42,26 @@ function App() { /> `/${account}/:address` - )} + path={ACCOUNT_ALIASES.flatMap((account) => [ + `/${account}/:address`, + `/${account}/:address/:tab`, + ])} + render={({ match, location }) => { + let pathname = `/address/${match.params.address}`; + if (match.params.tab) { + pathname += `/${match.params.tab}`; + } + return ; + }} + /> + ( - + )} /> diff --git a/explorer/src/components/AccountDetails.tsx b/explorer/src/components/AccountDetails.tsx index 2962fb9b2f..8e342fb96e 100644 --- a/explorer/src/components/AccountDetails.tsx +++ b/explorer/src/components/AccountDetails.tsx @@ -21,9 +21,11 @@ import { import { useCluster, ClusterStatus } from "providers/cluster"; import Address from "./common/Address"; import Signature from "./common/Signature"; +import { NavLink } from "react-router-dom"; +import { clusterPath } from "utils/url"; -type Props = { address: string }; -export default function AccountDetails({ address }: Props) { +type Props = { address: string; tab?: string }; +export default function AccountDetails({ address, tab }: Props) { let pubkey: PublicKey | undefined; try { pubkey = new PublicKey(address); @@ -32,6 +34,11 @@ export default function AccountDetails({ address }: Props) { // TODO handle bad addresses } + let moreTab: MoreTabs = "history"; + if (tab === "history" || tab === "tokens") { + moreTab = tab; + } + return (
@@ -41,12 +48,51 @@ export default function AccountDetails({ address }: Props) {
{pubkey && } - {pubkey && } - {pubkey && } + {pubkey && } ); } +type MoreTabs = "history" | "tokens"; +function MoreSection({ pubkey, tab }: { pubkey: PublicKey; tab: MoreTabs }) { + const address = pubkey.toBase58(); + const info = useAccountInfo(address); + if (!info || info.lamports === undefined) return null; + + return ( + <> +
+
+
+
    +
  • + + History + +
  • +
  • + + Tokens + +
  • +
+
+
+
+ {tab === "tokens" && } + {tab === "history" && } + + ); +} + function AccountCards({ pubkey }: { pubkey: PublicKey }) { const fetchAccount = useFetchAccountInfo(); const address = pubkey.toBase58(); @@ -56,8 +102,7 @@ function AccountCards({ pubkey }: { pubkey: PublicKey }) { // Fetch account on load React.useEffect(() => { - if (pubkey && !info && status === ClusterStatus.Connected) - fetchAccount(pubkey); + if (!info && status === ClusterStatus.Connected) fetchAccount(pubkey); }, [address, status]); // eslint-disable-line react-hooks/exhaustive-deps if (!info || info.status === FetchStatus.Fetching) { @@ -137,6 +182,11 @@ function TokensCard({ pubkey }: { pubkey: PublicKey }) { const fetchAccountTokens = useFetchAccountOwnedTokens(); const refresh = () => fetchAccountTokens(pubkey); + // Fetch owned tokens + React.useEffect(() => { + if (!ownedTokens) refresh(); + }, [address]); // eslint-disable-line react-hooks/exhaustive-deps + if (ownedTokens === undefined) { return null; } @@ -186,7 +236,7 @@ function TokensCard({ pubkey }: { pubkey: PublicKey }) { return (
-

Tokens

+

Owned Tokens