Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes for Android EVM networks feature #12204

Merged
merged 2 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,12 @@ public void finishNativeInitialization() {
Spinner spinner = findViewById(R.id.network_spinner);
spinner.setOnItemSelectedListener(this);
mJsonRpcService.getAllNetworks(chains -> {
EthereumChain[] customNetworks = Utils.getCustomNetworks(chains);
EthereumChain[] customNetworks = new EthereumChain[0];
// We want to hide custom networks for BUY and SWAP screens. We are
// going to add a support for SWAP at least in the near future.
if (mActivityType == ActivityType.SEND) {
customNetworks = Utils.getCustomNetworks(chains);
}
// Creating adapter for spinner
NetworkSpinnerAdapter dataAdapter = new NetworkSpinnerAdapter(this,
Utils.getNetworksList(this, customNetworks),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface Launcher {
/**
* Launches BraveWalletAddNetworksFragment.
*/
void launchAddNetwork(String chainId);
void launchAddNetwork(String chainId, boolean activeNetwork);
void setRefresher(Refresher refresher);
}

Expand All @@ -64,12 +64,17 @@ public View onCreateView(
final View view = inflater.inflate(R.layout.brave_wallet_add_network, container, false);

Button btAdd = view.findViewById(R.id.add);
btAdd.setOnClickListener(v -> {
if (!validateInputsAddChain(view)) {
// We have some errors in inputs
return;
}
});
boolean activeNetwork = getActivity().getIntent().getBooleanExtra("activeNetwork", false);
if (!activeNetwork) {
btAdd.setOnClickListener(v -> {
if (!validateInputsAddChain(view)) {
// We have some errors in inputs
return;
}
});
} else {
btAdd.setVisibility(View.GONE);
}
mChainId = getActivity().getIntent().getStringExtra("chainId");
if (!mChainId.isEmpty()) {
btAdd.setText(R.string.brave_wallet_add_network_submit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void onBindViewHolder(PreferenceViewHolder holder) {
TintedDrawable.constructTintedDrawable(getContext(), R.drawable.plus,
R.color.default_control_color_active_baseline),
null, null, null);
mbtAddNetwork.setOnClickListener(view -> { mLauncher.launchAddNetwork(""); });
mbtAddNetwork.setOnClickListener(view -> { mLauncher.launchAddNetwork("", false); });
mLauncher.setRefresher(this);

InitJsonRpcService();
Expand All @@ -71,8 +71,8 @@ public void onConnectionError(MojoException e) {
}

@Override
public void onItemClicked(EthereumChain chain) {
mLauncher.launchAddNetwork(chain.chainId);
public void onItemClicked(EthereumChain chain, boolean activeNetwork) {
mLauncher.launchAddNetwork(chain.chainId, activeNetwork);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ public void setSettingsLauncher(SettingsLauncher settingsLauncher) {
}

@Override
public void launchAddNetwork(String chainId) {
public void launchAddNetwork(String chainId, boolean activeNetwork) {
Intent intent = mSettingsLauncher.createSettingsActivityIntent(
getActivity(), BraveWalletAddNetworksFragment.class.getName());
intent.putExtra("chainId", chainId);
intent.putExtra("activeNetwork", activeNetwork);
startActivityForResult(intent, REQUEST_CODE_ADD_NETWORK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
public class NetworkListBaseAdapter extends RecyclerView.Adapter<ViewHolder> {
interface ItemClickListener {
void onItemClicked(EthereumChain chain);
void onItemClicked(EthereumChain chain, boolean activeNetwork);
void onItemRemove(EthereumChain chain);
void onItemSetAsActive(EthereumChain chain);
}
Expand Down Expand Up @@ -68,7 +68,7 @@ static class RowViewHolder extends ViewHolder {
mListener = listener;
}

protected void updateNetworkInfo(EthereumChain item) {
void updateNetworkInfo(EthereumChain item, boolean activeNetwork) {
mTitle.setText(item.chainName);
String description = item.chainId;
if (item.rpcUrls.length > 0) {
Expand All @@ -80,7 +80,7 @@ protected void updateNetworkInfo(EthereumChain item) {

// The more button will become visible if setMenuButtonDelegate is called.
mMoreButton.setVisibility(View.GONE);
mItem.setOnClickListener(view -> mListener.onItemClicked(item));
mItem.setOnClickListener(view -> mListener.onItemClicked(item, activeNetwork));
}

/**
Expand Down Expand Up @@ -112,18 +112,22 @@ public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
@SuppressLint("NotifyDataSetChanged")
public void onBindViewHolder(ViewHolder viewHolder, int i) {
final EthereumChain info = mElements.get(i);
((RowViewHolder) viewHolder).updateNetworkInfo(info);
boolean activeNetwork = info.chainId.equals(mActiveChainId);
((RowViewHolder) viewHolder).updateNetworkInfo(info, activeNetwork);

if (activeNetwork) {
return;
}

ModelList menuItems = new ModelList();
menuItems.add(buildMenuListItem(R.string.edit, 0, 0));
if (!info.chainId.equals(mActiveChainId)) {
menuItems.add(buildMenuListItem(R.string.remove, 0, 0));
menuItems.add(buildMenuListItem(R.string.brave_wallet_add_network_set_as_active, 0, 0));
}
menuItems.add(buildMenuListItem(R.string.remove, 0, 0));
menuItems.add(buildMenuListItem(R.string.brave_wallet_add_network_set_as_active, 0, 0));

ListMenu.Delegate delegate = (model) -> {
int textId = model.get(ListMenuItemProperties.TITLE_ID);
if (textId == R.string.edit) {
mListener.onItemClicked(info);
mListener.onItemClicked(info, activeNetwork);
} else if (textId == R.string.remove) {
mListener.onItemRemove(info);
} else if (textId == R.string.brave_wallet_add_network_set_as_active) {
Expand Down
Loading