Skip to content

Commit 3335cb9

Browse files
committed
feat: add freeze/unfreeze and remove key functionality
1 parent 38dd7f0 commit 3335cb9

6 files changed

Lines changed: 240 additions & 78 deletions

File tree

src/context/AccountContext/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export interface IAccountContext {
6969
identityHasValidCdd: boolean;
7070
accountIsMultisigSigner: boolean;
7171
refreshAccountIdentity: () => void;
72+
refreshSecondaryKeys: () => void;
7273
keyIdentityRelationships: Record<string, AccountIdentityRelation>;
7374
multiSigAccount: MultiSig | null;
7475
selectedAccountBalance: IAccountBalance;
@@ -102,6 +103,7 @@ export const initialState = {
102103
identityHasValidCdd: false,
103104
accountIsMultisigSigner: false,
104105
refreshAccountIdentity: () => {},
106+
refreshSecondaryKeys: () => {},
105107
keyIdentityRelationships: {},
106108
multiSigAccount: null,
107109
selectedAccountBalance: { free: '', locked: '', total: '' },

src/context/AccountContext/provider.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,21 @@ const AccountProvider = ({ children }: IProviderProps) => {
101101
setShouldRefreshIdentity(true);
102102
}, [setShouldRefreshIdentity]);
103103

104+
const refreshSecondaryKeys = useCallback(async () => {
105+
if (!identity) return;
106+
107+
setSecondaryKeysLoading(true);
108+
109+
try {
110+
const { data } = await identity.getSecondaryAccounts();
111+
setSecondaryKeys(data);
112+
} catch (error) {
113+
notifyGlobalError((error as Error).message);
114+
} finally {
115+
setSecondaryKeysLoading(false);
116+
}
117+
}, [identity]);
118+
104119
const blockWalletAddress = useCallback(
105120
(address: string) => {
106121
setBlockedWallets((prev) => {
@@ -531,6 +546,7 @@ const AccountProvider = ({ children }: IProviderProps) => {
531546
identityHasValidCdd,
532547
accountIsMultisigSigner,
533548
refreshAccountIdentity,
549+
refreshSecondaryKeys,
534550
keyIdentityRelationships,
535551
multiSigAccount,
536552
selectedAccountBalance,
@@ -562,6 +578,7 @@ const AccountProvider = ({ children }: IProviderProps) => {
562578
multiSigAccount,
563579
primaryKey,
564580
refreshAccountIdentity,
581+
refreshSecondaryKeys,
565582
rememberSelectedAccount,
566583
secondaryKeys,
567584
secondaryKeysLoading,

src/layouts/SecondaryKeys/components/SecondaryKeyItem/index.tsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ import {
4343
interface ISecondaryKeyItemProps {
4444
data: PermissionedAccount;
4545
onEdit: () => void;
46-
onRemove: () => void;
46+
onRemovePermissions: () => void;
47+
onRemoveKey: () => void;
48+
isTransactionInProgress?: boolean;
4749
}
4850

4951
type NormalizedPermission<T> = {
@@ -100,7 +102,9 @@ const formatPermissionDisplay = (
100102
export const SecondaryKeyItem = ({
101103
data,
102104
onEdit,
103-
onRemove,
105+
onRemovePermissions,
106+
onRemoveKey,
107+
isTransactionInProgress = false,
104108
}: ISecondaryKeyItemProps) => {
105109
const { allAccountsWithMeta, allKeyInfo, identity } =
106110
useContext(AccountContext);
@@ -445,24 +449,37 @@ export const SecondaryKeyItem = ({
445449
<Button
446450
variant="outline"
447451
onClick={onEdit}
452+
disabled={isTransactionInProgress}
448453
title="Edit permissions"
449454
aria-label="Edit permissions"
450455
>
451456
<Icon name="Edit" size="24px" />
452457
Edit permissions
453458
</Button>
454459
<Button
455-
onClick={onRemove}
456-
title="Remove permissions"
457-
aria-label="Remove all permissions for this secondary key"
460+
variant="primary"
461+
onClick={onRemovePermissions}
462+
disabled={isTransactionInProgress}
463+
title="Revoke all permissions from this secondary key"
464+
aria-label="Revoke permissions"
458465
>
459466
<Icon name="CloseIcon" size="24px" />
460-
Remove permissions
467+
Revoke Permissions
468+
</Button>
469+
<Button
470+
variant="primary"
471+
onClick={onRemoveKey}
472+
disabled={isTransactionInProgress}
473+
title="Completely remove this secondary key from your identity"
474+
aria-label="Remove secondary key"
475+
>
476+
<Icon name="CloseIcon" size="24px" />
477+
Remove Key
461478
</Button>
462479
<Button
463480
variant="secondary"
464481
onClick={toggleDetails}
465-
disabled={!hasDetails}
482+
disabled={!hasDetails || isTransactionInProgress}
466483
title={getDetailsButtonLabel()}
467484
aria-label={getDetailsButtonLabel()}
468485
aria-expanded={detailsExpanded}

src/layouts/SecondaryKeys/components/SecondaryKeyItem/styles.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,17 @@ export const StyledButtonsWrapper = styled.div<{ $expanded: boolean }>`
239239
display: flex;
240240
align-items: center;
241241
gap: 12px;
242+
flex-wrap: wrap;
242243
243244
& button {
244-
flex-grow: 1;
245+
flex: 1;
246+
min-width: 100px;
245247
}
248+
246249
& button:last-child {
247-
width: 100%;
248250
@media screen and (min-width: 1024px) {
251+
flex: 0 0 auto;
249252
width: initial;
250-
flex-grow: 0;
251253
}
252254
& .expand-icon {
253255
transform: ${({ $expanded }) =>
@@ -256,6 +258,24 @@ export const StyledButtonsWrapper = styled.div<{ $expanded: boolean }>`
256258
}
257259
258260
@media screen and (max-width: 1023px) {
259-
flex-wrap: wrap-reverse;
261+
& button {
262+
flex: 1 1 calc(50% - 6px);
263+
}
264+
& button:last-child {
265+
flex: 0 1 auto;
266+
width: 100%;
267+
}
268+
}
269+
270+
@media screen and (max-width: 767px) {
271+
gap: 10px;
272+
& button {
273+
flex: 1 1 calc(50% - 5px);
274+
font-size: 13px;
275+
padding: 8px 10px;
276+
}
277+
& button:last-child {
278+
flex: 0 1 100%;
279+
}
260280
}
261281
`;

0 commit comments

Comments
 (0)