Skip to content

Commit

Permalink
merge: #1 from feat/mono-account-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmemorygrinder authored Jun 21, 2024
2 parents db64c0c + 888d3a3 commit 07695fc
Show file tree
Hide file tree
Showing 67 changed files with 337 additions and 2,363 deletions.
467 changes: 11 additions & 456 deletions README.md

Large diffs are not rendered by default.

95 changes: 12 additions & 83 deletions packages/dapp/src/components/AccountMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,100 +1,29 @@
import { AddIcon, ChevronDownIcon, DownloadIcon } from '@chakra-ui/icons';
import { DownloadIcon } from '@chakra-ui/icons';
import {
Menu,
MenuButton,
MenuList,
MenuItem,
Button,
Flex,
useDisclosure,
Spinner,
Text,
useColorModeValue,
Box,
IconButton,
} from '@chakra-ui/react';

import { GenerateAccountModal } from './GenerateAccountModal';
import { ImportAccountModal } from './ImportAccountModal';

import { useAccountList } from '@/hooks/useAccountList';
import {
useActiveAccount,
invalidateActiveAccount,
} from '@/hooks/useActiveAccount';
import { invalidateOperations } from '@/hooks/useOperations';
import { useSetActiveAccount } from '@/hooks/useSetActiveAccount';
import { useShowCredentials } from '@/hooks/useShowCredentials';
import { invalidateTokens } from '@/hooks/useTokens';

export const AccountMenu = () => {
const {
isOpen: isImportOpen,
onOpen: onImportOpen,
onClose: onImportClose,
} = useDisclosure();
const {
isOpen: isGenerateOpen,
onOpen: onGenerateOpen,
onClose: onGenerateClose,
} = useDisclosure();
const showIconBg = useColorModeValue('gray.100', 'gray.600');

const { isLoading: accountsListLoading, data: accountsList } =
useAccountList();
const { isLoading: activeAccountLoading, data: activeAccount } =
useActiveAccount();
const setActiveAccount = useSetActiveAccount();
const showCredentials = useShowCredentials();

return (
<Menu>
<MenuButton
as={Button}
disabled={activeAccountLoading || accountsListLoading}
rightIcon={<ChevronDownIcon />}
>
{activeAccountLoading ? <Spinner /> : activeAccount?.name}
</MenuButton>
<MenuList>
{!accountsListLoading &&
accountsList?.map((account) => (
<MenuItem
key={account!.address}
onClick={() =>
setActiveAccount({ address: account!.address })?.then(() => {
invalidateActiveAccount();
invalidateOperations();
invalidateTokens();
})
}
>
<Flex justify={'space-between'} align={'center'} w={'full'}>
<Text flexGrow={1}>{account!.name}</Text>
<Box
borderRadius={'lg'}
bg={showIconBg}
p={2}
onClick={(evt) => {
evt.preventDefault();
showCredentials({ address: account!.address });
}}
>
<DownloadIcon />
</Box>
</Flex>
</MenuItem>
))}
<Flex justifyContent={'space-between'} m={4} gap={4}>
<Button onClick={onImportOpen} leftIcon={<DownloadIcon />}>
Import Account
</Button>
<Button onClick={onGenerateOpen} leftIcon={<AddIcon />}>
Generate Account
</Button>
</Flex>
</MenuList>
<ImportAccountModal isOpen={isImportOpen} onClose={onImportClose} />
<GenerateAccountModal isOpen={isGenerateOpen} onClose={onGenerateClose} />
</Menu>
<>
{activeAccountLoading ? (
<Spinner />
) : (
<IconButton onClick={(evt) => {
evt.preventDefault();
showCredentials({ address: activeAccount?.address});
}} icon={<DownloadIcon />} aria-label={''} />
)}
</>
);
};
78 changes: 0 additions & 78 deletions packages/dapp/src/components/GenerateAccountModal.tsx

This file was deleted.

12 changes: 9 additions & 3 deletions packages/dapp/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const Header = () => {
<Flex
justifyContent={{ base: 'center', lg: 'space-between' }}
w={'full'}
id="header"
p={5}
flexWrap={'wrap'}
bg={'grey.100'}
Expand All @@ -40,7 +41,7 @@ export const Header = () => {
</Flex>
</Show>
</Flex>
<Show below="md">
<Show below="lg">
<Flex
gap={4}
align={'center'}
Expand All @@ -50,8 +51,13 @@ export const Header = () => {
>
<ThemeSwitch />
{!ready && <ConnectMetamaskButton />}
{ready && <AccountMenu />}
{ready && <NetworkMenu />}

{ready && (
<Flex gap={4}>
<AccountMenu />
<NetworkMenu />
</Flex>
)}
</Flex>
</Show>
</>
Expand Down
111 changes: 0 additions & 111 deletions packages/dapp/src/components/ImportAccountModal.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion packages/dapp/src/components/OperationTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const OperationTab = () => {
<IconButton
aria-label="delete-all"
icon={<DeleteIcon />}
onClick={() => clearOperations({})}
onClick={() => clearOperations()}
/>
<IconButton
aria-label="Refresh"
Expand Down
1 change: 0 additions & 1 deletion packages/dapp/src/components/TokenRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export const TokenRow = ({ token }: { token: string }) => {
icon={<DeleteIcon />}
onClick={() => {
deleteToken({
accountAddress: account!.address,
address: token,
}).then(() => {
invalidateTokens();
Expand Down
10 changes: 4 additions & 6 deletions packages/dapp/src/components/TokenTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export const TokenTab = () => {
useActiveAccount();
const { isLoading: isLoadingTokenList, data: tokenList } = useTokens();
const { isLoading: isLoadingAccountBalance, data: accountBalance } =
useAccountBalance({ address: activeAccount?.address });
useAccountBalance({
address: activeAccount?.address,
});
const { colorMode } = useColorMode();
const headerBg = useColorModeValue('teal.400', 'teal.600');
const sendButtonBg = useColorModeValue('gray.400', 'gray.600');
Expand All @@ -74,11 +76,7 @@ export const TokenTab = () => {
>
<Flex justifyContent={'space-between'} align={'center'}>
<Heading pl={3}>
{isLoadingActiveAccount ? (
<Spinner />
) : (
activeAccount?.name || 'My Account'
)}
{isLoadingActiveAccount ? <Spinner /> : 'My Account'}
</Heading>
<Flex justify={'space-between'} align={'center'} mt={2}>
<Link
Expand Down
Loading

0 comments on commit 07695fc

Please sign in to comment.