Skip to content

Commit d476f02

Browse files
authoredJul 19, 2023
[Tech] Proxy Server Updates (#404)
* init * bump version, fix session params * update yarn lock * refactor providers, web3 to ethers * fix types * fix types, fix build * fix ipc handlers * test fixes, linting, prettier, format on save * improve zod error response * fix eslint errors in tests, fix logger types * fix mm extension tests * fix mm sdk * fix wc and mm sdk uri * fix window.ethereum type errors * prettier * fix mmsdk and wc * rm log * rm only * merge submodules * point ext helper to main
1 parent 08a1d20 commit d476f02

File tree

31 files changed

+1383
-2879
lines changed

31 files changed

+1383
-2879
lines changed
 

‎.eslintignore

-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ i18next-parser.config.js
22
flatpak/build/
33
flatpak/.flatpak-builder/
44
vite.config.ts
5-
**/__tests__/**
65
**/__mocks__/**
76
sign/**

‎.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"env": {
33
"browser": true,
44
"es2021": true,
5-
"node": true
5+
"node": true,
6+
"jest": true
67
},
78
"extends": [
89
"eslint:recommended",

‎.vscode/settings.json

-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,5 @@
88
},
99
"[typescriptreact]": {
1010
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
11-
},
12-
"[typescript]": {
13-
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
1411
}
1512
}

‎package.json

+13-7
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@
155155
"@hyperplay/ui": "^0.1.4",
156156
"@mantine/core": "^6.0.9",
157157
"@mantine/hooks": "^6.0.9",
158-
"@metamask/sdk": "^0.1.0",
158+
"@metamask/sdk": "^0.5.3",
159159
"@mui/icons-material": "^5.10.9",
160160
"@mui/material": "^5.10.12",
161161
"@node-steam/vdf": "^2.2.0",
162-
"@rudderstack/rudder-sdk-node": "^2.0.0",
162+
"@rudderstack/rudder-sdk-node": "^2.0.3",
163163
"@sentry/electron": "^4.6.0",
164164
"@sentry/react": "7.50.0",
165165
"@shockpkg/icon-encoder": "^2.1.3",
@@ -169,18 +169,22 @@
169169
"@types/qrcode": "^1.5.0",
170170
"@types/react-blockies": "^1.4.1",
171171
"@types/unzipper": "^0.10.6",
172-
"@walletconnect/web3-provider": "^1.8.0",
172+
"@walletconnect/browser-utils": "^1.8.0",
173+
"@walletconnect/ethereum-provider": "^2.9.0",
174+
"@walletconnect/modal": "^2.6.0",
175+
"@walletconnect/types": "^2.9.0",
173176
"axios": "^0.26.1",
174177
"bn.js": "^5.2.1",
175178
"check-disk-space": "^3.3.1",
176-
"classic-level": "^1.2.0",
179+
"classic-level": "1.2.0",
177180
"classnames": "^2.3.1",
178181
"compare-versions": "^6.0.0-rc.1",
179182
"crc": "^4.1.1",
180183
"discord-rich-presence-typescript": "^0.0.8",
181184
"easydl": "^1.0.3",
182185
"electron-store": "^8.0.1",
183186
"electron-updater": "^5.0.1",
187+
"ethers": "^6.6.3",
184188
"express": "^4.18.1",
185189
"filesize": "^8.0.7",
186190
"find-process": "^1.4.7",
@@ -195,10 +199,11 @@
195199
"i18next-http-backend": "^1.4.0",
196200
"ini": "^3.0.0",
197201
"jsdom": "^20.0.0",
202+
"lokijs": "^1.5.12",
198203
"mobx": "^6.9.0",
199204
"mobx-react-lite": "^3.4.0",
200205
"plist": "^3.0.5",
201-
"qrcode": "^1.5.1",
206+
"qrcode": "^1.5.3",
202207
"react": "^18.2.0",
203208
"react-blockies": "^1.4.1",
204209
"react-dom": "^18.2.0",
@@ -214,8 +219,8 @@
214219
"systeminformation": "^5.15.0",
215220
"ts-prune": "^0.10.3",
216221
"tslib": "^2.4.0",
217-
"web3": "^1.7.5",
218-
"yauzl": "^2.10.0"
222+
"yauzl": "^2.10.0",
223+
"zod": "^3.21.4"
219224
},
220225
"scripts": {
221226
"start": "vite",
@@ -273,6 +278,7 @@
273278
"@types/react-router-dom": "^5.3.3",
274279
"@types/supertest": "^2.0.12",
275280
"@types/tmp": "^0.2.3",
281+
"@types/ws": "^8.5.5",
276282
"@typescript-eslint/eslint-plugin": "^5.20.0",
277283
"@typescript-eslint/parser": "^5.20.0",
278284
"@vitejs/plugin-react": "^2.2.0",
+14-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { backendEvents } from './../backend_events'
12
/* eslint-disable @typescript-eslint/no-explicit-any */
23
let connectedResolve: any
34

@@ -7,24 +8,24 @@ export const getConnectedPromise = async function () {
78
})
89
}
910

10-
export function walletConnected(accounts: string[]) {
11+
backendEvents.on('walletConnected', function (accounts: string[]) {
1112
console.log('renderer receives: connected, accts = ', accounts)
1213
connectedResolve()
13-
}
14+
})
1415

15-
export function walletDisconnected(code: number, reason: string) {
16+
backendEvents.on('walletDisconnected', function (code: number, reason: string) {
1617
console.log('renderer receives: disconnected: ', code, reason)
17-
}
18+
})
1819

19-
export function accountsChanged(accounts: string[]) {
20-
console.log('renderer receives: accounts changed to ', accounts)
21-
connectedResolve()
22-
}
20+
backendEvents.on('connectionRequestRejected', function () {
21+
console.log('renderer receives: connection request rejected ')
22+
})
2323

24-
export function chainChanged(chainId: number) {
24+
backendEvents.on('chainChanged', function (chainId: number) {
2525
console.log('renderer receives: chain changed to ', chainId)
26-
}
26+
})
2727

28-
export function connectionRequestRejected() {
29-
console.log('renderer receives: connection request rejected ')
30-
}
28+
backendEvents.on('accountsChanged', function (accounts: string[]) {
29+
console.log('renderer receives: accounts changed to ', accounts)
30+
connectedResolve()
31+
})

‎src/backend/__tests__/constants.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('Constants - getShell', () => {
2828

2929
async function getShell(): Promise<string> {
3030
jest.resetModules()
31-
return await import('../constants').then((module) => {
31+
return import('../constants').then((module) => {
3232
return module.execOptions.shell
3333
})
3434
}

‎src/backend/__tests__/main_window.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('main_window', () => {
1717
})
1818

1919
describe('if there is a main window', () => {
20-
let window = {
20+
const window = {
2121
webContents: {
2222
send: jest.fn()
2323
}

‎src/backend/__tests__/utils.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { test_data } from './test_data/github-api-heroic-test-data.json'
77
import path from 'path'
88
import {
99
copyFileSync,
10-
createWriteStream,
1110
existsSync,
1211
readFileSync,
1312
rmSync,
@@ -60,6 +59,7 @@ describe('backend/utils.ts', () => {
6059
[{ target: 'v2.4.0-beta.1', base: '2.4.0' }, false],
6160
[{ target: 'v2.4.0-beta.2', base: '2.4.0-beta.1' }, true],
6261
[{ target: 'v2.4.0-beta.1', base: '2.4.0-beta.2' }, false],
62+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
6363
[{ target: undefined as any, base: undefined as any }, false]
6464
])
6565

‎src/backend/logger/__tests__/logfile.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ let tmpDir = {} as DirResult
1717

1818
const shouldSkip = platform() === 'win32'
1919
const skipMessage = 'on windows so skipping test'
20-
const emptyTest = it('should do nothing', () => {})
20+
const emptyTest = it('should do nothing', () => {
21+
console.log('running empty test')
22+
})
2123

2224
describe('logger/logfile.ts', () => {
2325
if (shouldSkip) {
@@ -173,11 +175,9 @@ describe('logger/logfile.ts', () => {
173175
})
174176

175177
test('appendMessageToLogFile fails', () => {
176-
const appendFileSyncSpy = jest
177-
.spyOn(graceful_fs, 'appendFileSync')
178-
.mockImplementation(() => {
179-
throw Error('append failed')
180-
})
178+
jest.spyOn(graceful_fs, 'appendFileSync').mockImplementation(() => {
179+
throw Error('append failed')
180+
})
181181

182182
logfile.appendMessageToLogFile('Hello World')
183183
expect(logError).toBeCalledWith(

‎src/backend/logger/__tests__/logger.test.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ function getStringPassedToLogFile(type: logLevel, skipMessagePrefix = false) {
4242

4343
const shouldSkip = platform() === 'win32'
4444
const skipMessage = 'on windows so skipping test'
45-
const emptyTest = it('should do nothing', () => {})
45+
const emptyTest = it('should do nothing', () => {
46+
console.log('running empty test')
47+
})
4648

4749
describe('logger/logger.ts', () => {
4850
if (shouldSkip) {
@@ -62,7 +64,7 @@ describe('logger/logger.ts', () => {
6264
.mockImplementation()
6365

6466
interface TestCaseProps {
65-
function: Function
67+
function: logger.LogFunction
6668
spyConsole: jest.SpyInstance
6769
}
6870

@@ -95,7 +97,7 @@ describe('logger/logger.ts', () => {
9597
jest.spyOn(global.console, 'log').mockImplementation()
9698
jest.spyOn(global.console, 'warn').mockImplementation()
9799

98-
const testCases = new Map<logLevel, Function>([
100+
const testCases = new Map<logLevel, logger.LogFunction>([
99101
['ERROR', logger.logError],
100102
['INFO', logger.logInfo],
101103
['WARNING', logger.logWarning],
@@ -116,7 +118,7 @@ describe('logger/logger.ts', () => {
116118
jest.spyOn(global.console, 'log').mockImplementation()
117119
jest.spyOn(global.console, 'warn').mockImplementation()
118120

119-
const testCases = new Map<logLevel, Function>([
121+
const testCases = new Map<logLevel, logger.LogFunction>([
120122
['ERROR', logger.logError],
121123
['INFO', logger.logInfo],
122124
['WARNING', logger.logWarning],

‎src/backend/logger/logger.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ function logBase(
160160
* @param showDialog set true to show in frontend
161161
* @defaultvalue {@link LogPrefix.General}
162162
*/
163-
export function logDebug(input: LogInputType, options?: LogOptions): void
164-
export function logDebug(input: LogInputType, prefix?: LogPrefix): void
165163
export function logDebug(
166164
input: LogInputType,
167165
options_or_prefix?: LogOptions | LogPrefix
@@ -177,15 +175,15 @@ export function logDebug(
177175
* @param showDialog set true to show in frontend
178176
* @defaultvalue {@link LogPrefix.General}
179177
*/
180-
export function logError(input: LogInputType, options?: LogOptions): void
181-
export function logError(input: LogInputType, prefix?: LogPrefix): void
182178
export function logError(
183179
input: LogInputType,
184180
options_or_prefix?: LogOptions | LogPrefix
185181
) {
186182
logBase(input, 'ERROR', options_or_prefix)
187183
}
188184

185+
export type LogFunction = typeof logError
186+
189187
/**
190188
* Log info messages
191189
* @param input info messages to log
@@ -194,8 +192,6 @@ export function logError(
194192
* @param showDialog set true to show in frontend
195193
* @defaultvalue {@link LogPrefix.General}
196194
*/
197-
export function logInfo(input: LogInputType, options?: LogOptions): void
198-
export function logInfo(input: LogInputType, prefix?: LogPrefix): void
199195
export function logInfo(
200196
input: LogInputType,
201197
options_or_prefix?: LogOptions | LogPrefix
@@ -211,8 +207,6 @@ export function logInfo(
211207
* @param showDialog set true to show in frontend
212208
* @defaultvalue {@link LogPrefix.General}
213209
*/
214-
export function logWarning(input: LogInputType, options?: LogOptions): void
215-
export function logWarning(input: LogInputType, prefix?: LogPrefix): void
216210
export function logWarning(
217211
input: LogInputType,
218212
options_or_prefix?: LogOptions | LogPrefix

‎src/backend/main.ts

+15-35
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,8 @@ import { getFonts } from 'font-list'
121121
import { runWineCommand, verifyWinePrefix } from './launcher'
122122
import shlex from 'shlex'
123123
import { initQueue } from './downloadmanager/downloadqueue'
124-
import * as ProviderHelper from './hyperplay-proxy-server/providerHelper'
125124
import * as ExtensionHelper from './hyperplay-extension-helper/extensionProvider'
126125
import * as ProxyServer from './hyperplay-proxy-server/proxy'
127-
import {
128-
AccountsChangedType,
129-
ChainChangedType,
130-
ConnectionRequestRejectedType,
131-
WalletConnectedType,
132-
WalletDisconnectedType
133-
} from './hyperplay-proxy-server/commonProxyTypes'
134126

135127
ProxyServer.serverStarted.then(() => console.log('Server started'))
136128
import {
@@ -1800,41 +1792,29 @@ import { backendEvents } from 'backend/backend_events'
18001792
import { toggleOverlay } from 'backend/hyperplay-overlay'
18011793

18021794
// sends messages to renderer process through preload.ts callbacks
1803-
export const walletConnected: WalletConnectedType = function (
1804-
accounts: string[]
1805-
) {
1795+
backendEvents.on('walletConnected', function (accounts: string[]) {
18061796
getMainWindow()?.webContents.send('walletConnected', accounts)
1807-
}
1797+
})
18081798

1809-
export const walletDisconnected: WalletDisconnectedType = function (
1810-
code: number,
1811-
reason: string
1812-
) {
1799+
backendEvents.on('walletDisconnected', function (code: number, reason: string) {
18131800
getMainWindow()?.webContents.send('walletDisconnected', code, reason)
1814-
}
1801+
})
18151802

1816-
export const accountsChanged: AccountsChangedType = function (
1817-
accounts: string[]
1818-
) {
1819-
getMainWindow()?.webContents.send('accountChanged', accounts)
1820-
}
1803+
backendEvents.on('connectionRequestRejected', function () {
1804+
getMainWindow()?.webContents.send('connectionRequestRejected')
1805+
})
18211806

1822-
export const chainChanged: ChainChangedType = function (chainId: number) {
1807+
backendEvents.on('chainChanged', function (chainId: number) {
18231808
getMainWindow()?.webContents.send('chainChanged', chainId)
1824-
}
1809+
})
18251810

1826-
export const connectionRequestRejected: ConnectionRequestRejectedType =
1827-
function () {
1828-
getMainWindow()?.webContents.send('connectionRequestRejected')
1829-
}
1811+
backendEvents.on('accountsChanged', function (accounts: string[]) {
1812+
getMainWindow()?.webContents.send('accountChanged', accounts)
1813+
})
18301814

1831-
ProviderHelper.passEventCallbacks(
1832-
accountsChanged,
1833-
walletConnected,
1834-
walletDisconnected,
1835-
chainChanged,
1836-
connectionRequestRejected
1837-
)
1815+
backendEvents.on('metamaskOtpUpdated', function (otp: string) {
1816+
getMainWindow()?.webContents.send('metamaskOtpUpdated', otp)
1817+
})
18381818

18391819
ipcMain.on('openHyperplaySite', async () => openUrlOrFile(hyperplaySite))
18401820

‎src/backend/metrics/metrics.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { apiObject } from '@rudderstack/rudder-sdk-node'
22
import { sendFrontendMessage } from 'backend/main_window'
33
import { GameInfo, MetricsOptInStatus } from 'common/types'
44
import Store from 'electron-store'
5-
import web3 from 'web3'
65
import { getAppVersion, getFormattedOsName, processIsClosed } from '../utils'
76
import { rudderstack } from './rudderstack-client'
87
import { PossibleMetricEventNames, PossibleMetricPayloads } from './types'
98
import { hrtime } from 'process'
109
import find from 'find-process'
1110
import { backendEvents } from 'backend/backend_events'
11+
import { ethers } from 'ethers'
1212

1313
/**
1414
* Our global anonymous id which is used for any events that contain data that
@@ -98,7 +98,7 @@ const METRICS_PARTICIPATION_EVENTS = ['Metrics Opt-in', 'Metrics Opt-out']
9898
* @returns A random hex string
9999
*/
100100
function generateRandomId() {
101-
return web3.utils.randomHex(24)
101+
return ethers.hexlify(ethers.randomBytes(24))
102102
}
103103

104104
/**

0 commit comments

Comments
 (0)