diff options
author | Torsten Grote <t@grobox.de> | 2020-05-13 10:03:04 -0300 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2020-05-13 10:03:04 -0300 |
commit | 508a12b8f7957dcf817fb2f29a6b924b22ebdc55 (patch) | |
tree | 504f261474f78c904de25748facd8a0e5b52e0ab /wallet/src | |
parent | 688b7a2a8169f4f587f6f8373ed26228e88a9727 (diff) | |
download | taler-android-508a12b8f7957dcf817fb2f29a6b924b22ebdc55.tar.gz taler-android-508a12b8f7957dcf817fb2f29a6b924b22ebdc55.tar.bz2 taler-android-508a12b8f7957dcf817fb2f29a6b924b22ebdc55.zip |
[wallet] adapt fee parsing to wallet-core changes
Diffstat (limited to 'wallet/src')
3 files changed, 34 insertions, 34 deletions
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<CoinFees>, + val coinFees: List<CoinFee>, val wireFees: List<WireFee> ) { companion object { fun fromExchangeWithdrawDetailsJson(json: JSONObject): ExchangeFees { val earliestDepositExpiration = json.getJSONObject("earliestDepositExpiration").getLong("t_ms") - - val selectedDenoms = json.getJSONArray("selectedDenoms") - val coinFees = HashMap<CoinFee, Int>(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<CoinFee>(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<CoinFees>) : Adapter<CoinFeeViewHolder>() { +private class CoinFeeAdapter(private val items: List<CoinFee>) : Adapter<CoinFeeViewHolder>() { 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<CoinFees>) : Adapter<CoinFe private val depositFeeView: TextView = v.findViewById(R.id.depositFeeView) private val refreshFeeView: TextView = v.findViewById(R.id.refreshFeeView) private val refundFeeView: TextView = v.findViewById(R.id.refundFeeView) - fun bind(item: CoinFees) { - val fee = item.coinFee + fun bind(item: CoinFee) { coinView.text = res.getQuantityString( R.plurals.exchange_fee_coin, item.quantity, - fee.coin, + item.coin, item.quantity ) withdrawFeeView.text = - v.context.getString(R.string.exchange_fee_withdraw_fee, fee.feeWithdraw) + v.context.getString(R.string.exchange_fee_withdraw_fee, item.feeWithdraw) depositFeeView.text = - v.context.getString(R.string.exchange_fee_deposit_fee, fee.feeDeposit) + v.context.getString(R.string.exchange_fee_deposit_fee, item.feeDeposit) refreshFeeView.text = - v.context.getString(R.string.exchange_fee_refresh_fee, fee.feeRefresh) + v.context.getString(R.string.exchange_fee_refresh_fee, item.feeRefresh) refundFeeView.text = - v.context.getString(R.string.exchange_fee_refund_fee, fee.feeRefresh) + v.context.getString(R.string.exchange_fee_refund_fee, item.feeRefresh) } } } diff --git a/wallet/src/main/res/layout/fragment_select_exchange.xml b/wallet/src/main/res/layout/fragment_select_exchange.xml index cb8d35a..6f8814f 100644 --- a/wallet/src/main/res/layout/fragment_select_exchange.xml +++ b/wallet/src/main/res/layout/fragment_select_exchange.xml @@ -80,7 +80,8 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="8dp" - app:layout_constraintEnd_toEndOf="@+id/withdrawFeeView" + android:layout_marginEnd="16dp" + app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/expirationLabel" app:layout_constraintTop_toTopOf="@+id/expirationLabel" tools:text="in 5 years" /> @@ -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" /> |