Skip to content

Commit

Permalink
Add memo field to new Send module
Browse files Browse the repository at this point in the history
  • Loading branch information
ealymbaev committed May 6, 2024
1 parent cbcfca7 commit ecc3472
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class BitcoinPreSendHandler {
}

extension BitcoinPreSendHandler: IPreSendHandler {
var hasMemo: Bool {
true
}

var hasSettings: Bool {
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import Foundation
import SwiftUI

protocol IPreSendHandler {
var hasMemo: Bool { get }
var hasSettings: Bool { get }
func settingsView(onChangeSettings: @escaping () -> Void) -> AnyView
func sendData(amount: Decimal, address: String, memo: String?) -> SendData?
}

extension IPreSendHandler {
var hasMemo: Bool {
false
}

var hasSettings: Bool {
false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ struct PreSendView: View {
addressView()
}

if let handler = viewModel.handler, handler.hasMemo {
memoView()
}

buttonView()
}
.padding(EdgeInsets(top: .margin12, leading: .margin16, bottom: .margin16, trailing: .margin16))
Expand Down Expand Up @@ -194,6 +198,17 @@ struct PreSendView: View {
.modifier(CautionPrompt(cautionState: $viewModel.addressCautionState))
}

@ViewBuilder private func memoView() -> some View {
InputTextRow {
InputTextView(
placeholder: "send.confirmation.memo_placeholder".localized,
multiline: true,
font: .themeBody.italic(),
text: $viewModel.memo
)
}
}

@ViewBuilder private func buttonView() -> some View {
let (title, disabled, showProgress) = buttonState()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ class PreSendViewModel: ObservableObject {
}
}

@Published var memo: String = "" {
didSet {
syncSendData()
}
}

var handler: IPreSendHandler?
@Published var sendData: SendData?

Expand Down Expand Up @@ -228,7 +234,7 @@ extension PreSendViewModel {
return
}

sendData = handler.sendData(amount: amount, address: success.address.raw, memo: nil)
sendData = handler.sendData(amount: amount, address: success.address.raw, memo: memo)
}

func setAmountIn(percent: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ThemeKit
struct InputTextView: View {
var placeholder: String = ""
var multiline: Bool
var font: Font

var text: Binding<String>

Expand All @@ -14,9 +15,10 @@ struct InputTextView: View {

var isValidText: ((String) -> Bool)?

init(placeholder: String = "", multiline: Bool = false, text: Binding<String>, secured: Binding<Bool> = .constant(false), isValidText: ((String) -> Bool)? = nil) {
init(placeholder: String = "", multiline: Bool = false, font: Font = .themeBody, text: Binding<String>, secured: Binding<Bool> = .constant(false), isValidText: ((String) -> Bool)? = nil) {
self.placeholder = placeholder
self.multiline = multiline
self.font = font
self.text = text
_secured = secured

Expand All @@ -25,7 +27,7 @@ struct InputTextView: View {

var body: some View {
editView()
.font(.themeBody)
.font(font)
.accentColor(.themeLeah)
.modifier(Validated(text: text, isValidText: isValidText))
}
Expand Down

0 comments on commit ecc3472

Please sign in to comment.