fix: only allow editing active key

This commit is contained in:
Matthew Russell 2024-03-08 14:29:50 +00:00
parent 3fa4fda718
commit 540eb94d84
No known key found for this signature in database
2 changed files with 31 additions and 13 deletions

View File

@ -94,6 +94,7 @@ export const VegaWalletConnectButton = ({
<KeypairRadioGroup <KeypairRadioGroup
pubKey={pubKey} pubKey={pubKey}
pubKeys={pubKeys} pubKeys={pubKeys}
activeKey={activeKey?.publicKey}
onSelect={selectPubKey} onSelect={selectPubKey}
/> />
<TradingDropdownSeparator /> <TradingDropdownSeparator />
@ -138,10 +139,12 @@ export const VegaWalletConnectButton = ({
const KeypairRadioGroup = ({ const KeypairRadioGroup = ({
pubKey, pubKey,
pubKeys, pubKeys,
activeKey,
onSelect, onSelect,
}: { }: {
pubKey: string | undefined; pubKey: string | undefined;
pubKeys: Key[]; pubKeys: Key[];
activeKey: string | undefined;
onSelect: (pubKey: string) => void; onSelect: (pubKey: string) => void;
}) => { }) => {
const { data } = usePartyProfilesQuery({ const { data } = usePartyProfilesQuery({
@ -157,14 +160,27 @@ const KeypairRadioGroup = ({
(e) => e.node.partyId === pk.publicKey (e) => e.node.partyId === pk.publicKey
); );
return ( return (
<KeypairItem key={pk.publicKey} pk={pk} alias={profile?.node.alias} /> <KeypairItem
key={pk.publicKey}
pk={pk}
isActive={activeKey === pk.publicKey}
alias={profile?.node.alias}
/>
); );
})} })}
</TradingDropdownRadioGroup> </TradingDropdownRadioGroup>
); );
}; };
const KeypairItem = ({ pk, alias }: { pk: Key; alias: string | undefined }) => { const KeypairItem = ({
pk,
isActive,
alias,
}: {
pk: Key;
alias: string | undefined;
isActive: boolean;
}) => {
const t = useT(); const t = useT();
const [copied, setCopied] = useCopyTimeout(); const [copied, setCopied] = useCopyTimeout();
const setOpen = useProfileDialogStore((store) => store.setOpen); const setOpen = useProfileDialogStore((store) => store.setOpen);
@ -201,7 +217,7 @@ const KeypairItem = ({ pk, alias }: { pk: Key; alias: string | undefined }) => {
className="flex items-center gap-1" className="flex items-center gap-1"
> >
{alias ? alias : t('No alias')} {alias ? alias : t('No alias')}
<VegaIcon name={VegaIconNames.EDIT} /> {isActive && <VegaIcon name={VegaIconNames.EDIT} />}
</button> </button>
</Tooltip> </Tooltip>
</div> </div>

View File

@ -131,6 +131,7 @@ const KeypairListItem = ({
data-testid={`key-${pk.publicKey}`} data-testid={`key-${pk.publicKey}`}
> >
<span className="truncate">{alias ? alias : t('No alias')}</span> <span className="truncate">{alias ? alias : t('No alias')}</span>
{isActive && (
<button <button
data-testid="alias" data-testid="alias"
onClick={() => { onClick={() => {
@ -141,6 +142,7 @@ const KeypairListItem = ({
> >
<VegaIcon name={VegaIconNames.EDIT} /> <VegaIcon name={VegaIconNames.EDIT} />
</button> </button>
)}
</span> </span>
</div> </div>
); );