Skip to content

Commit

Permalink
Misc small fixes (#1269)
Browse files Browse the repository at this point in the history
  • Loading branch information
kugel3 authored Aug 8, 2024
1 parent f7b6dcb commit 2cd26ed
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 37 deletions.
2 changes: 1 addition & 1 deletion RadixWallet/Core/DesignSystem/Components/CloseButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extension CloseButton {

var alignment: Alignment {
switch self {
case .toolbar: .center
case .toolbar: .leading
case .homeCard: .topTrailing
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extension DappInteractionFlow {
.transaction { $0.animation = nil }
} destination: {
destinations(for: $0)
.toolbar(.visible, for: .navigationBar)
.navigationBarBackButtonHidden()
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Expand All @@ -37,7 +38,6 @@ extension DappInteractionFlow {
}
}
}
.navigationTransition(.slide, interactivity: .disabled)
.onAppear { store.send(.view(.appeared)) }
.alert(
store: store.scope(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ extension DisplayEntitiesControlledByMnemonic {
}
case .scanning:
if accounts == 0 {
L10n.SeedPhrases.SeedPhrase.noConnectedAccountsScan
L10n.SeedPhrases.SeedPhrase.noConnectedAccountsReveal
} else if accounts == 1 {
L10n.SeedPhrases.SeedPhrase.oneConnectedAccountScan
L10n.SeedPhrases.SeedPhrase.oneConnectedAccountReveal
} else {
L10n.SeedPhrases.SeedPhrase.multipleConnectedAccountsScan(accounts)
L10n.SeedPhrases.SeedPhrase.multipleConnectedAccountsReveal(accounts)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ extension CustomizeFees {
public var body: some SwiftUI.View {
WithViewStore(store, observe: \.viewState, send: { .view($0) }) { viewStore in
VStack(spacing: .zero) {
HStack {
CloseButton {
viewStore.send(.closeButtonTapped)
}
Spacer()
}
ScrollView {
VStack(spacing: .zero) {
VStack {
Expand Down Expand Up @@ -111,6 +105,9 @@ extension CustomizeFees {
.padding(.bottom, .medium1)
}
}
.withNavigationBar {
store.send(.view(.closeButtonTapped))
}
}
.destinations(with: store)
}
Expand Down Expand Up @@ -159,7 +156,7 @@ extension CustomizeFees {
}

if let insufficientBalanceMessage = viewState.insufficientBalanceMessage {
WarningErrorView(text: insufficientBalanceMessage, type: .error)
WarningErrorView(text: insufficientBalanceMessage, type: .warning)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SwiftUI
// MARK: - CustomizeFees
public struct CustomizeFees: FeatureReducer, Sendable {
public struct State: Hashable, Sendable {
@CasePathable
enum CustomizationModeState: Hashable, Sendable {
case normal(NormalFeesCustomization.State)
case advanced(AdvancedFeesCustomization.State)
Expand Down Expand Up @@ -47,6 +48,7 @@ public struct CustomizeFees: FeatureReducer, Sendable {
case closeButtonTapped
}

@CasePathable
public enum ChildAction: Equatable, Sendable {
case normalFeesCustomization(NormalFeesCustomization.Action)
case advancedFeesCustomization(AdvancedFeesCustomization.Action)
Expand All @@ -61,16 +63,18 @@ public struct CustomizeFees: FeatureReducer, Sendable {
}

public struct Destination: DestinationReducer {
@CasePathable
public enum State: Sendable, Hashable {
case selectFeePayer(SelectFeePayer.State)
}

@CasePathable
public enum Action: Sendable, Equatable {
case selectFeePayer(SelectFeePayer.Action)
}

public var body: some ReducerOf<Self> {
Scope(state: /State.selectFeePayer, action: /Action.selectFeePayer) {
Scope(state: \.selectFeePayer, action: \.selectFeePayer) {
SelectFeePayer()
}
}
Expand All @@ -80,16 +84,14 @@ public struct CustomizeFees: FeatureReducer, Sendable {
@Dependency(\.errorQueue) var errorQueue

public var body: some ReducerOf<Self> {
Scope(state: \.modeState, action: /Action.child) {
EmptyReducer()
.ifCaseLet(/State.CustomizationModeState.normal, action: /ChildAction.normalFeesCustomization) {
NormalFeesCustomization()
}
.ifCaseLet(/State.CustomizationModeState.advanced, action: /ChildAction.advancedFeesCustomization) {
AdvancedFeesCustomization()
}
Scope(state: \.modeState, action: \.child) {
Scope(state: \.normal, action: \.normalFeesCustomization) {
NormalFeesCustomization()
}
Scope(state: \.advanced, action: \.advancedFeesCustomization) {
AdvancedFeesCustomization()
}
}

Reduce(core)
.ifLet(destinationPath, action: /Action.destination) {
Destination()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ extension SelectFeePayer {
.multilineTextAlignment(.center)
.textStyle(.sheetTitle)
.foregroundColor(.app.gray1)
.padding(.top, .medium3)
.padding(.horizontal, .medium1)
.padding(.bottom, .small2)

Expand Down Expand Up @@ -102,6 +101,9 @@ extension SelectFeePayer {
.controlState(viewStore.selectButtonControlState)
}
}
.withNavigationBar {
store.send(.view(.closeButtonTapped))
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public struct SelectFeePayer: Sendable, FeatureReducer {
case selectedPayer(FeePayerCandidate?)
case confirmedFeePayer(FeePayerCandidate)
case pullToRefreshStarted
case closeButtonTapped
}

public enum DelegateAction: Sendable, Equatable {
Expand All @@ -36,6 +37,7 @@ public struct SelectFeePayer: Sendable, FeatureReducer {

@Dependency(\.transactionClient) var transactionClient
@Dependency(\.errorQueue) var errorQueue
@Dependency(\.dismiss) var dismiss

public init() {}

Expand All @@ -54,6 +56,11 @@ public struct SelectFeePayer: Sendable, FeatureReducer {

case .pullToRefreshStarted:
return loadCandidates(refresh: true)

case .closeButtonTapped:
return .run { _ in
await dismiss()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension TransactionReview.State {
viewControlState: viewControlState,
rawTransaction: displayMode.rawTransaction,
showApprovalSlider: reviewedTransaction != nil,
canApproveTX: canApproveTX && reviewedTransaction?.feePayingValidation.wrappedValue == .valid,
canApproveTX: canApproveTX && reviewedTransaction?.feePayingValidation.wrappedValue?.isValid == true,
sliderResetDate: sliderResetDate,
canToggleViewMode: reviewedTransaction != nil && reviewedTransaction?.isNonConforming == false,
viewRawTransactionButtonState: reviewedTransaction?.feePayer.isSuccess == true ? .enabled : .disabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public struct TransactionReview: Sendable, FeatureReducer {
public enum InternalAction: Sendable, Equatable {
case previewLoaded(TaskResult<TransactionToReview>)
case updateSections(TransactionReview.Sections?)
case buildTransactionItentResult(TaskResult<TransactionIntent>)
case buildTransactionIntentResult(TaskResult<TransactionIntent>)
case notarizeResult(TaskResult<NotarizeTransactionResponse>)
case determineFeePayerResult(TaskResult<FeePayerSelectionResult?>)
}
Expand Down Expand Up @@ -340,7 +340,7 @@ public struct TransactionReview: Sendable, FeatureReducer {
#endif

return .run { send in
await send(.internal(.buildTransactionItentResult(TaskResult {
await send(.internal(.buildTransactionIntentResult(TaskResult {
try await transactionClient.buildTransactionIntent(request)
})))
}
Expand Down Expand Up @@ -422,6 +422,7 @@ public struct TransactionReview: Sendable, FeatureReducer {
transactionSigners: preview.transactionSigners,
signingFactors: preview.signingFactors,
accountWithdraws: preview.analyzedManifestToReview.withdrawals,
accountDeposits: preview.analyzedManifestToReview.deposits,
isNonConforming: preview.analyzedManifestToReview.detailedManifestClass == nil
)

Expand Down Expand Up @@ -449,7 +450,7 @@ public struct TransactionReview: Sendable, FeatureReducer {

return .none

case let .buildTransactionItentResult(.success(intent)):
case let .buildTransactionIntentResult(.success(intent)):
guard let reviewedTransaction = state.reviewedTransaction else {
return .none
}
Expand Down Expand Up @@ -487,7 +488,7 @@ public struct TransactionReview: Sendable, FeatureReducer {
))
return .none

case let .buildTransactionItentResult(.failure(error)),
case let .buildTransactionIntentResult(.failure(error)),
let .notarizeResult(.failure(error)):
errorQueue.schedule(error)
return .none
Expand Down Expand Up @@ -967,23 +968,35 @@ public struct ReviewedTransaction: Hashable, Sendable {
var signingFactors: SigningFactors

let accountWithdraws: [AccountAddress: [ResourceIndicator]]
let accountDeposits: [AccountAddress: [ResourceIndicator]]
let isNonConforming: Bool
}

// MARK: - FeeValidationOutcome
enum FeeValidationOutcome {
case valid
case valid(introducesNewAccount: Bool)
case needsFeePayer
case insufficientBalance

var isValid: Bool {
guard case .valid = self else { return false }
return true
}
}

extension ReviewedTransaction {
var involvedAccounts: Set<AccountAddress> {
Set(accountWithdraws.keys).union(accountDeposits.keys)
}

var feePayingValidation: Loadable<FeeValidationOutcome> {
feePayer.map { selected in
let introducesNewAccount = selected.map { !involvedAccounts.contains($0.account.address) } ?? false

guard let feePayer = selected,
let feePayerWithdraws = accountWithdraws[feePayer.account.address]
else {
return selected.validateBalance(forFee: transactionFee)
return selected.validateBalance(forFee: transactionFee, introducesNewAccount: introducesNewAccount)
}

let xrdAddress = ResourceAddress.xrd(on: networkID)
Expand All @@ -1002,16 +1015,16 @@ extension ReviewedTransaction {
return .insufficientBalance
}

return .valid
return .valid(introducesNewAccount: false)
}
}
}

extension FeePayerCandidate? {
func validateBalance(forFee transactionFee: TransactionFee) -> FeeValidationOutcome {
func validateBalance(forFee transactionFee: TransactionFee, introducesNewAccount: Bool) -> FeeValidationOutcome {
if transactionFee.totalFee.lockFee == .zero {
// If no fee is required - valid
return .valid
return .valid(introducesNewAccount: introducesNewAccount)
}

guard let self else {
Expand All @@ -1024,7 +1037,7 @@ extension FeePayerCandidate? {
return .insufficientBalance
}

return .valid
return .valid(introducesNewAccount: introducesNewAccount)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ extension TransactionReviewNetworkFee {
}

loadable(viewStore.reviewedTransaction.feePayingValidation) { validation in
if case .needsFeePayer = validation {
switch validation {
case .needsFeePayer:
WarningErrorView(text: L10n.TransactionReview.feePayerRequiredMessage, type: .warning)
} else if case .insufficientBalance = validation {
WarningErrorView(text: L10n.TransactionReview.insufficientBalance, type: .error)
case .insufficientBalance:
WarningErrorView(text: L10n.TransactionReview.insufficientBalance, type: .warning)
case .valid(introducesNewAccount: true):
EmptyView() // TODO: Here we could show a warning, that this introduces a new account into the transaction - the link between the accounts will now be public
case .valid(introducesNewAccount: false):
EmptyView()
}

Button(L10n.TransactionReview.NetworkFee.customizeButtonTitle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ final class CustomizeFeePayerTests: TestCase {
),
signingFactors: [:],
accountWithdraws: [:],
accountDeposits: [:],
isNonConforming: true
)

Expand Down

0 comments on commit 2cd26ed

Please sign in to comment.