From 683f5e1abfc53e544a1e54db5634e30a0ac26636 Mon Sep 17 00:00:00 2001 From: romchornyi Date: Mon, 2 Nov 2026 13:48:35 +0200 Subject: [PATCH 1/2] fix(wallet): say funds are still confirming on a Core identity top-up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Core → Identity top-up on the internal transfer screen still said "Insufficient balance" for an amount that only needs incoming coins to confirm, while Core → Platform with the same amount said "still confirming". The top-up's asset lock is built by the same pooled funding as Core → Platform, so it now gets the same verdict, with no route cost on top of the L1 reserve. The three Core routes share one helper for the live pooled inputs. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Qvx8sdEhHcsmPbjRBJ9AKh --- .../InternalTransferViewModel.swift | 59 ++++++++++--------- .../PooledSendableBalanceTests.swift | 32 ++++++++++ 2 files changed, 63 insertions(+), 28 deletions(-) diff --git a/DashWallet/Sources/UI/Payments/InternalTransfer/InternalTransferViewModel.swift b/DashWallet/Sources/UI/Payments/InternalTransfer/InternalTransferViewModel.swift index 11599ae08b..b718753e57 100644 --- a/DashWallet/Sources/UI/Payments/InternalTransfer/InternalTransferViewModel.swift +++ b/DashWallet/Sources/UI/Payments/InternalTransfer/InternalTransferViewModel.swift @@ -1575,6 +1575,21 @@ final class InternalTransferViewModel: ObservableObject { } } + /// `coreTransferFundsMessage` for the typed amount: the caller gives its + /// route's ceiling and the cost the route adds on top of the L1 reserve; + /// the L1 reserve is the cached one and the pooled figures are read live. + private func coreRouteFundsMessage(ceilingDuffs: UInt64, routeCostDuffs: UInt64) -> String? { + let state = SwiftDashSDKWalletState.shared + return Self.coreTransferFundsMessage( + requestedDuffs: dashDuffsUnsigned, + ceilingDuffs: ceilingDuffs, + sendableDuffs: state.sendableDuffs, + l1ReserveDuffs: coreL1FeeReserveDuffs, + routeCostDuffs: routeCostDuffs, + pooledKnown: state.pooledSpendableDuffs != nil, + pool: SwiftDashSDKTransactionSender.sendPoolConfirmationSnapshot) + } + /// Inline, user-facing explanation for an amount rejected before Confirm. /// Zero stays quiet while the user has not entered an amount; a /// fee-estimation failure fails closed with a generic retry. @@ -1618,18 +1633,11 @@ final class InternalTransferViewModel: ObservableObject { guard let feeDuffs = CoreToShieldedAmountPolicy.currentPoolFeeDuffs else { return Self.feeEstimateUnavailableMessage } - let ceilingDuffs = SwiftDashSDKWalletState.feeAwareMax( - spendable: coreSpendableDuffs, - reserve: feeDuffs) - let state = SwiftDashSDKWalletState.shared - return Self.coreTransferFundsMessage( - requestedDuffs: dashDuffsUnsigned, - ceilingDuffs: ceilingDuffs, - sendableDuffs: state.sendableDuffs, - l1ReserveDuffs: coreL1FeeReserveDuffs, - routeCostDuffs: feeDuffs, - pooledKnown: state.pooledSpendableDuffs != nil, - pool: SwiftDashSDKTransactionSender.sendPoolConfirmationSnapshot) + return coreRouteFundsMessage( + ceilingDuffs: SwiftDashSDKWalletState.feeAwareMax( + spendable: coreSpendableDuffs, + reserve: feeDuffs), + routeCostDuffs: feeDuffs) case .coreToPlatform: // The static address-funding reserve rides on top of the amount, @@ -1640,18 +1648,11 @@ final class InternalTransferViewModel: ObservableObject { } let routeReserveDuffs = CoreToPlatformAmountPolicy.reserveDuffs( reserveCredits: reserveCredits) - let ceilingDuffs = CoreToPlatformAmountPolicy.maxAmountDuffs( - spendableDuffs: coreSpendableDuffs, - reserveCredits: reserveCredits) - let state = SwiftDashSDKWalletState.shared - return Self.coreTransferFundsMessage( - requestedDuffs: dashDuffsUnsigned, - ceilingDuffs: ceilingDuffs, - sendableDuffs: state.sendableDuffs, - l1ReserveDuffs: coreL1FeeReserveDuffs, - routeCostDuffs: routeReserveDuffs, - pooledKnown: state.pooledSpendableDuffs != nil, - pool: SwiftDashSDKTransactionSender.sendPoolConfirmationSnapshot) + return coreRouteFundsMessage( + ceilingDuffs: CoreToPlatformAmountPolicy.maxAmountDuffs( + spendableDuffs: coreSpendableDuffs, + reserveCredits: reserveCredits), + routeCostDuffs: routeReserveDuffs) case .platformToShielded: if awaitingPlatformShieldResync { @@ -1781,10 +1782,12 @@ final class InternalTransferViewModel: ObservableObject { } switch source { case .core: - return TransferSpendAmountPolicy.insufficientBalanceMessage( - balanceName: source.balanceName, - requestedDuffs: dashDuffsUnsigned, - spendableDuffs: coreSpendableDuffs) + // The SDK builds the top-up's asset lock with the same pooled + // funding as Core → Platform; the lock holds nothing back beyond + // the ordinary L1 reserve, so the ceiling is the cached envelope. + return coreRouteFundsMessage( + ceilingDuffs: coreSpendableDuffs, + routeCostDuffs: 0) case .platform: guard let ceiling = platformIdentityFundableDuffs else { return Self.feeEstimateUnavailableMessage diff --git a/DashWalletTests/PooledSendableBalanceTests.swift b/DashWalletTests/PooledSendableBalanceTests.swift index d1ad4067e9..e6a3f67d1a 100644 --- a/DashWalletTests/PooledSendableBalanceTests.swift +++ b/DashWalletTests/PooledSendableBalanceTests.swift @@ -367,6 +367,38 @@ final class PooledSendableBalanceTests: XCTestCase { XCTAssertEqual(message, "Insufficient balance") } + // The Core → Identity top-up adds no route cost: only the L1 reserve + // rides on top of the amount, and the ceiling is the cached envelope. + + func testNoRouteCostReturnsStillConfirmingWhenTheL1ReserveFits() { + let message = coreRouteMessage( + requestedDuffs: 110_000_000, + routeCostDuffs: 0, + pool: pool(confirmed: 100_000_000, unconfirmed: 20_000_000)) + + XCTAssertEqual(message, SendAmountError.fundsStillConfirming(20_000_000).errorDescription) + } + + func testNoRouteCostReturnsInsufficientWhenTheL1ReserveUsesTheLastRoom() { + let message = coreRouteMessage( + requestedDuffs: 119_500_000, + routeCostDuffs: 0, + pool: pool(confirmed: 100_000_000, unconfirmed: 20_000_000)) + + XCTAssertEqual(message, "Insufficient balance") + } + + func testNoRouteCostHandlesConfirmedFundsBelowTheL1Reserve() { + let message = coreRouteMessage( + requestedDuffs: 90_000_000, + cachedSpendableDuffs: 0, + sendableDuffs: 50_000, + routeCostDuffs: 0, + pool: pool(confirmed: 50_000, unconfirmed: 100_000_000)) + + XCTAssertEqual(message, SendAmountError.fundsStillConfirming(100_000_000).errorDescription) + } + func testAGapWithNothingConfirmingIsNeverCalledAWait() { // The pool holds more than the gate counts, but none of it is // confirming — a pooled figure not re-read yet, or an account the From 8540260fdc69a39f87a0d362b999bf94f4a14f16 Mon Sep 17 00:00:00 2001 From: romchornyi Date: Mon, 2 Nov 2026 14:05:15 +0200 Subject: [PATCH 2/2] test(wallet): cover the no-route-cost verdict at its edges The first receive into an empty wallet, a shortfall waiting cannot cover, the reserve taking exactly the room left, and an unknown pooled figure next to a pool that would say "still confirming" (the pool must not be read). Amounts are picked so a non-zero route cost would change the verdict. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Qvx8sdEhHcsmPbjRBJ9AKh --- .../PooledSendableBalanceTests.swift | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/DashWalletTests/PooledSendableBalanceTests.swift b/DashWalletTests/PooledSendableBalanceTests.swift index e6a3f67d1a..70f736f836 100644 --- a/DashWalletTests/PooledSendableBalanceTests.swift +++ b/DashWalletTests/PooledSendableBalanceTests.swift @@ -399,6 +399,54 @@ final class PooledSendableBalanceTests: XCTestCase { XCTAssertEqual(message, SendAmountError.fundsStillConfirming(100_000_000).errorDescription) } + func testNoRouteCostHandlesTheFirstReceiveIntoAnEmptyWallet() { + // 1.5M of room after confirmation: the 1M L1 reserve fits, any route + // cost above 0.5M would not. + let message = coreRouteMessage( + requestedDuffs: 98_500_000, + cachedSpendableDuffs: 0, + sendableDuffs: 0, + routeCostDuffs: 0, + pool: pool(confirmed: 0, unconfirmed: 100_000_000)) + + XCTAssertEqual(message, SendAmountError.fundsStillConfirming(100_000_000).errorDescription) + } + + func testNoRouteCostReturnsInsufficientWhenTheAmountCannotFitAfterConfirmation() { + let message = coreRouteMessage( + requestedDuffs: 121_000_000, + routeCostDuffs: 0, + pool: pool(confirmed: 100_000_000, unconfirmed: 20_000_000)) + + XCTAssertEqual(message, "Insufficient balance") + } + + func testNoRouteCostDoesNotWaitWhileThePooledFigureIsUnknown() { + // A pool that would answer "still confirming" if it were read. + var poolReads = 0 + let snapshot = pool(confirmed: 100_000_000, unconfirmed: 20_000_000) + let message = InternalTransferViewModel.coreTransferFundsMessage( + requestedDuffs: 110_000_000, + ceilingDuffs: 99_000_000, + sendableDuffs: 100_000_000, + l1ReserveDuffs: 1_000_000, + routeCostDuffs: 0, + pooledKnown: false, + pool: { poolReads += 1; return snapshot }) + + XCTAssertEqual(message, "Insufficient balance") + XCTAssertEqual(poolReads, 0) + } + + func testNoRouteCostReturnsStillConfirmingWhenTheL1ReserveTakesExactlyTheRoomLeft() { + let message = coreRouteMessage( + requestedDuffs: 119_000_000, + routeCostDuffs: 0, + pool: pool(confirmed: 100_000_000, unconfirmed: 20_000_000)) + + XCTAssertEqual(message, SendAmountError.fundsStillConfirming(20_000_000).errorDescription) + } + func testAGapWithNothingConfirmingIsNeverCalledAWait() { // The pool holds more than the gate counts, but none of it is // confirming — a pooled figure not re-read yet, or an account the