Skip to content

Commit

Permalink
Uplift of #9669 (squashed) to beta
Browse files Browse the repository at this point in the history
  • Loading branch information
brave-browser-releases committed Aug 10, 2021
1 parent 56a2538 commit d554220
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,24 @@
"message": "Please backup your Brave wallet.",
"description": "Description for backup wallet notification"
},
"mismatchedProviderAccountsLearnMore": {
"message": "Learn More",
"description": "Notification button text to learn more about linking with a custodian account"
},
"mismatchedProviderAccountsTitle": {
"message": "Error: Different account",
"description": "Title for mismatched provider accounts notification"
},
"mismatchedProviderAccountsNotification": {
"message": "Hmm, it looks like your Brave Rewards wallet has already been verified with another $name$ account. Please try verifying again using your previous account.",
"description": "Description for mismatched provider accounts notification",
"placeholders": {
"name": {
"content": "$1",
"example": "Uphold"
}
}
},
"upholdBATNotAllowedForUserLearnMore": {
"message": "Learn More",
"description": "Notification button text to learn more about why BAT is not allowed for user"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export const getUIMessages = (): Record<string, string> => {
'includeInAuto',
'insufficientFunds',
'insufficientFundsNotification',
'mismatchedProviderAccountsLearnMore',
'mismatchedProviderAccountsNotification',
'mismatchedProviderAccountsTitle',
'monthApr',
'monthAug',
'monthDec',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ export class Panel extends React.Component<Props, State> {

onDeviceLimitReached = this.onEvent('https://support.brave.com/hc/en-us/articles/360056508071')

onMismatchedProviderAccounts = this.onEvent('https://support.brave.com/hc/en-us/articles/360034841711-What-is-a-verified-wallet-')

onUpholdBATNotAllowedForUser = this.onEvent('https://support.uphold.com/hc/en-us/articles/360033020351-Brave-BAT-and-US-availability')

onUpholdBlockedUser = this.onEvent('https://support.uphold.com/hc/en-us/articles/360045765351-Why-we-block-or-restrict-accounts-and-how-to-reduce-the-risk')
Expand Down Expand Up @@ -348,11 +350,14 @@ export class Panel extends React.Component<Props, State> {
case 'backupWallet':
clickEvent = this.onBackupWallet.bind(this, id)
break
case 'deviceLimitReached':
clickEvent = this.onDeviceLimitReached.bind(this, id)
break
case 'insufficientFunds':
clickEvent = this.onAddFunds.bind(this, id)
break
case 'deviceLimitReached':
clickEvent = this.onDeviceLimitReached.bind(this, id)
case 'mismatchedProviderAccounts':
clickEvent = this.onMismatchedProviderAccounts.bind(this, id)
break
case 'upholdBATNotAllowedForUser':
clickEvent = this.onUpholdBATNotAllowedForUser.bind(this, id)
Expand Down Expand Up @@ -469,16 +474,10 @@ export class Panel extends React.Component<Props, State> {
}

switch (args[0]) {
case 'wallet_new_verified': {
text = (
<>
<div><b>{getMessage('walletVerifiedNotification')}</b></div>
{getMessage('walletVerifiedTextNotification', [args[1]])}
</>
)
isAlert = 'success'
case 'wallet_device_limit_reached':
type = 'deviceLimitReached'
text = getMessage('deviceLimitReachedNotification')
break
}
case 'wallet_disconnected': {
text = (
<>
Expand All @@ -489,10 +488,20 @@ export class Panel extends React.Component<Props, State> {
isAlert = 'error'
break
}
case 'wallet_device_limit_reached':
type = 'deviceLimitReached'
text = getMessage('deviceLimitReachedNotification')
case 'wallet_mismatched_provider_accounts':
type = 'mismatchedProviderAccounts'
text = getMessage('mismatchedProviderAccountsNotification', [args[1]])
break
case 'wallet_new_verified': {
text = (
<>
<div><b>{getMessage('walletVerifiedNotification')}</b></div>
{getMessage('walletVerifiedTextNotification', [args[1]])}
</>
)
isAlert = 'success'
break
}
case 'uphold_bat_not_allowed_for_user':
type = 'upholdBATNotAllowedForUser'
text = getMessage('upholdBATNotAllowedForUserNotification')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export type NotificationType =
'error' |
'grant' |
'insufficientFunds' |
'mismatchedProviderAccounts' |
'pendingContribution' |
'tipsProcessed' |
'upholdBATNotAllowedForUser' |
Expand Down Expand Up @@ -279,6 +280,7 @@ export default class WalletWrapper extends React.PureComponent<Props, State> {
buttonAction = this.onNotificationClick
break
case 'deviceLimitReached':
case 'mismatchedProviderAccounts':
case 'upholdBATNotAllowedForUser':
case 'upholdBlockedUser':
case 'upholdPendingUser':
Expand Down Expand Up @@ -465,6 +467,7 @@ export default class WalletWrapper extends React.PureComponent<Props, State> {
case 'backupWallet':
case 'deviceLimitReached':
case 'insufficientFunds':
case 'mismatchedProviderAccounts':
case 'upholdBATNotAllowedForUser':
case 'upholdBlockedUser':
case 'upholdPendingUser':
Expand Down Expand Up @@ -500,6 +503,7 @@ export default class WalletWrapper extends React.PureComponent<Props, State> {
switch (notification.type) {
case 'backupWallet':
case 'deviceLimitReached':
case 'mismatchedProviderAccounts':
case 'pendingContribution':
case 'upholdBATNotAllowedForUser':
case 'upholdBlockedUser':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ type::Result PostClaimUphold::CheckStatusCode(const int status_code) const {

if (status_code == net::HTTP_FORBIDDEN) {
BLOG(0, "Forbidden");
return type::Result::LEDGER_ERROR;
return type::Result::TOO_MANY_RESULTS;
}

if (status_code == net::HTTP_NOT_FOUND) {
Expand All @@ -130,7 +130,7 @@ type::Result PostClaimUphold::CheckStatusCode(const int status_code) const {
}

if (status_code == net::HTTP_CONFLICT) {
BLOG(0, "Not found");
BLOG(0, "Conflict");
return type::Result::ALREADY_EXISTS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ TEST_F(PostClaimUpholdTest, ServerError403) {

claim_->Request(30.0, "address",
[](const type::Result result, const std::string& address) {
EXPECT_EQ(result, type::Result::LEDGER_ERROR);
EXPECT_EQ(result, type::Result::TOO_MANY_RESULTS);
EXPECT_EQ(address, kExpectedAddress);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ namespace ledger {
namespace log {

const char kACAddedToQueue[] = "ac_added_to_queue";
const char kWalletConnected[] = "wallet_connected";
const char kWalletVerified[] = "wallet_verified";
const char kWalletDisconnected[] = "wallet_disconnected";
const char kRecurringTipAdded[] = "recurring_tip_added";
const char kRecurringTipRemoved[] = "recurring_tip_removed";
const char kDatabaseMigrated[] = "database_migrated";
const char kDeviceLimitReached[] = "device_limit_reached";
const char kMismatchedProviderAccounts[] = "mismatched_provider_accounts";
const char kPromotionsClaimed[] = "promotion_claimed";
const char kRecurringTipAdded[] = "recurring_tip_added";
const char kRecurringTipRemoved[] = "recurring_tip_removed";
const char kWalletConnected[] = "wallet_connected";
const char kWalletDisconnected[] = "wallet_disconnected";
const char kWalletRecovered[] = "wallet_recovered";
const char kDeviceLimitReached[] = "device_limit_reached";
const char kWalletStatusChange[] = "wallet_status_change";
const char kWalletVerified[] = "wallet_verified";

} // namespace log
} // namespace ledger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace ledger {
namespace notifications {

const char kWalletDeviceLimitReached[] = "wallet_device_limit_reached";
const char kWalletMismatchedProviderAccounts[] =
"wallet_mismatched_provider_accounts";
const char kWalletDisconnected[] = "wallet_disconnected";
const char kWalletNewVerified[] = "wallet_new_verified";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void Uphold::DisconnectWallet(const std::string& notification) {
const bool shutting_down = ledger_->IsShuttingDown();

if (!manual && !shutting_down) {
ledger_->ledger_client()->ShowNotification(notification, {},
ledger_->ledger_client()->ShowNotification(notification, {"Uphold"},
[](type::Result _) {});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1109,8 +1109,37 @@ INSTANTIATE_TEST_SUITE_P(
type::Result::ALREADY_EXISTS,
type::WalletStatus::NOT_CONNECTED
},
LinkWalletParamType{ // Mismatched provider accounts.
"01_mismatched_provider_accounts",
R"({ "status": 5, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150" })",
type::UrlResponse{
{},
{},
net::HttpStatusCode::HTTP_OK,
R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })",
{}
},
type::UrlResponse{
{},
{},
net::HttpStatusCode::HTTP_OK,
R"([ { "id": "962ef3b8-bc12-4619-a349-c8083931b795", "label": "Brave Browser" } ])",
{}
},
false,
R"({ "payment_id": "f375da3c-c206-4f09-9422-665b8e5952db", "recovery_seed": "OG2zYotDSeZ81qLtr/uq5k/GC6WE5/7BclT1lHi4l+w=" })",
type::UrlResponse{
{},
{},
net::HttpStatusCode::HTTP_FORBIDDEN,
{},
{}
},
type::Result::TOO_MANY_RESULTS,
type::WalletStatus::NOT_CONNECTED
},
LinkWalletParamType{ // Rewards Link (Claim) Wallet failed.
"01_link_wallet_failed",
"02_link_wallet_failed",
R"({ "status": 5, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150" })",
type::UrlResponse{
{},
Expand Down Expand Up @@ -1139,7 +1168,7 @@ INSTANTIATE_TEST_SUITE_P(
type::WalletStatus::PENDING
},
LinkWalletParamType{ // Happy path.
"02_happy_path",
"03_happy_path",
R"({ "status": 5, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150" })",
type::UrlResponse{
{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,18 @@ void UpholdWallet::OnLinkWallet(const type::Result result,
return callback(type::Result::ALREADY_EXISTS);
}

if (result == type::Result::TOO_MANY_RESULTS) {
// Entering NOT_CONNECTED.
ledger_->uphold()->DisconnectWallet(
ledger::notifications::kWalletMismatchedProviderAccounts);

ledger_->database()->SaveEventLog(
log::kMismatchedProviderAccounts,
constant::kWalletUphold + std::string("/") + id.substr(0, 5));

return callback(type::Result::TOO_MANY_RESULTS);
}

if (result != type::Result::LEDGER_OK) {
return callback(type::Result::CONTINUE);
}
Expand Down

0 comments on commit d554220

Please sign in to comment.