[#663] Shield Funds button is enabled when there are no funds to shield (#665)

- This adds new logic for disabling the shield funds button and tests that
check that the state is consistent with the intended behaviour.
- handling button opacity is left for another PR
- one more condition to disable shield button
This commit is contained in:
Francisco Gindre 2023-03-14 06:04:49 -03:00 committed by GitHub
parent d5b92c32c5
commit a74dfa03ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 1 deletions

View File

@ -26,6 +26,14 @@ struct BalanceBreakdownReducer: ReducerProtocol {
var totalBalance: Zatoshi {
shieldedBalance.data.total + transparentBalance.data.total
}
var isShieldableBalanceAvailable: Bool {
transparentBalance.data.verified.amount >= autoShieldingThreshold.amount
}
var isShieldingButtonDisabled: Bool {
shieldingFunds || !isShieldableBalanceAvailable
}
}
enum Action: Equatable, BindableAction {

View File

@ -95,7 +95,7 @@ extension BalanceBreakdownView {
)
.activeButtonStyle
.padding(.top, 30)
.disable(when: viewStore.shieldingFunds, dimmingOpacity: 0.5)
.disable(when: !viewStore.isShieldableBalanceAvailable || viewStore.shieldingFunds, dimmingOpacity: 0.5)
}
}

View File

@ -86,4 +86,59 @@ class BalanceBreakdownTests: XCTestCase {
// the .onDisappear action cancels the observer of the synchronizer status change.
await store.send(.onDisappear)
}
@MainActor func testShieldFundsButtonDisabledWhenNoShieldableFunds() async throws {
let store = TestStore(
initialState: .placeholder,
reducer: BalanceBreakdownReducer()
)
XCTAssertFalse(store.state.shieldingFunds)
XCTAssertFalse(store.state.isShieldableBalanceAvailable)
XCTAssertTrue(store.state.isShieldingButtonDisabled)
}
@MainActor func testShieldFundsButtonEnabledWhenShieldableFundsAvailable() async throws {
let store = TestStore(
initialState: BalanceBreakdownReducer.State(
autoShieldingThreshold: Zatoshi(1_000_000),
latestBlock: L10n.General.unknown,
shieldedBalance: Balance.zero,
shieldingFunds: false,
transparentBalance: Balance(
WalletBalance(
verified: 1_000_000,
total: 1_000_000
)
)
),
reducer: BalanceBreakdownReducer()
)
XCTAssertFalse(store.state.shieldingFunds)
XCTAssertTrue(store.state.isShieldableBalanceAvailable)
XCTAssertFalse(store.state.isShieldingButtonDisabled)
}
@MainActor func testShieldFundsButtonDisabledWhenShieldableFundsAvailableAndShielding() async throws {
let store = TestStore(
initialState: BalanceBreakdownReducer.State(
autoShieldingThreshold: Zatoshi(1_000_000),
latestBlock: L10n.General.unknown,
shieldedBalance: Balance.zero,
shieldingFunds: true,
transparentBalance: Balance(
WalletBalance(
verified: 1_000_000,
total: 1_000_000
)
)
),
reducer: BalanceBreakdownReducer()
)
XCTAssertTrue(store.state.shieldingFunds)
XCTAssertTrue(store.state.isShieldableBalanceAvailable)
XCTAssertTrue(store.state.isShieldingButtonDisabled)
}
}