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

[Metrics] Add wallet metrics #560

Merged
merged 30 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
10b7548
add wallet metrics, render debug logs
BrettCleary Sep 28, 2023
efbbc4c
fix metrics
BrettCleary Sep 30, 2023
903def9
rm unused import
BrettCleary Sep 30, 2023
bd7dbaa
fix edge cases, improve connection reporting
BrettCleary Sep 30, 2023
7610e85
rm log
BrettCleary Sep 30, 2023
6646ea7
revert electron extension installer
BrettCleary Nov 9, 2023
92f4341
track wallet connected on backend, fix otp, rm walletstore
BrettCleary Nov 10, 2023
2158643
ignore mm sdk-comm
BrettCleary Nov 10, 2023
df3c2ef
revert wallet connected type
BrettCleary Nov 10, 2023
51ea735
rm otp updated handler
BrettCleary Nov 10, 2023
813a698
rm random commented line
BrettCleary Nov 10, 2023
11fba43
rm console log
BrettCleary Nov 10, 2023
5544a2d
rm memo, fix connected screen event multiple sends
BrettCleary Nov 10, 2023
75116ce
refactor walletSelection import screen
BrettCleary Nov 10, 2023
a4a7e9b
update mm to 0.12.0
BrettCleary Nov 10, 2023
f283239
refactor Import screen into components
BrettCleary Nov 13, 2023
8a7b80a
add back strict mode
BrettCleary Nov 13, 2023
be33b58
clean up ImportAndCreateOption
BrettCleary Nov 13, 2023
d75397e
onboarding metrics fixes
BrettCleary Nov 13, 2023
46f3acd
patch metamask sdk
BrettCleary Nov 14, 2023
5079d6b
fix postinstall script call
BrettCleary Nov 14, 2023
f5b175f
Merge branch 'main' into metrics/wallet_events
BrettCleary Nov 14, 2023
af0af9a
prettier
BrettCleary Nov 14, 2023
e8f1a4d
fix test
BrettCleary Nov 14, 2023
4559931
fix import, mm sdk type
BrettCleary Nov 14, 2023
5131d9c
handle rejection
BrettCleary Nov 14, 2023
c55bba3
add strict mode back
BrettCleary Nov 14, 2023
eb9cdfb
refactor profile bg color into function
BrettCleary Nov 15, 2023
a29cc7b
add translations and brackets
BrettCleary Nov 15, 2023
e4d2fc3
merge submodules
BrettCleary Nov 15, 2023
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ vite-plugin-electron.log
.yarn/

flathub/update-flathub.js
xyz.hyperplay.HyperPlay
xyz.hyperplay.HyperPlay

.sdk-comm
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
"@mantine/carousel": "^6.0.19",
"@mantine/core": "^6.0.19",
"@mantine/hooks": "^6.0.19",
"@metamask/sdk": "^0.5.3",
"@metamask/sdk": "^0.12.0",
"@mui/icons-material": "^5.10.9",
"@mui/material": "^5.10.12",
"@node-steam/vdf": "^2.2.0",
Expand Down Expand Up @@ -211,7 +211,9 @@
"mime": "^3.0.0",
"mobx": "^6.9.0",
"mobx-react-lite": "^3.4.0",
"patch-package": "^8.0.0",
"plist": "^3.0.5",
"postinstall-postinstall": "^2.1.0",
"qrcode": "^1.5.3",
"react": "^18.2.0",
"react-blockies": "^1.4.1",
Expand Down Expand Up @@ -268,6 +270,7 @@
"flatpak:prepare": "node ./flatpak/prepareFlatpak.js",
"flatpak:prepare-release": "node ./flatpak/prepareFlatpak.js release",
"i18n": "i18next",
"postinstall": "patch-package",
"prepare": "husky install",
"prettier": "prettier --check .",
"prettier-fix": "prettier --write ."
Expand Down Expand Up @@ -350,7 +353,9 @@
"electron": true,
"electron-vite>esbuild": true,
"playwright": true,
"vite>esbuild": true
"vite>esbuild": true,
"$root$": true,
"postinstall-postinstall": true
}
}
}
40 changes: 40 additions & 0 deletions patches/@metamask+sdk+0.12.0.patch
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this conflicts with our window.ethereum type definition in the frontend even though this is imported in the main process

There is also no reason for this to be exported by the node.js mm sdk. Created an issue here for it MetaMask/metamask-sdk#491

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
diff --git a/node_modules/@metamask/sdk/dist/browser/es/src/index.d.ts b/node_modules/@metamask/sdk/dist/browser/es/src/index.d.ts
index 431737f..25e4f92 100644
--- a/node_modules/@metamask/sdk/dist/browser/es/src/index.d.ts
+++ b/node_modules/@metamask/sdk/dist/browser/es/src/index.d.ts
@@ -5,15 +5,6 @@ import { MetaMaskSDK, MetaMaskSDKOptions } from './sdk';
import { RPC_URLS_MAP } from './services/MetaMaskSDK/InitializerManager/setupReadOnlyRPCProviders';
import { PROVIDER_UPDATE_TYPE } from './types/ProviderUpdateType';
import type { SDKLoggingOptions } from './types/SDKLoggingOptions';
-declare global {
- interface Window {
- ReactNativeWebView?: WebView;
- sdkProvider: SDKProvider;
- ethereum?: SDKProvider;
- extension: unknown;
- MSStream: unknown;
- }
-}
export { CommunicationLayerPreference, ConnectionStatus, DEFAULT_SERVER_URL, EventType, MessageType, RPC_URLS_MAP, MetaMaskSDK, PROVIDER_UPDATE_TYPE, PlatformType, SDKProvider, };
export type { MetaMaskSDKOptions, SDKLoggingOptions, ServiceStatus };
export default MetaMaskSDK;
diff --git a/node_modules/@metamask/sdk/dist/node/es/src/index.d.ts b/node_modules/@metamask/sdk/dist/node/es/src/index.d.ts
index 431737f..25e4f92 100644
--- a/node_modules/@metamask/sdk/dist/node/es/src/index.d.ts
+++ b/node_modules/@metamask/sdk/dist/node/es/src/index.d.ts
@@ -5,15 +5,6 @@ import { MetaMaskSDK, MetaMaskSDKOptions } from './sdk';
import { RPC_URLS_MAP } from './services/MetaMaskSDK/InitializerManager/setupReadOnlyRPCProviders';
import { PROVIDER_UPDATE_TYPE } from './types/ProviderUpdateType';
import type { SDKLoggingOptions } from './types/SDKLoggingOptions';
-declare global {
- interface Window {
- ReactNativeWebView?: WebView;
- sdkProvider: SDKProvider;
- ethereum?: SDKProvider;
- extension: unknown;
- MSStream: unknown;
- }
-}
export { CommunicationLayerPreference, ConnectionStatus, DEFAULT_SERVER_URL, EventType, MessageType, RPC_URLS_MAP, MetaMaskSDK, PROVIDER_UPDATE_TYPE, PlatformType, SDKProvider, };
export type { MetaMaskSDKOptions, SDKLoggingOptions, ServiceStatus };
export default MetaMaskSDK;
2 changes: 1 addition & 1 deletion src/backend/hyperplay-extension-helper
2 changes: 1 addition & 1 deletion src/backend/hyperplay-overlay
2 changes: 1 addition & 1 deletion src/backend/hyperplay-proxy-server
34 changes: 30 additions & 4 deletions src/backend/metrics/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import {
ImportableBrowser,
MetaMaskInitMethod
} from 'backend/hyperplay-extension-helper/ipcHandlers/types'
import { getPlatformName, getStoreName } from 'backend/utils'
import { AppPlatforms, InstallPlatform, Runner } from 'common/types'
import { PROVIDERS } from 'common/types/proxy-types'

export interface MetricsOptIn {
event: 'Metrics Opt-in'
Expand Down Expand Up @@ -39,9 +44,28 @@ export interface OnboardingSkipped {
sensitiveProperties?: never
}

export interface OnboardingCompleted {
event: 'Onboarding Completed'
properties?: never
export interface OnboardingProviderClicked {
event: 'Onboarding Provider Clicked'
properties: {
provider: PROVIDERS
}
sensitiveProperties?: never
}

export interface WalletConnected {
event: 'Wallet Connected'
properties?: {
provider: PROVIDERS
}
sensitiveProperties?: never
}

export interface MetaMaskInitialized {
event: 'MetaMask Initialized'
properties?: {
initMethod: MetaMaskInitMethod
browser?: ImportableBrowser
}
sensitiveProperties?: never
}

Expand Down Expand Up @@ -270,8 +294,10 @@ export type PossibleMetricPayloads =
| MetricsErrorCorrection
| GameStoreConnectionStarted
| OnboardingStarted
| OnboardingProviderClicked
| OnboardingSkipped
| OnboardingCompleted
| WalletConnected
| MetaMaskInitialized
| GameInstallRequested
| GameInstallStarted
| GameInstallSuccess
Expand Down
14 changes: 10 additions & 4 deletions src/common/typedefs/ipcBridge.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ interface HyperPlaySyncIPCFunctions {
providerRequestFailed: ProxiedProviderEventCallback
loadingScreenReady: () => void
reloadApp: () => void
createNewMetaMaskWallet: () => void
createNewMetaMaskWallet: (mmInitMethod: MetaMaskInitMethod) => void
enableOnEvents: (topic: string) => void
addHyperPlayShortcut: (gameId: string) => void
ignoreExitToTray: () => void
Expand Down Expand Up @@ -179,13 +179,19 @@ interface HyperPlayAsyncIPCFunctions {
updateProperties: chrome.tabs.UpdateProperties
) => Promise<chrome.tabs.Tab>
chromeTabsRemove: (tabIds: number | number[]) => Promise<void>
//
importMetaMask: (dbPath: string | null | undefined) => Promise<boolean>
importMetaMask: (
mmInitMethod: MetaMaskInitMethod,
dbPath?: string | null,
browser?: ImportableBrowser
) => Promise<boolean>
getMetaMaskImportOptions: () => Promise<MetaMaskImportOptions>
isExtensionInitialized: () => Promise<boolean>
getTabUrl: () => Promise<string>
getExtensionId: () => Promise<string>
getConnectionUris: (providerSelection: PROVIDERS) => Promise<string>
getConnectionUris: (
providerSelection: PROVIDERS,
isBootstrapping?: boolean
) => Promise<string>
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
providerRequest: (args: RequestArguments) => Promise<any>
getConnectedProvider: () => Promise<PROVIDERS>
Expand Down
5 changes: 5 additions & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,11 @@ export type AvailablePlatforms = {
icon: IconDefinition
}[]

export type WalletOnboardCloseReason =
| 'skipped'
| 'connected'
| 'requestedMetaMaskConnection'

export type Filter =
| 'alphabeticalAscending'
| 'alphabeticalDescending'
Expand Down
7 changes: 5 additions & 2 deletions src/frontend/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import DownloadToastManager from './components/UI/DownloadToastManager'
import TopNavBar from './components/UI/TopNavBar'
import StoreNavHandler from './StoreNavHandler'
import QaAuthHandler from './QaAuthHandler'
import { WalletOnboardCloseReason } from 'common/types'
import { DeviceStateController } from './state/DeviceState'
import { ENABLE_AMAZON_STORE } from './constants'

Expand Down Expand Up @@ -111,8 +112,10 @@ function App() {
<OnboardingStoreController />
{onboardingStore.isOnboardingOpen && (
<Onboarding
disableOnboarding={() => {
window.api.trackEvent({ event: 'Onboarding Skipped' })
disableOnboarding={(disableReason: WalletOnboardCloseReason) => {
if (disableReason === 'skipped') {
window.api.trackEvent({ event: 'Onboarding Skipped' })
}
onboardingStore.closeOnboarding()
}}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const container = document.getElementById('root')
const root = createRoot(container!) // createRoot(container!) if you use TypeScript

root.render(
<React.StrictMode>
<>
<StoreController />
<GlobalState>
<>
Expand All @@ -120,7 +120,7 @@ root.render(
</I18nextProvider>
</>
</GlobalState>
</React.StrictMode>
</>
)

// helper function to set the theme class and load custom css if needed
Expand Down
7 changes: 6 additions & 1 deletion src/frontend/screens/Onboarding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import Analytics from './analytics'
import WalletSelection from './walletSelection'
import { onboardingStore } from 'frontend/helpers/electronStores'
import classNames from 'classnames'
import { WalletOnboardCloseReason } from 'common/types'

interface OnboardingProps {
disableOnboarding: () => void
disableOnboarding: (disableReason: WalletOnboardCloseReason) => void
}

const Onboarding: React.FC<OnboardingProps> = function (props) {
Expand All @@ -27,6 +28,10 @@ const Onboarding: React.FC<OnboardingProps> = function (props) {
// Track the screen view once each time the view changes
useEffect(() => {
window.api.trackScreen('Onboarding', { view: currentScreen })

if (currentScreen === ONBOARDING_SCREEN.WALLET_SELECTION) {
window.api.trackEvent({ event: 'Onboarding Started' })
}
}, [currentScreen])

function getWelcomeElement() {
Expand Down
Loading
Loading