UNPKG

@ledgerhq/live-common

Version:
39 lines 1.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useFetchRates = useFetchRates; const helpers_1 = require("@ledgerhq/ledger-wallet-framework/account/helpers"); const fetchRates_1 = require("../../api/v5/fetchRates"); const useAPI_1 = require("../../../../hooks/useAPI"); const useFilteredProviders_1 = require("./useFilteredProviders"); function useFetchRates({ fromCurrencyAccount, toCurrency, fromCurrencyAmount, onSuccess, isEnabled = true, }) { const currencyFrom = fromCurrencyAccount ? (0, helpers_1.getAccountCurrency)(fromCurrencyAccount).id : undefined; const unitFrom = fromCurrencyAccount ? (0, helpers_1.getAccountCurrency)(fromCurrencyAccount).units[0] : undefined; const unitTo = toCurrency?.units[0]; const formattedCurrencyAmount = (unitFrom && `${fromCurrencyAmount.shiftedBy(-unitFrom.magnitude)}`) ?? "0"; const { providers, loading, error } = (0, useFilteredProviders_1.useFilteredProviders)(); const toCurrencyId = toCurrency?.id; return (0, useAPI_1.useAPI)({ queryFn: fetchRates_1.fetchRates, queryProps: { providers, unitTo: unitTo, unitFrom: unitFrom, currencyFrom, toCurrencyId, fromCurrencyAmount: formattedCurrencyAmount, }, staleTimeout: 20000, enabled: !!toCurrencyId && !!currencyFrom && fromCurrencyAmount.gt(0) && !!unitFrom && !!unitTo && !loading && isEnabled && !error, onSuccess, }); } //# sourceMappingURL=useFetchRates.js.map