From b42880ddbd3b808f4f179e23f814b13daf86e844 Mon Sep 17 00:00:00 2001 From: StephenHeaps <5314553+StephenHeaps@users.noreply.github.com> Date: Mon, 17 Jul 2023 10:18:41 -0400 Subject: [PATCH] Fix brave/brave-ios#7730: Bump Brave Core to 1.57.9 (brave/brave-ios#7731) * AccountInfo refactor updates * Update BraveCore to v1.57.9 --------- Co-authored-by: Kyle Hickinson --- .../Rewards/PublisherInfoExtensions.swift | 1 - .../Ads/AdsNotificationHandler.swift | 12 +- .../Browser/BrowserViewController.swift | 2 +- .../BrowserViewController+Wallet.swift | 6 +- .../NewTabPageViewController.swift | 11 +- .../Sections/BraveNewsSectionProvider.swift | 6 +- .../Brave/Frontend/Rewards/BraveRewards.swift | 22 ++- .../Customize/NewsSettingsView.swift | 2 +- .../Extensions/BraveAdsExtensions.swift | 7 +- .../Crypto/Stores/AccountActivityStore.swift | 6 +- .../Crypto/Stores/AssetDetailStore.swift | 4 +- .../Crypto/Stores/CryptoStore.swift | 4 +- .../Crypto/Stores/KeyringStore.swift | 45 ++--- .../BraveWallet/Crypto/Stores/NFTStore.swift | 4 +- .../Crypto/Stores/NetworkStore.swift | 4 +- .../Crypto/Stores/PortfolioStore.swift | 4 +- .../Crypto/Stores/SendTokenStore.swift | 6 +- .../Crypto/Stores/SettingsStore.swift | 4 +- .../Crypto/Stores/SwapTokenStore.swift | 4 +- .../Stores/TransactionsActivityStore.swift | 4 +- .../Crypto/Stores/UserAssetsStore.swift | 4 +- .../Extensions/BraveWalletExtensions.swift | 23 ++- .../BraveWalletSwiftUIExtensions.swift | 11 +- .../BraveWallet/Panels/WalletPanelView.swift | 3 +- .../MockBlockchainRegistry.swift | 4 + .../MockBraveWalletService.swift | 10 +- .../Preview Content/MockContent.swift | 32 ++-- .../MockEthTxManagerProxy.swift | 4 + .../Preview Content/MockJsonRpcService.swift | 4 + .../Preview Content/MockKeyringService.swift | 157 +++++++++++------- .../BraveWalletTests/KeyringStoreTests.swift | 8 +- .../NetworkSelectionStoreTests.swift | 2 +- .../BraveWalletTests/NetworkStoreTests.swift | 2 +- .../PortfolioStoreTests.swift | 6 +- .../SelectAccountTokenStoreTests.swift | 18 +- .../SendTokenStoreTests.swift | 30 ++-- .../BraveWalletTests/SettingsStoreTests.swift | 2 +- .../TransactionConfirmationStoreTests.swift | 2 +- .../TransactionParserTests.swift | 42 +++-- .../TransactionsActivityStoreTests.swift | 2 +- package-lock.json | 12 +- package.json | 2 +- 42 files changed, 328 insertions(+), 210 deletions(-) diff --git a/Sources/Brave/Extensions/Rewards/PublisherInfoExtensions.swift b/Sources/Brave/Extensions/Rewards/PublisherInfoExtensions.swift index 5c5ad169adf7..d926c2bdbcf9 100644 --- a/Sources/Brave/Extensions/Rewards/PublisherInfoExtensions.swift +++ b/Sources/Brave/Extensions/Rewards/PublisherInfoExtensions.swift @@ -30,7 +30,6 @@ extension ProviderDisplayString { } extension BraveCore.BraveRewards.PublisherInfo: ProviderDisplayString {} -extension BraveCore.BraveRewards.PendingContributionInfo: ProviderDisplayString {} extension BraveCore.BraveRewards.PublisherInfo { /// The display name to show when showing Publisher names (example: "X on GitHub", "Y on diff --git a/Sources/Brave/Frontend/Brave Rewards/Ads/AdsNotificationHandler.swift b/Sources/Brave/Frontend/Brave Rewards/Ads/AdsNotificationHandler.swift index 94747f1bcb06..3bcc463a9cdf 100644 --- a/Sources/Brave/Frontend/Brave Rewards/Ads/AdsNotificationHandler.swift +++ b/Sources/Brave/Frontend/Brave Rewards/Ads/AdsNotificationHandler.swift @@ -43,19 +43,19 @@ class AdsNotificationHandler: BraveAdsNotificationHandler { guard let self = self else { return } switch action { case .opened: - self.ads.reportNotificationAdEvent(notification.placementID, eventType: .clicked) + self.ads.reportNotificationAdEvent(notification.placementID, eventType: .clicked, completion: { _ in }) case .dismissed: - self.ads.reportNotificationAdEvent(notification.placementID, eventType: .dismissed) + self.ads.reportNotificationAdEvent(notification.placementID, eventType: .dismissed, completion: { _ in }) case .timedOut: - self.ads.reportNotificationAdEvent(notification.placementID, eventType: .timedOut) + self.ads.reportNotificationAdEvent(notification.placementID, eventType: .timedOut, completion: { _ in }) case .disliked: - self.ads.reportNotificationAdEvent(notification.placementID, eventType: .dismissed) - self.ads.toggleThumbsDown(forAd: notification.creativeInstanceID, advertiserId: notification.advertiserID) + self.ads.reportNotificationAdEvent(notification.placementID, eventType: .dismissed, completion: { _ in }) + self.ads.toggleThumbsDown(forAd: notification.creativeInstanceID, advertiserId: notification.advertiserID, segment: notification.segment) } self.actionOccured?(notification, action) } - ads.reportNotificationAdEvent(notification.placementID, eventType: .viewed) + ads.reportNotificationAdEvent(notification.placementID, eventType: .viewed, completion: { _ in }) notificationsPresenter?.display(notification: rewardsNotification, from: presentingController) } diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController.swift b/Sources/Brave/Frontend/Browser/BrowserViewController.swift index 2281e612fc8b..eed2740f21df 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController.swift @@ -335,7 +335,7 @@ public class BrowserViewController: UIViewController { if rewards.isEnabled { rewards.startLedgerService(nil) } else { - rewards.ads.initialize { _ in } + rewards.ads.initialize(walletInfo: .init()) { _ in } } } diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Wallet.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Wallet.swift index 8ed5bd74cf60..2a908d7898a0 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Wallet.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Wallet.swift @@ -346,7 +346,7 @@ extension Tab: BraveWalletProviderDelegate { let origin = getOrigin() // check if we receive account creation request without a wallet setup - let keyring = await keyringService.keyringInfo(BraveWallet.DefaultKeyringId) + let keyring = await keyringService.keyringInfo(BraveWallet.KeyringId.default) if !keyring.isKeyringCreated { // Wallet is not setup. User must onboard / setup wallet first. self.tabDelegate?.showWalletNotification(self, origin: origin) @@ -583,10 +583,10 @@ extension Tab: BraveWalletSolanaEventsListener { } extension Tab: BraveWalletKeyringServiceObserver { - func keyringCreated(_ keyringId: String) { + func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - func keyringRestored(_ keyringId: String) { + func keyringRestored(_ keyringId: BraveWallet.KeyringId) { } func keyringReset() { diff --git a/Sources/Brave/Frontend/Browser/New Tab Page/NewTabPageViewController.swift b/Sources/Brave/Frontend/Browser/New Tab Page/NewTabPageViewController.swift index 46b2667563be..6b31ab3f86c5 100644 --- a/Sources/Brave/Frontend/Browser/New Tab Page/NewTabPageViewController.swift +++ b/Sources/Brave/Frontend/Browser/New Tab Page/NewTabPageViewController.swift @@ -445,7 +445,8 @@ class NewTabPageViewController: UIViewController { rewards.ads.reportNewTabPageAdEvent( background.wallpaperId.uuidString, creativeInstanceId: sponsoredBackground.creativeInstanceId, - eventType: event + eventType: event, + completion: { _ in } ) } } @@ -560,7 +561,7 @@ class NewTabPageViewController: UIViewController { Preferences.BraveNews.userOptedIn.value = true Preferences.BraveNews.isShowingOptIn.value = false Preferences.BraveNews.isEnabled.value = true - rewards.ads.initialize { [weak self] _ in + rewards.ads.initialize(walletInfo: .init()) { [weak self] _ in // Initialize ads if it hasn't already been done self?.loadFeedContents() } @@ -588,7 +589,8 @@ class NewTabPageViewController: UIViewController { rewards.ads.reportPromotedContentAdEvent( item.content.urlHash, creativeInstanceId: creativeInstanceID, - eventType: .clicked + eventType: .clicked, + completion: { _ in } ) } delegate?.navigateToInput( @@ -616,7 +618,8 @@ class NewTabPageViewController: UIViewController { rewards.ads.reportInlineContentAdEvent( ad.placementID, creativeInstanceId: ad.creativeInstanceID, - eventType: .clicked + eventType: .clicked, + completion: { _ in } ) } delegate?.navigateToInput( diff --git a/Sources/Brave/Frontend/Browser/New Tab Page/Sections/BraveNewsSectionProvider.swift b/Sources/Brave/Frontend/Browser/New Tab Page/Sections/BraveNewsSectionProvider.swift index 738049f1aa33..fa5263d7266c 100644 --- a/Sources/Brave/Frontend/Browser/New Tab Page/Sections/BraveNewsSectionProvider.swift +++ b/Sources/Brave/Frontend/Browser/New Tab Page/Sections/BraveNewsSectionProvider.swift @@ -209,7 +209,8 @@ class BraveNewsSectionProvider: NSObject, NTPObservableSectionProvider { self?.rewards.ads.reportPromotedContentAdEvent( item.content.urlHash, creativeInstanceId: creativeInstanceID, - eventType: .viewed + eventType: .viewed, + completion: { _ in } ) } } @@ -218,7 +219,8 @@ class BraveNewsSectionProvider: NSObject, NTPObservableSectionProvider { self?.rewards.ads.reportInlineContentAdEvent( ad.placementID, creativeInstanceId: ad.creativeInstanceID, - eventType: .viewed + eventType: .viewed, + completion: { _ in } ) self?.recordWeeklyAdsViewedP3A(adViewed: true) } diff --git a/Sources/Brave/Frontend/Rewards/BraveRewards.swift b/Sources/Brave/Frontend/Rewards/BraveRewards.swift index cae52391eb12..e70e29f0e884 100644 --- a/Sources/Brave/Frontend/Rewards/BraveRewards.swift +++ b/Sources/Brave/Frontend/Rewards/BraveRewards.swift @@ -68,23 +68,28 @@ public class BraveRewards: NSObject { } private(set) var isAdsInitialized: Bool = false - private func fetchWalletAndInitializeAds() { + private func fetchWalletAndInitializeAds(toggleAds: Bool? = nil) { if isAdsInitialized { return } isAdsInitialized = true guard let ledger = ledger else { return } ledger.currentWalletInfo { wallet in - if let wallet = wallet { + var walletInfo: BraveAds.WalletInfo? + if let wallet { let seed = wallet.recoverySeed.map(\.uint8Value) - self.ads.updateWalletInfo( - wallet.paymentId, - base64Seed: Data(seed).base64EncodedString() + walletInfo = .init( + paymentId: wallet.paymentId, + recoverySeed: Data(seed).base64EncodedString() ) } - self.ads.initialize() { success in + self.ads.initialize(walletInfo: walletInfo ?? .init()) { success in if !success { self.isAdsInitialized = false + } else { + if let toggleAds { + self.ads.isEnabled = toggleAds + } } } } @@ -120,7 +125,6 @@ public class BraveRewards: NSObject { guard let self = self else { return } self.ledger?.setAutoContributeEnabled(newValue) let wasEnabled = self.ads.isEnabled - self.ads.isEnabled = newValue if !wasEnabled && newValue { Preferences.Rewards.adsEnabledTimestamp.value = Date() } else if wasEnabled && !newValue { @@ -130,7 +134,7 @@ public class BraveRewards: NSObject { if !newValue { self.proposeAdsShutdown() } else { - self.fetchWalletAndInitializeAds() + self.fetchWalletAndInitializeAds(toggleAds: true) } self.didChangeValue(for: \.isEnabled) } @@ -163,7 +167,7 @@ public class BraveRewards: NSObject { at: configuration.storageURL.appendingPathComponent("ads") ) if ads.isEnabled { - ads.initialize { _ in } + ads.initialize(walletInfo: .init()) { _ in } } } } diff --git a/Sources/BraveNews/Customize/NewsSettingsView.swift b/Sources/BraveNews/Customize/NewsSettingsView.swift index 43c544a33f57..32bfb7d9c46e 100644 --- a/Sources/BraveNews/Customize/NewsSettingsView.swift +++ b/Sources/BraveNews/Customize/NewsSettingsView.swift @@ -271,7 +271,7 @@ public struct NewsSettingsView: View { OptInView { @MainActor in Preferences.BraveNews.isShowingOptIn.value = false // Initialize ads if it hasn't already been done - await dataSource.ads?.initialize() + await dataSource.ads?.initialize(walletInfo: .init()) if dataSource.isSourcesExpired { await withCheckedContinuation { c in dataSource.load { diff --git a/Sources/BraveShared/Extensions/BraveAdsExtensions.swift b/Sources/BraveShared/Extensions/BraveAdsExtensions.swift index ebc1a8ac8b29..49bbb9ab4765 100644 --- a/Sources/BraveShared/Extensions/BraveAdsExtensions.swift +++ b/Sources/BraveShared/Extensions/BraveAdsExtensions.swift @@ -9,21 +9,22 @@ import Shared import UIKit extension BraveAds { - public func initialize(_ completion: @escaping (Bool) -> Void) { + public func initialize(walletInfo: BraveAds.WalletInfo, completion: @escaping (Bool) -> Void) { self.initialize( with: .init(deviceId: UIDevice.current.identifierForVendor?.uuidString ?? ""), buildChannelInfo: .init( isRelease: AppConstants.buildChannel == .release, name: AppConstants.buildChannel.rawValue ), + walletInfo: walletInfo, completion: completion ) } @discardableResult - @MainActor public func initialize() async -> Bool { + @MainActor public func initialize(walletInfo: BraveAds.WalletInfo) async -> Bool { await withCheckedContinuation { c in - self.initialize { success in + self.initialize(walletInfo: walletInfo) { success in c.resume(returning: success) } } diff --git a/Sources/BraveWallet/Crypto/Stores/AccountActivityStore.swift b/Sources/BraveWallet/Crypto/Stores/AccountActivityStore.swift index d03adf995268..5721832a1985 100644 --- a/Sources/BraveWallet/Crypto/Stores/AccountActivityStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/AccountActivityStore.swift @@ -270,10 +270,10 @@ class AccountActivityStore: ObservableObject { } extension AccountActivityStore: BraveWalletKeyringServiceObserver { - func keyringCreated(_ keyringId: String) { + func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - - func keyringRestored(_ keyringId: String) { + + func keyringRestored(_ keyringId: BraveWallet.KeyringId) { } func keyringReset() { diff --git a/Sources/BraveWallet/Crypto/Stores/AssetDetailStore.swift b/Sources/BraveWallet/Crypto/Stores/AssetDetailStore.swift index 4a1464a68bce..b0dbfe2a76f0 100644 --- a/Sources/BraveWallet/Crypto/Stores/AssetDetailStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/AssetDetailStore.swift @@ -366,10 +366,10 @@ extension AssetDetailStore: BraveWalletKeyringServiceObserver { update() } - func keyringCreated(_ keyringId: String) { + func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - func keyringRestored(_ keyringId: String) { + func keyringRestored(_ keyringId: BraveWallet.KeyringId) { } func locked() { diff --git a/Sources/BraveWallet/Crypto/Stores/CryptoStore.swift b/Sources/BraveWallet/Crypto/Stores/CryptoStore.swift index 1c3db4dfafe0..48b00aa51a14 100644 --- a/Sources/BraveWallet/Crypto/Stores/CryptoStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/CryptoStore.swift @@ -551,7 +551,7 @@ extension CryptoStore: BraveWalletKeyringServiceObserver { WalletProviderAccountCreationRequestManager.shared.cancelAllPendingRequests(coins: [.eth, .sol]) rejectAllPendingWebpageRequests() } - public func keyringCreated(_ keyringId: String) { + public func keyringCreated(_ keyringId: BraveWallet.KeyringId) { Task { @MainActor [weak self] in if let newCoin = WalletConstants.supportedCoinTypes.first(where: { $0.keyringId == keyringId }) { self?.userAssetManager.migrateUserAssets(for: newCoin, completion: { @@ -560,7 +560,7 @@ extension CryptoStore: BraveWalletKeyringServiceObserver { } } } - public func keyringRestored(_ keyringId: String) { + 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 WalletUserAssetGroup.removeAllGroup() { [weak self] in diff --git a/Sources/BraveWallet/Crypto/Stores/KeyringStore.swift b/Sources/BraveWallet/Crypto/Stores/KeyringStore.swift index 8769c0129d79..43de3dfed151 100644 --- a/Sources/BraveWallet/Crypto/Stores/KeyringStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/KeyringStore.swift @@ -66,7 +66,13 @@ struct RecoveryWord: Hashable, Identifiable { /// This wraps a KeyringService that you would obtain through BraveCore and makes it observable public class KeyringStore: ObservableObject { /// The defualt keyring information. By default this is an empty keyring which has no accounts. - @Published private(set) var defaultKeyring: BraveWallet.KeyringInfo = .init() + @Published private(set) var defaultKeyring: BraveWallet.KeyringInfo = .init( + id: .default, + isKeyringCreated: false, + isLocked: true, + isBackedUp: false, + accountInfos: [] + ) /// Whether or not the user should be viewing the onboarding flow to setup a keyring @Published private(set) var isOnboardingVisible: Bool = false /// Whether or not the last time the wallet was locked was due to the user manually locking it @@ -142,7 +148,7 @@ public class KeyringStore: ObservableObject { rpcService.add(self) updateKeyringInfo() - self.keyringService.keyringInfo(BraveWallet.DefaultKeyringId) { [self] keyringInfo in + self.keyringService.keyringInfo(BraveWallet.KeyringId.default) { [self] keyringInfo in isOnboardingVisible = !keyringInfo.isKeyringCreated if isKeychainPasswordStored && isOnboardingVisible { // If a user deletes the app and they had a stored user password in the past that keychain item @@ -172,7 +178,7 @@ public class KeyringStore: ObservableObject { let selectedAccountAddress = await keyringService.selectedAccount(selectedCoin) let allKeyrings = await keyringService.keyrings(for: WalletConstants.supportedCoinTypes) self.defaultAccounts = await keyringService.defaultAccounts(for: WalletConstants.supportedCoinTypes) - if let defaultKeyring = allKeyrings.first(where: { $0.id == BraveWallet.DefaultKeyringId }) { + if let defaultKeyring = allKeyrings.first(where: { $0.id == BraveWallet.KeyringId.default }) { self.defaultKeyring = defaultKeyring self.isDefaultKeyringCreated = defaultKeyring.isKeyringCreated } @@ -208,11 +214,7 @@ public class KeyringStore: ObservableObject { if coreSelectedAccount != account.address { // Update the selected account in core - let success = await keyringService.setSelectedAccount( - account.coin, - keyringId: account.keyringId, - address: account.address - ) + let success = await keyringService.setSelectedAccount(account.accountId) if success { self.selectedAccount = account } @@ -312,9 +314,13 @@ public class KeyringStore: ObservableObject { } func addPrimaryAccount(_ name: String, coin: BraveWallet.CoinType, completion: ((Bool) -> Void)? = nil) { - keyringService.addAccount(name, coin: coin) { success in + keyringService.addAccount( + coin, + keyringId: coin.keyringId, + accountName: name + ) { accountInfo in self.updateKeyringInfo() - completion?(success) + completion?(accountInfo != nil) } } @@ -351,7 +357,10 @@ public class KeyringStore: ObservableObject { } func removeSecondaryAccount(for account: BraveWallet.AccountInfo, password: String, completion: ((Bool) -> Void)? = nil) { - keyringService.removeImportedAccount(account.coin, keyringId: account.keyringId, address: account.address, password: password) { success in + keyringService.removeAccount( + account.accountId, + password: password + ) { success in completion?(success) if success { self.updateKeyringInfo() @@ -364,15 +373,11 @@ public class KeyringStore: ObservableObject { self.updateKeyringInfo() completion?(success) } - if account.isImported { - keyringService.setKeyringImportedAccountName(account.coin, keyringId: account.keyringId, address: account.address, name: name, completion: handler) - } else { - keyringService.setKeyringDerivedAccountName(account.coin, keyringId: account.keyringId, address: account.address, name: name, completion: handler) - } + keyringService.setAccountName(account.accountId, name: name, completion: handler) } func privateKey(for account: BraveWallet.AccountInfo, password: String, completion: @escaping (String?) -> Void) { - keyringService.encodePrivateKey(forExport: account.coin, keyringId: account.keyringId, address: account.address, password: password, completion: { key in + keyringService.encodePrivateKey(forExport: account.accountId, password: password, completion: { key in completion(key.isEmpty ? nil : key) }) } @@ -429,21 +434,21 @@ extension KeyringStore: BraveWalletKeyringServiceObserver { updateKeyringInfo() } - public func keyringCreated(_ keyringId: String) { + public func keyringCreated(_ keyringId: BraveWallet.KeyringId) { Task { @MainActor in let newKeyring = await keyringService.keyringInfo(keyringId) if let newKeyringCoin = newKeyring.coin { let selectedAccount = await keyringService.selectedAccount(newKeyringCoin) // if the new Keyring doesn't have a selected account, select the first account if selectedAccount == nil, let newAccount = newKeyring.accountInfos.first { - await keyringService.setSelectedAccount(newAccount.coin, keyringId: newAccount.keyringId, address: newAccount.address) + await keyringService.setSelectedAccount(newAccount.accountId) } } updateKeyringInfo() } } - public func keyringRestored(_ keyringId: String) { + public func keyringRestored(_ keyringId: BraveWallet.KeyringId) { updateKeyringInfo() } diff --git a/Sources/BraveWallet/Crypto/Stores/NFTStore.swift b/Sources/BraveWallet/Crypto/Stores/NFTStore.swift index d73522a971ed..3a61fa7737f1 100644 --- a/Sources/BraveWallet/Crypto/Stores/NFTStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/NFTStore.swift @@ -183,9 +183,9 @@ extension NFTStore: BraveWalletKeyringServiceObserver { } public func backedUp() { } - public func keyringCreated(_ keyringId: String) { + public func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - public func keyringRestored(_ keyringId: String) { + public func keyringRestored(_ keyringId: BraveWallet.KeyringId) { } public func locked() { } diff --git a/Sources/BraveWallet/Crypto/Stores/NetworkStore.swift b/Sources/BraveWallet/Crypto/Stores/NetworkStore.swift index 45fd2677486e..52e7584f800a 100644 --- a/Sources/BraveWallet/Crypto/Stores/NetworkStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/NetworkStore.swift @@ -330,10 +330,10 @@ extension NetworkStore: BraveWalletKeyringServiceObserver { } } - public func keyringCreated(_ keyringId: String) { + public func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - public func keyringRestored(_ keyringId: String) { + public func keyringRestored(_ keyringId: BraveWallet.KeyringId) { } public func keyringReset() { diff --git a/Sources/BraveWallet/Crypto/Stores/PortfolioStore.swift b/Sources/BraveWallet/Crypto/Stores/PortfolioStore.swift index dec691684b1f..bc0d6b60d83c 100644 --- a/Sources/BraveWallet/Crypto/Stores/PortfolioStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/PortfolioStore.swift @@ -315,9 +315,9 @@ extension PortfolioStore: BraveWalletKeyringServiceObserver { } public func backedUp() { } - public func keyringCreated(_ keyringId: String) { + public func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - public func keyringRestored(_ keyringId: String) { + public func keyringRestored(_ keyringId: BraveWallet.KeyringId) { } public func locked() { } diff --git a/Sources/BraveWallet/Crypto/Stores/SendTokenStore.swift b/Sources/BraveWallet/Crypto/Stores/SendTokenStore.swift index c7640a2e3195..a51b41935ce9 100644 --- a/Sources/BraveWallet/Crypto/Stores/SendTokenStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/SendTokenStore.swift @@ -195,7 +195,7 @@ public class SendTokenStore: ObservableObject { let selectedAccount = await self.keyringService.selectedAccount(selectedCoin) if selectedAccount != account.address { - _ = await self.keyringService.setSelectedAccount(account.coin, keyringId: account.keyringId, address: account.address) + _ = await self.keyringService.setSelectedAccount(account.accountId) } let selectedChain = await rpcService.network(selectedCoin, origin: nil) @@ -617,10 +617,10 @@ extension SendTokenStore: BraveWalletKeyringServiceObserver { public func keyringReset() { } - public func keyringCreated(_ keyringId: String) { + public func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - public func keyringRestored(_ keyringId: String) { + public func keyringRestored(_ keyringId: BraveWallet.KeyringId) { } public func locked() { diff --git a/Sources/BraveWallet/Crypto/Stores/SettingsStore.swift b/Sources/BraveWallet/Crypto/Stores/SettingsStore.swift index cb6c41de25bb..58f43bd9ed85 100644 --- a/Sources/BraveWallet/Crypto/Stores/SettingsStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/SettingsStore.swift @@ -157,10 +157,10 @@ public class SettingsStore: ObservableObject { } extension SettingsStore: BraveWalletKeyringServiceObserver { - public func keyringCreated(_ keyringId: String) { + public func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - public func keyringRestored(_ keyringId: String) { + public func keyringRestored(_ keyringId: BraveWallet.KeyringId) { } public func keyringReset() { diff --git a/Sources/BraveWallet/Crypto/Stores/SwapTokenStore.swift b/Sources/BraveWallet/Crypto/Stores/SwapTokenStore.swift index 9d2fdad179ac..82e5874941dd 100644 --- a/Sources/BraveWallet/Crypto/Stores/SwapTokenStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/SwapTokenStore.swift @@ -893,10 +893,10 @@ extension SwapTokenStore: BraveWalletKeyringServiceObserver { public func keyringReset() { } - public func keyringCreated(_ keyringId: String) { + public func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - public func keyringRestored(_ keyringId: String) { + public func keyringRestored(_ keyringId: BraveWallet.KeyringId) { } public func locked() { diff --git a/Sources/BraveWallet/Crypto/Stores/TransactionsActivityStore.swift b/Sources/BraveWallet/Crypto/Stores/TransactionsActivityStore.swift index b6917229eafd..13f880a890ea 100644 --- a/Sources/BraveWallet/Crypto/Stores/TransactionsActivityStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/TransactionsActivityStore.swift @@ -190,9 +190,9 @@ class TransactionsActivityStore: ObservableObject { } extension TransactionsActivityStore: BraveWalletKeyringServiceObserver { - func keyringCreated(_ keyringId: String) { } + func keyringCreated(_ keyringId: BraveWallet.KeyringId) { } - func keyringRestored(_ keyringId: String) { } + func keyringRestored(_ keyringId: BraveWallet.KeyringId) { } func keyringReset() { } diff --git a/Sources/BraveWallet/Crypto/Stores/UserAssetsStore.swift b/Sources/BraveWallet/Crypto/Stores/UserAssetsStore.swift index c62935ee448c..8f675fd29688 100644 --- a/Sources/BraveWallet/Crypto/Stores/UserAssetsStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/UserAssetsStore.swift @@ -231,11 +231,11 @@ public class UserAssetsStore: ObservableObject { } extension UserAssetsStore: BraveWalletKeyringServiceObserver { - public func keyringCreated(_ keyringId: String) { + public func keyringCreated(_ keyringId: BraveWallet.KeyringId) { update() } - public func keyringRestored(_ keyringId: String) { + public func keyringRestored(_ keyringId: BraveWallet.KeyringId) { } public func keyringReset() { diff --git a/Sources/BraveWallet/Extensions/BraveWalletExtensions.swift b/Sources/BraveWallet/Extensions/BraveWalletExtensions.swift index c9db8cc53d5e..92f276bda9b6 100644 --- a/Sources/BraveWallet/Extensions/BraveWalletExtensions.swift +++ b/Sources/BraveWallet/Extensions/BraveWalletExtensions.swift @@ -92,19 +92,30 @@ extension BraveWallet.OriginInfo { } } +extension BraveWallet.AccountId { + /// Two `AccountIds` equal iff their `unique_key` fields equal. Use this to + /// check AccountIds for equality or to store as string keys. Persist with + /// caution as format may change. + /// https://github.com/brave/brave-core/pull/18767 + open override func isEqual(_ object: Any?) -> Bool { + guard let object = object as? BraveWallet.AccountId else { return false } + return self.uniqueKey == object.uniqueKey + } +} + extension BraveWallet.CoinType { - public var keyringId: String { + public var keyringId: BraveWallet.KeyringId { switch self { case .eth: - return BraveWallet.DefaultKeyringId + return BraveWallet.KeyringId.default case .sol: - return BraveWallet.SolanaKeyringId + return BraveWallet.KeyringId.solana case .fil: - return BraveWallet.FilecoinKeyringId + return BraveWallet.KeyringId.filecoin case .btc: - return BraveWallet.BitcoinKeyring84Id + return BraveWallet.KeyringId.bitcoin84 @unknown default: - return BraveWallet.DefaultKeyringId + return BraveWallet.KeyringId.default } } diff --git a/Sources/BraveWallet/Extensions/BraveWalletSwiftUIExtensions.swift b/Sources/BraveWallet/Extensions/BraveWalletSwiftUIExtensions.swift index 31c2f1f6390b..bd1bb0880330 100644 --- a/Sources/BraveWallet/Extensions/BraveWalletSwiftUIExtensions.swift +++ b/Sources/BraveWallet/Extensions/BraveWalletSwiftUIExtensions.swift @@ -12,7 +12,16 @@ extension BraveWallet.AccountInfo: Identifiable { address } public var isPrimary: Bool { - !isImported + // no hardware support on iOS + accountId.kind != .imported + } + + public var isImported: Bool { + accountId.kind == .imported + } + + public var coin: BraveWallet.CoinType { + accountId.coin } } diff --git a/Sources/BraveWallet/Panels/WalletPanelView.swift b/Sources/BraveWallet/Panels/WalletPanelView.swift index bef91072f593..a0490266df46 100644 --- a/Sources/BraveWallet/Panels/WalletPanelView.swift +++ b/Sources/BraveWallet/Panels/WalletPanelView.swift @@ -39,7 +39,8 @@ public struct WalletPanelContainerView: View { private var visibleScreen: VisibleScreen { let keyring = keyringStore.defaultKeyring // check if we are still fetching the `defaultKeyring` - if keyringStore.defaultKeyring.id.isEmpty { + if keyringStore.defaultKeyring.id == .default, + keyringStore.defaultKeyring.accountInfos.isEmpty { return .loading } // keyring fetched, check if user has created a wallet diff --git a/Sources/BraveWallet/Preview Content/MockBlockchainRegistry.swift b/Sources/BraveWallet/Preview Content/MockBlockchainRegistry.swift index 771929f8e9f0..718ae27e5e63 100644 --- a/Sources/BraveWallet/Preview Content/MockBlockchainRegistry.swift +++ b/Sources/BraveWallet/Preview Content/MockBlockchainRegistry.swift @@ -67,4 +67,8 @@ class MockBlockchainRegistry: BraveWalletBlockchainRegistry { func onRampCurrencies(_ completion: @escaping ([BraveWallet.OnRampCurrency]) -> Void) { completion([]) } + + func topDapps(_ chainId: String, coin: BraveWallet.CoinType, completion: @escaping ([BraveWallet.Dapp]) -> Void) { + completion([]) + } } diff --git a/Sources/BraveWallet/Preview Content/MockBraveWalletService.swift b/Sources/BraveWallet/Preview Content/MockBraveWalletService.swift index e17650e6a1ff..78dc2a594ece 100644 --- a/Sources/BraveWallet/Preview Content/MockBraveWalletService.swift +++ b/Sources/BraveWallet/Preview Content/MockBraveWalletService.swift @@ -150,15 +150,15 @@ class MockBraveWalletService: BraveWalletBraveWalletService { self.coin = coin } - func addPermission(_ coin: BraveWallet.CoinType, origin: URLOrigin, account: String, completion: @escaping (Bool) -> Void) { + func addPermission(_ accountId: BraveWallet.AccountId, origin: URLOrigin, completion: @escaping (Bool) -> Void) { completion(false) } - func hasPermission(_ coin: BraveWallet.CoinType, origin: URLOrigin, account: String, completion: @escaping (Bool, Bool) -> Void) { + func hasPermission(_ accountId: BraveWallet.AccountId, origin: URLOrigin, completion: @escaping (Bool, Bool) -> Void) { completion(false, false) } - func resetPermission(_ coin: BraveWallet.CoinType, origin: URLOrigin, account: String, completion: @escaping (Bool) -> Void) { + func resetPermission(_ accountId: BraveWallet.AccountId, origin: URLOrigin, completion: @escaping (Bool) -> Void) { completion(false) } @@ -235,5 +235,9 @@ class MockBraveWalletService: BraveWalletBraveWalletService { func balanceScannerSupportedChains(_ completion: @escaping ([String]) -> Void) { completion([]) } + + func discoverEthAllowances(_ completion: @escaping ([BraveWallet.AllowanceInfo]) -> Void) { + completion([]) + } } #endif diff --git a/Sources/BraveWallet/Preview Content/MockContent.swift b/Sources/BraveWallet/Preview Content/MockContent.swift index fbe07f835524..05c37ba54c4c 100644 --- a/Sources/BraveWallet/Preview Content/MockContent.swift +++ b/Sources/BraveWallet/Preview Content/MockContent.swift @@ -131,11 +131,18 @@ extension BraveWallet.BlockchainToken { extension BraveWallet.AccountInfo { static var previewAccount: BraveWallet.AccountInfo { - let account = BraveWallet.AccountInfo() - account.name = "Account 1" - account.address = "0x879240B2D6179E9EC40BC2AFFF9E9EC40BC2AFFF" - account.keyringId = BraveWallet.DefaultKeyringId - return account + .init( + accountId: .init( + coin: .eth, + keyringId: BraveWallet.KeyringId.default, + kind: .derived, + address: "0x879240B2D6179E9EC40BC2AFFF9E9EC40BC2AFFF", + uniqueKey: "0x879240B2D6179E9EC40BC2AFFF9E9EC40BC2AFFF" + ), + address: "0x879240B2D6179E9EC40BC2AFFF9E9EC40BC2AFFF", + name: "Account 1", + hardware: nil + ) } } @@ -172,7 +179,8 @@ extension BraveWallet.TransactionInfo { confirmedTime: Date(timeIntervalSince1970: 1636402508), // Monday, November 8, 2021 8:15:08 PM originInfo: .init(), groupId: nil, - chainId: BraveWallet.MainnetChainId + chainId: BraveWallet.MainnetChainId, + effectiveRecipient: "0x3f2116ef98fcab1a9c3c2d8988e0064ab59acfca" ) } static var previewConfirmedSwap: BraveWallet.TransactionInfo { @@ -210,7 +218,8 @@ extension BraveWallet.TransactionInfo { confirmedTime: Date(timeIntervalSince1970: 1636402508), // Monday, November 8, 2021 8:15:08 PM originInfo: .init(), groupId: nil, - chainId: BraveWallet.MainnetChainId + chainId: BraveWallet.MainnetChainId, + effectiveRecipient: "0xdef1c0ded9bec7f1a1670819833240f027b25eff" ) } /// Approved Unlimited DAI @@ -246,7 +255,8 @@ extension BraveWallet.TransactionInfo { confirmedTime: Date(timeIntervalSince1970: 1636402508), // Monday, November 8, 2021 8:15:08 PM originInfo: .init(), groupId: nil, - chainId: BraveWallet.MainnetChainId + chainId: BraveWallet.MainnetChainId, + effectiveRecipient: BraveWallet.BlockchainToken.previewDaiToken.contractAddress ) } /// Solana System Transfer @@ -283,7 +293,8 @@ extension BraveWallet.TransactionInfo { confirmedTime: Date(timeIntervalSince1970: 1667854820), // Monday, November 7, 2022 9:00:20 PM GMT originInfo: .init(), groupId: nil, - chainId: BraveWallet.SolanaMainnet + chainId: BraveWallet.SolanaMainnet, + effectiveRecipient: nil // Currently only available for ETH and FIL ) } /// Solana Token Transfer @@ -320,7 +331,8 @@ extension BraveWallet.TransactionInfo { confirmedTime: Date(timeIntervalSince1970: 1636402508), // Monday, November 8, 2021 8:15:08 PM originInfo: .init(), groupId: nil, - chainId: BraveWallet.SolanaMainnet + chainId: BraveWallet.SolanaMainnet, + effectiveRecipient: nil // Currently only available for ETH and FIL ) } static private func _transactionBase64ToData(_ base64String: String) -> [NSNumber] { diff --git a/Sources/BraveWallet/Preview Content/MockEthTxManagerProxy.swift b/Sources/BraveWallet/Preview Content/MockEthTxManagerProxy.swift index 063a2c23b1eb..490c28b41c76 100644 --- a/Sources/BraveWallet/Preview Content/MockEthTxManagerProxy.swift +++ b/Sources/BraveWallet/Preview Content/MockEthTxManagerProxy.swift @@ -52,6 +52,10 @@ class MockEthTxManagerProxy: BraveWalletEthTxManagerProxy { func makeErc1155Transfer(fromData from: String, to: String, tokenId: String, value: String, contractAddress: String, completion: @escaping (Bool, [NSNumber]) -> Void) { completion(false, []) } + + func makeFilForwarderTransferData(_ toAddressFil: String, completion: @escaping (Bool, [NSNumber]) -> Void) { + completion(false, []) + } } #endif diff --git a/Sources/BraveWallet/Preview Content/MockJsonRpcService.swift b/Sources/BraveWallet/Preview Content/MockJsonRpcService.swift index be14621dcffb..e879b02641f6 100644 --- a/Sources/BraveWallet/Preview Content/MockJsonRpcService.swift +++ b/Sources/BraveWallet/Preview Content/MockJsonRpcService.swift @@ -138,6 +138,10 @@ class MockJsonRpcService: BraveWalletJsonRpcService { func splTokenAccountBalance(_ walletAddress: String, tokenMintAddress: String, chainId: String, completion: @escaping (String, UInt8, String, BraveWallet.SolanaProviderError, String) -> Void) { completion("", 0, "", .internalError, "Error Message") } + + func splTokenBalances(_ pubkey: String, chainId: String, completion: @escaping ([BraveWallet.SPLTokenAmount], BraveWallet.SolanaProviderError, String) -> Void) { + completion([], .internalError, "Error Message") + } func erc1155TokenBalance(_ contractAddress: String, tokenId: String, accountAddress: String, chainId: String, completion: @escaping (String, BraveWallet.ProviderError, String) -> Void) { completion("", .internalError, "") diff --git a/Sources/BraveWallet/Preview Content/MockKeyringService.swift b/Sources/BraveWallet/Preview Content/MockKeyringService.swift index b4001de6d9bd..ff1d97124fea 100644 --- a/Sources/BraveWallet/Preview Content/MockKeyringService.swift +++ b/Sources/BraveWallet/Preview Content/MockKeyringService.swift @@ -11,7 +11,7 @@ import BraveCore /// /// - note: Do not use this directly, use ``CryptoKeyringStore.previewStore`` class MockKeyringService: BraveWalletKeyringService { - private var keyrings: [BraveWallet.KeyringInfo] = [.init(id: BraveWallet.DefaultKeyringId, isKeyringCreated: false, isLocked: false, isBackedUp: true, accountInfos: [])] + private var keyrings: [BraveWallet.KeyringInfo] = [.init(id: BraveWallet.KeyringId.default, isKeyringCreated: false, isLocked: false, isBackedUp: true, accountInfos: [])] private var privateKeys: [String: String] = [:] private var password = "" // Not a real phrase, has a duplicated word for testing @@ -19,7 +19,7 @@ class MockKeyringService: BraveWalletKeyringService { private var observers: NSHashTable = .weakObjects() private var selectedAccount: BraveWallet.AccountInfo? private var defaultKeyring: BraveWallet.KeyringInfo { - return keyrings.first(where: { $0.id == BraveWallet.DefaultKeyringId }) ?? keyrings[0] + return keyrings.first(where: { $0.id == BraveWallet.KeyringId.default }) ?? keyrings[0] } func add(_ observer: BraveWalletKeyringServiceObserver) { @@ -59,31 +59,45 @@ class MockKeyringService: BraveWalletKeyringService { return address } - func addAccount(_ accountName: String, coin: BraveWallet.CoinType, completion: @escaping (Bool) -> Void) { - let info = BraveWallet.AccountInfo() - info.name = accountName - info.address = nextAddress() + func addAccount(_ coin: BraveWallet.CoinType, keyringId: BraveWallet.KeyringId, accountName: String, completion: @escaping (BraveWallet.AccountInfo?) -> Void) { + let address = nextAddress() + let info = BraveWallet.AccountInfo( + accountId: .init( + coin: coin, + keyringId: keyringId, + kind: .imported, + address: address, + uniqueKey: address + ), + address: address, + name: accountName, + hardware: nil + ) defaultKeyring.accountInfos.append(info) observers.allObjects.forEach { $0.accountsChanged() } - completion(true) + completion(info) } func createWallet(_ password: String, completion: @escaping (String) -> Void) { defaultKeyring.isKeyringCreated = true defaultKeyring.isLocked = false self.password = password - addAccount("Account 1", coin: .eth) { [self] _ in - selectedAccount = defaultKeyring.accountInfos.first - } - observers.allObjects.forEach { - $0.keyringCreated(BraveWallet.DefaultKeyringId) + self.addAccount( + .eth, + keyringId: BraveWallet.KeyringId.default, + accountName: "Account 1" + ) { [self] accountInfo in + selectedAccount = accountInfo + observers.allObjects.forEach { + $0.keyringCreated(BraveWallet.KeyringId.default) + } + completion(mnemonic) } - completion(mnemonic) } - func keyringInfo(_ keyringId: String, completion: @escaping (BraveWallet.KeyringInfo) -> Void) { + func keyringInfo(_ keyringId: BraveWallet.KeyringId, completion: @escaping (BraveWallet.KeyringInfo) -> Void) { let keyringInfo = keyrings.first(where: { $0.id == keyringId }) ?? keyrings[0] completion(keyringInfo.copy() as! BraveWallet.KeyringInfo) // swiftlint:disable:this force_cast } @@ -133,7 +147,7 @@ class MockKeyringService: BraveWalletKeyringService { self.password = password // Test store does not test phrase validity observers.allObjects.forEach { - $0.keyringRestored(BraveWallet.DefaultKeyringId) + $0.keyringRestored(BraveWallet.KeyringId.default) } completion(true) } @@ -176,10 +190,19 @@ class MockKeyringService: BraveWalletKeyringService { } func importAccount(_ accountName: String, privateKey: String, completion: @escaping (Bool, String) -> Void) { - let info = BraveWallet.AccountInfo() - info.name = accountName - info.address = nextImportedAddress() - info.isImported = true + let address = nextImportedAddress() + let info = BraveWallet.AccountInfo( + accountId: .init( + coin: .eth, + keyringId: BraveWallet.KeyringId.default, + kind: .imported, + address: address, + uniqueKey: address + ), + address: address, + name: accountName, + hardware: nil + ) privateKeys[info.address] = privateKey defaultKeyring.accountInfos.append(info) observers.allObjects.forEach { @@ -204,7 +227,7 @@ class MockKeyringService: BraveWalletKeyringService { completion(false, "") } - func encodePrivateKey(forExport coin: BraveWallet.CoinType, keyringId: String, address: String, password: String, completion: @escaping (String) -> Void) { + func encodePrivateKey(forExport accountId: BraveWallet.AccountId, password: String, completion: @escaping (String) -> Void) { completion("807df4db569fab37cdf475a4bda779897f0f3dd9c5d90a2cb953c88ef762fd96") } @@ -216,8 +239,8 @@ class MockKeyringService: BraveWalletKeyringService { } } - func removeImportedAccount(_ coin: BraveWallet.CoinType, keyringId: String, address: String, password: String, completion: @escaping (Bool) -> Void) { - guard let index = defaultKeyring.accountInfos.firstIndex(where: { $0.address == address }) else { + func removeAccount(_ accountId: BraveWallet.AccountId, password: String, completion: @escaping (Bool) -> Void) { + guard let index = defaultKeyring.accountInfos.firstIndex(where: { $0.address == accountId.address }) else { completion(false) return } @@ -242,8 +265,8 @@ class MockKeyringService: BraveWalletKeyringService { completion(selectedAccount?.address) } - func setSelectedAccount(_ coin: BraveWallet.CoinType, keyringId: String, address: String, completion: @escaping (Bool) -> Void) { - guard let account = defaultKeyring.accountInfos.first(where: { $0.address == address }) else { + func setSelectedAccount(_ accountId: BraveWallet.AccountId, completion: @escaping (Bool) -> Void) { + guard let account = defaultKeyring.accountInfos.first(where: { $0.address == accountId.address }) else { completion(false) return } @@ -274,20 +297,9 @@ class MockKeyringService: BraveWalletKeyringService { completion(false) } - func setKeyringDerivedAccountName(_ coin: BraveWallet.CoinType, keyringId: String, address: String, name: String, completion: @escaping (Bool) -> Void) { - keyringInfo(keyringId) { keyring in - if let account = keyring.accountInfos.first(where: { $0.address == address }) { - account.name = name - completion(true) - return - } - completion(false) - } - } - - func setKeyringImportedAccountName(_ coin: BraveWallet.CoinType, keyringId: String, address: String, name: String, completion: @escaping (Bool) -> Void) { - keyringInfo(keyringId) { keyring in - if let account = keyring.accountInfos.first(where: { $0.address == address && $0.isImported }) { + 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 @@ -296,15 +308,8 @@ class MockKeyringService: BraveWalletKeyringService { } } - func keyringsInfo(_ keyrings: [String], completion: @escaping ([BraveWallet.KeyringInfo]) -> Void) { - var keyringInfo = [BraveWallet.KeyringInfo]() - for item in self.keyrings where keyrings.contains(item.id) { - keyringInfo.append(item.copy() as! BraveWallet.KeyringInfo) // swiftlint:disable:this force_cast - } - completion(keyringInfo) - } - - func addHardwareAccounts(_ info: [BraveWallet.HardwareWalletAccount]) { + func addHardwareAccounts(_ info: [BraveWallet.HardwareWalletAccount]) async -> [BraveWallet.AccountInfo]? { + nil } func setHardwareAccountName(_ coin: BraveWallet.CoinType, keyringId: String, address: String, name: String, completion: @escaping (Bool) -> Void) { @@ -326,8 +331,20 @@ class MockKeyringService: BraveWalletKeyringService { completion("") } - func addBitcoinAccount(_ accountName: String, networkId: String, keyringId: String, completion: @escaping (Bool) -> Void) { - completion(false) + func addBitcoinAccount(_ accountName: String, networkId: String, keyringId: BraveWallet.KeyringId, completion: @escaping (BraveWallet.AccountInfo?) -> Void) { + let bitcoinAccount = BraveWallet.AccountInfo( + accountId: .init( + coin: .btc, + keyringId: keyringId, + kind: .derived, + address: "btc1", + uniqueKey: "btc1" + ), + address: "btc1", + name: "BTC Account 1", + hardware: nil + ) + completion(bitcoinAccount) } func allAccounts(_ completion: @escaping (BraveWallet.AllAccountsInfo) -> Void) { @@ -337,36 +354,48 @@ class MockKeyringService: BraveWalletKeyringService { extension BraveWallet.AccountInfo { static let mockEthAccount: BraveWallet.AccountInfo = .init( + accountId: .init( + coin: .eth, + keyringId: BraveWallet.KeyringId.default, + kind: .derived, + address: "mock_eth_id", + uniqueKey: "mock_eth_id" + ), address: "mock_eth_id", name: "mock_eth_name", - isImported: false, - hardware: nil, - coin: .eth, - keyringId: BraveWallet.DefaultKeyringId + hardware: nil ) static let mockSolAccount: BraveWallet.AccountInfo = .init( + accountId: .init( + coin: .sol, + keyringId: BraveWallet.KeyringId.solana, + kind: .derived, + address: "mock_sol_id", + uniqueKey: "mock_sol_id" + ), address: "mock_sol_id", name: "mock_sol_name", - isImported: false, - hardware: nil, - coin: .sol, - keyringId: BraveWallet.SolanaKeyringId + hardware: nil ) static let mockFilAccount: BraveWallet.AccountInfo = .init( + accountId: .init( + coin: .fil, + keyringId: BraveWallet.KeyringId.filecoin, + kind: .derived, + address: "mock_fil_id", + uniqueKey: "mock_fil_id" + ), address: "mock_fil_id", name: "mock_fil_name", - isImported: false, - hardware: nil, - coin: .fil, - keyringId: BraveWallet.FilecoinKeyringId + hardware: nil ) } extension BraveWallet.KeyringInfo { static let mockDefaultKeyringInfo: BraveWallet.KeyringInfo = .init( - id: BraveWallet.DefaultKeyringId, + id: BraveWallet.KeyringId.default, isKeyringCreated: true, isLocked: false, isBackedUp: false, @@ -374,7 +403,7 @@ extension BraveWallet.KeyringInfo { ) static let mockSolanaKeyringInfo: BraveWallet.KeyringInfo = .init( - id: BraveWallet.SolanaKeyringId, + id: BraveWallet.KeyringId.solana, isKeyringCreated: true, isLocked: false, isBackedUp: false, @@ -382,7 +411,7 @@ extension BraveWallet.KeyringInfo { ) static let mockFilecoinKeyringInfo: BraveWallet.KeyringInfo = .init( - id: BraveWallet.FilecoinKeyringId, + id: BraveWallet.KeyringId.filecoin, isKeyringCreated: true, isLocked: false, isBackedUp: false, diff --git a/Tests/BraveWalletTests/KeyringStoreTests.swift b/Tests/BraveWalletTests/KeyringStoreTests.swift index 49b2a1ab28e8..107e008cce5b 100644 --- a/Tests/BraveWalletTests/KeyringStoreTests.swift +++ b/Tests/BraveWalletTests/KeyringStoreTests.swift @@ -21,11 +21,11 @@ class KeyringStoreTests: XCTestCase { let keyringService = BraveWallet.TestKeyringService() keyringService._keyringInfo = { keyringId, completion in switch keyringId { - case BraveWallet.DefaultKeyringId: + case BraveWallet.KeyringId.default: completion(.mockDefaultKeyringInfo) - case BraveWallet.SolanaKeyringId: + case BraveWallet.KeyringId.solana: completion(.mockSolanaKeyringInfo) - case BraveWallet.FilecoinKeyringId: + case BraveWallet.KeyringId.filecoin: completion(.mockFilecoinKeyringInfo) default: completion(.init()) @@ -34,7 +34,7 @@ class KeyringStoreTests: XCTestCase { keyringService._addObserver = { _ in } keyringService._isLocked = { $0(false) } keyringService._selectedAccount = { $1(currentSelectedAccount.address) } - keyringService._setSelectedAccount = { $3(true) } + keyringService._setSelectedAccount = { $1(true) } let rpcService = BraveWallet.TestJsonRpcService() rpcService._addObserver = { _ in } diff --git a/Tests/BraveWalletTests/NetworkSelectionStoreTests.swift b/Tests/BraveWalletTests/NetworkSelectionStoreTests.swift index 019674f0edf2..48d947d9251b 100644 --- a/Tests/BraveWalletTests/NetworkSelectionStoreTests.swift +++ b/Tests/BraveWalletTests/NetworkSelectionStoreTests.swift @@ -27,7 +27,7 @@ import Preferences keyringService._keyringInfo = { keyringId, completion in let isEthereumKeyringId = keyringId == BraveWallet.CoinType.eth.keyringId let keyring: BraveWallet.KeyringInfo = .init( - id: BraveWallet.DefaultKeyringId, + id: BraveWallet.KeyringId.default, isKeyringCreated: true, isLocked: false, isBackedUp: true, diff --git a/Tests/BraveWalletTests/NetworkStoreTests.swift b/Tests/BraveWalletTests/NetworkStoreTests.swift index 8ad060a32b38..61917e1c49b2 100644 --- a/Tests/BraveWalletTests/NetworkStoreTests.swift +++ b/Tests/BraveWalletTests/NetworkStoreTests.swift @@ -25,7 +25,7 @@ import BraveCore keyringService._keyringInfo = { keyringId, completion in let isEthereumKeyringId = keyringId == BraveWallet.CoinType.eth.keyringId let keyring: BraveWallet.KeyringInfo = .init( - id: BraveWallet.DefaultKeyringId, + id: BraveWallet.KeyringId.default, isKeyringCreated: true, isLocked: false, isBackedUp: true, diff --git a/Tests/BraveWalletTests/PortfolioStoreTests.swift b/Tests/BraveWalletTests/PortfolioStoreTests.swift index d9ed7083ddb8..2eacd44127f5 100644 --- a/Tests/BraveWalletTests/PortfolioStoreTests.swift +++ b/Tests/BraveWalletTests/PortfolioStoreTests.swift @@ -82,9 +82,9 @@ class PortfolioStoreTests: XCTestCase { // setup test services let keyringService = BraveWallet.TestKeyringService() keyringService._keyringInfo = { keyringId, completion in - if keyringId == BraveWallet.DefaultKeyringId { + if keyringId == BraveWallet.KeyringId.default { let keyring: BraveWallet.KeyringInfo = .init( - id: BraveWallet.DefaultKeyringId, + id: BraveWallet.KeyringId.default, isKeyringCreated: true, isLocked: false, isBackedUp: true, @@ -93,7 +93,7 @@ class PortfolioStoreTests: XCTestCase { completion(keyring) } else { let keyring: BraveWallet.KeyringInfo = .init( - id: BraveWallet.SolanaKeyringId, + id: BraveWallet.KeyringId.solana, isKeyringCreated: true, isLocked: false, isBackedUp: true, diff --git a/Tests/BraveWalletTests/SelectAccountTokenStoreTests.swift b/Tests/BraveWalletTests/SelectAccountTokenStoreTests.swift index baa51c8e6d7e..fae3c244fa2a 100644 --- a/Tests/BraveWalletTests/SelectAccountTokenStoreTests.swift +++ b/Tests/BraveWalletTests/SelectAccountTokenStoreTests.swift @@ -52,12 +52,16 @@ import BraveCore ] private let mockEthAccount2: BraveWallet.AccountInfo = .init( + accountId: .init( + coin: .eth, + keyringId: BraveWallet.KeyringId.default, + kind: .derived, + address: "mock_eth_id_2", + uniqueKey: "mock_eth_id_2" + ), address: "mock_eth_id_2", name: "Ethereum Account 2", - isImported: false, - hardware: nil, - coin: .eth, - keyringId: BraveWallet.DefaultKeyringId + hardware: nil ) private let formatter = WeiFormatter(decimalFormatStyle: .decimals(precision: 18)) @@ -102,9 +106,9 @@ import BraveCore let keyringService = BraveWallet.TestKeyringService() keyringService._keyringInfo = { keyringId, completion in - if keyringId == BraveWallet.DefaultKeyringId { + if keyringId == BraveWallet.KeyringId.default { let keyring: BraveWallet.KeyringInfo = .init( - id: BraveWallet.DefaultKeyringId, + id: BraveWallet.KeyringId.default, isKeyringCreated: true, isLocked: false, isBackedUp: true, @@ -113,7 +117,7 @@ import BraveCore completion(keyring) } else { let keyring: BraveWallet.KeyringInfo = .init( - id: BraveWallet.SolanaKeyringId, + id: BraveWallet.KeyringId.solana, isKeyringCreated: true, isLocked: false, isBackedUp: true, diff --git a/Tests/BraveWalletTests/SendTokenStoreTests.swift b/Tests/BraveWalletTests/SendTokenStoreTests.swift index a0ea01c35b02..9ba6915859ce 100644 --- a/Tests/BraveWalletTests/SendTokenStoreTests.swift +++ b/Tests/BraveWalletTests/SendTokenStoreTests.swift @@ -31,7 +31,7 @@ class SendTokenStoreTests: XCTestCase { let keyringService = BraveWallet.TestKeyringService() keyringService._addObserver = { _ in } keyringService._selectedAccount = { $1(accountAddress) } - keyringService._setSelectedAccount = { _, _, _, completion in completion(true) } + keyringService._setSelectedAccount = { _, completion in completion(true) } keyringService._checksumEthAddress = { address, completion in completion(address) } let rpcService = BraveWallet.TestJsonRpcService() rpcService._network = { $2(selectedNetwork) } @@ -1308,10 +1308,18 @@ class SendTokenStoreTests: XCTestCase { .copy(asVisibleAsset: true).then { $0.chainId = BraveWallet.GoerliChainId } - private lazy var account2: BraveWallet.AccountInfo = (account.copy() as! BraveWallet.AccountInfo).then { - $0.name = "Account 2" - $0.address = "0x2222222222179E9EC40BC2AFFF9E9EC40BC2AFFF" - } + private let account2: BraveWallet.AccountInfo = .init( + accountId: .init( + coin: .eth, + keyringId: BraveWallet.KeyringId.default, + kind: .derived, + address: "mock_eth_id_2", + uniqueKey: "mock_eth_id_2" + ), + address: "mock_eth_id_2", + name: "Ethereum Account 2", + hardware: nil + ) /// Test `didSelect(account:token:)` with a new token that is on the currently selected account and currently selected network. @MainActor func testDidSelectSameAccountSameNetwork() async { @@ -1371,9 +1379,9 @@ class SendTokenStoreTests: XCTestCase { selectedNetwork: .mockGoerli ) let setSelectedAccountExpectation = expectation(description: "setSelectedAccountExpectation") - keyringService._setSelectedAccount = { coin, keyringId, address, completion in + keyringService._setSelectedAccount = { accountId, completion in defer { setSelectedAccountExpectation.fulfill() } - XCTAssertEqual(address, self.account2.address) + XCTAssertEqual(accountId.address, self.account2.address) completion(true) } let store = SendTokenStore( @@ -1419,9 +1427,9 @@ class SendTokenStoreTests: XCTestCase { allNetworks: allNetworks ) let setSelectedAccountExpectation = expectation(description: "setSelectedAccountExpectation") - keyringService._setSelectedAccount = { coin, keyringId, address, completion in + keyringService._setSelectedAccount = { accountId, completion in defer { setSelectedAccountExpectation.fulfill() } - XCTAssertEqual(address, self.account2.address) + XCTAssertEqual(accountId.address, self.account2.address) completion(true) } let setNetworkExpectation = expectation(description: "setNetworkExpectation") @@ -1485,9 +1493,9 @@ class SendTokenStoreTests: XCTestCase { allNetworks: allNetworks ) let setSelectedAccountExpectation = expectation(description: "setSelectedAccountExpectation") - keyringService._setSelectedAccount = { coin, keyringId, address, completion in + keyringService._setSelectedAccount = { accountId, completion in defer { setSelectedAccountExpectation.fulfill() } - XCTAssertEqual(address, BraveWallet.AccountInfo.mockSolAccount.address) + XCTAssertEqual(accountId.address, BraveWallet.AccountInfo.mockSolAccount.address) completion(true) } let setNetworkExpectation = expectation(description: "setNetworkExpectation") diff --git a/Tests/BraveWalletTests/SettingsStoreTests.swift b/Tests/BraveWalletTests/SettingsStoreTests.swift index 45a4b791dafd..d0f0c75889b8 100644 --- a/Tests/BraveWalletTests/SettingsStoreTests.swift +++ b/Tests/BraveWalletTests/SettingsStoreTests.swift @@ -22,7 +22,7 @@ class SettingsStoreTests: XCTestCase { let keyringService = BraveWallet.TestKeyringService() keyringService._keyringInfo = { _, completion in let keyring: BraveWallet.KeyringInfo = .init( - id: BraveWallet.DefaultKeyringId, + id: BraveWallet.KeyringId.default, isKeyringCreated: true, isLocked: false, isBackedUp: true, diff --git a/Tests/BraveWalletTests/TransactionConfirmationStoreTests.swift b/Tests/BraveWalletTests/TransactionConfirmationStoreTests.swift index 80c07ea052d0..25e3da70b1fc 100644 --- a/Tests/BraveWalletTests/TransactionConfirmationStoreTests.swift +++ b/Tests/BraveWalletTests/TransactionConfirmationStoreTests.swift @@ -95,7 +95,7 @@ import BraveCore isLocked: false, isBackedUp: true, accountInfos: []) - if id == BraveWallet.DefaultKeyringId { + if id == BraveWallet.KeyringId.default { keyring.accountInfos = accountInfos.filter { $0.coin == .eth } } else { keyring.accountInfos = accountInfos.filter { $0.coin == .sol } diff --git a/Tests/BraveWalletTests/TransactionParserTests.swift b/Tests/BraveWalletTests/TransactionParserTests.swift index f2e637044a04..b619340516f5 100644 --- a/Tests/BraveWalletTests/TransactionParserTests.swift +++ b/Tests/BraveWalletTests/TransactionParserTests.swift @@ -15,12 +15,16 @@ private extension BraveWallet.AccountInfo { coin: BraveWallet.CoinType = .eth ) { self.init( + accountId: .init( + coin: coin, + keyringId: coin.keyringId, + kind: .derived, + address: address, + uniqueKey: address + ), address: address, name: name, - isImported: false, - hardware: nil, - coin: .eth, - keyringId: BraveWallet.DefaultKeyringId + hardware: nil ) } } @@ -86,7 +90,8 @@ class TransactionParserTests: XCTestCase { confirmedTime: Date(), originInfo: nil, groupId: nil, - chainId: BraveWallet.MainnetChainId + chainId: BraveWallet.MainnetChainId, + effectiveRecipient: transactionData.baseData.to ) let expectedParsedTransaction = ParsedTransaction( @@ -180,7 +185,8 @@ class TransactionParserTests: XCTestCase { confirmedTime: Date(), originInfo: nil, groupId: nil, - chainId: BraveWallet.MainnetChainId + chainId: BraveWallet.MainnetChainId, + effectiveRecipient: transactionData.baseData.to ) let expectedParsedTransaction = ParsedTransaction( @@ -265,7 +271,8 @@ class TransactionParserTests: XCTestCase { confirmedTime: Date(), originInfo: nil, groupId: nil, - chainId: BraveWallet.MainnetChainId + chainId: BraveWallet.MainnetChainId, + effectiveRecipient: transactionData.baseData.to ) let expectedParsedTransaction = ParsedTransaction( @@ -354,7 +361,8 @@ class TransactionParserTests: XCTestCase { confirmedTime: Date(), originInfo: nil, groupId: nil, - chainId: BraveWallet.MainnetChainId + chainId: BraveWallet.MainnetChainId, + effectiveRecipient: transactionData.baseData.to ) let expectedParsedTransaction = ParsedTransaction( @@ -439,7 +447,8 @@ class TransactionParserTests: XCTestCase { confirmedTime: Date(), originInfo: nil, groupId: nil, - chainId: BraveWallet.MainnetChainId + chainId: BraveWallet.MainnetChainId, + effectiveRecipient: transactionData.baseData.to ) let expectedParsedTransaction = ParsedTransaction( @@ -522,7 +531,8 @@ class TransactionParserTests: XCTestCase { confirmedTime: Date(), originInfo: nil, groupId: nil, - chainId: BraveWallet.MainnetChainId + chainId: BraveWallet.MainnetChainId, + effectiveRecipient: transactionData.baseData.to ) let expectedParsedTransaction = ParsedTransaction( @@ -609,7 +619,8 @@ class TransactionParserTests: XCTestCase { confirmedTime: Date(), originInfo: nil, groupId: nil, - chainId: BraveWallet.MainnetChainId + chainId: BraveWallet.MainnetChainId, + effectiveRecipient: transactionData.baseData.to ) let expectedParsedTransaction = ParsedTransaction( @@ -693,7 +704,8 @@ class TransactionParserTests: XCTestCase { confirmedTime: Date(), originInfo: nil, groupId: nil, - chainId: BraveWallet.MainnetChainId + chainId: BraveWallet.SolanaMainnet, + effectiveRecipient: nil ) let expectedParsedTransaction = ParsedTransaction( transaction: transaction, @@ -789,7 +801,8 @@ class TransactionParserTests: XCTestCase { confirmedTime: Date(), originInfo: nil, groupId: nil, - chainId: BraveWallet.MainnetChainId + chainId: BraveWallet.SolanaMainnet, + effectiveRecipient: nil ) let expectedParsedTransaction = ParsedTransaction( transaction: transaction, @@ -872,7 +885,8 @@ class TransactionParserTests: XCTestCase { confirmedTime: Date(), originInfo: nil, groupId: nil, - chainId: BraveWallet.MainnetChainId + chainId: BraveWallet.SolanaMainnet, + effectiveRecipient: nil ) let expectedParsedTransaction = ParsedTransaction( transaction: transaction, diff --git a/Tests/BraveWalletTests/TransactionsActivityStoreTests.swift b/Tests/BraveWalletTests/TransactionsActivityStoreTests.swift index 912acd7a1e48..23e721ddb7aa 100644 --- a/Tests/BraveWalletTests/TransactionsActivityStoreTests.swift +++ b/Tests/BraveWalletTests/TransactionsActivityStoreTests.swift @@ -38,7 +38,7 @@ class TransactionsActivityStoreTests: XCTestCase { let keyringService = BraveWallet.TestKeyringService() keyringService._addObserver = { _ in } keyringService._keyringInfo = { keyringId, completion in - if keyringId == BraveWallet.DefaultKeyringId { + if keyringId == BraveWallet.KeyringId.default { completion(.mockDefaultKeyringInfo) } else { completion(.mockSolanaKeyringInfo) diff --git a/package-lock.json b/package-lock.json index 3cf8bb527d70..3b506a3fcb5c 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.56.5/brave-core-ios-1.56.5.tgz", + "brave-core-ios": "https://github.com/brave/brave-browser/releases/download/v1.57.9/brave-core-ios-1.57.9.tgz", "leo-sf-symbols": "github:brave/leo-sf-symbols#60a41d77d4e58bd48284848a04ad3f9b79bf7daa", "page-metadata-parser": "^1.1.3", "webpack-cli": "^4.8.0" @@ -356,9 +356,9 @@ } }, "node_modules/brave-core-ios": { - "version": "1.56.5", - "resolved": "https://github.com/brave/brave-browser/releases/download/v1.56.5/brave-core-ios-1.56.5.tgz", - "integrity": "sha512-O+E7G9peq74XTkvMaxSbN4+qc/wIKKIfRJyr3JeWg4BVJZaaBdv47H2SQSK5XX9gHDN6wMa1Edj5h0CW0bKmww==", + "version": "1.57.9", + "resolved": "https://github.com/brave/brave-browser/releases/download/v1.57.9/brave-core-ios-1.57.9.tgz", + "integrity": "sha512-aE2rjvN9RF9GIC23gg6Im9TK88zv6dCb6jRqZ/pnJb0c7xqRCy2Fp6rclhTptkjzR9hvFMankSazt4nNoNZZZw==", "license": "ISC" }, "node_modules/browserslist": { @@ -1738,8 +1738,8 @@ } }, "brave-core-ios": { - "version": "https://github.com/brave/brave-browser/releases/download/v1.56.5/brave-core-ios-1.56.5.tgz", - "integrity": "sha512-O+E7G9peq74XTkvMaxSbN4+qc/wIKKIfRJyr3JeWg4BVJZaaBdv47H2SQSK5XX9gHDN6wMa1Edj5h0CW0bKmww==" + "version": "https://github.com/brave/brave-browser/releases/download/v1.57.9/brave-core-ios-1.57.9.tgz", + "integrity": "sha512-aE2rjvN9RF9GIC23gg6Im9TK88zv6dCb6jRqZ/pnJb0c7xqRCy2Fp6rclhTptkjzR9hvFMankSazt4nNoNZZZw==" }, "browserslist": { "version": "4.17.1", diff --git a/package.json b/package.json index d457e27a6755..f954ccc1d819 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.56.5/brave-core-ios-1.56.5.tgz", + "brave-core-ios": "https://github.com/brave/brave-browser/releases/download/v1.57.9/brave-core-ios-1.57.9.tgz", "leo-sf-symbols": "github:brave/leo-sf-symbols#60a41d77d4e58bd48284848a04ad3f9b79bf7daa", "page-metadata-parser": "^1.1.3", "webpack-cli": "^4.8.0"