From 9079f4cf2b9c65167b76a4670f2a381bd5d29a1d Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Thu, 8 Apr 2021 02:59:23 -0300 Subject: [PATCH] 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. --- package-lock.json | 4 +- package.json | 2 +- .../service_node/service_node_list.vue | 6 +-- .../service_node/service_node_staking.vue | 4 +- src/mixins/service_node_mixin.js | 40 +++++++++++++------ 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7632445..5f80b4c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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": { diff --git a/package.json b/package.json index 1c5b2f3..64e1cc1 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/components/service_node/service_node_list.vue b/src/components/service_node/service_node_list.vue index f8f8312..ae97546 100644 --- a/src/components/service_node/service_node_list.vue +++ b/src/components/service_node/service_node_list.vue @@ -30,9 +30,9 @@ {{ $t("strings.serviceNodeDetails.minContribution") }}: - {{ getMinContribution(node) }} OXEN • + {{ getMinContribution(node, our_address) }} OXEN • {{ $t("strings.serviceNodeDetails.maxContribution") }}: - {{ openForContriubtionOxen(node) }} OXEN + {{ openForContributionOxen(node, our_address) }} OXEN @@ -118,7 +118,7 @@ export default { nodeWithMinContribution(node) { const nodeWithMinContribution = { ...node, - minContribution: this.getMinContribution(node) + minContribution: this.getMinContribution(node, this.our_address) }; return nodeWithMinContribution; }, diff --git a/src/components/service_node/service_node_staking.vue b/src/components/service_node/service_node_staking.vue index 7ede1a7..e2940f6 100644 --- a/src/components/service_node/service_node_staking.vue +++ b/src/components/service_node/service_node_staking.vue @@ -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; diff --git a/src/mixins/service_node_mixin.js b/src/mixins/service_node_mixin.js index 3972ac6..87056cd 100644 --- a/src/mixins/service_node_mixin.js +++ b/src/mixins/service_node_mixin.js @@ -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); } } };