Skip to content

Commit

Permalink
Merge pull request #462 from trilitech/remove-get-icons-pt2
Browse files Browse the repository at this point in the history
Remove get icons pt2
  • Loading branch information
ryutamago authored Sep 27, 2023
2 parents 3917377 + 5858726 commit 887e147
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import SignPage from "../../../SendFlow/Multisig/SignPage";
import { useSelectedNetwork } from "../../../../utils/hooks/networkHooks";
import { parseRawMichelson } from "../../../../multisig/decode/decodeLambda";
import useAddressKind from "../../../AddressTile/useAddressKind";
import { AccountTileBase, LabelAndAddress } from "../../../AccountTile/AccountTileDisplay";
import { AccountTileBase, LabelAndAddress } from "../../../AccountTile/AccountTile";
import AccountTileIcon from "../../../AccountTile/AccountTileIcon";

const MultisigSignerTile: React.FC<{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { AccountType } from "../../../../types/Account";
import { AccountTileBase, LabelAndAddress } from "../../../AccountTile/AccountTileDisplay";
import { AccountTileBase, LabelAndAddress } from "../../../AccountTile/AccountTile";
import MultisigActionButton, { MultisigSignerState } from "./MultisigActionButton";
import { AddressKind } from "../../../AddressTile/types";
import AccountTileIcon from "../../../AccountTile/AccountTileIcon";
Expand Down
42 changes: 42 additions & 0 deletions src/components/AccountTile/AccountTile.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { mockImplicitAccount, mockMultisigAccount } from "../../mocks/factories";
import { render, screen } from "../../mocks/testUtils";
import { AccountType } from "../../types/Account";
import accountsSlice from "../../utils/redux/slices/accountsSlice";
import { multisigActions } from "../../utils/redux/slices/multisigsSlice";
import store from "../../utils/redux/store";
import { AccountTile } from "./AccountTile";
describe("<AccountTile />", () => {
describe("icon and label", () => {
it("mnemonic account", () => {
const implicitAccount0 = mockImplicitAccount(0);
store.dispatch(accountsSlice.actions.addAccount([implicitAccount0]));
render(<AccountTile address={implicitAccount0.address.pkh} balance="3" />);
expect(screen.getByTestId("identicon")).toBeInTheDocument();
expect(screen.getByText("Account 0")).toBeTruthy();
});

it("ledger account", () => {
const implicitAccount0 = mockImplicitAccount(0, AccountType.LEDGER);
store.dispatch(accountsSlice.actions.addAccount([implicitAccount0]));
render(<AccountTile address={implicitAccount0.address.pkh} balance="3" />);
expect(screen.getByTestId("ledger-icon")).toBeInTheDocument();
expect(screen.getByText("Account 0 ledger")).toBeTruthy();
});

it("social account", () => {
const implicitAccount0 = mockImplicitAccount(0, AccountType.SOCIAL);
store.dispatch(accountsSlice.actions.addAccount([implicitAccount0]));
render(<AccountTile address={implicitAccount0.address.pkh} balance="3" />);
expect(screen.getByTestId("social-icon")).toBeInTheDocument();
expect(screen.getByText("google Account 0")).toBeTruthy();
});

it("multisig account", () => {
const multisig = mockMultisigAccount(0);
store.dispatch(multisigActions.setMultisigs([multisig]));
render(<AccountTile address={multisig.address.pkh} balance="3" />);
expect(screen.getByTestId("key-icon")).toBeInTheDocument();
expect(screen.getByText("label")).toBeTruthy();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { Box, Flex, FlexProps, Heading, Text } from "@chakra-ui/layout";
import React from "react";
import colors from "../../style/colors";
import { AccountType } from "../../types/Account";
import { formatPkh } from "../../utils/formatPkh";
import { getIcon } from "./getIcon";
import { prettyTezAmount } from "../../utils/format";

export type Props = {
label: string;
address: string;
balance: string | undefined;
onClick?: React.MouseEventHandler<HTMLDivElement>;
selected?: boolean;
kind: AccountType;
};
import useAddressKind from "../AddressTile/useAddressKind";
import { RawPkh, parsePkh } from "../../types/Address";
import AccountTileIcon from "./AccountTileIcon";

export const AccountTileBase: React.FC<
{
Expand Down Expand Up @@ -58,16 +50,14 @@ export const LabelAndAddress: React.FC<{ label: string | null; pkh: string }> =
);
};

export const AccountTileDisplay: React.FC<Props> = ({
selected,
onClick,
address,
balance,
label,
kind,
}) => {
export const AccountTile: React.FC<{
address: RawPkh;
balance: string | undefined;
onClick?: React.MouseEventHandler<HTMLDivElement>;
selected?: boolean;
}> = ({ selected, onClick, address, balance }) => {
const border = onClick ? `1px solid ${selected ? colors.orangeL : colors.gray[700]}` : undefined;

const addressKind = useAddressKind(parsePkh(address));
return (
<AccountTileBase
data-testid={`account-tile-${address}` + (selected ? "-selected" : "")}
Expand All @@ -78,8 +68,8 @@ export const AccountTileDisplay: React.FC<Props> = ({
_hover={{
border,
}}
icon={getIcon(kind, address)}
leftElement={<LabelAndAddress pkh={address} label={label} />}
icon={<AccountTileIcon addressKind={addressKind} />}
leftElement={<LabelAndAddress pkh={address} label={addressKind.label} />}
rightElement={
balance && (
<Heading mb={4} alignSelf="flex-end" size="lg">
Expand Down
17 changes: 0 additions & 17 deletions src/components/AccountTile/AccountTileDisplay.test.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions src/components/AccountTile/AddressKind.tsx

This file was deleted.

73 changes: 0 additions & 73 deletions src/components/AccountTile/getIcon.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/style/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const theme = extendTheme({
FormLabel: {
baseStyle: {
fontWeight: "600",
marginBottom: "4px",
marginBottom: "12px",
size: "md",
},
sizes,
Expand Down
6 changes: 2 additions & 4 deletions src/views/home/AccountsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { deriveAccount } from "../../utils/redux/thunks/restoreMnemonicAccounts"
import AccountPopover from "./AccountPopover";
import DeriveAccountDisplay from "./DeriveAccountDisplay.tsx";
import { FormPage } from "../../components/SendFlow/MultisigAccount/FormPage";
import { AccountTileDisplay } from "../../components/AccountTile/AccountTileDisplay";
import { AccountTile } from "../../components/AccountTile/AccountTile";
import colors from "../../style/colors";

export const AccountListHeader = () => {
Expand Down Expand Up @@ -71,13 +71,11 @@ const AccountGroup: React.FC<{

{accounts.map(account => {
return (
<AccountTileDisplay
kind={account.type}
<AccountTile
selected={account.address.pkh === selected}
onClick={_ => onSelect(account.address.pkh)}
key={account.address.pkh}
address={account.address.pkh}
label={account.label}
balance={balances[account.address.pkh]}
/>
);
Expand Down

0 comments on commit 887e147

Please sign in to comment.