Skip to content

Commit

Permalink
Implements new persona api
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Jul 4, 2020
1 parent 24c107d commit e28b725
Show file tree
Hide file tree
Showing 47 changed files with 226 additions and 899 deletions.
1 change: 1 addition & 0 deletions browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "walletRecoverySuccess", IDS_BRAVE_REWARDS_LOCAL_WALLET_RECOVERY_SUCCESS }, // NOLINT
{ "walletRestored", IDS_BRAVE_REWARDS_LOCAL_WALLET_RESTORED },
{ "walletRecoveryFail", IDS_BRAVE_REWARDS_LOCAL_WALLET_RECOVERY_FAIL }, // NOLINT
{ "walletRecoveryOutdated", IDS_BRAVE_REWARDS_LOCAL_WALLET_RECOVERY_OUTDATED }, // NOLINT
{ "almostThere", IDS_BRAVE_REWARDS_LOCAL_ALMOST_THERE },
{ "notQuite", IDS_BRAVE_REWARDS_LOCAL_NOT_QUITE },
{ "proveHuman", IDS_BRAVE_REWARDS_LOCAL_PROVE_HUMAN },
Expand Down
1 change: 0 additions & 1 deletion components/brave_rewards/browser/rewards_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ void RewardsService::RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterDoublePref(prefs::kStateAutoContributeAmount, 0.0);
registry->RegisterUint64Pref(prefs::kStateNextReconcileStamp, 0ull);
registry->RegisterUint64Pref(prefs::kStateCreationStamp, 0ull);
registry->RegisterStringPref(prefs::kStateAnonymousCardId, "");
registry->RegisterStringPref(prefs::kStateRecoverySeed, "");
registry->RegisterStringPref(prefs::kStatePaymentId, "");
registry->RegisterBooleanPref(prefs::kStateInlineTipRedditEnabled, false);
Expand Down
16 changes: 0 additions & 16 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1005,22 +1005,6 @@ void RewardsServiceImpl::OnPublisherStateLoaded(
data);
}

void RewardsServiceImpl::LoadNicewareList(
ledger::GetNicewareListCallback callback) {
if (!Connected()) {
return;
}

std::string data = ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_BRAVE_REWARDS_NICEWARE_LIST).as_string();

if (data.empty()) {
BLOG(0, "Failed to read in niceware list");
}
callback(data.empty() ? ledger::Result::LEDGER_ERROR
: ledger::Result::LEDGER_OK, data);
}

void RewardsServiceImpl::LoadURL(
const std::string& url,
const std::vector<std::string>& headers,
Expand Down
1 change: 0 additions & 1 deletion components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ class RewardsServiceImpl : public RewardsService,
ledger::Result result);
void OnLedgerStateLoaded(ledger::OnLoadCallback callback,
std::pair<std::string, base::Value> data);
void LoadNicewareList(ledger::GetNicewareListCallback callback) override;
void OnPublisherStateLoaded(ledger::OnLoadCallback callback,
const std::string& data);
void OnGetRewardsParameters(
Expand Down
1 change: 0 additions & 1 deletion components/brave_rewards/common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const char kStateAutoContributeEnabled[] = "brave.rewards.ac.enabled";
const char kStateAutoContributeAmount[] = "brave.rewards.ac.amount";
const char kStateNextReconcileStamp[] = "brave.rewards.ac.next_reconcile_stamp";
const char kStateCreationStamp[] = "brave.rewards.creation_stamp";
const char kStateAnonymousCardId[] = "brave.rewards.wallet.anonymous_card_id";
const char kStateRecoverySeed[] = "brave.rewards.wallet.seed";
const char kStatePaymentId[] = "brave.rewards.wallet.payment_id";
const char kStateInlineTipRedditEnabled[] = "brave.rewards.inline_tip.reddit";
Expand Down
1 change: 0 additions & 1 deletion components/brave_rewards/common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ extern const char kStateAutoContributeEnabled[];
extern const char kStateAutoContributeAmount[];
extern const char kStateNextReconcileStamp[];
extern const char kStateCreationStamp[];
extern const char kStateAnonymousCardId[];
extern const char kStateRecoverySeed[];
extern const char kStatePaymentId[];
extern const char kStateInlineTipRedditEnabled[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<include name="IDR_BRAVE_REWARDS_IMG_CAPTCHA_BAT" file="page/img/captcha_bat.png" type="BINDATA" />
<include name="IDR_BRAVE_REWARDS_IMG_WELCOME_BG" file="page/img/welcome_bg.svg" type="BINDATA" />
<include name="IDR_BRAVE_REWARDS_FAVICON" file="page/img/favicon.ico" type="BINDATA" />
<include name="IDR_BRAVE_REWARDS_NICEWARE_LIST" file="../../../vendor/bat-native-ledger/niceware/wordlist" type="BINDATA" />
<include name="IDR_BRAVE_REWARDS_IMG_TAP" file="page/promos/assets/tap_bg.svg" type="BINDATA" />

<!-- WebUI Brave Rewards Internals resources -->
Expand Down
20 changes: 17 additions & 3 deletions components/brave_rewards/resources/page/components/pageWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class PageWallet extends React.Component<Props, State> {
}
}

if (walletRecoverySuccess) {
if (walletRecoverySuccess === 0) {
const batFormatString = onlyAnonWallet ? getLocale('batPoints') : getLocale('bat')

return {
Expand Down Expand Up @@ -745,6 +745,20 @@ class PageWallet extends React.Component<Props, State> {
)
}

getBackupErrorMessage = () => {
const { ui } = this.props.rewardsData
const { walletRecoverySuccess } = ui
if (walletRecoverySuccess === 1) {
return getLocale('walletRecoveryFail')
}

if (walletRecoverySuccess === 2) {
return getLocale('walletRecoveryOutdated')
}

return ''
}

render () {
const {
recoveryKey,
Expand All @@ -754,7 +768,7 @@ class PageWallet extends React.Component<Props, State> {
pendingContributionTotal
} = this.props.rewardsData
const { total } = balance
const { walletRecoverySuccess, emptyWallet, modalBackup, onlyAnonWallet } = ui
const { emptyWallet, modalBackup, onlyAnonWallet } = ui

const pendingTotal = parseFloat((pendingContributionTotal || 0).toFixed(3))

Expand Down Expand Up @@ -810,7 +824,7 @@ class PageWallet extends React.Component<Props, State> {
onSaveFile={this.onModalBackupOnSaveFile}
onRestore={this.onModalBackupOnRestore}
onVerify={this.onVerifyClick.bind(this, true)}
error={walletRecoverySuccess === false ? getLocale('walletRecoveryFail') : ''}
error={this.getBackupErrorMessage()}
/>
: null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const walletReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State,

if (!key || key.length === 0) {
let ui = state.ui
ui.walletRecoverySuccess = false
ui.walletRecoverySuccess = 0

state = {
...state,
Expand Down
1 change: 0 additions & 1 deletion components/brave_rewards/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ source_set("brave_rewards_unit_tests") {
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/legacy/report_balance_state_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/legacy/unsigned_tx_state_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/legacy/wallet_info_state_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/test/niceware_partial_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/database/database_util_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/promotion_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/credentials/credentials_util_unittest.cc",
Expand Down
2 changes: 1 addition & 1 deletion components/definitions/rewards.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ declare namespace Rewards {
promosDismissed?: {
[key: string]: boolean
}
walletRecoverySuccess: boolean | null
walletRecoverySuccess: number | null
walletServerProblem: boolean
walletCorrupted: boolean
onBoardingDisplayed?: boolean
Expand Down
1 change: 1 addition & 0 deletions components/resources/brave_components_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@
<message name="IDS_BRAVE_REWARDS_LOCAL_WALLET_RECOVERY_SUCCESS" desc="">{{balance}} {{currency}} was recovered. Your wallet key has been verified and loaded successfully.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_WALLET_RESTORED" desc="">Wallet restored!</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_WALLET_RECOVERY_FAIL" desc="">Please re-enter keys or try different keys.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_WALLET_RECOVERY_OUTDATED" desc="">You are using old recovery keys. Please update them. You can find instructions how to do this here.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_ALMOST_THERE" desc="">Almost there…</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_PROVE_HUMAN" desc="">Prove that you are human!</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_NOT_QUITE" desc="">Hmmm, not quite...</message>
Expand Down
18 changes: 0 additions & 18 deletions components/services/bat_ledger/bat_ledger_client_mojo_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,24 +176,6 @@ void BatLedgerClientMojoBridge::FetchFavIcon(const std::string& url,
base::BindOnce(&OnFetchFavIcon, std::move(callback)));
}

void OnLoadNicewareList(
const ledger::GetNicewareListCallback& callback,
const ledger::Result result,
const std::string& data) {
callback(result, data);
}

void BatLedgerClientMojoBridge::LoadNicewareList(
ledger::GetNicewareListCallback callback) {
if (!Connected()) {
callback(ledger::Result::LEDGER_ERROR, "");
return;
}

bat_ledger_client_->LoadNicewareList(
base::BindOnce(&OnLoadNicewareList, std::move(callback)));
}

std::string BatLedgerClientMojoBridge::URIEncode(const std::string& value) {
if (!Connected())
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ class BatLedgerClientMojoBridge :

void PendingContributionSaved(const ledger::Result result) override;

void LoadNicewareList(ledger::GetNicewareListCallback callback) override;

void OnLoadLedgerState(ledger::OnLoadCallback callback,
const ledger::Result result, const std::string& data);
void OnLoadPublisherState(ledger::OnLoadCallback callback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,6 @@ void LedgerClientMojoBridge::FetchFavIcon(const std::string& url,
std::bind(LedgerClientMojoBridge::OnFetchFavIcon, holder, _1, _2));
}

// static
void LedgerClientMojoBridge::OnLoadNicewareList(
CallbackHolder<LoadNicewareListCallback>* holder,
const ledger::Result result,
const std::string& data) {
DCHECK(holder);
if (holder->is_valid())
std::move(holder->get()).Run(result, data);
delete holder;
}

void LedgerClientMojoBridge::LoadNicewareList(
LoadNicewareListCallback callback) {
// deleted in OnLoadNicewareList
auto* holder = new CallbackHolder<LoadNicewareListCallback>(
AsWeakPtr(), std::move(callback));
ledger_client_->LoadNicewareList(
std::bind(LedgerClientMojoBridge::OnLoadNicewareList,
holder, _1, _2));
}

void LedgerClientMojoBridge::URIEncode(const std::string& value,
URIEncodeCallback callback) {
std::move(callback).Run(ledger_client_->URIEncode(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class LedgerClientMojoBridge :
void FetchFavIcon(const std::string& url, const std::string& favicon_key,
FetchFavIconCallback callback) override;

void LoadNicewareList(LoadNicewareListCallback callback) override;

void SetTimer(uint64_t time_offset, SetTimerCallback callback) override;
void KillTimer(const uint32_t timer_id) override;
void OnPanelPublisherInfo(
Expand Down Expand Up @@ -196,11 +194,6 @@ class LedgerClientMojoBridge :
bool success,
const std::string& favicon_url);

static void OnLoadNicewareList(
CallbackHolder<LoadNicewareListCallback>* holder,
const ledger::Result result,
const std::string& data);

static void OnLoadURL(
CallbackHolder<LoadURLCallback>* holder,
const ledger::UrlResponse& response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ interface BatLedgerClient {
FetchFavIcon(string url, string favicon_key) => (bool success,
string favicon_url);

LoadNicewareList() => (ledger.mojom.Result result, string data);

LoadURL(string url, array<string> headers, string content,
string content_type, ledger.mojom.UrlMethod method) => (ledger.mojom.UrlResponse response);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ describe('rewards reducer', () => {
it('import flow - existing state', () => {
const initState: Rewards.State = { ...defaultState }
initState.ui.emptyWallet = false
initState.ui.walletRecoverySuccess = true
initState.ui.walletRecoverySuccess = 1

const expectedState: Rewards.State = { ...defaultState }
expectedState.ui.emptyWallet = false
expectedState.ui.walletRecoverySuccess = true
expectedState.ui.walletRecoverySuccess = 1

const assertion = reducers({
rewardsData: initState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ class ConfirmationsClientMock : public ConfirmationsClient {
MOCK_METHOD1(LoadPublisherState, void(
ledger::OnLoadCallback callback));

MOCK_METHOD1(LoadNicewareList, void(
ledger::GetNicewareListCallback callback));

MOCK_METHOD2(SaveActivityInfo, void(
ledger::PublisherInfoPtr publisher_info,
ledger::PublisherInfoCallback callback));
Expand Down
1 change: 0 additions & 1 deletion vendor/bat-native-ledger/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ source_set("ledger") {
"//url",
rebase_path("bat-native-ads", dep_base),
rebase_path("bat-native-confirmations", dep_base),
rebase_path("bat-native-anonize:anonize2", dep_base),
rebase_path("bip39wally-core-native:bip39wally-core", dep_base),
rebase_path("bat-native-tweetnacl:tweetnacl", dep_base),
rebase_path("bat-native-rapidjson", dep_base),
Expand Down
4 changes: 0 additions & 4 deletions vendor/bat-native-ledger/include/bat/ledger/ledger_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ using PublisherInfoCallback =
// TODO(nejczdovc) we should be providing result back as well
using PublisherInfoListCallback =
std::function<void(PublisherInfoList)>;
using GetNicewareListCallback =
std::function<void(const Result, const std::string&)>;
using FetchIconCallback = std::function<void(bool, const std::string&)>;
using LoadURLCallback = std::function<void(const ledger::UrlResponse&)>;
using OnLoadCallback = std::function<void(const Result,
Expand Down Expand Up @@ -80,8 +78,6 @@ class LEDGER_EXPORT LedgerClient {

virtual void LoadPublisherState(OnLoadCallback callback) = 0;

virtual void LoadNicewareList(ledger::GetNicewareListCallback callback) = 0;

virtual void OnPanelPublisherInfo(Result result,
ledger::PublisherInfoPtr publisher_info,
uint64_t windowId) = 0;
Expand Down
1 change: 0 additions & 1 deletion vendor/bat-native-ledger/niceware/wordlist

This file was deleted.

Loading

0 comments on commit e28b725

Please sign in to comment.