diff --git a/RadixWallet.xcodeproj/project.pbxproj b/RadixWallet.xcodeproj/project.pbxproj index c8a362d728..eeb8002974 100644 --- a/RadixWallet.xcodeproj/project.pbxproj +++ b/RadixWallet.xcodeproj/project.pbxproj @@ -9279,7 +9279,7 @@ repositoryURL = "https://github.com/radixdlt/sargon"; requirement = { kind = exactVersion; - version = 1.1.64; + version = 1.1.68; }; }; /* End XCRemoteSwiftPackageReference section */ diff --git a/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 5891022331..0af481af69 100644 --- a/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -114,8 +114,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/radixdlt/sargon", "state" : { - "revision" : "7ca859a59155eea571d7ec725db04dfc9520c391", - "version" : "1.1.64" + "revision" : "18dd3e2bc0c4ea8ceafb2c9bd73af78ce1578e0b", + "version" : "1.1.68" } }, { diff --git a/RadixWallet/Clients/PreAuthorizationClient/PreAuthorizationClient+Interface.swift b/RadixWallet/Clients/PreAuthorizationClient/PreAuthorizationClient+Interface.swift index 755cb8f8fb..6c4515acdb 100644 --- a/RadixWallet/Clients/PreAuthorizationClient/PreAuthorizationClient+Interface.swift +++ b/RadixWallet/Clients/PreAuthorizationClient/PreAuthorizationClient+Interface.swift @@ -29,6 +29,6 @@ extension PreAuthorizationClient { struct PollStatusRequest: Sendable { let subintentHash: SubintentHash - let expiration: DappToWalletInteractionSubintentExpiration + let expirationTimestamp: Instant } } diff --git a/RadixWallet/Clients/PreAuthorizationClient/PreAuthorizationClient+Live.swift b/RadixWallet/Clients/PreAuthorizationClient/PreAuthorizationClient+Live.swift index 11a26440ea..26695f55c6 100644 --- a/RadixWallet/Clients/PreAuthorizationClient/PreAuthorizationClient+Live.swift +++ b/RadixWallet/Clients/PreAuthorizationClient/PreAuthorizationClient+Live.swift @@ -69,7 +69,7 @@ extension PreAuthorizationClient: DependencyKey { } let pollStatus: PollStatus = { request in - try await SargonOS.shared.pollPreAuthorizationStatus(intentHash: request.subintentHash, expiration: request.expiration) + try await SargonOS.shared.pollPreAuthorizationStatus(intentHash: request.subintentHash, expirationTimestamp: request.expirationTimestamp) } return Self( diff --git a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionCoordinator.swift b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionCoordinator.swift index fa0a7dd974..54ec3628a3 100644 --- a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionCoordinator.swift +++ b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionCoordinator.swift @@ -40,7 +40,7 @@ struct DappInteractionCoordinator: Sendable, FeatureReducer { } enum DelegateAction: Sendable, Equatable { - case submit(WalletToDappInteractionResponse, DappMetadata, PreAuthorizationData? = nil) + case submit(WalletToDappInteractionResponse, DappMetadata) case dismiss(DappMetadata, DappInteractionCompletionKind) case dismissSilently } @@ -102,8 +102,8 @@ struct DappInteractionCoordinator: Sendable, FeatureReducer { case .flow(.delegate(.dismiss)): return .send(.delegate(.dismissSilently)) - case let .flow(.delegate(.submit(response, dappMetadata, preAuthData))): - return .send(.delegate(.submit(.success(response), dappMetadata, preAuthData))) + case let .flow(.delegate(.submit(response, dappMetadata))): + return .send(.delegate(.submit(.success(response), dappMetadata))) default: return .none diff --git a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionFlow.swift b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionFlow.swift index 66f25213a4..97907c07c0 100644 --- a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionFlow.swift +++ b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionFlow.swift @@ -125,7 +125,7 @@ struct DappInteractionFlow: Sendable, FeatureReducer { enum DelegateAction: Sendable, Equatable { case dismissWithFailure(WalletToDappInteractionFailureResponse) case dismissWithSuccess(DappMetadata, DappInteractionCompletionKind) - case submit(WalletToDappInteractionSuccessResponse, DappMetadata, PreAuthorizationData? = nil) + case submit(WalletToDappInteractionSuccessResponse, DappMetadata) case dismiss } @@ -512,13 +512,12 @@ extension DappInteractionFlow { func handlePreAuthorizationSignature( _ item: State.AnyInteractionItem, - _ signedSubintent: SignedSubintent, - _ expiration: DappToWalletInteractionSubintentExpiration + _ signedSubintent: SignedSubintent ) -> Effect { let preAuthResponse = newWalletToDappInteractionPreAuthorizationResponseItems(signedSubintent: signedSubintent) state.responseItems[item] = .remote(.preAuthorization(preAuthResponse)) - return continueEffect(for: &state, preAuthData: .init(subintentHash: signedSubintent.subintent.hash(), expiration: expiration)) + return continueEffect(for: &state) } func handlePreAuthorizationFailure( @@ -588,8 +587,8 @@ extension DappInteractionFlow { .accountsProofOfOwnership(.delegate(.failedToSign)): return dismissEffect(for: state, errorKind: .failedToSignAuthChallenge, message: nil) - case let .preAuthorizationReview(.delegate(.signedPreAuthorization(encoded, expiration))): - return handlePreAuthorizationSignature(item, encoded, expiration) + case let .preAuthorizationReview(.delegate(.signedPreAuthorization(encoded))): + return handlePreAuthorizationSignature(item, encoded) case let .preAuthorizationReview(.delegate(.failed(error))): return handlePreAuthorizationFailure(error) @@ -746,7 +745,7 @@ extension DappInteractionFlow { } } - func continueEffect(for state: inout State, preAuthData: PreAuthorizationData? = nil) -> Effect { + func continueEffect(for state: inout State) -> Effect { if let nextRequest = state.interactionItems.first(where: { state.responseItems[$0] == nil }), let destination = Path.State( @@ -768,11 +767,11 @@ extension DappInteractionFlow { } return .none } else { - return finishInteractionFlow(state, preAuthData: preAuthData) + return finishInteractionFlow(state) } } - func finishInteractionFlow(_ state: State, preAuthData: PreAuthorizationData?) -> Effect { + func finishInteractionFlow(_ state: State) -> Effect { guard let response = WalletToDappInteractionSuccessResponse( for: state.remoteInteraction, with: state.responseItems.values.compactMap(/State.AnyInteractionResponseItem.remote) @@ -796,7 +795,7 @@ extension DappInteractionFlow { } } - await send(.delegate(.submit(response, state.dappMetadata, preAuthData))) + await send(.delegate(.submit(response, state.dappMetadata))) } } diff --git a/RadixWallet/Features/DappInteractionFeature/Interactor/DappInteractor.swift b/RadixWallet/Features/DappInteractionFeature/Interactor/DappInteractor.swift index c00b8f8dbd..c22167c975 100644 --- a/RadixWallet/Features/DappInteractionFeature/Interactor/DappInteractor.swift +++ b/RadixWallet/Features/DappInteractionFeature/Interactor/DappInteractor.swift @@ -4,12 +4,6 @@ import SwiftUI typealias RequestEnvelope = DappInteractionClient.RequestEnvelope -// MARK: - PreAuthorizationData -struct PreAuthorizationData: Sendable, Hashable { - let subintentHash: SubintentHash - let expiration: DappToWalletInteractionSubintentExpiration -} - // MARK: - RequestEnvelope + Identifiable extension RequestEnvelope: Identifiable { typealias ID = WalletInteractionId @@ -49,15 +43,13 @@ struct DappInteractor: Sendable, FeatureReducer { case sentResponseToDapp( WalletToDappInteractionResponse, for: RequestEnvelope, - DappMetadata, - PreAuthorizationData? + DappMetadata ) case failedToSendResponseToDapp( WalletToDappInteractionResponse, for: RequestEnvelope, DappMetadata, - reason: String, - preAuthData: PreAuthorizationData? + reason: String ) case presentResponseSuccessView(DappMetadata, DappInteractionCompletionKind, P2P.Route) case presentInvalidRequest( @@ -86,7 +78,7 @@ struct DappInteractor: Sendable, FeatureReducer { enum ResponseFailure: Sendable, Hashable { case cancelButtonTapped(RequestEnvelope) - case retryButtonTapped(WalletToDappInteractionResponse, for: RequestEnvelope, DappMetadata, PreAuthorizationData?) + case retryButtonTapped(WalletToDappInteractionResponse, for: RequestEnvelope, DappMetadata) } enum InvalidRequest: Sendable, Hashable { @@ -168,12 +160,12 @@ struct DappInteractor: Sendable, FeatureReducer { case .presentQueuedRequestIfNeeded: return presentQueuedRequestIfNeededEffect(for: &state) - case let .sentResponseToDapp(response, for: request, dappMetadata, preAuthData): + case let .sentResponseToDapp(response, for: request, dappMetadata): switch response { - case .success: - if let preAuthData { + case let .success(success): + if let response = success.preAuthorizationResponse { dismissCurrentModalAndRequest(request, for: &state, clearDappInteraction: false) - return pollPreAuthorizationEffect(for: &state, request: request, dappMetadata: dappMetadata, preAuthData: preAuthData) + return pollPreAuthorizationEffect(for: &state, request: request, dappMetadata: dappMetadata, response: response) } else { dismissCurrentModalAndRequest(request, for: &state) return .send(.internal(.presentResponseSuccessView(dappMetadata, .personaData, request.route))) @@ -183,7 +175,7 @@ struct DappInteractor: Sendable, FeatureReducer { return delayedMediumEffect(internal: .presentQueuedRequestIfNeeded) } - case let .failedToSendResponseToDapp(response, for: request, dappMetadata, reason, preAuthData): + case let .failedToSendResponseToDapp(response, for: request, dappMetadata, reason): dismissCurrentModalAndRequest(request, for: &state) state.destination = .responseFailure(.init( title: { TextState(L10n.Common.errorAlertTitle) }, @@ -191,7 +183,7 @@ struct DappInteractor: Sendable, FeatureReducer { ButtonState(role: .cancel, action: .cancelButtonTapped(request)) { TextState(L10n.Common.cancel) } - ButtonState(action: .retryButtonTapped(response, for: request, dappMetadata, preAuthData)) { + ButtonState(action: .retryButtonTapped(response, for: request, dappMetadata)) { TextState(L10n.Common.retry) } }, @@ -251,8 +243,8 @@ struct DappInteractor: Sendable, FeatureReducer { let request = dappInteraction.request switch delegateAction { - case let .submit(responseToDapp, dappMetadata, preAuthData): - return sendResponseToDappEffect(responseToDapp, for: request, dappMetadata: dappMetadata, preAuthData: preAuthData) + case let .submit(responseToDapp, dappMetadata): + return sendResponseToDappEffect(responseToDapp, for: request, dappMetadata: dappMetadata) case let .dismiss(dappMetadata, txID): dismissCurrentModalAndRequest(request, for: &state) return delayedShortEffect(for: .internal(.presentResponseSuccessView(dappMetadata, txID, request.route))) @@ -276,8 +268,8 @@ struct DappInteractor: Sendable, FeatureReducer { case let .cancelButtonTapped(request): dismissCurrentModalAndRequest(request, for: &state) return .send(.internal(.presentQueuedRequestIfNeeded)) - case let .retryButtonTapped(response, request, dappMetadata, preAuthData): - return sendResponseToDappEffect(response, for: request, dappMetadata: dappMetadata, preAuthData: preAuthData) + case let .retryButtonTapped(response, request, dappMetadata): + return sendResponseToDappEffect(response, for: request, dappMetadata: dappMetadata) } case let .invalidRequest(action): @@ -333,8 +325,7 @@ struct DappInteractor: Sendable, FeatureReducer { func sendResponseToDappEffect( _ responseToDapp: WalletToDappInteractionResponse, for request: RequestEnvelope, - dappMetadata: DappMetadata, - preAuthData: PreAuthorizationData? + dappMetadata: DappMetadata ) -> Effect { .run { send in @@ -359,8 +350,7 @@ struct DappInteractor: Sendable, FeatureReducer { .sentResponseToDapp( responseToDapp, for: request, - dappMetadata, - preAuthData + dappMetadata ) )) } else { @@ -373,8 +363,7 @@ struct DappInteractor: Sendable, FeatureReducer { responseToDapp, for: request, dappMetadata, - reason: error.localizedDescription, - preAuthData: preAuthData + reason: error.localizedDescription ) )) } else { @@ -401,13 +390,13 @@ struct DappInteractor: Sendable, FeatureReducer { for state: inout State, request: RequestEnvelope, dappMetadata: DappMetadata, - preAuthData: PreAuthorizationData + response: WalletToDappInteractionSubintentResponseItem ) -> Effect { state.destination = .pollPreAuthorizationStatus( .init( dAppMetadata: dappMetadata, - subintentHash: preAuthData.subintentHash, - expiration: preAuthData.expiration, + subintentHash: response.signedSubintent.subintent.hash(), + expirationTimestamp: response.expirationTimestamp, isDeepLink: request.route.isDeepLink, request: request ) @@ -572,3 +561,14 @@ private extension DappInteractionCompletionKind { } } } + +private extension WalletToDappInteractionSuccessResponse { + var preAuthorizationResponse: WalletToDappInteractionSubintentResponseItem? { + switch items { + case let .preAuthorization(preAuthorization): + preAuthorization.response + case .authorizedRequest, .unauthorizedRequest, .transaction: + nil + } + } +} diff --git a/RadixWallet/Features/PreAuthorizationReview/PollPreAuthorizationStatus/PollPreAuthorizationStatus.swift b/RadixWallet/Features/PreAuthorizationReview/PollPreAuthorizationStatus/PollPreAuthorizationStatus.swift index 4dd69ce91c..3e2b6f5e40 100644 --- a/RadixWallet/Features/PreAuthorizationReview/PollPreAuthorizationStatus/PollPreAuthorizationStatus.swift +++ b/RadixWallet/Features/PreAuthorizationReview/PollPreAuthorizationStatus/PollPreAuthorizationStatus.swift @@ -5,7 +5,7 @@ struct PollPreAuthorizationStatus: Sendable, FeatureReducer { struct State: Sendable, Hashable { let dAppMetadata: DappMetadata let subintentHash: SubintentHash - let expiration: Expiration + let expirationTimestamp: Instant let isDeepLink: Bool let request: RequestEnvelope var status = Status.unknown @@ -14,21 +14,16 @@ struct PollPreAuthorizationStatus: Sendable, FeatureReducer { init( dAppMetadata: DappMetadata, subintentHash: SubintentHash, - expiration: Expiration, + expirationTimestamp: Instant, isDeepLink: Bool, request: RequestEnvelope ) { self.dAppMetadata = dAppMetadata self.subintentHash = subintentHash - self.expiration = expiration + self.expirationTimestamp = expirationTimestamp self.isDeepLink = isDeepLink self.request = request - switch expiration { - case let .afterDelay(afterDelay): - secondsToExpiration = Int(afterDelay.expireAfterSeconds) - case let .atTime(atTime): - secondsToExpiration = Int(atTime.date.timeIntervalSinceNow) - } + self.secondsToExpiration = Int(expirationTimestamp.date.timeIntervalSinceNow) } } @@ -79,7 +74,7 @@ struct PollPreAuthorizationStatus: Sendable, FeatureReducer { private func pollStatus(state: inout State) -> Effect { let request = PreAuthorizationClient.PollStatusRequest( subintentHash: state.subintentHash, - expiration: state.expiration + expirationTimestamp: state.expirationTimestamp ) return .run { send in let status = try await preAuthorizationClient.pollStatus(request) diff --git a/RadixWallet/Features/PreAuthorizationReview/PreAuthorizationReview.swift b/RadixWallet/Features/PreAuthorizationReview/PreAuthorizationReview.swift index 61b433d0b6..7edba2fef9 100644 --- a/RadixWallet/Features/PreAuthorizationReview/PreAuthorizationReview.swift +++ b/RadixWallet/Features/PreAuthorizationReview/PreAuthorizationReview.swift @@ -44,7 +44,7 @@ struct PreAuthorizationReview: Sendable, FeatureReducer { } enum DelegateAction: Sendable, Equatable { - case signedPreAuthorization(SignedSubintent, DappToWalletInteractionSubintentExpiration) + case signedPreAuthorization(SignedSubintent) case failed(PreAuthorizationFailure) } @@ -272,7 +272,7 @@ private extension PreAuthorizationReview { func handleSignedSubinent(state: inout State, signedSubintent: SignedSubintent) -> Effect { state.destination = nil - return .send(.delegate(.signedPreAuthorization(signedSubintent, state.expiration))) + return .send(.delegate(.signedPreAuthorization(signedSubintent))) } }