Skip to content

Commit

Permalink
feat: CP-9474 import private key activate account, design fixes (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
vvava authored Dec 2, 2024
1 parent ac914da commit 78c6046
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
19 changes: 13 additions & 6 deletions src/pages/Accounts/AccountItemChip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,30 @@ import { Account, AccountType } from '@src/background/services/accounts/models';

interface AccountItemChipProps {
account: Account;
isActive?: boolean;
}

export function AccountItemChip({ account }: AccountItemChipProps) {
export function AccountItemChip({ account, isActive }: AccountItemChipProps) {
const { t } = useTranslation();
const { type: accountType } = account;

const fontColor = isActive ? 'white' : 'inherit';

const icon = useMemo(() => {
switch (accountType) {
case AccountType.IMPORTED:
return <KeyIcon />;
return <KeyIcon color={fontColor} />;

case AccountType.FIREBLOCKS:
return <FireblocksIcon />;
return <FireblocksIcon color={fontColor} />;

case AccountType.WALLET_CONNECT:
return <WalletConnectIcon />;
return <WalletConnectIcon color={fontColor} />;

default:
return null;
}
}, [accountType]);
}, [accountType, fontColor]);

const label = useMemo(() => {
switch (accountType) {
Expand All @@ -58,7 +61,11 @@ export function AccountItemChip({ account }: AccountItemChipProps) {
icon={icon}
label={label}
size="small"
sx={{ fontWeight: 'normal' }}
sx={{
fontWeight: isActive ? '600' : 'normal',
color: fontColor,
backgroundColor: isActive ? 'grey.400' : 'rgba(255, 255, 255, 0.16)',
}}
/>
);
}
2 changes: 1 addition & 1 deletion src/pages/Accounts/components/AccountItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export const AccountItem = forwardRef(

{isImportedAccount && (
<Stack direction="row">
<AccountItemChip account={account} />
<AccountItemChip account={account} isActive={isActive} />
</Stack>
)}
</Stack>
Expand Down
6 changes: 4 additions & 2 deletions src/pages/ImportPrivateKey/ImportPrivateKey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { AccountsTab } from '../Accounts/Accounts';
import { DerivedAddress, NetworkType } from './components/DerivedAddress';
import { utils } from '@avalabs/avalanchejs';
import { usePrivateKeyImport } from '../Accounts/hooks/usePrivateKeyImport';
import { useAccountsContext } from '@src/contexts/AccountsProvider';

type DerivedAddresses = {
addressC: string;
Expand All @@ -49,20 +50,21 @@ export function ImportPrivateKey() {
const balance = useBalanceTotalInCurrency(derivedAddresses as Account);
const { isImporting: isImportLoading, importPrivateKey } =
usePrivateKeyImport();
const { selectAccount } = useAccountsContext();
const history = useHistory();

const isLoading = hasFocus && !derivedAddresses && !error;

const handleImport = async () => {
capture('ImportPrivateKeyClicked');
try {
await importPrivateKey(privateKey);
const importedAccountId = await importPrivateKey(privateKey);
await selectAccount(importedAccountId);
toast.success(t('Private Key Imported'), { duration: 2000 });
capture('ImportPrivateKeySucceeded');
history.replace(`/accounts?activeTab=${AccountsTab.Imported}`);
} catch (err) {
toast.error(t('Private Key Import Failed'), { duration: 2000 });
console.error(err);
}
};

Expand Down

0 comments on commit 78c6046

Please sign in to comment.