Skip to content

Commit f56a743

Browse files
committed
fixup sonarcubes warnings
1 parent b9901f3 commit f56a743

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

src/components/viewmodels/rooms/UserIdentityWarningViewModel.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,33 @@ export function useUserIdentityWarningViewModel(room: Room, key: string): UserId
4545
const crypto = cli.getCrypto();
4646

4747
const [members, setMembers] = useState<RoomMember[]>([]);
48-
const [currentPrompt, setPrompt] = useState<ViolationPrompt | undefined>(undefined);
48+
const [currentPrompt, setCurrentPrompt] = useState<ViolationPrompt | undefined>(undefined);
4949

5050
const loadViolations = useMemo(
5151
() =>
5252
throttle(async (): Promise<void> => {
5353
const isEncrypted = crypto && (await crypto.isEncryptionEnabledInRoom(room.roomId));
5454
if (!isEncrypted) {
5555
setMembers([]);
56-
setPrompt(undefined);
56+
setCurrentPrompt(undefined);
5757
return;
5858
}
5959

6060
const targetMembers = await room.getEncryptionTargetMembers();
6161
setMembers(targetMembers);
62-
const violations = await mapToViolations(crypto!, targetMembers);
62+
const violations = await mapToViolations(crypto, targetMembers);
6363

6464
let candidatePrompt: ViolationPrompt | undefined;
6565
if (violations.length > 0) {
6666
// sort by user ID to ensure consistent ordering
67-
candidatePrompt = violations.sort((a, b) => a.member.userId.localeCompare(b.member.userId))[0];
67+
const sortedViolations = violations.sort((a, b) => a.member.userId.localeCompare(b.member.userId));
68+
candidatePrompt = sortedViolations[0];
6869
} else {
6970
candidatePrompt = undefined;
7071
}
7172

7273
// is the current prompt still valid?
73-
setPrompt((existingPrompt): ViolationPrompt | undefined => {
74+
setCurrentPrompt((existingPrompt): ViolationPrompt | undefined => {
7475
if (existingPrompt && violations.includes(existingPrompt)) {
7576
return existingPrompt;
7677
} else if (candidatePrompt) {
@@ -102,8 +103,6 @@ export function useUserIdentityWarningViewModel(room: Room, key: string): UserId
102103
// someone changed their display name. Anyhow let's refresh.
103104
const userId = event.getStateKey();
104105
shouldRefresh = !!userId;
105-
} else {
106-
shouldRefresh = false;
107106
}
108107

109108
if (shouldRefresh) {
@@ -138,17 +137,22 @@ export function useUserIdentityWarningViewModel(room: Room, key: string): UserId
138137
});
139138
}, [loadViolations]);
140139

141-
let onButtonClick: (ev: ButtonEvent) => void = async (ev: ButtonEvent) => {};
140+
let onButtonClick: (ev: ButtonEvent) => void = () => {};
142141
if (currentPrompt) {
143-
onButtonClick = async (ev: ButtonEvent): Promise<void> => {
142+
onButtonClick = (ev: ButtonEvent): void => {
144143
// XXX do we want some posthog tracking?
144+
if (!crypto) {
145+
return;
146+
}
145147
ev.preventDefault();
146-
if (currentPrompt) {
147-
if (currentPrompt.type === "VerificationViolation") {
148-
await crypto?.withdrawVerificationRequirement(currentPrompt.member.userId);
149-
} else if (currentPrompt.type === "PinViolation") {
150-
await crypto?.pinCurrentUserIdentity(currentPrompt.member.userId);
151-
}
148+
if (currentPrompt.type === "VerificationViolation") {
149+
crypto.withdrawVerificationRequirement(currentPrompt.member.userId).catch((e) => {
150+
logger.error("Error withdrawing verification requirement:", e);
151+
});
152+
} else if (currentPrompt.type === "PinViolation") {
153+
crypto.pinCurrentUserIdentity(currentPrompt.member.userId).catch((e) => {
154+
logger.error("Error withdrawing verification requirement:", e);
155+
});
152156
}
153157
};
154158
}

test/unit-tests/components/views/rooms/UserIdentityWarning-test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ describe("UserIdentityWarning", () => {
141141
jest.spyOn(crypto, "getUserVerificationStatus").mockResolvedValue(
142142
new UserVerificationStatus(false, false, false, true),
143143
);
144-
crypto.pinCurrentUserIdentity = jest.fn();
144+
crypto.pinCurrentUserIdentity = jest.fn().mockResolvedValue(undefined);
145145
renderComponent(client, room);
146146

147147
await waitFor(() =>
@@ -164,7 +164,7 @@ describe("UserIdentityWarning", () => {
164164
jest.spyOn(crypto, "getUserVerificationStatus").mockResolvedValue(
165165
new UserVerificationStatus(false, true, false, true),
166166
);
167-
crypto.withdrawVerificationRequirement = jest.fn();
167+
crypto.withdrawVerificationRequirement = jest.fn().mockResolvedValue(undefined);
168168
renderComponent(client, room);
169169

170170
await waitFor(() =>

0 commit comments

Comments
 (0)