Skip to content

Commit

Permalink
feat: pass in state and client into transaction, to check network inf…
Browse files Browse the repository at this point in the history
…o and account status
  • Loading branch information
HashMapsData2Value committed Oct 23, 2024
1 parent d594ddc commit b451328
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
36 changes: 15 additions & 21 deletions ui/pages/transaction/controller.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package transaction

import (
"encoding/base64"
"fmt"
"context"

encoder "github.com/algonode/algourl/encoder"
msgpack "github.com/algorand/go-algorand-sdk/encoding/msgpack"
Expand All @@ -20,29 +19,24 @@ func (m ViewModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m.HandleMessage(msg)
}

type NetworkParameters struct {
Network string
GenesisHash []byte
}

func (m ViewModel) UpdateTxnURLAndQRCode() error {

// TODO: Replace with a check for online status
goOnline := true
///////////////////////////////////////////////
var format api.AccountInformationParamsFormat = "json"
r, err := m.Client.AccountInformationWithResponse(
context.Background(),
m.Data.Address,
&api.AccountInformationParams{
Format: &format,
})

// TODO: Replace with a fetch of the actual genesis id and hash
genesisHash, err := base64.StdEncoding.DecodeString("wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=")
if err != nil {
fmt.Printf("Failed to decode genesis hash: %v\n", err)
return err
}

extStatus := NetworkParameters{
Network: "mainnet-v1.0",
GenesisHash: genesisHash,
goOnline := false
if r.JSON200.Status == "Online" {
goOnline = true
}
///////////////////////////////////////////////

tx := types.Transaction{}

Expand All @@ -62,8 +56,8 @@ func (m ViewModel) UpdateTxnURLAndQRCode() error {
Fee: 0,
FirstValid: types.Round(*m.Data.EffectiveFirstValid),
LastValid: types.Round(*m.Data.EffectiveLastValid),
GenesisHash: types.Digest(extStatus.GenesisHash),
GenesisID: extStatus.Network,
GenesisHash: types.Digest(m.NetworkParams.GenesisHash),
GenesisID: m.NetworkParams.Network,
},
KeyregTxnFields: types.KeyregTxnFields{
VotePK: types.VotePK(m.Data.Key.VoteParticipationKey),
Expand All @@ -83,8 +77,8 @@ func (m ViewModel) UpdateTxnURLAndQRCode() error {
Fee: 0,
FirstValid: types.Round(*m.Data.EffectiveFirstValid),
LastValid: types.Round(*m.Data.EffectiveLastValid),
GenesisHash: types.Digest(extStatus.GenesisHash),
GenesisID: extStatus.Network,
GenesisHash: types.Digest(m.NetworkParams.GenesisHash),
GenesisID: m.NetworkParams.Network,
},
}
}
Expand Down
19 changes: 18 additions & 1 deletion ui/pages/transaction/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ package transaction

import (
"github.com/algorandfoundation/hack-tui/api"
"github.com/algorandfoundation/hack-tui/internal"
"github.com/algorandfoundation/hack-tui/ui/controls"
"github.com/charmbracelet/lipgloss"
)

var green = lipgloss.NewStyle().Foreground(lipgloss.Color("10"))

type NetworkParameters struct {
Network string
GenesisHash []byte
}

type ViewModel struct {
// Width is the last known horizontal lines
Width int
Expand All @@ -20,6 +26,12 @@ type ViewModel struct {
// Participation Key
Data api.ParticipationKey

// Network/Genesis id and Genesis Hash
NetworkParams NetworkParameters

// client is the API client
Client *api.ClientWithResponses

// Components
controls controls.Model

Expand All @@ -29,8 +41,13 @@ type ViewModel struct {
}

// New creates and instance of the ViewModel with a default controls.Model
func New() ViewModel {
func New(state *internal.StateModel, client *api.ClientWithResponses) ViewModel {
return ViewModel{
Client: client,
NetworkParams: NetworkParameters{
Network: state.Status.Network,
GenesisHash: state.Status.GenesisHash,
},
controls: controls.New(" (a)ccounts | (k)eys | " + green.Render("(t)xn ")),
}
}
2 changes: 1 addition & 1 deletion ui/viewport.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func MakeViewportViewModel(state *internal.StateModel, client *api.ClientWithRes
accountsPage: accounts.New(state),
keysPage: keys.New("", state.ParticipationKeys),
generatePage: generate.New("", client),
transactionPage: transaction.New(),
transactionPage: transaction.New(state, client),

// Current Page
page: AccountsPage,
Expand Down

0 comments on commit b451328

Please sign in to comment.