Skip to content

Commit

Permalink
Merge pull request #68 from vechain/feat/style-choose-name
Browse files Browse the repository at this point in the history
Feat/style choose name
  • Loading branch information
Agilulfo1820 authored Feb 7, 2025
2 parents ae07517 + a0d256d commit dcf70f4
Show file tree
Hide file tree
Showing 23 changed files with 327 additions and 108 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use client';

import { Text, Icon, HStack, Button, Image } from '@chakra-ui/react';
import { Text, Icon, HStack, Button } from '@chakra-ui/react';
import { humanAddress, humanDomain } from '../../../utils';
import { Wallet } from '@/types';
import { MdOutlineNavigateNext } from 'react-icons/md';
import { AccountAvatar } from '@/components/common';

type Props = {
wallet: Wallet;
Expand All @@ -30,12 +31,9 @@ export const AccountSelector = ({
variant="vechainKitSelector"
>
<HStack spacing={2} align="center">
<Image
src={wallet?.image}
alt={wallet?.domain}
width={5}
height={5}
rounded="full"
<AccountAvatar
wallet={wallet}
props={{ width: 5, height: 5 }}
/>
<Text fontSize={size} fontWeight="500">
{humanDomain(wallet?.domain ?? '', 6, 4) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const ActionButton = ({
borderRadius={'full'}
alt="left-image"
alignSelf={'end'}
objectFit="cover"
/>
) : (
<Icon as={leftIcon} fontSize={'25px'} />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
Alert,
AlertIcon,
Text,
Button,
VStack,
HStack,
} from '@chakra-ui/react';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';

export const ExchangeWarningAlert = () => {
const { t } = useTranslation();
const [showFullText, setShowFullText] = useState(false);

return (
<Alert status="warning" fontSize={'xs'} borderRadius={'xl'} p={2}>
<VStack spacing={1} align="stretch" w="full">
<HStack spacing={2} align="flex-start">
<AlertIcon boxSize={4} />
<Text w="full">
{t(
'Sending to OceanX or other exchanges may result in loss of funds.',
)}
{showFullText &&
t('Send the tokens to your VeWorld wallet first.')}
<Button
variant="link"
size="xs"
onClick={() => setShowFullText(!showFullText)}
color="inherit"
pl={6}
mt={0}
>
{t(showFullText ? 'Show Less' : 'Read More')}
</Button>
</Text>
</HStack>
</VStack>
</Alert>
);
};
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './FeatureAnnouncementCard';
export * from './ExchangeWarningAlert';
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
Image,
ModalBody,
ModalCloseButton,
VStack,
Expand All @@ -17,6 +16,7 @@ import {
import { MdOutlineNavigateNext } from 'react-icons/md';
import { ActionButton } from '@/components';
import {
AccountAvatar,
AddressDisplay,
ModalBackButton,
StickyHeaderContainer,
Expand Down Expand Up @@ -78,11 +78,7 @@ export const WalletSettingsContent = ({

<ModalBody w={'full'}>
<VStack justify={'center'}>
<Image
src={account?.image}
maxW={'100px'}
borderRadius="50%"
/>
<AccountAvatar wallet={account} props={{ maxW: '100px' }} />
<AddressDisplay wallet={account} />
{network.type !== 'main' && (
<Tag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import {
Button,
ModalFooter,
InputRightElement,
List,
ListItem,
Tag,
HStack,
} from '@chakra-ui/react';
import { ModalBackButton, StickyHeaderContainer } from '@/components/common';
import { AccountModalContentTypes } from '../../Types';
Expand All @@ -27,6 +23,7 @@ import {
} from '@/hooks';
import { useTranslation } from 'react-i18next';
import { useVeChainKitConfig } from '@/providers';
import { ExistingDomainsList } from './Components/ExistingDomainsList';

export type ChooseNameSearchContentProps = {
name: string;
Expand Down Expand Up @@ -166,69 +163,13 @@ export const ChooseNameSearchContent = ({
</StickyHeaderContainer>

<ModalBody>
{isLoadingOwnedDomains ? (
<Text fontSize="sm" color="gray.500">
{t('Loading your domains...')}
</Text>
) : allUserDomains.length > 0 ? (
<VStack spacing={4} align="stretch" mb={6}>
<Text
fontSize="sm"
fontWeight="500"
color={isDark ? 'whiteAlpha.800' : 'gray.600'}
>
{t('Your existing domains')}
</Text>
<List spacing={2}>
{allUserDomains.map((domain) => {
const isCurrentDomain =
domain.name === account?.domain;
return (
<ListItem
key={domain.name}
p={3}
bg={isDark ? '#1a1a1a' : 'gray.50'}
borderRadius="md"
cursor={
isCurrentDomain
? 'default'
: 'pointer'
}
opacity={isCurrentDomain ? 0.7 : 1}
_hover={{
bg: isCurrentDomain
? isDark
? '#1a1a1a'
: 'gray.50'
: isDark
? '#252525'
: 'gray.100',
}}
onClick={() =>
!isCurrentDomain &&
handleDomainSelect(domain.name)
}
>
<HStack justify="space-between">
<Text>{domain.name}</Text>
{isCurrentDomain && (
<Tag
size="sm"
colorScheme="green"
variant="subtle"
>
{t('Current')}
</Tag>
)}
</HStack>
</ListItem>
);
})}
</List>
</VStack>
) : null}

<VStack spacing={4} align="stretch">
<ExistingDomainsList
domains={allUserDomains}
onDomainSelect={handleDomainSelect}
isLoading={isLoadingOwnedDomains}
/>

<InputGroup size="lg">
<Input
placeholder={t('Enter your name')}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
import {
Accordion,
AccordionItem,
AccordionButton,
AccordionPanel,
Box,
Text,
Icon,
List,
ListItem,
Tag,
HStack,
VStack,
} from '@chakra-ui/react';
import { useTranslation } from 'react-i18next';
import { IoChevronDown, IoChevronUp } from 'react-icons/io5';
import { useVeChainKitConfig } from '@/providers';
import { useWallet } from '@/hooks';
import { useWalletMetadata } from '@/hooks/api/wallet/useWalletMetadata';
import { AccountAvatar } from '@/components/common';

type ExistingDomainsListProps = {
domains: { name: string }[];
onDomainSelect: (domain: string) => void;
isLoading?: boolean;
};

export const ExistingDomainsList = ({
domains,
onDomainSelect,
isLoading,
}: ExistingDomainsListProps) => {
const { t } = useTranslation();
const { darkMode: isDark } = useVeChainKitConfig();
const { account, connection } = useWallet();

// avoid flickering after loading by returning null, so if no domains are found, it will not show the accordion
if (domains.length === 0 || isLoading) {
return null;
}

return (
<Accordion allowToggle>
<AccordionItem border="none">
{({ isExpanded }) => (
<>
<AccordionButton
bg={isDark ? 'whiteAlpha.50' : 'gray.50'}
borderRadius="xl"
_hover={{
bg: isDark ? 'whiteAlpha.100' : 'gray.100',
}}
opacity={isLoading ? 0.7 : 1}
transition="all 0.2s"
disabled={isLoading}
>
<Box flex="1" textAlign="left" py={2}>
<Text fontWeight="500">
{isLoading
? t('Loading your domains...')
: `${t('Your existing domains')} (${
domains.length
})`}
</Text>
</Box>
<Icon
as={isExpanded ? IoChevronUp : IoChevronDown}
fontSize="20px"
opacity={0.5}
/>
</AccordionButton>
<AccordionPanel pb={4} pt={2}>
<List spacing={2}>
{domains.map((domain) => {
const isCurrentDomain =
domain.name === account?.domain;
const metadata = useWalletMetadata(
domain.name,
connection.network,
);
return (
<ListItem
key={domain.name}
p={4}
bg={isDark ? '#1f1f1e' : 'white'}
borderRadius="xl"
cursor={
isCurrentDomain
? 'default'
: 'pointer'
}
opacity={isCurrentDomain ? 0.7 : 1}
border={`1px solid ${
isDark ? '#2d2d2d' : '#eaeaea'
}`}
_hover={{
bg: isCurrentDomain
? isDark
? '#1f1f1e'
: 'white'
: isDark
? '#252525'
: 'gray.50',
borderColor: isDark
? '#3d3d3d'
: '#dedede',
}}
onClick={() =>
!isCurrentDomain &&
onDomainSelect(domain.name)
}
transition="all 0.2s"
>
<HStack spacing={3} align="center">
<AccountAvatar
props={{
width: '40px',
height: '40px',
src: metadata.image,
alt: domain.name,
}}
/>

<VStack
align="start"
spacing={0}
flex={1}
>
<Text
color={
isDark
? 'whiteAlpha.900'
: 'gray.700'
}
fontSize="md"
fontWeight="500"
>
{domain.name}
</Text>
{isCurrentDomain && (
<Text
fontSize="sm"
color={
isDark
? 'whiteAlpha.600'
: 'gray.500'
}
>
{t(
'Current domain',
)}
</Text>
)}
</VStack>

{isCurrentDomain && (
<Tag
size="sm"
bg={
isDark
? 'whiteAlpha.200'
: 'gray.100'
}
color={
isDark
? 'whiteAlpha.800'
: 'gray.600'
}
px={3}
py={1}
borderRadius="full"
>
{t('Current')}
</Tag>
)}
</HStack>
</ListItem>
);
})}
</List>
</AccordionPanel>
</>
)}
</AccordionItem>
</Accordion>
);
};
Loading

0 comments on commit dcf70f4

Please sign in to comment.