@@ -28,14 +28,12 @@ import com.tonapps.wallet.api.entity.ConfigEntity
2828import com.tonapps.wallet.api.entity.EthenaEntity
2929import com.tonapps.wallet.api.entity.OnRampArgsEntity
3030import com.tonapps.wallet.api.entity.OnRampMerchantEntity
31- import com.tonapps.wallet.api.entity.SwapEntity
3231import com.tonapps.wallet.api.entity.TokenEntity
3332import com.tonapps.wallet.api.entity.value.Timestamp
3433import com.tonapps.wallet.api.internal.ConfigRepository
3534import com.tonapps.wallet.api.internal.InternalApi
3635import com.tonapps.wallet.api.internal.SwapApi
3736import com.tonapps.wallet.api.tron.TronApi
38- import com.tonapps.wallet.api.tron.entity.TronEventEntity
3937import io.Serializer
4038import io.batteryapi.apis.DefaultApi
4139import io.batteryapi.models.Balance
@@ -61,8 +59,6 @@ import kotlinx.coroutines.delay
6159import kotlinx.coroutines.flow.Flow
6260import kotlinx.coroutines.flow.emptyFlow
6361import kotlinx.coroutines.flow.filter
64- import kotlinx.coroutines.flow.filterNotNull
65- import kotlinx.coroutines.flow.map
6662import kotlinx.coroutines.withContext
6763import okhttp3.MediaType.Companion.toMediaType
6864import okhttp3.OkHttpClient
@@ -191,19 +187,19 @@ class API(
191187 return withRetry { battery(testnet).getRechargeMethods(false ) }
192188 }
193189
194- fun getOnRampData () = internalApi.getOnRampData()
190+ fun getOnRampData () = internalApi.getOnRampData(config.webSwapsUrl )
195191
196- fun getOnRampPaymentMethods (currency : String ) = internalApi.getOnRampPaymentMethods(currency)
192+ fun getOnRampPaymentMethods (currency : String ) = internalApi.getOnRampPaymentMethods(config.webSwapsUrl, currency)
197193
198- fun getOnRampMerchants () = internalApi.getOnRampMerchants()
194+ fun getOnRampMerchants () = internalApi.getOnRampMerchants(config.webSwapsUrl )
199195
200196 fun getSwapAssets (): JSONArray = runCatching {
201- swapApi.getSwapAssets()?.let (::JSONArray )
197+ swapApi.getSwapAssets(config.webSwapsUrl )?.let (::JSONArray )
202198 }.getOrNull() ? : JSONArray ()
203199
204200 @Throws
205201 suspend fun calculateOnRamp (args : OnRampArgsEntity ): OnRampMerchantEntity .Data = withContext(Dispatchers .IO ) {
206- val data = internalApi.calculateOnRamp(args) ? : throw Exception (" Empty response" )
202+ val data = internalApi.calculateOnRamp(config.webSwapsUrl, args) ? : throw Exception (" Empty response" )
207203 val json = JSONObject (data)
208204 val items = json.getJSONArray(" items" ).map { OnRampMerchantEntity (it) }
209205 val suggested = json.optJSONArray(" suggested" )?.map { OnRampMerchantEntity (it) } ? : emptyList()
@@ -261,7 +257,11 @@ class API(
261257 configRepository.refresh(testnet)
262258 }
263259
264- fun swapStream (from : SwapAssetParam , to : SwapAssetParam , userAddress : String ) = swapApi.stream(from, to, userAddress)
260+ fun swapStream (
261+ from : SwapAssetParam ,
262+ to : SwapAssetParam ,
263+ userAddress : String
264+ ) = swapApi.stream(config.webSwapsUrl, from, to, userAddress)
265265
266266 suspend fun getPageTitle (url : String ): String = withContext(Dispatchers .IO ) {
267267 try {
@@ -537,6 +537,15 @@ class API(
537537 }
538538 }
539539
540+ fun getRates (from : String , to : String ): Map <String , TokenRates >? {
541+ return withRetry {
542+ rates().getRates(
543+ tokens = listOf (from),
544+ currencies = listOf (to)
545+ ).rates
546+ }
547+ }
548+
540549 fun getNft (address : String , testnet : Boolean ): NftItem ? {
541550 return withRetry { nft(testnet).getNftItemByAddress(address) }
542551 }
0 commit comments