render seal option only if sealkey set

This commit is contained in:
Roland Osborne 2022-12-12 14:31:54 -08:00
parent 0940be25e8
commit 89b7e2b950
2 changed files with 27 additions and 6 deletions

View File

@ -87,9 +87,13 @@ export function ChannelsBody({ state, actions, openConversation }) {
)}
<View style={styles.addControls}>
<View style={styles.sealed}>
{ state.sealable && (
<>
<Switch style={styles.switch} trackColor={styles.track}
value={state.sealed} onValueChange={actions.setSealed} />
<Text style={styles.sealedText}>Sealed</Text>
</>
)}
</View>
<TouchableOpacity style={styles.cancel} onPress={actions.hideAdding}>
<Text>Cancel</Text>
@ -184,9 +188,13 @@ export function Channels({ openConversation }) {
)}
<View style={styles.addControls}>
<View style={styles.sealed}>
{ state.sealable && (
<>
<Switch style={styles.switch} trackColor={styles.track}
value={state.sealed} onValueChange={actions.setSealed} />
<Text>Sealed</Text>
</>
)}
</View>
<TouchableOpacity style={styles.cancel} onPress={actions.hideAdding}>
<Text>Cancel</Text>

View File

@ -3,6 +3,7 @@ import { useWindowDimensions } from 'react-native';
import { useNavigate } from 'react-router-dom';
import { CardContext } from 'context/CardContext';
import { ChannelContext } from 'context/ChannelContext';
import { AccountContext } from 'context/AccountContext';
import { ProfileContext } from 'context/ProfileContext';
import { AppContext } from 'context/AppContext';
import config from 'constants/Config';
@ -19,9 +20,11 @@ export function useChannels() {
addSubject: null,
addMembers: [],
sealed: false,
sealable: false,
});
const items = useRef([]);
const account = useContext(AccountContext);
const channel = useContext(ChannelContext);
const card = useContext(CardContext);
const profile = useContext(ProfileContext);
@ -32,6 +35,16 @@ export function useChannels() {
setState((s) => ({ ...s, ...value }));
}
useEffect(() => {
const { status, sealKey } = account.state;
if (status?.seal?.publicKey && sealKey?.public && sealKey?.private && sealKey?.public === status.seal.publicKey) {
updateState({ sealable: true });
}
else {
updateState({ sealed: false, sealable: false });
}
}, [account]);
useEffect(() => {
const contacts = Array.from(card.state.cards.values());
const filtered = contacts.filter(contact => {