Skip to content

Commit

Permalink
Adds retries for unverified publishers
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Jun 5, 2019
1 parent b1f22e9 commit 31d38e6
Show file tree
Hide file tree
Showing 31 changed files with 386 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class RewardsNotificationService {
REWARDS_NOTIFICATION_INSUFFICIENT_FUNDS,
REWARDS_NOTIFICATION_BACKUP_WALLET,
REWARDS_NOTIFICATION_TIPS_PROCESSED,
REWARDS_NOTIFICATION_ADS_LAUNCH
REWARDS_NOTIFICATION_ADS_LAUNCH,
REWARDS_NOTIFICATION_VERIFIED_PUBLISHER,
REWARDS_NOTIFICATION_PENDING_NOT_ENOUGH_FUNDS
};

struct RewardsNotification {
Expand Down
32 changes: 32 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3197,4 +3197,36 @@ void RewardsServiceImpl::GetCountryCodes(
callback(country_codes);
}

void RewardsServiceImpl::OnContributeUnverifiedPublishers(
ledger::Result result,
const std::string& publisher_key,
const std::string& publisher_name) {
if (result == ledger::Result::PENDING_NOT_ENOUGH_FUNDS) {
RewardsNotificationService::RewardsNotificationArgs args;
notification_service_->AddNotification(
RewardsNotificationService::
REWARDS_NOTIFICATION_PENDING_NOT_ENOUGH_FUNDS,
args,
"rewards_notification_not_enough_funds");
return;
}

if (result == ledger::Result::PENDING_PUBLISHER_REMOVED) {
for (auto& observer : observers_) {
observer.OnPendingContributionRemoved(this, ledger::Result::LEDGER_OK);
}
return;
}

if (result == ledger::Result::VERIFIED_PUBLISHER) {
RewardsNotificationService::RewardsNotificationArgs args;
args.push_back(publisher_name);
notification_service_->AddNotification(
RewardsNotificationService::REWARDS_NOTIFICATION_VERIFIED_PUBLISHER,
args,
"rewards_notification_verified_publisher_" + publisher_key);
return;
}
}

} // namespace brave_rewards
5 changes: 5 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,11 @@ class RewardsServiceImpl : public RewardsService,
const std::vector<std::string>& countries,
ledger::GetCountryCodesCallback callback) override;

void OnContributeUnverifiedPublishers(
ledger::Result result,
const std::string& publisher_key,
const std::string& publisher_name) override;

bool Connected() const;
void ConnectionClosed();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,5 +420,23 @@
"twitterTipsIconLabel": {
"message": "Tip",
"description": "Icon label for Twitter tips"
},
"verifiedPublisherNotification": {
"message": "Creator $name$ recently verified",
"description": "Notification text that tells user which publisher did just verified",
"placeholders": {
"name": {
"content": "$1",
"example": "brave.com"
}
}
},
"pendingNotEnoughFundsNotification": {
"message": "You have pending tips due to insufficient funds",
"description": "Notification text that tells user his wallet is under funded for pending contribution to complete"
},
"pendingContributionTitle": {
"message": "Pending Contribution",
"description": "Notification title for pending contribution type"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const getMessage = (message: string, substitutions?: string[]): string =>

export const getUIMessages = (): Record<string, string> => {
const strings = [
'addFunds',
'and',
'backupNow',
'backupWalletNotification',
Expand Down Expand Up @@ -79,6 +80,7 @@ export const getUIMessages = (): Record<string, string> => {
'ok',
'on',
'oneTimeDonation',
'pendingContributionTitle',
'privacyPolicy',
'recurringDonations',
'reservedAmountText',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,14 @@ export class Panel extends React.Component<Props, State> {
}
}

openRewardsAddFundsPage () {
openRewardsAddFundsPage (id?: string) {
chrome.tabs.create({
url: 'chrome://rewards/#add-funds'
})

if (id) {
this.actions.deleteNotification(id)
}
}

showTipSiteDetail = () => {
Expand Down Expand Up @@ -255,6 +259,9 @@ export class Panel extends React.Component<Props, State> {
case 'ads-launch':
clickEvent = this.openRewardsPage.bind(this, id)
break
case 'insufficientFunds':
clickEvent = this.openRewardsAddFundsPage.bind(this, id)
break
default:
clickEvent = undefined
break
Expand Down Expand Up @@ -336,6 +343,22 @@ export class Panel extends React.Component<Props, State> {
type = 'ads-launch'
text = getMessage('braveAdsLaunchMsg')
break
case RewardsNotificationType.REWARDS_NOTIFICATION_VERIFIED_PUBLISHER: {
let name = ''
if (notification.args &&
Array.isArray(notification.args) &&
notification.args.length > 0) {
name = notification.args[0]
}

type = 'pendingContribution'
text = getMessage('verifiedPublisherNotification', [name])
break
}
case RewardsNotificationType.REWARDS_NOTIFICATION_PENDING_NOT_ENOUGH_FUNDS:
type = 'insufficientFunds'
text = getMessage('pendingNotEnoughFundsNotification')
break
default:
type = ''
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@ export const enum RewardsNotificationType {
REWARDS_NOTIFICATION_INSUFFICIENT_FUNDS,
REWARDS_NOTIFICATION_BACKUP_WALLET,
REWARDS_NOTIFICATION_TIPS_PROCESSED,
REWARDS_NOTIFICATION_ADS_LAUNCH
REWARDS_NOTIFICATION_ADS_LAUNCH,
REWARDS_NOTIFICATION_VERIFIED_PUBLISHER,
REWARDS_NOTIFICATION_PENDING_NOT_ENOUGH_FUNDS
}
Original file line number Diff line number Diff line change
Expand Up @@ -803,4 +803,13 @@ void BatLedgerClientMojoProxy::GetCountryCodes(
base::BindOnce(&OnGetCountryCodes, std::move(callback)));
}

void BatLedgerClientMojoProxy::OnContributeUnverifiedPublishers(
ledger::Result result,
const std::string& publisher_key,
const std::string& publisher_name) {
bat_ledger_client_->OnContributeUnverifiedPublishers(ToMojomResult(result),
publisher_key,
publisher_name);
}

} // namespace bat_ledger
5 changes: 5 additions & 0 deletions components/services/bat_ledger/bat_ledger_client_mojo_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ class BatLedgerClientMojoProxy : public ledger::LedgerClient,
const std::vector<std::string>& countries,
ledger::GetCountryCodesCallback callback) override;

void OnContributeUnverifiedPublishers(
ledger::Result result,
const std::string& publisher_key,
const std::string& publisher_name) override;

private:
bool Connected() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,4 +773,13 @@ void LedgerClientMojoProxy::GetCountryCodes(
_1));
}

void LedgerClientMojoProxy::OnContributeUnverifiedPublishers(
int32_t result,
const std::string& publisher_key,
const std::string& publisher_name) {
ledger_client_->OnContributeUnverifiedPublishers(ToLedgerResult(result),
publisher_key,
publisher_name);
}

} // namespace bat_ledger
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ class LedgerClientMojoProxy : public mojom::BatLedgerClient,
const std::vector<std::string>& countries,
GetCountryCodesCallback callback) override;

void OnContributeUnverifiedPublishers(
int32_t result,
const std::string& publisher_key,
const std::string& publisher_name) override;

private:
// workaround to pass base::OnceCallback into std::bind
// also serves as a wrapper for passing ledger::LedgerCallbackHandler*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,7 @@ interface BatLedgerClient {

GetCountryCodes(array<string> countries) =>
(array<int32> limited_country_codes);

OnContributeUnverifiedPublishers(int32 result, string publisher_key,
string publisher_name);
};
32 changes: 9 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
"@types/react-redux": "6.0.4",
"@types/redux-logger": "^3.0.7",
"awesome-typescript-loader": "^5.2.1",
"brave-ui": "github:brave/brave-ui#cedd99a936c6a6c2e28d4a21dbdcc9324e797d68",
"brave-ui": "github:brave/brave-ui#7f885688e568ec4b9aca61a899aa18a2a240656f",
"css-loader": "^2.1.1",
"csstype": "^2.5.5",
"deep-freeze-node": "^1.1.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ class MockConfirmationsClient : public ConfirmationsClient {
MOCK_METHOD2(GetCountryCodes, void(
const std::vector<std::string>& countries,
ledger::GetCountryCodesCallback callback));

MOCK_METHOD3(OnContributeUnverifiedPublishers, void(
ledger::Result result,
const std::string& publisher_key,
const std::string& publisher_name));
};

} // namespace confirmations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ LEDGER_EXPORT enum Result {
GRANT_ALREADY_CLAIMED = 18,

CONTRIBUTION_AMOUNT_TOO_LOW = 19,
VERIFIED_PUBLISHER = 20,
PENDING_PUBLISHER_REMOVED = 21,
PENDING_NOT_ENOUGH_FUNDS = 22,
};

// LedgerCallbackHandler must not be destroyed if they have pending callbacks
Expand Down
5 changes: 5 additions & 0 deletions vendor/bat-native-ledger/include/bat/ledger/ledger_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ class LEDGER_EXPORT LedgerClient {
virtual void GetCountryCodes(
const std::vector<std::string>& countries,
GetCountryCodesCallback callback) = 0;

virtual void OnContributeUnverifiedPublishers(
ledger::Result result,
const std::string& publisher_key,
const std::string& publisher_name) = 0;
};

} // namespace ledger
Expand Down
Loading

0 comments on commit 31d38e6

Please sign in to comment.