-
Notifications
You must be signed in to change notification settings - Fork 920
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
Show test networks separately #19467
Changes from 5 commits
0d12f56
0cd9180
03072d7
26a5572
8b687b0
d194853
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,6 @@ | |
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class NetworkModel implements JsonRpcServiceObserver { | ||
|
@@ -65,6 +64,7 @@ public class NetworkModel implements JsonRpcServiceObserver { | |
private final MediatorLiveData<List<NetworkInfo>> _mPrimaryNetworks; | ||
private final MediatorLiveData<List<NetworkInfo>> _mSecondaryNetworks; | ||
private Map<String, NetworkSelectorModel> mNetworkSelectorMap; | ||
private MutableLiveData<NetworkLists> _mNetworkLists; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated d194853 |
||
private OriginInfo mOriginInfo; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated d194853 |
||
public final LiveData<String[]> mCustomNetworkIds; | ||
public LiveData<NetworkInfo> mNeedToCreateAccountForNetwork; | ||
|
@@ -76,6 +76,7 @@ public class NetworkModel implements JsonRpcServiceObserver { | |
public final LiveData<NetworkInfo> mDefaultNetwork; | ||
public final LiveData<List<NetworkInfo>> mPrimaryNetworks; | ||
public final LiveData<List<NetworkInfo>> mSecondaryNetworks; | ||
public LiveData<NetworkLists> mNetworkLists; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated d194853 |
||
private Origin mOrigin; | ||
|
||
public NetworkModel(BraveWalletService braveWalletService, JsonRpcService jsonRpcService, | ||
|
@@ -109,6 +110,8 @@ public NetworkModel(BraveWalletService braveWalletService, JsonRpcService jsonRp | |
mSecondaryNetworks = _mSecondaryNetworks; | ||
jsonRpcService.addObserver(this); | ||
mNetworkSelectorMap = new HashMap<>(); | ||
_mNetworkLists = new MutableLiveData<>(); | ||
mNetworkLists = _mNetworkLists; | ||
_mPairChainAndNetwork.setValue(Pair.create("", Collections.emptyList())); | ||
_mPairChainAndNetwork.addSource(_mChainId, chainId -> { | ||
_mPairChainAndNetwork.setValue( | ||
|
@@ -271,23 +274,23 @@ public void refreshNetworks() { | |
} | ||
|
||
static void getAllNetworks(JsonRpcService jsonRpcService, List<Integer> supportedCoins, | ||
Callbacks.Callback1<Set<NetworkInfo>> callback) { | ||
Callbacks.Callback1<List<NetworkInfo>> callback) { | ||
if (jsonRpcService == null) { | ||
callback.call(Collections.emptySet()); | ||
callback.call(Collections.emptyList()); | ||
return; | ||
} | ||
|
||
NetworkResponsesCollector networkResponsesCollector = | ||
new NetworkResponsesCollector(jsonRpcService, supportedCoins); | ||
networkResponsesCollector.getNetworks(networkInfoSet -> { | ||
networkResponsesCollector.getNetworks(networkInfoList -> { | ||
if (!AndroidUtils.isDebugBuild()) { | ||
networkInfoSet = | ||
networkInfoSet.stream() | ||
networkInfoList = | ||
networkInfoList.stream() | ||
.filter(networkInfo | ||
-> !NetworkUtils.Filters.isLocalNetwork(networkInfo)) | ||
.collect(Collectors.toSet()); | ||
.collect(Collectors.toList()); | ||
} | ||
callback.call(networkInfoSet); | ||
callback.call(networkInfoList); | ||
}); | ||
} | ||
|
||
|
@@ -311,8 +314,31 @@ public void init() { | |
} | ||
} | ||
|
||
getAllNetworks(mJsonRpcService, mSharedData.getSupportedCryptoCoins(), | ||
allNetworks -> { _mCryptoNetworks.postValue(new ArrayList<>(allNetworks)); }); | ||
getAllNetworks( | ||
mJsonRpcService, mSharedData.getSupportedCryptoCoins(), cryptoNetworks -> { | ||
_mCryptoNetworks.postValue(cryptoNetworks); | ||
|
||
List<NetworkInfo> primary = new ArrayList<>(); | ||
List<NetworkInfo> secondary = new ArrayList<>(); | ||
List<NetworkInfo> test = new ArrayList<>(); | ||
NetworkLists networkLists = | ||
new NetworkLists(cryptoNetworks, primary, secondary, test); | ||
for (NetworkInfo networkInfo : cryptoNetworks) { | ||
if (WalletConstants.SUPPORTED_TOP_LEVEL_CHAIN_IDS.contains( | ||
networkInfo.chainId)) { | ||
primary.add(networkInfo); | ||
} else if (WalletConstants.KNOWN_TEST_CHAIN_IDS.contains( | ||
networkInfo.chainId)) { | ||
test.add(networkInfo); | ||
} else if (!WalletConstants.SUPPORTED_TOP_LEVEL_CHAIN_IDS.contains( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can just do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's just a matter of taste, but I would probably add a forth There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replaced with |
||
networkInfo.chainId) | ||
&& !WalletConstants.KNOWN_TEST_CHAIN_IDS.contains( | ||
networkInfo.chainId)) { | ||
secondary.add(networkInfo); | ||
} | ||
} | ||
_mNetworkLists.postValue(networkLists); | ||
}); | ||
} | ||
} | ||
|
||
|
@@ -455,4 +481,33 @@ public void onConnectionError(MojoException e) {} | |
|
||
@Override | ||
public void close() {} | ||
|
||
public static class NetworkLists { | ||
// Networks from core. | ||
public List<NetworkInfo> mCoreNetworks; | ||
public List<NetworkInfo> mPrimaryNetworkList; | ||
public List<NetworkInfo> mSecondaryNetworkList; | ||
public List<NetworkInfo> mTestNetworkList; | ||
|
||
public NetworkLists() { | ||
mCoreNetworks = Collections.emptyList(); | ||
mPrimaryNetworkList = Collections.emptyList(); | ||
mSecondaryNetworkList = Collections.emptyList(); | ||
mTestNetworkList = Collections.emptyList(); | ||
} | ||
public NetworkLists(List<NetworkInfo> mCoreNetworks, List<NetworkInfo> mPrimaryNetworkList, | ||
List<NetworkInfo> mSecondaryNetworkList, List<NetworkInfo> mTestNetworkList) { | ||
this.mCoreNetworks = mCoreNetworks; | ||
this.mPrimaryNetworkList = mPrimaryNetworkList; | ||
this.mSecondaryNetworkList = mSecondaryNetworkList; | ||
this.mTestNetworkList = mTestNetworkList; | ||
} | ||
|
||
public NetworkLists(NetworkLists networkLists) { | ||
this.mCoreNetworks = new ArrayList<>(networkLists.mCoreNetworks); | ||
this.mPrimaryNetworkList = new ArrayList<>(networkLists.mPrimaryNetworkList); | ||
this.mSecondaryNetworkList = new ArrayList<>(networkLists.mSecondaryNetworkList); | ||
this.mTestNetworkList = new ArrayList<>(networkLists.mTestNetworkList); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getSubTestNetworks
method is unused and can be safely removed now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated d194853