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(components): add public account name and description in account … #309

Merged
merged 4 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

<<<<<<< HEAD
- [#309](https://github.com/alleslabs/celatone-frontend/pull/309) Add public account name and description in account detail page
=======
jennieramida marked this conversation as resolved.
Show resolved Hide resolved
- [#289](https://github.com/alleslabs/celatone-frontend/pull/289) Add public accounts to public projects
>>>>>>> develop
- [#308](https://github.com/alleslabs/celatone-frontend/pull/308) Adjust view more button to full width and fix empty state layout in contract history
- [#304](https://github.com/alleslabs/celatone-frontend/pull/304) Remove suffix for token card
- [#282](https://github.com/alleslabs/celatone-frontend/pull/282) Change details page top section explorer link to copy link
Expand Down
47 changes: 46 additions & 1 deletion src/lib/pages/account-details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TabPanels,
Tabs,
Text,
Image,
} from "@chakra-ui/react";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
Expand All @@ -15,11 +16,16 @@ 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 { CustomIcon } from "lib/components/icon";
import PageContainer from "lib/components/PageContainer";
import { InvalidState } from "lib/components/state";
import { useAccountDetailsTableCounts } from "lib/model/account";
import { useAccountId } from "lib/services/accountService";
import { AmpEvent, AmpTrack, AmpTrackUseTab } from "lib/services/amplitude";
import {
usePublicProjectByAccountAddress,
usePublicProjectBySlug,
} from "lib/services/publicProjectService";
import type { HumanAddr } from "lib/types";
import { formatPrice, getFirstQueryParam, scrollToTop } from "lib/utils";

Expand Down Expand Up @@ -54,7 +60,12 @@ const InvalidAccount = () => <InvalidState title="Account does not exist" />;
const AccountDetailsBody = ({ accountAddress }: AccountDetailsBodyProps) => {
const [tabIndex, setTabIndex] = useState(TabIndex.Overview);
const tableHeaderId = "accountDetailsTab";
const { data: publicInfo } = usePublicProjectByAccountAddress(accountAddress);
const { data: publicInfoBySlug } = usePublicProjectBySlug(publicInfo?.slug);
const { data: accountId } = useAccountId(accountAddress);

const publicDetail = publicInfoBySlug?.details;

const {
tableCounts,
refetchCodesCount,
Expand All @@ -71,12 +82,23 @@ const AccountDetailsBody = ({ accountAddress }: AccountDetailsBodyProps) => {
scrollToTop();
};

const displayName = publicInfo?.name || "Account Details";
jennieramida marked this conversation as resolved.
Show resolved Hide resolved

return (
<>
<Flex direction="column" gap={1} mt={6} mb={6}>
<Flex gap={1}>
{publicDetail?.logo && (
<Image
src={publicDetail.logo}
borderRadius="full"
alt={publicDetail.name}
width={7}
height={7}
/>
)}
<Heading as="h5" variant="h5">
Account Details
{displayName}
</Heading>
</Flex>
<Flex gap={2}>
Expand All @@ -90,6 +112,29 @@ const AccountDetailsBody = ({ accountAddress }: AccountDetailsBodyProps) => {
/>
</Flex>
</Flex>
{publicInfo?.description && (
<Flex
direction="column"
bg="pebble.900"
maxW="100%"
borderRadius="8px"
py={4}
px={5}
my={6}
flex="1"
>
<Flex align="center" gap={1} h="32px">
<CustomIcon name="website" ml="0" my="0" />
<Text variant="body2" fontWeight={500} color="text.dark">
Public Account Description
</Text>
</Flex>
<Text variant="body2" color="text.main" mb="1">
{publicInfo?.description}
</Text>
</Flex>
)}

<Tabs index={tabIndex}>
<TabList
borderBottom="1px solid"
Expand Down
31 changes: 31 additions & 0 deletions src/lib/services/publicProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,34 @@ export const usePublicProjectByCodeId = (
}
);
};

export const usePublicProjectByAccountAddress = (
accountAddress: Option<string>
): UseQueryResult<PublicInfo> => {
const { currentChainRecord } = useWallet();
const queryFn = useCallback(async () => {
if (!accountAddress)
throw new Error(
"Wallet address not found (usePublicProjectByAccountAddress)"
);
if (!currentChainRecord)
throw new Error("No chain selected (usePublicProjectByAccountAddress)");
return axios
.get<PublicInfo>(
`${CELATONE_API_ENDPOINT}/accounts/${getChainApiPath(
currentChainRecord.chain.chain_name
)}/${currentChainRecord.chain.chain_id}/${accountAddress}`
)
.then(({ data: projectInfo }) => projectInfo);
}, [accountAddress, currentChainRecord]);
return useQuery(
["public_project_by_account_address", accountAddress, currentChainRecord],
queryFn,
{
keepPreviousData: true,
enabled: !!accountAddress,
retry: false,
refetchOnWindowFocus: false,
}
);
};
Loading