Fix for bug 11964 -- getMaxDepositAmount's nested response. Accepts both the nested shape wallet-core now sends (result.{material,available}.rawAmount) and the flat shape its sibling getMaxPeerPushDebitAmount still sends, so neither direction of the core divergence breaks the deposit flow. `getMaxDepositAmount` keeps returning `response.rawAmount` and that now resolves to `available.rawAmount` for the nested shape -- `available` being the one that reads as "the most that could be deposited" (KUDOS:94, the balance) where `material` was KUDOS:17.28 for the same wallet. Which of the two the deposit screen ought to show is still a judgement for whoever owns that screen; this patch only makes the response decode, which has to happen either way. Not included deliberately: the duplicate `fileprivate struct AmountResponse` in Model+Deposit.swift and Model+P2P.swift. Sharing one type would have made this divergence a compile error, but the two shapes are genuinely different now, so merging them is a design decision rather than a fix. Generated against taler-ios master, 2026-11-08. Apply with `git apply`. --- a/TalerWallet1/Model/Model+Deposit.swift +++ b/TalerWallet1/Model/Model+Deposit.swift @@ -140,11 +140,61 @@ } } // MARK: - max Deposit amount /// Check if initiating a deposit is possible, check fees +/// wallet-core nests this response: `result.material` and `result.available` +/// each carry instructedAmount/effectiveAmount/rawAmount plus `fees`, and +/// there is no `rawAmount` at the top level. Decoding it as flat threw +/// `DecodingError.keyNotFound` for 'rawAmount', the error surfaced to the +/// user as "Unknown error" / "The data couldn't be read because it is +/// missing", and a deposit could not be started at all. +/// +/// The sibling `getMaxPeerPushDebitAmount` (Model+P2P.swift) really is flat, +/// which is why only this one broke. Both shapes are accepted here rather +/// than only the nested one, so the app does not break again in the other +/// direction if a core build sends the flat shape. fileprivate struct AmountResponse: Codable { + struct Bucket: Codable { + let instructedAmount: Amount? + let effectiveAmount: Amount? + let rawAmount: Amount + let fees: DepositFees? + } + let effectiveAmount: Amount? let rawAmount: Amount + /// Present for the nested shape, nil for the flat one. + let material: Bucket? + let available: Bucket? + + private enum CodingKeys: String, CodingKey { + case effectiveAmount, rawAmount, material, available + } + + init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + let material = try container.decodeIfPresent(Bucket.self, forKey: .material) + let available = try container.decodeIfPresent(Bucket.self, forKey: .available) + self.material = material + self.available = available + if let flat = try container.decodeIfPresent(Amount.self, forKey: .rawAmount) { + self.rawAmount = flat + self.effectiveAmount = try container.decodeIfPresent(Amount.self, + forKey: .effectiveAmount) + } else if let bucket = available ?? material { + // `available` is the one that reads as "the most that could be + // deposited": for the same wallet it was KUDOS:94, the balance, + // where `material` was KUDOS:17.28. + self.rawAmount = bucket.rawAmount + self.effectiveAmount = bucket.effectiveAmount + } else { + throw DecodingError.keyNotFound(CodingKeys.rawAmount, + DecodingError.Context(codingPath: decoder.codingPath, + debugDescription: "getMaxDepositAmount: the response has " + + "neither a top-level rawAmount nor a material or " + + "available bucket")) + } + } } fileprivate struct GetMaxDepositAmount: WalletBackendFormattedRequest { typealias Response = AmountResponse var operation: String { "getMaxDepositAmount" }