goCake/rewards.go

82 lines
1.8 KiB
Go
Raw Normal View History

2020-11-22 17:33:27 +00:00
package main
import (
"net/http"
"time"
)
// Rewards needs a comment
func Rewards(w http.ResponseWriter, r *http.Request) {
type data struct {
Title string
Uploaded bool
Success bool
Rewards rewards
CumulativeRewards map[time.Month]string
Colors []string
Currency string
ErrorText string
Lending bool
}
// set common attributes
2021-01-16 14:13:12 +00:00
var d data
2020-11-22 17:33:27 +00:00
// set title according to site that called this function
switch r.URL.Path {
case "/rewards":
d.Title = "Cake"
case "/kraken":
d.Title = "Kraken"
}
// check the method used to access this site (GET/POST)
switch r.Method {
case http.MethodGet:
// display upload site
d.Uploaded = false
d.Success = false
render(w, "rewards.html", d)
case http.MethodPost:
// upload the file that was posted here
var success bool = false
lines, err := uploadFile(w, r)
if err == nil {
success = true
} else {
// set ErrorText
d.ErrorText = err.Error()
}
// prepare data for usage
var color string
var currency string
var precision int
var rewards rewards
if success == true {
currency = lines[1].Cryptocurrency
color, precision, d.Lending = getCurrencyOpts(currency)
rewards = monthlyRewardOverview(lines)
d.CumulativeRewards = getCumulative(rewards, precision)
d.Success = success
d.Rewards.Staking = rewards.Staking
d.Rewards.Confectionery = rewards.Confectionery
d.Rewards.Lapis = rewards.Lapis
d.Rewards.LapisDFI = rewards.LapisDFI
d.Rewards.Referral = rewards.Referral
d.Rewards.Airdrop = rewards.Airdrop
d.Rewards.Swapped = rewards.Swapped
2021-01-16 14:13:12 +00:00
d.Rewards.Deposits = rewards.Deposits
2020-11-22 17:33:27 +00:00
d.Colors = getOtherColors(color, 8)
d.Currency = currency
}
d.Uploaded = true
render(w, "rewards.html", d)
}
// create a new line instance
}