From 584e115c276a0231ea28c09acf0e840fd88bc417 Mon Sep 17 00:00:00 2001 From: StephenHeaps <5314553+StephenHeaps@users.noreply.github.com> Date: Thu, 12 Oct 2023 15:25:34 -0400 Subject: [PATCH] [v1.60] Fix #8182: KeyringInfo Refactor, Bump BraveCore to v1.60.81 (#8197) * Address changes for removing `accountInfos` array from `KeyringInfo`. * Update BraveCore to v1.60.81 --- .../BrowserViewController+Wallet.swift | 2 +- .../Activity/AccountActivityView.swift | 3 +- .../Crypto/Accounts/Add/AddAccountView.swift | 9 +-- .../Accounts/Details/AccountDetailsView.swift | 2 +- .../Crypto/Stores/AccountActivityStore.swift | 6 +- .../Crypto/Stores/AssetDetailStore.swift | 22 +++---- .../Crypto/Stores/BuyTokenStore.swift | 2 +- .../Crypto/Stores/CryptoStore.swift | 6 +- .../Crypto/Stores/KeyringStore.swift | 34 ++++------- .../BraveWallet/Crypto/Stores/NFTStore.swift | 2 +- .../Crypto/Stores/NetworkStore.swift | 10 ++-- .../Crypto/Stores/PortfolioStore.swift | 2 +- .../Stores/SelectAccountTokenStore.swift | 39 ++++++------- .../Crypto/Stores/SendTokenStore.swift | 2 +- .../Crypto/Stores/SettingsStore.swift | 2 +- .../Crypto/Stores/SwapTokenStore.swift | 2 +- .../Stores/TransactionConfirmationStore.swift | 25 ++++---- .../Stores/TransactionDetailsStore.swift | 5 +- .../Stores/TransactionsActivityStore.swift | 10 ++-- .../Crypto/Stores/UserAssetsStore.swift | 2 +- .../Extensions/BraveWalletExtensions.swift | 17 +++++- .../Extensions/KeyringServiceExtensions.swift | 11 ++-- .../WalletTxServiceExtensions.swift | 21 +++---- .../Connect/EditSiteConnectionView.swift | 2 +- .../Connect/NewSiteConnectionView.swift | 6 +- .../Preview Content/MockKeyringService.swift | 58 ++++++++++++------- .../AccountActivityStoreTests.swift | 3 + .../AssetDetailStoreTests.swift | 13 ++--- .../NetworkSelectionStoreTests.swift | 18 +----- .../BraveWalletTests/NetworkStoreTests.swift | 6 +- .../PortfolioStoreTests.swift | 46 +++------------ .../SelectAccountTokenStoreTests.swift | 20 +++++-- .../BraveWalletTests/SettingsStoreTests.swift | 5 +- .../TransactionConfirmationStoreTests.swift | 19 +++--- .../TransactionsActivityStoreTests.swift | 3 + package-lock.json | 12 ++-- package.json | 2 +- 37 files changed, 216 insertions(+), 233 deletions(-) diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Wallet.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Wallet.swift index dc014bdd827..4e5de27fec7 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Wallet.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Wallet.swift @@ -582,7 +582,7 @@ extension Tab: BraveWalletKeyringServiceObserver { func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - func keyringRestored(_ keyringId: BraveWallet.KeyringId) { + func walletRestored() { } func keyringReset() { diff --git a/Sources/BraveWallet/Crypto/Accounts/Activity/AccountActivityView.swift b/Sources/BraveWallet/Crypto/Accounts/Activity/AccountActivityView.swift index da81f2c0a36..3317dc704e3 100644 --- a/Sources/BraveWallet/Crypto/Accounts/Activity/AccountActivityView.swift +++ b/Sources/BraveWallet/Crypto/Accounts/Activity/AccountActivityView.swift @@ -164,8 +164,7 @@ struct AccountActivityView: View { } } ) - .onReceive(keyringStore.$allKeyrings) { allKeyrings in - let allAccounts = allKeyrings.flatMap(\.accountInfos) + .onReceive(keyringStore.$allAccounts) { allAccounts in if !allAccounts.contains(where: { $0.address == accountInfo.address }) { // Account was deleted detailsPresentation = nil diff --git a/Sources/BraveWallet/Crypto/Accounts/Add/AddAccountView.swift b/Sources/BraveWallet/Crypto/Accounts/Add/AddAccountView.swift index 212125d50b1..fa152b5d355 100644 --- a/Sources/BraveWallet/Crypto/Accounts/Add/AddAccountView.swift +++ b/Sources/BraveWallet/Crypto/Accounts/Add/AddAccountView.swift @@ -348,12 +348,13 @@ struct AddAccountView: View { } private func defaultAccountName(for coin: BraveWallet.CoinType, chainId: String, isPrimary: Bool) -> String { - let keyringId = BraveWallet.KeyringId.keyringId(for: coin, on: chainId) - let keyringInfo = keyringStore.allKeyrings.first { $0.id == keyringId } + let accountsForCoin = keyringStore.allAccounts.filter { $0.coin == coin } if isPrimary { - return String.localizedStringWithFormat(coin.defaultAccountName, (keyringInfo?.accountInfos.filter(\.isPrimary).count ?? 0) + 1) + let numberOfPrimaryAccountsForCoin = accountsForCoin.filter(\.isPrimary).count + return String.localizedStringWithFormat(coin.defaultAccountName, numberOfPrimaryAccountsForCoin + 1) } else { - return String.localizedStringWithFormat(coin.defaultSecondaryAccountName, (keyringInfo?.accountInfos.filter(\.isImported).count ?? 0) + 1) + let numberOfImportedAccounts = accountsForCoin.filter(\.isImported).count + return String.localizedStringWithFormat(coin.defaultSecondaryAccountName, numberOfImportedAccounts + 1) } } } diff --git a/Sources/BraveWallet/Crypto/Accounts/Details/AccountDetailsView.swift b/Sources/BraveWallet/Crypto/Accounts/Details/AccountDetailsView.swift index b8bdf607789..966d5fc6ae5 100644 --- a/Sources/BraveWallet/Crypto/Accounts/Details/AccountDetailsView.swift +++ b/Sources/BraveWallet/Crypto/Accounts/Details/AccountDetailsView.swift @@ -185,7 +185,7 @@ struct AccountDetailsView_Previews: PreviewProvider { static var previews: some View { AccountDetailsView( keyringStore: .previewStoreWithWalletCreated, - account: KeyringStore.previewStoreWithWalletCreated.defaultKeyring.accountInfos.first!, + account: KeyringStore.previewStoreWithWalletCreated.allAccounts.first!, editMode: false ) .previewColorSchemes() diff --git a/Sources/BraveWallet/Crypto/Stores/AccountActivityStore.swift b/Sources/BraveWallet/Crypto/Stores/AccountActivityStore.swift index 8369fa7574a..2538a004403 100644 --- a/Sources/BraveWallet/Crypto/Stores/AccountActivityStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/AccountActivityStore.swift @@ -118,7 +118,6 @@ class AccountActivityStore: ObservableObject { self.userVisibleAssets = updatedUserVisibleAssets self.userVisibleNFTs = updatedUserVisibleNFTs - let keyringForAccount = await keyringService.keyringInfo(account.keyringId) typealias TokenNetworkAccounts = (token: BraveWallet.BlockchainToken, network: BraveWallet.NetworkInfo, accounts: [BraveWallet.AccountInfo]) let allTokenNetworkAccounts = allVisibleUserAssets.flatMap { networkAssets in networkAssets.tokens.map { token in @@ -199,9 +198,10 @@ class AccountActivityStore: ObservableObject { $0[$1.token.assetRatioId.lowercased()] = Double($1.price) }) + let allAccountsForCoin = await keyringService.allAccounts().accounts.filter { $0.coin == account.coin } self.transactionSummaries = await fetchTransactionSummarys( networksForAccountCoin: networksForAccountCoin, - accountInfos: keyringForAccount.accountInfos, + accountInfos: allAccountsForCoin, userVisibleTokens: userVisibleAssets.map(\.token), allTokens: allTokens, assetRatios: assetRatios @@ -278,7 +278,7 @@ extension AccountActivityStore: BraveWalletKeyringServiceObserver { func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - func keyringRestored(_ keyringId: BraveWallet.KeyringId) { + func walletRestored() { } func keyringReset() { diff --git a/Sources/BraveWallet/Crypto/Stores/AssetDetailStore.swift b/Sources/BraveWallet/Crypto/Stores/AssetDetailStore.swift index 36d08dcb514..64b1b7da0cb 100644 --- a/Sources/BraveWallet/Crypto/Stores/AssetDetailStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/AssetDetailStore.swift @@ -158,9 +158,8 @@ class AssetDetailStore: ObservableObject { self.isSwapSupported = await swapService.isSwapSupported(token.chainId) // fetch accounts - let keyringId = BraveWallet.KeyringId.keyringId(for: token.coin, on: token.chainId) - let keyring = await keyringService.keyringInfo(keyringId) - var updatedAccounts = keyring.accountInfos.map { + let allAccountsForTokenCoin = await keyringService.allAccounts().accounts.filter { $0.coin == token.coin } + var updatedAccounts = allAccountsForTokenCoin.map { AccountAssetViewModel(account: $0, decimalBalance: 0.0, balance: "", fiatBalance: "") } @@ -187,9 +186,13 @@ class AssetDetailStore: ObservableObject { } } - self.accounts = await fetchAccountBalances(updatedAccounts, keyring: keyring, network: network) + self.accounts = await fetchAccountBalances(updatedAccounts, network: network) let assetRatios = [token.assetRatioId.lowercased(): assetPriceValue] - self.transactionSummaries = await fetchTransactionSummarys(keyring: keyring, network: network, assetRatios: assetRatios) + self.transactionSummaries = await fetchTransactionSummarys( + accounts: allAccountsForTokenCoin, + network: network, + assetRatios: assetRatios + ) case .coinMarket(let coinMarket): // comes from Market tab self.price = self.currencyFormatter.string(from: NSNumber(value: coinMarket.currentPrice)) ?? "" @@ -244,7 +247,6 @@ class AssetDetailStore: ObservableObject { @MainActor private func fetchAccountBalances( _ accountAssetViewModels: [AccountAssetViewModel], - keyring: BraveWallet.KeyringInfo, network: BraveWallet.NetworkInfo ) async -> [AccountAssetViewModel] { guard case let .blockchainToken(token) = assetDetailType @@ -278,7 +280,7 @@ class AssetDetailStore: ObservableObject { } @MainActor private func fetchTransactionSummarys( - keyring: BraveWallet.KeyringInfo, + accounts: [BraveWallet.AccountInfo], network: BraveWallet.NetworkInfo, assetRatios: [String: Double] ) async -> [TransactionSummary] { @@ -287,7 +289,7 @@ class AssetDetailStore: ObservableObject { let userVisibleAssets = assetManager.getAllUserAssetsInNetworkAssets(networks: [network]).flatMap { $0.tokens } let allTokens = await blockchainRegistry.allTokens(network.chainId, coin: network.coin) let allTransactions = await withTaskGroup(of: [BraveWallet.TransactionInfo].self) { @MainActor group -> [BraveWallet.TransactionInfo] in - for account in keyring.accountInfos { + for account in accounts { group.addTask { @MainActor in await self.txService.allTransactionInfo( network.coin, @@ -337,7 +339,7 @@ class AssetDetailStore: ObservableObject { TransactionParser.transactionSummary( from: transaction, network: network, - accountInfos: keyring.accountInfos, + accountInfos: accounts, visibleTokens: userVisibleAssets, allTokens: allTokens, assetRatios: assetRatios, @@ -382,7 +384,7 @@ extension AssetDetailStore: BraveWalletKeyringServiceObserver { func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - func keyringRestored(_ keyringId: BraveWallet.KeyringId) { + func walletRestored() { } func locked() { diff --git a/Sources/BraveWallet/Crypto/Stores/BuyTokenStore.swift b/Sources/BraveWallet/Crypto/Stores/BuyTokenStore.swift index 6bb8ffa0ddc..e8701be9a1b 100644 --- a/Sources/BraveWallet/Crypto/Stores/BuyTokenStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/BuyTokenStore.swift @@ -244,7 +244,7 @@ extension BuyTokenStore: BraveWalletKeyringServiceObserver { public func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - public func keyringRestored(_ keyringId: BraveWallet.KeyringId) { + public func walletRestored() { } public func keyringReset() { diff --git a/Sources/BraveWallet/Crypto/Stores/CryptoStore.swift b/Sources/BraveWallet/Crypto/Stores/CryptoStore.swift index 2e96a3707ac..3360a4c2d35 100644 --- a/Sources/BraveWallet/Crypto/Stores/CryptoStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/CryptoStore.swift @@ -423,13 +423,13 @@ public class CryptoStore: ObservableObject { @MainActor func fetchPendingTransactions() async -> [BraveWallet.TransactionInfo] { - let allKeyrings = await keyringService.keyrings(for: WalletConstants.supportedCoinTypes()) + let allAccounts = await keyringService.allAccounts().accounts var allNetworksForCoin: [BraveWallet.CoinType: [BraveWallet.NetworkInfo]] = [:] for coin in WalletConstants.supportedCoinTypes() { let allNetworks = await rpcService.allNetworks(coin) allNetworksForCoin[coin] = allNetworks } - return await txService.pendingTransactions(networksForCoin: allNetworksForCoin, for: allKeyrings) + return await txService.pendingTransactions(networksForCoin: allNetworksForCoin, for: allAccounts) } @MainActor @@ -583,7 +583,7 @@ extension CryptoStore: BraveWalletKeyringServiceObserver { // when user creates or imports a new account with a new keyring since any new // supported coin type / keyring will be migrated inside `CryptoStore`'s init() } - public func keyringRestored(_ keyringId: BraveWallet.KeyringId) { + public func walletRestored() { // This observer method will only get called when user restore a wallet // from the lock screen // We will need to diff --git a/Sources/BraveWallet/Crypto/Stores/KeyringStore.swift b/Sources/BraveWallet/Crypto/Stores/KeyringStore.swift index d7badf73f87..035b7973bf2 100644 --- a/Sources/BraveWallet/Crypto/Stores/KeyringStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/KeyringStore.swift @@ -119,8 +119,7 @@ public class KeyringStore: ObservableObject { id: .default, isKeyringCreated: false, isLocked: true, - isBackedUp: false, - accountInfos: [] + isBackedUp: false ) /// A boolean indciates front-end has or has not loaded Keyring from the core @Published var isDefaultKeyringLoaded = false @@ -154,9 +153,7 @@ public class KeyringStore: ObservableObject { /// keyring has been created @Published var isDefaultKeyringCreated: Bool = false /// All `AccountInfo` for all available keyrings - var allAccounts: [BraveWallet.AccountInfo] { - allKeyrings.flatMap(\.accountInfos) - } + @Published var allAccounts: [BraveWallet.AccountInfo] = [] /// A list of default account with all support coin types @Published var defaultAccounts: [BraveWallet.AccountInfo] = [] @@ -220,8 +217,7 @@ public class KeyringStore: ObservableObject { return } Task { @MainActor in // fetch all KeyringInfo for all coin types - let selectedAccount = await keyringService.allAccounts().selectedAccount - let selectedAccountAddress = selectedAccount?.address + let allAccounts = await keyringService.allAccounts() let allKeyrings = await keyringService.keyrings(for: WalletConstants.supportedCoinTypes()) if let defaultKeyring = allKeyrings.first(where: { $0.id == BraveWallet.KeyringId.default }) { self.defaultKeyring = defaultKeyring @@ -229,16 +225,10 @@ public class KeyringStore: ObservableObject { self.isDefaultKeyringCreated = defaultKeyring.isKeyringCreated } self.allKeyrings = allKeyrings - if let selectedAccountKeyring = allKeyrings.first(where: { $0.id == selectedAccount?.keyringId }) { - if self.selectedAccount.address != selectedAccountAddress { - if let selectedAccount = selectedAccountKeyring.accountInfos.first(where: { $0.address == selectedAccountAddress }) { - self.selectedAccount = selectedAccount - } else if let firstAccount = selectedAccountKeyring.accountInfos.first { - // try and correct invalid state (no selected account for this coin type) - self.selectedAccount = firstAccount - } // else selected account address does not exist in keyring (should not occur...) - } // else `self.selectedAccount` is already the currently selected account - } // else keyring for selected coin is unavailable (should not occur...) + self.allAccounts = allAccounts.accounts + if let selectedAccount = allAccounts.selectedAccount { + self.selectedAccount = selectedAccount + } } } @@ -514,18 +504,18 @@ extension KeyringStore: BraveWalletKeyringServiceObserver { } Task { @MainActor in - let newKeyring = await keyringService.keyringInfo(keyringId) - let selectedAccount = await keyringService.allAccounts().selectedAccount + let allAccounts = await keyringService.allAccounts() + let allAccountsForKeyring = allAccounts.accounts.filter { $0.keyringId == keyringId } // if the new Keyring doesn't have a selected account, select the first account - if selectedAccount == nil, let newAccount = newKeyring.accountInfos.first { + if allAccounts.selectedAccount == nil, let newAccount = allAccountsForKeyring.first { await keyringService.setSelectedAccount(newAccount.accountId) } updateKeyringInfo() } } - public func keyringRestored(_ keyringId: BraveWallet.KeyringId) { - if isOnboardingVisible && !isRestoringWallet, keyringId == BraveWallet.KeyringId.default { + public func walletRestored() { + if isOnboardingVisible && !isRestoringWallet { // Another window has restored a wallet. We should dismiss onboarding on this // window and allow the other window to continue with it's onboarding flow. isOnboardingVisible = false diff --git a/Sources/BraveWallet/Crypto/Stores/NFTStore.swift b/Sources/BraveWallet/Crypto/Stores/NFTStore.swift index baee7d745d1..d3bcc267972 100644 --- a/Sources/BraveWallet/Crypto/Stores/NFTStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/NFTStore.swift @@ -254,7 +254,7 @@ extension NFTStore: BraveWalletKeyringServiceObserver { } public func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - public func keyringRestored(_ keyringId: BraveWallet.KeyringId) { + public func walletRestored() { } public func locked() { } diff --git a/Sources/BraveWallet/Crypto/Stores/NetworkStore.swift b/Sources/BraveWallet/Crypto/Stores/NetworkStore.swift index b58dd699446..e90d5097dc7 100644 --- a/Sources/BraveWallet/Crypto/Stores/NetworkStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/NetworkStore.swift @@ -109,9 +109,9 @@ public class NetworkStore: ObservableObject { _ network: BraveWallet.NetworkInfo, isForOrigin: Bool ) async -> SetSelectedChainError? { - let keyringId = BraveWallet.KeyringId.keyringId(for: network.coin, on: network.chainId) - let keyringInfo = await keyringService.keyringInfo(keyringId) - if keyringInfo.accountInfos.isEmpty { + let allAccounts = await keyringService.allAccounts() + let allAccountsForNetworkCoin = allAccounts.accounts.filter { $0.coin == network.coin } + if allAccountsForNetworkCoin.isEmpty { // Need to prompt user to create new account via alert return .selectedChainHasNoAccounts } else { @@ -121,7 +121,7 @@ public class NetworkStore: ObservableObject { self.defaultSelectedChainId = network.chainId } - let currentlySelectedCoin = await keyringService.allAccounts().selectedAccount?.coin ?? .eth + let currentlySelectedCoin = allAccounts.selectedAccount?.coin ?? .eth let rpcServiceNetwork = await rpcService.network(currentlySelectedCoin, origin: isForOrigin ? origin : nil) guard rpcServiceNetwork.chainId != network.chainId else { if !isForOrigin { // `isSwapSupported` is for the `defaultSelectedChain` @@ -332,7 +332,7 @@ extension NetworkStore: BraveWalletKeyringServiceObserver { public func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - public func keyringRestored(_ keyringId: BraveWallet.KeyringId) { + public func walletRestored() { } public func keyringReset() { diff --git a/Sources/BraveWallet/Crypto/Stores/PortfolioStore.swift b/Sources/BraveWallet/Crypto/Stores/PortfolioStore.swift index 85a41f192d7..5c2edb9ec0c 100644 --- a/Sources/BraveWallet/Crypto/Stores/PortfolioStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/PortfolioStore.swift @@ -658,7 +658,7 @@ extension PortfolioStore: BraveWalletKeyringServiceObserver { } public func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - public func keyringRestored(_ keyringId: BraveWallet.KeyringId) { + public func walletRestored() { } public func locked() { } diff --git a/Sources/BraveWallet/Crypto/Stores/SelectAccountTokenStore.swift b/Sources/BraveWallet/Crypto/Stores/SelectAccountTokenStore.swift index ef92e8514cc..f49aeb5c211 100644 --- a/Sources/BraveWallet/Crypto/Stores/SelectAccountTokenStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/SelectAccountTokenStore.swift @@ -143,7 +143,7 @@ class SelectAccountTokenStore: ObservableObject { } @MainActor func update() async { - let allKeyrings = await keyringService.keyrings(for: WalletConstants.supportedCoinTypes()) + let allAccounts = await keyringService.allAccounts() let allNetworks = await rpcService.allNetworksForSupportedCoins() self.allNetworks = allNetworks // setup network filters if not currently setup @@ -154,27 +154,26 @@ class SelectAccountTokenStore: ObservableObject { } let allVisibleUserAssets = assetManager.getAllVisibleAssetsInNetworkAssets(networks: allNetworks).flatMap { $0.tokens } guard !Task.isCancelled else { return } - self.accountSections = allKeyrings.flatMap { keyring in - let tokensForCoin = allVisibleUserAssets.filter { $0.coin == keyring.coin } - return keyring.accountInfos.map { account in - let tokenBalances = tokensForCoin.compactMap { token in - let tokenNetwork = allNetworks.first(where: { $0.chainId == token.chainId }) ?? .init() - if tokenNetwork.supportedKeyrings.contains(keyring.id.rawValue as NSNumber) { - return AccountSection.TokenBalance( - token: token, - network: allNetworks.first(where: { $0.chainId == token.chainId }) ?? .init(), - balance: cachedBalance(for: token, in: account), - price: cachedPrice(for: token, in: account), - nftMetadata: cachedMetadata(for: token) - ) - } - return nil + let tokensGroupedByCoinType = Dictionary(grouping: allVisibleUserAssets, by: \.coin) + self.accountSections = allAccounts.accounts.map { account in + let tokensForAccountCoin = tokensGroupedByCoinType[account.coin] ?? [] + let tokenBalances = tokensForAccountCoin.compactMap { token in + let tokenNetwork = allNetworks.first(where: { $0.chainId == token.chainId }) ?? .init() + if tokenNetwork.supportedKeyrings.contains(account.keyringId.rawValue as NSNumber) { + return AccountSection.TokenBalance( + token: token, + network: allNetworks.first(where: { $0.chainId == token.chainId }) ?? .init(), + balance: cachedBalance(for: token, in: account), + price: cachedPrice(for: token, in: account), + nftMetadata: cachedMetadata(for: token) + ) } - return AccountSection( - account: account, - tokenBalances: tokenBalances - ) + return nil } + return AccountSection( + account: account, + tokenBalances: tokenBalances + ) } updateAccountBalances() diff --git a/Sources/BraveWallet/Crypto/Stores/SendTokenStore.swift b/Sources/BraveWallet/Crypto/Stores/SendTokenStore.swift index ba089e8917a..6dd10268b7a 100644 --- a/Sources/BraveWallet/Crypto/Stores/SendTokenStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/SendTokenStore.swift @@ -664,7 +664,7 @@ extension SendTokenStore: BraveWalletKeyringServiceObserver { public func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - public func keyringRestored(_ keyringId: BraveWallet.KeyringId) { + public func walletRestored() { } public func locked() { diff --git a/Sources/BraveWallet/Crypto/Stores/SettingsStore.swift b/Sources/BraveWallet/Crypto/Stores/SettingsStore.swift index e72736d8e4c..d3ed97c2c82 100644 --- a/Sources/BraveWallet/Crypto/Stores/SettingsStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/SettingsStore.swift @@ -170,7 +170,7 @@ extension SettingsStore: BraveWalletKeyringServiceObserver { public func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - public func keyringRestored(_ keyringId: BraveWallet.KeyringId) { + public func walletRestored() { } public func keyringReset() { diff --git a/Sources/BraveWallet/Crypto/Stores/SwapTokenStore.swift b/Sources/BraveWallet/Crypto/Stores/SwapTokenStore.swift index dc3ac55850a..47a38d22288 100644 --- a/Sources/BraveWallet/Crypto/Stores/SwapTokenStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/SwapTokenStore.swift @@ -890,7 +890,7 @@ extension SwapTokenStore: BraveWalletKeyringServiceObserver { public func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - public func keyringRestored(_ keyringId: BraveWallet.KeyringId) { + public func walletRestored() { } public func locked() { diff --git a/Sources/BraveWallet/Crypto/Stores/TransactionConfirmationStore.swift b/Sources/BraveWallet/Crypto/Stores/TransactionConfirmationStore.swift index f891eb4a27b..360ede6c791 100644 --- a/Sources/BraveWallet/Crypto/Stores/TransactionConfirmationStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/TransactionConfirmationStore.swift @@ -224,8 +224,7 @@ public class TransactionConfirmationStore: ObservableObject { clearTrasactionInfoBeforeUpdate() let coin = transaction.coin - let keyringId = BraveWallet.KeyringId.keyringId(for: transaction.coin, on: transaction.chainId) - let keyring = await keyringService.keyringInfo(keyringId) + let allAccountsForCoin = await keyringService.allAccounts().accounts.filter { $0.coin == coin } if !allNetworks.contains(where: { $0.chainId == transaction.chainId }) { allNetworks = await rpcService.allNetworksForSupportedCoins() } @@ -247,7 +246,7 @@ public class TransactionConfirmationStore: ObservableObject { guard let parsedTransaction = transaction.parsedTransaction( network: network, - accountInfos: keyring.accountInfos, + accountInfos: allAccountsForCoin, visibleTokens: userVisibleTokens, allTokens: allTokens, assetRatios: assetRatios, @@ -259,7 +258,7 @@ public class TransactionConfirmationStore: ObservableObject { activeParsedTransaction = parsedTransaction await fetchActiveTransactionDetails( - keyring: keyring, + accounts: allAccountsForCoin, network: network, allTokens: allTokens, shouldFetchCurrentAllowance: shouldFetchCurrentAllowance, @@ -389,7 +388,7 @@ public class TransactionConfirmationStore: ObservableObject { } @MainActor func fetchActiveTransactionDetails( - keyring: BraveWallet.KeyringInfo, + accounts: [BraveWallet.AccountInfo], network: BraveWallet.NetworkInfo, allTokens: [BraveWallet.BlockchainToken], shouldFetchCurrentAllowance: Bool, @@ -424,7 +423,7 @@ public class TransactionConfirmationStore: ObservableObject { isBalanceSufficient = false } } else if shouldFetchGasTokenBalance { - if let account = keyring.accountInfos.first(where: { $0.address == activeParsedTransaction.fromAddress }) { + if let account = accounts.first(where: { $0.address == activeParsedTransaction.fromAddress }) { await fetchGasTokenBalance(token: network.nativeToken, account: account, network: network) } } @@ -453,7 +452,7 @@ public class TransactionConfirmationStore: ObservableObject { isBalanceSufficient = false } } else if shouldFetchGasTokenBalance { - if let account = keyring.accountInfos.first(where: { $0.address == activeParsedTransaction.fromAddress }) { + if let account = accounts.first(where: { $0.address == activeParsedTransaction.fromAddress }) { await fetchGasTokenBalance(token: network.nativeToken, account: account, network: network) } } @@ -486,7 +485,7 @@ public class TransactionConfirmationStore: ObservableObject { isBalanceSufficient = false } } else if shouldFetchGasTokenBalance { - if let account = keyring.accountInfos.first(where: { $0.address == activeParsedTransaction.fromAddress }) { + if let account = accounts.first(where: { $0.address == activeParsedTransaction.fromAddress }) { await fetchGasTokenBalance(token: network.nativeToken, account: account, network: network) } } @@ -511,7 +510,7 @@ public class TransactionConfirmationStore: ObservableObject { isBalanceSufficient = false } } else if shouldFetchGasTokenBalance { - if let account = keyring.accountInfos.first(where: { $0.address == activeParsedTransaction.fromAddress }) { + if let account = accounts.first(where: { $0.address == activeParsedTransaction.fromAddress }) { await fetchGasTokenBalance(token: network.nativeToken, account: account, network: network) } } @@ -539,7 +538,7 @@ public class TransactionConfirmationStore: ObservableObject { isBalanceSufficient = false } } else if shouldFetchGasTokenBalance { - if let account = keyring.accountInfos.first(where: { $0.address == activeParsedTransaction.fromAddress }) { + if let account = accounts.first(where: { $0.address == activeParsedTransaction.fromAddress }) { await fetchGasTokenBalance(token: network.nativeToken, account: account, network: network) } } @@ -567,7 +566,7 @@ public class TransactionConfirmationStore: ObservableObject { isBalanceSufficient = false } } else if shouldFetchGasTokenBalance { - if let account = keyring.accountInfos.first(where: { $0.address == activeParsedTransaction.fromAddress }) { + if let account = accounts.first(where: { $0.address == activeParsedTransaction.fromAddress }) { await fetchGasTokenBalance(token: network.nativeToken, account: account, network: network) } } @@ -597,13 +596,13 @@ public class TransactionConfirmationStore: ObservableObject { } @MainActor private func fetchAllTransactions() async -> [BraveWallet.TransactionInfo] { - let allKeyrings = await keyringService.keyrings(for: WalletConstants.supportedCoinTypes()) + let allAccounts = await keyringService.allAccounts().accounts var allNetworksForCoin: [BraveWallet.CoinType: [BraveWallet.NetworkInfo]] = [:] for coin in WalletConstants.supportedCoinTypes() { let allNetworks = await rpcService.allNetworks(coin) allNetworksForCoin[coin] = allNetworks } - return await txService.pendingTransactions(networksForCoin: allNetworksForCoin, for: allKeyrings) + return await txService.pendingTransactions(networksForCoin: allNetworksForCoin, for: allAccounts) .sorted(by: { $0.createdTime > $1.createdTime }) } diff --git a/Sources/BraveWallet/Crypto/Stores/TransactionDetailsStore.swift b/Sources/BraveWallet/Crypto/Stores/TransactionDetailsStore.swift index 7dda58072ae..e6bb7f90470 100644 --- a/Sources/BraveWallet/Crypto/Stores/TransactionDetailsStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/TransactionDetailsStore.swift @@ -75,8 +75,6 @@ class TransactionDetailsStore: ObservableObject { return } self.network = network - let keringId = BraveWallet.KeyringId.keyringId(for: coin, on: transaction.chainId) - let keyring = await keyringService.keyringInfo(keringId) var allTokens: [BraveWallet.BlockchainToken] = await blockchainRegistry.allTokens(network.chainId, coin: network.coin) + tokenInfoCache.map(\.value) let userVisibleTokens: [BraveWallet.BlockchainToken] = assetManager.getAllUserAssetsInNetworkAssets(networks: [network]).flatMap { $0.tokens } let unknownTokenContractAddresses = transaction.tokenContractAddresses @@ -105,9 +103,10 @@ class TransactionDetailsStore: ObservableObject { if transaction.coin == .sol { (solEstimatedTxFee, _, _) = await solanaTxManagerProxy.estimatedTxFee(network.chainId, txMetaId: transaction.id) } + let allAccounts = await keyringService.allAccounts().accounts guard let parsedTransaction = transaction.parsedTransaction( network: network, - accountInfos: keyring.accountInfos, + accountInfos: allAccounts, visibleTokens: userVisibleTokens, allTokens: allTokens, assetRatios: assetRatios, diff --git a/Sources/BraveWallet/Crypto/Stores/TransactionsActivityStore.swift b/Sources/BraveWallet/Crypto/Stores/TransactionsActivityStore.swift index ef76d186889..7d80e08c762 100644 --- a/Sources/BraveWallet/Crypto/Stores/TransactionsActivityStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/TransactionsActivityStore.swift @@ -69,10 +69,8 @@ class TransactionsActivityStore: ObservableObject { func update() { updateTask?.cancel() updateTask = Task { @MainActor in - let allKeyrings = await self.keyringService.keyrings( - for: WalletConstants.supportedCoinTypes() - ) - let allAccountInfos = allKeyrings.flatMap(\.accountInfos) + let allAccounts = await keyringService.allAccounts() + let allAccountInfos = allAccounts.accounts // setup network filters if not currently setup if self.networkFilters.isEmpty { self.networkFilters = await self.rpcService.allNetworksForSupportedCoins().map { @@ -84,7 +82,7 @@ class TransactionsActivityStore: ObservableObject { let allNetworksAllCoins = networksForCoin.values.flatMap { $0 } let allTransactions = await txService.allTransactions( - networksForCoin: networksForCoin, for: allKeyrings + networksForCoin: networksForCoin, for: allAccountInfos ).filter { $0.txStatus != .rejected } let userVisibleTokens = assetManager.getAllVisibleAssetsInNetworkAssets(networks: allNetworksAllCoins).flatMap(\.tokens) let allTokens = await blockchainRegistry.allTokens( @@ -188,7 +186,7 @@ class TransactionsActivityStore: ObservableObject { extension TransactionsActivityStore: BraveWalletKeyringServiceObserver { func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - func keyringRestored(_ keyringId: BraveWallet.KeyringId) { } + func walletRestored() { } func keyringReset() { } diff --git a/Sources/BraveWallet/Crypto/Stores/UserAssetsStore.swift b/Sources/BraveWallet/Crypto/Stores/UserAssetsStore.swift index 8cefa3e0a9b..60dcc7247d7 100644 --- a/Sources/BraveWallet/Crypto/Stores/UserAssetsStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/UserAssetsStore.swift @@ -239,7 +239,7 @@ extension UserAssetsStore: BraveWalletKeyringServiceObserver { update() } - public func keyringRestored(_ keyringId: BraveWallet.KeyringId) { + public func walletRestored() { } public func keyringReset() { diff --git a/Sources/BraveWallet/Extensions/BraveWalletExtensions.swift b/Sources/BraveWallet/Extensions/BraveWalletExtensions.swift index 04c71dd2495..8300a90d8a5 100644 --- a/Sources/BraveWallet/Extensions/BraveWalletExtensions.swift +++ b/Sources/BraveWallet/Extensions/BraveWalletExtensions.swift @@ -220,7 +220,22 @@ extension BraveWallet.CoinType { extension BraveWallet.KeyringInfo { var coin: BraveWallet.CoinType? { - accountInfos.first?.coin + switch self.id { + case .default: + return .eth + case .solana: + return .sol + case .filecoin, .filecoinTestnet: + return .fil + case .bitcoin84, .bitcoin84Testnet: + return .btc + case .zCashMainnet: + return nil + case .zCashTestnet: + return nil + @unknown default: + return nil + } } } diff --git a/Sources/BraveWallet/Extensions/KeyringServiceExtensions.swift b/Sources/BraveWallet/Extensions/KeyringServiceExtensions.swift index 57de683426e..c061425538f 100644 --- a/Sources/BraveWallet/Extensions/KeyringServiceExtensions.swift +++ b/Sources/BraveWallet/Extensions/KeyringServiceExtensions.swift @@ -66,12 +66,11 @@ extension BraveWalletKeyringService { /// Check if any wallet account has been created given a coin type and a chain id @MainActor func isAccountAvailable(for coin: BraveWallet.CoinType, chainId: String) async -> Bool { + // KeyringId must be checked with chainId for Filecoin, BTC (2 keyring types). let keyringId = BraveWallet.KeyringId.keyringId(for: coin, on: chainId) - let keyringInfo = await keyringInfo(keyringId) - // If user restore a wallet, `BraveWallet.KeyringInfo.isKeyringCreated` can be true, - // but `BraveWallet.KeyringInfo.accountInfos` will be empty. - // Hence, we will have to check if `BraveWallet.KeyringInfo.accountInfos` is empty instead of - // checking the boolean of `BraveWallet.KeyringInfo.isKeyringCreated` - return !keyringInfo.accountInfos.isEmpty + // `KeyringInfo.isKeyringCreated` insufficient check as this value can + // be true with no accounts after wallet restore. + let allAccountsForKeyring = await allAccounts().accounts.filter { $0.keyringId == keyringId } + return !allAccountsForKeyring.isEmpty } } diff --git a/Sources/BraveWallet/Extensions/WalletTxServiceExtensions.swift b/Sources/BraveWallet/Extensions/WalletTxServiceExtensions.swift index 36a1dc692fa..7cb4a2814e1 100644 --- a/Sources/BraveWallet/Extensions/WalletTxServiceExtensions.swift +++ b/Sources/BraveWallet/Extensions/WalletTxServiceExtensions.swift @@ -11,30 +11,25 @@ extension BraveWalletTxService { // Fetches all pending transactions for all given keyrings func pendingTransactions( networksForCoin: [BraveWallet.CoinType: [BraveWallet.NetworkInfo]], - for keyrings: [BraveWallet.KeyringInfo] + for accounts: [BraveWallet.AccountInfo] ) async -> [BraveWallet.TransactionInfo] { - await allTransactions(networksForCoin: networksForCoin, for: keyrings) + await allTransactions(networksForCoin: networksForCoin, for: accounts) .filter { $0.txStatus == .unapproved } } // Fetches all transactions for all given keyrings func allTransactions( networksForCoin: [BraveWallet.CoinType: [BraveWallet.NetworkInfo]], - for keyrings: [BraveWallet.KeyringInfo] + for accounts: [BraveWallet.AccountInfo] ) async -> [BraveWallet.TransactionInfo] { return await withTaskGroup( of: [BraveWallet.TransactionInfo].self, body: { @MainActor group in - for keyring in keyrings { - guard let keyringCoin = keyring.coin, - let networksForKeyringCoin = networksForCoin[keyringCoin] else { - continue - } - for info in keyring.accountInfos { - for network in networksForKeyringCoin where network.supportedKeyrings.contains(keyring.id.rawValue as NSNumber) { - group.addTask { @MainActor in - await self.allTransactionInfo(info.coin, chainId: network.chainId, from: info.accountId) - } + for account in accounts { + guard let networksForAccount = networksForCoin[account.coin] else { continue } + for network in networksForAccount where network.supportedKeyrings.contains(account.keyringId.rawValue as NSNumber) { + group.addTask { @MainActor in + await self.allTransactionInfo(account.coin, chainId: network.chainId, from: account.accountId) } } } diff --git a/Sources/BraveWallet/Panels/Connect/EditSiteConnectionView.swift b/Sources/BraveWallet/Panels/Connect/EditSiteConnectionView.swift index 1065fc81d7d..4ab8803e15a 100644 --- a/Sources/BraveWallet/Panels/Connect/EditSiteConnectionView.swift +++ b/Sources/BraveWallet/Panels/Connect/EditSiteConnectionView.swift @@ -131,7 +131,7 @@ struct EditSiteConnectionView: View { } private var accountInfos: [BraveWallet.AccountInfo] { - keyringStore.allKeyrings.first(where: { $0.coin == coin })?.accountInfos ?? [] + keyringStore.allAccounts.filter { $0.coin == coin } } var body: some View { diff --git a/Sources/BraveWallet/Panels/Connect/NewSiteConnectionView.swift b/Sources/BraveWallet/Panels/Connect/NewSiteConnectionView.swift index 6698bff5ac6..df3b48a9810 100644 --- a/Sources/BraveWallet/Panels/Connect/NewSiteConnectionView.swift +++ b/Sources/BraveWallet/Panels/Connect/NewSiteConnectionView.swift @@ -41,7 +41,7 @@ public struct NewSiteConnectionView: View { @State private var isConfirmationViewVisible: Bool = false private var accountInfos: [BraveWallet.AccountInfo] { - let allAccounts = keyringStore.allKeyrings.first(where: { $0.coin == coin })?.accountInfos ?? [] + let allAccounts = keyringStore.allAccounts.filter { $0.coin == coin } return allAccounts.filter { self.accounts.contains($0.address) } } @@ -194,7 +194,7 @@ public struct NewSiteConnectionView: View { } private var accountsAddressesToConfirm: String { - keyringStore.defaultKeyring.accountInfos + accountInfos .filter { selectedAccounts.contains($0.id) } .map(\.address.truncatedAddress) .joined(separator: ", ") @@ -228,7 +228,7 @@ public struct NewSiteConnectionView: View { } Section { Button { - let accounts = keyringStore.allKeyrings.flatMap(\.accountInfos) + let accounts = accountInfos .filter { selectedAccounts.contains($0.id) } .map(\.address) onConnect(accounts) diff --git a/Sources/BraveWallet/Preview Content/MockKeyringService.swift b/Sources/BraveWallet/Preview Content/MockKeyringService.swift index 1677758a7e3..669ce72c697 100644 --- a/Sources/BraveWallet/Preview Content/MockKeyringService.swift +++ b/Sources/BraveWallet/Preview Content/MockKeyringService.swift @@ -11,7 +11,15 @@ import BraveCore /// /// - note: Do not use this directly, use ``CryptoKeyringStore.previewStore`` class MockKeyringService: BraveWalletKeyringService { - private var keyrings: [BraveWallet.KeyringInfo] = [.init(id: BraveWallet.KeyringId.default, isKeyringCreated: false, isLocked: false, isBackedUp: true, accountInfos: [])] + private var keyrings: [BraveWallet.KeyringInfo] = [ + .init( + id: BraveWallet.KeyringId.default, + isKeyringCreated: false, + isLocked: false, + isBackedUp: true + ) + ] + private var allAccounts: [BraveWallet.AccountInfo] = [] private var privateKeys: [String: String] = [:] private var password = "" // Not a real phrase, has a duplicated word for testing @@ -74,7 +82,7 @@ class MockKeyringService: BraveWalletKeyringService { name: accountName, hardware: nil ) - defaultKeyring.accountInfos.append(info) + allAccounts.append(info) observers.allObjects.forEach { $0.accountsChanged() } @@ -148,7 +156,7 @@ class MockKeyringService: BraveWalletKeyringService { self.password = password // Test store does not test phrase validity observers.allObjects.forEach { - $0.keyringRestored(BraveWallet.KeyringId.default) + $0.walletRestored() } completion(true) } @@ -206,7 +214,7 @@ class MockKeyringService: BraveWalletKeyringService { hardware: nil ) privateKeys[info.address] = privateKey - defaultKeyring.accountInfos.append(info) + allAccounts.append(info) observers.allObjects.forEach { $0.accountsChanged() } @@ -242,11 +250,11 @@ class MockKeyringService: BraveWalletKeyringService { } func removeAccount(_ accountId: BraveWallet.AccountId, password: String, completion: @escaping (Bool) -> Void) { - guard let index = defaultKeyring.accountInfos.firstIndex(where: { $0.address == accountId.address }) else { + guard let index = allAccounts.firstIndex(where: { $0.address == accountId.address }) else { completion(false) return } - defaultKeyring.accountInfos.remove(at: index) + allAccounts.remove(at: index) observers.allObjects.forEach { $0.accountsChanged() } @@ -268,7 +276,7 @@ class MockKeyringService: BraveWalletKeyringService { } func setSelectedAccount(_ accountId: BraveWallet.AccountId, completion: @escaping (Bool) -> Void) { - guard let account = defaultKeyring.accountInfos.first(where: { $0.address == accountId.address }) else { + guard let account = allAccounts.first(where: { $0.address == accountId.address }) else { completion(false) return } @@ -300,14 +308,12 @@ class MockKeyringService: BraveWalletKeyringService { } func setAccountName(_ accountId: BraveWallet.AccountId, name: String, completion: @escaping (Bool) -> Void) { - keyringInfo(accountId.keyringId) { keyring in - if let account = keyring.accountInfos.first(where: { $0.accountId == accountId }) { - account.name = name - completion(true) - return - } + guard let account = allAccounts.first(where: { $0.address == accountId.address }) else { completion(false) + return } + account.name = name + completion(true) } func addHardwareAccounts(_ info: [BraveWallet.HardwareWalletAccount]) async -> [BraveWallet.AccountInfo]? { @@ -418,31 +424,41 @@ extension BraveWallet.KeyringInfo { id: BraveWallet.KeyringId.default, isKeyringCreated: true, isLocked: false, - isBackedUp: false, - accountInfos: [.mockEthAccount] + isBackedUp: false ) static let mockSolanaKeyringInfo: BraveWallet.KeyringInfo = .init( id: BraveWallet.KeyringId.solana, isKeyringCreated: true, isLocked: false, - isBackedUp: false, - accountInfos: [.mockSolAccount] + isBackedUp: false ) static let mockFilecoinKeyringInfo: BraveWallet.KeyringInfo = .init( id: BraveWallet.KeyringId.filecoin, isKeyringCreated: true, isLocked: false, - isBackedUp: false, - accountInfos: [.mockFilAccount] + isBackedUp: false ) static let mockFilecoinTestnetKeyringInfo: BraveWallet.KeyringInfo = .init( id: BraveWallet.KeyringId.filecoinTestnet, isKeyringCreated: true, isLocked: false, - isBackedUp: false, - accountInfos: [.mockFilTestnetAccount] + isBackedUp: false + ) +} + +extension BraveWallet.AllAccountsInfo { + static let mock: BraveWallet.AllAccountsInfo = .init( + accounts: [ + .mockEthAccount, + .mockSolAccount, + .mockFilAccount, + .mockFilTestnetAccount + ], + selectedAccount: .mockEthAccount, + ethDappSelectedAccount: .mockEthAccount, + solDappSelectedAccount: .mockSolAccount ) } diff --git a/Tests/BraveWalletTests/AccountActivityStoreTests.swift b/Tests/BraveWalletTests/AccountActivityStoreTests.swift index 231e823cd27..bd00b75e52b 100644 --- a/Tests/BraveWalletTests/AccountActivityStoreTests.swift +++ b/Tests/BraveWalletTests/AccountActivityStoreTests.swift @@ -55,6 +55,9 @@ class AccountActivityStoreTests: XCTestCase { completion(.mockDefaultKeyringInfo) } } + keyringService._allAccounts = { + $0(.mock) + } let rpcService = BraveWallet.TestJsonRpcService() rpcService._addObserver = { _ in } diff --git a/Tests/BraveWalletTests/AssetDetailStoreTests.swift b/Tests/BraveWalletTests/AssetDetailStoreTests.swift index e4f82d31385..8c3cbb5add8 100644 --- a/Tests/BraveWalletTests/AssetDetailStoreTests.swift +++ b/Tests/BraveWalletTests/AssetDetailStoreTests.swift @@ -27,6 +27,9 @@ class AssetDetailStoreTests: XCTestCase { keyringService._keyringInfo = { $1(.mockDefaultKeyringInfo) } + keyringService._allAccounts = { completion in + completion(.mock) + } keyringService._addObserver = { _ in } let mockEthBalance: Double = 1 @@ -235,15 +238,10 @@ class AssetDetailStoreTests: XCTestCase { keyringService._keyringInfo = { $1(keyring) } - keyringService._addObserver = { _ in } keyringService._allAccounts = { completion in - completion(.init( - accounts: keyring.accountInfos, - selectedAccount: keyring.accountInfos.first, - ethDappSelectedAccount: keyring.accountInfos.first, - solDappSelectedAccount: nil - )) + completion(.mock) } + keyringService._addObserver = { _ in } let mockEthBalance: Double = 1 let ethBalanceWei = formatter.weiString( @@ -251,7 +249,6 @@ class AssetDetailStoreTests: XCTestCase { radix: .hex, decimals: Int(BraveWallet.BlockchainToken.previewToken.decimals) ) ?? "" - let formattedEthBalance = currencyFormatter.string(from: NSNumber(value: mockEthBalance)) ?? "" let rpcService = BraveWallet.TestJsonRpcService() rpcService._network = { $2(.mockMainnet) diff --git a/Tests/BraveWalletTests/NetworkSelectionStoreTests.swift b/Tests/BraveWalletTests/NetworkSelectionStoreTests.swift index d291a2fa5e1..4a8e5bc325d 100644 --- a/Tests/BraveWalletTests/NetworkSelectionStoreTests.swift +++ b/Tests/BraveWalletTests/NetworkSelectionStoreTests.swift @@ -25,13 +25,11 @@ import Preferences let keyringService = BraveWallet.TestKeyringService() keyringService._keyringInfo = { keyringId, completion in - let isEthereumKeyringId = keyringId == BraveWallet.KeyringId.default let keyring: BraveWallet.KeyringInfo = .init( id: BraveWallet.KeyringId.default, isKeyringCreated: true, isLocked: false, - isBackedUp: true, - accountInfos: isEthereumKeyringId ? [.previewAccount] : [] + isBackedUp: true ) completion(keyring) } @@ -217,23 +215,11 @@ import Preferences ] keyringService._keyringInfo = { keyringId, completion in - let accountInfos: [BraveWallet.AccountInfo] - switch keyringId { - case BraveWallet.KeyringId.default: - accountInfos = accountInfosDict[.eth, default: []] - case BraveWallet.KeyringId.solana: - accountInfos = accountInfosDict[.sol, default: []] - case BraveWallet.KeyringId.filecoin: - accountInfos = accountInfosDict[.fil, default: []] - default: - accountInfos = [] - } let keyring: BraveWallet.KeyringInfo = .init( id: keyringId, isKeyringCreated: true, isLocked: false, - isBackedUp: false, - accountInfos: accountInfos + isBackedUp: false ) completion(keyring) } diff --git a/Tests/BraveWalletTests/NetworkStoreTests.swift b/Tests/BraveWalletTests/NetworkStoreTests.swift index d16846dcb30..425269de906 100644 --- a/Tests/BraveWalletTests/NetworkStoreTests.swift +++ b/Tests/BraveWalletTests/NetworkStoreTests.swift @@ -31,13 +31,11 @@ import Preferences let keyringService = BraveWallet.TestKeyringService() keyringService._keyringInfo = { keyringId, completion in - let isEthereumKeyringId = keyringId == BraveWallet.KeyringId.default let keyring: BraveWallet.KeyringInfo = .init( - id: BraveWallet.KeyringId.default, + id: keyringId, isKeyringCreated: true, isLocked: false, - isBackedUp: true, - accountInfos: isEthereumKeyringId ? [.previewAccount] : [] + isBackedUp: true ) completion(keyring) } diff --git a/Tests/BraveWalletTests/PortfolioStoreTests.swift b/Tests/BraveWalletTests/PortfolioStoreTests.swift index 4be18b49760..a0d85dc0f95 100644 --- a/Tests/BraveWalletTests/PortfolioStoreTests.swift +++ b/Tests/BraveWalletTests/PortfolioStoreTests.swift @@ -118,7 +118,6 @@ import Preferences let formatter = WeiFormatter(decimalFormatStyle: .decimals(precision: 18)) // config filecoin on mainnet - let mockFilAccountInfos: [BraveWallet.AccountInfo] = [filAccount1, filAccount2] let mockFilUserAssets: [BraveWallet.BlockchainToken] = [ BraveWallet.NetworkInfo.mockFilecoinMainnet.nativeToken.copy(asVisibleAsset: true) ] @@ -128,7 +127,6 @@ import Preferences decimals: Int(BraveWallet.BlockchainToken.mockFilToken.decimals) ) ?? "" // config filecoin on testnet - let mockFilTestnetAccountInfos: [BraveWallet.AccountInfo] = [filTestnetAccount] let mockFilTestnetBalanceInWei = formatter.weiString( from: mockFILBalanceTestnet, radix: .decimal, @@ -136,13 +134,11 @@ import Preferences ) ?? "" // config Solana - let mockSolAccountInfos: [BraveWallet.AccountInfo] = [solAccount1, solAccount2] let mockSolUserAssets: [BraveWallet.BlockchainToken] = [ BraveWallet.NetworkInfo.mockSolana.nativeToken.copy(asVisibleAsset: true), .mockSpdToken // Verify non-visible assets not displayed #6386 ] // config Ethereum - let mockEthAccountInfos: [BraveWallet.AccountInfo] = [ethAccount1, ethAccount2] let mockEthUserAssets: [BraveWallet.BlockchainToken] = [ .previewToken.copy(asVisibleAsset: true), .previewDaiToken, // Verify non-visible assets not displayed #6386 @@ -172,35 +168,6 @@ import Preferences filTestnet.nativeToken.copy(asVisibleAsset: true) ] - let ethKeyring: BraveWallet.KeyringInfo = .init( - id: BraveWallet.KeyringId.default, - isKeyringCreated: true, - isLocked: false, - isBackedUp: true, - accountInfos: mockEthAccountInfos - ) - let solKeyring: BraveWallet.KeyringInfo = .init( - id: BraveWallet.KeyringId.solana, - isKeyringCreated: true, - isLocked: false, - isBackedUp: true, - accountInfos: mockSolAccountInfos - ) - let filKeyring: BraveWallet.KeyringInfo = .init( - id: .filecoin, - isKeyringCreated: true, - isLocked: false, - isBackedUp: true, - accountInfos: mockFilAccountInfos - ) - let filTestnetKeyring: BraveWallet.KeyringInfo = .init( - id: .filecoinTestnet, - isKeyringCreated: true, - isLocked: false, - isBackedUp: true, - accountInfos: mockFilTestnetAccountInfos - ) - // setup test services let keyringService = BraveWallet.TestKeyringService() keyringService._addObserver = { _ in } @@ -210,10 +177,15 @@ import Preferences } keyringService._allAccounts = { $0(.init( - accounts: ethKeyring.accountInfos + solKeyring.accountInfos + filKeyring.accountInfos + filTestnetKeyring.accountInfos, - selectedAccount: ethKeyring.accountInfos.first, - ethDappSelectedAccount: ethKeyring.accountInfos.first, - solDappSelectedAccount: solKeyring.accountInfos.first + accounts: [ + self.ethAccount1, self.ethAccount2, + self.solAccount1, self.solAccount2, + self.filAccount1, self.filAccount2, + self.filTestnetAccount + ], + selectedAccount: self.ethAccount1, + ethDappSelectedAccount: self.ethAccount1, + solDappSelectedAccount: self.solAccount1 )) } let rpcService = BraveWallet.TestJsonRpcService() diff --git a/Tests/BraveWalletTests/SelectAccountTokenStoreTests.swift b/Tests/BraveWalletTests/SelectAccountTokenStoreTests.swift index e742d37154f..d58e91f0875 100644 --- a/Tests/BraveWalletTests/SelectAccountTokenStoreTests.swift +++ b/Tests/BraveWalletTests/SelectAccountTokenStoreTests.swift @@ -145,8 +145,7 @@ import Preferences id: BraveWallet.KeyringId.default, isKeyringCreated: true, isLocked: false, - isBackedUp: true, - accountInfos: [.mockEthAccount, self.mockEthAccount2] + isBackedUp: true ) completion(keyring) case .solana: @@ -154,8 +153,7 @@ import Preferences id: BraveWallet.KeyringId.solana, isKeyringCreated: true, isLocked: false, - isBackedUp: true, - accountInfos: [.mockSolAccount] + isBackedUp: true ) completion(keyring) case .filecoin: @@ -166,6 +164,20 @@ import Preferences completion(.mockDefaultKeyringInfo) } } + keyringService._allAccounts = { + $0(.init( + accounts: [ + .mockEthAccount, + self.mockEthAccount2, + .mockSolAccount, + .mockFilAccount, + .mockFilTestnetAccount + ], + selectedAccount: .mockEthAccount, + ethDappSelectedAccount: .mockEthAccount, + solDappSelectedAccount: .mockSolAccount + )) + } let rpcService = BraveWallet.TestJsonRpcService() rpcService._allNetworks = { coin, completion in completion(self.allNetworks[coin] ?? []) diff --git a/Tests/BraveWalletTests/SettingsStoreTests.swift b/Tests/BraveWalletTests/SettingsStoreTests.swift index d0f0c75889b..b5f8883b1c9 100644 --- a/Tests/BraveWalletTests/SettingsStoreTests.swift +++ b/Tests/BraveWalletTests/SettingsStoreTests.swift @@ -16,7 +16,6 @@ class SettingsStoreTests: XCTestCase { /// Sets up TestKeyringService, TestBraveWalletService and TestTxService with some default values. private func setupServices() -> (BraveWallet.TestKeyringService, BraveWallet.TestBraveWalletService, BraveWallet.TestJsonRpcService, BraveWallet.TestTxService, IpfsAPI) { - let mockAccountInfos: [BraveWallet.AccountInfo] = [.previewAccount] let mockUserAssets: [BraveWallet.BlockchainToken] = [.previewToken.copy(asVisibleAsset: true)] let keyringService = BraveWallet.TestKeyringService() @@ -25,8 +24,8 @@ class SettingsStoreTests: XCTestCase { id: BraveWallet.KeyringId.default, isKeyringCreated: true, isLocked: false, - isBackedUp: true, - accountInfos: mockAccountInfos) + isBackedUp: true + ) completion(keyring) } keyringService._addObserver = { _ in } diff --git a/Tests/BraveWalletTests/TransactionConfirmationStoreTests.swift b/Tests/BraveWalletTests/TransactionConfirmationStoreTests.swift index 93c8427e3c0..0a91dd8a68c 100644 --- a/Tests/BraveWalletTests/TransactionConfirmationStoreTests.swift +++ b/Tests/BraveWalletTests/TransactionConfirmationStoreTests.swift @@ -114,17 +114,18 @@ import Preferences id: id, isKeyringCreated: true, isLocked: false, - isBackedUp: true, - accountInfos: []) - if id == BraveWallet.KeyringId.default { - keyring.accountInfos = accountInfos.filter { $0.coin == .eth } - } else if id == .solana { - keyring.accountInfos = accountInfos.filter { $0.coin == .sol } - } else { - keyring.accountInfos = accountInfos.filter { $0.coin == .fil } - } + isBackedUp: true + ) completion(keyring) } + keyringService._allAccounts = { + $0(.init( + accounts: accountInfos, + selectedAccount: accountInfos.first, + ethDappSelectedAccount: accountInfos.first(where: { $0.coin == .eth }), + solDappSelectedAccount: accountInfos.first(where: { $0.coin == .sol }) + )) + } let solTxManagerProxy = BraveWallet.TestSolanaTxManagerProxy() solTxManagerProxy._estimatedTxFee = { $2(0, .success, "") } diff --git a/Tests/BraveWalletTests/TransactionsActivityStoreTests.swift b/Tests/BraveWalletTests/TransactionsActivityStoreTests.swift index 234de71cb26..e4d6c06fc28 100644 --- a/Tests/BraveWalletTests/TransactionsActivityStoreTests.swift +++ b/Tests/BraveWalletTests/TransactionsActivityStoreTests.swift @@ -65,6 +65,9 @@ class TransactionsActivityStoreTests: XCTestCase { completion(.mockDefaultKeyringInfo) } } + keyringService._allAccounts = { + $0(.mock) + } let rpcService = BraveWallet.TestJsonRpcService() rpcService._allNetworks = { coin, completion in diff --git a/package-lock.json b/package-lock.json index 0d2676b6e68..cabb411117c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MPL-2.0", "dependencies": { "@mozilla/readability": "^0.4.2", - "brave-core-ios": "https://github.com/brave/brave-browser/releases/download/v1.60.67/brave-core-ios-1.60.67.tgz", + "brave-core-ios": "https://github.com/brave/brave-browser/releases/download/v1.60.81/brave-core-ios-1.60.81.tgz", "leo": "github:brave/leo#7f2dfddb70aff1501ef5a2f3c640a8c74a7343ee", "leo-sf-symbols": "github:brave/leo-sf-symbols#d6056328b8d6ef06e68996ff02a22e06f52590c3", "page-metadata-parser": "^1.1.3", @@ -493,9 +493,9 @@ } }, "node_modules/brave-core-ios": { - "version": "1.60.67", - "resolved": "https://github.com/brave/brave-browser/releases/download/v1.60.67/brave-core-ios-1.60.67.tgz", - "integrity": "sha512-1jojRJJmZZ/LgSNlG5lyhFYTjcUOOthvGkE9nDWnKLUebdAYeFGOCUSnE4XWJPd3/DVghiWdooldAd0+GE7x+Q==", + "version": "1.60.81", + "resolved": "https://github.com/brave/brave-browser/releases/download/v1.60.81/brave-core-ios-1.60.81.tgz", + "integrity": "sha512-TXqECLiiXegyeXnVfUfZ9q8GtZT+3ErJ2AbGa4YFaI5Cl/rna0AzEfn8H3UgaOiIif8yULbjr7gdrCKCiPHtYA==", "license": "ISC" }, "node_modules/browserslist": { @@ -3171,8 +3171,8 @@ } }, "brave-core-ios": { - "version": "https://github.com/brave/brave-browser/releases/download/v1.60.67/brave-core-ios-1.60.67.tgz", - "integrity": "sha512-1jojRJJmZZ/LgSNlG5lyhFYTjcUOOthvGkE9nDWnKLUebdAYeFGOCUSnE4XWJPd3/DVghiWdooldAd0+GE7x+Q==" + "version": "https://github.com/brave/brave-browser/releases/download/v1.60.81/brave-core-ios-1.60.81.tgz", + "integrity": "sha512-TXqECLiiXegyeXnVfUfZ9q8GtZT+3ErJ2AbGa4YFaI5Cl/rna0AzEfn8H3UgaOiIif8yULbjr7gdrCKCiPHtYA==" }, "browserslist": { "version": "4.17.1", diff --git a/package.json b/package.json index 01c13237205..a9f12e711eb 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "license": "MPL-2.0", "dependencies": { "@mozilla/readability": "^0.4.2", - "brave-core-ios": "https://github.com/brave/brave-browser/releases/download/v1.60.67/brave-core-ios-1.60.67.tgz", + "brave-core-ios": "https://github.com/brave/brave-browser/releases/download/v1.60.81/brave-core-ios-1.60.81.tgz", "leo": "github:brave/leo#7f2dfddb70aff1501ef5a2f3c640a8c74a7343ee", "leo-sf-symbols": "github:brave/leo-sf-symbols#d6056328b8d6ef06e68996ff02a22e06f52590c3", "page-metadata-parser": "^1.1.3",