From d4212e24e64273567fb36bc8e93f28d46b970abf Mon Sep 17 00:00:00 2001 From: Marco van Dijk Date: Fri, 22 Apr 2022 01:38:03 +0200 Subject: [PATCH] fix sorting by fees then stake --- src/components/WinnerMonth.js | 107 +++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 47 deletions(-) diff --git a/src/components/WinnerMonth.js b/src/components/WinnerMonth.js index 680bb6e..82f00e2 100644 --- a/src/components/WinnerMonth.js +++ b/src/components/WinnerMonth.js @@ -136,53 +136,6 @@ const WinnerMonth = (obj) => { orchList = [...obj.data.winningTicketsReceived]; } - let sortedList = []; - if (orchList.length) { - // Sort this months data - while (orchList.length) { - let ticketIdx2 = orchList.length - 1; - let largestIdx = 0; - let largestValue = 0; - let thisVal = null; - // Find current O with most ticket wins in Eth - while (ticketIdx2 >= 0) { - const currentOrch = orchList[ticketIdx2]; - thisVal = currentOrch.sum; - if (!thisVal) { - ticketIdx2 -= 1; - continue; - } - if (thisVal > largestValue) { - largestIdx = ticketIdx2; - largestValue = thisVal; - } - ticketIdx2 -= 1; - } - // Else try to sort by stake - if (!thisVal) { - ticketIdx2 = orchList.length - 1; - while (ticketIdx2 >= 0) { - const currentOrch = orchList[ticketIdx2]; - thisVal = currentOrch.totalStake; - if (!thisVal) { - ticketIdx2 -= 1; - continue; - } - if (thisVal > largestValue) { - largestIdx = ticketIdx2; - largestValue = thisVal; - } - ticketIdx2 -= 1; - } - } - // Push current biggest list - sortedList.push(orchList[largestIdx]); - // Remove from list - orchList.splice(largestIdx, 1); - } - } - - // Pies for earnings overview let earningsObj; if (obj.data.winningTicketsReceived && obj.data.winningTicketsReceived.length) { @@ -242,6 +195,66 @@ const WinnerMonth = (obj) => { ; } + let sortedList = []; + if (orchList.length) { + // Sort this months data + while (orchList.length) { + let ticketIdx2 = orchList.length - 1; + let largestIdx = 0; + let largestValue = 0; + + // Find current O with most ticket wins in Eth + while (ticketIdx2 >= 0) { + const currentOrch = orchList[ticketIdx2]; + let thisVal; + + for (const obj of ticketList) { + if (obj.address == currentOrch.address) { + thisVal = obj.sum; + } + } + + if (!thisVal) { + ticketIdx2 -= 1; + continue; + } + if (thisVal > largestValue) { + largestIdx = ticketIdx2; + largestValue = thisVal; + } + ticketIdx2 -= 1; + } + // Else try to sort by stake + if (!largestValue) { + ticketIdx2 = orchList.length - 1; + while (ticketIdx2 >= 0) { + const currentOrch = orchList[ticketIdx2]; + let thisVal; + + for (const obj of stakeList) { + if (obj.address == currentOrch.address) { + thisVal = obj.totalStake; + } + } + + if (!thisVal) { + ticketIdx2 -= 1; + continue; + } + if (thisVal > largestValue) { + largestIdx = ticketIdx2; + largestValue = thisVal; + } + ticketIdx2 -= 1; + } + } + // Push current biggest list + sortedList.push(orchList[largestIdx]); + // Remove from list + orchList.splice(largestIdx, 1); + } + } + return (
{obj.data.reactivationCount ?