@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
41 lines • 1.58 kB
JavaScript
import axios from "axios";
export async function getMinimumSwapAmount(AccountFrom, AccountTo) {
try {
const requestConfig = {
method: "GET",
url: `https://swap-stg.ledger-test.com/v5/quote`,
params: {
from: AccountFrom.currency.id,
to: AccountTo.currency.id,
amountFrom: 0.0001,
addressFrom: AccountFrom.address,
fiatForCounterValue: "USD",
slippage: 1,
networkFees: 0.001,
networkFeesCurrency: AccountTo.currency.speculosApp.name.toLowerCase(),
displayLanguage: "en",
theme: "light",
"providers-whitelist": "changelly,exodus,thorswap,uniswap,cic",
tradeType: "INPUT",
uniswapOrderType: "uniswapxv1",
},
headers: {
accept: "application/json",
},
};
const { data } = await axios(requestConfig);
const minimumAmounts = data
.filter((item) => item.parameter?.minAmount !== undefined)
.map((item) => parseFloat(item.parameter.minAmount))
.filter((amount) => !isNaN(amount));
if (minimumAmounts.length === 0) {
throw new Error("No valid minimum amounts returned from swap quote API.");
}
return Math.max(...minimumAmounts);
}
catch (error) {
console.error("Error fetching swap minimum amount:", error);
throw error;
}
}
//# sourceMappingURL=swap.js.map