Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes #916

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,40 @@ extension AccountPreferences.State {
var viewState: AccountPreferences.ViewState {
.init(
account: account,
sections: [
.init(
id: .personalize,
title: L10n.AccountSettings.personalizeHeading,
rows: [.accountLabel(account)]
),
.init(
id: .onLedgerBehaviour,
title: L10n.AccountSettings.setBehaviorHeading,
rows: [.thirdPartyDeposits(account.onLedgerSettings.thirdPartyDeposits.depositRule)]
),
.init(
id: .development,
title: L10n.AccountSettings.developmentHeading,
rows: [.devAccountPreferneces()]
),
]
sections: {
var sections: [AccountPreferences.ViewState.Section] = [
.init(
id: .personalize,
title: L10n.AccountSettings.personalizeHeading,
rows: [.accountLabel(account)]
),
.init(
id: .onLedgerBehaviour,
title: L10n.AccountSettings.setBehaviorHeading,
rows: [.thirdPartyDeposits(account.onLedgerSettings.thirdPartyDeposits.depositRule)]
),
]

if account.networkID != .mainnet {
sections.append(.init(
id: .development,
title: L10n.AccountSettings.developmentHeading,
rows: [.devAccountPreferneces()]
))
}

return sections
}()
)
}
}

// MARK: - AccountPreferences.View
extension AccountPreferences {
public struct ViewState: Equatable {
typealias Section = PreferenceSection<AccountPreferences.Section, AccountPreferences.Section.SectionRow>.ViewState
let account: Profile.Network.Account
var sections: [PreferenceSection<AccountPreferences.Section, AccountPreferences.Section.SectionRow>.ViewState]
var sections: [Section]
}

@MainActor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import SwiftUI
public struct FungibleResourceAsset: Sendable, FeatureReducer {
public struct State: Sendable, Hashable, Identifiable {
public typealias ID = String
static let defaultFee: RETDecimal = 1

public var id: ID {
resource.resourceAddress.address
Expand Down Expand Up @@ -57,6 +58,7 @@ public struct FungibleResourceAsset: Sendable, FeatureReducer {
public enum ChooseXRDAmountAlert: Hashable, Sendable {
case deductFee(RETDecimal)
case sendAll(RETDecimal)
case cancel
}

public enum NeedsToPayFeeFromOtherAccount: Hashable, Sendable {
Expand Down Expand Up @@ -88,16 +90,16 @@ public struct FungibleResourceAsset: Sendable, FeatureReducer {
let remainingAmount = (state.balance - sumOfOthers).clamped

if state.isXRD {
if remainingAmount >= 1 {
if remainingAmount >= State.defaultFee {
state.alert = .chooseXRDAmount(
feeDeductedAmount: remainingAmount - 1,
feeDeductedAmount: remainingAmount - State.defaultFee,
maxAmount: remainingAmount
)
} else {
return .none
} else if remainingAmount > 0 {
state.alert = .willNeedToPayFeeFromOtherAccount(remainingAmount)
return .none
}

return .none
}

state.transferAmount = remainingAmount
Expand All @@ -121,7 +123,8 @@ public struct FungibleResourceAsset: Sendable, FeatureReducer {
state.transferAmountStr = amount.formattedPlain(useGroupingSeparator: false)
return .send(.delegate(.amountChanged))

case .presented(.needsToPayFeeFromOtherAccount(.cancel)):
case .presented(.needsToPayFeeFromOtherAccount(.cancel)),
.presented(.chooseXRDAmountAlert(.cancel)):
return .none

case .dismiss:
Expand All @@ -146,6 +149,10 @@ extension AlertState where Action == FungibleResourceAsset.ViewAction.Alert {
TextState(L10n.AssetTransfer.MaxAmountDialog.sendAllButton(maxAmount.formatted())),
action: .send(.chooseXRDAmountAlert(.sendAll(maxAmount)))
),
ButtonState.default(
TextState(L10n.Common.cancel),
action: .send(.chooseXRDAmountAlert(.cancel))
),
]
)
}
Expand Down
Loading