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/initia name service #950

Merged
merged 13 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ next.config.original.js
.sentryclirc
next.config.original.js
next.config.wizardcopy.js

#Localization
credentials.json
token.json
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

- [#950](https://github.com/alleslabs/celatone-frontend/pull/950) Add initia username
- [#971](https://github.com/alleslabs/celatone-frontend/pull/971) Support search functionality with LCD endpoint
- [#970](https://github.com/alleslabs/celatone-frontend/pull/970) Support account details lite version
- [#964](https://github.com/alleslabs/celatone-frontend/pull/964) Support migrate page lite version with LCD
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@
"@emotion/styled": "^11.11.0",
"@graphql-codegen/cli": "^5.0.0",
"@graphql-typed-document-node/core": "^3.2.0",
"@initia/initia.js": "0.1.12",
"@initia/initia.proto": "0.1.12",
"@initia/initia.js": "0.2.5",
"@initia/initia.proto": "0.2.0",
"@initia/utils": "0.62.0",
"@interchain-ui/react": "1.23.9",
"@monaco-editor/react": "^4.6.0",
"@rjsf/chakra-ui": "v5.18.1",
Expand Down
287 changes: 230 additions & 57 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/lib/app-provider/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ export enum CELATONE_QUERY_KEYS {
// ICNS
ICNS_NAMES_BY_ADDRESS_LCD = "CELATONE_QUERY_ICNS_NAMES_BY_ADDRESS_LCD",
ADDRESS_BY_ICNS_NAME_LCD = "CELATONE_QUERY_ADDRESS_BY_ICNS_NAME_LCD",
// INITA USERNAME
INITIA_USERNAME_BY_ADDRESS = "CELATONE_QUERY_INITIA_USERNAME_BY_ADDRESS",
ADDRESS_BY_INITIA_USERNAME = "CELATONE_QUERY_ADDRESS_BY_INITIA_USERNAME",
// POOL
POOL_LIST = "CELATONE_QUERY_POOL_LIST",
POOL_LIST_COUNT = "CELATONE_QUERY_POOL_LIST_COUNT",
Expand Down
40 changes: 37 additions & 3 deletions src/lib/layout/Searchbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Flex,
FormControl,
IconButton,
Image,
List,
ListItem,
Spinner,
Expand Down Expand Up @@ -47,6 +48,7 @@ const StyledListItem = chakra(ListItem, {
bg: "gray.900",
},
});

interface ResultItemProps {
index: number;
type: SearchResultType;
Expand Down Expand Up @@ -102,6 +104,24 @@ const getRouteOptions = (
}
};

const InitiaUsername = ({ username }: { username: string }) => {
return (
<Flex gap={1} align="center" flexWrap="wrap">
<Flex gap={1} align="center">
<Image
src="https://assets.alleslabs.dev/webapp-assets/name-services/initia-username.svg"
borderRadius="full"
width={4}
height={4}
/>
<Text variant="body3" color="text.dark">
{username}
</Text>
</Flex>
</Flex>
);
};

const ResultItem = ({
index,
type,
Expand All @@ -116,6 +136,7 @@ const ResultItem = ({
const normalizedIcnsValue = value.endsWith(`.${metadata.icns.bech32Prefix}`)
? value
: `${value}.${metadata.icns.bech32Prefix}`;

return (
<StyledListItem id={`item-${index}`}>
<Text variant="body2" fontWeight={500} color="text.dark" p={2}>
Expand All @@ -136,7 +157,9 @@ const ResultItem = ({
onClose?.();
}}
>
<Text variant="body2">{metadata.icns.address || value}</Text>
<Text variant="body2">
{metadata.icns.address || metadata.initiaUsername.address || value}
</Text>
{metadata.icns.icnsNames?.primaryName && (
<Flex gap={1} align="center" flexWrap="wrap">
<Flex gap={1} align="center">
Expand All @@ -163,6 +186,9 @@ const ResultItem = ({
)}
</Flex>
)}
{metadata.initiaUsername?.username && (
<InitiaUsername username={metadata.initiaUsername.username} />
)}
</Flex>
)}
</StyledListItem>
Expand Down Expand Up @@ -292,7 +318,9 @@ const Searchbar = () => {
const queryValues =
type === "Module Path"
? (splitModule(keyword) as [Addr, string])
: metadata.icns.address || keyword;
: metadata.icns.address ||
metadata.initiaUsername.address ||
keyword;
navigate({
pathname: routeOptions.pathname,
query: generateQueryObject(routeOptions.query, queryValues),
Expand All @@ -301,7 +329,13 @@ const Searchbar = () => {
onClose();
}
},
[keyword, metadata.icns.address, navigate, onClose]
[
keyword,
metadata.icns.address,
metadata.initiaUsername.address,
navigate,
onClose,
]
);

const handleOnKeyEnter = useCallback(
Expand Down
139 changes: 111 additions & 28 deletions src/lib/pages/account-details/components/AccountHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Flex, Heading, IconButton, Image, Text } from "@chakra-ui/react";
import {
Flex,
Heading,
IconButton,
Image,
Skeleton,
Text,
} from "@chakra-ui/react";
import { observer } from "mobx-react-lite";

import { useMobile, useMoveConfig } from "lib/app-provider";
Expand All @@ -13,6 +20,8 @@ import { PrimaryNameMark } from "lib/components/PrimaryNameMark";
import { TotalValue } from "lib/components/TotalValue";
import { useAccountStore } from "lib/providers/store";
import type { AccountData } from "lib/services/types";
import { useInitiaUsernameByAddress } from "lib/services/username";
import type { AccountLocalInfo } from "lib/stores/account";
import type { BechAddr, HexAddr, Option } from "lib/types";

interface AccounHeaderProps {
Expand All @@ -21,17 +30,90 @@ interface AccounHeaderProps {
hexAddress: HexAddr;
}

const AccountTitle = ({
accountData,
accountLocalInfo,
hexAddress,
}: {
accountData: Option<AccountData>;
accountLocalInfo: Option<AccountLocalInfo>;
hexAddress: HexAddr;
}) => {
const move = useMoveConfig({ shouldRedirect: false });
const { data, isLoading, isFetching } = useInitiaUsernameByAddress(
hexAddress,
move.enabled
);

const handleDisplayName = () => {
if (accountLocalInfo?.name) return accountLocalInfo.name;
if (accountData?.publicInfo?.name) return accountData?.publicInfo?.name;
if (accountData?.icns?.primaryName) return accountData?.icns?.primaryName;
if (move.enabled && data?.username) return data?.username;
return "Account Details";
};

const handleIcon = () => {
const altText =
accountData?.projectInfo?.name ?? accountData?.icns?.primaryName;

if (accountData?.projectInfo?.logo || accountData?.icns?.primaryName)
return (
<Image
src="https://assets.alleslabs.dev/webapp-assets/name-services/icns.png"
borderRadius="full"
alt={altText}
width={7}
height={7}
/>
);

if (move.enabled && data?.username && !accountLocalInfo?.name)
return (
<Image
src="https://assets.alleslabs.dev/webapp-assets/name-services/initia-username.svg"
borderRadius="full"
alt={altText}
width={6}
height={6}
mr={1}
/>
);

if (accountLocalInfo?.name)
return <CustomIcon name="bookmark" boxSize={5} color="secondary.main" />;
return <CustomIcon name="wallet" boxSize={5} color="secondary.main" />;
};

if (isLoading && isFetching)
return (
<Skeleton
h={6}
w={32}
borderRadius={4}
startColor="gray.500"
endColor="gray.700"
/>
);

return (
<Flex gap={1} align="center">
{handleIcon()}
<Heading as="h5" variant={{ base: "h6", md: "h5" }}>
{handleDisplayName()}
</Heading>
</Flex>
);
};

export const AccountHeader = observer(
({ accountData, accountAddress, hexAddress }: AccounHeaderProps) => {
const move = useMoveConfig({ shouldRedirect: false });
const { isAccountSaved, getAccountLocalInfo } = useAccountStore();
const { data } = useInitiaUsernameByAddress(hexAddress, move.enabled);

const isSaved = isAccountSaved(accountAddress);
const accountLocalInfo = getAccountLocalInfo(accountAddress);
const displayName =
accountLocalInfo?.name ??
accountData?.publicInfo?.name ??
(accountData?.icns?.primaryName || "Account Details");

const isMobile = useMobile();

Expand All @@ -43,29 +125,11 @@ export const AccountHeader = observer(
>
<Flex direction="column" gap={2} w={{ base: "full", lg: "auto" }}>
<Flex gap={4} align="center" minH="36px">
<Flex gap={1} align="center">
{accountData?.projectInfo?.logo ||
accountData?.icns?.primaryName ? (
<Image
src={
accountData?.projectInfo?.logo ??
"https://celatone-api.alleslabs.dev/images/entities/icns"
}
borderRadius="full"
alt={
accountData?.projectInfo?.name ??
accountData?.icns?.primaryName
}
width={7}
height={7}
/>
) : (
<CustomIcon name="wallet" boxSize={5} color="secondary.main" />
)}
<Heading as="h5" variant={{ base: "h6", md: "h5" }}>
{displayName}
</Heading>
</Flex>
<AccountTitle
accountData={accountData}
accountLocalInfo={accountLocalInfo}
hexAddress={hexAddress}
/>
{!isMobile && (
<>
{isSaved && accountLocalInfo ? (
Expand Down Expand Up @@ -147,6 +211,25 @@ export const AccountHeader = observer(
/>
</Flex>
)}
{accountLocalInfo?.name && (
<Flex
mt={{ base: 1, md: 0 }}
direction={{ base: "column", md: "row" }}
alignItems="center"
>
<Text fontWeight={500} color="text.dark" variant="body2" mr={2}>
Initia Username:
</Text>
<Image
src="https://assets.alleslabs.dev/webapp-assets/name-services/initia-username.svg"
borderRadius="full"
width={4}
height={4}
mr={1}
/>
<Text variant="body2">{data?.username}</Text>
</Flex>
)}
</Flex>
{accountData?.icns && (
<Flex gap={2} align="center">
Expand Down
Loading
Loading