Fix staking for reserved contribution spots

Reserved contributions for the current wallet were not properly being
added into the available contribution room available to a wallet; this
fixes it to include any unfilled reserved spots when showing available
stakes.
This commit is contained in:
Jason Rhinelander 2021-04-08 02:59:23 -03:00
parent 2d1188f2ad
commit 9079f4cf2b
5 changed files with 36 additions and 20 deletions

4
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "loki-electron-wallet",
"version": "1.5.4",
"name": "oxen-electron-wallet",
"version": "1.5.7",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "oxen-electron-wallet",
"version": "1.5.6",
"version": "1.5.7",
"description": "Modern GUI interface for Oxen Currency",
"productName": "Oxen Electron Wallet",
"repository": {

View File

@ -30,9 +30,9 @@
</span>
<span v-if="node.awaitingContribution" class="contrib-amounts">
{{ $t("strings.serviceNodeDetails.minContribution") }}:
{{ getMinContribution(node) }} OXEN
{{ getMinContribution(node, our_address) }} OXEN
{{ $t("strings.serviceNodeDetails.maxContribution") }}:
{{ openForContriubtionOxen(node) }} OXEN
{{ openForContributionOxen(node, our_address) }} OXEN
</span>
</q-item-label>
</q-item-section>
@ -118,7 +118,7 @@ export default {
nodeWithMinContribution(node) {
const nodeWithMinContribution = {
...node,
minContribution: this.getMinContribution(node)
minContribution: this.getMinContribution(node, this.our_address)
};
return nodeWithMinContribution;
},

View File

@ -289,11 +289,11 @@ export default {
},
minStake() {
const node = this.getNodeWithPubKey();
return this.getMinContribution(node);
return this.getMinContribution(node, this.award_address);
},
maxStake() {
const node = this.getNodeWithPubKey();
return this.openForContriubtionOxen(node);
return this.openForContributionOxen(node, this.award_address);
},
getFeeDecimal(node) {
const operatorPortion = node.portions_for_operator;

View File

@ -1,27 +1,43 @@
export default {
methods: {
getMinContribution(node) {
// Returns the atomic, unfilled, reserved contributions for the given wallet
getUnfilledReservedContribution(node, addr) {
for (const contributor of node.contributors)
if (contributor.address === addr && contributor.amount === 0 && contributor.reserved > 0)
return contributor.reserved;
return 0;
},
getMinContribution(node, myaddr) {
if (node.funded)
return 0;
const MAX_NUMBER_OF_CONTRIBUTORS = 4;
// This is calculated in the same way it is calculated on the LokiBlocks site
const openContributionRemaining = this.openForContribution(node);
const minContributionAtomicUnits =
!node.funded && node.contributors.length < MAX_NUMBER_OF_CONTRIBUTORS
? openContributionRemaining /
(MAX_NUMBER_OF_CONTRIBUTORS - node.contributors.length)
: 0;
// If we have a reserved spot then that is our minimum:
let minContributionAtomicUnits = this.getUnfilledReservedContribution(node, myaddr);
// Otherwise we can contribute our fair share of whatever amount is left (i.e. REMAINING/N
// when there are N available spots).
if (minContributionAtomicUnits === 0 && node.contributors.length < MAX_NUMBER_OF_CONTRIBUTORS) {
const openContributionRemaining = this.openForContribution(node);
minContributionAtomicUnits = openContributionRemaining /
(MAX_NUMBER_OF_CONTRIBUTORS - node.contributors.length);
}
const minContributionOxen = minContributionAtomicUnits / 1e9;
// ceiling to 4 decimal places
return minContributionOxen.toFixed(4);
},
openForContribution(node) {
const openContributionRemaining =
openForContribution(node, addr = null) {
let openContributionRemaining =
node.staking_requirement > node.total_reserved
? node.staking_requirement - node.total_reserved
: 0;
if (addr)
openContributionRemaining += this.getUnfilledReservedContribution(node, addr);
return openContributionRemaining;
},
openForContriubtionOxen(node) {
return (this.openForContribution(node) / 1e9).toFixed(4);
openForContributionOxen(node, addr = null) {
return (this.openForContribution(node, addr) / 1e9).toFixed(4);
}
}
};