web/storagenode: get current month earnings from estimated payout

The current month estimated earnings on the main dashboard
was calculated on the frontend using hardcoded payout rates for
all satellites.
Instead, we could just use the calculate the current month earnings
from the estimated payout info.

Updates https://github.com/storj/storj-private/issues/245

Change-Id: Ie8ec3e4f2b86455c68f664690ef28bb352107bca
This commit is contained in:
Clement Sam 2023-05-09 06:53:29 +00:00 committed by Storj Robot
parent 1003d8213c
commit d80d674863
5 changed files with 15 additions and 35 deletions

View File

@ -8,7 +8,6 @@ import {
} from '@/app/types/payout';
import { StorageNodeState } from '@/app/types/sno';
import { getHeldPercentage } from '@/app/utils/payout';
import { SizeBreakpoints } from '@/private/memory/size';
import {
EstimatedPayout,
PayoutPeriod,
@ -70,7 +69,6 @@ export function newPayoutModule(service: PayoutService): StoreModule<PayoutState
},
[PAYOUT_MUTATIONS.SET_TOTAL](state: PayoutState, totalPayments: TotalPayments): void {
state.totalPayments = totalPayments;
state.currentMonthEarnings = totalPayments.currentMonthEarnings;
},
[PAYOUT_MUTATIONS.SET_RANGE](state: PayoutState, periodRange: PayoutInfoRange): void {
state.periodRange = periodRange;
@ -83,6 +81,7 @@ export function newPayoutModule(service: PayoutService): StoreModule<PayoutState
},
[PAYOUT_MUTATIONS.SET_ESTIMATION](state: PayoutState, estimatedInfo: EstimatedPayout): void {
state.estimation = estimatedInfo;
state.currentMonthEarnings = estimatedInfo.currentMonth.payout + estimatedInfo.currentMonth.held;
},
[PAYOUT_MUTATIONS.SET_PERIODS](state: PayoutState, periods: PayoutPeriod[]): void {
state.payoutPeriods = periods;
@ -115,26 +114,6 @@ export function newPayoutModule(service: PayoutService): StoreModule<PayoutState
const totalPayments = await service.totalPayments(start, end, satelliteId);
// TODO: move to service
const currentBandwidthDownload = (rootState.node.egressChartData || [])
.map(data => data.egress.usage)
.reduce((previous, current) => previous + current, 0);
const currentBandwidthAuditAndRepair = (rootState.node.egressChartData || [])
.map(data => data.egress.audit + data.egress.repair)
.reduce((previous, current) => previous + current, 0);
const approxHourInMonth = 720;
const currentDiskSpace = (rootState.node.storageChartData || [])
.map(data => data.atRestTotal)
.reduce((previous, current) => previous + current, 0) / approxHourInMonth;
const thisMonthEarnings = (currentBandwidthDownload * BANDWIDTH_DOWNLOAD_PRICE_PER_TB
+ currentBandwidthAuditAndRepair * BANDWIDTH_REPAIR_PRICE_PER_TB
+ currentDiskSpace * DISK_SPACE_PRICE_PER_TB) / SizeBreakpoints.TB;
totalPayments.setCurrentMonthEarnings(thisMonthEarnings);
commit(PAYOUT_MUTATIONS.SET_HELD_PERCENT, getHeldPercentage(rootState.node.selectedSatellite.joinDate));
commit(PAYOUT_MUTATIONS.SET_TOTAL, totalPayments);
},

View File

@ -54,6 +54,12 @@ export default class Dashboard extends Vue {
console.error(error);
}
try {
await this.$store.dispatch(PAYOUT_ACTIONS.GET_ESTIMATION);
} catch (error) {
console.error(error);
}
await this.$store.dispatch(APPSTATE_ACTIONS.SET_LOADING, false);
}
}

View File

@ -178,8 +178,6 @@ export class TotalPayments {
public held = 0;
public paid = 0;
public disposed = 0;
// TODO: remove
public currentMonthEarnings = 0;
public balance = 0;
public constructor(
@ -193,10 +191,6 @@ export class TotalPayments {
});
}
public setCurrentMonthEarnings(value: number): void {
this.currentMonthEarnings = value;
}
private convertToCents(value: number): number {
return value / PRICE_DIVIDER;
}

View File

@ -6,7 +6,7 @@ import { createLocalVue, shallowMount } from '@vue/test-utils';
import { newPayoutModule, PAYOUT_MUTATIONS } from '@/app/store/modules/payout';
import { PayoutHttpApi } from '@/storagenode/api/payout';
import { Paystub, TotalPayments } from '@/storagenode/payouts/payouts';
import { EstimatedPayout, Paystub, PreviousMonthEstimatedPayout, TotalPayments } from '@/storagenode/payouts/payouts';
import { PayoutService } from '@/storagenode/payouts/service';
import TotalPayoutArea from '@/app/components/TotalPayoutArea.vue';
@ -45,10 +45,15 @@ describe('TotalPayoutArea', (): void => {
paystub.paid = 1000000;
const totalPayments = new TotalPayments([paystub]);
totalPayments.setCurrentMonthEarnings(40000);
await store.commit(PAYOUT_MUTATIONS.SET_TOTAL, totalPayments);
const currentMonthEstimation = new PreviousMonthEstimatedPayout();
currentMonthEstimation.payout = 30000;
currentMonthEstimation.held = 10000;
const estimation = new EstimatedPayout();
estimation.currentMonth = currentMonthEstimation;
await store.commit(PAYOUT_MUTATIONS.SET_ESTIMATION, estimation);
expect(wrapper).toMatchSnapshot();
totalPayments.held = 400000;

View File

@ -63,7 +63,6 @@ describe('mutations', (): void => {
paystub.distributed = 500000;
const totalPayments = new TotalPayments([paystub]);
totalPayments.setCurrentMonthEarnings(22);
store.commit(PAYOUT_MUTATIONS.SET_TOTAL, totalPayments);
@ -71,7 +70,6 @@ describe('mutations', (): void => {
expect(state.payoutModule.totalPayments.paid).toBe(100);
expect(state.payoutModule.totalPayments.disposed).toBe(10);
expect(state.payoutModule.totalPayments.balance).toBe(50);
expect(state.payoutModule.currentMonthEarnings).toBe(22);
});
it('sets period range', (): void => {
@ -277,7 +275,6 @@ describe('actions', () => {
expect(state.payoutModule.totalPayments.paid).toBe(200);
expect(state.payoutModule.totalPayments.disposed).toBe(5);
expect(state.payoutModule.totalPayments.balance).toBe(150);
expect(state.payoutModule.currentMonthEarnings).toBe(0);
});
it('get total throws an error when api call fails', async (): Promise<void> => {
@ -290,7 +287,6 @@ describe('actions', () => {
expect(state.payoutModule.totalPayments.held).toBe(5);
expect(state.payoutModule.totalPayments.paid).toBe(200);
expect(state.payoutModule.totalPayments.balance).toBe(150);
expect(state.payoutModule.currentMonthEarnings).toBe(0);
}
});