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

Commit

Permalink
Fix #7785: User assets are not migrated if user restore wallet from l…
Browse files Browse the repository at this point in the history
…ock screen (#7793)
  • Loading branch information
nuo-xu authored Jul 28, 2023
1 parent 6688d4a commit 8a4e183
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Sources/BraveWallet/Crypto/Stores/CryptoStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public class CryptoStore: ObservableObject {
private let solTxManagerProxy: BraveWalletSolanaTxManagerProxy
private let ipfsApi: IpfsAPI
private let userAssetManager: WalletUserAssetManager
private var isUpdatingUserAssets: Bool = false

public init(
keyringService: BraveWalletKeyringService,
Expand Down Expand Up @@ -561,11 +562,19 @@ extension CryptoStore: BraveWalletKeyringServiceObserver {
}
}
public func keyringRestored(_ keyringId: BraveWallet.KeyringId) {
// if a keyring is restored, we want to reset user assets local storage
// and migrate with for new keyring
// This observer method will only get called when user restore a wallet
// from the lock screen
// We will need to
// 1. reset wallet user asset migration flag
// 2. wipe user assets local storage
// 3. migrate user assets with new keyring
guard !isUpdatingUserAssets else { return }
isUpdatingUserAssets = true
Preferences.Wallet.migrateCoreToWalletUserAssetCompleted.reset()
WalletUserAssetGroup.removeAllGroup() { [weak self] in
self?.userAssetManager.migrateUserAssets(completion: {
self?.updateAssets()
self?.isUpdatingUserAssets = false
})
}
}
Expand Down
1 change: 1 addition & 0 deletions Sources/BraveWallet/WalletUserAssetManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public class WalletUserAssetManager: WalletUserAssetManagerType {

public func migrateUserAssets(for coin: BraveWallet.CoinType? = nil, completion: (() -> Void)? = nil) {
guard !Preferences.Wallet.migrateCoreToWalletUserAssetCompleted.value else {
completion?()
return
}
Task { @MainActor in
Expand Down

0 comments on commit 8a4e183

Please sign in to comment.