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

Fix #8385: Bump BraveCore to v1.61.x #8386

Merged
merged 8 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,31 @@ class AdsNotificationHandler: BraveAdsNotificationHandler {
self.ads.notificationsHandler = self
}

func showNotification(_ notification: NotificationAd) {
func showNotificationAd(_ notification: NotificationAd) {
guard let presentingController = presentingController else { return }

let rewardsNotification = RewardsNotification(ad: notification) { [weak self] action in
guard let self = self else { return }
switch action {
case .opened:
self.ads.reportNotificationAdEvent(notification.placementID, eventType: .clicked, completion: { _ in })
self.ads.triggerNotificationAdEvent(notification.placementID, eventType: .viewed, completion: { _ in })
case .dismissed:
self.ads.reportNotificationAdEvent(notification.placementID, eventType: .dismissed, completion: { _ in })
self.ads.triggerNotificationAdEvent(notification.placementID, eventType: .dismissed, completion: { _ in })
case .timedOut:
self.ads.reportNotificationAdEvent(notification.placementID, eventType: .timedOut, completion: { _ in })
self.ads.triggerNotificationAdEvent(notification.placementID, eventType: .timedOut, completion: { _ in })
}
self.actionOccured?(notification, action)
}

ads.reportNotificationAdEvent(notification.placementID, eventType: .viewed, completion: { _ in })
ads.triggerNotificationAdEvent(notification.placementID, eventType: .viewed, completion: { _ in })
notificationsPresenter?.display(notification: rewardsNotification, from: presentingController)
}

func clearNotification(withIdentifier identifier: String) {
func closeNotificationAd(_ identifier: String) {
notificationsPresenter?.removeNotification(with: identifier)
}

func shouldShowNotifications() -> Bool {
func canShowNotificationAds() -> Bool {
guard let presentingController = presentingController,
let rootVC = presentingController.currentScene?.browserViewController
else { return false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ extension Tab: BraveWalletProviderDelegate {
let origin = getOrigin()

// check if we receive account creation request without a wallet setup
let keyring = await keyringService.keyringInfo(BraveWallet.KeyringId.default)
if !keyring.isKeyringCreated {
let isWalletCreated = await keyringService.isWalletCreated()
if !isWalletCreated {
// Wallet is not setup. User must onboard / setup wallet first.
self.tabDelegate?.showWalletNotification(self, origin: origin)
return
Expand Down Expand Up @@ -579,13 +579,13 @@ extension Tab: BraveWalletSolanaEventsListener {
}

extension Tab: BraveWalletKeyringServiceObserver {
func keyringCreated(_ keyringId: BraveWallet.KeyringId) {
func walletCreated() {
}

func walletRestored() {
}

func keyringReset() {
func walletReset() {
reload()
tabDelegate?.updateURLBarWalletButton()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,11 @@ class NewTabPageViewController: UIViewController {
if let eventType {
p3aHelper.recordEvent(eventType, on: sponsoredBackground)
}
rewards.ads.reportNewTabPageAdEvent(
rewards.ads.triggerNewTabPageAdEvent(
background.wallpaperId.uuidString,
creativeInstanceId: sponsoredBackground.creativeInstanceId,
eventType: event,
completion: { _ in }
)
completion: { _ in })
}
}

Expand Down Expand Up @@ -619,12 +618,10 @@ class NewTabPageViewController: UIViewController {
let item = context.item
if !switchingToPrivateMode, item.content.contentType == .partner,
let creativeInstanceID = item.content.creativeInstanceID {
rewards.ads.reportPromotedContentAdEvent(
rewards.ads.triggerPromotedContentAdEvent(
item.content.urlHash,
creativeInstanceId: creativeInstanceID,
eventType: .clicked,
completion: { _ in }
)
eventType: .clicked, completion: { _ in })
}
if switchingToPrivateMode, Preferences.Privacy.privateBrowsingLock.value {
self.askForLocalAuthentication { [weak self] success, error in
Expand Down Expand Up @@ -660,12 +657,11 @@ class NewTabPageViewController: UIViewController {
case .inlineContentAdAction(.opened(let inNewTab, let switchingToPrivateMode), let ad):
guard let url = ad.targetURL.asURL else { return }
if !switchingToPrivateMode {
rewards.ads.reportInlineContentAdEvent(
rewards.ads.triggerInlineContentAdEvent(
ad.placementID,
creativeInstanceId: ad.creativeInstanceID,
eventType: .clicked,
completion: { _ in }
)
completion: { _ in })
}
delegate?.navigateToInput(
url.absoluteString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,20 @@ class BraveNewsSectionProvider: NSObject, NTPObservableSectionProvider {
if case .partner(let item) = card,
let creativeInstanceID = item.content.creativeInstanceID {
iabTrackedCellContexts[indexPath] = .init(collectionView: collectionView) { [weak self] in
self?.rewards.ads.reportPromotedContentAdEvent(
self?.rewards.ads.triggerPromotedContentAdEvent(
item.content.urlHash,
creativeInstanceId: creativeInstanceID,
eventType: .viewed,
completion: { _ in }
)
completion: { _ in })
}
}
if case .ad(let ad) = card {
iabTrackedCellContexts[indexPath] = .init(collectionView: collectionView) { [weak self] in
self?.rewards.ads.reportInlineContentAdEvent(
self?.rewards.ads.triggerInlineContentAdEvent(
ad.placementID,
creativeInstanceId: ad.creativeInstanceID,
eventType: .viewed,
completion: { _ in }
)
completion: { _ in })
self?.recordWeeklyAdsViewedP3A(adViewed: true)
}
}
Expand Down
39 changes: 17 additions & 22 deletions Sources/Brave/Frontend/Rewards/BraveRewards.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public class BraveRewards: NSObject {
)
}
// If ads is already initialized just toggle rewards ads and update the wallet info
if self.ads.isAdsServiceRunning() {
if self.ads.isServiceRunning() {
if let walletInfo {
self.ads.updateWalletInfo(walletInfo.paymentId, base64Seed: walletInfo.recoverySeed)
self.ads.notifyRewardsWalletDidUpdate(walletInfo.paymentId, base64Seed: walletInfo.recoverySeed)
}
if let toggleAds {
self.ads.isEnabled = toggleAds
Expand All @@ -98,14 +98,14 @@ public class BraveRewards: NSObject {
private var braveNewsObservation: AnyCancellable?

private var shouldShutdownAds: Bool {
ads.isAdsServiceRunning() && !ads.isEnabled && !Preferences.BraveNews.isEnabled.value
ads.isServiceRunning() && !ads.isEnabled && !Preferences.BraveNews.isEnabled.value
}

/// Propose that the ads service should be shutdown based on whether or not that all features
/// that use it are disabled
private func proposeAdsShutdown() {
if !shouldShutdownAds { return }
ads.shutdown {
ads.shutdownService {
self.ads = BraveAds(stateStoragePath: self.configuration.storageURL.appendingPathComponent("ads").path)
}
}
Expand Down Expand Up @@ -160,8 +160,8 @@ public class BraveRewards: NSObject {
try? FileManager.default.removeItem(
at: configuration.storageURL.appendingPathComponent("ledger")
)
if ads.isAdsServiceRunning(), !Preferences.BraveNews.isEnabled.value {
ads.shutdown { [self] in
if ads.isServiceRunning(), !Preferences.BraveNews.isEnabled.value {
ads.shutdownService { [self] in
try? FileManager.default.removeItem(
at: configuration.storageURL.appendingPathComponent("ads")
)
Expand All @@ -186,8 +186,8 @@ public class BraveRewards: NSObject {
rewardsAPI?.selectedTabId = UInt32(tabId)
tabRetrieved(tabId, url: url, html: nil)
}
if ads.isAdsServiceRunning() && !isPrivate {
ads.reportTabUpdated(tabId, url: url, redirectedFrom: tab.redirectURLs, isSelected: isSelected)
if ads.isServiceRunning() && !isPrivate {
ads.notifyTabDidChange(tabId, url: url, redirectChain: tab.redirectURLs, isSelected: isSelected)
}
}

Expand All @@ -203,14 +203,9 @@ public class BraveRewards: NSObject {
adsInnerText: String?
) {
tabRetrieved(tabId, url: url, html: html)
if let innerText = adsInnerText, ads.isAdsServiceRunning() {
ads.reportLoadedPage(
with: url,
redirectedFrom: redirectionURLs ?? [],
html: html,
innerText: innerText,
tabId: tabId
)
if let innerText = adsInnerText, ads.isServiceRunning() {
ads.notifyTabHtmlContentDidChange(tabId, url: url, redirectChain: redirectionURLs ?? [], html: html)
ads.notifyTabTextContentDidChange(tabId, url: url, redirectChain: redirectionURLs ?? [], text: innerText)
}
rewardsAPI?.reportLoadedPage(url: url, tabId: UInt32(tabId))
}
Expand All @@ -227,14 +222,14 @@ public class BraveRewards: NSObject {

/// Report that media has started on a tab with a given id
func reportMediaStarted(tabId: Int) {
if !ads.isAdsServiceRunning() { return }
ads.reportMediaStarted(tabId: tabId)
if !ads.isServiceRunning() { return }
ads.notifyTabDidStartPlayingMedia(tabId)
}

/// Report that media has stopped on a tab with a given id
func reportMediaStopped(tabId: Int) {
if !ads.isAdsServiceRunning() { return }
ads.reportMediaStopped(tabId: tabId)
if !ads.isServiceRunning() { return }
ads.notifyTabDidStopPlayingMedia(tabId)
}

/// Report that a tab with a given id navigated to a new page in the same tab
Expand All @@ -244,8 +239,8 @@ public class BraveRewards: NSObject {

/// Report that a tab with a given id was closed by the user
func reportTabClosed(tabId: Int) {
if ads.isAdsServiceRunning() {
ads.reportTabClosed(tabId: tabId)
if ads.isServiceRunning() {
ads.notifyDidCloseTab(tabId)
}
rewardsAPI?.reportTabNavigationOrClosed(tabId: UInt32(tabId))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class RewardsDebugSettingsViewController: TableViewController {

super.init(style: .grouped)

self.rewards.ads.detailsForCurrentCycle { [weak self] viewed, amount, date in
self.rewards.ads.getStatementOfAccounts { [weak self] viewed, amount, date in
self?.adsInfo = (viewed, amount, date)
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/BraveNews/Composer/FeedCardGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ extension FeedCardGenerator {
case .braveAd:
// If we fail to obtain inline content ads during a card gen it can be assumed that
// all further calls will fail since cards are generated all at once
guard !contentAdsQueryFailed, let ads = ads, ads.isAdsServiceRunning() else { return [] }
guard !contentAdsQueryFailed, let ads = ads, ads.isServiceRunning() else { return [] }
if !inlineContentAdsPurged {
inlineContentAdsPurged = true
_ = await Task { @MainActor in
await ads.purgeOrphanedAdEvents(.inlineContentAd)
await ads.purgeOrphanedAdEvents(for: .inlineContentAd)
}.value
}
let contentAd = await Task { @MainActor in
await ads.inlineContentAds(dimensions: "900x750").1
await ads.maybeServeInlineContentAd("900x750").1
}.value
guard let ad = contentAd else {
contentAdsQueryFailed = true
Expand Down
2 changes: 1 addition & 1 deletion Sources/BraveShared/Extensions/BraveAdsExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

extension BraveAds {
public func initialize(walletInfo: BraveAds.WalletInfo? = nil, completion: @escaping (Bool) -> Void) {
self.initialize(
self.initService(
with: .init(deviceId: UIDevice.current.identifierForVendor?.uuidString ?? ""),
buildChannelInfo: .init(
isRelease: AppConstants.buildChannel == .release,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ struct AssetDetailView: View {
}
)
)
.onChange(of: keyringStore.defaultKeyring) { newValue in
if newValue.isLocked, isShowingAuroraBridgeAlert {
.onChange(of: keyringStore.isWalletLocked) { isLocked in
if isLocked, isShowingAuroraBridgeAlert {
isShowingAuroraBridgeAlert = false
}
}
Expand Down
5 changes: 2 additions & 3 deletions Sources/BraveWallet/Crypto/CryptoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ public struct CryptoView: View {
}

private var visibleScreen: VisibleScreen {
let keyring = keyringStore.defaultKeyring
if !keyring.isKeyringCreated || keyringStore.isOnboardingVisible {
if !keyringStore.isWalletCreated || keyringStore.isOnboardingVisible {
return .onboarding
}
if keyring.isLocked || keyringStore.isRestoreFromUnlockBiometricsPromptVisible {
if keyringStore.isWalletLocked || keyringStore.isRestoreFromUnlockBiometricsPromptVisible {
return .unlock
}
return .crypto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct PortfolioHeaderView: View {
@ObservedObject private var isShowingBalances = Preferences.Wallet.isShowingBalances

private var isShowingBackupBanner: Bool {
!keyringStore.defaultKeyring.isBackedUp && !dismissedBackupBannerThisSession
!keyringStore.isWalletBackedUp && !dismissedBackupBannerThisSession
}

private var emptyBalanceData: [BalanceTimePrice] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,13 @@ class AccountActivityStore: ObservableObject, WalletObserverStore {
}

extension AccountActivityStore: BraveWalletKeyringServiceObserver {
func keyringCreated(_ keyringId: BraveWallet.KeyringId) {
func walletCreated() {
}

func walletRestored() {
}

func keyringReset() {
func walletReset() {
}

func locked() {
Expand Down
4 changes: 2 additions & 2 deletions Sources/BraveWallet/Crypto/Stores/AssetDetailStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,14 @@ class AssetDetailStore: ObservableObject, WalletObserverStore {
}

extension AssetDetailStore: BraveWalletKeyringServiceObserver {
func keyringReset() {
func walletReset() {
}

func accountsChanged() {
update()
}

func keyringCreated(_ keyringId: BraveWallet.KeyringId) {
func walletCreated() {
}

func walletRestored() {
Expand Down
4 changes: 2 additions & 2 deletions Sources/BraveWallet/Crypto/Stores/CryptoStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ public class CryptoStore: ObservableObject, WalletObserverStore {
guard !isObserving else { return }
self.keyringServiceObserver = KeyringServiceObserver(
keyringService: keyringService,
_keyringReset: { [weak self] in
_walletReset: { [weak self] in
WalletProviderPermissionRequestsManager.shared.cancelAllPendingRequests(for: [.eth, .sol])
WalletProviderAccountCreationRequestManager.shared.cancelAllPendingRequests(coins: [.eth, .sol])
self?.rejectAllPendingWebpageRequests()
},
_keyringCreated: { _ in
_walletCreated: {
// 1. We don't need to rely on this observer method to migrate user visible assets
// when user creates a new wallet, since in this case `CryptoStore` has not yet been initialized
// 2. We don't need to rely on this observer method to migrate user visible assets
Expand Down
Loading