Skip to content

Commit

Permalink
add vip dependency to getFixRateFrorAmount + remove double request fr…
Browse files Browse the repository at this point in the history
…om createFixTransaction
  • Loading branch information
ismurzin committed May 31, 2024
1 parent 5e6d2a4 commit 1d16817
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ object Changelly2Repository {
finally: (() -> Unit)? = null
) =
doRequest(scope, {
changellyApi.getFixRateForAmount(exportSymbol(from), exportSymbol(to), amount)
val isVip = userRepository.statusFlow.value.isVIP()
val api = if (isVip) viperApi else changellyApi
api.getFixRateForAmount(exportSymbol(from), exportSymbol(to), amount)
}, success, error, finally)

fun fixRate(
Expand Down Expand Up @@ -77,17 +79,12 @@ object Changelly2Repository {
)
}
try {
// changelly can handle rates only from same api keys
// that's why new rateId should be refetched
val rate = viperApi.getFixRate(fromSymbol, toSymbol)
val viperRateId = rate.body()?.result?.firstOrNull()?.id
?: throw RuntimeException("Unable to fetch rates")
return viperApi.createFixTransaction(
fromSymbol,
toSymbol,
amount,
addressTo,
viperRateId,
rateId,
refundAddress,
)
} catch (e: Exception) {
Expand Down

0 comments on commit 1d16817

Please sign in to comment.