Masternode improvements

-Added support for a couple masternode list and count formats that do not have a separate fieldname for each value
-Masternode grid columns are now shown or hidden based on whether there is any data
This commit is contained in:
Joe Uhren
2024-02-02 15:21:45 -07:00
parent f57db7c033
commit dace981d6a
4 changed files with 271 additions and 61 deletions
+52 -2
View File
@@ -133,6 +133,56 @@ function encodeP2PKaddress(p2pk_descriptor, cb) {
});
}
function normalizeMasternodeCount(raw_count) {
// check if any data was returned
if (raw_count != null) {
// check if the data is in the expected object format
if (raw_count.total != null && raw_count.enabled != null) {
// data is already in the correct format
return raw_count;
} else {
const regex = /^\d+ \/ \d+$/;
// check if the data is in the format of "{enabled_count} / {total_count}"
if (regex.test(raw_count)) {
const splitCount = raw_count.split('/');
// enabled / total format detected
// return the data formatted as an object
return {
enabled: splitCount[0].trim(),
total: splitCount[1].trim()
};
// check if the data is in the format of "Total: {total_count} Enabled: {enabled_count}"
} else if (raw_count.indexOf('Total: ') > -1 && raw_count.indexOf('Enabled: ')) {
// Total: {total_count} Enabled: {enabled_count}" format detected
const totalRegex = /Total: (\d+)/;
const enabledRegex = /Enabled: (\d+)/;
const totalMatch = raw_count.match(totalRegex);
const enabledMatch = raw_count.match(enabledRegex);
// check if both the total and enabled values were found
if (totalMatch && enabledMatch) {
// return the data formatted as an object
return {
total: totalMatch[1],
enabled: enabledMatch[1]
};
} else {
// the data is in an unrecognized format
return raw_count;
}
} else {
// the data is in an unrecognized format
return raw_count;
}
}
} else {
// no data returned, so nothing to fix
return raw_count;
}
}
module.exports = {
convert_to_satoshi: function(amount, cb) {
// fix to 8dp & convert to string
@@ -358,7 +408,7 @@ module.exports = {
if (response == 'There was an error. Check your console.')
return cb(null);
else
return cb(response);
return cb(normalizeMasternodeCount(response));
});
} else {
var uri = base_url + 'getmasternodecount';
@@ -368,7 +418,7 @@ module.exports = {
if (body == 'There was an error. Check your console.')
return cb(null);
else
return cb(body);
return cb(normalizeMasternodeCount(body));
});
}
} else {