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 --- .../java/net/taler/wallet/withdraw/ExchangeFees.kt | 36 ++++++++++------------ .../wallet/withdraw/SelectExchangeFragment.kt | 17 +++++----- .../main/res/layout/fragment_select_exchange.xml | 15 ++++++--- 3 files changed, 34 insertions(+), 34 deletions(-) (limited to 'wallet/src') 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