fix pixels staying on after render
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
@@ -134,6 +135,47 @@ func (m *mempool) CurrentFees() (int, int, int, error) {
|
||||
return data.Fastest, data.HalfHour, data.Hour, err
|
||||
}
|
||||
|
||||
func (m *mempool) CurrentPrice() (int, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, "https://api.coincap.io/v2/assets/bitcoin", nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp, err := m.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode >= http.StatusInternalServerError {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if resp.StatusCode >= http.StatusBadRequest {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
b, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var data struct {
|
||||
Data struct {
|
||||
PriceUSD string `json:"priceUsd"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
err = json.Unmarshal(b, &data)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
parts := strings.Split(data.Data.PriceUSD, ".")
|
||||
i, err := strconv.Atoi(parts[0])
|
||||
return i, err
|
||||
}
|
||||
|
||||
func (m *mempool) Listen(ctx context.Context, messages chan Message, errs chan error, done chan struct{}) {
|
||||
for {
|
||||
select {
|
||||
|
||||
Reference in New Issue
Block a user