Skip to content

Commit

Permalink
Review fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cypt4 committed Oct 11, 2023
1 parent 60ce4d2 commit c37d36f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 22 deletions.
4 changes: 4 additions & 0 deletions browser/browser_context_keyed_service_factories.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "brave/browser/brave_rewards/rewards_service_factory.h"
#include "brave/browser/brave_shields/ad_block_pref_service_factory.h"
#include "brave/browser/brave_wallet/asset_ratio_service_factory.h"
#include "brave/browser/brave_wallet/bitcoin_wallet_service_factory.h"
#include "brave/browser/brave_wallet/brave_wallet_ipfs_service_factory.h"
#include "brave/browser/brave_wallet/brave_wallet_service_factory.h"
#include "brave/browser/brave_wallet/json_rpc_service_factory.h"
Expand Down Expand Up @@ -152,6 +153,9 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
brave_wallet::TxServiceFactory::GetInstance();
brave_wallet::BraveWalletServiceFactory::GetInstance();

if (brave_wallet::IsBitcoinEnabled()) {
brave_wallet::BitcoinWalletServiceFactory::GetInstance();
}
if (brave_wallet::IsZCashEnabled()) {
brave_wallet::ZCashWalletServiceFactory::GetInstance();
}
Expand Down
26 changes: 9 additions & 17 deletions components/brave_wallet/browser/zcash/zcash_rpc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,9 @@ std::string GetPrefixedProtobuf(const std::string& serialized_proto) {
return result;
}

std::string MakeGetAddressUtxosURLParams(
const std::vector<std::string>& addresses) {
std::string MakeGetAddressUtxosURLParams(const std::string& address) {
zcash::GetAddressUtxosRequest request;
for (const auto& address : addresses) {
request.add_addresses(address);
}
request.add_addresses(address);
request.set_maxentries(1);
request.set_startheight(0);
return GetPrefixedProtobuf(request.SerializeAsString());
Expand Down Expand Up @@ -115,24 +112,19 @@ absl::optional<std::string> ResolveSerializedMessage(
if (grpc_response_body.size() < 5) {
return absl::nullopt;
}
if (grpc_response_body.c_str()[0] != 0) {
if (grpc_response_body[0] != 0) {
// Compression is not supported yet
return absl::nullopt;
}
uint32_t size = 0;

uint8_t as_bytes[4];
const char* size_start = &(grpc_response_body.c_str()[1]);
for (int i = 0; i < 4; i++) {
as_bytes[i] = static_cast<uint8_t>(size_start[i]);
}
base::ReadBigEndian<uint32_t>(as_bytes, &size);
base::ReadBigEndian(
reinterpret_cast<const uint8_t*>(&(grpc_response_body[1])), &size);

if (grpc_response_body.size() != size + 5) {
return absl::nullopt;
}

return grpc_response_body.substr(5, grpc_response_body.size() - 5);
return grpc_response_body.substr(5);
}

} // namespace
Expand All @@ -145,7 +137,7 @@ ZCashRpc::ZCashRpc(
ZCashRpc::~ZCashRpc() = default;

void ZCashRpc::GetUtxoList(const std::string& chain_id,
const std::vector<std::string>& addresses,
const std::string& address,
ZCashRpc::GetUtxoListCallback callback) {
GURL request_url = MakeGetAddressUtxosURL(
GetNetworkURL(prefs_, chain_id, mojom::CoinType::ZEC));
Expand All @@ -156,7 +148,7 @@ void ZCashRpc::GetUtxoList(const std::string& chain_id,
}

auto url_loader =
MakeGRPCLoader(request_url, MakeGetAddressUtxosURLParams(addresses));
MakeGRPCLoader(request_url, MakeGetAddressUtxosURLParams(address));

UrlLoadersList::iterator it = url_loaders_list_.insert(
url_loaders_list_.begin(), std::move(url_loader));
Expand All @@ -174,7 +166,6 @@ void ZCashRpc::OnGetUtxosResponse(
const std::unique_ptr<std::string> response_body) {
auto current_loader = std::move(*it);
url_loaders_list_.erase(it);
zcash::GetAddressUtxosResponse response;
if (current_loader->NetError()) {
std::move(callback).Run(base::unexpected("Network error"));
return;
Expand All @@ -191,6 +182,7 @@ void ZCashRpc::OnGetUtxosResponse(
return;
}

zcash::GetAddressUtxosResponse response;
if (!response.ParseFromString(message.value())) {
std::move(callback).Run(base::unexpected("Can't parse response"));
return;
Expand Down
2 changes: 1 addition & 1 deletion components/brave_wallet/browser/zcash/zcash_rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ZCashRpc {
~ZCashRpc();

void GetUtxoList(const std::string& chain_id,
const std::vector<std::string>& addresses,
const std::string& address,
GetUtxoListCallback callback);

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export const CreateAccountModal = () => {
}
{selectedAccountType?.coin === BraveWallet.CoinType.ZEC &&
<SelectWrapper>
<Select value={bitcoinNetwork} onChange={onChangeZCashNetwork}>
<Select value={zcashNetwork} onChange={onChangeZCashNetwork}>
{ZCashNetworkTypes.map((network) => {
return (
<div data-value={network} key={network}>
Expand Down
1 change: 1 addition & 0 deletions components/brave_wallet_ui/constants/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ export interface TransactionProviderErrorRegistry {

export const SupportedCoinTypes = [
BraveWallet.CoinType.SOL,
BraveWallet.CoinType.ETH,
BraveWallet.CoinType.FIL,
BraveWallet.CoinType.BTC,
BraveWallet.CoinType.ZEC
Expand Down
6 changes: 3 additions & 3 deletions components/resources/wallet_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,9 @@
<message name="IDS_BRAVE_WALLET_PRIMARY_NETWORKS" desc="Portfolio settings primary networks title">Primary networks</message>
<message name="IDS_BRAVE_WALLET_ETH_ACCOUNT_DESCRIPTION" desc="Ethereum account description">Ethereum + EVM Chains</message>
<message name="IDS_BRAVE_WALLET_SOL_ACCOUNT_DESCRIPTION" desc="Solana account description">Solana + SVM Chains</message>
<message name="IDS_BRAVE_WALLET_FIL_ACCOUNT_DESCRIPTION" desc="Filecoin account description">Filecoin</message>
<message name="IDS_BRAVE_WALLET_BTC_ACCOUNT_DESCRIPTION" desc="Bitcoin account description">Bitcoin</message>
<message name="IDS_BRAVE_WALLET_ZEC_ACCOUNT_DESCRIPTION" desc="ZCash account description">ZCash</message>
<message name="IDS_BRAVE_WALLET_FIL_ACCOUNT_DESCRIPTION" desc="Filecoin account description" translateable="false">Filecoin</message>
<message name="IDS_BRAVE_WALLET_BTC_ACCOUNT_DESCRIPTION" desc="Bitcoin account description" translateable="false">Bitcoin</message>
<message name="IDS_BRAVE_WALLET_ZEC_ACCOUNT_DESCRIPTION" desc="ZCash account description" translateable="false">ZCash</message>
<message name="IDS_BRAVE_WALLET_SHOW_NETWORK_LOGO_ON_NFTS_TITLE" desc="Show network logo filter title">Network Logo</message>
<message name="IDS_BRAVE_WALLET_SHOW_NETWORK_LOGO_ON_NFTS_DESCRIPTION" desc="Show network logo filter description">Show network logo on NFTs</message>
<message name="IDS_BRAVE_WALLET_SHOW_SPAM_NFTS_TITLE" desc="Show spam NFTs filter title">Spam NFTs</message>
Expand Down

0 comments on commit c37d36f

Please sign in to comment.