Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ABW-3634] Fix bug where Account Details wouldn't show Verify Address on Ledger #1229

Merged
merged 5 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
22 changes: 20 additions & 2 deletions RadixWallet/Core/FeaturePrelude/AddressView/AddressDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,6 +32,7 @@ public struct AddressDetails: Sendable, FeatureReducer {
public enum InternalAction: Sendable, Equatable {
case loadedTitle(TaskResult<String?>)
case loadedQrImage(TaskResult<CGImage>)
case loadedShowVerifyOnLedger(Bool)
}

@Dependency(\.accountsClient) var accountsClient
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
}
}

Expand All @@ -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
Expand Down Expand Up @@ -141,6 +147,18 @@ public struct AddressDetails: Sendable, FeatureReducer {
await send(.internal(.loadedQrImage(result)))
}
}

private func loadShowVerifyOnLedgerEffect(state: State) -> Effect<Action> {
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
Expand Down
10 changes: 5 additions & 5 deletions RadixWallet/Core/SharedModels/LedgerIdentifiable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ extension AccountDetails {

@ViewBuilder
func header(with viewStore: ViewStore<AccountDetails.ViewState, AccountDetails.ViewAction>) -> some SwiftUI.View {
AddressView(.address(.account(viewStore.accountAddress, isLedgerHWAccount: viewStore.isLedgerAccount)))
AddressView(.address(.account(viewStore.accountAddress)))
.foregroundColor(.app.whiteTransparent)
.textStyle(.body2HighImportance)
.padding(.bottom, .small1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading