Skip to content

Commit

Permalink
In asset transfer too
Browse files Browse the repository at this point in the history
  • Loading branch information
kugel3 committed Aug 21, 2023
1 parent 67ad1d7 commit 1fa17d2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
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)
}
}
}

0 comments on commit 1fa17d2

Please sign in to comment.