From 508a12b8f7957dcf817fb2f29a6b924b22ebdc55 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Wed, 13 May 2020 10:03:04 -0300 Subject: [wallet] adapt fee parsing to wallet-core changes --- wallet/build.gradle | 9 ++++-- .../java/net/taler/wallet/withdraw/ExchangeFees.kt | 36 ++++++++++------------ .../wallet/withdraw/SelectExchangeFragment.kt | 17 +++++----- .../main/res/layout/fragment_select_exchange.xml | 15 ++++++--- 4 files changed, 41 insertions(+), 36 deletions(-) diff --git a/wallet/build.gradle b/wallet/build.gradle index b86f99c..f976b24 100644 --- a/wallet/build.gradle +++ b/wallet/build.gradle @@ -23,7 +23,7 @@ plugins { id "de.undercouch.download" } -def walletCoreVersion = "v0.7.1-dev.2" +def walletCoreVersion = "v0.7.1-dev.3" android { compileSdkVersion 29 @@ -35,7 +35,7 @@ android { minSdkVersion 24 targetSdkVersion 29 versionCode 6 - versionName "0.7.1.dev.1" + versionName "0.7.1.dev.3" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" buildConfigField "String", "WALLET_CORE_VERSION", "\"$walletCoreVersion\"" } @@ -112,6 +112,11 @@ task downloadWalletLibrary(type: Download) { overwrite false doFirst { new File(walletLibraryDir).mkdirs() + if (!file(dest).exists()) { // delete old versions before fetching new one + delete fileTree(walletLibraryDir) { + include 'taler-wallet-android-*.js' + } + } } } tasks.withType(MergeResources) { diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/ExchangeFees.kt b/wallet/src/main/java/net/taler/wallet/withdraw/ExchangeFees.kt index 4494e38..9c815c9 100644 --- a/wallet/src/main/java/net/taler/wallet/withdraw/ExchangeFees.kt +++ b/wallet/src/main/java/net/taler/wallet/withdraw/ExchangeFees.kt @@ -22,17 +22,13 @@ import org.json.JSONObject data class CoinFee( val coin: Amount, + val quantity: Int, val feeDeposit: Amount, val feeRefresh: Amount, val feeRefund: Amount, val feeWithdraw: Amount ) -data class CoinFees( - val quantity: Int, - val coinFee: CoinFee -) - data class WireFee( val start: Timestamp, val end: Timestamp, @@ -44,26 +40,28 @@ data class ExchangeFees( val withdrawFee: Amount, val overhead: Amount, val earliestDepositExpiration: Timestamp, - val coinFees: List, + val coinFees: List, val wireFees: List ) { companion object { fun fromExchangeWithdrawDetailsJson(json: JSONObject): ExchangeFees { val earliestDepositExpiration = json.getJSONObject("earliestDepositExpiration").getLong("t_ms") - - val selectedDenoms = json.getJSONArray("selectedDenoms") - val coinFees = HashMap(selectedDenoms.length()) - for (i in 0 until selectedDenoms.length()) { - val denom = selectedDenoms.getJSONObject(i) + val selectedDenoms = json.getJSONObject("selectedDenoms") + val denoms = selectedDenoms.getJSONArray("selectedDenoms") + val coinFees = ArrayList(denoms.length()) + for (i in 0 until denoms.length()) { + val denom = denoms.getJSONObject(i) + val d = denom.getJSONObject("denom") val coinFee = CoinFee( - coin = Amount.fromJsonObject(denom.getJSONObject("value")), - feeDeposit = Amount.fromJsonObject(denom.getJSONObject("feeDeposit")), - feeRefresh = Amount.fromJsonObject(denom.getJSONObject("feeRefresh")), - feeRefund = Amount.fromJsonObject(denom.getJSONObject("feeRefund")), - feeWithdraw = Amount.fromJsonObject(denom.getJSONObject("feeWithdraw")) + coin = Amount.fromJsonObject(d.getJSONObject("value")), + quantity = denom.getInt("count"), + feeDeposit = Amount.fromJsonObject(d.getJSONObject("feeDeposit")), + feeRefresh = Amount.fromJsonObject(d.getJSONObject("feeRefresh")), + feeRefund = Amount.fromJsonObject(d.getJSONObject("feeRefund")), + feeWithdraw = Amount.fromJsonObject(d.getJSONObject("feeWithdraw")) ) - coinFees[coinFee] = (coinFees[coinFee] ?: 0) + 1 + coinFees.add(coinFee) } val wireFeesJson = json.getJSONObject("wireFees") @@ -89,9 +87,7 @@ data class ExchangeFees( withdrawFee = Amount.fromJsonObject(json.getJSONObject("withdrawFee")), overhead = Amount.fromJsonObject(json.getJSONObject("overhead")), earliestDepositExpiration = Timestamp(earliestDepositExpiration), - coinFees = coinFees.map { (coinFee, quantity) -> - CoinFees(quantity, coinFee) - }, + coinFees = coinFees, wireFees = wireFees ) } diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/SelectExchangeFragment.kt b/wallet/src/main/java/net/taler/wallet/withdraw/SelectExchangeFragment.kt index fd614c6..2ade9f2 100644 --- a/wallet/src/main/java/net/taler/wallet/withdraw/SelectExchangeFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/withdraw/SelectExchangeFragment.kt @@ -31,8 +31,8 @@ import kotlinx.android.synthetic.main.fragment_select_exchange.* import net.taler.common.Amount import net.taler.common.toRelativeTime import net.taler.common.toShortDate -import net.taler.wallet.R import net.taler.wallet.MainViewModel +import net.taler.wallet.R import net.taler.wallet.withdraw.CoinFeeAdapter.CoinFeeViewHolder import net.taler.wallet.withdraw.WireFeeAdapter.WireFeeViewHolder @@ -73,7 +73,7 @@ class SelectExchangeFragment : Fragment() { } -private class CoinFeeAdapter(private val items: List) : Adapter() { +private class CoinFeeAdapter(private val items: List) : Adapter() { override fun getItemCount() = items.size override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CoinFeeViewHolder { val v = @@ -92,22 +92,21 @@ private class CoinFeeAdapter(private val items: List) : Adapter @@ -100,11 +101,13 @@ android:id="@+id/coinFeesList" android:layout_width="0dp" android:layout_height="wrap_content" + android:layout_marginStart="16dp" android:layout_marginTop="8dp" + android:layout_marginEnd="16dp" android:overScrollMode="never" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" - app:layout_constraintEnd_toEndOf="@+id/withdrawFeeView" - app:layout_constraintStart_toStartOf="@+id/withdrawFeeLabel" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/coinFeesLabel" tools:listitem="@layout/list_item_coin_fee" /> @@ -123,11 +126,13 @@ android:id="@+id/wireFeesList" android:layout_width="0dp" android:layout_height="wrap_content" + android:layout_marginStart="16dp" android:layout_marginTop="8dp" + android:layout_marginEnd="16dp" android:overScrollMode="never" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" - app:layout_constraintEnd_toEndOf="@+id/withdrawFeeView" - app:layout_constraintStart_toStartOf="@+id/withdrawFeeLabel" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/wireFeesLabel" tools:listitem="@layout/list_item_wire_fee" /> -- cgit v1.2.3