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 15, 2020
1 parent ab08531 commit 481ef74
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 18 deletions.
Binary file modified BraveRewards/BraveRewards.framework/BraveRewards
Binary file not shown.
10 changes: 5 additions & 5 deletions BraveRewards/BraveRewards.framework/Headers/BATBraveLedger.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ NS_SWIFT_NAME(BraveLedger)
#pragma mark - User Wallets

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ NS_SWIFT_NAME(LedgerObserver)
/// Wallet balance was fetched and updated
@property (nonatomic, copy, nullable) void (^fetchedBalance)();

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

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

@end

Expand Down
6 changes: 4 additions & 2 deletions BraveRewards/BraveRewards.framework/Headers/Enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ typedef NS_ENUM(NSInteger, BATLogLevel) {
BATLogLevelLogResponse = 6
} NS_SWIFT_NAME(LogLevel);

typedef NSString *BATExternalWalletType NS_STRING_ENUM;
typedef NSString *BATWalletType NS_SWIFT_NAME(WalletType) NS_STRING_ENUM;

static BATExternalWalletType const BATExternalWalletTypeUphold = @"uphold";
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.
14 changes: 14 additions & 0 deletions BraveRewardsUI/Extensions/BraveLedgerExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ 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 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 @@ -88,6 +88,7 @@ internal extension Strings {
static let emptyWalletTitle = NSLocalizedString("BraveRewardsEmptyWalletTitle", bundle: .rewardsUI, value: "Your wallet is ready for action.", comment: "")
static let recurringTipTitle = NSLocalizedString("BraveRewardsRecurringTipTitle", bundle: .rewardsUI, value: "Recurring tip", comment: "")
static let unverifiedPublisherDisclaimer = NSLocalizedString("BraveRewardsUnverifiedPublisherDisclaimer", 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: .rewardsUI, value: "Claim", comment: "")
static let autoContributeMinimumLength = NSLocalizedString("BraveRewardsAutoContributeMinimumLength", bundle: .rewardsUI, value: "Minimum Page Time", comment: "")
static let autoContributeMinimumVisitsMessage = NSLocalizedString("BraveRewardsAutoContributeMinimumVisitsMessage", bundle: .rewardsUI, value: "Minimum visits for publisher relevancy", comment: "")
Expand Down Expand Up @@ -156,6 +157,7 @@ internal extension Strings {
static let learnMoreCreateWallet1 = NSLocalizedString("BraveRewardsLearnMoreCreateWallet1", bundle: .rewardsUI, value: "Yes, I'm In!", comment: "")
static let learnMoreBraveAdsTitle = NSLocalizedString("BraveRewardsLearnMoreBraveAdsTitle", bundle: .rewardsUI, value: "Ads", comment: "")
static let tippingUnverifiedDisclaimer = NSLocalizedString("BraveRewardsTippingUnverifiedDisclaimer", 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("BraveRewardsTippingUnverifiedDisclaimer", 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: .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: .rewardsUI, value: "Cancel", comment: "")
static let disabledSubtitle = NSLocalizedString("BraveRewardsDisabledSubtitle", 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, walletBalances: [WalletType: Double]) {
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 (walletBalances[.anonymous] ?? 0) > 0 || (walletBalances[.unblindedTokens] ?? 0) > 0 {
// 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/323811f8fe9eb8248ff1146353d931dff06b8d1b
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.walletBalances[.anonymous] ?? 0) > 0 || (state.ledger.walletBalances[.unblindedTokens] ?? 0) > 0 {
// 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 :
Expand Down
25 changes: 22 additions & 3 deletions BraveRewardsUI/Wallet/WalletViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,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,
walletBalances: self.state.ledger.walletBalances
)
}

// Create an artificial delay so user sees something is happening
Expand Down Expand Up @@ -288,14 +292,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,
walletBalances: state.ledger.walletBalances
)
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,
walletBalances: state.ledger.walletBalances
)
publisherView.checkAgainButton.isHidden = publisher.status != .notVerified

self.publisherSummaryView.setAutoContribute(enabled:
Expand Down Expand Up @@ -629,6 +641,13 @@ extension WalletViewController {
crypto: Strings.walletBalanceType,
dollarValue: state.ledger.usdBalanceString
)
if let publisher = publisher {
publisherSummaryView.publisherView.setStatus(
publisher.status,
externalWalletStatus: self.state.ledger.upholdWalletStatus,
walletBalances: self.state.ledger.walletBalances
)
}
if let wallet = state.ledger.externalWallets[.uphold] {
switch wallet.status {
case .notConnected:
Expand Down

0 comments on commit 481ef74

Please sign in to comment.