Skip to content

Commit a055974

Browse files
DRadmirclaude
andcommitted
Fix reserved fee info text display for zero amounts in staking
Previously, the reserved fee info text would display even when the input amount was zero. This change adds a check to ensure the info text only appears when the user has entered a non-zero amount that would trigger the reserved fee warning. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f4c345a commit a055974

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

Features/Transfer/Sources/ViewModels/AmountSceneViewModel.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ public final class AmountSceneViewModel {
102102
return nil
103103
case .stake, .freeze:
104104
guard reservedForFee > .zero else { return nil }
105-
guard let inputValue = try? formatter.inputNumber(from: amountInputModel.text, decimals: asset.decimals.asInt) else { return nil }
106-
guard inputValue >= availableBalanceForStaking, inputValue <= availableValue else { return nil }
105+
guard let inputValue = try? formatter.inputNumber(from: amountInputModel.text, decimals: asset.decimals.asInt),
106+
!inputValue.isZero, inputValue >= availableBalanceForStaking, inputValue <= availableValue
107+
else { return nil }
107108
return Localized.Transfer.reservedFees(formatter.string(reservedForFee, asset: asset))
108109
}
109110
}

Features/Transfer/Tests/ViewModels/AmountSceneViewModelTests.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,9 @@ struct AmountSceneViewModelTests {
4040

4141
#expect(model.infoText != nil)
4242
#expect(model.amountInputModel.text == "1.99975")
43-
}
44-
45-
@Test
46-
func stakingMaxWithInsufficientBalance() {
47-
let assetData = AssetData.mock(asset: .mockBNB(), balance: .mock(available: 1_000_000_000_000)) // Less than reserve
48-
let model = AmountSceneViewModel.mock(type: .stake(validators: [], recommendedValidator: nil), assetData: assetData)
49-
50-
model.onSelectMaxButton()
51-
52-
#expect(model.amountInputModel.text == "0")
53-
#expect(model.infoText != nil)
43+
44+
model.amountInputModel.text = .zero
45+
#expect(model.infoText == nil)
5446
}
5547

5648
// @Test

0 commit comments

Comments
 (0)