Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ABW-1797] Dismiss Asset Transfer Amount #681

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/Core/DesignSystem/Components/PlainListRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public struct PlainListRow<Icon: View>: View {
}
.frame(minHeight: .settingsRowHeight)
.padding(.horizontal, .medium3)
.contentShape(Rectangle())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ public struct AssetTransfer: Sendable, FeatureReducer {
return .none

case .backgroundTapped:
state.message?.focused = false
if state.message?.focused == true {
state.message?.focused = false
}

for id in state.accounts.receivingAccounts.ids {
for assetID in state.accounts.receivingAccounts[id: id]?.assets.ids ?? [] {
state.accounts.receivingAccounts[id: id]?.assets[id: assetID]?.unsetFocus()
}
}

return .none

case .sendTransferTapped:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public struct FungibleResourceAsset: Sendable, FeatureReducer {
// Total transfer sum for the transferred resource
public var totalTransferSum: BigDecimal

public var focused: Bool = false

init(resource: AccountPortfolio.FungibleResource, isXRD: Bool, totalTransferSum: BigDecimal = .zero) {
self.resource = resource
self.isXRD = isXRD
Expand All @@ -39,6 +41,7 @@ public struct FungibleResourceAsset: Sendable, FeatureReducer {
public enum ViewAction: Equatable, Sendable {
case amountChanged(String)
case maxAmountTapped
case focusChanged(Bool)
case removeTapped
}

Expand Down Expand Up @@ -67,6 +70,10 @@ public struct FungibleResourceAsset: Sendable, FeatureReducer {
state.transferAmountStr = remainingAmount.droppingTrailingZeros.formatWithoutRounding()
return .send(.delegate(.amountChanged))

case let .focusChanged(focused):
state.focused = focused
return .none

case .removeTapped:
return .send(.delegate(.removed))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ extension FungibleResourceAsset {
}
}

extension ViewStore<FungibleResourceAsset.State, FungibleResourceAsset.ViewAction> {
var focusedBinding: Binding<Bool> {
binding(get: \.focused, send: ViewAction.focusChanged)
}
}

extension FungibleResourceAsset.View {
public var body: some View {
WithViewStore(store, observe: { $0 }, send: { .view($0) }) { viewStore in
Expand All @@ -35,21 +41,13 @@ extension FungibleResourceAsset.View {
send: { .amountChanged($0) }
)
)
.toolbar {
ToolbarItemGroup(placement: .keyboard) {
Spacer()

Button(L10n.Common.done) {
focused = false
}
}
}
.keyboardType(.decimalPad)
.lineLimit(1)
.multilineTextAlignment(.trailing)
.foregroundColor(.app.gray1)
.textStyle(.sectionHeader)
.focused($focused)
.bind(viewStore.focusedBinding, to: $focused)
}

if viewStore.totalExceedsBalance {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import FeaturePrelude

// MARK: - ResourceAsset
// Higher order reducer composing all types of assets that can be transferred
public struct ResourceAsset: Sendable, FeatureReducer {
public enum State: Sendable, Hashable, Identifiable {
Expand Down Expand Up @@ -57,3 +58,12 @@ public struct ResourceAsset: Sendable, FeatureReducer {
}
}
}

extension ResourceAsset.State {
mutating func unsetFocus() {
if case var .fungibleAsset(state) = self, state.focused {
state.focused = false
self = .fungibleAsset(state)
}
}
}
Loading