@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
48 lines • 1.92 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMinimumSwapAmount = void 0;
const axios_1 = __importDefault(require("axios"));
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 (0, axios_1.default)(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;
}
}
exports.getMinimumSwapAmount = getMinimumSwapAmount;
//# sourceMappingURL=swap.js.map