Skip to content

Commit

Permalink
Check with Sargon if Gateway is already added (#1204)
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasbzurovski committed Jul 10, 2024
1 parent b174f94 commit 2cf28b0
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion RadixWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8578,7 +8578,7 @@
repositoryURL = "https://github.com/radixdlt/sargon";
requirement = {
kind = exactVersion;
version = 1.0.22;
version = 1.0.23;
};
};
8318BB172BC8403800057BCB /* XCRemoteSwiftPackageReference "swift-custom-dump" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/radixdlt/sargon",
"state" : {
"revision" : "32fe10386b8b5f439420aa7f7c71c19e7da1bb1f",
"version" : "1.0.22"
"revision" : "eb02bd76b1261527938aac2cd982b8e1b505acf2",
"version" : "1.0.23"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public struct GatewaysClient: Sendable {
public var addGateway: AddGateway
public var removeGateway: RemoveGateway
public var changeGateway: ChangeGateway
public var hasGateway: HasGateway

public init(
currentGatewayValues: @escaping CurrentGatewayValues,
Expand All @@ -18,7 +19,8 @@ public struct GatewaysClient: Sendable {
getCurrentGateway: @escaping GetCurrentGateway,
addGateway: @escaping AddGateway,
removeGateway: @escaping RemoveGateway,
changeGateway: @escaping ChangeGateway
changeGateway: @escaping ChangeGateway,
hasGateway: @escaping HasGateway
) {
self.currentGatewayValues = currentGatewayValues
self.gatewaysValues = gatewaysValues
Expand All @@ -27,6 +29,7 @@ public struct GatewaysClient: Sendable {
self.addGateway = addGateway
self.removeGateway = removeGateway
self.changeGateway = changeGateway
self.hasGateway = hasGateway
}
}

Expand All @@ -38,6 +41,7 @@ extension GatewaysClient {
public typealias AddGateway = @Sendable (Gateway) async throws -> Void
public typealias RemoveGateway = @Sendable (Gateway) async throws -> Void
public typealias ChangeGateway = @Sendable (Gateway) async throws -> Void
public typealias HasGateway = @Sendable (Url) async -> Bool
}

extension GatewaysClient {
Expand Down
3 changes: 3 additions & 0 deletions RadixWallet/Clients/GatewaysClient/GatewaysClient+Live.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ extension GatewaysClient: DependencyKey {
try await profileStore.updating { profile in
try profile.changeGateway(to: gateway)
}
},
hasGateway: { url in
await appPreferencesClient.getPreferences().hasGateway(with: url)
}
)
}
Expand Down
6 changes: 4 additions & 2 deletions RadixWallet/Clients/GatewaysClient/GatewaysClient+Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ extension GatewaysClient: TestDependencyKey {
getCurrentGateway: unimplemented("\(Self.self).getCurrentGateway"),
addGateway: unimplemented("\(Self.self).addGateway"),
removeGateway: unimplemented("\(Self.self).removeGateway"),
changeGateway: unimplemented("\(Self.self).changeGateway")
changeGateway: unimplemented("\(Self.self).changeGateway"),
hasGateway: unimplemented("\(Self.self).hasGateway")
)

public static let noop = Self(
Expand All @@ -27,6 +28,7 @@ extension GatewaysClient: TestDependencyKey {
getCurrentGateway: { .nebunet },
addGateway: { _ in },
removeGateway: { _ in },
changeGateway: { _ in }
changeGateway: { _ in },
hasGateway: { _ in false }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ public struct AddNewGateway: Sendable, FeatureReducer {
guard let url = URL(string: state.inputtedURL)?.httpsURL else { return .none }

return .run { send in
let gateways = await gatewaysClient.getAllGateways()
let duplicate = gateways.first(where: { $0.url == url })
if let _ = duplicate {
let hasGateway = await gatewaysClient.hasGateway(url)
if hasGateway {
await send(.internal(.showDuplicateURLError))
} else {
await send(.internal(.validateNewGateway(url)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ final class GatewaySettingsFeatureTests: TestCase {
$0.gatewaysClient.getAllGateways = {
allGateways
}
$0.gatewaysClient.hasGateway = { _ in false }
}
store.exhaustivity = .off

Expand All @@ -199,6 +200,31 @@ final class GatewaySettingsFeatureTests: TestCase {
await store.receive(.internal(.addGatewayResult(.success(.instance))))
await store.receive(.delegate(.dismiss))
}

func test_whenNewAddGatewayButtonIsTapped_duplicateGatewayIsRejected() async throws {
// given
let allGateways: Gateways = [.nebunet, .hammunet, .enkinet, .mardunet]
let validURL = URL.previewValue.absoluteString
var initialState = AddNewGateway.State()
initialState.inputtedURL = validURL

let store = TestStore(
initialState: initialState,
reducer: AddNewGateway.init
) {
$0.gatewaysClient.getAllGateways = {
allGateways
}
$0.gatewaysClient.hasGateway = { url in
url.absoluteString == validURL
}
}
store.exhaustivity = .off

// when
await store.send(.view(.addNewGatewayButtonTapped))
await store.receive(.internal(.showDuplicateURLError))
}
}

#if DEBUG
Expand Down

0 comments on commit 2cf28b0

Please sign in to comment.