Skip to content

Commit

Permalink
feature: add cspr name support (#1057)
Browse files Browse the repository at this point in the history
* add csprName support, update the home page and header, remove unused code

* added cspr name support to deploys list

* fix e2e tests

* fix onboarding e2e tests
  • Loading branch information
ost-ptk authored Sep 16, 2024
1 parent 3dfdb5c commit da427a5
Show file tree
Hide file tree
Showing 65 changed files with 681 additions and 813 deletions.
2 changes: 1 addition & 1 deletion e2e-tests/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const RECOVER_FIRST_ACCOUNT_FROM_TWELVE_WORDS = {
};

export const RECOVER_SECOND_ACCOUNT_FROM_TWELVE_WORDS = {
accountName: 'Account 1',
accountName: 'Account 2',
publicKey:
'02022cafccfb61ffc4e4221e4d2c38eec6035d579d04c1396b1c2027dc0729c53589',
truncatedPublicKey: '02022...53589'
Expand Down
24 changes: 18 additions & 6 deletions e2e-tests/onboarding-flow/recover-secret-phrase-flow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ onboarding.describe('Onboarding UI: recover secret phrase flow', () => {
await page.getByText('All accounts').click();

await onboardingExpect(
page.getByText(DEFAULT_FIRST_ACCOUNT.accountName)
page
.getByText(DEFAULT_FIRST_ACCOUNT.accountName, { exact: true })
.nth(1)
).toBeVisible();
await onboardingExpect(
page.getByText(DEFAULT_FIRST_ACCOUNT.truncatedPublicKey).nth(0)
Expand Down Expand Up @@ -100,10 +102,12 @@ onboarding.describe('Onboarding UI: recover secret phrase flow', () => {
await page.getByText('All accounts').click();

await onboardingExpect(
page.getByText(DEFAULT_FIRST_ACCOUNT.accountName)
page
.getByText(DEFAULT_FIRST_ACCOUNT.accountName, { exact: true })
.nth(1)
).toBeVisible();
await onboardingExpect(
page.getByText(DEFAULT_FIRST_ACCOUNT.truncatedPublicKey).nth(0)
page.getByText(DEFAULT_FIRST_ACCOUNT.truncatedPublicKey).nth(1)
).toBeVisible();
await onboardingExpect(
page.getByText(DEFAULT_SECOND_ACCOUNT.accountName)
Expand Down Expand Up @@ -158,7 +162,11 @@ onboarding.describe('Onboarding UI: recover secret phrase flow', () => {
await page.getByText('All accounts').click();

await onboardingExpect(
page.getByText(RECOVER_FIRST_ACCOUNT_FROM_TWELVE_WORDS.accountName)
page
.getByText(RECOVER_FIRST_ACCOUNT_FROM_TWELVE_WORDS.accountName, {
exact: true
})
.nth(1)
).toBeVisible();
await onboardingExpect(
page
Expand Down Expand Up @@ -213,12 +221,16 @@ onboarding.describe('Onboarding UI: recover secret phrase flow', () => {
await page.getByText('All accounts').click();

await onboardingExpect(
page.getByText(RECOVER_FIRST_ACCOUNT_FROM_TWELVE_WORDS.accountName)
page
.getByText(RECOVER_FIRST_ACCOUNT_FROM_TWELVE_WORDS.accountName, {
exact: true
})
.nth(1)
).toBeVisible();
await onboardingExpect(
page
.getByText(RECOVER_FIRST_ACCOUNT_FROM_TWELVE_WORDS.truncatedPublicKey)
.nth(0)
.nth(1)
).toBeVisible();
await onboardingExpect(
page.getByText(RECOVER_SECOND_ACCOUNT_FROM_TWELVE_WORDS.accountName)
Expand Down
8 changes: 6 additions & 2 deletions e2e-tests/popup/connect-account/connect-account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ popup.describe('Popup UI: connect account', () => {
page.getByRole('button', { name: 'Disconnect' })
).toBeVisible();
await popupExpect(
page.getByText(ACCOUNT_NAMES.defaultFirstAccountName)
page
.getByText(ACCOUNT_NAMES.defaultFirstAccountName, { exact: true })
.nth(1)
).toBeVisible();
}
);
Expand Down Expand Up @@ -98,7 +100,9 @@ popup.describe('Popup UI: connect account', () => {
page.getByRole('button', { name: 'Disconnect' })
).toBeVisible();
await popupExpect(
page.getByText(ACCOUNT_NAMES.defaultFirstAccountName)
page
.getByText(ACCOUNT_NAMES.defaultFirstAccountName, { exact: true })
.nth(1)
).toBeVisible();
await popupExpect(
page.getByText(ACCOUNT_NAMES.defaultSecondAccountName)
Expand Down
31 changes: 24 additions & 7 deletions e2e-tests/popup/contacts/contacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ popup.describe('Popup UI: contacts', () => {
).toBeVisible();

await popupExpect(
popupPage.getByText(DEFAULT_FIRST_ACCOUNT.accountName)
popupPage
.getByText(DEFAULT_FIRST_ACCOUNT.accountName, { exact: true })
.nth(1)
).toBeVisible();

await popupExpect(
Expand Down Expand Up @@ -135,7 +137,10 @@ popup.describe('Popup UI: contacts', () => {
await unlockVault();
await addContact();

await popupPage.getByText(DEFAULT_FIRST_ACCOUNT.accountName).click();
await popupPage
.getByText(DEFAULT_FIRST_ACCOUNT.accountName, { exact: true })
.nth(1)
.click();

await popupExpect(
popupPage.getByRole('heading', {
Expand All @@ -144,7 +149,9 @@ popup.describe('Popup UI: contacts', () => {
).toBeVisible();

await popupExpect(
popupPage.getByText(DEFAULT_FIRST_ACCOUNT.publicKey)
popupPage
.getByText(DEFAULT_FIRST_ACCOUNT.publicKey, { exact: true })
.nth(1)
).toBeVisible();
}
);
Expand All @@ -155,7 +162,10 @@ popup.describe('Popup UI: contacts', () => {
await unlockVault();
await addContact();

await popupPage.getByText(DEFAULT_FIRST_ACCOUNT.accountName).click();
await popupPage
.getByText(DEFAULT_FIRST_ACCOUNT.accountName, { exact: true })
.nth(1)
.click();

await popupPage.getByTestId('edit-contact-button').click();

Expand Down Expand Up @@ -190,7 +200,9 @@ popup.describe('Popup UI: contacts', () => {
await popupPage.getByRole('button', { name: 'Save' }).click();

await popupExpect(
popupPage.getByText(DEFAULT_FIRST_ACCOUNT.accountName)
popupPage
.getByText(DEFAULT_FIRST_ACCOUNT.accountName, { exact: true })
.nth(1)
).not.toBeVisible();

await popupPage.getByText(DEFAULT_SECOND_ACCOUNT.accountName).click();
Expand All @@ -213,7 +225,10 @@ popup.describe('Popup UI: contacts', () => {
await unlockVault();
await addContact();

await popupPage.getByText(DEFAULT_FIRST_ACCOUNT.accountName).click();
await popupPage
.getByText(DEFAULT_FIRST_ACCOUNT.accountName, { exact: true })
.nth(1)
.click();

await popupPage.getByTestId('delete-contact-button').click();

Expand All @@ -233,7 +248,9 @@ popup.describe('Popup UI: contacts', () => {
await popupPage.getByRole('button', { name: 'Delete' }).click();

await popupExpect(
popupPage.getByText(DEFAULT_FIRST_ACCOUNT.accountName)
popupPage
.getByText(DEFAULT_FIRST_ACCOUNT.accountName, { exact: true })
.nth(1)
).not.toBeVisible();
}
);
Expand Down
12 changes: 9 additions & 3 deletions e2e-tests/popup/disconnect-account/disconnect-account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ popup.describe('Popup UI: disconnect account', () => {
await popupPage.getByText('Connected sites').click();

await popupExpect(
popupPage.getByText(ACCOUNT_NAMES.defaultFirstAccountName)
popupPage
.getByText(ACCOUNT_NAMES.defaultFirstAccountName, { exact: true })
.nth(1)
).toBeVisible();
await popupExpect(
popupPage.getByText(ACCOUNT_NAMES.defaultSecondAccountName)
Expand All @@ -40,7 +42,9 @@ popup.describe('Popup UI: disconnect account', () => {
await disconnectIcons[0].click();

await popupExpect(
popupPage.getByText(ACCOUNT_NAMES.defaultFirstAccountName)
popupPage
.getByText(ACCOUNT_NAMES.defaultFirstAccountName, { exact: true })
.nth(1)
).not.toBeVisible();
await popupExpect(
popupPage.getByText(ACCOUNT_NAMES.defaultSecondAccountName)
Expand All @@ -55,7 +59,9 @@ popup.describe('Popup UI: disconnect account', () => {
await popupPage.getByText('Connected sites').click();

await popupExpect(
popupPage.getByText(ACCOUNT_NAMES.defaultFirstAccountName)
popupPage
.getByText(ACCOUNT_NAMES.defaultFirstAccountName, { exact: true })
.nth(1)
).toBeVisible();
await popupExpect(
popupPage.getByText(ACCOUNT_NAMES.defaultSecondAccountName)
Expand Down
3 changes: 2 additions & 1 deletion e2e-tests/popup/rename-account/rename-account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ popup.describe('Popup UI: rename account', () => {
async ({ popupPage, unlockVault }) => {
await unlockVault();

await popupPage.getByTestId('popover-children-container').click();
await popupPage.getByTestId('connection-status-modal').click();
await popupPage.getByTestId('popover-children-container').nth(0).click();

await popupPage.getByText('Rename').click();

Expand Down
24 changes: 16 additions & 8 deletions src/apps/popup/pages/account-settings/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import {
selectVaultLedgerAccountNames
} from '@background/redux/vault/selectors';

import { useFetchAccountInfo } from '@hooks/use-fetch-account-info';

import { getAccountHashFromPublicKey } from '@libs/entities/Account';
import {
ContentContainer,
Expand All @@ -27,6 +25,7 @@ import {
TileContainer,
VerticalSpaceContainer
} from '@libs/layout';
import { useFetchAccountInfo } from '@libs/services/account-info';
import {
Hash,
HashVariant,
Expand All @@ -49,19 +48,16 @@ export function AccountSettingsPageContent() {
}

const accountHash = getAccountHashFromPublicKey(account.publicKey);
const { accountInfoStandardName } = useFetchAccountInfo(account);
const accountInfo = useFetchAccountInfo([account.publicKey]);

const csprName = accountInfo && accountInfo[accountHash]?.csprName;

return (
<>
<ContentContainer>
<Tile>
<TileContainer paddingVertical={SpacingSize.XL}>
<Typography type="header">{account.name}</Typography>
{accountInfoStandardName && (
<Typography type="body" ellipsis>
{accountInfoStandardName}
</Typography>
)}
<VerticalSpaceContainer top={SpacingSize.XL}>
<QRCodeCanvas
id="qrCode"
Expand All @@ -83,6 +79,18 @@ export function AccountSettingsPageContent() {
/>
</FlexColumn>
</VerticalSpaceContainer>
{csprName ? (
<VerticalSpaceContainer top={SpacingSize.XL}>
<FlexColumn gap={SpacingSize.Small}>
<Typography type="bodySemiBold">
<Trans t={t}>CSPR.name</Trans>
</Typography>
<Typography type="captionRegular" color="contentSecondary">
{csprName}
</Typography>
</FlexColumn>
</VerticalSpaceContainer>
) : null}
<VerticalSpaceContainer top={SpacingSize.XL}>
<FlexColumn gap={SpacingSize.Small}>
<Typography type="bodySemiBold">
Expand Down
16 changes: 13 additions & 3 deletions src/apps/popup/pages/all-accounts/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,29 @@ import { useSelector } from 'react-redux';

import {
selectConnectedAccountNamesWithActiveOrigin,
selectVaultAccountsPublicKeys,
selectVaultActiveAccountName,
selectVaultHiddenAccounts,
selectVaultVisibleAccounts
} from '@background/redux/vault/selectors';

import { getAccountHashFromPublicKey } from '@libs/entities/Account';
import { ContentContainer, SpacingSize } from '@libs/layout';
import { AccountListRows } from '@libs/types/account';
import { useFetchAccountInfo } from '@libs/services/account-info';
import {
AccountListRowWithAccountHash,
AccountListRows
} from '@libs/types/account';
import { List } from '@libs/ui/components';
import { AccountListItem } from '@libs/ui/components/account-list/account-list-item';
import { sortAccounts } from '@libs/ui/components/account-list/utils';

export const AllAccountsContent = () => {
const [visibleAccountsWithId, setVisibleAccountsWithId] = useState<
AccountListRows[]
AccountListRowWithAccountHash<AccountListRows>[]
>([]);
const [hiddenAccountsWithId, setHiddeAccountsWithId] = useState<
AccountListRows[]
AccountListRowWithAccountHash<AccountListRows>[]
>([]);

const { t } = useTranslation();
Expand All @@ -31,6 +36,9 @@ export const AllAccountsContent = () => {
const connectedAccountNames =
useSelector(selectConnectedAccountNamesWithActiveOrigin) || [];
const activeAccountName = useSelector(selectVaultActiveAccountName);
const accountsPublicKeys = useSelector(selectVaultAccountsPublicKeys);

const accountInfo = useFetchAccountInfo(accountsPublicKeys);

useEffect(() => {
const visibleAccountListRows = sortAccounts(
Expand Down Expand Up @@ -77,6 +85,7 @@ export const AllAccountsContent = () => {
isActiveAccount={isActiveAccount}
isConnected={isConnected}
showHideAccountItem
accountInfo={accountInfo}
/>
);
}}
Expand All @@ -97,6 +106,7 @@ export const AllAccountsContent = () => {
isActiveAccount={false}
isConnected={isConnected}
showHideAccountItem
accountInfo={accountInfo}
/>
);
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React from 'react';
import { useSelector } from 'react-redux';
import styled from 'styled-components';

import { RouterPath, useTypedNavigate } from '@popup/router';

import { selectAllPublicKeys } from '@background/redux/contacts/selectors';

import { AlignedFlexRow, FlexColumn, SpacingSize } from '@libs/layout';
import { useFetchAccountInfo } from '@libs/services/account-info';
import { Avatar, Hash, HashVariant, Typography } from '@libs/ui/components';

const Container = styled(AlignedFlexRow)`
Expand All @@ -15,23 +19,40 @@ const Container = styled(AlignedFlexRow)`
interface ContactsPlateProps {
publicKey: string;
name: string;
accountHash: string;
}

export const ContactsPlate = ({ publicKey, name }: ContactsPlateProps) => {
export const ContactsPlate = ({
publicKey,
name,
accountHash
}: ContactsPlateProps) => {
const navigate = useTypedNavigate();

const contactPublicKeys = useSelector(selectAllPublicKeys);
const accountInfo = useFetchAccountInfo(contactPublicKeys);

const csprName = accountInfo && accountInfo[accountHash]?.csprName;
const brandingLogo = accountInfo && accountInfo[accountHash]?.brandingLogo;

return (
<Container
gap={SpacingSize.Medium}
onClick={() => {
navigate(RouterPath.ContactDetails.replace(':contactName', name));
}}
>
<Avatar publicKey={publicKey} size={24} borderRadius={2} />
<Avatar
publicKey={publicKey}
size={24}
borderRadius={2}
brandingLogo={brandingLogo}
/>
<FlexColumn>
<Typography type="captionRegular">{name}</Typography>
<Hash
value={publicKey}
csprName={csprName}
variant={HashVariant.CaptionHash}
truncatedSize="medium"
truncated
Expand Down
Loading

0 comments on commit da427a5

Please sign in to comment.