Skip to content

Commit 513eb36

Browse files
committed
Removes annon address from external wallet flow
Resolves brave/brave-browser#11150
1 parent 91447f0 commit 513eb36

File tree

17 files changed

+9
-295
lines changed

17 files changed

+9
-295
lines changed

components/brave_rewards/browser/external_wallet.cc

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ namespace brave_rewards {
2222
base::Value dict(base::Value::Type::DICTIONARY);
2323
dict.SetStringKey("token", token);
2424
dict.SetStringKey("address", address);
25-
dict.SetStringKey("anon_address", anon_address);
2625

2726
// enum class WalletStatus : int32_t
2827
dict.SetIntKey("status", static_cast<int32_t>(status));

components/brave_rewards/browser/external_wallet.h

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ struct ExternalWallet {
1818

1919
std::string token;
2020
std::string address;
21-
std::string anon_address;
2221
uint32_t status;
2322
std::string type;
2423
std::string verify_url;

components/brave_rewards/browser/rewards_service_impl.cc

-7
Original file line numberDiff line numberDiff line change
@@ -3186,7 +3186,6 @@ void RewardsServiceImpl::SaveExternalWallet(const std::string& wallet_type,
31863186
new_wallet.SetStringKey("withdraw_url", wallet->withdraw_url);
31873187
new_wallet.SetStringKey("account_url", wallet->account_url);
31883188
new_wallet.SetStringKey("login_url", wallet->login_url);
3189-
new_wallet.SetStringKey("anon_address", wallet->anon_address);
31903189

31913190
new_wallets.SetKey(wallet_type, std::move(new_wallet));
31923191

@@ -3255,11 +3254,6 @@ RewardsServiceImpl::GetExternalWallets() {
32553254
wallet->login_url = *login_url;
32563255
}
32573256

3258-
auto* anon_address = it.second.FindStringKey("anon_address");
3259-
if (anon_address) {
3260-
wallet->anon_address = *anon_address;
3261-
}
3262-
32633257
wallets.insert(std::make_pair(it.first, std::move(wallet)));
32643258
}
32653259

@@ -3285,7 +3279,6 @@ void RewardsServiceImpl::OnGetExternalWallet(
32853279
external->user_name = wallet->user_name;
32863280
external->account_url = wallet->account_url;
32873281
external->login_url = wallet->login_url;
3288-
external->anon_address = wallet->anon_address;
32893282
}
32903283

32913284
std::move(callback).Run(static_cast<int>(result), std::move(external));

components/brave_rewards/browser/test/common/rewards_browsertest_response.cc

-9
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ void RewardsBrowserTestResponse::LoadMocks() {
198198
path.AppendASCII("uphold_commit_resp.json"),
199199
&uphold_commit_resp_));
200200

201-
ASSERT_TRUE(base::ReadFileToString(
202-
path.AppendASCII("uphold_addresses_resp.json"),
203-
&uphold_addresses_resp_));
204-
205201
std::vector<std::string> publisher_keys {
206202
"bumpsmack.com",
207203
"duckduckgo.com",
@@ -340,11 +336,6 @@ void RewardsBrowserTestResponse::Get(
340336
"commit",
341337
base::CompareCase::INSENSITIVE_ASCII)) {
342338
*response = uphold_commit_resp_;
343-
} else if (base::EndsWith(
344-
url,
345-
"addresses",
346-
base::CompareCase::INSENSITIVE_ASCII)) {
347-
*response = uphold_addresses_resp_;
348339
} else {
349340
*response = rewards_browsertest_util::GetUpholdCard(
350341
external_balance_,

components/brave_rewards/browser/test/common/rewards_browsertest_response.h

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class RewardsBrowserTestResponse {
6767
std::string uphold_auth_resp_;
6868
std::string uphold_transactions_resp_;
6969
std::string uphold_commit_resp_;
70-
std::string uphold_addresses_resp_;
7170
std::string user_funds_balance_resp_;
7271

7372
std::vector<Request> requests_;

test/data/rewards-data/uphold_addresses_resp.json

-11
This file was deleted.

vendor/bat-native-ledger/include/bat/ledger/public/interfaces/ledger.mojom

-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ struct ExternalWallet {
145145
string type;
146146
string token;
147147
string address;
148-
string anon_address;
149148
WalletStatus status;
150149
string verify_url;
151150
string add_url;

vendor/bat-native-ledger/src/bat/ledger/internal/state/state_migration.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace braveledger_state {
2222
StateMigration::StateMigration(bat_ledger::LedgerImpl* ledger) :
2323
v1_(std::make_unique<StateMigrationV1>(ledger)),
2424
v2_(std::make_unique<StateMigrationV2>(ledger)),
25-
v3_(std::make_unique<StateMigrationV3>(ledger)),
25+
v3_(std::make_unique<StateMigrationV3>()),
2626
v4_(std::make_unique<StateMigrationV4>(ledger)),
2727
ledger_(ledger) {
2828
DCHECK(v1_ && v2_ && v3_ && v4_);

vendor/bat-native-ledger/src/bat/ledger/internal/state/state_migration_v3.cc

+4-27
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,18 @@
33
* License, v. 2.0. If a copy of the MPL was not distributed with this
44
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
55

6-
#include <utility>
7-
8-
#include "bat/ledger/global_constants.h"
9-
#include "bat/ledger/internal/ledger_impl.h"
10-
#include "bat/ledger/internal/state/state_keys.h"
116
#include "bat/ledger/internal/state/state_migration_v3.h"
12-
#include "bat/ledger/internal/state/state_util.h"
13-
#include "bat/ledger/internal/uphold/uphold_util.h"
147

158
namespace braveledger_state {
169

17-
StateMigrationV3::StateMigrationV3(bat_ledger::LedgerImpl* ledger) :
18-
ledger_(ledger) {
19-
}
10+
StateMigrationV3::StateMigrationV3() = default;
2011

2112
StateMigrationV3::~StateMigrationV3() = default;
2213

2314
void StateMigrationV3::Migrate(ledger::ResultCallback callback) {
24-
const std::string anon_address =
25-
ledger_->GetStringState(ledger::kStateUpholdAnonAddress);
26-
27-
if (!anon_address.empty()) {
28-
auto wallets = ledger_->GetExternalWallets();
29-
auto wallet = braveledger_uphold::GetWallet(std::move(wallets));
30-
if (!wallet) {
31-
BLOG(0, "Wallet is null, but we can't recover");
32-
callback(ledger::Result::LEDGER_OK);
33-
return;
34-
}
35-
36-
wallet->anon_address = anon_address;
37-
ledger_->SaveExternalWallet(ledger::kWalletUphold, std::move(wallet));
38-
ledger_->ClearState(ledger::kStateUpholdAnonAddress);
39-
}
40-
15+
// In this migration we migrated anon address to uphold wallet in preferences
16+
// because anon address was removed we can also remove this step
17+
// Ref: https://github.com/brave/brave-browser/issues/11150
4118
callback(ledger::Result::LEDGER_OK);
4219
}
4320

vendor/bat-native-ledger/src/bat/ledger/internal/state/state_migration_v3.h

+1-11
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,16 @@
66
#ifndef BRAVELEDGER_BAT_STATE_STATE_MIGRATION_V3_H_
77
#define BRAVELEDGER_BAT_STATE_STATE_MIGRATION_V3_H_
88

9-
#include <memory>
10-
#include <string>
11-
129
#include "bat/ledger/ledger.h"
1310

14-
namespace bat_ledger {
15-
class LedgerImpl;
16-
}
17-
1811
namespace braveledger_state {
1912

2013
class StateMigrationV3 {
2114
public:
22-
explicit StateMigrationV3(bat_ledger::LedgerImpl* ledger);
15+
StateMigrationV3();
2316
~StateMigrationV3();
2417

2518
void Migrate(ledger::ResultCallback callback);
26-
27-
private:
28-
bat_ledger::LedgerImpl* ledger_; // NOT OWNED
2919
};
3020

3121
} // namespace braveledger_state

vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.cc

-4
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,6 @@ void Uphold::GetUser(GetUserCallback callback) {
227227
user_->Get(callback);
228228
}
229229

230-
void Uphold::CreateAnonAddressIfNecessary(ledger::ResultCallback callback) {
231-
card_->CreateAnonAddressIfNecessary(callback);
232-
}
233-
234230
void Uphold::SaveTransferFee(ledger::TransferFeePtr transfer_fee) {
235231
if (!transfer_fee) {
236232
BLOG(0, "Transfer fee is null");

vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.h

-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ class Uphold {
6969

7070
void GetUser(GetUserCallback callback);
7171

72-
void CreateAnonAddressIfNecessary(ledger::ResultCallback callback);
73-
7472
void OnTimer(const uint32_t timer_id);
7573

7674
private:

vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_card.cc

-161
Original file line numberDiff line numberDiff line change
@@ -242,165 +242,4 @@ void UpholdCard::OnUpdate(
242242
callback(ledger::Result::LEDGER_OK);
243243
}
244244

245-
void UpholdCard::GetCardAddresses(
246-
GetCardAddressesCallback callback) {
247-
auto wallets = ledger_->GetExternalWallets();
248-
auto wallet = GetWallet(std::move(wallets));
249-
if (!wallet) {
250-
BLOG(0, "Wallet is null");
251-
callback(ledger::Result::LEDGER_ERROR, {});
252-
return;
253-
}
254-
255-
const auto headers = RequestAuthorization(wallet->token);
256-
const std::string path = base::StringPrintf(
257-
"/v0/me/cards/%s/addresses",
258-
wallet->address.c_str());
259-
260-
auto address_callback = std::bind(&UpholdCard::OnGetCardAddresses,
261-
this,
262-
_1,
263-
callback);
264-
265-
const auto url = GetAPIUrl(path);
266-
ledger_->LoadURL(
267-
url,
268-
headers,
269-
"",
270-
"application/json",
271-
ledger::UrlMethod::GET,
272-
address_callback);
273-
}
274-
275-
void UpholdCard::OnGetCardAddresses(
276-
const ledger::UrlResponse& response,
277-
GetCardAddressesCallback callback) {
278-
BLOG(6, ledger::UrlResponseToString(__func__, response));
279-
280-
std::map<std::string, std::string> addresses;
281-
const ledger::Result result =
282-
braveledger_response_util::ParseUpholdGetCardAddresses(
283-
response,
284-
&addresses);
285-
286-
if (result == ledger::Result::EXPIRED_TOKEN) {
287-
BLOG(0, "Expired token");
288-
callback(ledger::Result::EXPIRED_TOKEN, {});
289-
uphold_->DisconnectWallet();
290-
return;
291-
}
292-
293-
if (result != ledger::Result::LEDGER_OK) {
294-
BLOG(0, "Couldn't get card addresses");
295-
callback(ledger::Result::LEDGER_ERROR, {});
296-
return;
297-
}
298-
299-
callback(ledger::Result::LEDGER_OK, addresses);
300-
}
301-
302-
void UpholdCard::CreateAnonAddressIfNecessary(ledger::ResultCallback callback) {
303-
auto address_callback = std::bind(&UpholdCard::OnCreateAnonAddressIfNecessary,
304-
this,
305-
_1,
306-
_2,
307-
callback);
308-
309-
GetCardAddresses(address_callback);
310-
}
311-
312-
void UpholdCard::OnCreateAnonAddressIfNecessary(
313-
ledger::Result result,
314-
std::map<std::string, std::string> addresses,
315-
ledger::ResultCallback callback) {
316-
if (result == ledger::Result::LEDGER_OK && addresses.size() > 0) {
317-
auto iter = addresses.find(kAnonID);
318-
if (iter != addresses.end() && !iter->second.empty()) {
319-
auto wallets = ledger_->GetExternalWallets();
320-
auto wallet = GetWallet(std::move(wallets));
321-
if (!wallet) {
322-
BLOG(0, "Wallet is null");
323-
callback(ledger::Result::LEDGER_ERROR);
324-
return;
325-
}
326-
327-
wallet->anon_address = iter->second;
328-
ledger_->SaveExternalWallet(ledger::kWalletUphold, std::move(wallet));
329-
callback(ledger::Result::LEDGER_OK);
330-
return;
331-
}
332-
}
333-
334-
CreateAnonAddress(callback);
335-
}
336-
337-
void UpholdCard::CreateAnonAddress(ledger::ResultCallback callback) {
338-
auto wallets = ledger_->GetExternalWallets();
339-
auto wallet = GetWallet(std::move(wallets));
340-
if (!wallet) {
341-
BLOG(0, "Wallet is null");
342-
callback(ledger::Result::LEDGER_ERROR);
343-
return;
344-
}
345-
346-
const auto headers = RequestAuthorization(wallet->token);
347-
const std::string path = base::StringPrintf(
348-
"/v0/me/cards/%s/addresses",
349-
wallet->address.c_str());
350-
351-
const std::string payload = base::StringPrintf(
352-
R"({
353-
"network": "%s"
354-
})",
355-
kAnonID);
356-
357-
auto anon_callback = std::bind(&UpholdCard::OnCreateAnonAddress,
358-
this,
359-
_1,
360-
callback);
361-
362-
const auto url = GetAPIUrl(path);
363-
ledger_->LoadURL(
364-
url,
365-
headers,
366-
payload,
367-
"application/json",
368-
ledger::UrlMethod::POST,
369-
anon_callback);
370-
}
371-
372-
void UpholdCard::OnCreateAnonAddress(
373-
const ledger::UrlResponse& response,
374-
ledger::ResultCallback callback) {
375-
BLOG(6, ledger::UrlResponseToString(__func__, response));
376-
377-
std::string id;
378-
const ledger::Result result =
379-
braveledger_response_util::ParseUpholdCreateCard(response, &id);
380-
if (result == ledger::Result::EXPIRED_TOKEN) {
381-
BLOG(0, "Expired token");
382-
callback(ledger::Result::EXPIRED_TOKEN);
383-
uphold_->DisconnectWallet();
384-
return;
385-
}
386-
387-
if (result != ledger::Result::LEDGER_OK || id.empty()) {
388-
BLOG(0, "Couldn't create anon address");
389-
callback(ledger::Result::LEDGER_ERROR);
390-
return;
391-
}
392-
393-
auto wallets = ledger_->GetExternalWallets();
394-
auto wallet = GetWallet(std::move(wallets));
395-
if (!wallet) {
396-
BLOG(0, "Wallet is null");
397-
callback(ledger::Result::LEDGER_ERROR);
398-
return;
399-
}
400-
401-
wallet->anon_address = id;
402-
ledger_->SaveExternalWallet(ledger::kWalletUphold, std::move(wallet));
403-
callback(ledger::Result::LEDGER_OK);
404-
}
405-
406245
} // namespace braveledger_uphold

0 commit comments

Comments
 (0)