From ee76431e287d200dcd96406f95a58a3dc83e5fa7 Mon Sep 17 00:00:00 2001 From: kvhnuke <10602065+kvhnuke@users.noreply.github.com> Date: Wed, 27 Mar 2024 13:41:23 -0700 Subject: [PATCH 1/9] fix: subscan activity --- .../libs/activity-handlers/providers/subscan/index.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/extension/src/providers/polkadot/libs/activity-handlers/providers/subscan/index.ts b/packages/extension/src/providers/polkadot/libs/activity-handlers/providers/subscan/index.ts index 536d59cf6..845f6c4df 100644 --- a/packages/extension/src/providers/polkadot/libs/activity-handlers/providers/subscan/index.ts +++ b/packages/extension/src/providers/polkadot/libs/activity-handlers/providers/subscan/index.ts @@ -17,7 +17,14 @@ const getAddressActivity = async ( ): Promise => { return cacheFetch( { - url: `${endpoint}api/scan/transfers?address=${address}&row=50`, + url: `${endpoint}api/v2/scan/transfers`, + post: { + address: address, + row: 50, + }, + headers: { + "Content-Type": "application/json", + }, }, TTL ).then((res) => { @@ -59,7 +66,7 @@ export default async ( activity.asset_symbol !== "" ? activity.asset_symbol : network.currencyName, - price: price, + price: activity.asset_symbol === network.currencyName ? price : "0", }, }; }); From 65eebcec8926a4be036db81230379d964b9b4d19 Mon Sep 17 00:00:00 2001 From: kvhnuke <10602065+kvhnuke@users.noreply.github.com> Date: Fri, 29 Mar 2024 12:05:34 -0700 Subject: [PATCH 2/9] devop: add setting to disable metrics --- .../extension/src/libs/metrics/amplitude.ts | 7 +++++-- packages/extension/src/libs/metrics/index.ts | 12 +++++++++++ packages/extension/src/libs/metrics/types.ts | 4 ++++ .../src/libs/settings-state/index.ts | 1 + .../src/libs/settings-state/types.ts | 1 + .../ethereum/tests/ethereum.events.mocha.ts | 1 + .../ethereum/tests/ethereum.requests.mocha.ts | 1 + .../polkadot/tests/polkadot.requests.mocha.ts | 1 + .../settings/views/settings-general/index.vue | 21 +++++++++++++++++++ 9 files changed, 47 insertions(+), 2 deletions(-) diff --git a/packages/extension/src/libs/metrics/amplitude.ts b/packages/extension/src/libs/metrics/amplitude.ts index 54798ca68..2ca127398 100644 --- a/packages/extension/src/libs/metrics/amplitude.ts +++ b/packages/extension/src/libs/metrics/amplitude.ts @@ -1,4 +1,4 @@ -import { init, track, Types } from "@amplitude/analytics-browser"; +import { init, track, Types, setOptOut } from "@amplitude/analytics-browser"; import { detectBrowser, detectOS } from "@action/utils/browser"; import SettingsState from "../settings-state"; @@ -32,7 +32,7 @@ class Metrics { instanceName: process.env.IS_DEV ? "enkrypt-extension-dev" : "enkrypt-extension", - optOut: false, + optOut: !set.isMetricsEnabled, serverUrl: process.env.IS_DEV ? "https://analytics-enkrypt-dev.mewwallet.dev/record" : "https://analytics-enkrypt.mewwallet.dev/record", @@ -63,6 +63,9 @@ class Metrics { } ); } + setOptOut(val: boolean) { + setOptOut(val); + } } export default Metrics; diff --git a/packages/extension/src/libs/metrics/index.ts b/packages/extension/src/libs/metrics/index.ts index eb507d69a..a83aaa617 100644 --- a/packages/extension/src/libs/metrics/index.ts +++ b/packages/extension/src/libs/metrics/index.ts @@ -7,6 +7,7 @@ import { NFTEventType, NetworkChangeEvents, SendEventType, + SettingEventType, SwapEventType, } from "./types"; @@ -68,6 +69,16 @@ const trackDAppsEvents = ( ) => { metrics.track("dapps", { event, ...options }); }; + +const optOutofMetrics = (optOut: boolean) => { + metrics.setOptOut(false); + metrics.track("settings", { + event: SettingEventType.OptOut, + value: optOut ? 1 : 0, + }); + metrics.setOptOut(optOut); +}; + export { trackNetworkSelected, trackSwapEvents, @@ -75,4 +86,5 @@ export { trackSendEvents, trackNFTEvents, trackDAppsEvents, + optOutofMetrics, }; diff --git a/packages/extension/src/libs/metrics/types.ts b/packages/extension/src/libs/metrics/types.ts index 16ba765b8..b35f023a1 100644 --- a/packages/extension/src/libs/metrics/types.ts +++ b/packages/extension/src/libs/metrics/types.ts @@ -38,3 +38,7 @@ export enum NFTEventType { export enum DAppsEventType { DAppsOpen = "dapps_open", } + +export enum SettingEventType { + OptOut = "opt_out", +} diff --git a/packages/extension/src/libs/settings-state/index.ts b/packages/extension/src/libs/settings-state/index.ts index 025b13f81..2987d650d 100644 --- a/packages/extension/src/libs/settings-state/index.ts +++ b/packages/extension/src/libs/settings-state/index.ts @@ -49,6 +49,7 @@ class SettingsState { const settings: EnkryptSettingsType = { installedTimestamp: 0, randomUserID: "", + isMetricsEnabled: true, }; return merge(settings, state); } diff --git a/packages/extension/src/libs/settings-state/types.ts b/packages/extension/src/libs/settings-state/types.ts index 79f2bb3f8..a7d375b64 100644 --- a/packages/extension/src/libs/settings-state/types.ts +++ b/packages/extension/src/libs/settings-state/types.ts @@ -20,6 +20,7 @@ export interface BtcSettingsType { export interface EnkryptSettingsType { installedTimestamp: number; randomUserID: string; + isMetricsEnabled: boolean; } export interface SettingsType { evm: EVMSettingsType; diff --git a/packages/extension/src/providers/ethereum/tests/ethereum.events.mocha.ts b/packages/extension/src/providers/ethereum/tests/ethereum.events.mocha.ts index 4925883ad..df2d976d1 100644 --- a/packages/extension/src/providers/ethereum/tests/ethereum.events.mocha.ts +++ b/packages/extension/src/providers/ethereum/tests/ethereum.events.mocha.ts @@ -22,6 +22,7 @@ const defaultSettings = { enkrypt: { installedTimestamp: 0, randomUserID: "", + isMetricsEnabled: true, }, manifestVersion: 3, }; diff --git a/packages/extension/src/providers/ethereum/tests/ethereum.requests.mocha.ts b/packages/extension/src/providers/ethereum/tests/ethereum.requests.mocha.ts index f0cc48a69..15d9a6a5f 100644 --- a/packages/extension/src/providers/ethereum/tests/ethereum.requests.mocha.ts +++ b/packages/extension/src/providers/ethereum/tests/ethereum.requests.mocha.ts @@ -23,6 +23,7 @@ const defaultSettings = { enkrypt: { installedTimestamp: 0, randomUserID: "", + isMetricsEnabled: true, }, manifestVersion: 3, }; diff --git a/packages/extension/src/providers/polkadot/tests/polkadot.requests.mocha.ts b/packages/extension/src/providers/polkadot/tests/polkadot.requests.mocha.ts index 27b3d9357..ab7693779 100644 --- a/packages/extension/src/providers/polkadot/tests/polkadot.requests.mocha.ts +++ b/packages/extension/src/providers/polkadot/tests/polkadot.requests.mocha.ts @@ -64,6 +64,7 @@ const tempWindow: EnkryptWindow = { enkrypt: { installedTimestamp: 0, randomUserID: "", + isMetricsEnabled: true, }, manifestVersion: 3, }, diff --git a/packages/extension/src/ui/action/views/settings/views/settings-general/index.vue b/packages/extension/src/ui/action/views/settings/views/settings-general/index.vue index 7beec7ed8..cf5cde455 100644 --- a/packages/extension/src/ui/action/views/settings/views/settings-general/index.vue +++ b/packages/extension/src/ui/action/views/settings/views/settings-general/index.vue @@ -38,6 +38,18 @@

Enable Enkrypt act like Unisat wallet for dapps

+ +
+

+ MEW uses Amplitude events to improve Enkrypt. No identifiable + information is collected. +

+
+