feat: add alias to wallet menu

This commit is contained in:
Matthew Russell 2024-03-07 14:51:57 +00:00
parent 5e435a8537
commit 474b66bbff
No known key found for this signature in database

View File

@ -12,6 +12,8 @@ import CopyToClipboard from 'react-copy-to-clipboard';
import { ViewType, useSidebar } from '../sidebar'; import { ViewType, useSidebar } from '../sidebar';
import { useGetCurrentRouteId } from '../../lib/hooks/use-get-current-route-id'; import { useGetCurrentRouteId } from '../../lib/hooks/use-get-current-route-id';
import { useT } from '../../lib/use-t'; import { useT } from '../../lib/use-t';
import { usePartyProfilesQuery } from '../vega-wallet-connect-button/__generated__/PartyProfiles';
import { useProfileDialogStore } from '../../stores/profile-dialog-store';
export const VegaWalletMenu = ({ export const VegaWalletMenu = ({
setMenu, setMenu,
@ -23,6 +25,11 @@ export const VegaWalletMenu = ({
const currentRouteId = useGetCurrentRouteId(); const currentRouteId = useGetCurrentRouteId();
const setViews = useSidebar((store) => store.setViews); const setViews = useSidebar((store) => store.setViews);
const { data } = usePartyProfilesQuery({
variables: { partyIds: pubKeys.map((pk) => pk.publicKey) },
skip: pubKeys.length <= 0,
});
const activeKey = useMemo(() => { const activeKey = useMemo(() => {
return pubKeys?.find((pk) => pk.publicKey === pubKey); return pubKeys?.find((pk) => pk.publicKey === pubKey);
}, [pubKey, pubKeys]); }, [pubKey, pubKeys]);
@ -37,14 +44,21 @@ export const VegaWalletMenu = ({
return ( return (
<div> <div>
<div className="grow my-4" role="list"> <div className="grow my-4" role="list">
{(pubKeys || []).map((pk) => ( {(pubKeys || []).map((pk) => {
<KeypairListItem const profile = data?.partiesProfilesConnection?.edges.find(
key={pk.publicKey} (e) => e.node.partyId === pk.publicKey
pk={pk} );
isActive={activeKey?.publicKey === pk.publicKey} return (
onSelectItem={onSelectItem} <KeypairListItem
/> key={pk.publicKey}
))} pk={pk}
isActive={activeKey?.publicKey === pk.publicKey}
onSelectItem={onSelectItem}
alias={profile?.node.alias}
setMenu={setMenu}
/>
);
})}
</div> </div>
<div className="flex flex-col gap-2 m-4"> <div className="flex flex-col gap-2 m-4">
@ -72,14 +86,19 @@ export const VegaWalletMenu = ({
const KeypairListItem = ({ const KeypairListItem = ({
pk, pk,
isActive, isActive,
alias,
onSelectItem, onSelectItem,
setMenu,
}: { }: {
pk: Key; pk: Key;
isActive: boolean; isActive: boolean;
alias: string | undefined;
onSelectItem: (pk: string) => void; onSelectItem: (pk: string) => void;
setMenu: (open: 'nav' | 'wallet' | null) => void;
}) => { }) => {
const t = useT(); const t = useT();
const [copied, setCopied] = useCopyTimeout(); const [copied, setCopied] = useCopyTimeout();
const setOpen = useProfileDialogStore((store) => store.setOpen);
return ( return (
<div <div
@ -106,6 +125,23 @@ const KeypairListItem = ({
</CopyToClipboard> </CopyToClipboard>
{copied && <span className="text-xs">{t('Copied')}</span>} {copied && <span className="text-xs">{t('Copied')}</span>}
</span> </span>
<span
className="flex gap-2 items-center"
data-testid={`key-${pk.publicKey}`}
>
<button
data-testid="alias"
onClick={() => {
setOpen(pk.publicKey);
setMenu(null);
}}
className="flex items-center gap-1"
>
{alias ? alias : t('No alias')}
<VegaIcon name={VegaIconNames.EDIT} />
</button>
</span>
</div> </div>
); );
}; };