Skip to content

Commit

Permalink
review(stephen): handle race condition. title-case button title.
Browse files Browse the repository at this point in the history
  • Loading branch information
nuo-xu committed Dec 13, 2024
1 parent 0b28467 commit d0a4e7f
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ public class TransactionConfirmationStore: ObservableObject, WalletObserverStore
let originalTxGasFee = BDouble(parsedTx.gasFee?.fee ?? "0"),
activeTxGasFee > originalTxGasFee
{
return .cancel(toCancelParsedTx: parsedTx)
return .cancel(originalParsedTx: parsedTx)
}
}
} else if activeTransaction.coin == .eth {
Expand All @@ -461,7 +461,7 @@ public class TransactionConfirmationStore: ObservableObject, WalletObserverStore
let originalTxGasFee = BDouble(parsedTx.gasFee?.fee ?? "0"),
activeTxGasFee > originalTxGasFee
{
return .speedUp
return .speedUp(originalParsedTx: parsedTx)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ import Preferences
import Strings

public class TransactionStatusStore: ObservableObject, WalletObserverStore {
@Published var activeTxStatus: BraveWallet.TransactionStatus {
didSet {
originalTxStatus = activeTxStatus
}
}
@Published var activeTxStatus: BraveWallet.TransactionStatus
@Published var txProviderError: TransactionProviderError?
@Published var isOriginalTxConfirmed: Bool = false

enum FollowUpAction: Equatable {
case cancel(toCancelParsedTx: ParsedTransaction)
case speedUp
case cancel(originalParsedTx: ParsedTransaction)
case speedUp(originalParsedTx: ParsedTransaction)
case none
}

Expand All @@ -31,16 +28,11 @@ public class TransactionStatusStore: ObservableObject, WalletObserverStore {
private let txService: BraveWalletTxService
private var txServiceObserver: TxServiceObserver?

private var originalTxParsed: ParsedTransaction
private var originalTxStatus: BraveWallet.TransactionStatus

var isObserving: Bool {
txServiceObserver != nil
}

var activeParsedTx: ParsedTransaction {
originalTxParsed
}
var activeParsedTx: ParsedTransaction

var isCancelAvailable: Bool {
guard activeParsedTx.transaction.coin == .eth else { return false }
Expand All @@ -65,8 +57,7 @@ public class TransactionStatusStore: ObservableObject, WalletObserverStore {
followUpAction: FollowUpAction
) {
self.activeTxStatus = activeTxStatus
self.originalTxStatus = activeTxStatus
self.originalTxParsed = activeTxParsed
self.activeParsedTx = activeTxParsed
self.txProviderError = txProviderError
self.keyringService = keyringService
self.rpcService = rpcService
Expand Down Expand Up @@ -94,6 +85,22 @@ public class TransactionStatusStore: ObservableObject, WalletObserverStore {
guard let self else { return }
if self.activeParsedTx.transaction.id == txInfo.id {
self.activeTxStatus = txInfo.txStatus
} else {
if case .cancel(let originalParsedTx) = followUpAction,
originalParsedTx.transaction.id == txInfo.id,
txInfo.txStatus == .confirmed
{
// cancel tx is submitted
// but the original tx is confirmed
isOriginalTxConfirmed = true
} else if case .speedUp(let originalParsedTx) = followUpAction,
originalParsedTx.transaction.id == txInfo.id,
txInfo.txStatus == .confirmed
{
// speed up tx is submitted
// but the original tx is confirmed
isOriginalTxConfirmed = true
}
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,18 +603,52 @@ struct TransactionStatusView: View {
GeometryReader { geometry in
ScrollView(.vertical) {
VStack {
speedUpView
.hidden(isHidden: !isShowingSpeedUpBanner)
Spacer()
txStatusIconView
if txStatusStore.isOriginalTxConfirmed {
Spacer()
ZStack {
Circle()
.fill(Color(braveSystemName: .systemfeedbackErrorBackground))
.frame(width: 100, height: 100)
Image(braveSystemName: "leo.close")
.font(.title.weight(.semibold))
.foregroundColor(Color(braveSystemName: .systemfeedbackErrorIcon))
}
.padding(.bottom, 30)
txStatusTextView
VStack {
Group {
switch txStatusStore.followUpAction {
case .cancel(_):
Text(Strings.Wallet.unableToCancel)
case .speedUp:
Text(Strings.Wallet.unableToSpeedUp)
case .none:
EmptyView()
}
}
.font(.title2.weight(.semibold))
.foregroundColor(Color(braveSystemName: .textPrimary))
.padding(.bottom, 8)
Text(Strings.Wallet.originalTransactionIsConfirmed)
.font(.subheadline)
.foregroundColor(Color(braveSystemName: .textSecondary))
}
.multilineTextAlignment(.center)
.padding(.top, 10)
Spacer()
disclosureView
.padding(.bottom, 8)
.hidden(isHidden: hideDisclosureView)
buttonContainerView
Spacer()
} else {
speedUpView
.hidden(isHidden: !isShowingSpeedUpBanner)
Spacer()
txStatusIconView
.padding(.bottom, 30)
txStatusTextView
.padding(.top, 10)
Spacer()
disclosureView
.padding(.bottom, 8)
.hidden(isHidden: hideDisclosureView)
buttonContainerView
}
}
.frame(maxWidth: .infinity, minHeight: geometry.size.height)
.padding(.horizontal, 24)
Expand Down
25 changes: 23 additions & 2 deletions ios/brave-ios/Sources/BraveWallet/WalletStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4551,7 +4551,7 @@ extension Strings {
"wallet.cancelTransactionStatusButtonTitle",
tableName: "BraveWallet",
bundle: .module,
value: "Cancel transaction",
value: "Cancel Transaction",
comment: "The button title that for user to cancel a submitted transaction inside transaction status view."
)
public static let cancelTransactionStatusConfirmationDescription = NSLocalizedString(
Expand All @@ -4572,9 +4572,30 @@ extension Strings {
"wallet.speedUpButtonTitle",
tableName: "BraveWallet",
bundle: .module,
value: "Speed up",
value: "Speed Up",
comment: "The button title for the button inside speed up banner."
)
public static let unableToCancel = NSLocalizedString(
"wallet.unableToCancel",
tableName: "BraveWallet",
bundle: .module,
value: "Unable to cancel",
comment: "The title will be displayed when a cancel tx has been dropped or replaced on chain."
)
public static let unableToSpeedUp = NSLocalizedString(
"wallet.unableToSpeedUp",
tableName: "BraveWallet",
bundle: .module,
value: "Unable to speed up",
comment: "The title will be displayed when a speed-up tx has been dropped or replaced on chain."
)
public static let originalTransactionIsConfirmed = NSLocalizedString(
"wallet.originalTransactionIsConfirmed",
tableName: "BraveWallet",
bundle: .module,
value: "The original transaction has been confirmed.",
comment: "The message will be displayed when a cancel/speed-up tx has been dropped or replaced on chain."
)
public static let ensOffchainGatewayTitle = NSLocalizedString(
"wallet.ensOffchainGatewayTitle",
tableName: "BraveWallet",
Expand Down

0 comments on commit d0a4e7f

Please sign in to comment.