mirror of
https://github.com/lil-org/tokenary.git
synced 2024-12-02 09:33:49 +03:00
add transaction editing stubs
This commit is contained in:
parent
172e99ac21
commit
ed0cc5c91c
@ -77,6 +77,15 @@ struct Transaction {
|
||||
return "Fee: " + feeString
|
||||
}
|
||||
|
||||
mutating func setCustomNonce(value: UInt) {
|
||||
// TODO: implement
|
||||
// TODO: gas = nil if a value is different — gotta recalculate
|
||||
}
|
||||
|
||||
mutating func setCustomGasPriceGwei(value: Double) {
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
func valueWithSymbol(chain: EthereumNetwork, price: Double?, withLabel: Bool) -> String? {
|
||||
guard let value = value, let value = BigInt(hexString: value) else { return nil }
|
||||
let costString = chain.mightShowPrice ? cost(value: value, price: price) : ""
|
||||
|
@ -5,9 +5,12 @@ import SwiftUI
|
||||
struct EditTransactionView: View {
|
||||
|
||||
@Environment(\.presentationMode) var presentationMode
|
||||
@State private var initialTransaction: Transaction
|
||||
@State private var didEdit = true // TODO: tmp for dev
|
||||
|
||||
private var transaction: Transaction
|
||||
private let initialNonce: String
|
||||
private let initialGasPrice: String
|
||||
|
||||
@State private var canProceedWithOK = true
|
||||
@State private var gasPrice: String = ""
|
||||
@State private var nonce: String = ""
|
||||
@State private var gasPriceErrorMessage: String? = nil
|
||||
@ -16,10 +19,12 @@ struct EditTransactionView: View {
|
||||
private let completion: ((Transaction?) -> Void)
|
||||
|
||||
init(initialTransaction: Transaction, completion: @escaping ((Transaction?) -> Void)) {
|
||||
self._initialTransaction = State(initialValue: initialTransaction)
|
||||
self.transaction = initialTransaction
|
||||
self.completion = completion
|
||||
self._gasPrice = State(initialValue: initialTransaction.gasPriceGwei ?? "")
|
||||
self._nonce = State(initialValue: initialTransaction.decimalNonceString ?? "")
|
||||
self.initialNonce = initialTransaction.decimalNonceString ?? ""
|
||||
self.initialGasPrice = initialTransaction.gasPriceGwei ?? ""
|
||||
self._gasPrice = State(initialValue: initialGasPrice)
|
||||
self._nonce = State(initialValue: initialNonce)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@ -34,7 +39,7 @@ struct EditTransactionView: View {
|
||||
}
|
||||
TextField(Strings.customNonce, text: $nonce)
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
.onChange(of: nonce) { _ in validateNonce() }
|
||||
.onChange(of: nonce) { _ in didUpdateNonce() }
|
||||
}.padding()
|
||||
VStack {
|
||||
HStack {
|
||||
@ -46,17 +51,18 @@ struct EditTransactionView: View {
|
||||
}
|
||||
TextField(Strings.customGasPrice, text: $gasPrice)
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
.onChange(of: gasPrice) { _ in validateGasPrice() }
|
||||
.onChange(of: gasPrice) { _ in didUpdateGasPrice() }
|
||||
}.padding([.horizontal, .bottom])
|
||||
HStack {
|
||||
Button(Strings.cancel) { completion(nil) }.keyboardShortcut(.cancelAction)
|
||||
Button(Strings.ok) { completion(nil) }.keyboardShortcut(.defaultAction)
|
||||
.disabled(!didEdit) // TODO: directly check if there are custom values entered?
|
||||
Button(Strings.ok) { completion(transaction) }.keyboardShortcut(.defaultAction).disabled(!canProceedWithOK)
|
||||
}.frame(height: 36).offset(CGSize(width: 0, height: -6)).padding(.top, 2)
|
||||
}
|
||||
}
|
||||
|
||||
private func validateGasPrice() {
|
||||
private func didUpdateGasPrice() {
|
||||
// TODO: update transaction
|
||||
// TODO: update canProceedWithOK
|
||||
if gasPrice.isEmpty || !isNumber(gasPrice) {
|
||||
gasPriceErrorMessage = "invalid gas price"
|
||||
} else {
|
||||
@ -64,7 +70,9 @@ struct EditTransactionView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private func validateNonce() {
|
||||
private func didUpdateNonce() {
|
||||
// TODO: update transaction
|
||||
// TODO: update canProceedWithOK
|
||||
if nonce.isEmpty || !isNumber(nonce) {
|
||||
nonceErrorMessage = "invalid nonce"
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user