WIP: rearranged stuff

This commit is contained in:
Nils Stinnesbeck 2020-11-22 18:33:27 +01:00
parent 21ba0458e1
commit b7dd4e221f
6 changed files with 165 additions and 73 deletions

69
cake.go
View File

@ -35,75 +35,6 @@ type rewards struct {
Swapped map[time.Month]string
}
// CakeRewards needs a comment
func CakeRewards(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
d := data{
Title: "Pool by Cake Rewards",
}
// 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
d.Colors = getOtherColors(color, 8)
d.Currency = currency
}
d.Uploaded = true
// prettify.Print(rewards)
render(w, "rewards.html", d)
}
// create a new line instance
}
func getCumulative(r rewards, precision int) map[time.Month]string {
// create map to calculate cumulative rewards
res := make(map[time.Month]string)

75
kraken.go Normal file
View File

@ -0,0 +1,75 @@
package main
import (
"net/http"
"time"
)
// KrakenRewards needs a comment
func KrakenRewards(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
d := data{
Title: "Kraken Rewards",
}
// 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
d.Colors = getOtherColors(color, 8)
d.Currency = currency
}
d.Uploaded = true
// prettify.Print(rewards)
render(w, "rewards.html", d)
}
// create a new line instance
}

View File

@ -10,8 +10,8 @@ func main() {
// when navigating to /home it should serve the home page
http.HandleFunc("/", Home)
http.HandleFunc("/rewards", CakeRewards)
http.HandleFunc("/table", CakeRewards)
http.HandleFunc("/rewards", Rewards)
http.HandleFunc("/kraken", Rewards)
http.ListenAndServe(":8080", nil)
}

80
rewards.go Normal file
View File

@ -0,0 +1,80 @@
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
d := data{}
// 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
d.Colors = getOtherColors(color, 8)
d.Currency = currency
}
d.Uploaded = true
render(w, "rewards.html", d)
}
// create a new line instance
}

View File

@ -22,10 +22,12 @@
<li><a {{ if (eq .Title "Home") }}class="active"{{end}} href="/">Home</a></li>
<!-- <li><a {{ if (eq .Title "Rewards") }}class="active"{{end}} href="rewards">Monthly Rewards</a></li> -->
<!-- <li><a {{ if (eq .Title "Graphs") }}class="active"{{end}} href="graphs">Graphs</a></li> -->
<li><a {{ if (eq .Title "Pool by Cake Rewards") }}class="active"{{end}} href="rewards">Pool by Cake Rewards</a></li>
<li><a {{ if (eq .Title "Cake") }}class="active"{{end}} href="rewards">Pool by Cake Rewards</a></li>
<li><a {{ if (eq .Title "Kraken") }}class="active"{{end}} href="kraken">Kraken Rewards</a></li>
{{ end }}
</ul>
</nav>
{{end}}
{{define "footer"}}

View File

@ -2,9 +2,13 @@
<div class="mainbody">
{{if not .Success}}
<!-- not successful -->
<p>If you upload your CSV file from Cake here, we will display some graphs here</p>
<p>If you upload your CSV file from {{.Title}} here, we will display some graphs here</p>
<div class="indent">
{{ if eq .Title "Cake" }}
<form enctype="multipart/form-data" action="/rewards" method="post">
{{ else }}
<form enctype="multipart/form-data" action="/kraken" method="post">
{{ end }}
<input type="file" name="csvFile" />
<input type="submit" value="upload" />
</form>