1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +01:00

refactor sentryHooks object (#16435)

This commit is contained in:
Peter Yinusa 2022-11-09 19:28:32 +00:00 committed by GitHub
parent 25bb6ef861
commit 6cca9892b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 10 deletions

View File

@ -79,7 +79,7 @@ const localStore = inTest ? new ReadOnlyNetworkStore() : new LocalStore();
let versionedData; let versionedData;
if (inTest || process.env.METAMASK_DEBUG) { if (inTest || process.env.METAMASK_DEBUG) {
global.metamaskGetState = localStore.get.bind(localStore); global.stateHooks.metamaskGetState = localStore.get.bind(localStore);
} }
const phishingPageUrl = new URL(process.env.PHISHING_WARNING_PAGE_URL); const phishingPageUrl = new URL(process.env.PHISHING_WARNING_PAGE_URL);
@ -753,7 +753,7 @@ browser.runtime.onInstalled.addListener(({ reason }) => {
}); });
function setupSentryGetStateGlobal(store) { function setupSentryGetStateGlobal(store) {
global.sentryHooks.getSentryState = function () { global.stateHooks.getSentryState = function () {
const fullState = store.getState(); const fullState = store.getState();
const debugState = maskObject({ metamask: fullState }, SENTRY_STATE); const debugState = maskObject({ metamask: fullState }, SENTRY_STATE);
return { return {

View File

@ -1,10 +1,10 @@
import setupSentry from './lib/setupSentry'; import setupSentry from './lib/setupSentry';
// The root compartment will populate this with hooks // The root compartment will populate this with hooks
global.sentryHooks = {}; global.stateHooks = {};
// setup sentry error reporting // setup sentry error reporting
global.sentry = setupSentry({ global.sentry = setupSentry({
release: process.env.METAMASK_VERSION, release: process.env.METAMASK_VERSION,
getState: () => global.sentryHooks?.getSentryState?.() || {}, getState: () => global.stateHooks?.getSentryState?.() || {},
}); });

View File

@ -4,12 +4,12 @@ Fixture data can be generated by following these steps:
1. Load the unpacked extension in development or test mode 1. Load the unpacked extension in development or test mode
2. Inspecting the background context of the extension 2. Inspecting the background context of the extension
3. Call `metamaskGetState`, then call [`copy`][1] on the results 3. Call `stateHooks.metamaskGetState`, then call [`copy`][1] on the results
You can then paste the contents directly in your fixture file. You can then paste the contents directly in your fixture file.
```js ```js
copy(await metamaskGetState()) copy(await stateHooks.metamaskGetState())
``` ```

View File

@ -405,7 +405,9 @@ class Driver {
const htmlSource = await this.driver.getPageSource(); const htmlSource = await this.driver.getPageSource();
await fs.writeFile(`${filepathBase}-dom.html`, htmlSource); await fs.writeFile(`${filepathBase}-dom.html`, htmlSource);
const uiState = await this.driver.executeScript( const uiState = await this.driver.executeScript(
() => window.getCleanAppState && window.getCleanAppState(), () =>
window.stateHooks.getCleanAppState &&
window.stateHooks.getCleanAppState(),
); );
await fs.writeFile( await fs.writeFile(
`${filepathBase}-state.json`, `${filepathBase}-state.json`,

View File

@ -164,7 +164,7 @@ async function startApp(metamaskState, backgroundConnection, opts) {
} }
function setupDebuggingHelpers(store) { function setupDebuggingHelpers(store) {
window.getCleanAppState = async function () { window.stateHooks.getCleanAppState = async function () {
const state = clone(store.getState()); const state = clone(store.getState());
state.version = global.platform.getVersion(); state.version = global.platform.getVersion();
state.browser = window.navigator.userAgent; state.browser = window.navigator.userAgent;
@ -173,7 +173,7 @@ function setupDebuggingHelpers(store) {
}); });
return state; return state;
}; };
window.sentryHooks.getSentryState = function () { window.stateHooks.getSentryState = function () {
const fullState = store.getState(); const fullState = store.getState();
const debugState = maskObject(fullState, SENTRY_STATE); const debugState = maskObject(fullState, SENTRY_STATE);
return { return {
@ -185,7 +185,7 @@ function setupDebuggingHelpers(store) {
} }
window.logStateString = async function (cb) { window.logStateString = async function (cb) {
const state = await window.getCleanAppState(); const state = await window.stateHooks.getCleanAppState();
browser.runtime browser.runtime
.getPlatformInfo() .getPlatformInfo()
.then((platform) => { .then((platform) => {