Skip to content

Commit

Permalink
Adjust final calc
Browse files Browse the repository at this point in the history
Minimize
  • Loading branch information
Liquid369 committed Apr 25, 2023
1 parent 766b314 commit ff1fc44
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
2 changes: 1 addition & 1 deletion index.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,6 @@ <h4 class="stake-balances" style="background-color: #2c0044; border-radius: 10px
</div>
</div>
</div>
</div>

<br />

Expand All @@ -1012,6 +1011,7 @@ <h4 class="stake-balances" style="background-color: #2c0044; border-radius: 10px
</button>
</center>
</div>
</div>

<div id="Settings" class="tabcontent">
<label for="currency" data-i18n="settingsCurrency">Choose a display currency:</label>
Expand Down
9 changes: 5 additions & 4 deletions scripts/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,15 +513,16 @@ export async function updateStakingRewardsGUI() {

export async function updateMasternodeRewardsGUI() {
const network = getNetwork();
const masternodeRewards = await network.getMasternodeRewards();
const arrMasternodeRewards = await network.getMasternodeRewards();

if (network.areRewardsMasternodeComplete) {
// Hide the load more button
doms.domGuiMasternodeLoadMore.style.display = 'none';
}

//DOMS.DOM-optimised list generation
const strList = masternodeRewards
.map(
const strList = arrMasternodeRewards
.map(
(cReward) =>
`<i style="opacity: 0.75; cursor: pointer" onclick="window.open('${
cExplorer.url + '/tx/' + cReward.id
Expand All @@ -533,7 +534,7 @@ export async function updateMasternodeRewardsGUI() {
)
.join('<br>');
// Calculate total
const nRewards = masternodeRewards.reduce(
const nRewards = arrMasternodeRewards.reduce(
(total, reward) => total + reward.amount,
0
);
Expand Down
29 changes: 9 additions & 20 deletions scripts/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class ExplorerNetwork extends Network {
this.blocks = 0;

this.arrRewards = [];
this.masternodeRewards = [];
this.arrMnRewards = [];
this.rewardsSyncing = false;
this.rewardsMasternodeSyncing = false;
}
Expand Down Expand Up @@ -349,35 +349,24 @@ export class ExplorerNetwork extends Network {
*/
async getMasternodeRewards() {
if (this.rewardsMasternodeSyncing) {
return this.masternodeRewards;
return this.arrMnRewards;
}
if(localStorage.getItem('masternode')) {
const cMasternode = new Masternode(
JSON.parse(localStorage.getItem('masternode'))
);
const cMasternodeData = await cMasternode.getFullData();
if (this.rewardsMasternodeSyncing) {
return this.masternodeRewards;
return this.arrMnRewards;
}
try {
if (!this.enabled || this.areRewardsMasternodeComplete)
return this.masternodeRewards;
return this.arrMnRewards;
this.rewardsMasternodeSyncing = true;
const nHeight = this.masternodeRewards.length
? this.masternodeRewards[this.masternodeRewards.length - 1].blockHeight
const nHeight = this.arrMnRewards.length
? this.arrMnRewards[this.arrMnRewards.length - 1].blockHeight
: 0;
const mapPaths = new Map();
const txSum = (v) =>
v.reduce(
(t, s) =>
t +
(s.addresses
.map((strAddr) => mapPaths.get(strAddr))
.filter((v) => v).length && s.addresses.length === 2
? parseInt(s.value)
: 0),
0
);
let cData;
cData = await (
await fetch(
Expand All @@ -391,7 +380,7 @@ export class ExplorerNetwork extends Network {
mapPaths.set(cMasternodeData.addr, ':)');
if (cData && cData.transactions) {
// Update rewards
this.masternodeRewards = this.masternodeRewards.concat(
this.arrMnRewards = this.arrMnRewards.concat(
cData.transactions
.filter(
(tx) => tx.vout[0].addresses[0] === 'CoinStake TX'
Expand All @@ -401,7 +390,7 @@ export class ExplorerNetwork extends Network {
id: tx.txid,
time: tx.blockTime,
blockHeight: tx.blockHeight,
amount: txSum(tx.vout.slice(-1)) / COIN,
amount: tx.vout[2].value / COIN,
};
})
.filter((tx) => tx.amount != 0)
Expand All @@ -412,7 +401,7 @@ export class ExplorerNetwork extends Network {
this.areMasternodeRewardsComplete = true;
}
}
return this.masternodeRewards;
return this.arrMnRewards;
} catch (e) {
console.error(e);
} finally {
Expand Down

0 comments on commit ff1fc44

Please sign in to comment.