Skip to content

Commit

Permalink
Merge pull request #282 from alleslabs/feat/copy-link
Browse files Browse the repository at this point in the history
feat: change details page top section explorer link to copy link
  • Loading branch information
evilpeach committed Apr 21, 2023
2 parents 2e5a1b1 + 8a17574 commit cac3495
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

- [#282](https://github.com/alleslabs/celatone-frontend/pull/282) Change details page top section explorer link to copy link
- [#293](https://github.com/alleslabs/celatone-frontend/pull/293) Add comma separator to pagination and total blocks
- [#291](https://github.com/alleslabs/celatone-frontend/pull/291) Update tx count query
- [#285](https://github.com/alleslabs/celatone-frontend/pull/285) Add data fetching error state, and empty state to blocks page
Expand Down
55 changes: 55 additions & 0 deletions src/lib/components/CopyLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Flex, Text, Tooltip, useClipboard } from "@chakra-ui/react";
import { useWallet } from "@cosmos-kit/react";
import { useState } from "react";

import { AmpTrackCopier } from "lib/services/amplitude";

import { CustomIcon } from "./icon";

interface CopyLinkProps {
value: string;
amptrackSection?: string;
type: string;
}

export const CopyLink = ({ value, amptrackSection, type }: CopyLinkProps) => {
const { address } = useWallet();
const { onCopy, hasCopied } = useClipboard(value);
const [isHover, setIsHover] = useState(false);
return (
<Tooltip
hasArrow
isOpen={isHover || hasCopied}
label={hasCopied ? "Copied!" : "Click to copy"}
placement="top"
arrowSize={8}
bgColor="honeydew.darker"
closeOnClick={false}
>
<Flex
align="center"
onClick={() => {
AmpTrackCopier(amptrackSection, type);
onCopy();
}}
_hover={{
textDecoration: "underline",
textDecorationColor: "lilac.light",
"& > p": { color: "lilac.light" },
}}
cursor="pointer"
onMouseEnter={() => setIsHover(true)}
onMouseLeave={() => setIsHover(false)}
>
<Text
variant="body2"
color="lilac.main"
transition="all .25s ease-in-out"
>
{value === address ? `${value} (Me)` : value}
</Text>
<CustomIcon cursor="pointer" marginLeft={2} name="copy" boxSize={3} />
</Flex>
</Tooltip>
);
};
9 changes: 4 additions & 5 deletions src/lib/pages/account-details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { useEffect, useState } from "react";

import { useValidateAddress } from "lib/app-provider";
import { BackButton } from "lib/components/button";
import { CopyLink } from "lib/components/CopyLink";
import { CustomTab } from "lib/components/CustomTab";
import { ExplorerLink } from "lib/components/ExplorerLink";
import PageContainer from "lib/components/PageContainer";
import { InvalidState } from "lib/components/state";
import { useAccountDetailsTableCounts } from "lib/model/account";
Expand Down Expand Up @@ -82,11 +82,10 @@ const AccountDetailsBody = ({ accountAddress }: AccountDetailsBodyProps) => {
<Text fontWeight={500} color="text.dark" variant="body2">
Wallet Address:
</Text>
<ExplorerLink
type="user_address"
<CopyLink
value={accountAddress}
textFormat="normal"
maxWidth="full"
amptrackSection="account_top"
type="user_address"
/>
</Flex>
</Flex>
Expand Down
8 changes: 6 additions & 2 deletions src/lib/pages/code-details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useRouter } from "next/router";
import { useEffect } from "react";

import { BackButton } from "lib/components/button";
import { ExplorerLink } from "lib/components/ExplorerLink";
import { CopyLink } from "lib/components/CopyLink";
import { CustomIcon } from "lib/components/icon";
import { GitHubLink } from "lib/components/links";
import { Loading } from "lib/components/Loading";
Expand Down Expand Up @@ -71,7 +71,11 @@ const CodeDetailsBody = observer(
<Text fontWeight={500} color="text.dark" variant="body2">
Code ID:
</Text>
<ExplorerLink type="code_id" value={codeId.toString()} />
<CopyLink
value={codeId.toString()}
amptrackSection="code_top"
type="code_id"
/>
</Flex>
<Flex gap={2}>
<Text fontWeight={500} color="text.dark" variant="body2">
Expand Down
9 changes: 4 additions & 5 deletions src/lib/pages/contract-details/components/ContractTop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import router from "next/router";

import { useInternalNavigate } from "lib/app-provider";
import { AdminButton } from "lib/components/button";
import { ExplorerLink } from "lib/components/ExplorerLink";
import { CopyLink } from "lib/components/CopyLink";
import { CustomIcon } from "lib/components/icon";
import { GitHubLink } from "lib/components/links";
import {
Expand Down Expand Up @@ -119,11 +119,10 @@ export const ContractTop = ({ contractData }: ContractTopProps) => {
>
Contract Address:
</Text>
<ExplorerLink
type="contract_address"
<CopyLink
value={contractAddress}
textFormat="normal"
maxWidth="none"
amptrackSection="contract_top"
type="contract_address"
/>
</Flex>
<Flex gap={2}>
Expand Down
8 changes: 3 additions & 5 deletions src/lib/pages/tx-details/components/TxHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { FlexProps } from "@chakra-ui/react";
import { Button, Box, Flex, Heading, Text } from "@chakra-ui/react";

import { ExplorerLink } from "lib/components/ExplorerLink";
import { CopyLink } from "lib/components/CopyLink";
import { CustomIcon } from "lib/components/icon";
import { useOpenTxTab } from "lib/hooks";
import { AmpTrackViewJson } from "lib/services/amplitude";
Expand Down Expand Up @@ -41,12 +41,10 @@ export const TxHeader = ({ txData, ...flexProps }: TxHeaderProps) => {
<Text variant="body2" fontWeight={500} color="text.dark">
Transaction Hash:
</Text>
<ExplorerLink
<CopyLink
value={txData.txhash}
amptrackSection="tx_header"
type="tx_hash"
textFormat="normal"
maxWidth="full"
ampCopierSection="tx_header"
/>
</Flex>
<Flex gap={2} fontSize="14px" color="text.dark" align="center">
Expand Down

2 comments on commit cac3495

@vercel
Copy link

@vercel vercel bot commented on cac3495 Apr 21, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on cac3495 Apr 21, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.