) => {
+ if (event.key === 'Enter') {
+ event.preventDefault();
+ onComplete();
+ }
+ };
+ if (isEditingName) {
+ return (
+ <>
+
+
+
+
+ }
+ onClick={onComplete}
+ />
+ } onClick={onAbort} />
+
+ >
+ );
+ }
+ return (
+ <>
+ {displayName}
+ } onClick={onEdit} />
+ >
+ );
+}
+
+type AccountListItemProps = {
+ credential: WalletCredential;
+};
+
+function AccountListItem({ credential }: AccountListItemProps) {
const { t } = useTranslation('x', { keyPrefix: 'accounts' });
const nav = useNavigate();
const navToPrivateKey = () => nav(absoluteRoutes.settings.accounts.privateKey.path);
const navToConnectedSites = () => nav(absoluteRoutes.settings.accounts.connectedSites.path);
const navToIdCards = () => nav(absoluteRoutes.settings.idCards.path);
+ const identityName = useIdentityName(credential);
+ const accountInfo = useAccountInfo(credential);
+ const setAccount = useWritableSelectedAccount(credential.address);
+ const fallbackName = displaySplitAddress(credential.address);
+ const accountName = credential.credName !== '' ? credential.credName : fallbackName;
+ const { address } = credential;
+ const ccdBalance =
+ accountInfo === undefined ? 'Loading' : displayAsCcd(accountInfo.accountAmount.microCcdAmount, false);
+ const onNewAccountName = (newName: string) => setAccount({ credName: newName });
+ return (
+
+
+
+
+
+ {address}
+ copyToClipboard(address)} icon={} />
+
+
+ {t('ccdBalance')}
+ {ccdBalance}
+
+
+ {t('connectedSites')}
+ }
+ leftLabel
+ />
+
+
+ {t('privateKey')}
+ }
+ leftLabel
+ />
+
+
+ {t('attachedTo')}
+ }
+ leftLabel
+ />
+
+
+ );
+}
+
+export default function Accounts() {
+ const { t } = useTranslation('x', { keyPrefix: 'accounts' });
+ const accounts = useAtomValue(credentialsAtom);
return (
@@ -49,55 +168,8 @@ export default function Accounts() {
} />
- {ACCOUNT_LIST.map(({ account, address, balance, attached }) => (
-
-
- {account}
- } />
-
-
- {address}
- copyToClipboard(address)}
- icon={}
- />
-
-
- {t('totalBalance')}
- {balance} USD
-
-
- {t('connectedSites')}
- }
- leftLabel
- />
-
-
- {t('privateKey')}
- }
- leftLabel
- />
-
-
- {t('attachedTo')}
- }
- leftLabel
- />
-
-
+ {accounts.map((item) => (
+
))}
diff --git a/packages/browser-wallet/src/popup/popupX/pages/Accounts/i18n/en.ts b/packages/browser-wallet/src/popup/popupX/pages/Accounts/i18n/en.ts
index 9fb69e2de..96e7d0f0f 100644
--- a/packages/browser-wallet/src/popup/popupX/pages/Accounts/i18n/en.ts
+++ b/packages/browser-wallet/src/popup/popupX/pages/Accounts/i18n/en.ts
@@ -1,6 +1,6 @@
const t = {
accounts: 'Accounts',
- totalBalance: 'Total Balance',
+ ccdBalance: 'CCD Balance',
connectedSites: 'Connected sites',
seeList: 'See list',
privateKey: 'Private key',
diff --git a/packages/browser-wallet/src/popup/shared/utils/account-helpers.ts b/packages/browser-wallet/src/popup/shared/utils/account-helpers.ts
index 18d4e2816..10abf351d 100644
--- a/packages/browser-wallet/src/popup/shared/utils/account-helpers.ts
+++ b/packages/browser-wallet/src/popup/shared/utils/account-helpers.ts
@@ -10,15 +10,19 @@ import { isIdentityOfCredential } from '@shared/utils/identity-helpers';
import { getNextUnused } from '@shared/utils/number-helpers';
import { useDecryptedSeedPhrase } from './seed-phrase-helpers';
+/** Format an account address for display by showing the 4 first and last characters in the base58check representation. */
+export function displaySplitAddress(address: string) {
+ return `${address.slice(0, 4)}...${address.slice(-4)}`;
+}
+
export const displayNameOrSplitAddress = (account: WalletCredential | undefined) => {
const { credName, address } = account || { address: '' };
- return credName || `${address.slice(0, 4)}...${address.slice(address.length - 4)}`;
+ return credName || displaySplitAddress(address);
};
export const displayNameAndSplitAddress = (account: WalletCredential | undefined) => {
const { credName, address } = account || { address: '' };
- const splitAddress = `${address.slice(0, 4)}...${address.slice(address.length - 4)}`;
- return `${credName ? `${credName} / ` : ''}${splitAddress}`;
+ return `${credName ? `${credName} / ` : ''}${displaySplitAddress(address)}`;
};
export function useIdentityOf(cred?: WalletCredential) {
@@ -51,9 +55,11 @@ export function useIdentityName(credential: WalletCredential, fallback?: string)
export function useWritableSelectedAccount(accountAddress: string) {
const [accounts, setAccounts] = useAtom(writableCredentialAtom);
- const setAccount = (update: WalletCredential) =>
+ const setAccount = (update: Partial) =>
setAccounts(
- accounts.map((account) => (account.address === accountAddress ? { ...account, ...update } : account))
+ accounts.map((account) =>
+ account.address === accountAddress ? ({ ...account, ...update } as WalletCredential) : account
+ )
);
return setAccount;