Skip to content

Commit

Permalink
Handle 404 and 403 errors from uphold
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed May 6, 2020
1 parent fb83ff4 commit 3e87572
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
6 changes: 2 additions & 4 deletions browser/ui/webui/brave_rewards_page_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1522,10 +1522,9 @@ void RewardsDOMHandler::OnFetchBalance(
base::DictionaryValue data;
data.SetIntKey("status", result);
base::Value balance_value(base::Value::Type::DICTIONARY);
balance_value.SetDoubleKey("total", balance->total);

if (result == 0 && balance) {
balance_value.SetDoubleKey("total", balance->total);

base::Value rates(base::Value::Type::DICTIONARY);
for (auto const& rate : balance->rates) {
rates.SetDoubleKey(rate.first, rate.second);
Expand All @@ -1537,10 +1536,9 @@ void RewardsDOMHandler::OnFetchBalance(
wallets.SetDoubleKey(wallet.first, wallet.second);
}
balance_value.SetKey("wallets", std::move(wallets));

data.SetKey("balance", std::move(balance_value));
}

data.SetKey("balance", std::move(balance_value));
web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.balance", data);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ const walletReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State,
ui.walletServerProblem = true
} else if (status === 24) { // on ledger::Result::EXPIRED_TOKEN
chrome.send('brave_rewards.getExternalWallet', ['uphold'])
state.balance.total = action.payload.balance.total || 0
}

state = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,11 @@ void Uphold::OnFetchBalance(
const std::map<std::string, std::string>& headers) {
ledger_->LogResponse(__func__, response_status_code, response, headers);

if (response_status_code == net::HTTP_UNAUTHORIZED) {
callback(ledger::Result::EXPIRED_TOKEN, 0.0);
if (response_status_code == net::HTTP_UNAUTHORIZED ||
response_status_code == net::HTTP_NOT_FOUND ||
response_status_code == net::HTTP_FORBIDDEN) {
DisconnectWallet();
return;
}

if (response_status_code == net::HTTP_NOT_FOUND) {
callback(ledger::Result::LEDGER_ERROR, 0.0);
callback(ledger::Result::EXPIRED_TOKEN, 0.0);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void Balance::OnUpholdFetchBalance(ledger::Balance info,

info_ptr->wallets.insert(std::make_pair(ledger::kWalletUphold, balance));
info_ptr->total += balance;
callback(ledger::Result::LEDGER_OK, std::move(info_ptr));
callback(result, std::move(info_ptr));
}

// static
Expand Down

0 comments on commit 3e87572

Please sign in to comment.