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

Commit 7d37617

Browse files
committed
code cleanup
1 parent f1b4759 commit 7d37617

4 files changed

Lines changed: 6 additions & 19 deletions

File tree

Features/Swap/Sources/ViewModels/SwapSceneViewModel.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,7 @@ extension SwapSceneViewModel {
346346
var accumulated: [SwapperQuote] = []
347347
var errors: [Error] = []
348348

349-
for await result in swapQuotesProvider.fetchQuotes(
350-
wallet: wallet,
351-
fromAsset: input.fromAsset,
352-
toAsset: input.toAsset,
353-
amount: input.value,
354-
useMaxAmount: input.useMaxAmount
355-
) {
349+
for await result in swapQuotesProvider.fetchQuotes(wallet: wallet, input: input) {
356350
try Task.checkCancellation()
357351

358352
switch result {

Features/Swap/Tests/SwapTests/SwapSceneViewModelTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ struct SwapSceneViewModelTests {
138138
toValueMock: String = "250000000000"
139139
) async -> SwapSceneViewModel {
140140
let swapper = GemSwapperMock(
141-
quotes: [.mock(toValue: toValueMock)],
142141
quoteByProvider: .mock(toValue: toValueMock)
143142
)
144143
let model = SwapSceneViewModel.mock(swapper: swapper)

Packages/FeatureServices/SwapService/SwapQuotesProvider.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Copyright (c). Gem Wallet. All rights reserved.
22

3-
import Foundation
4-
import BigInt
53
import Foundation
64
import Primitives
75

@@ -10,7 +8,7 @@ import struct Gemstone.SwapperProviderType
108

119
public protocol SwapQuotesProvidable: Sendable {
1210
func supportedAssets(for assetId: AssetId) -> ([Primitives.Chain], [Primitives.AssetId])
13-
func fetchQuotes(wallet: Wallet, fromAsset: Asset, toAsset: Asset, amount: BigInt, useMaxAmount: Bool) -> AsyncStream<Result<SwapperQuote, Error>>
11+
func fetchQuotes(wallet: Wallet, input: SwapQuoteInput) -> AsyncStream<Result<SwapperQuote, Error>>
1412
}
1513

1614
public struct SwapQuotesProvider: SwapQuotesProvidable {
@@ -24,13 +22,12 @@ public struct SwapQuotesProvider: SwapQuotesProvidable {
2422
swapService.supportedAssets(for: assetId)
2523
}
2624

27-
public func fetchQuotes(wallet: Wallet, fromAsset: Asset, toAsset: Asset, amount: BigInt, useMaxAmount: Bool) -> AsyncStream<Result<SwapperQuote, Error>> {
25+
public func fetchQuotes(wallet: Wallet, input: SwapQuoteInput) -> AsyncStream<Result<SwapperQuote, Error>> {
2826
AsyncStream { continuation in
2927
Task {
3028
do {
31-
let input = SwapQuoteInput(fromAsset: fromAsset, toAsset: toAsset, value: amount, useMaxAmount: useMaxAmount)
32-
let walletAddress = try wallet.account(for: fromAsset.chain).address
33-
let destinationAddress = try wallet.account(for: toAsset.chain).address
29+
let walletAddress = try wallet.account(for: input.fromAsset.chain).address
30+
let destinationAddress = try wallet.account(for: input.toAsset.chain).address
3431
let providers = try swapService.getProvidersForQuote(input: input, walletAddress: walletAddress, destinationAddress: destinationAddress)
3532
await fetchFromProviders(providers, input: input, walletAddress: walletAddress, destinationAddress: destinationAddress, continuation: continuation)
3633
} catch {

Packages/FeatureServices/SwapService/TestKit/GemSwapperMock.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import struct Gemstone.SwapperSwapResult
1515

1616
public final class GemSwapperMock: GemSwapperProtocol {
1717
private let permit2ForQuote: Permit2ApprovalData
18-
private let quotes: [SwapperQuote]
1918
private let quoteByProvider: SwapperQuote
2019
private let quoteData: GemSwapQuoteData
2120
private let providers: [SwapperProviderType]
@@ -28,7 +27,6 @@ public final class GemSwapperMock: GemSwapperProtocol {
2827

2928
public init(
3029
permit2ForQuote: Permit2ApprovalData = .mock(),
31-
quotes: [SwapperQuote] = [.mock()],
3230
quoteByProvider: SwapperQuote = .mock(),
3331
quoteData: GemSwapQuoteData = .mock(),
3432
providers: [SwapperProviderType] = [.mock()],
@@ -40,7 +38,6 @@ public final class GemSwapperMock: GemSwapperProtocol {
4038
fetchQuoteError: Error? = nil
4139
) {
4240
self.permit2ForQuote = permit2ForQuote
43-
self.quotes = quotes
4441
self.quoteByProvider = quoteByProvider
4542
self.quoteData = quoteData
4643
self.providers = providers
@@ -63,7 +60,7 @@ public final class GemSwapperMock: GemSwapperProtocol {
6360
if let error = fetchQuoteError {
6461
throw error
6562
}
66-
return quotes
63+
return [quoteByProvider]
6764
}
6865

6966
public func fetchQuoteByProvider(provider: SwapperProvider, request: SwapperQuoteRequest) async throws -> SwapperQuote {

0 commit comments

Comments
 (0)