Skip to content

Commit

Permalink
[ABW-3666] Fix Add gateway crash (#1266)
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasbzurovski authored Aug 7, 2024
1 parent d99829d commit 894086f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
6 changes: 3 additions & 3 deletions RadixWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -913,8 +913,8 @@
5BBC7D9F2C3D390E00B04BD6 /* BootstrapClient+Live.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BBC7D9C2C3D390D00B04BD6 /* BootstrapClient+Live.swift */; };
5BBC7DA42C3D442800B04BD6 /* URLRequest+Extra.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BBC7DA32C3D442800B04BD6 /* URLRequest+Extra.swift */; };
5BBC7DA62C3EFA9700B04BD6 /* HideAccountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BBC7DA52C3EFA9700B04BD6 /* HideAccountView.swift */; };
5BBC7DAA2C403F3400B04BD6 /* AccountCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BBC7DA92C403F3400B04BD6 /* AccountCard.swift */; };
5BBC7DA82C40278E00B04BD6 /* NonFungibleResourceAsset+Reducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BBC7DA72C40278E00B04BD6 /* NonFungibleResourceAsset+Reducer.swift */; };
5BBC7DAA2C403F3400B04BD6 /* AccountCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BBC7DA92C403F3400B04BD6 /* AccountCard.swift */; };
5BC82B6C2BED18A1009AC162 /* FactoryReset+View.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC82B6A2BED18A1009AC162 /* FactoryReset+View.swift */; };
5BC82B6D2BED18A1009AC162 /* FactoryReset+Reducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC82B6B2BED18A1009AC162 /* FactoryReset+Reducer.swift */; };
830818482B9F1621002D8351 /* HTTPClient+Live.swift in Sources */ = {isa = PBXBuildFile; fileRef = 830818472B9F1621002D8351 /* HTTPClient+Live.swift */; };
Expand Down Expand Up @@ -2064,8 +2064,8 @@
5BBC7D9C2C3D390D00B04BD6 /* BootstrapClient+Live.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BootstrapClient+Live.swift"; sourceTree = "<group>"; };
5BBC7DA32C3D442800B04BD6 /* URLRequest+Extra.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URLRequest+Extra.swift"; sourceTree = "<group>"; };
5BBC7DA52C3EFA9700B04BD6 /* HideAccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HideAccountView.swift; sourceTree = "<group>"; };
5BBC7DA92C403F3400B04BD6 /* AccountCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountCard.swift; sourceTree = "<group>"; };
5BBC7DA72C40278E00B04BD6 /* NonFungibleResourceAsset+Reducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NonFungibleResourceAsset+Reducer.swift"; sourceTree = "<group>"; };
5BBC7DA92C403F3400B04BD6 /* AccountCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountCard.swift; sourceTree = "<group>"; };
5BC82B6A2BED18A1009AC162 /* FactoryReset+View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FactoryReset+View.swift"; sourceTree = "<group>"; };
5BC82B6B2BED18A1009AC162 /* FactoryReset+Reducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FactoryReset+Reducer.swift"; sourceTree = "<group>"; };
830818472B9F1621002D8351 /* HTTPClient+Live.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "HTTPClient+Live.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -8721,7 +8721,7 @@
repositoryURL = "https://github.com/radixdlt/sargon";
requirement = {
kind = exactVersion;
version = 1.0.33;
version = 1.0.34;
};
};
A415574E2B757C5E0040AD4E /* XCRemoteSwiftPackageReference "swift-composable-architecture" */ = {
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" : "3d4c3babf97bb5c7702e3cba74add5a04f00bfdd",
"version" : "1.0.33"
"revision" : "823d811c9e9d0093977ea9cb20ff4ba2f5e77747",
"version" : "1.0.34"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +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
public typealias HasGateway = @Sendable (FfiUrl) async -> Bool
}

extension GatewaysClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public struct AddNewGateway: Sendable, FeatureReducer {
var inputtedURL: String = ""
var errorText: String?
var addGatewayButtonState: ControlState = .disabled
var ffiUrl: FfiUrl?

public init() {}
}
Expand Down Expand Up @@ -56,14 +57,14 @@ public struct AddNewGateway: Sendable, FeatureReducer {
}

case .addNewGatewayButtonTapped:
guard let url = URL(string: state.inputtedURL)?.httpsURL else { return .none }
guard let ffiUrl = state.ffiUrl else { return .none }

return .run { send in
let hasGateway = await gatewaysClient.hasGateway(url)
let hasGateway = await gatewaysClient.hasGateway(ffiUrl)
if hasGateway {
await send(.internal(.showDuplicateURLError))
} else {
await send(.internal(.validateNewGateway(url)))
await send(.internal(.validateNewGateway(ffiUrl.url)))
}
}

Expand All @@ -75,8 +76,13 @@ public struct AddNewGateway: Sendable, FeatureReducer {
case let .textFieldChanged(inputtedURL):
state.inputtedURL = inputtedURL
state.errorText = nil
let url = URL(string: inputtedURL)
state.addGatewayButtonState = url != nil ? .enabled : .disabled
if let url = URL(string: state.inputtedURL)?.httpsURL, let ffiUrl = try? FfiUrl(urlPath: url.absoluteString) {
state.ffiUrl = ffiUrl
state.addGatewayButtonState = .enabled
} else {
state.ffiUrl = nil
state.addGatewayButtonState = .disabled
}
return .none
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@testable import Radix_Wallet_Dev
import Sargon
import SargonUniFFI
import XCTest

// MARK: - GatewaySettingsFeatureTests
Expand Down Expand Up @@ -180,6 +181,7 @@ final class GatewaySettingsFeatureTests: TestCase {
let validURL = URL.previewValue.absoluteString
var initialState = AddNewGateway.State()
initialState.inputtedURL = validURL
initialState.ffiUrl = try? .init(urlPath: validURL)

let store = TestStore(
initialState: initialState,
Expand All @@ -206,6 +208,7 @@ final class GatewaySettingsFeatureTests: TestCase {
let validURL = URL.previewValue.absoluteString
var initialState = AddNewGateway.State()
initialState.inputtedURL = validURL
initialState.ffiUrl = try? .init(urlPath: validURL)

let store = TestStore(
initialState: initialState,
Expand All @@ -215,7 +218,7 @@ final class GatewaySettingsFeatureTests: TestCase {
allGateways
}
$0.gatewaysClient.hasGateway = { url in
url.absoluteString == validURL
url.url.absoluteString == validURL
}
}
store.exhaustivity = .off
Expand All @@ -229,6 +232,6 @@ final class GatewaySettingsFeatureTests: TestCase {
#if DEBUG

extension URL {
public static let previewValue = URL(string: "https://example.com")!
public static let previewValue = URL(string: "https://example.com/")!
}
#endif // DEBUG

0 comments on commit 894086f

Please sign in to comment.