Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettCleary committed Jan 31, 2025
1 parent 1272854 commit 3fa9280
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 43 deletions.
6 changes: 5 additions & 1 deletion src/backend/extension/importer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ export const initExtension = async function (api: HyperPlayAPI) {
try {
const extensionImporter = await import('@hyperplay/extension-importer')
const isInitialized = store.get('isInitialized', false)
extensionImporter.initExtension(api, getInjectedProviderSession(), isInitialized)
extensionImporter.initExtension(
api,
getInjectedProviderSession(),
isInitialized
)
} catch (err) {
logError(`Error initializing extension ${err}`, LogPrefix.HyperPlay)
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/extension/provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ initExtensionProvider()
providerRequests.on('request', (method, ...args) => {
console.log('sending proivder request to injected browser window')
const win = getInjectedBrowserWindow()
if (win === null){
if (win === null) {
throw 'tried to send a provider request to injected provider browser window but it is not initialized yet!'
}
win.webContents.send(method, ...args)
Expand Down
56 changes: 28 additions & 28 deletions src/backend/injected_provider_window.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { app, BrowserWindow, session } from 'electron';
import { publicDir } from './constants';
import path from 'path';
import { app, BrowserWindow, session } from 'electron'
import { publicDir } from './constants'
import path from 'path'

let injectedBrowserWindow: BrowserWindow | null = null

Expand All @@ -11,32 +11,32 @@ export const getInjectedBrowserWindow = () => {
let injectedProviderSession: Electron.Session | null = null

export const getInjectedProviderSession = () => {
if (injectedProviderSession === null){
injectedProviderSession = session.fromPartition('persist:injectedProvider')
}
return injectedProviderSession
if (injectedProviderSession === null) {
injectedProviderSession = session.fromPartition('persist:injectedProvider')
}
return injectedProviderSession
}

export function createInjectedProviderWindow(){
const sessionForInjectedProviderWindow = getInjectedProviderSession()
injectedBrowserWindow = new BrowserWindow({
show: false,
webPreferences: {
webviewTag: true,
contextIsolation: true,
nodeIntegration: true,
webSecurity: app.isPackaged,
session: sessionForInjectedProviderWindow,
preload: path.join(__dirname, '../preload/preload.js'),
}
})
export function createInjectedProviderWindow() {
const sessionForInjectedProviderWindow = getInjectedProviderSession()
injectedBrowserWindow = new BrowserWindow({
show: false,
webPreferences: {
webviewTag: true,
contextIsolation: true,
nodeIntegration: true,
webSecurity: app.isPackaged,
session: sessionForInjectedProviderWindow,
preload: path.join(__dirname, '../preload/preload.js')
}
})

const devAppUrl = 'http://localhost:5173/?view=InjectedProviderApp'
const prodAppUrl = `file://${path.join(
publicDir,
'../build/index.html?view=InjectedProviderApp'
)}`
const url = app.isPackaged ? prodAppUrl : devAppUrl
injectedBrowserWindow.loadURL(url)
return injectedBrowserWindow
const devAppUrl = 'http://localhost:5173/?view=InjectedProviderApp'
const prodAppUrl = `file://${path.join(
publicDir,
'../build/index.html?view=InjectedProviderApp'
)}`
const url = app.isPackaged ? prodAppUrl : devAppUrl
injectedBrowserWindow.loadURL(url)
return injectedBrowserWindow
}
6 changes: 4 additions & 2 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,10 @@ if (!gotTheLock) {

createInjectedProviderWindow()

const providerPreloadPath = path.join(__dirname, '../preload/providerPreload.js')
const providerPreloadPath = path.join(
__dirname,
'../preload/providerPreload.js'
)
// inject window.ethereum into the main window and the overlay window
session.defaultSession.setPreloads([providerPreloadPath])

Expand Down Expand Up @@ -2121,4 +2124,3 @@ ipcMain.handle('getHyperPlayListings', async () => {
*/

import './storeManagers/legendary/eos_overlay/ipc_handler'

4 changes: 2 additions & 2 deletions src/backend/proxy/providerPreload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ const listenToRendererCalls = (
}
let prevAccounts: string[] = []
ipcRenderer[fxn]('providerApi' + topic, async (ev: any, ...args: any[]) => {
if (topic === 'accountsChanged' && args.length > 0){
if (topic === 'accountsChanged' && args.length > 0) {
const newAccts = args[0]
/**
* Our current implementation causes an infinite loop with wagmi here https://github.com/wevm/wagmi/blob/651aa72827a79f38a89f5a64209592816c8e6492/packages/connectors/src/metaMask.ts#L428-L452
* since we emit and "accountsChanged" event after a "eth_requestAccounts" request in our provider implementation. This causes onConnect to fire again in the MM connector.
* @TODO fix our provider implementation so "accountsChanged" is only emitted when accounts do change
*/
if (JSON.stringify(newAccts) === JSON.stringify(prevAccounts)){
if (JSON.stringify(newAccts) === JSON.stringify(prevAccounts)) {
return
}
prevAccounts = newAccts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const ExtensionContents = observer(() => {
* so we change the key to get it to reload when the url changes
*/
key={state}
partition='persist:injectedProvider'
partition="persist:injectedProvider"
></webview>
)
})
Expand Down
11 changes: 7 additions & 4 deletions src/frontend/InjectedProviderApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import React from 'react'
import InjectedProviderHandler from './state/InjectedProviderHandler'
import { observer } from 'mobx-react-lite'

export default observer(function(){
console.log('eth listeners bound: ', InjectedProviderHandler.ethereumListenersBound)
return <div></div>
})
export default observer(function () {
console.log(
'eth listeners bound: ',
InjectedProviderHandler.ethereumListenersBound
)
return <div></div>
})
2 changes: 1 addition & 1 deletion src/frontend/ViewManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Views = {
InjectedProviderApp: <InjectedProviderApp />
}

type Keys<T> = keyof T;
type Keys<T> = keyof T

type URLSearchParamsProxy = URLSearchParams & {
view?: Keys<typeof Views> & 'BrowserGame'
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/screens/MetaMaskHome/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const MetaMaskHome = function ({ path = 'home.html' }: MetaMaskHomeProps) {
)}`}
allowpopups={trueAsStr}
key={'metamask_home' + path + hash}
partition='persist:injectedProvider'
partition="persist:injectedProvider"
/>
</div>
</>
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/store/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const StoreController = () => {
for await (const storeKey of storeKeys) {
try {
const store = (await stores[storeKey]()).default

await store.init?.()
} catch(err){
} catch (err) {
console.error(`Error initializing store ${storeKey} ${err}`)
}
}
Expand Down

0 comments on commit 3fa9280

Please sign in to comment.