uses function remove() to delete existing network ("testnet" for example), then add a new custom network with the same name ("testnet"), expecting the function get("testnet") will return the added custom network object, but actually we get a undefined object.
function removeNetwork(network) {
...
for (var key in networkMaps) {
const index = networkMaps[key].indexOf(network);
if (index >= 0) {
delete networkMaps[key][index]; // it leaves an _undefined_ object in the array instead of removing it!
}
}
}
function get(arg, keys) {
...
if(networkMaps[arg] && networkMaps[arg].length >= 1) {
return networkMaps[arg][0]; // it returns the _undefined_ object without checking if it is a valid network.
} else {
return networkMaps[arg];
}
}
bug fix
function removeNetwork(network) {
...
for (var key in networkMaps) {
const index = networkMaps[key].indexOf(network);
if (index >= 0) {
networkMaps[key].splice(index, 1); //remove it physically.
}
}
}
src:
issue
uses function remove() to delete existing network ("testnet" for example), then add a new custom network with the same name ("testnet"), expecting the function get("testnet") will return the added custom network object, but actually we get a undefined object.
root cause
bug fix