Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show no admin and correctly handle explorer link by address type #115

Merged
merged 7 commits into from
Jan 24, 2023

Conversation

poomthiti
Copy link
Contributor

@poomthiti poomthiti commented Jan 20, 2023

@vercel
Copy link

vercel bot commented Jan 20, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
celatone-frontend-initial-demo 🔄 Building (Inspect) Jan 24, 2023 at 4:30AM (UTC)
celatone-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 24, 2023 at 4:30AM (UTC)
osmosis-celatone-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 24, 2023 at 4:30AM (UTC)
terra-celatone-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 24, 2023 at 4:30AM (UTC)
terra-network-celatone-test 🔄 Building (Inspect) Jan 24, 2023 at 4:30AM (UTC)
4 Ignored Deployments
Name Status Preview Comments Updated
celatone-custom-chain-temp ⬜️ Ignored (Inspect) Jan 24, 2023 at 4:30AM (UTC)
celatone-frontend ⬜️ Ignored (Inspect) Jan 24, 2023 at 4:30AM (UTC)
osmosis-celatone-frontend ⬜️ Ignored (Inspect) Jan 24, 2023 at 4:30AM (UTC)
terra-celatone-frontend ⬜️ Ignored (Inspect) Jan 24, 2023 at 4:30AM (UTC)

@poomthiti poomthiti added the bug Something isn't working label Jan 22, 2023
Copy link
Collaborator

@evilpeach evilpeach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor to this

import { chakra, Divider, Flex, Text } from "@chakra-ui/react";

import { ExplorerLink } from "lib/components/ExplorerLink";
import { LabelText } from "lib/components/LabelText";
import { useGetAddressType } from "lib/hooks";
import type { ContractData } from "lib/model/contract";
import { formatUTC, dateFromNow } from "lib/utils";
import { getAddressTypeText } from "lib/utils/address";

interface InstantiateInfoProps {
  contractData: ContractData;
}

const Container = chakra(Flex, {
  baseStyle: {
    direction: "column",
    gap: 6,
    w: "250px",
  },
});

export const InstantiateInfo = ({
  contractData: {
    instantiateInfo,
    chainId,
    codeInfo,
    initTxHash,
    initProposalId,
    initProposalTitle,
  },
}: InstantiateInfoProps) => {
  const getAddressType = useGetAddressType();

  if (!instantiateInfo) {
    return (
      <Container>
        <Text variant="body2" color="text.dark">
          Error fetching data
        </Text>
      </Container>
    );
  }

  const instantiatorType = getAddressType(instantiateInfo.instantiator);
  const adminTypeOpt = instantiateInfo.admin
    ? getAddressType(instantiateInfo.admin)
    : undefined;

  return (
    <Container>
      <LabelText label="Network">{chainId}</LabelText>

      <LabelText label="From Code" helperText1={codeInfo?.description}>
        <ExplorerLink
          type="code_id"
          value={instantiateInfo.codeId}
          canCopyWithHover
        />
      </LabelText>

      <LabelText
        label="Admin Address"
        helperText1={
          adminTypeOpt ? getAddressTypeText(adminTypeOpt) : undefined
        }
      >
        {instantiateInfo.admin ? (
          <ExplorerLink
            type={adminTypeOpt}
            value={instantiateInfo.admin}
            canCopyWithHover
          />
        ) : (
          <Text variant="body2" color="text.dark">
            No Admin
          </Text>
        )}
      </LabelText>

      <Divider border="1px solid" borderColor="divider.main" />

      {instantiateInfo &&
        (instantiateInfo.createdHeight !== -1 ? (
          <LabelText
            label="Instantiated Block Height"
            helperText1={
              instantiateInfo.createdTime
                ? formatUTC(instantiateInfo.createdTime)
                : undefined
            }
            helperText2={
              instantiateInfo.createdTime
                ? dateFromNow(instantiateInfo.createdTime)
                : undefined
            }
          >
            <ExplorerLink
              type="block_height"
              value={instantiateInfo.createdHeight.toString()}
              canCopyWithHover
            />
          </LabelText>
        ) : (
          <LabelText label="Instantiated Block Height">N/A</LabelText>
        ))}

      <LabelText
        label="Instantiated by"
        helperText1={getAddressTypeText(instantiatorType)}
      >
        <ExplorerLink
          type={instantiatorType}
          value={instantiateInfo.instantiator}
          canCopyWithHover
        />
      </LabelText>

      {initTxHash ? (
        <LabelText label="Instantiate Transaction">
          <ExplorerLink
            type="tx_hash"
            value={initTxHash.toUpperCase()}
            canCopyWithHover
          />
        </LabelText>
      ) : (
        <LabelText
          label="Instantiate Proposal ID"
          helperText1={initProposalTitle}
        >
          <ExplorerLink
            value={initProposalId ? `#${initProposalId}` : "Genesis"}
            canCopyWithHover
            isReadOnly={!initProposalId}
          />
        </LabelText>
      )}

      {instantiateInfo.ibcPortId && (
        <LabelText label="IBC Port ID">{instantiateInfo.ibcPortId}</LabelText>
      )}
    </Container>
  );
};

@poomthiti poomthiti deleted the fix/show-noadmin branch January 24, 2023 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants