Skip to content

Commit

Permalink
feat: adds getPrice function
Browse files Browse the repository at this point in the history
  • Loading branch information
jeeanribeiro committed Jul 17, 2024
1 parent 1efab18 commit 684f2bb
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/desktop/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ const rendererPlugins = [
PRELOAD_SCRIPT: JSON.stringify(false),
'process.env.APP_PROTOCOL': JSON.stringify(appProtocol),
'process.env.WALLETCONNECT_PROJECT_ID': JSON.stringify(process.env.WALLETCONNECT_PROJECT_ID),
'process.env.TRANSAK_API_KEY': JSON.stringify(process.env.TRANSAK_API_KEY),
}),
// The ethereumjs libraries require the NormalModuleReplacementPlugin & the ProvidePlugin
new NormalModuleReplacementPlugin(/node:/, (resource) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { TransakApi } from '../apis'
import { ITransakApiPriceParams } from '../interfaces'

export async function getTransakPrice(
params: ITransakApiPriceParams
): Promise<{ fiatAmount: number; cryptoAmount: number } | undefined> {
const transakApi = new TransakApi()
const { response } = (await transakApi.getPrices(params)) ?? {}

if (!response) {
return
}

const { cryptoAmount, fiatAmount } = response

return { fiatAmount, cryptoAmount }
}
1 change: 1 addition & 0 deletions packages/shared/src/lib/auxiliary/transak/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './getTransakPrice'
export * from './updateTransakCryptoCurrencies'
export * from './updateTransakFiatCurrencies'
17 changes: 17 additions & 0 deletions packages/shared/src/lib/auxiliary/transak/apis/transak.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
ITransakApiCryptoCurrenciesResponse,
ITransakApiCryptoCurrenciesResponseItem,
ITransakApiFiatCurrenciesResponse,
ITransakApiPriceParams,
ITransakApiPriceResponse,
} from '../interfaces'
import { TransakApiEndpoint } from '../enums'

Expand Down Expand Up @@ -39,4 +41,19 @@ export class TransakApi extends BaseApi {
})
return filteredResponse
}

async getPrices(params: ITransakApiPriceParams): Promise<ITransakApiPriceResponse | undefined> {
const partnerApiKey = process.env.TRANSAK_API_KEY ?? ''
const { fiatCurrency, cryptoCurrency, isBuyOrSell, networkName, paymentMethod, fiatAmount } = params
const response = await this.get<ITransakApiPriceResponse>(TransakApiEndpoint.Price, {
partnerApiKey,
fiatCurrency,
cryptoCurrency,
isBuyOrSell,
networkName,
paymentMethod,
fiatAmount,
})
return response
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum TransakApiEndpoint {
CryptoCurrencies = 'api/v2/currencies/crypto-currencies',
FiatCurrencies = 'fiat/public/v1/currencies/fiat-currencies',
Price = 'api/v1/pricing/public/quotes',
}
2 changes: 2 additions & 0 deletions packages/shared/src/lib/auxiliary/transak/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './transak-api-crypto-currencies-response.interface'
export * from './transak-api-fiat-currencies-response.interface'
export * from './transak-api-price-params.interface'
export * from './transak-api-price-response.interface'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { FiatCurrency } from '@core/market/enums'

export interface ITransakApiPriceParams {
fiatCurrency: keyof typeof FiatCurrency
cryptoCurrency: string
isBuyOrSell: 'BUY' | 'SELL'
networkName: string
paymentMethod: string
fiatAmount: number
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
interface ITransakApiPriceResponseFeeBreakdown {
name: string
value: number
id: string
ids: string[]
}

interface ITransakApiPriceResponseContent {
quoteId: string
conversionPrice: number
marketConversionPrice: number
slippage: number
fiatCurrency: string
cryptoCurrency: string
paymentMethod: string
fiatAmount: number
cryptoAmount: number
isBuyOrSell: 'BUY' | 'SELL'
network: string
feeDecimal: number
totalFee: number
feeBreakdown: ITransakApiPriceResponseFeeBreakdown[]
nonce: number
cryptoLiquidityProvider: string
notes: string[]
}

export interface ITransakApiPriceResponse {
response: ITransakApiPriceResponseContent
}

0 comments on commit 684f2bb

Please sign in to comment.