fix: observe KeyStatusChanged event and correctly update hasProtections info

This commit is contained in:
VardanHakobyan
2021-06-16 16:00:14 +04:00
parent 6a3433d522
commit 17515848b4

View File

@@ -14,7 +14,7 @@ const Protections: FunctionalComponent<Props> = ({ application }) => {
application.clearProtectionSession();
};
const hasProtections = application.hasProtectionSources();
const [hasProtections, setHasProtections] = useState(() => application.hasProtectionSources());
const getProtectionsDisabledUntil = useCallback((): string | null => {
const protectionExpiry = application.getProtectionSessionExpiryDate();
@@ -51,8 +51,16 @@ const Protections: FunctionalComponent<Props> = ({ application }) => {
ApplicationEvent.ProtectionSessionExpiryDateChanged
);
const removeKeyStatusChangedObserver = application.addEventObserver(
async () => {
setHasProtections(application.hasProtectionSources());
},
ApplicationEvent.KeyStatusChanged
);
return () => {
removeProtectionSessionExpiryDateChangedObserver();
removeKeyStatusChangedObserver();
};
}, [application, getProtectionsDisabledUntil]);