diff --git a/RadixWallet/Clients/AccountsClient/AccountsClient+Interface.swift b/RadixWallet/Clients/AccountsClient/AccountsClient+Interface.swift index 21bdcf8b1d..694e15084e 100644 --- a/RadixWallet/Clients/AccountsClient/AccountsClient+Interface.swift +++ b/RadixWallet/Clients/AccountsClient/AccountsClient+Interface.swift @@ -139,4 +139,13 @@ extension AccountsClient { public func saveVirtualAccount(_ account: Account) async throws { try await saveVirtualAccounts([account]) } + + public func isLedgerHWAccount(_ address: AccountAddress) async -> Bool { + do { + let account = try await getAccountByAddress(address) + return account.isLedgerControlled + } catch { + return false + } + } } diff --git a/RadixWallet/Core/FeaturePrelude/AddressView/AddressDetails+View.swift b/RadixWallet/Core/FeaturePrelude/AddressView/AddressDetails+View.swift index 8aabd419ae..58f46f4ffd 100644 --- a/RadixWallet/Core/FeaturePrelude/AddressView/AddressDetails+View.swift +++ b/RadixWallet/Core/FeaturePrelude/AddressView/AddressDetails+View.swift @@ -221,14 +221,3 @@ private extension AddressDetails.View { return .init(result) } } - -private extension AddressDetails.State { - var showVerifyOnLedger: Bool { - switch address { - case let .account(_, isLedgerHWAccount): - isLedgerHWAccount - default: - false - } - } -} diff --git a/RadixWallet/Core/FeaturePrelude/AddressView/AddressDetails.swift b/RadixWallet/Core/FeaturePrelude/AddressView/AddressDetails.swift index 87a529351e..299480690d 100644 --- a/RadixWallet/Core/FeaturePrelude/AddressView/AddressDetails.swift +++ b/RadixWallet/Core/FeaturePrelude/AddressView/AddressDetails.swift @@ -9,6 +9,7 @@ public struct AddressDetails: Sendable, FeatureReducer { var showEnlarged = false var showShare = false + var showVerifyOnLedger = false public init(address: LedgerIdentifiable.Address) { self.address = address @@ -31,6 +32,7 @@ public struct AddressDetails: Sendable, FeatureReducer { public enum InternalAction: Sendable, Equatable { case loadedTitle(TaskResult) case loadedQrImage(TaskResult) + case loadedShowVerifyOnLedger(Bool) } @Dependency(\.accountsClient) var accountsClient @@ -48,6 +50,7 @@ public struct AddressDetails: Sendable, FeatureReducer { case .task: return loadTitleEffect(state: &state) .merge(with: loadQrCodeEffect(state: &state)) + .merge(with: loadShowVerifyOnLedgerEffect(state: state)) case .copyButtonTapped: pasteboardClient.copyString(state.address.address) return .none @@ -70,7 +73,7 @@ public struct AddressDetails: Sendable, FeatureReducer { await openURL(url) } case .verifyOnLedgerButtonTapped: - if case let .account(address, _) = state.address { + if case let .account(address) = state.address { ledgerHardwareWalletClient.verifyAddress(of: address) } return .none @@ -97,6 +100,9 @@ public struct AddressDetails: Sendable, FeatureReducer { case let .loadedQrImage(.failure(error)): state.qrImage = .failure(error) return .none + case let .loadedShowVerifyOnLedger(value): + state.showVerifyOnLedger = value + return .none } } @@ -111,7 +117,7 @@ public struct AddressDetails: Sendable, FeatureReducer { private func loadTitle(address: LedgerIdentifiable.Address) async throws -> String? { switch address { - case let .account(address, _): + case let .account(address): try await accountsClient.getAccountByAddress(address).displayName.rawValue case let .resource(address): try await onLedgerEntitiesClient.getResource(address).resourceTitle @@ -141,6 +147,18 @@ public struct AddressDetails: Sendable, FeatureReducer { await send(.internal(.loadedQrImage(result))) } } + + private func loadShowVerifyOnLedgerEffect(state: State) -> Effect { + switch state.address { + case let .account(address): + .run { send in + let showVerifyOnLedger = await accountsClient.isLedgerHWAccount(address) + await send(.internal(.loadedShowVerifyOnLedger(showVerifyOnLedger))) + } + default: + .send(.internal(.loadedShowVerifyOnLedger(false))) + } + } } // MARK: - Helpers diff --git a/RadixWallet/Core/SharedModels/LedgerIdentifiable.swift b/RadixWallet/Core/SharedModels/LedgerIdentifiable.swift index dd7e48015c..24141c8def 100644 --- a/RadixWallet/Core/SharedModels/LedgerIdentifiable.swift +++ b/RadixWallet/Core/SharedModels/LedgerIdentifiable.swift @@ -4,7 +4,7 @@ public enum LedgerIdentifiable: Sendable { case transaction(IntentHash) public static func address(of account: Account) -> Self { - .address(.account(account.address, isLedgerHWAccount: account.isLedgerControlled)) + .address(.account(account.address)) } public var address: String { @@ -33,7 +33,7 @@ public enum LedgerIdentifiable: Sendable { // MARK: LedgerIdentifiable.Address extension LedgerIdentifiable { public enum Address: Hashable, Sendable, Identifiable { - case account(AccountAddress, isLedgerHWAccount: Bool = false) + case account(AccountAddress) case package(PackageAddress) case resource(ResourceAddress) case resourcePool(PoolAddress) @@ -48,7 +48,7 @@ extension LedgerIdentifiable { public func formatted(_ format: AddressFormat) -> String { switch self { - case let .account(accountAddress, _): + case let .account(accountAddress): accountAddress.formatted(format) case let .package(packageAddress): packageAddress.formatted(format) @@ -86,7 +86,7 @@ extension LedgerIdentifiable { public var id: String { switch self { - case let .account(accountAddress, _): + case let .account(accountAddress): accountAddress.id case let .package(packageAddress): packageAddress.id @@ -109,7 +109,7 @@ extension LedgerIdentifiable.Address { public init?(address: Address) { switch address { case let .account(accountAddress): - self = .account(accountAddress, isLedgerHWAccount: false) + self = .account(accountAddress) case let .resource(resourceAddress): self = .resource(resourceAddress) case let .pool(poolAddress): diff --git a/RadixWallet/Features/AccountDetailsFeature/Coordinator/AccountDetails+View.swift b/RadixWallet/Features/AccountDetailsFeature/Coordinator/AccountDetails+View.swift index a91e772432..33c916d41c 100644 --- a/RadixWallet/Features/AccountDetailsFeature/Coordinator/AccountDetails+View.swift +++ b/RadixWallet/Features/AccountDetailsFeature/Coordinator/AccountDetails+View.swift @@ -78,7 +78,7 @@ extension AccountDetails { @ViewBuilder func header(with viewStore: ViewStore) -> some SwiftUI.View { - AddressView(.address(.account(viewStore.accountAddress, isLedgerHWAccount: viewStore.isLedgerAccount))) + AddressView(.address(.account(viewStore.accountAddress))) .foregroundColor(.app.whiteTransparent) .textStyle(.body2HighImportance) .padding(.bottom, .small1) diff --git a/RadixWallet/Features/CreateAccount/Children/NewAccountCompletion/NewAccountCompletion+View.swift b/RadixWallet/Features/CreateAccount/Children/NewAccountCompletion/NewAccountCompletion+View.swift index 23f441c48b..94fd80a2d3 100644 --- a/RadixWallet/Features/CreateAccount/Children/NewAccountCompletion/NewAccountCompletion+View.swift +++ b/RadixWallet/Features/CreateAccount/Children/NewAccountCompletion/NewAccountCompletion+View.swift @@ -31,7 +31,6 @@ extension NewAccountCompletion { } self.isFirstOnNetwork = state.isFirstOnNetwork - self.accountAddress = state.account.address self.appearanceID = state.account.appearanceID self.explanation = L10n.CreateAccount.Completion.explanation diff --git a/RadixWallet/Features/HomeFeature/Children/AccountRow/Home+AccountRow+View.swift b/RadixWallet/Features/HomeFeature/Children/AccountRow/Home+AccountRow+View.swift index 70b245eda9..059678d207 100644 --- a/RadixWallet/Features/HomeFeature/Children/AccountRow/Home+AccountRow+View.swift +++ b/RadixWallet/Features/HomeFeature/Children/AccountRow/Home+AccountRow+View.swift @@ -113,7 +113,7 @@ extension Home.AccountRow { } HStack { - AddressView(.address(.account(viewStore.address, isLedgerHWAccount: viewStore.isLedgerAccount))) + AddressView(.address(.account(viewStore.address))) .foregroundColor(.app.whiteTransparent) .textStyle(.body2HighImportance)