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

Commit

Permalink
Fix #2202: Display correct publisher disclaimer for connected wallets (
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehickinson committed Jan 22, 2020
1 parent a2d3790 commit a5b3d93
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 9 deletions.
Binary file modified BraveRewards/BraveRewards.framework/BraveRewards
Binary file not shown.
19 changes: 19 additions & 0 deletions BraveRewards/BraveRewards.framework/Headers/BATBraveLedger.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ extern NSString * const BATBraveLedgerErrorDomain NS_SWIFT_NAME(BraveLedgerError

extern NSNotificationName const BATBraveLedgerNotificationAdded NS_SWIFT_NAME(BraveLedger.NotificationAdded);

typedef NSString *BATBraveGeneralLedgerNotificationID NS_SWIFT_NAME(GeneralLedgerNotificationID) NS_STRING_ENUM;
extern BATBraveGeneralLedgerNotificationID const BATBraveGeneralLedgerNotificationIDWalletNowVerified;
extern BATBraveGeneralLedgerNotificationID const BATBraveGeneralLedgerNotificationIDWalletDisconnected;

NS_SWIFT_NAME(BraveLedger)
@interface BATBraveLedger : NSObject

Expand Down Expand Up @@ -94,6 +98,21 @@ NS_SWIFT_NAME(BraveLedger)
/// Returns reserved amount of pending contributions to publishers.
@property (nonatomic, readonly) double reservedAmount;

#pragma mark - User Wallets

/// The last updated external wallet if a user has hooked one up
@property (nonatomic, readonly) NSDictionary<BATWalletType, BATExternalWallet *> *externalWallets;

- (void)fetchExternalWalletForType:(BATWalletType)walletType
completion:(nullable void (^)(BATExternalWallet * _Nullable wallet))completion;

- (void)disconnectWalletOfType:(BATWalletType)walletType
completion:(nullable void (^)(BATResult result))completion;

- (void)authorizeExternalWalletOfType:(BATWalletType)walletType
queryItems:(NSDictionary<NSString *, NSString *> *)queryItems
completion:(void (^)(BATResult result, NSURL * _Nullable redirectURL))completion;

#pragma mark - Publishers

@property (nonatomic, readonly, getter=isLoadingPublisherList) BOOL loadingPublisherList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ NS_SWIFT_NAME(LedgerObserver)
/// Wallet balance was fetched and updated
@property (nonatomic, copy, nullable) void (^fetchedBalance)();

@property (nonatomic, copy, nullable) void (^externalWalletAuthorized)(BATWalletType type);

@property (nonatomic, copy, nullable) void (^externalWalletDisconnected)(BATWalletType type);

@end

NS_ASSUME_NONNULL_END
7 changes: 7 additions & 0 deletions BraveRewards/BraveRewards.framework/Headers/Enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ typedef NS_ENUM(NSInteger, BATLogLevel) {
BATLogLevelLogRequest = 5,
BATLogLevelLogResponse = 6
} NS_SWIFT_NAME(LogLevel);

typedef NSString *BATWalletType NS_SWIFT_NAME(WalletType) NS_STRING_ENUM;

static BATWalletType const BATWalletTypeUphold = @"uphold";
static BATWalletType const BATWalletTypeAnonymous = @"anonymous";
static BATWalletType const BATWalletTypeUnblindedTokens = @"blinded";

Binary file modified BraveRewards/BraveRewards.framework/Info.plist
Binary file not shown.
19 changes: 19 additions & 0 deletions BraveRewardsUI/Extensions/BraveLedgerExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ private let log = Logger.rewardsLogger

extension BraveLedger {

var walletBalances: [WalletType: Double] {
guard let wallets = balance?.wallets else { return [:] }
var balances: [WalletType: Double] = [:]
for wallet in wallets {
balances[WalletType(rawValue: wallet.key)] = wallet.value.doubleValue
}
return balances
}

var walletContainsBraveFunds: Bool {
let balances = walletBalances
return (balances[.anonymous] ?? 0) > 0 || (balances[.unblindedTokens] ?? 0) > 0
}

var upholdWalletStatus: WalletStatus {
guard let userWallet = externalWallets[.uphold] else { return .notConnected }
return userWallet.status
}

/// The total balance or 0 if the balance hasn't been loaded yet
fileprivate var balanceTotal: Double {
return balance?.total ?? 0
Expand Down
2 changes: 2 additions & 0 deletions BraveRewardsUI/Localized Strings/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ internal extension Strings {
static let EmptyWalletTitle = NSLocalizedString("BraveRewardsEmptyWalletTitle", bundle: Bundle.RewardsUI, value: "Your wallet is ready for action.", comment: "")
static let RecurringTipTitle = NSLocalizedString("BraveRewardsRecurringTipTitle", bundle: Bundle.RewardsUI, value: "Recurring tip", comment: "")
static let UnverifiedPublisherDisclaimer = NSLocalizedString("BraveRewardsUnverifiedPublisherDisclaimer", bundle: Bundle.RewardsUI, value: "This creator has not yet signed up to receive contributions from Brave users. Any tips you send will remain in your wallet until they verify.", comment: "")
static let connectedPublisherDisclaimer = NSLocalizedString("BraveRewardsConnectedPublisherDisclaimer", bundle: .RewardsUI, value: "This Brave Verified Creator has not yet configured their account to receive contributions from Brave Users. Any tips you send will remain in your wallet until they complete this process.", comment: "")
static let SettingsGrantClaimButtonTitle = NSLocalizedString("BraveRewardsSettingsGrantClaimButtonTitle", bundle: Bundle.RewardsUI, value: "Claim", comment: "")
static let AutoContributeMinimumLength = NSLocalizedString("BraveRewardsAutoContributeMinimumLength", bundle: Bundle.RewardsUI, value: "Minimum Page Time", comment: "")
static let AutoContributeMinimumVisitsMessage = NSLocalizedString("BraveRewardsAutoContributeMinimumVisitsMessage", bundle: Bundle.RewardsUI, value: "Minimum visits for publisher relevancy", comment: "")
Expand Down Expand Up @@ -157,6 +158,7 @@ internal extension Strings {
static let LearnMoreCreateWallet1 = NSLocalizedString("BraveRewardsLearnMoreCreateWallet1", bundle: Bundle.RewardsUI, value: "Yes, I'm In!", comment: "")
static let LearnMoreBraveAdsTitle = NSLocalizedString("BraveRewardsLearnMoreBraveAdsTitle", bundle: Bundle.RewardsUI, value: "Ads", comment: "")
static let TippingUnverifiedDisclaimer = NSLocalizedString("BraveRewardsTippingUnverifiedDisclaimer", bundle: Bundle.RewardsUI, value: "NOTE: This creator has not yet signed up to receive contributions from Brave users. Your browser will keep trying to contribute until they verify, or until 90 days have passed.", comment: "")
static let tippingNotConnectedDisclaimer = NSLocalizedString("BraveRewardsTippingNotConnectedDisclaimer", bundle: .RewardsUI, value: "NOTE: This Brave Verified Creator has not yet signed up to receive contributions from Brave users. Your browser will keep trying to contribute until they verify, or until 90 days have passed.", comment: "")
static let SettingsTipsBody = NSLocalizedString("BraveRewardsSettingsTipsBody", bundle: Bundle.RewardsUI, value: "Tip content creators directly as you browse. You can also set up recurring monthly tips so you can support sites continuously.", comment: "")
static let Cancel = NSLocalizedString("Cancel", bundle: Bundle.RewardsUI, value: "Cancel", comment: "")
static let DisabledSubtitle = NSLocalizedString("BraveRewardsDisabledSubtitle", bundle: Bundle.RewardsUI, value: "Get Rewarded for Browsing!", comment: "")
Expand Down
18 changes: 15 additions & 3 deletions BraveRewardsUI/Publisher/PublisherView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,28 @@ class PublisherView: UIStackView {
verifiedLabelStackView.isHidden = hidden
}

func setStatus(_ status: PublisherStatus) {
func setStatus(_ status: PublisherStatus, externalWalletStatus: WalletStatus, hasBraveFunds: Bool) {
if status != .notVerified {
verificationSymbolImageView.image = UIImage(frameworkResourceNamed: "icn-verify")
verifiedLabel.text = Strings.Verified
} else {
verificationSymbolImageView.image = UIImage(frameworkResourceNamed: "icn-unverified")
verifiedLabel.text = Strings.NotYetVerified
}
// Shows if the publisher is also .connected
unverifiedDisclaimerView.isHidden = status == .verified
if hasBraveFunds {
// Use that balance first, therefore not showing any differently
unverifiedDisclaimerView.isHidden = status != .notVerified
} else {
if externalWalletStatus == .notConnected {
unverifiedDisclaimerView.isHidden = status != .notVerified
} else {
unverifiedDisclaimerView.isHidden = status == .verified
if status == .connected {
unverifiedDisclaimerView.text = "\(Strings.connectedPublisherDisclaimer) \(Strings.DisclaimerLearnMore)"
unverifiedDisclaimerView.setURLInfo([Strings.DisclaimerLearnMore: "learn-more"])
}
}
}
}

func updatePublisherName(_ name: String, provider: String) {
Expand Down
2 changes: 1 addition & 1 deletion BraveRewardsUI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ The latest BraveRewards.framework was built on:

```
brave-browser/b08ea58f46fc531f6abe9dca41f4381815d58372
brave-core/62dfd8e87c339a4947b08c511c3e41fb16e351f8
brave-core/3fda9986d7508620be473f3127eb18c08a636db3
```
17 changes: 15 additions & 2 deletions BraveRewardsUI/Tipping/TippingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,21 @@ class TippingViewController: UIViewController, UIViewControllerTransitioningDele
self.tippingView.overviewView.socialStackView.addArrangedSubview(UIImageView(image: UIImage(frameworkResourceNamed: $0.iconName)))
})
}

self.tippingView.overviewView.disclaimerView.isHidden = banner.status == .verified

if state.ledger.walletContainsBraveFunds {
// Use that balance first, therefore not showing any differently
tippingView.overviewView.disclaimerView.isHidden = banner.status != .notVerified
} else {
if state.ledger.upholdWalletStatus == .notConnected {
tippingView.overviewView.disclaimerView.isHidden = banner.status != .notVerified
} else {
tippingView.overviewView.disclaimerView.isHidden = banner.status == .verified
if banner.status == .connected {
tippingView.overviewView.disclaimerView.text = "\(Strings.tippingNotConnectedDisclaimer) \(Strings.DisclaimerLearnMore)"
tippingView.overviewView.disclaimerView.setURLInfo([Strings.DisclaimerLearnMore: "learn-more"])
}
}
}

let bannerAmounts = banner.amounts.isEmpty ? TippingViewController.defaultTippingAmounts : banner.amounts.compactMap({ $0.doubleValue })
self.tippingView.optionSelectionView.options = bannerAmounts.map {
Expand Down
36 changes: 33 additions & 3 deletions BraveRewardsUI/Wallet/WalletViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import UIKit
import SnapKit
import BraveRewards
import Network
import BraveShared

protocol WalletContentView: AnyObject {
var innerScrollView: UIScrollView? { get }
Expand Down Expand Up @@ -228,7 +229,11 @@ class WalletViewController: UIViewController, RewardsSummaryProtocol {
let updateStates = {
publisherView.setCheckAgainIsLoading(false)
publisherView.checkAgainButton.isHidden = true
publisherView.setStatus(status)
publisherView.setStatus(
status,
externalWalletStatus: self.state.ledger.upholdWalletStatus,
hasBraveFunds: self.state.ledger.walletContainsBraveFunds
)
}

// Create an artificial delay so user sees something is happening
Expand Down Expand Up @@ -281,14 +286,22 @@ class WalletViewController: UIViewController, RewardsSummaryProtocol {

guard let publisher = publisher else {
publisherView.updatePublisherName(state.dataSource?.displayString(for: state.url) ?? "", provider: "")
publisherView.setStatus(.notVerified)
publisherView.setStatus(
.notVerified,
externalWalletStatus: state.ledger.upholdWalletStatus,
hasBraveFunds: state.ledger.walletContainsBraveFunds
)
return
}

let provider = " \(publisher.provider.isEmpty ? "" : String(format: Strings.OnProviderText, publisher.providerDisplayString))"
publisherView.updatePublisherName(publisher.name, provider: provider)

publisherView.setStatus(publisher.status)
publisherView.setStatus(
publisher.status,
externalWalletStatus: state.ledger.upholdWalletStatus,
hasBraveFunds: state.ledger.walletContainsBraveFunds
)
publisherView.checkAgainButton.isHidden = publisher.status != .notVerified

self.publisherSummaryView.setAutoContribute(enabled:
Expand Down Expand Up @@ -580,6 +593,23 @@ extension WalletViewController {
crypto: Strings.WalletBalanceType,
dollarValue: state.ledger.usdBalanceString
)
if let publisher = publisher {
publisherSummaryView.publisherView.setStatus(
publisher.status,
externalWalletStatus: self.state.ledger.upholdWalletStatus,
hasBraveFunds: self.state.ledger.walletContainsBraveFunds
)
}
}

/// Fetch an updated external wallet from ledger if the user isn't in JP
func updateExternalWallet() {
if Preferences.Rewards.isUsingBAP.value == true { return }

// If we can show Uphold, grab verification status of the wallet
state.ledger.fetchExternalWallet(forType: .uphold) { _ in
self.updateWalletHeader()
}
}

func setupLedgerObservers() {
Expand Down

0 comments on commit a5b3d93

Please sign in to comment.