Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #6652: Asset auto-discovery on wallet open (#6751)
Browse files Browse the repository at this point in the history
Call `discoverAssetsOnAllSupportedChains` when Wallet is opened. Show loading state beside Assets in Section title.
  • Loading branch information
StephenHeaps authored Jan 16, 2023
1 parent 902f49f commit fb96c48
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/BraveWallet/Crypto/CryptoPagesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct CryptoPagesView: View {
// Give the animation time
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.fetchedPendingRequestsThisSession = true
self.cryptoStore.prepare()
self.cryptoStore.prepare(isInitialOpen: true)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/BraveWallet/Crypto/Portfolio/PortfolioView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ struct PortfolioView: View {
}, header: {
HStack {
Text(Strings.Wallet.assetsTitle)
if portfolioStore.isLoadingDiscoverAssets {
ProgressView()
.padding(.leading, 5)
}
Spacer()
networkFilterButton
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/BraveWallet/Crypto/Stores/CryptoStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,11 @@ public class CryptoStore: ObservableObject {
}
}

func prepare() {
func prepare(isInitialOpen: Bool = false) {
Task { @MainActor in
if isInitialOpen {
portfolioStore.discoverAssetsOnAllSupportedChains()
}
let pendingTransactions = await fetchPendingTransactions()
if !pendingTransactions.isEmpty {
if self.buySendSwapDestination != nil {
Expand Down
10 changes: 10 additions & 0 deletions Sources/BraveWallet/Crypto/Stores/PortfolioStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public class PortfolioStore: ObservableObject {
update()
}
}
@Published private(set) var isLoadingDiscoverAssets: Bool = false

public private(set) lazy var userAssetsStore: UserAssetsStore = .init(
walletService: self.walletService,
Expand Down Expand Up @@ -147,6 +148,11 @@ public class PortfolioStore: ObservableObject {
}
}

func discoverAssetsOnAllSupportedChains() {
isLoadingDiscoverAssets = true
walletService.discoverAssetsOnAllSupportedChains()
}

func update() {
self.updateTask?.cancel()
self.updateTask = Task { @MainActor in
Expand Down Expand Up @@ -419,5 +425,9 @@ extension PortfolioStore: BraveWalletBraveWalletServiceObserver {
}

public func onDiscoverAssetsCompleted(_ discoveredAssets: [BraveWallet.BlockchainToken]) {
isLoadingDiscoverAssets = false
if !discoveredAssets.isEmpty {
update()
}
}
}

0 comments on commit fb96c48

Please sign in to comment.