Skip to content

Commit

Permalink
Merge pull request #220 from HunnySajid/feat/218
Browse files Browse the repository at this point in the history
feat: move passcode to session storage from local
  • Loading branch information
HunnySajid authored Nov 12, 2024
2 parents 5d47ae0 + 579acdf commit 6ae062f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
14 changes: 12 additions & 2 deletions src/components/selectCredential.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export function SelectCredential(): JSX.Element {
if (error) {
toast.error(error?.message);
} else {
const _credentials = data?.credentials?.filter(_cred => _cred.issueeName) ?? [];
const _credentials =
data?.credentials?.filter((_cred) => _cred.issueeName) ?? [];
setCredentials(_credentials);
}
};
Expand Down Expand Up @@ -83,7 +84,9 @@ export function SelectCredential(): JSX.Element {
</span>
<ReactTooltip id={credential?.sad?.d} delayShow={200}>
<Flex flexDirection="row" fontSize={0} $flexGap={1}>
<Text $color="">{formatMessage({ id: "credential.unidentifiedIssuee" })}</Text>
<Text $color="">
{formatMessage({ id: "credential.unidentifiedIssuee" })}
</Text>
</Flex>
</ReactTooltip>
</>
Expand All @@ -92,6 +95,13 @@ export function SelectCredential(): JSX.Element {
</Box>
</Box>
))}
{!isLoading && !credentials?.length ? (
<Text fontSize={0} $color="subtext">
{formatMessage({ id: "message.noItems" })}
</Text>
) : (
<></>
)}
</>
);
}
6 changes: 3 additions & 3 deletions src/pages/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import browser from "webextension-polyfill";
import { configService } from "@pages/background/services/config";
import { sessionStorageService } from "@pages/background/services/browser-storage";
import { IMessage } from "@config/types";
import { senderIsPopup } from "@pages/background/utils";
import { setActionIcon } from "@shared/browser/action-utils";
Expand All @@ -13,7 +14,7 @@ const SAVE_TIMESTAMP_INTERVAL_MS = 2 * 1000;
function saveTimestamp() {
const timestamp = new Date().toISOString();

browser.storage.session.set({ timestamp });
sessionStorageService.setValue("timestamp", timestamp);
}

browser.runtime.onStartup.addListener(function () {
Expand All @@ -33,7 +34,6 @@ browser.runtime.onInstalled.addListener(function (object) {
}
});


// Listener to handle internal messages from content scripts from active tab and popup
browser.runtime.onMessage.addListener(function (
message: IMessage<any>,
Expand Down Expand Up @@ -97,4 +97,4 @@ async function initBackground() {
saveTimestamp();
setInterval(saveTimestamp, SAVE_TIMESTAMP_INTERVAL_MS);
}
initBackground();
initBackground();
11 changes: 8 additions & 3 deletions src/pages/background/services/browser-storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import browser from "webextension-polyfill";
import browser, { Storage } from "webextension-polyfill";

export const getSyncStorage = () => {
return browser.storage.sync;
Expand All @@ -8,7 +8,11 @@ export const getNonSyncStorage = () => {
return browser.storage.local;
};

const BrowserStorage = (storage = getNonSyncStorage()) => {
export const getSessionStorage = () => {
return browser.storage.session;
};

const BrowserStorage = (storage: Storage.StorageArea) => {
const _storage = storage;

const getAllKeys = async () => {
Expand Down Expand Up @@ -43,4 +47,5 @@ const BrowserStorage = (storage = getNonSyncStorage()) => {
};
};

export const browserStorageService = BrowserStorage();
export const browserStorageService = BrowserStorage(getNonSyncStorage());
export const sessionStorageService = BrowserStorage(getSessionStorage());
14 changes: 7 additions & 7 deletions src/pages/background/services/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { browserStorageService } from "@pages/background/services/browser-storage";
import { sessionStorageService } from "@pages/background/services/browser-storage";

const USER_ENUMS = {
PASSCODE: "user-passcode",
Expand All @@ -7,31 +7,31 @@ const USER_ENUMS = {

const User = () => {
const getPasscode = async (): Promise<string> => {
return (await browserStorageService.getValue(
return (await sessionStorageService.getValue(
USER_ENUMS.PASSCODE
)) as string;
};

const removePasscode = async () => {
await browserStorageService.removeKey(USER_ENUMS.PASSCODE);
await sessionStorageService.removeKey(USER_ENUMS.PASSCODE);
};

const setPasscode = async (passcode: string) => {
await browserStorageService.setValue(USER_ENUMS.PASSCODE, passcode);
await sessionStorageService.setValue(USER_ENUMS.PASSCODE, passcode);
};

const getControllerId = async (): Promise<string> => {
return (await browserStorageService.getValue(
return (await sessionStorageService.getValue(
USER_ENUMS.CONTROLLER_ID
)) as string;
};

const removeControllerId = async () => {
await browserStorageService.removeKey(USER_ENUMS.CONTROLLER_ID);
await sessionStorageService.removeKey(USER_ENUMS.CONTROLLER_ID);
};

const setControllerId = async (controllerId: string) => {
await browserStorageService.setValue(
await sessionStorageService.setValue(
USER_ENUMS.CONTROLLER_ID,
controllerId
);
Expand Down

0 comments on commit 6ae062f

Please sign in to comment.