diff --git a/packages/desktop/lib/electron/managers/transak.manager.ts b/packages/desktop/lib/electron/managers/transak.manager.ts index 6dff3c91f0..00af4cab2b 100644 --- a/packages/desktop/lib/electron/managers/transak.manager.ts +++ b/packages/desktop/lib/electron/managers/transak.manager.ts @@ -202,7 +202,7 @@ export default class TransakManager implements ITransakManager { } private getUrl(data: ITransakWindowData): string { - const { address, currency, service } = data + const { address, currency, service, amount } = data const apiKey = process.env.TRANSAK_API_KEY if (!Object.values(MarketCurrency).includes(currency as MarketCurrency)) { @@ -216,7 +216,7 @@ export default class TransakManager implements ITransakManager { const queryParams = { apiKey, defaultFiatCurrency: currency, - defaultCryptoAmount: 100, + defaultFiatAmount: amount, walletAddress: address, productsAvailed: service, cryptoCurrencyCode: 'IOTA', diff --git a/packages/desktop/lib/electron/processes/main.process.ts b/packages/desktop/lib/electron/processes/main.process.ts index 7dfcfaea8c..037fb1cfde 100644 --- a/packages/desktop/lib/electron/processes/main.process.ts +++ b/packages/desktop/lib/electron/processes/main.process.ts @@ -34,6 +34,7 @@ import { shouldReportError } from '../utils/error.utils' import { ensureDirectoryExistence } from '../utils/file-system.utils' import { getMachineId } from '../utils/os.utils' import { registerPowerMonitorListeners } from '../listeners' +import { ITransakWindowData } from '@core/app/interfaces' export let appIsReady = false @@ -374,9 +375,7 @@ export function getOrInitWindow(windowName: string, ...args: unknown[]): Browser case 'error': return openErrorWindow() case 'transak': - return transakManager?.openWindow( - args[0] as { currency: string; address: string; service: 'BUY' | 'SELL' } - ) + return transakManager?.openWindow(args[0] as ITransakWindowData) default: throw Error(`Window ${windowName} not found`) } diff --git a/packages/desktop/views/dashboard/buy-sell/views/BuySellMainView.svelte b/packages/desktop/views/dashboard/buy-sell/views/BuySellMainView.svelte index 1ae9b58eda..b22f536cdf 100644 --- a/packages/desktop/views/dashboard/buy-sell/views/BuySellMainView.svelte +++ b/packages/desktop/views/dashboard/buy-sell/views/BuySellMainView.svelte @@ -12,6 +12,8 @@ TransakWindowPlaceholder, } from '../components' import { isDashboardSideBarExpanded } from '@core/ui' + import { MarketCoinId, MarketCurrency } from '@core/market/enums' + import { marketCoinPrices } from '@core/market/stores' import { DrawerState } from '@desktop/auxiliary/drawer/types' import { drawerState } from '@desktop/auxiliary/drawer/stores' @@ -59,12 +61,37 @@ }) } + function getDefaultFiatAmount(currency: MarketCurrency): number { + switch (currency) { + case MarketCurrency.Usd: + case MarketCurrency.Eur: + case MarketCurrency.Gbp: + return 100 + default: { + const conversionRate = + $marketCoinPrices[MarketCoinId.Iota]?.[currency] / + $marketCoinPrices[MarketCoinId.Iota]?.[MarketCurrency.Usd] + const fiatAmount = 100 * conversionRate + const roundedAmount = customRound(fiatAmount) + return roundedAmount + } + } + } + + function customRound(number) { + const magnitude = Math.pow(10, Math.floor(Math.log10(number))) + return magnitude <= 10 + ? Math.round(number / magnitude) * magnitude + : Math.round((number / magnitude) * 10) * (magnitude / 10) + } + async function resetTransak(): Promise { await Platform.closeTransak() await Platform.openTransak({ currency: $activeProfile?.settings.marketCurrency, address: $selectedAccount.depositAddress, service: 'BUY', + amount: getDefaultFiatAmount($activeProfile?.settings.marketCurrency ?? MarketCurrency.Usd), }) await updateTransakBounds() } diff --git a/packages/shared/src/lib/core/app/interfaces/transak-window-data.interface.ts b/packages/shared/src/lib/core/app/interfaces/transak-window-data.interface.ts index c60397178d..bfec2f07c6 100644 --- a/packages/shared/src/lib/core/app/interfaces/transak-window-data.interface.ts +++ b/packages/shared/src/lib/core/app/interfaces/transak-window-data.interface.ts @@ -2,4 +2,5 @@ export interface ITransakWindowData { currency: string address: string service: 'BUY' | 'SELL' + amount: number }