Skip to content

Commit

Permalink
Fix brave/brave-ios#8023: Incorrect asset detail opened from search (b…
Browse files Browse the repository at this point in the history
…rave/brave-ios#8024)

* Use correct token identifier for `AssetDetailType` id.

* Don't re-initialize `AssetDetailStore` for each `SearchAssetView`.
  • Loading branch information
StephenHeaps authored Sep 5, 2023
1 parent e97da0d commit 71756cd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
64 changes: 39 additions & 25 deletions Sources/BraveWallet/Crypto/Search/AssetSearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct AssetSearchView: View {
@State private var query = ""
@State private var networkFilters: [Selectable<BraveWallet.NetworkInfo>] = []
@State private var isPresentingNetworkFilter = false
@State private var selectedToken: BraveWallet.BlockchainToken?

public init(
keyringStore: KeyringStore,
Expand Down Expand Up @@ -96,31 +97,7 @@ struct AssetSearchView: View {
.frame(maxWidth: .infinity)
} else {
ForEach(filteredTokens) { assetViewModel in

NavigationLink(
destination: {
if assetViewModel.token.isErc721 {
NFTDetailView(
nftDetailStore: cryptoStore.nftDetailStore(for: assetViewModel.token, nftMetadata: allNFTMetadata[assetViewModel.token.id]),
buySendSwapDestination: .constant(nil)
) { metadata in
allNFTMetadata[assetViewModel.token.id] = metadata
}
.onDisappear {
cryptoStore.closeNFTDetailStore(for: assetViewModel.token)
}
} else {
AssetDetailView(
assetDetailStore: cryptoStore.assetDetailStore(for: .blockchainToken(assetViewModel.token)),
keyringStore: keyringStore,
networkStore: cryptoStore.networkStore
)
.onDisappear {
cryptoStore.closeAssetDetailStore(for: .blockchainToken(assetViewModel.token))
}
}
}
) {
Button(action: { selectedToken = assetViewModel.token }) {
SearchAssetView(
title: title(for: assetViewModel.token),
symbol: assetViewModel.token.symbol,
Expand Down Expand Up @@ -150,6 +127,40 @@ struct AssetSearchView: View {
}
.listStyle(.insetGrouped)
.listBackgroundColor(Color(UIColor.braveGroupedBackground))
.background(
NavigationLink(
isActive: Binding(
get: { selectedToken != nil },
set: { if !$0 { selectedToken = nil } }
),
destination: {
if let selectedToken {
if selectedToken.isErc721 {
NFTDetailView(
nftDetailStore: cryptoStore.nftDetailStore(for: selectedToken, nftMetadata: allNFTMetadata[selectedToken.id]),
buySendSwapDestination: .constant(nil)
) { metadata in
allNFTMetadata[selectedToken.id] = metadata
}
.onDisappear {
cryptoStore.closeNFTDetailStore(for: selectedToken)
}
} else {
AssetDetailView(
assetDetailStore: cryptoStore.assetDetailStore(for: .blockchainToken(selectedToken)),
keyringStore: keyringStore,
networkStore: cryptoStore.networkStore
)
.onDisappear {
cryptoStore.closeAssetDetailStore(for: .blockchainToken(selectedToken))
}
}
}
},
label: {
EmptyView()
})
)
.navigationTitle(Strings.Wallet.searchTitle.capitalized)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
Expand Down Expand Up @@ -230,6 +241,9 @@ struct SearchAssetView<ImageView: View>: View {
.foregroundColor(Color(.braveLabel))
}
Spacer()
Image(systemName: "chevron.right")
.font(.body.weight(.semibold))
.foregroundColor(Color(.separator))
}
.frame(maxWidth: .infinity)
.padding(.vertical, 6)
Expand Down
2 changes: 1 addition & 1 deletion Sources/BraveWallet/Crypto/Stores/AssetDetailStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ enum AssetDetailType: Identifiable {
var id: String {
switch self {
case .blockchainToken(let token):
return token.tokenId
return token.id
case .coinMarket(let coinMarket):
return coinMarket.id
}
Expand Down

0 comments on commit 71756cd

Please sign in to comment.