Skip to content

Commit

Permalink
feat: adds dark mode in Transak (#2154)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeeanribeiro authored Mar 18, 2024
1 parent ea79bd3 commit ecf5227
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
10 changes: 9 additions & 1 deletion packages/desktop/lib/electron/managers/transak.manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BrowserWindow, app, shell, screen } from 'electron'
import { BrowserWindow, app, shell, screen, nativeTheme } from 'electron'
import { windows } from '../constants/windows.constant'
import features from '@features/features'
import { ITransakManager, ITransakWindowData } from '@core/app'
Expand Down Expand Up @@ -213,6 +213,13 @@ export default class TransakManager implements ITransakManager {
throw new Error('Invalid Transak service')
}

const colorMode =
nativeTheme.themeSource === 'system'
? nativeTheme.shouldUseDarkColors
? 'DARK'
: 'LIGHT'
: nativeTheme.themeSource.toUpperCase()

const queryParams = {
apiKey,
defaultFiatCurrency: currency,
Expand All @@ -226,6 +233,7 @@ export default class TransakManager implements ITransakManager {
disableWalletAddressForm: true,
isFeeCalculationHidden: true,
disablePaymentMethods: ['apple_pay', 'google_pay'],
colorMode,
}

const urlObject = buildUrl({ origin: TRANSAK_WIDGET_URL, query: queryParams })
Expand Down
7 changes: 6 additions & 1 deletion packages/desktop/lib/electron/processes/main.process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,12 @@ nativeTheme.on('updated', () => {
})

ipcMain.handle('get-theme', () => nativeTheme.themeSource)
ipcMain.handle('update-theme', (_e, theme) => (nativeTheme.themeSource = theme))
ipcMain.handle('update-theme', (_e, theme) => {
nativeTheme.themeSource = theme
if (features?.buySell?.enabled) {
windows.main.webContents.send('reset-transak')
}
})
ipcMain.handle('should-be-dark-mode', () => nativeTheme.shouldUseDarkColors)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { Platform } from '@core/app'
import { activeProfile } from '@core/profile/stores'
import { IPopupState, IProfileAuthPopupState, popupState, profileAuthPopup } from '@desktop/auxiliary/popup'
import { onDestroy, tick } from 'svelte'
import { onDestroy, onMount, tick } from 'svelte'
import {
TransakAccountPanel,
TransakConnectionPanel,
Expand All @@ -17,13 +17,15 @@
import { DrawerState } from '@desktop/auxiliary/drawer/types'
import { drawerState } from '@desktop/auxiliary/drawer/stores'
let isTransakOpen: boolean = false
$: $isDashboardSideBarExpanded, void updateTransakBounds()
$: if ($selectedAccountIndex !== undefined) {
void resetTransak()
}
$: void handleOverlayChanges($popupState, $profileAuthPopup, $settingsState, $drawerState)
$: isTransakOpen, void handleOverlayChanges($popupState, $profileAuthPopup, $settingsState, $drawerState)
async function handleOverlayChanges(
state: IPopupState,
Expand Down Expand Up @@ -87,17 +89,25 @@
async function resetTransak(): Promise<void> {
await Platform.closeTransak()
isTransakOpen = false
await Platform.openTransak({
currency: $activeProfile?.settings.marketCurrency,
address: $selectedAccount.depositAddress,
service: 'BUY',
amount: getDefaultFiatAmount($activeProfile?.settings.marketCurrency ?? MarketCurrency.Usd),
})
isTransakOpen = true
await updateTransakBounds()
}
onMount(() => {
Platform.onEvent('reset-transak', resetTransak)
})
onDestroy(() => {
void Platform.closeTransak()
isTransakOpen = false
Platform.removeListenersForEvent('reset-transak')
})
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface IPlatformEventMap {
'nft-download-done': INFTDownloadState
'nft-download-interrupted': INFTDownloadState
'notification-activated': unknown
'reset-transak': void
'signed-eip712': IEvmSignature
'signed-message': IEvmSignature
'transak-not-loaded': void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { MarketCurrency } from '@core/market/enums/market-currency.enum'

export interface ITransakWindowData {
currency: string
currency: MarketCurrency
address: string
service: 'BUY' | 'SELL'
amount: number
Expand Down

0 comments on commit ecf5227

Please sign in to comment.