Skip to content

Commit

Permalink
fix(server): changelly limits
Browse files Browse the repository at this point in the history
  • Loading branch information
mahnunchik committed May 10, 2024
1 parent 15a1210 commit 1631eb4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions server/lib/changelly.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,29 @@ async function estimate(from, to, value) {
async function estimateV4(from, to, value) {
const fromCrypto = getCrypto(from);
const toCrypto = getCrypto(to);

const { result: params } = await request('getPairsParams', [{
from: fromCrypto.changelly.ticker,
to: toCrypto.changelly.ticker,
}]);
if (!params || !params[0]) {
return {
error: 'ExchangeDisabled',
};
}
if (Big(value).lt(params[0].minAmountFloat)) {
return {
error: 'SmallAmountError',
amount: normalizeNumber(params[0].minAmountFloat, fromCrypto.decimals),
};
}
if (Big(value).gt(params[0].maxAmountFloat)) {
return {
error: 'BigAmountError',
amount: normalizeNumber(params[0].maxAmountFloat, fromCrypto.decimals),
};
}

const data = await request('getExchangeAmount', [{
from: fromCrypto.changelly.ticker,
to: toCrypto.changelly.ticker,
Expand Down

0 comments on commit 1631eb4

Please sign in to comment.