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

feat: change details page top section explorer link to copy link #282

Merged
merged 2 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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
- [#281](https://github.com/alleslabs/celatone-frontend/pull/281) Change Osmosis mainnet GraphQL
- [#251](https://github.com/alleslabs/celatone-frontend/pull/251) Refactor Code and Contract tables into general components
- [#252](https://github.com/alleslabs/celatone-frontend/pull/252) Refactor Empty State image source logic
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