summaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net/taler/wallet/exchanges/ExchangeManager.kt
diff options
context:
space:
mode:
Diffstat (limited to 'wallet/src/main/java/net/taler/wallet/exchanges/ExchangeManager.kt')
-rw-r--r--wallet/src/main/java/net/taler/wallet/exchanges/ExchangeManager.kt16
1 files changed, 14 insertions, 2 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/exchanges/ExchangeManager.kt b/wallet/src/main/java/net/taler/wallet/exchanges/ExchangeManager.kt
index 8205eb7..36b5017 100644
--- a/wallet/src/main/java/net/taler/wallet/exchanges/ExchangeManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/exchanges/ExchangeManager.kt
@@ -20,6 +20,8 @@ import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.launch
import kotlinx.serialization.Serializable
import net.taler.common.Event
@@ -29,12 +31,12 @@ import net.taler.wallet.backend.WalletBackendApi
@Serializable
data class ExchangeListResponse(
- val exchanges: List<ExchangeItem>
+ val exchanges: List<ExchangeItem>,
)
class ExchangeManager(
private val api: WalletBackendApi,
- private val scope: CoroutineScope
+ private val scope: CoroutineScope,
) {
private val mProgress = MutableLiveData<Boolean>()
@@ -78,4 +80,14 @@ class ExchangeManager(
}
}
+ fun findExchangeForCurrency(currency: String): Flow<ExchangeItem?> = flow {
+ val response = api.request("listExchanges", ExchangeListResponse.serializer())
+ var exchange: ExchangeItem? = null
+ response.onSuccess { exchangeListResponse ->
+ // just pick the first for now
+ exchange = exchangeListResponse.exchanges.find { it.currency == currency }
+ }
+ emit(exchange)
+ }
+
}