Skip to content

Commit

Permalink
enhancement: default amount to 100 dollars with conversion to each fi…
Browse files Browse the repository at this point in the history
…at currency (#2119)
  • Loading branch information
jeeanribeiro authored Mar 13, 2024
1 parent 8dd6453 commit 46af768
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/desktop/lib/electron/managers/transak.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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',
Expand Down
5 changes: 2 additions & 3 deletions packages/desktop/lib/electron/processes/main.process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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`)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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<void> {
await Platform.closeTransak()
await Platform.openTransak({
currency: $activeProfile?.settings.marketCurrency,
address: $selectedAccount.depositAddress,
service: 'BUY',
amount: getDefaultFiatAmount($activeProfile?.settings.marketCurrency ?? MarketCurrency.Usd),
})
await updateTransakBounds()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export interface ITransakWindowData {
currency: string
address: string
service: 'BUY' | 'SELL'
amount: number
}

0 comments on commit 46af768

Please sign in to comment.