refactor: one shared extension-API module, and drive the dApp flows on Firefox (closes #153)
This commit was merged in pull request #281.
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
// its own refresh — see updatePhishingList().
|
||||
|
||||
const vendoredConfig = require("./phishingBlocklist.json");
|
||||
const { storageLocal } = require("./browserApi");
|
||||
|
||||
const BLOCKLIST_URL =
|
||||
"https://raw.githubusercontent.com/MetaMask/eth-phishing-detect/main/src/config.json";
|
||||
@@ -46,18 +47,10 @@ let lastAttemptTime = 0;
|
||||
let fetchPromise = null;
|
||||
let loadPromise = null;
|
||||
|
||||
// Resolved on use rather than captured at module load, so a test can install
|
||||
// a stub after requiring the module and so the popup — which has no reason to
|
||||
// touch the delta — does not fail to load where the API is absent.
|
||||
function storageApi() {
|
||||
if (typeof browser !== "undefined" && browser.storage) {
|
||||
return browser.storage.local;
|
||||
}
|
||||
if (typeof chrome !== "undefined" && chrome.storage) {
|
||||
return chrome.storage.local;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// storageLocal() resolves on use rather than at module load, so a test can
|
||||
// install a stub after requiring this module, and it returns null where the
|
||||
// API is absent — which is why the popup, with no reason to touch the delta,
|
||||
// loads fine without it.
|
||||
|
||||
/**
|
||||
* Sanitise a timestamp read back from storage.
|
||||
@@ -86,7 +79,7 @@ function sanitizeTimestamp(value) {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function loadDeltaFromStorage() {
|
||||
const storage = storageApi();
|
||||
const storage = storageLocal();
|
||||
if (!storage) return;
|
||||
try {
|
||||
const result = await storage.get(DELTA_STORAGE_KEY);
|
||||
@@ -122,7 +115,7 @@ function ensureDeltaLoaded() {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function saveDeltaToStorage() {
|
||||
const storage = storageApi();
|
||||
const storage = storageLocal();
|
||||
if (!storage) return;
|
||||
try {
|
||||
const data = {
|
||||
|
||||
Reference in New Issue
Block a user