summaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net/taler/wallet/withdraw/ExchangeFees.kt
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-05-13 10:03:04 -0300
committerTorsten Grote <t@grobox.de>2020-05-13 10:03:04 -0300
commit508a12b8f7957dcf817fb2f29a6b924b22ebdc55 (patch)
tree504f261474f78c904de25748facd8a0e5b52e0ab /wallet/src/main/java/net/taler/wallet/withdraw/ExchangeFees.kt
parent688b7a2a8169f4f587f6f8373ed26228e88a9727 (diff)
downloadtaler-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/main/java/net/taler/wallet/withdraw/ExchangeFees.kt')
-rw-r--r--wallet/src/main/java/net/taler/wallet/withdraw/ExchangeFees.kt36
1 files changed, 16 insertions, 20 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
)
}