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: mono account refactor #1

Merged
merged 7 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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 {

Check failure on line 2 in packages/dapp/src/components/AccountMenu.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

Replace `⏎··Spinner,⏎··IconButton,⏎` with `·Spinner,·IconButton·`
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 {

Check failure on line 7 in packages/dapp/src/components/AccountMenu.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

Replace `⏎··useActiveAccount,⏎` with `·useActiveAccount·`
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) => {

Check failure on line 22 in packages/dapp/src/components/AccountMenu.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

Insert `⏎·········`
evt.preventDefault();

Check failure on line 23 in packages/dapp/src/components/AccountMenu.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

Insert `··`
showCredentials({ address: activeAccount?.address});

Check failure on line 24 in packages/dapp/src/components/AccountMenu.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

Replace `showCredentials({·address:·activeAccount?.address` with `··showCredentials({·address:·activeAccount?.address·`
}} icon={<DownloadIcon />} aria-label={''} />

Check failure on line 25 in packages/dapp/src/components/AccountMenu.tsx

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

Replace `}}·icon={<DownloadIcon·/>}·aria-label={''}` with `··}}⏎··········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
Loading