present sealed option only if seal key has been set and unlocked

This commit is contained in:
Roland Osborne 2022-12-12 14:15:45 -08:00
parent 9ed93b07d1
commit 0940be25e8
2 changed files with 19 additions and 2 deletions

View File

@ -26,8 +26,12 @@ export function Channels({ open, active }) {
const addFooter = (
<AddFooter>
<div class="seal">
{ state.sealable && (
<>
<Switch checked={state.seal} onChange={actions.setSeal} size="small" />
<span class="sealText">Sealed Channel</span>
</>
)}
</div>
<Button key="back" onClick={actions.clearShowAdd}>Cancel</Button>
<Button key="save" type="primary" loading={state.busy} onClick={addChannel}>Save</Button>

View File

@ -2,6 +2,7 @@ import { useContext, useState, useEffect } from 'react';
import { StoreContext } from 'context/StoreContext';
import { ChannelContext } from 'context/ChannelContext';
import { CardContext } from 'context/CardContext';
import { AccountContext } from 'context/AccountContext';
import { ProfileContext } from 'context/ProfileContext';
import { ViewportContext } from 'context/ViewportContext';
@ -17,14 +18,26 @@ export function useChannels() {
members: new Set(),
subject: null,
seal: false,
sealable: false,
});
const card = useContext(CardContext);
const channel = useContext(ChannelContext);
const account = useContext(AccountContext);
const store = useContext(StoreContext);
const profile = useContext(ProfileContext);
const viewport = useContext(ViewportContext);
useEffect(() => {
const { seal, sealKey } = account.state;
if (seal?.publicKey && sealKey?.public && sealKey?.private && seal.publicKey === sealKey.public) {
updateState({ sealable: true });
}
else {
updateState({ sealable: false });
}
}, [account]);
const updateState = (value) => {
setState((s) => ({ ...s, ...value }));
}