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

On ramp integration cleanup #1256

Merged
merged 7 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
67 changes: 3 additions & 64 deletions apps/desktop-wallet/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { configureAutoUpdater, handleAutoUpdaterUserActions, setupAutoUpdaterLis
import { setupLedgerDevicePermissions } from './ledger'
import { setupAppMenu } from './menu'
import { handleNativeThemeUserActions, setupNativeThemeListeners } from './nativeTheme'
import { handleOnRampWindows } from './onRamp'
import { ICON_PATH, RENDERER_PATH } from './paths'
import { IS_RC, isIpcSenderValid, isMac, isWindows } from './utils'
import {
Expand All @@ -34,8 +35,6 @@ contextMenu()
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow: BrowserWindow | null
// Window for on-ramp services
let onRampWindow: BrowserWindow | null

function createWindow() {
mainWindow = new BrowserWindow({
Expand Down Expand Up @@ -127,6 +126,8 @@ app.on('ready', async function () {

handleAutoUpdaterUserActions()

handleOnRampWindows(mainWindow)

ipcMain.handle('app:hide', ({ senderFrame }) => {
if (!isIpcSenderValid(senderFrame)) return null

Expand Down Expand Up @@ -208,68 +209,6 @@ app.on('ready', async function () {
mainWindow?.webContents.send('window:maximized', false)
})

ipcMain.handle('app:openOnRampServiceWindow', (event, { url, targetLocation }) => {
if (onRampWindow) {
onRampWindow.show()
return
}

onRampWindow = new BrowserWindow({
width: 1000,
height: 800,
webPreferences: {
contextIsolation: true,
webSecurity: true
}
})

onRampWindow.loadURL(url)

onRampWindow.webContents.on('did-navigate', (event, currentUrl) => {
console.log(`Navigated to: ${currentUrl}`)
if (currentUrl.includes(targetLocation)) {
onRampWindow?.close()
onRampWindow = null

mainWindow?.webContents.send('target-location-reached')
}
})

// Ensure window reference is cleaned up
onRampWindow.on('closed', () => {
onRampWindow = null
})

// Handle child windows opening (onramper opens provider in a new window)
onRampWindow.webContents.setWindowOpenHandler(({ url }) => {
const childWindow = new BrowserWindow({
parent: onRampWindow!,
width: 800,
height: 600,
webPreferences: {
contextIsolation: true,
webSecurity: true
}
})
childWindow.loadURL(url)

// Listen for navigation events on the new window
childWindow.webContents.on('did-navigate', (event, currentUrl) => {
console.log(`Child window navigated to: ${currentUrl}`)
if (currentUrl.includes(targetLocation)) {
childWindow?.close()
onRampWindow?.close()
onRampWindow = null

mainWindow?.webContents.send('target-location-reached')
}
})

// Prevent the default action (which would be Electron creating a default window)
return { action: 'deny' }
})
})

createWindow()
})

Expand Down
63 changes: 63 additions & 0 deletions apps/desktop-wallet/electron/onRamp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { BrowserWindow, ipcMain } from 'electron'

export const handleOnRampWindows = (mainWindow: BrowserWindow | null) => {
let onRampWindow: BrowserWindow | null

ipcMain.handle('app:openOnRampServiceWindow', (event, { url, targetLocation }) => {
if (onRampWindow) {
onRampWindow.show()
return
}

onRampWindow = new BrowserWindow({
width: 1000,
height: 800,
webPreferences: {
contextIsolation: true,
webSecurity: true
}
})

// Ensure window reference is cleaned up when closed
onRampWindow.on('closed', () => {
onRampWindow = null
})

onRampWindow.loadURL(url)

onRampWindow.webContents.on('did-navigate', (event, currentUrl) => {
if (currentUrl.includes(targetLocation)) {
onRampWindow?.close()

mainWindow?.webContents.send('target-location-reached')
}
})

// Handle child windows opening (onramper opens provider in a new window)
onRampWindow.webContents.setWindowOpenHandler(({ url }) => {
const childWindow = new BrowserWindow({
parent: onRampWindow!,
width: 800,
height: 600,
webPreferences: {
contextIsolation: true,
webSecurity: true
}
})
childWindow.loadURL(url)

// Listen for navigation events on the new window
childWindow.webContents.on('did-navigate', (event, currentUrl) => {
if (currentUrl.includes(targetLocation)) {
childWindow?.close()
onRampWindow?.close()

mainWindow?.webContents.send('target-location-reached')
}
})

// Prevent the default action (which would be Electron creating a default window)
return { action: 'deny' }
})
})
}
6 changes: 3 additions & 3 deletions apps/desktop-wallet/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ contextBridge.exposeInMainWorld('electron', {
openOnRampServiceWindow: ({ url, targetLocation }: { url: string; targetLocation: string }) =>
ipcRenderer.invoke('app:openOnRampServiceWindow', { url, targetLocation }),
onOnRampTargetLocationReached: (callback: () => void) => {
ipcRenderer.on('target-location-reached', callback)

return () => ipcRenderer.removeListener('target-location-reached', callback)
const sanitizedCallback = (_event: IpcRendererEvent) => callback()
ipcRenderer.on('target-location-reached', sanitizedCallback)
return () => ipcRenderer.removeListener('target-location-reached', sanitizedCallback)
},
setProxySettings: (proxySettings: ProxySettings) => ipcRenderer.invoke('app:setProxySettings', proxySettings),
restart: () => ipcRenderer.invoke('app:restart')
Expand Down
6 changes: 3 additions & 3 deletions apps/desktop-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@
"dependencies": {
"@tanstack/react-query": "5.45.0",
"@tanstack/react-query-devtools": "^5.50.1",
"axios": "^1.7.4",
"electron-context-menu": "^3.1.2",
"electron-is-dev": "^2.0.0",
"electron-updater": "^6.3.9",
"react-custom-scroll": "^7.0.0"
"electron-updater": "^6.3.9"
},
"trustedDependencies": [
"electron",
Expand Down Expand Up @@ -97,6 +95,7 @@
"@walletconnect/utils": "2.17.2",
"@yornaath/batshit": "^0.10.1",
"ajv": "^8.12.0",
"axios": "^1.7.4",
"better-sqlite3": "^8.3.0",
"bip39": "^3.0.4",
"classnames": "^2.3.1",
Expand Down Expand Up @@ -129,6 +128,7 @@
"react-apexcharts": "^1.4.0",
"react-color": "^2.19.3",
"react-confetti": "^6.0.1",
"react-custom-scroll": "^7.0.0",
"react-detect-click-outside": "^1.1.2",
"react-dom": "^18.2.0",
"react-hook-form": "^7.42.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ const useFetchAddressSingleTokenBalances = ({
})

return {
data: (isALPH ? alphBalances : addressTokenBalances) || {
availableBalance: '0',
lockedBalance: '0',
totalBalance: '0'
},
data: isALPH ? alphBalances : addressTokenBalances,
isLoading: isALPH ? isLoadingAlphBalances : isLoadingTokenBalances
}
}
Expand Down
6 changes: 2 additions & 4 deletions apps/desktop-wallet/src/style/globalStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,10 @@ export const GlobalStyle = createGlobalStyle`
}
}

// Custom scrollbars theme
.rcs-inner-handle {
color: white;
background-color: ${({ theme }) =>
colord(theme.font.tertiary)
.alpha(theme.name === 'light' ? 0.1 : 0.15)
.toHex()} !important;
background-color: ${({ theme }) => colord(theme.font.primary).alpha(0.1).toHex()} !important;
}
`

Expand Down
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading