Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc committed Nov 15, 2023
1 parent 610d056 commit 41547ec
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/script/components/UserDevices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const UserDevices: React.FC<UserDevicesProps> = ({

{showDeviceList && deviceMode === FIND_MODE.NOT_FOUND && <NoDevicesFound {...{noPadding, user}} />}

{current.state === UserDevicesState.DEVICE_DETAILS && (
{current.state === UserDevicesState.DEVICE_DETAILS && selectedClient && (
<DeviceDetails
{...{
renderDeviceBadges: renderBadges,
Expand All @@ -158,7 +158,7 @@ const UserDevices: React.FC<UserDevicesProps> = ({
logger,
messageRepository,
noPadding,
selectedClient,
device: selectedClient,
user,
}}
/>
Expand Down
23 changes: 11 additions & 12 deletions src/script/components/userDevices/DeviceDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ import type {Logger} from 'Util/Logger';
import {splitFingerprint} from 'Util/StringUtil';

import type {ClientRepository, ClientEntity} from '../../client';
import {MLSPublicKeys} from '../../client';
import {Config} from '../../Config';
import {ConversationState} from '../../conversation/ConversationState';
import type {MessageRepository} from '../../conversation/MessageRepository';
import type {CryptographyRepository} from '../../cryptography/CryptographyRepository';
import type {User} from '../../entity/User';
import {MotionDuration} from '../../motion/MotionDuration';
import {FormattedId} from '../../page/MainContent/panels/preferences/DevicesPreferences/components/FormattedId';
import {MLSDeviceDetails} from '../../page/MainContent/panels/preferences/DevicesPreferences/components/MLSDeviceDetails';

interface DeviceDetailsProps {
clickToShowSelfFingerprint: () => void;
Expand All @@ -50,12 +48,12 @@ interface DeviceDetailsProps {
logger: Logger;
messageRepository: MessageRepository;
noPadding: boolean;
selectedClient?: ClientEntity;
device: ClientEntity;
user: User;
}

export const DeviceDetails = ({
selectedClient,
device,
cryptographyRepository,
user,
clickToShowSelfFingerprint,
Expand All @@ -68,24 +66,24 @@ export const DeviceDetails = ({
const [fingerprintRemote, setFingerprintRemote] = useState<string>();
const [isResettingSession, setIsResettingSession] = useState(false);

const clientMeta = useMemo(() => selectedClient?.meta, [selectedClient]);
const clientMeta = useMemo(() => device?.meta, [device]);

const {isVerified} = useKoSubscribableChildren(clientMeta, ['isVerified']);
const {name: userName} = useKoSubscribableChildren(user, ['name']);

useEffect(() => {
setFingerprintRemote(undefined);
if (selectedClient) {
if (device) {
void cryptographyRepository
.getRemoteFingerprint(user.qualifiedId, selectedClient.id)
.getRemoteFingerprint(user.qualifiedId, device.id)
.then(remoteFingerprint => setFingerprintRemote(remoteFingerprint));
}
}, [selectedClient]);
}, [device]);

const clickToToggleDeviceVerification = () => {
const toggleVerified = !isVerified;
clientRepository
.verifyClient(user.qualifiedId, selectedClient, toggleVerified)
.verifyClient(user.qualifiedId, device, toggleVerified)
.catch((error: DexieError) => logger.warn(`Failed to toggle client verification: ${error.message}`));
};

Expand All @@ -97,19 +95,20 @@ export const DeviceDetails = ({
setIsResettingSession(true);
if (conversation) {
messageRepository
.resetSession(user.qualifiedId, selectedClient.id, conversation)
.resetSession(user.qualifiedId, device.id, conversation)
.then(_resetProgress)
.catch(_resetProgress);
}
};

const activeConversation = conversationState.activeConversation();
const isConversationMLS = activeConversation && isMLSConversation(activeConversation);
const mlsFingerprint = selectedClient.mlsPublicKeys?.[MLSPublicKeys.ED25519];

return (
<div className={cx('participant-devices__header', {'participant-devices__header--padding': !noPadding})}>
{mlsFingerprint && <MLSDeviceDetails fingerprint={mlsFingerprint} />}
{/*
TODO get the fingerprint from CoreCrypto (?)
mlsFingerprint && <MLSDeviceDetails fingerprint={mlsFingerprint} />*/}

<div className="device-proteus-details">
<h3 className="device-details-title paragraph-body-3">{t('participantDevicesProteusDeviceVerification')}</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
*/

import React, {useEffect, useState} from 'react';
import React from 'react';

import {ClientEntity, MLSPublicKeys} from 'src/script/client/ClientEntity';

Expand All @@ -43,11 +43,7 @@ export const DetailedDevice: React.FC<DeviceProps> = ({
getCertificate,
isProteusVerified = false,
}) => {
const [certificate, setCertificate] = useState<string | undefined>();
const mlsFingerprint = device.mlsPublicKeys?.[MLSPublicKeys.ED25519];
useEffect(() => {
getCertificate?.(device.id).then(setCertificate);
}, []);

return (
<>
Expand All @@ -57,7 +53,11 @@ export const DetailedDevice: React.FC<DeviceProps> = ({
</h3>

{mlsFingerprint && (
<MLSDeviceDetails fingerprint={mlsFingerprint} isCurrentDevice={isCurrentDevice} certificate={certificate} />
<MLSDeviceDetails
fingerprint={mlsFingerprint}
isCurrentDevice={isCurrentDevice}
getCertificate={() => getCertificate(device.id)}
/>
)}

{/* Proteus */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('DeviceDetailsPreferences', () => {
const defaultParams = {
device,
getFingerprint: jest.fn().mockResolvedValue('00000000'),
getCertificate: jest.fn().mockResolvedValue('00000000'),
onClose: jest.fn(),
onRemove: jest.fn(),
onResetSession: jest.fn().mockResolvedValue(undefined),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*
*/

import {useEffect, useState} from 'react';

import {Config} from 'src/script/Config';
import {t} from 'Util/LocalizerUtil';
import {splitFingerprint} from 'Util/StringUtil';
Expand All @@ -31,11 +33,15 @@ import {FormattedId} from '../FormattedId';
interface MLSDeviceDetailsProps {
fingerprint: string;
isCurrentDevice?: boolean;
certificate?: string;
getCertificate: () => Promise<string | undefined>;
}

export const MLSDeviceDetails = ({fingerprint, isCurrentDevice, certificate}: MLSDeviceDetailsProps) => {
export const MLSDeviceDetails = ({fingerprint, isCurrentDevice, getCertificate}: MLSDeviceDetailsProps) => {
const [certificate, setCertificate] = useState<string | undefined>();
const isE2EIEnabled = supportsMLS() && Config.getConfig().FEATURE.ENABLE_E2EI;
useEffect(() => {
getCertificate?.().then(setCertificate);
}, []);

return (
<div css={styles.wrapper}>
Expand Down

0 comments on commit 41547ec

Please sign in to comment.