You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi guys
I want to make api call to update availableBalance each time operation changed
can you please suggest how to do
`struct TransactionTarget: ReducerProtocol {
// State of the ATMTargetSelection
struct State: Equatable {
// Unique identifier for the state
private let identifier: UUID
// Operation target of the ATM selection
fileprivate var operation: OperationTargetProtocol?
fileprivate var accountType: AccountSelectionView.AccountType?
// Internal state of the AccountSelectionView
fileprivate var _state: AccountSelectionView.State = .empty
// Optional balance value
fileprivate var availableBalance: Decimal?
public init(operation: OperationTargetProtocol?, accountType: AccountSelectionView.AccountType? = .debit, state: AccountSelectionView.State) {
self.identifier = UUID()
self.operation = operation
self.accountType = accountType
self._state = state
self.availableBalance = operation?.balanceViewModel?.availableBalance
/*
if operation?.balanceViewModel?.availableBalance == nil {
Task { [self] in
do {
@Dependency(\.selectTargetWorker) var worker
let result = try await worker.getAvailableBalance(
productId: operation?.targetId,
productType: BankProductType(rawValue: operation?.targetType ?? "") ?? .ACCOUNT
)
operation?.setAvailableBalance(result)
self.availableBalance = result?.availableBalance
} catch {
}
}
}
*/
}
// Optional amount value
fileprivate var amount: AmountModel? {
if let balance = operation?.balanceViewModel?.availableBalance {
return AmountModel(amount: balance, currency: .amd)
}
return nil
}
// Optional icon URL
fileprivate var iconUrl: URL? {
operation?.entitySettings?.mobileTypeIcon?.iconUrl
}
// Optional number value
fileprivate var number: String {
operation?.number ?? ""
}
// Optional target display name
fileprivate var targetDisplayName: String {
operation?.targetDisplayName ?? ""
}
// Background colors for the view
fileprivate var backgroundColors: [Color] {
return [Color(operation?.entitySettings?.mobileBackgroundFromColor?.color ?? .clear),
Color(operation?.entitySettings?.mobileBackgroundToColor?.color ?? .clear)]
}
// Equatable function to compare State instances
static func == (lhs: TransactionTarget.State, rhs: TransactionTarget.State) -> Bool {
lhs.identifier == rhs.identifier
}
}
enum Action {
case getAvailableBalance
case getBalanceResponse(TaskResult<Balance?>)
}
private enum CancelID { case getBalance }
@Dependency(\.selectTargetWorker) var worker
var body: some ReducerProtocol<State, Action> {
Reduce<State, Action> { state, action in
switch action {
case .getAvailableBalance:
if let operation = state.operation, operation.balanceViewModel?.availableBalance == nil {
return .run { [targetId = state.operation?.targetId, targetType = state.operation?.targetType] send in
await send(
.getBalanceResponse(
TaskResult { try await
worker.getAvailableBalance(
productId: targetId,
productType: BankProductType(rawValue: targetType ?? "") ?? .ACCOUNT)
}
)
)
}
.cancellable(id: CancelID.getBalance)
} else {
return .none
}
case let .getBalanceResponse(.success(result)):
state.availableBalance = result?.availableBalance
state.operation?.setAvailableBalance(result)
return .none
case .getBalanceResponse(.failure(_)):
return .none
}
}
}
}
struct TransactionTargetView: View {
let store: StoreOf
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys
I want to make api call to update availableBalance each time operation changed
can you please suggest how to do
`struct TransactionTarget: ReducerProtocol {
// State of the ATMTargetSelection
struct State: Equatable {
// Unique identifier for the state
private let identifier: UUID
}
struct TransactionTargetView: View {
let store: StoreOf
}`
Beta Was this translation helpful? Give feedback.
All reactions