diff --git a/web/storagenode/src/app/store/modules/payout.ts b/web/storagenode/src/app/store/modules/payout.ts index f9338c89c..95e3c445e 100644 --- a/web/storagenode/src/app/store/modules/payout.ts +++ b/web/storagenode/src/app/store/modules/payout.ts @@ -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 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); }, diff --git a/web/storagenode/src/app/views/DashboardArea.vue b/web/storagenode/src/app/views/DashboardArea.vue index 7de670bbe..b7498b610 100644 --- a/web/storagenode/src/app/views/DashboardArea.vue +++ b/web/storagenode/src/app/views/DashboardArea.vue @@ -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); } } diff --git a/web/storagenode/src/storagenode/payouts/payouts.ts b/web/storagenode/src/storagenode/payouts/payouts.ts index e30c13d7f..9e509f1f5 100644 --- a/web/storagenode/src/storagenode/payouts/payouts.ts +++ b/web/storagenode/src/storagenode/payouts/payouts.ts @@ -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; } diff --git a/web/storagenode/tests/unit/components/payments/TotalPayoutArea.spec.ts b/web/storagenode/tests/unit/components/payments/TotalPayoutArea.spec.ts index 12c76672f..3295472a0 100644 --- a/web/storagenode/tests/unit/components/payments/TotalPayoutArea.spec.ts +++ b/web/storagenode/tests/unit/components/payments/TotalPayoutArea.spec.ts @@ -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; diff --git a/web/storagenode/tests/unit/store/payout.spec.ts b/web/storagenode/tests/unit/store/payout.spec.ts index d7c24b07c..7a99ecf00 100644 --- a/web/storagenode/tests/unit/store/payout.spec.ts +++ b/web/storagenode/tests/unit/store/payout.spec.ts @@ -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 => { @@ -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); } });