-
Notifications
You must be signed in to change notification settings - Fork 2
/
store.go
62 lines (52 loc) · 1.88 KB
/
store.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
55
56
57
58
59
60
61
62
package store
import (
"context"
"github.com/earn-alliance/wallet-commander-cli/internal/log"
"github.com/earn-alliance/wallet-commander-cli/internal/query"
"github.com/earn-alliance/wallet-commander-cli/pkg/api"
"github.com/hasura/go-graphql-client"
)
type Store interface {
UpdateWalletCommandTransactionSuccess(id string, transaction string)
UpdateWalletCommandTransactionError(id string, status api.WalletCommanderStatus, msg string)
UpdateWalletCommanderActiveClient(clientId string, connected bool)
}
type WalletCommanderStore struct {
client *graphql.Client
}
func New(graphqlServerEndpoint string) Store {
return &WalletCommanderStore{
client: graphql.NewClient(graphqlServerEndpoint, nil),
}
}
func (w *WalletCommanderStore) UpdateWalletCommandTransactionSuccess(id string, transaction string) {
err := w.client.Mutate(context.Background(), &query.UpdateCommandResults, query.NewUpdateCommandResultsVars(
id,
transaction,
api.CommandStatusSuccess,
"",
))
if err != nil {
log.Logger().Errorf("could not update wallet command transaction to a successful state with err: %v", err)
}
}
func (w *WalletCommanderStore) UpdateWalletCommandTransactionError(id string, status api.WalletCommanderStatus, msg string) {
err := w.client.Mutate(context.Background(), &query.UpdateCommandResults, query.NewUpdateCommandResultsVars(
id,
"",
status,
msg,
))
if err != nil {
log.Logger().Errorf("could not update wallet command transaction to a errored state with err: %v", err)
}
}
func (w *WalletCommanderStore) UpdateWalletCommanderActiveClient(clientId string, connected bool) {
err := w.client.Mutate(context.Background(), &query.UpsertWalletCommanderActiveClients, query.NewUpsertWalletCommanderActiveClientVars(
clientId,
connected,
))
if err != nil {
log.Logger().Errorf("could not update wallet command active clients to a errored state with err: %v", err)
}
}