mirror of
https://github.com/Qortal/chrome-extension.git
synced 2025-03-28 08:15:55 +00:00
reset recoils on logout
This commit is contained in:
parent
0cc2bc240e
commit
203226d3d9
37
src/App.tsx
37
src/App.tsx
@ -100,6 +100,8 @@ import { Settings } from "./components/Group/Settings";
|
|||||||
import { MainAvatar } from "./components/MainAvatar";
|
import { MainAvatar } from "./components/MainAvatar";
|
||||||
import { useRetrieveDataLocalStorage } from "./useRetrieveDataLocalStorage";
|
import { useRetrieveDataLocalStorage } from "./useRetrieveDataLocalStorage";
|
||||||
import { useQortalGetSaveSettings } from "./useQortalGetSaveSettings";
|
import { useQortalGetSaveSettings } from "./useQortalGetSaveSettings";
|
||||||
|
import { useResetRecoilState } from "recoil";
|
||||||
|
import { canSaveSettingToQdnAtom, oldPinnedAppsAtom, settingsLocalLastUpdatedAtom, settingsQDNLastUpdatedAtom, sortablePinnedAppsAtom } from "./atoms/global";
|
||||||
|
|
||||||
type extStates =
|
type extStates =
|
||||||
| "not-authenticated"
|
| "not-authenticated"
|
||||||
@ -326,6 +328,21 @@ function App() {
|
|||||||
const qortalRequestCheckbox1Ref = useRef(null);
|
const qortalRequestCheckbox1Ref = useRef(null);
|
||||||
useRetrieveDataLocalStorage()
|
useRetrieveDataLocalStorage()
|
||||||
useQortalGetSaveSettings(userInfo?.name)
|
useQortalGetSaveSettings(userInfo?.name)
|
||||||
|
|
||||||
|
//resets for recoil
|
||||||
|
const resetAtomSortablePinnedAppsAtom = useResetRecoilState(sortablePinnedAppsAtom);
|
||||||
|
const resetAtomCanSaveSettingToQdnAtom = useResetRecoilState(canSaveSettingToQdnAtom);
|
||||||
|
const resetAtomSettingsQDNLastUpdatedAtom = useResetRecoilState(settingsQDNLastUpdatedAtom);
|
||||||
|
const resetAtomSettingsLocalLastUpdatedAtom = useResetRecoilState(settingsLocalLastUpdatedAtom);
|
||||||
|
const resetAtomOldPinnedAppsAtom = useResetRecoilState(oldPinnedAppsAtom);
|
||||||
|
|
||||||
|
const resetAllRecoil = () => {
|
||||||
|
resetAtomSortablePinnedAppsAtom();
|
||||||
|
resetAtomCanSaveSettingToQdnAtom();
|
||||||
|
resetAtomSettingsQDNLastUpdatedAtom();
|
||||||
|
resetAtomSettingsLocalLastUpdatedAtom();
|
||||||
|
resetAtomOldPinnedAppsAtom();
|
||||||
|
};
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isMobile) return;
|
if (!isMobile) return;
|
||||||
// Function to set the height of the app to the viewport height
|
// Function to set the height of the app to the viewport height
|
||||||
@ -595,6 +612,20 @@ function App() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const qortalRequestPermissonFromExtension = async (message, sender, sendResponse) => {
|
||||||
|
if (message.action === "QORTAL_REQUEST_PERMISSION" && isMainWindow) {
|
||||||
|
try {
|
||||||
|
console.log("payloadbefore", message.payload);
|
||||||
|
|
||||||
|
await show('do you accept?');
|
||||||
|
|
||||||
|
sendResponse({ accepted: true });
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error", error);
|
||||||
|
sendResponse({ accepted: false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Listen for messages from the background script
|
// Listen for messages from the background script
|
||||||
@ -667,7 +698,12 @@ function App() {
|
|||||||
console.log("isMainWindow", isMainWindow, window?.location?.href);
|
console.log("isMainWindow", isMainWindow, window?.location?.href);
|
||||||
return true; // Return true to indicate an async response is coming
|
return true; // Return true to indicate an async response is coming
|
||||||
}
|
}
|
||||||
|
if (message.action === "QORTAL_REQUEST_PERMISSION" && isMainWindow && message?.isFromExtension) {
|
||||||
|
qortalRequestPermissonFromExtension(message, sender, sendResponse);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (message.action === "QORTAL_REQUEST_PERMISSION" && isMainWindow) {
|
if (message.action === "QORTAL_REQUEST_PERMISSION" && isMainWindow) {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -1014,6 +1050,7 @@ function App() {
|
|||||||
setConfirmUseOfLocal(false);
|
setConfirmUseOfLocal(false);
|
||||||
setTxList([]);
|
setTxList([]);
|
||||||
setMemberGroups([]);
|
setMemberGroups([]);
|
||||||
|
resetAllRecoil()
|
||||||
};
|
};
|
||||||
|
|
||||||
function roundUpToDecimals(number, decimals = 8) {
|
function roundUpToDecimals(number, decimals = 8) {
|
||||||
|
@ -19,4 +19,9 @@ export const settingsQDNLastUpdatedAtom = atom({
|
|||||||
export const settingsLocalLastUpdatedAtom = atom({
|
export const settingsLocalLastUpdatedAtom = atom({
|
||||||
key: 'settingsLocalLastUpdatedAtom',
|
key: 'settingsLocalLastUpdatedAtom',
|
||||||
default: 0,
|
default: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const oldPinnedAppsAtom = atom({
|
||||||
|
key: 'oldPinnedAppsAtom',
|
||||||
|
default: [],
|
||||||
});
|
});
|
@ -205,9 +205,12 @@ export const AppsLibrary = ({ availableQapps, setMode, myName, hasPublishApp, i
|
|||||||
width: "60px",
|
width: "60px",
|
||||||
}}
|
}}
|
||||||
onClick={()=> {
|
onClick={()=> {
|
||||||
executeEvent("addTab", {
|
// executeEvent("addTab", {
|
||||||
data: qapp
|
// data: qapp
|
||||||
})
|
// })
|
||||||
|
executeEvent("selectedAppInfo", {
|
||||||
|
data: qapp,
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<AppCircleContainer>
|
<AppCircleContainer>
|
||||||
|
@ -344,7 +344,7 @@ export const useQortalMessageListener = (frameWindow) => {
|
|||||||
if (UIQortalRequests.includes(event.data.action)) {
|
if (UIQortalRequests.includes(event.data.action)) {
|
||||||
console.log('event?.data', event?.data);
|
console.log('event?.data', event?.data);
|
||||||
sendMessageToRuntime(
|
sendMessageToRuntime(
|
||||||
{ action: event.data.action, type: 'qortalRequest', payload: event.data },
|
{ action: event.data.action, type: 'qortalRequest', payload: event.data, isExtension: true },
|
||||||
event.ports[0]
|
event.ports[0]
|
||||||
);
|
);
|
||||||
} else if (
|
} else if (
|
||||||
@ -368,7 +368,7 @@ export const useQortalMessageListener = (frameWindow) => {
|
|||||||
console.log('data after', data)
|
console.log('data after', data)
|
||||||
if (data) {
|
if (data) {
|
||||||
sendMessageToRuntime(
|
sendMessageToRuntime(
|
||||||
{ action: event.data.action, type: 'qortalRequest', payload: data },
|
{ action: event.data.action, type: 'qortalRequest', payload: data, isExtension: true },
|
||||||
event.ports[0]
|
event.ports[0]
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import React, { useContext, useMemo, useState } from 'react'
|
import React, { useContext, useMemo, useState } from 'react'
|
||||||
import { useRecoilState } from 'recoil';
|
import { useRecoilState } from 'recoil';
|
||||||
import isEqual from 'lodash/isEqual'; // Import deep comparison utility
|
import isEqual from 'lodash/isEqual'; // Import deep comparison utility
|
||||||
import { canSaveSettingToQdnAtom, settingsLocalLastUpdatedAtom, settingsQDNLastUpdatedAtom, sortablePinnedAppsAtom } from '../../atoms/global';
|
import { canSaveSettingToQdnAtom, oldPinnedAppsAtom, settingsLocalLastUpdatedAtom, settingsQDNLastUpdatedAtom, sortablePinnedAppsAtom } from '../../atoms/global';
|
||||||
import { ButtonBase } from '@mui/material';
|
import { ButtonBase } from '@mui/material';
|
||||||
import { objectToBase64 } from '../../qdn/encryption/group-encryption';
|
import { objectToBase64 } from '../../qdn/encryption/group-encryption';
|
||||||
import { MyContext } from '../../App';
|
import { MyContext } from '../../App';
|
||||||
@ -17,7 +17,7 @@ export const Save = () => {
|
|||||||
const [openSnack, setOpenSnack] = useState(false);
|
const [openSnack, setOpenSnack] = useState(false);
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
const [infoSnack, setInfoSnack] = useState(null);
|
const [infoSnack, setInfoSnack] = useState(null);
|
||||||
const [oldPinnedApps, setOldPinnedApps] = useState(pinnedApps)
|
const [oldPinnedApps, setOldPinnedApps] = useRecoilState(oldPinnedAppsAtom)
|
||||||
console.log('oldpin', {oldPinnedApps, pinnedApps}, settingsQdnLastUpdated, settingsLocalLastUpdated, settingsQdnLastUpdated < settingsLocalLastUpdated,)
|
console.log('oldpin', {oldPinnedApps, pinnedApps}, settingsQdnLastUpdated, settingsLocalLastUpdated, settingsQdnLastUpdated < settingsLocalLastUpdated,)
|
||||||
const { show } = useContext(MyContext);
|
const { show } = useContext(MyContext);
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ export const Save = () => {
|
|||||||
}
|
}
|
||||||
console.log('!isEqual(oldChanges, newChanges)', !isEqual(oldChanges, newChanges))
|
console.log('!isEqual(oldChanges, newChanges)', !isEqual(oldChanges, newChanges))
|
||||||
if(settingsQdnLastUpdated === -100) return false
|
if(settingsQdnLastUpdated === -100) return false
|
||||||
return !isEqual(oldChanges, newChanges) || settingsQdnLastUpdated < settingsLocalLastUpdated
|
return !isEqual(oldChanges, newChanges) && settingsQdnLastUpdated < settingsLocalLastUpdated
|
||||||
}, [oldPinnedApps, pinnedApps, settingsQdnLastUpdated, settingsLocalLastUpdated])
|
}, [oldPinnedApps, pinnedApps, settingsQdnLastUpdated, settingsLocalLastUpdated])
|
||||||
|
|
||||||
const saveToQdn = async ()=> {
|
const saveToQdn = async ()=> {
|
||||||
|
@ -63,6 +63,8 @@ function getLocalStorage(key) {
|
|||||||
|
|
||||||
chrome?.runtime?.onMessage.addListener((request, sender, sendResponse) => {
|
chrome?.runtime?.onMessage.addListener((request, sender, sendResponse) => {
|
||||||
if (request) {
|
if (request) {
|
||||||
|
console.log('rquest', request)
|
||||||
|
const isFromExtension = request?.isExtension
|
||||||
switch (request.action) {
|
switch (request.action) {
|
||||||
case "GET_USER_ACCOUNT": {
|
case "GET_USER_ACCOUNT": {
|
||||||
getUserAccount()
|
getUserAccount()
|
||||||
@ -169,7 +171,7 @@ chrome?.runtime?.onMessage.addListener((request, sender, sendResponse) => {
|
|||||||
case "VOTE_ON_POLL": {
|
case "VOTE_ON_POLL": {
|
||||||
const data = request.payload;
|
const data = request.payload;
|
||||||
|
|
||||||
voteOnPoll(data)
|
voteOnPoll(data, isFromExtension)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
sendResponse(res);
|
sendResponse(res);
|
||||||
})
|
})
|
||||||
|
@ -139,7 +139,7 @@ const _deployAt = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const _voteOnPoll = async (pollName, optionIndex, optionName) => {
|
const _voteOnPoll = async ({pollName, optionIndex, optionName}, isFromExtension) => {
|
||||||
const fee = await getFee("VOTE_ON_POLL");
|
const fee = await getFee("VOTE_ON_POLL");
|
||||||
|
|
||||||
const resPermission = await getUserPermission({
|
const resPermission = await getUserPermission({
|
||||||
@ -147,7 +147,7 @@ const _voteOnPoll = async (pollName, optionIndex, optionName) => {
|
|||||||
text2: `Poll: ${pollName}`,
|
text2: `Poll: ${pollName}`,
|
||||||
text3: `Option: ${optionName}`,
|
text3: `Option: ${optionName}`,
|
||||||
fee: fee.fee,
|
fee: fee.fee,
|
||||||
});
|
}, isFromExtension);
|
||||||
const { accepted } = resPermission;
|
const { accepted } = resPermission;
|
||||||
|
|
||||||
if (accepted) {
|
if (accepted) {
|
||||||
@ -207,7 +207,22 @@ function sendToSaveFilePicker(data, sender) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getUserPermission(payload: any) {
|
async function responseFromExtension() {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
|
||||||
|
// Send message to the content script to check focus
|
||||||
|
chrome.runtime.sendMessage({ action: "QORTAL_REQUEST_PERMISSION", payloa }, (response) => {
|
||||||
|
|
||||||
|
if (chrome.runtime.lastError) {
|
||||||
|
resolve(false); // Error occurred, assume not focused
|
||||||
|
} else {
|
||||||
|
resolve(response); // Resolve based on the response
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getUserPermission(payload: any, isFromExtension?: boolean) {
|
||||||
function waitForWindowReady(windowId) {
|
function waitForWindowReady(windowId) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const checkInterval = setInterval(() => {
|
const checkInterval = setInterval(() => {
|
||||||
@ -224,6 +239,33 @@ async function getUserPermission(payload: any) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('isFromExtension', isFromExtension)
|
||||||
|
if(isFromExtension){
|
||||||
|
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
// Set a timeout for 1 second
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
resolve(false);
|
||||||
|
}, 30000);
|
||||||
|
|
||||||
|
// Send message to the content script to check focus
|
||||||
|
chrome.runtime.sendMessage(
|
||||||
|
{ action: "QORTAL_REQUEST_PERMISSION", payload, isFromExtension },
|
||||||
|
(response) => {
|
||||||
|
console.log("permission response", response);
|
||||||
|
if (response === undefined) return;
|
||||||
|
clearTimeout(timeout); // Clear the timeout if we get a response
|
||||||
|
|
||||||
|
if (chrome.runtime.lastError) {
|
||||||
|
resolve(false); // Error occurred, assume not focused
|
||||||
|
} else {
|
||||||
|
resolve(response); // Resolve based on the response
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
await new Promise((res) => {
|
await new Promise((res) => {
|
||||||
const popupUrl = chrome.runtime.getURL("index.html?secondary=true");
|
const popupUrl = chrome.runtime.getURL("index.html?secondary=true");
|
||||||
console.log("popupUrl", popupUrl);
|
console.log("popupUrl", popupUrl);
|
||||||
@ -294,7 +336,7 @@ async function getUserPermission(payload: any) {
|
|||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
// Set a timeout for 1 second
|
// Set a timeout for 1 second
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
resolve(false); // No response within 10 second, assume not focused
|
resolve(false);
|
||||||
}, 30000);
|
}, 30000);
|
||||||
|
|
||||||
// Send message to the content script to check focus
|
// Send message to the content script to check focus
|
||||||
@ -909,7 +951,7 @@ export const publishMultipleQDNResources = async (data: any, sender) => {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const voteOnPoll = async (data) => {
|
export const voteOnPoll = async (data, isFromExtension) => {
|
||||||
const requiredFields = ["pollName", "optionIndex"];
|
const requiredFields = ["pollName", "optionIndex"];
|
||||||
const missingFields: string[] = [];
|
const missingFields: string[] = [];
|
||||||
requiredFields.forEach((field) => {
|
requiredFields.forEach((field) => {
|
||||||
@ -941,7 +983,7 @@ export const voteOnPoll = async (data) => {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const optionName = pollInfo.pollOptions[optionIndex].optionName;
|
const optionName = pollInfo.pollOptions[optionIndex].optionName;
|
||||||
const resVoteOnPoll = await _voteOnPoll(pollName, optionIndex, optionName);
|
const resVoteOnPoll = await _voteOnPoll({pollName, optionIndex, optionName}, isFromExtension);
|
||||||
return resVoteOnPoll;
|
return resVoteOnPoll;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(error?.message || "Failed to vote on the poll.");
|
throw new Error(error?.message || "Failed to vote on the poll.");
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import React, { useCallback, useEffect } from 'react'
|
import React, { useCallback, useEffect } from 'react'
|
||||||
import { useRecoilState, useSetRecoilState } from 'recoil';
|
import { useRecoilState, useSetRecoilState } from 'recoil';
|
||||||
import { canSaveSettingToQdnAtom, settingsLocalLastUpdatedAtom, settingsQDNLastUpdatedAtom, sortablePinnedAppsAtom } from './atoms/global';
|
import { canSaveSettingToQdnAtom, oldPinnedAppsAtom, settingsLocalLastUpdatedAtom, settingsQDNLastUpdatedAtom, sortablePinnedAppsAtom } from './atoms/global';
|
||||||
import { getArbitraryEndpointReact, getBaseApiReact } from './App';
|
import { getArbitraryEndpointReact, getBaseApiReact } from './App';
|
||||||
import { decryptResource } from './components/Group/Group';
|
import { decryptResource } from './components/Group/Group';
|
||||||
import { base64ToUint8Array, uint8ArrayToObject } from './backgroundFunctions/encryption';
|
import { base64ToUint8Array, uint8ArrayToObject } from './backgroundFunctions/encryption';
|
||||||
@ -58,13 +58,19 @@ export const useQortalGetSaveSettings = (myName) => {
|
|||||||
const setCanSave = useSetRecoilState(canSaveSettingToQdnAtom);
|
const setCanSave = useSetRecoilState(canSaveSettingToQdnAtom);
|
||||||
const setSettingsQDNLastUpdated = useSetRecoilState(settingsQDNLastUpdatedAtom);
|
const setSettingsQDNLastUpdated = useSetRecoilState(settingsQDNLastUpdatedAtom);
|
||||||
const [settingsLocalLastUpdated] = useRecoilState(settingsLocalLastUpdatedAtom);
|
const [settingsLocalLastUpdated] = useRecoilState(settingsLocalLastUpdatedAtom);
|
||||||
|
const [oldPinnedApps, setOldPinnedApps] = useRecoilState(oldPinnedAppsAtom)
|
||||||
|
|
||||||
const getSavedSettings = useCallback(async (myName, settingsLocalLastUpdated)=> {
|
const getSavedSettings = useCallback(async (myName, settingsLocalLastUpdated)=> {
|
||||||
try {
|
try {
|
||||||
const {hasPublishRecord, timestamp} = await getPublishRecord(myName)
|
const {hasPublishRecord, timestamp} = await getPublishRecord(myName)
|
||||||
if(hasPublishRecord){
|
if(hasPublishRecord){
|
||||||
const settings = await getPublish(myName)
|
const settings = await getPublish(myName)
|
||||||
|
console.log('settings', settings, timestamp, settingsLocalLastUpdated )
|
||||||
if(settings?.sortablePinnedApps && timestamp > settingsLocalLastUpdated){
|
if(settings?.sortablePinnedApps && timestamp > settingsLocalLastUpdated){
|
||||||
setSortablePinnedApps(settings.sortablePinnedApps)
|
setSortablePinnedApps(settings.sortablePinnedApps)
|
||||||
|
setOldPinnedApps(settings.sortablePinnedApps)
|
||||||
|
setSettingsQDNLastUpdated(timestamp || 0)
|
||||||
|
} else if(settings?.sortablePinnedApps){
|
||||||
setSettingsQDNLastUpdated(timestamp || 0)
|
setSettingsQDNLastUpdated(timestamp || 0)
|
||||||
}
|
}
|
||||||
if(!settings){
|
if(!settings){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user