diff options
author | Torsten Grote <t@grobox.de> | 2022-09-06 18:18:47 -0300 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2022-09-06 18:18:47 -0300 |
commit | 4fe04766fbf5328d0816f7cd862228a71690fd1c (patch) | |
tree | 289e2c4fbfbd5462b0d4d2e2067227c68b840efa /wallet/src/main/java/net/taler/wallet/exchanges | |
parent | 3d3108dd40cd8d3395434905463a91b4b3a71d5a (diff) | |
download | taler-android-4fe04766fbf5328d0816f7cd862228a71690fd1c.tar.gz taler-android-4fe04766fbf5328d0816f7cd862228a71690fd1c.tar.bz2 taler-android-4fe04766fbf5328d0816f7cd862228a71690fd1c.zip |
[wallet] implement prototype for outgoing peer transactions
Diffstat (limited to 'wallet/src/main/java/net/taler/wallet/exchanges')
-rw-r--r-- | wallet/src/main/java/net/taler/wallet/exchanges/ExchangeManager.kt | 16 |
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) + } + } |