-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallet.go
54 lines (48 loc) · 1.29 KB
/
wallet.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"clout/display"
"clout/models"
"clout/network"
"clout/session"
"encoding/json"
"fmt"
"sort"
)
func HandleWallet(argMap map[string]string) {
pub58, username, balance, _ := session.LoggedInAs()
fmt.Println(username, balance)
fmt.Println("")
ListAssets(pub58)
}
func ListAssets(key string) {
js := network.GetUsersStateless(key)
var us models.UsersStateless
json.Unmarshal([]byte(js), &us)
fields := []string{"username", "balance", "price", "worth"}
sizes := []int{20, 11, 10, 10}
YouHODL := us.UserList[0].UsersYouHODL
sort.SliceStable(YouHODL, func(i, j int) bool {
return YouHODL[i].BalanceNanos > YouHODL[j].BalanceNanos
})
total := 0.0
for _, thing := range YouHODL {
value := display.OneE9Float(thing.ProfileEntryResponse.CoinPriceBitCloutNanos) *
display.OneE9Float(thing.BalanceNanos)
total += value
}
display.Row(sizes,
"",
"",
"",
display.Float(total))
display.Header(sizes, fields...)
for _, thing := range YouHODL {
value := display.OneE9Float(thing.ProfileEntryResponse.CoinPriceBitCloutNanos) *
display.OneE9Float(thing.BalanceNanos)
display.Row(sizes,
thing.ProfileEntryResponse.Username,
display.OneE9(thing.BalanceNanos),
display.OneE9(thing.ProfileEntryResponse.CoinPriceBitCloutNanos),
display.Float(value))
}
}