From 1d16817d561181fff314e3f23d9207d97aeda286 Mon Sep 17 00:00:00 2001 From: ismurzin Date: Fri, 31 May 2024 22:09:48 +0700 Subject: [PATCH] add vip dependency to getFixRateFrorAmount + remove double request from createFixTransaction --- .../changelly2/remote/Changelly2Repository.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/mbw/src/main/java/com/mycelium/wallet/external/changelly2/remote/Changelly2Repository.kt b/mbw/src/main/java/com/mycelium/wallet/external/changelly2/remote/Changelly2Repository.kt index 89c02474d..0655d6af0 100644 --- a/mbw/src/main/java/com/mycelium/wallet/external/changelly2/remote/Changelly2Repository.kt +++ b/mbw/src/main/java/com/mycelium/wallet/external/changelly2/remote/Changelly2Repository.kt @@ -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( @@ -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) {