Skip to content
This repository has been archived by the owner on Oct 15, 2019. It is now read-only.

Update lib with call updates & ads notifications #143

Merged
merged 1 commit into from
Aug 6, 2019
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
9 changes: 9 additions & 0 deletions BraveRewardsExample/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@
</button>
</subviews>
</stackView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="myC-t7-p9s">
<rect key="frame" x="129.5" y="478" width="116" height="30"/>
<state key="normal" title="Show Sample Ad"/>
<connections>
<action selector="tappedServeSampleAd:" destination="BYZ-38-t0r" eventType="touchUpInside" id="fzn-0y-3dA"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
Expand All @@ -93,8 +100,10 @@
<constraint firstItem="hvd-Au-5z4" firstAttribute="top" secondItem="9Yi-J0-QPl" secondAttribute="bottom" constant="28" id="Gcp-v6-kel"/>
<constraint firstItem="9Yi-J0-QPl" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="Lxh-PO-59a"/>
<constraint firstItem="fPD-d0-f26" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="QKC-yA-2Y9"/>
<constraint firstItem="myC-t7-p9s" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="UGe-3J-vhU"/>
<constraint firstItem="Rn5-Tc-ZWe" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="5" id="XUl-Lz-boD"/>
<constraint firstItem="fPD-d0-f26" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="5" id="Xh7-Tg-kpe"/>
<constraint firstItem="9Yi-J0-QPl" firstAttribute="top" secondItem="myC-t7-p9s" secondAttribute="bottom" constant="28" id="dPM-a2-OO7"/>
<constraint firstItem="Rn5-Tc-ZWe" firstAttribute="leading" secondItem="fPD-d0-f26" secondAttribute="trailing" constant="-2" id="g73-1o-XqK"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="Rn5-Tc-ZWe" secondAttribute="trailing" constant="16" id="kx6-mc-c6y"/>
</constraints>
Expand Down
14 changes: 14 additions & 0 deletions BraveRewardsExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class ViewController: UIViewController {
@IBOutlet var useMockLedgerSwitch: UISwitch!

var rewards: BraveRewards!
var notificationsHandler: SystemNotificationsHandler!

private static let testPublisherURL = "https://3zsistemi.si" //"https://bumpsmack.com"

Expand All @@ -142,6 +143,11 @@ class ViewController: UIViewController {
rewards = BraveRewards(configuration: .default)
rewards.delegate = self
}
notificationsHandler = SystemNotificationsHandler(ads: rewards.ads)
notificationsHandler.adTapped = { notification in
print(notification.url)
}
UNUserNotificationCenter.current().delegate = notificationsHandler
}

@IBAction func tappedBraveRewards() {
Expand All @@ -164,6 +170,14 @@ class ViewController: UIViewController {
popover.present(from: braveRewardsPanelButton, on: self)
}

@IBAction func tappedServeSampleAd(_ sender: Any) {
notificationsHandler.requestNotificationPermissions { granted in
if granted {
self.rewards.ads.serveSampleAd()
}
}
}

@IBAction func tappedLoadContent(_ sender: Any) {
DataLoader.loadContent(rewards: rewards)
}
Expand Down
16 changes: 8 additions & 8 deletions BraveRewardsUI/Add Funds/AddFundsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class AddFundsViewController: UIViewController {
}

let map: [(TokenAddressView.TokenKind, String?)] = [
(.bitcoin, state.ledger.btcAddress),
(.ethereum, state.ledger.ethAddress),
(.basicAttentionToken, state.ledger.batAddress),
(.litecoin, state.ledger.ltcAddress)
// (.bitcoin, state.ledger.btcAddress),
iccub marked this conversation as resolved.
Show resolved Hide resolved
// (.ethereum, state.ledger.ethAddress),
// (.basicAttentionToken, state.ledger.batAddress),
// (.litecoin, state.ledger.ltcAddress)
]
addFundsView.tokenViews = map.map { (kind, address) in
TokenAddressView(tokenKind: kind).then {
Expand All @@ -63,10 +63,10 @@ class AddFundsViewController: UIViewController {
}
}
let map: [TokenAddressView.TokenKind: String] = [
.bitcoin: state.ledger.btcAddress,
.ethereum: state.ledger.ethAddress,
.basicAttentionToken: state.ledger.batAddress,
.litecoin: state.ledger.ltcAddress
.bitcoin: "",
// .ethereum: state.ledger.ethAddress,
iccub marked this conversation as resolved.
Show resolved Hide resolved
// .basicAttentionToken: state.ledger.batAddress,
// .litecoin: state.ledger.ltcAddress
].compactMapValues({ $0 })
guard let address = map[addressView.tokenKind] else { return }
let qrCode = "\(addressView.tokenKind.codePrefix):\(address)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class AutoContributeDetailViewController: UIViewController {
}

private func loadPublishers(start: Int, limit: Int = AutoContributeDetailViewController.pageSize, completion: @escaping ([PublisherInfo]) -> Void) {
let sort = ActivityInfoFilter.OrderPair().then {
let sort = ActivityInfoFilterOrderPair().then {
$0.propertyName = "percent"
$0.ascending = false
}
Expand Down
8 changes: 6 additions & 2 deletions BraveRewardsUI/Tipping/TippingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,13 @@ class TippingViewController: UIViewController, UIViewControllerTransitioningDele

// Add recurring tips if isMonthly..
if self.tippingView.optionSelectionView.isMonthly {
self.state.ledger.addRecurringTip(publisherId: self.publisherInfo.id, amount: amount)
self.state.ledger.addRecurringTip(publisherId: self.publisherInfo.id, amount: amount) { _ in
// TODO: Handle started tip process
}
} else {
self.state.ledger.tipPublisherDirectly(self.publisherInfo, amount: Int32(amount), currency: "BAT")
self.state.ledger.tipPublisherDirectly(self.publisherInfo, amount: Int32(amount), currency: "BAT") { _ in
// TODO: Handle started tip process
}
}

let displayConfirmationView = { (recurringDate: String?) in
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ A UI framework for consuming Brave Rewards on [brave-ios](https://github.com/bra
The latest BraveRewards.framework was built on:

```
brave-browser/c4c4073fe5ab1347d79599c5e5df81387dd919da
brave-core/6a12246d3893108b3064255e6d21984cc57780d8
brave-browser/d87b70acc7a9b2a407d72a0beed6ef79ce654543
brave-core/98fbddc221a5915dd29c0d69186e5d6e9f2bdc1f
```

Building the code
Expand Down
Binary file modified lib/BraveRewards.framework/BraveRewards
Binary file not shown.
28 changes: 0 additions & 28 deletions lib/BraveRewards.framework/Headers/BATActivityInfoFilter.h

This file was deleted.

44 changes: 36 additions & 8 deletions lib/BraveRewards.framework/Headers/BATBraveAds.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,45 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#import <Foundation/Foundation.h>
#import <UserNotifications/UserNotifications.h>

typedef NS_ENUM(NSInteger, BATAdsNotificationEventType) {
BATAdsNotificationEventTypeViewed, // = ads::NotificationEventType::VIEWED
BATAdsNotificationEventTypeClicked, // = ads::NotificationEventType::CLICKED
BATAdsNotificationEventTypeDismissed, // = ads::NotificationEventType::DISMISSED
BATAdsNotificationEventTypeTimedOut // = ads::NotificationEventType::TIMEOUT
} NS_SWIFT_NAME(NotificationEventType);

NS_ASSUME_NONNULL_BEGIN

@class BATAdsNotification, BATBraveAds;

NS_SWIFT_NAME(BraveAdsDelegate)
@protocol BATBraveAdsDelegate <NSObject>
NS_SWIFT_NAME(BraveAdsNotificationHandler)
@protocol BATBraveAdsNotificationHandler
@required

/// The client should show the notification to the user. Return true if the notification was successfully shown,
/// otherwise, return false.
- (BOOL)braveAds:(BATBraveAds *)braveAds showNotification:(BATAdsNotification *)notification;

/// Determine whether or not the client can currently show notifications
/// to the user.
///
/// In the case of system notifications:
///
/// This can be a combination of permission checks and notification settings for
/// lock screen, alert type, etc. If the user hasn't yet decided on notification
/// authorization status, they should be asked when this is called
- (void)isNotificationsAvailable:(void (^)(BOOL available))completionHandler;
/// Show the given notification to the user (or add it to the queue)
- (void)showNotification:(BATAdsNotification *)notification;
/// Remove a pending notification from the queue or remove an already shown
/// notification from view
- (void)clearNotificationWithIdentifier:(NSString *)identifier;
@end

NS_SWIFT_NAME(BraveAds)
@interface BATBraveAds : NSObject

@property (nonatomic, weak, nullable) id<BATBraveAdsDelegate> delegate;
/// The notifications handler.
///
/// @see BATSystemNotificationsHandler
@property (nonatomic, weak, nullable) id<BATBraveAdsNotificationHandler> notificationsHandler;

#pragma mark - Global

Expand Down Expand Up @@ -60,6 +80,10 @@ NS_SWIFT_NAME(BraveAds)
// Should be called to inform Ads if Confirmations is ready
- (void)setConfirmationsIsReady:(BOOL)isReady;

#pragma mark - Notificiations

- (nullable BATAdsNotification *)adsNotificationForIdentifier:(NSString *)identifier;

#pragma mark - Reporting

/// Report that a page has loaded in the current browser tab, and the HTML is available for analysis
Expand All @@ -77,6 +101,10 @@ NS_SWIFT_NAME(BraveAds)
/// Report that a tab with a given id was closed by the user
- (void)reportTabClosedWithTabId:(NSInteger)tabId NS_SWIFT_NAME(reportTabClosed(tabId:));

/// Report that a notification event type was triggered for a given id
- (void)reportNotificationEvent:(NSString *)notificationId
eventType:(BATAdsNotificationEventType)eventType;

#pragma mark -

- (instancetype)init NS_UNAVAILABLE;
Expand Down
22 changes: 9 additions & 13 deletions lib/BraveRewards.framework/Headers/BATBraveLedger.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#import <Foundation/Foundation.h>
#import "Records.h"
#import "ledger.mojom.objc.h"
#import "BATActivityInfoFilter.h"
#import "BATRewardsNotification.h"
#import "BATBraveLedgerObserver.h"

Expand Down Expand Up @@ -82,15 +81,6 @@ NS_SWIFT_NAME(BraveLedger)
- (void)recoverWalletUsingPassphrase:(NSString *)passphrase
completion:(nullable void (^)(NSError * _Nullable))completion;

/// The wallet's addresses. nil if the wallet has not been created yet
@property (nonatomic, readonly, nullable) NSString *BATAddress;
@property (nonatomic, readonly, nullable) NSString *BTCAddress;
@property (nonatomic, readonly, nullable) NSString *ETHAddress;
@property (nonatomic, readonly, nullable) NSString *LTCAddress;

/// ?? Unavailable until we understand whats its for
- (void)addressesForPaymentId:(void (^)(NSDictionary<NSString *, NSString *> *))completion NS_UNAVAILABLE;

@property (nonatomic, readonly) double defaultContributionAmount;

/// Retrieves the users most up to date balance to determin whether or not the
Expand Down Expand Up @@ -160,7 +150,8 @@ NS_SWIFT_NAME(BraveLedger)
- (void)listRecurringTips:(void (NS_NOESCAPE ^)(NSArray<BATPublisherInfo *> *))completion;

- (void)addRecurringTipToPublisherWithId:(NSString *)publisherId
amount:(double)amount NS_SWIFT_NAME(addRecurringTip(publisherId:amount:));
amount:(double)amount
completion:(void (^)(BOOL success))completion NS_SWIFT_NAME(addRecurringTip(publisherId:amount:completion:));

- (void)removeRecurringTipForPublisherWithId:(NSString *)publisherId NS_SWIFT_NAME(removeRecurringTip(publisherId:));

Expand All @@ -171,7 +162,8 @@ NS_SWIFT_NAME(BraveLedger)

- (void)tipPublisherDirectly:(BATPublisherInfo *)publisher
amount:(int)amount
currency:(NSString *)currency;
currency:(NSString *)currency
completion:(void (^)(BATResult result))completion;


#pragma mark - Grants
Expand All @@ -181,6 +173,10 @@ NS_SWIFT_NAME(BraveLedger)
- (void)fetchAvailableGrantsForLanguage:(NSString *)language
paymentId:(NSString *)paymentId;

- (void)fetchAvailableGrantsForLanguage:(NSString *)language
paymentId:(NSString *)paymentId
completion:(nullable void (^)(NSArray<BATGrant *> *grants))completion;

- (void)grantCaptchaForPromotionId:(NSString *)promoID
promotionType:(NSString *)promotionType
completion:(void (^)(NSString *image, NSString *hint))completion;
Expand All @@ -206,7 +202,7 @@ NS_SWIFT_NAME(BraveLedger)
/// Get an encoded URL that can be placed in another URL
- (NSString *)encodedURI:(NSString *)uri;

@property (nonatomic, readonly) BATRewardsInternalsInfo *rewardsInternalInfo;
- (void)rewardsInternalInfo:(void (NS_NOESCAPE ^)(BATRewardsInternalsInfo * _Nullable info))completion;

#pragma mark - Reporting

Expand Down
4 changes: 2 additions & 2 deletions lib/BraveRewards.framework/Headers/BATBraveLedgerObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ NS_SWIFT_NAME(LedgerObserver)
/// Executed when the wallet is first initialized
@property (nonatomic, copy, nullable) void (^walletInitalized)(BATResult result);

/// An eligable grant was added to the wallet
@property (nonatomic, copy, nullable) void (^grantAdded)(BATGrant *grant);
/// Eligable grants were added to the wallet
@property (nonatomic, copy, nullable) void (^grantsAdded)(NSArray<BATGrant *> *grants);

/// A grant was claimed
@property (nonatomic, copy, nullable) void (^grantClaimed)(BATGrant *grant);
Expand Down
39 changes: 39 additions & 0 deletions lib/BraveRewards.framework/Headers/BATSystemNotificationsHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#import <Foundation/Foundation.h>
#import <UserNotifications/UserNotifications.h>

#import "BATBraveAds.h"

NS_ASSUME_NONNULL_BEGIN

/// A default system notifications handler for managing displaying Brave Ads.
///
/// If this class is set to the UNUserNotificationCenter's delegate (or receives
/// UNUserNotificationCenterDelegate methods via proxy) it will automatically
/// report notification events back to the ads lib
NS_SWIFT_NAME(SystemNotificationsHandler)
@interface BATSystemNotificationsHandler : NSObject <BATBraveAdsNotificationHandler, UNUserNotificationCenterDelegate>
/// An ad was tapped and a URL should be opened
@property (nonatomic, copy, nullable) void (^adTapped)(BATAdsNotification *);
/// The ads object
@property (nonatomic, readonly) BATBraveAds *ads;
/// Create a handler instance with the given ads instance.
///
/// @note This method automatically sets `notificationsHandler` on BATBraveAds
/// to itself
- (instancetype)initWithAds:(BATBraveAds *)ads;
/// Whether or not this class should handle UNUserNotificationCenterDelegate
/// methods given the request
///
/// Use this if you are _not_ setting the UNUserNotificationCenter's delegate to
/// an instance of this class. This will allow you to determine whether to
/// forward the delegate method to this object.
- (BOOL)shouldHandleNotificationRequest:(UNNotificationRequest *)request;
/// Requests the notification permissions
- (void)requestNotificationPermissions:(void (^)(BOOL granted))completion;
@end

NS_ASSUME_NONNULL_END
4 changes: 1 addition & 3 deletions lib/BraveRewards.framework/Headers/BraveRewards.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ FOUNDATION_EXPORT const unsigned char BraveRewardsVersionString[];

// Ads
#import <BraveRewards/BATAdsNotification.h>
#import <BraveRewards/BATSystemNotificationsHandler.h>

// Ledger
#import <BraveRewards/Enums.h>
#import <BraveRewards/Records.h>
#import <BraveRewards/ledger.mojom.objc.h>
#import <BraveRewards/BATRewardsNotification.h>

// Ledger custom models
#import <BraveRewards/BATActivityInfoFilter.h>
Loading