Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix types #1435

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions extension/src/background/helpers/dataStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export const SESSION_STORAGE_ENABLED = true;

export const normalizeMigratedData = async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a helper that really shouldn't be running anymore. This was used to migrate data from localStorage to chrome.storage. Apparently there was an error in the code here when we switched over to v3, but we never noticed because if a user is on v3, this function returns early on ln 39

const localStore = dataStorageAccess(browserLocalStorage);
const localStorageEntries = await browserLocalStorage.get(null);
const localStorageEntries = Object.entries(
await browserLocalStorage.get(null),
);

const applicationState = await localStore.getItem(APPLICATION_ID);
const isLocalStoreSetup = !!applicationState?.length;
Expand All @@ -44,7 +46,7 @@ export const normalizeMigratedData = async () => {
if (typeof value === "string") {
const parsedValue = JSON.parse(value);
// eslint-disable-next-line no-await-in-loop
await localStore.setItem(key as string, parsedValue);
await localStore.setItem(key, parsedValue);
}
} catch (e) {
// do not transform v
Expand Down
9 changes: 2 additions & 7 deletions extension/src/background/helpers/dataStorageAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ export interface SetItemParams {
[key: string]: any;
}

// https://github.com/mozilla/webextension-polyfill/issues/424
interface BrowserStorage extends browser.Storage.Static {
session: browser.Storage.StorageArea;
}

const storage = browser.storage as BrowserStorage;
const storage = browser.storage;

// browser storage uses local storage which stores values on disk and persists data across sessions
// session storage uses session storage which stores data in memory and clears data after every "session"
Expand All @@ -27,7 +22,7 @@ export const dataStorage = (
getItem: async (key: string) => {
// TODO: re-enable defaults by passing an object. The value of the key-value pair will be the default

const storageResult = await storageApi.get(key);
const storageResult: Record<string, any> = await storageApi.get(key);

return storageResult[key];
},
Expand Down
8 changes: 2 additions & 6 deletions extension/src/background/helpers/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ import { ExternalRequest, Response } from "@shared/api/types";

export const isResponse = (
message: ExternalRequest | Response,
): message is Response => {
return "messagedId" in message;
};
): message is Response => "messagedId" in message;

export const isExternalMessage = (
message: ExternalRequest | Response,
): message is ExternalRequest => {
return !("messagedId" in message);
};
): message is ExternalRequest => !("messagedId" in message);
8 changes: 2 additions & 6 deletions extension/src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
EXTERNAL_SERVICE_TYPES,
SERVICE_TYPES,
} from "@shared/constants/services";
import { ExternalRequest, Response } from "@shared/api/types";
import { buildStore } from "background/store";

import { popupMessageListener } from "./messageListener/popupMessageListener";
Expand All @@ -16,7 +17,6 @@ import {
migrateSorobanRpcUrlNetworkDetails,
versionedMigration,
} from "./helpers/dataStorage";
import { ExternalRequest, Response } from "@shared/api/types";
import { isExternalMessage, isResponse } from "./helpers/message";

export const initContentScriptMessageListener = () => {
Expand Down Expand Up @@ -45,11 +45,7 @@ export const initExtensionMessageListener = () => {
Object.values(EXTERNAL_SERVICE_TYPES).includes(req.type)
) {
// eslint-disable-next-line
res = await freighterApiMessageListener(
req as ExternalRequest,
sender,
sessionStore,
);
res = await freighterApiMessageListener(req, sender, sessionStore);
}

return res;
Expand Down