-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: adds Transak support * WIP UI * enhancement: position of transak window and browser window options Co-authored-by: Jean Ribeiro <[email protected]> * ui: layout and panes for buy view * fix: only call function if darwin * fix: use integers to set position * remove buy sell router * isolate most of transak code into a manager * improve UI * removes unused code * disable feature flag * add only available network --------- Co-authored-by: Nicole O'Brien <[email protected]> Co-authored-by: Tuditi <[email protected]> Co-authored-by: Mark Nardi <[email protected]>
- Loading branch information
1 parent
6d65fb0
commit 499ec30
Showing
29 changed files
with
438 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { IFeatureFlag } from '@lib/features/interfaces' | ||
|
||
const buySellFeatures: IFeatureFlag = { | ||
enabled: false, | ||
} | ||
|
||
export default buySellFeatures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
packages/desktop/lib/electron/managers/transak.manager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import { BrowserWindow, app } from 'electron' | ||
import { windows } from '../constants/windows.constant' | ||
import features from '@features/features' | ||
import { ITransakManager, ITransakWindowData } from '@core/app' | ||
import path from 'path' | ||
|
||
const SIDEBAR_WIDTH_EXPANDED = 256 | ||
const SIDEBAR_WIDTH_CLOSED = 80 | ||
const BORDER_HEIGHT = 1 | ||
const WINDOWS_TITLEBAR_HEIGHT = 28 | ||
const NAVBAR_HEIGHT = 40 | ||
const DASHBOARD_CONTAINER_PADDING = 32 | ||
|
||
export default class TransakManager implements ITransakManager { | ||
private sidebarExpanded = false | ||
private htmlPath = app.isPackaged | ||
? path.join(app.getAppPath(), '/public/transak.html') | ||
: path.join(__dirname, '../transak.html') | ||
private preloadPath = app.isPackaged | ||
? path.join(app.getAppPath(), '/public/build/transak.preload.js') | ||
: path.join(__dirname, 'transak.preload.js') | ||
|
||
public setSidebarExpanded(isOpen: boolean): void { | ||
this.sidebarExpanded = isOpen | ||
} | ||
|
||
public closeWindow(): void { | ||
if (windows.transak) { | ||
windows.transak.close() | ||
windows.transak = null | ||
} | ||
} | ||
|
||
public openWindow(data: ITransakWindowData): BrowserWindow { | ||
if (windows.transak !== null) { | ||
return windows.transak | ||
} | ||
|
||
windows.transak = new BrowserWindow({ | ||
parent: windows.main, | ||
width: 480, | ||
height: this.getWindowHeight(), | ||
useContentSize: true, | ||
titleBarStyle: 'hidden', | ||
frame: false, | ||
show: true, | ||
fullscreenable: false, | ||
transparent: true, | ||
movable: false, | ||
resizable: false, | ||
minimizable: false, | ||
skipTaskbar: true, | ||
acceptFirstMouse: true, | ||
hasShadow: false, | ||
thickFrame: false, | ||
roundedCorners: false, | ||
webPreferences: { | ||
nodeIntegration: false, | ||
contextIsolation: true, | ||
disableBlinkFeatures: 'Auxclick', | ||
webviewTag: false, | ||
enableWebSQL: false, | ||
devTools: !app.isPackaged || features?.electron?.developerTools?.enabled, | ||
preload: this.preloadPath, | ||
}, | ||
}) | ||
|
||
if (process.platform === 'darwin') { | ||
windows.transak.setWindowButtonVisibility(false) | ||
} | ||
|
||
this.positionWindow() | ||
this.sizeWindow() | ||
windows.main.on('move', () => this.positionWindow()) | ||
windows.main.on('resize', () => { | ||
this.positionWindow() | ||
this.sizeWindow() | ||
}) | ||
|
||
windows.transak.once('closed', () => { | ||
windows.transak = null | ||
}) | ||
|
||
windows.transak.webContents.session.setPermissionRequestHandler((webContents, permission, callback) => { | ||
if (permission === 'media') { | ||
callback(true) | ||
} else { | ||
callback(false) | ||
} | ||
}) | ||
|
||
void windows.transak.loadFile(this.htmlPath) | ||
windows.transak.webContents.on('did-finish-load', () => { | ||
const _data = { | ||
currency: data.currency, | ||
address: data.address, | ||
stage: app.isPackaged ? 'production' : 'staging', | ||
apiKey: process.env.TRANSAK_API_KEY, | ||
service: data.service, | ||
} | ||
windows.transak.webContents.send('transak-data', _data) | ||
}) | ||
|
||
windows.transak.setMenu(null) | ||
|
||
return windows.transak | ||
} | ||
|
||
public positionWindow(): void { | ||
if (windows.transak && windows.transak) { | ||
const [mainWindowX, mainWindowY] = windows.main.getPosition() | ||
const [mainWindowWidth] = windows.main.getSize() | ||
const [transakWidth] = windows.transak.getSize() | ||
|
||
const sidebarWidth = this.sidebarExpanded ? SIDEBAR_WIDTH_EXPANDED : SIDEBAR_WIDTH_CLOSED | ||
const dashboardWidth = mainWindowWidth - sidebarWidth | ||
const transakX = Math.floor(mainWindowX + sidebarWidth + dashboardWidth / 2 - transakWidth / 2) | ||
const topBarHeight = this.getTopBarHeight() | ||
const transakY = mainWindowY + topBarHeight + DASHBOARD_CONTAINER_PADDING + BORDER_HEIGHT | ||
|
||
windows.transak.setPosition(transakX, transakY) | ||
} | ||
} | ||
|
||
private sizeWindow(): void { | ||
const [transakWidth] = windows.transak.getSize() | ||
const transakHeight = this.getWindowHeight() | ||
windows.transak.setSize(transakWidth, transakHeight) | ||
} | ||
|
||
private getTopBarHeight(): number { | ||
const titleBarHeight = process.platform === 'win32' ? WINDOWS_TITLEBAR_HEIGHT + BORDER_HEIGHT : 0 | ||
const topBarHeight = NAVBAR_HEIGHT + BORDER_HEIGHT + titleBarHeight | ||
return topBarHeight | ||
} | ||
|
||
private getWindowHeight(): number { | ||
const [, mainWindowHeight] = windows.main.getSize() | ||
const topBarHeight = this.getTopBarHeight() | ||
return mainWindowHeight - topBarHeight - (DASHBOARD_CONTAINER_PADDING + BORDER_HEIGHT) * 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { IpcRendererEvent, ipcRenderer } from 'electron' | ||
|
||
interface TransakData { | ||
apiKey: string | ||
currency: string | ||
address: string | ||
stage: 'production' | 'staging' | ||
service: 'BUY' | 'SELL' | ||
} | ||
|
||
window.addEventListener('DOMContentLoaded', () => { | ||
ipcRenderer.on('transak-data', (_: IpcRendererEvent, data: TransakData) => { | ||
window.document.documentElement.style.height = '100%' | ||
window.document.body.style.margin = '0' | ||
window.document.body.style.padding = '0' | ||
window.document.body.style.width = '100dvw' | ||
window.document.body.style.height = '100dvh' | ||
window.document.body.style.borderRadius = '16px' | ||
window.document.body.style.display = 'flex' | ||
window.document.body.style.alignItems = 'center' | ||
window.document.body.style.justifyContent = 'center' | ||
|
||
if (window.document.getElementById('transakIframe')) { | ||
return | ||
} | ||
|
||
const { apiKey, currency, address, stage, service } = data | ||
const transakUrl = stage === 'production' ? 'https://global.transak.com' : 'https://global-stg.transak.com' | ||
|
||
const iframe = window.document.createElement('iframe') | ||
iframe.id = 'transakIframe' | ||
iframe.src = `${transakUrl}/?apiKey=${apiKey}&defaultFiatCurrency=${currency}&walletAddress=${address}&productsAvailed=${service}&cryptoCurrencyCode=IOTA&network=miota&themeColor=7C41C9&hideMenu=true` | ||
iframe.style.width = '100%' | ||
iframe.style.height = '100%' | ||
iframe.style.border = 'none' | ||
iframe.style.borderRadius = '16px' | ||
iframe.allow = 'camera;microphone;payment' | ||
iframe.sandbox.add('allow-scripts', 'allow-same-origin') | ||
|
||
window.document.body.appendChild(iframe) | ||
|
||
window.addEventListener('message', (message) => { | ||
if (message.source !== iframe.contentWindow) return | ||
|
||
if (message?.data?.event_id === 'TRANSAK_ORDER_SUCCESSFUL') { | ||
void ipcRenderer.invoke('close-transak') | ||
} | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/> | ||
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'self'; frame-src https://global-stg.transak.com https://global.transak.com; object-src 'none';"> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.