Skip to content

Commit

Permalink
release/5.19.0 (#1292)
Browse files Browse the repository at this point in the history
* flips the session store flag, updates listeners to not be intialized … (#1169)

* capture amplitude errors to better understand why they're triggering sentry (#1167)

* flips the session store flag, updates listeners to not be intialized async for v3

* updates e2e tests for manifest v3

---------

Co-authored-by: Piyal Basu <pbasu235@gmail.com>

* add scripts tag for Firefox (#1294)

* uses chrome storage in migrations instead of local storage

* checks for migrated account in migration logic to set migrated network

* don't babel-polyfill contentScript (#1297)

* don't clear all of localStore on recoverAccount (#1301)

---------

Co-authored-by: aristides <aristides.staffieri@stellar.org>
  • Loading branch information
piyalbasu and aristidesstaffieri authored May 28, 2024
1 parent 0634ab6 commit 8bc1985
Show file tree
Hide file tree
Showing 24 changed files with 124 additions and 153 deletions.
3 changes: 1 addition & 2 deletions @shared/constants/soroban/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ export const DEFAULT_ASSETS_LISTS: AssetsLists = {
isEnabled: true,
},
{
url:
"https://raw.githubusercontent.com/soroswap/token-list/main/tokenList.json",
url: "https://raw.githubusercontent.com/soroswap/token-list/main/tokenList.json",
isEnabled: true,
},
{
Expand Down
9 changes: 4 additions & 5 deletions extension/e2e-tests/test-fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ export const test = base.extend<{
},
extensionId: async ({ context }, use) => {
// for manifest v2:
let [background] = context.backgroundPages();
if (!background) background = await context.waitForEvent("backgroundpage");
// let [background] = context.backgroundPages();
// if (!background) background = await context.waitForEvent("backgroundpage");

// for manifest v3:
// let [background] = context.serviceWorkers();
// if (!background)
// background = await context.waitForEvent('serviceworker');
let [background] = context.serviceWorkers();
if (!background) background = await context.waitForEvent("serviceworker");

const extensionId = background.url().split("/")[2];
await use(extensionId);
Expand Down
2 changes: 1 addition & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@
"stellar-sdk>stellar-base>sodium-native": false
}
}
}
}
9 changes: 3 additions & 6 deletions extension/public/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import {
initAlarmListener,
} from "background";

import { buildStore } from "background/store";

async function main() {
const store = await buildStore();
function main() {
initContentScriptMessageListener();
initExtensionMessageListener(store);
initExtensionMessageListener();
initInstalledListener();
initAlarmListener(store);
initAlarmListener();
}

main();
19 changes: 5 additions & 14 deletions extension/public/static/manifest/v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@
}
},
"background": {
"scripts": [
"background.min.js"
],
"scripts": ["background.min.js"],
"persistent": true
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"contentScript.min.js"
],
"matches": ["<all_urls>"],
"js": ["contentScript.min.js"],
"run_at": "document_start"
}
],
Expand All @@ -41,9 +35,6 @@
"48": "images/icon48.png",
"128": "images/icon128.png"
},
"permissions": [
"storage",
"alarms"
],
"permissions": ["storage", "alarms"],
"manifest_version": 2
}
}
24 changes: 12 additions & 12 deletions extension/public/static/manifest/v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
"version": "5.18.5",
"version_name": "5.18.5",
"description": "Freighter is a non-custodial wallet extension that enables you to sign Stellar transactions via your browser.",
"browser_specific_settings": {
"gecko": {
"id": "{3ee0dd4e-8c64-4b92-b539-25718a10f62f}",
"strict_min_version": "48.0"
}
},
"background": {
"service_worker": "background.min.js"
"service_worker": "background.min.js",
"scripts": ["background.min.js"]
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"contentScript.min.js"
],
"matches": ["<all_urls>"],
"js": ["contentScript.min.js"],
"run_at": "document_start"
}
],
Expand All @@ -32,9 +35,6 @@
"48": "images/icon48.png",
"128": "images/icon128.png"
},
"permissions": [
"storage",
"alarms"
],
"permissions": ["storage", "alarms"],
"manifest_version": 3
}
}
27 changes: 16 additions & 11 deletions extension/src/background/helpers/dataStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const browserLocalStorage = storage?.local;
export const browserSessionStorage = storage?.session;

// Session Storage Feature Flag - turn on when storage.session is supported
export const SESSION_STORAGE_ENABLED = false;
export const SESSION_STORAGE_ENABLED = true;

export type StorageOption =
| typeof browserLocalStorage
Expand All @@ -62,6 +62,9 @@ export const dataStorage = (
clear: async () => {
await storageApi.clear();
},
remove: async (keys: string | string[]) => {
await storageApi.remove(keys);
},
});

export const dataStorageAccess = (
Expand All @@ -74,12 +77,13 @@ export const dataStorageAccess = (
await store.setItem({ [keyId]: value });
},
clear: () => store.clear(),
remove: store.remove,
};
};

export const normalizeMigratedData = async () => {
const localStore = dataStorageAccess(browserLocalStorage);
const localStorageEntries = Object.entries(localStorage);
const localStorageEntries = await browserLocalStorage.get(null);

const applicationState = await localStore.getItem(APPLICATION_ID);
const isLocalStoreSetup = !!applicationState?.length;
Expand All @@ -95,7 +99,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, parsedValue);
await localStore.setItem(key as string, parsedValue);
}
} catch (e) {
// do not transform v
Expand Down Expand Up @@ -148,17 +152,17 @@ export const migrateSorobanRpcUrlNetworkDetails = async () => {
// This migration migrates the storage for custom tokens IDs to be keyed by network
const migrateTokenIdList = async () => {
const localStore = dataStorageAccess(browserLocalStorage);
const tokenIdsByKey = (await localStore.getItem(TOKEN_ID_LIST)) as Record<
string,
object
>;
const tokenIdsByKey = await localStore.getItem(TOKEN_ID_LIST);
const storageVersion = (await localStore.getItem(STORAGE_VERSION)) as string;

if (!storageVersion || semver.lt(storageVersion, "1.0.0")) {
const newTokenList = {
[NETWORKS.FUTURENET]: tokenIdsByKey,
};
await localStore.setItem(TOKEN_ID_LIST, newTokenList);
if (Array.isArray(tokenIdsByKey)) {
const newTokenList = {
[NETWORKS.FUTURENET]: tokenIdsByKey,
};
await localStore.setItem(TOKEN_ID_LIST, newTokenList);
}

await migrateDataStorageVersion("1.0.0");
}
};
Expand Down Expand Up @@ -247,6 +251,7 @@ const migrateSorobanRpcUrlNetwork = async () => {
NETWORK_ID,
);
if (
migratedNetwork &&
migratedNetwork.network === NETWORKS.FUTURENET &&
!migratedNetwork.sorobanRpcUrl
) {
Expand Down
10 changes: 6 additions & 4 deletions extension/src/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import browser from "webextension-polyfill";
import { Store } from "redux";
import { ROUTES } from "popup/constants/routes";
import {
EXTERNAL_SERVICE_TYPES,
SERVICE_TYPES,
} from "@shared/constants/services";
import { buildStore } from "background/store";

import { popupMessageListener } from "./messageListener/popupMessageListener";
import { freighterApiMessageListener } from "./messageListener/freighterApiMessageListener";
Expand All @@ -27,8 +27,9 @@ export const initContentScriptMessageListener = () => {
});
};

export const initExtensionMessageListener = (sessionStore: Store) => {
export const initExtensionMessageListener = () => {
browser?.runtime?.onMessage?.addListener(async (request, sender) => {
const sessionStore = await buildStore();
// todo this is kinda ugly
let res;
if (Object.values(SERVICE_TYPES).includes(request.type as SERVICE_TYPES)) {
Expand Down Expand Up @@ -70,8 +71,9 @@ export const initInstalledListener = () => {
browser?.runtime?.onInstalled.addListener(versionedMigration);
};

export const initAlarmListener = (sessionStore: Store) => {
browser?.alarms?.onAlarm.addListener(({ name }: { name: string }) => {
export const initAlarmListener = () => {
browser?.alarms?.onAlarm.addListener(async ({ name }: { name: string }) => {
const sessionStore = await buildStore();
if (name === SESSION_ALARM_NAME) {
sessionStore.dispatch(timeoutAccountAccess());
}
Expand Down
17 changes: 16 additions & 1 deletion extension/src/background/messageListener/popupMessageListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { MessageResponder } from "background/types";

import {
ALLOWLIST_ID,
ACCOUNT_NAME_LIST_ID,
APPLICATION_ID,
ASSETS_LISTS_ID,
CACHED_ASSET_ICONS_ID,
Expand Down Expand Up @@ -766,7 +767,21 @@ export const popupMessageListener = (request: Request, sessionStore: Store) => {
publicKey: wallet.getPublicKey(0),
privateKey: wallet.getSecret(0),
};
localStore.clear();

const keyIdList = await getKeyIdList();

if (keyIdList.length) {
/* Clear any existing account data while maintaining app settings */

// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < keyIdList.length; i += 1) {
await localStore.remove(`stellarkeys:${keyIdList[i]}`);
}

await localStore.setItem(KEY_ID_LIST, []);
await localStore.remove(ACCOUNT_NAME_LIST_ID);
}

await localStore.setItem(KEY_DERIVATION_NUMBER_ID, "0");

await _storeAccount({
Expand Down
16 changes: 9 additions & 7 deletions extension/src/helpers/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ const handlersLookup: { [key: string]: MetricHandler<any>[] } = {};
* intended for metrics emission, nothing else.
*/
export function metricsMiddleware<State>(): Middleware<object, State> {
return ({ getState }) => (next) => (action: AnyAction) => {
const state = getState();
(handlersLookup[action.type] || []).forEach((handler) =>
handler(state, action),
);
return next(action);
};
return ({ getState }) =>
(next) =>
(action: AnyAction) => {
const state = getState();
(handlersLookup[action.type] || []).forEach((handler) =>
handler(state, action),
);
return next(action);
};
}

// I can't figure out how to get the properties off a thunk for the ActionType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ export const HardwareSign = ({
transactionData: { destination },
} = useSelector(transactionSubmissionSelector);
const bipPath = useSelector(bipPathSelector);
const [hardwareConnectSuccessful, setHardwareConnectSuccessful] = useState(
false,
);
const [hardwareConnectSuccessful, setHardwareConnectSuccessful] =
useState(false);
const [connectError, setConnectError] = useState("");
const isSwap = useIsSwap();
const [isDetectBtnDirty, setIsDetectBtnDirty] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,8 @@ export const ModifyAssetList = ({
({ url }) => url === decodedAssetListUrl,
);
if (assetsListsSelection) {
const {
url,
name,
description,
provider,
isEnabled,
} = assetsListsSelection;
const { url, name, description, provider, isEnabled } =
assetsListsSelection;
setAssetListInfo({
url,
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ export const NetworkForm = ({ isEditing }: NetworkFormProps) => {
? {
...networkDetailsToEdit,
isSwitchSelected: false,
isAllowHttpSelected: !networkDetailsToEdit?.networkUrl.includes(
"https",
),
isAllowHttpSelected:
!networkDetailsToEdit?.networkUrl.includes("https"),
}
: {
networkName: "",
Expand Down Expand Up @@ -170,9 +169,8 @@ export const NetworkForm = ({ isEditing }: NetworkFormProps) => {
}),
);

const addCustomNetworkFulfilled = addCustomNetwork.fulfilled.match(
addCustomNetworkRes,
);
const addCustomNetworkFulfilled =
addCustomNetwork.fulfilled.match(addCustomNetworkRes);
let changeNetworkFulfilled = true;

if (values.isSwitchSelected) {
Expand Down
Loading

0 comments on commit 8bc1985

Please sign in to comment.