Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 11ef600

Browse files
committed
add applyAccumulatedQuotes helper
1 parent 7d37617 commit 11ef600

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

Features/Swap/Sources/ViewModels/SwapSceneViewModel.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,7 @@ extension SwapSceneViewModel {
352352
switch result {
353353
case .success(let quote):
354354
accumulated.append(quote)
355-
let sorted = try? accumulated.sorted { try BigInt.from(string: $0.toValue) > BigInt.from(string: $1.toValue) }
356-
accumulated = sorted ?? accumulated
357-
swapState.quotes = .data(accumulated)
358-
selectedSwapQuote = accumulated.first
359-
if let selectedSwapQuote, let asset = toAsset?.asset {
360-
applyQuote(selectedSwapQuote, asset: asset)
361-
}
355+
applyAccumulatedQuotes(&accumulated)
362356
case .failure(let error):
363357
errors.append(error)
364358
}
@@ -382,6 +376,16 @@ extension SwapSceneViewModel {
382376
}
383377
}
384378

379+
private func applyAccumulatedQuotes(_ accumulated: inout [SwapperQuote]) {
380+
let sorted = try? accumulated.sorted { try BigInt.from(string: $0.toValue) > BigInt.from(string: $1.toValue) }
381+
accumulated = sorted ?? accumulated
382+
swapState.quotes = .data(accumulated)
383+
selectedSwapQuote = accumulated.first
384+
if let selectedSwapQuote, let asset = toAsset?.asset {
385+
applyQuote(selectedSwapQuote, asset: asset)
386+
}
387+
}
388+
385389
private func prioritizedSwapError(_ errors: [Error]) -> SwapperError? {
386390
let inputErrors: [(BigInt?, String?)] = errors.compactMap { error in
387391
guard let swapperError = error as? SwapperError, case .InputAmountError(let minAmount) = swapperError else { return nil }

0 commit comments

Comments
 (0)