- 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:
parent
d5b92c32c5
commit
a74dfa03ae
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue