Skip to content

Commit

Permalink
web/storagenode: payout history table
Browse files Browse the repository at this point in the history
Change-Id: I448ea8424baf31400d9868ef9ca2b8002caa7bbd
  • Loading branch information
NikolaiYurchenko committed Aug 13, 2020
1 parent c548475 commit 4cdba36
Show file tree
Hide file tree
Showing 27 changed files with 1,631 additions and 78 deletions.
25 changes: 18 additions & 7 deletions storagenode/heldamount/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,13 @@ func (service *Service) PayoutHistoryMonthly(ctx context.Context, period string)
paystub.SurgePercent = 100
}

earned := (paystub.CompGetAudit + paystub.CompGet + paystub.CompGetRepair + paystub.CompAtRest) / (paystub.SurgePercent * 100)
surge := earned * paystub.SurgePercent / 100
surge := paystub.CompGetAudit + paystub.CompGet + paystub.CompGetRepair + paystub.CompAtRest
earned := surge / paystub.SurgePercent * 100

heldPercent, err := service.getHeldRate(stats.JoinedAt, paystub.Period)
if err != nil {
return nil, ErrHeldAmountService.Wrap(err)
}

payoutHistory.Held = paystub.Held
payoutHistory.Receipt = paystub.Receipt
Expand All @@ -299,7 +304,7 @@ func (service *Service) PayoutHistoryMonthly(ctx context.Context, period string)
payoutHistory.SurgePercent = paystub.SurgePercent
payoutHistory.SatelliteURL = url.Address
payoutHistory.Paid = paystub.Paid
payoutHistory.HeldPercent = service.getHeldRate(stats.JoinedAt)
payoutHistory.HeldPercent = heldPercent

result = append(result, payoutHistory)
}
Expand Down Expand Up @@ -367,9 +372,15 @@ func (paystub *PayStub) UsageAtRestTbM() {
paystub.UsageAtRest /= 720
}

func (service *Service) getHeldRate(joinTime time.Time) (heldRate int64) {
monthsSinceJoin := date.MonthsCountSince(joinTime)
switch monthsSinceJoin {
func (service *Service) getHeldRate(joinedAt time.Time, period string) (heldRate int64, err error) {
layout := "2006-01-02T15:04:05.000Z"
periodTime, err := time.Parse(layout, period+"-12T11:45:26.371Z")
if err != nil {
return 0, err
}

months := date.MonthsBetweenDates(joinedAt, periodTime)
switch months {
case 0, 1, 2:
heldRate = 75
case 3, 4, 5:
Expand All @@ -380,5 +391,5 @@ func (service *Service) getHeldRate(joinTime time.Time) (heldRate int64) {
heldRate = 0
}

return heldRate
return heldRate, nil
}
6 changes: 6 additions & 0 deletions web/storagenode/src/app/components/SNOHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ export default class SNOHeader extends Vue {
console.error(`${error.message} satellite data.`);
}
try {
await this.$store.dispatch(PAYOUT_ACTIONS.GET_PAYOUT_HISTORY);
} catch (error) {
console.error(error.message);
}
try {
await this.$store.dispatch(PAYOUT_ACTIONS.GET_ESTIMATION, this.$store.state.node.selectedSatellite.id);
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019 Storj Labs, Inc.
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.

<template>
Expand Down Expand Up @@ -112,8 +112,9 @@ export default class SatelliteSelectionDropdownItem extends Vue {
&__image {
position: absolute;
top: 10px;
top: 50%;
left: 10px;
transform: translateY(-50%);
}
&__name {
Expand Down Expand Up @@ -168,7 +169,7 @@ export default class SatelliteSelectionDropdownItem extends Vue {
.disqualified,
.suspended {
margin-left: 20px;
margin-left: 24px;
}
.copy-button {
Expand Down
17 changes: 7 additions & 10 deletions web/storagenode/src/app/components/payments/EstimationArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,15 @@ import {
BANDWIDTH_REPAIR_PRICE_PER_TB,
DISK_SPACE_PRICE_PER_TB, PAYOUT_ACTIONS,
} from '@/app/store/modules/payout';
import { EstimatedPayout, HeldInfo, PayoutInfoRange, PayoutPeriod } from '@/app/types/payout';
import {
EstimatedPayout,
HeldInfo,
monthNames,
PayoutInfoRange,
PayoutPeriod,
} from '@/app/types/payout';
import { formatBytes, TB } from '@/app/utils/converter';
/**
* Holds all months names.
*/
const monthNames = [
'January', 'February', 'March', 'April',
'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December',
];
/**
* Describes table row data item.
*/
Expand Down

0 comments on commit 4cdba36

Please sign in to comment.