Skip to content

Commit ea3cc0c

Browse files
committed
Pulls forms and data tables into separate file
1 parent f351d08 commit ea3cc0c

File tree

92 files changed

+1133
-931
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1133
-931
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@
1818
"typescript.preferences.importModuleSpecifier": "relative",
1919
"typescript.suggest.autoImports": true,
2020
"javascript.suggest.autoImports": true,
21-
"editor.acceptSuggestionOnEnter": "on"
21+
"editor.acceptSuggestionOnEnter": "on",
22+
"files.associations": {
23+
"*.tbx": "json"
24+
}
2225
}

app/app.go

Lines changed: 83 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,29 @@ package app
33
import (
44
"context"
55
"encoding/json"
6-
"os"
7-
"path/filepath"
6+
"errors"
7+
"fmt"
88
"sync"
99

1010
"github.com/TrueBlocks/trueblocks-browse/pkg/daemons"
11-
"github.com/TrueBlocks/trueblocks-browse/pkg/messages"
1211
"github.com/TrueBlocks/trueblocks-browse/pkg/types"
1312
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
14-
coreConfig "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config"
1513
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file"
1614
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
15+
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/names"
1716
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
1817
coreTypes "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
19-
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils"
2018
sdk "github.com/TrueBlocks/trueblocks-sdk/v3"
2119
"github.com/wailsapp/wails/v2/pkg/runtime"
2220
)
2321

2422
type App struct {
25-
sdk.Globals `json:",inline"`
23+
sdk.Globals
2624

2725
ctx context.Context
2826
meta coreTypes.MetaData
2927
dirty bool
3028

31-
renderCtxs map[base.Address][]*output.RenderCtx
32-
3329
// Containers
3430
projects types.ProjectContainer
3531
monitors types.MonitorContainer
@@ -43,101 +39,112 @@ type App struct {
4339
config types.ConfigContainer
4440

4541
// Memory caches
46-
HistoryCache *types.HistoryMap `json:"historyCache"`
47-
EnsCache *sync.Map `json:"ensCache"`
48-
BalanceCache *sync.Map `json:"balanceCache"`
42+
ensCache *sync.Map
43+
balanceCache *sync.Map
44+
namesMap map[base.Address]coreTypes.Name
45+
historyCache *types.HistoryMap
46+
renderCtxs map[base.Address][]*output.RenderCtx
4947

5048
// Controllers
51-
ScraperController *daemons.DaemonScraper
52-
FreshenController *daemons.DaemonFreshen
53-
IpfsController *daemons.DaemonIpfs
49+
scraperController *daemons.DaemonScraper
50+
freshenController *daemons.DaemonFreshen
51+
ipfsController *daemons.DaemonIpfs
52+
53+
// During initialization, we do things that may cause errors, but
54+
// we have not yet opened the window, so we defer them until we can
55+
// decide what to do.
56+
deferredErrors []error
57+
}
58+
59+
func (a *App) String() string {
60+
bytes, _ := json.Marshal(a)
61+
return string(bytes)
5462
}
5563

5664
func NewApp() *App {
57-
a := App{
58-
renderCtxs: make(map[base.Address][]*output.RenderCtx),
65+
a := &App{
66+
ensCache: &sync.Map{},
67+
balanceCache: &sync.Map{},
68+
namesMap: make(map[base.Address]coreTypes.Name),
69+
historyCache: &types.HistoryMap{},
70+
renderCtxs: make(map[base.Address][]*output.RenderCtx),
5971
}
60-
a.EnsCache = &sync.Map{}
61-
a.BalanceCache = &sync.Map{}
62-
a.HistoryCache = &types.HistoryMap{}
63-
a.names.NamesMap = make(map[base.Address]coreTypes.Name)
64-
a.projects = types.NewProjectContainer("", []types.HistoryContainer{})
72+
a.freshenController = daemons.NewFreshen(a, "freshen", 3000, a.IsShowing("freshen"))
73+
a.scraperController = daemons.NewScraper(a, "scraper", 7000, a.IsShowing("scraper"))
74+
a.ipfsController = daemons.NewIpfs(a, "ipfs", 10000, a.IsShowing("ipfs"))
6575
a.session.LastSub = make(map[string]string)
6676

67-
return &a
77+
return a
6878
}
6979

70-
func (a *App) String() string {
71-
bytes, _ := json.MarshalIndent(a, "", " ")
72-
return string(bytes)
73-
}
80+
var ErrLoadingNames = errors.New("error loading names")
81+
var ErrWindowSize = errors.New("error fixing window size")
7482

7583
func (a *App) Startup(ctx context.Context) {
7684
a.ctx = ctx
77-
a.loadSession()
78-
a.Chain = a.session.LastChain
7985

80-
a.FreshenController = daemons.NewFreshen(a, "freshen", 3000, a.IsShowing("freshen"))
81-
a.ScraperController = daemons.NewScraper(a, "scraper", 7000, a.IsShowing("scraper"))
82-
a.IpfsController = daemons.NewIpfs(a, "ipfs", 10000, a.IsShowing("ipfs"))
83-
go a.startDaemons()
86+
// We do various setups prior to showing the window. Improves interactivity.
87+
// But...something may fail, so we need to keep track of errors.
88+
var err error
89+
if err = a.session.Load(); err != nil {
90+
a.deferredErrors = append(a.deferredErrors, err)
91+
}
8492

85-
fn := filepath.Join(a.session.LastFolder, a.session.LastFile)
86-
if file.FileExists(fn) {
87-
a.LoadFile(fn)
88-
a.dirty = false
89-
} else {
90-
a.dirty = true
93+
// Load the trueBlocks.toml file
94+
if err = a.config.Load(); err != nil {
95+
a.deferredErrors = append(a.deferredErrors, err)
96+
}
97+
if a.session.LastChain, err = a.config.IsValidChain(a.session.LastChain); err != nil {
98+
a.deferredErrors = append(a.deferredErrors, err)
9199
}
100+
a.Chain = a.session.LastChain
92101

93-
logger.Info("Starting freshen process...")
94-
_ = a.Refresh()
102+
// We always need names, so let's load it before showing the window
103+
if a.namesMap, err = names.LoadNamesMap(a.getChain(), coreTypes.All, nil); err == nil {
104+
wErr := fmt.Errorf("%w: %v", ErrLoadingNames, err)
105+
a.deferredErrors = append(a.deferredErrors, wErr)
106+
}
95107
}
96108

109+
// DomReady is called by Wails when the app is ready to go. Adjust the window size and show it.
97110
func (a *App) DomReady(ctx context.Context) {
98-
win := a.GetWindow()
99-
runtime.WindowSetPosition(a.ctx, win.X, win.Y)
100-
runtime.WindowSetSize(a.ctx, win.Width, win.Height)
101-
runtime.WindowShow(a.ctx)
111+
var err error
102112

103-
if path, err := utils.GetConfigFn("", "trueBlocks.toml"); err != nil {
104-
messages.EmitMessage(a.ctx, messages.Error, &messages.MessageMsg{
105-
String1: err.Error(),
106-
})
107-
} else {
108-
if err := coreConfig.ReadToml(path, &a.config.Config); err != nil {
109-
messages.EmitMessage(a.ctx, messages.Error, &messages.MessageMsg{
110-
String1: err.Error(),
111-
})
112-
}
113+
// We're ready to open the window, but first we need to make sure it will show...
114+
if a.session.Window, err = a.session.CleanWindowSize(a.ctx); err != nil {
115+
wErr := fmt.Errorf("%w: %v", ErrWindowSize, err)
116+
a.deferredErrors = append(a.deferredErrors, wErr)
117+
}
118+
// DO NOT COLLAPSE - A VALID WINDOW IS RETURNED EVEN ON ERROR
119+
runtime.WindowSetPosition(a.ctx, a.session.Window.X, a.session.Window.Y)
120+
runtime.WindowSetSize(a.ctx, a.session.Window.Width, a.session.Window.Height)
121+
runtime.WindowShow(a.ctx)
122+
if err != nil {
123+
a.deferredErrors = append(a.deferredErrors, err)
113124
}
114-
}
115125

116-
func (a *App) Shutdown(ctx context.Context) {
117-
a.saveSession()
118-
}
126+
// We now have a window, so we can finally show any accumulated errors
127+
for _, err := range a.deferredErrors {
128+
a.emitErrorMsg(err, nil)
129+
}
119130

120-
func (a *App) saveSession() {
121-
if !isTesting {
122-
a.session.Window.X, a.session.Window.Y = runtime.WindowGetPosition(a.ctx)
123-
a.session.Window.Width, a.session.Window.Height = runtime.WindowGetSize(a.ctx)
124-
a.session.Window.Y += 38 // TODO: This is a hack to account for the menu bar - not sure why it's needed
131+
fn := a.getFullPath()
132+
if file.FileExists(fn) {
133+
a.readFile(fn)
134+
} else {
135+
a.newFile()
125136
}
126-
_ = a.session.Save()
127-
}
128137

129-
func (a *App) loadSession() {
130-
_ = a.session.Load()
131-
a.session.CleanWindowSize(a.ctx)
132-
a.Chain = a.session.LastChain
133-
}
138+
go a.Refresh()
134139

135-
func (a *App) Logger(msg string) {
136-
logger.Info(msg)
137-
}
140+
go a.freshenController.Run()
141+
go a.scraperController.Run()
142+
go a.ipfsController.Run()
138143

139-
var isTesting bool
144+
logger.Info("Fininished loading...")
145+
}
140146

141-
func init() {
142-
isTesting = os.Getenv("TB_TEST_MODE") == "true"
147+
// Shutdown is called by Wails when the app is closed
148+
func (a *App) Shutdown(ctx context.Context) {
149+
a.saveSession()
143150
}

app/app_debug.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

app/app_getters.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,12 @@ func (a *App) GetEnv(key string) string {
3434
return os.Getenv(key)
3535
}
3636

37-
func (a *App) GetMeta() coreTypes.MetaData {
38-
return a.meta
39-
}
40-
4137
func (a *App) GetAppTitle() string {
4238
return a.session.Window.Title
4339
}
4440

4541
func (a *App) GetRoute() string {
46-
if !a.IsConfigured() {
42+
if !a.isConfigured() {
4743
return "/wizard"
4844
}
4945

@@ -55,12 +51,12 @@ func (a *App) GetRoute() string {
5551
return route
5652
}
5753

58-
func (a *App) GetAddress() base.Address {
54+
func (a *App) GetSelected() base.Address {
5955
addr := a.session.LastSub["/history"]
6056
return base.HexToAddress(addr)
6157
}
6258

63-
func (a *App) GetChain() string {
59+
func (a *App) getChain() string {
6460
return a.Chain
6561
}
6662

app/app_info.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package app
2+
3+
import (
4+
"path/filepath"
5+
6+
coreTypes "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
7+
)
8+
9+
type AppInfo struct {
10+
Chain string `json:"chain"`
11+
Filename string `json:"filename"`
12+
Dirty bool `json:"dirty"`
13+
Meta coreTypes.MetaData `json:"meta"`
14+
State coreTypes.WizState `json:"state"`
15+
IsConfigured bool `json:"isConfigured"`
16+
}
17+
18+
func (a *App) getFolder() string {
19+
return a.session.LastFolder
20+
}
21+
22+
func (a *App) getFilename() string {
23+
return a.session.LastFile
24+
}
25+
26+
func (a *App) getFullPath() string {
27+
return filepath.Join(a.getFolder(), a.getFilename())
28+
}
29+
30+
func (a *App) GetAppInfo() AppInfo {
31+
return AppInfo{
32+
Chain: a.Chain,
33+
Filename: a.getFullPath(),
34+
Dirty: a.dirty,
35+
Meta: a.meta,
36+
State: a.getWizardState(),
37+
IsConfigured: a.isConfigured(),
38+
}
39+
}

app/app_setters.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package app
33
import (
44
"os"
55

6-
"github.com/TrueBlocks/trueblocks-browse/pkg/types"
76
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
87
)
98

@@ -22,11 +21,12 @@ func (a *App) SetRoute(route, subRoute string) {
2221
}
2322

2423
func (a *App) SetChain(chain string, address base.Address) {
25-
a.CancelAllContexts() // cancel what's happening on the old chain
24+
a.emitInfoMsg("Switching to chain", chain)
25+
a.CancelAllContexts()
2626
a.Chain = chain
2727
a.session.LastChain = chain
2828
a.saveSession()
29-
a.Reload(address)
29+
a.GoToAddress(address)
3030
a.monitors = types.MonitorContainer{}
3131
a.names = types.NameContainer{}
3232
a.abis = types.AbiContainer{}

app/data_abi.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"sync/atomic"
1010
"time"
1111

12-
"github.com/TrueBlocks/trueblocks-browse/pkg/messages"
1312
"github.com/TrueBlocks/trueblocks-browse/pkg/types"
1413
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
1514
coreTypes "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
@@ -76,12 +75,10 @@ func (a *App) loadAbis(wg *sync.WaitGroup, errorChan chan error) error {
7675
// EXISTING_CODE
7776
// EXISTING_CODE
7877
if err := sdk.SortAbis(a.abis.Items, a.abis.Sorts); err != nil {
79-
messages.EmitMessage(a.ctx, messages.Error, &messages.MessageMsg{
80-
String1: err.Error(),
81-
})
78+
a.emitErrorMsg(err, nil)
8279
}
8380
a.abis.Summarize()
84-
messages.EmitMessage(a.ctx, messages.Info, &messages.MessageMsg{String1: "Loaded abis"})
81+
a.emitInfoMsg("Loaded abis", "")
8582
}
8683

8784
return nil
@@ -95,10 +92,7 @@ func (a *App) ModifyAbi(modData *ModifyData) error {
9592
opts.Globals.Decache = true
9693

9794
if _, _, err := opts.Abis(); err != nil {
98-
messages.EmitMessage(a.ctx, messages.Error, &messages.MessageMsg{
99-
String1: err.Error(),
100-
Address: modData.Address,
101-
})
95+
a.emitAddressErrorMsg(err, modData.Address)
10296
return err
10397
} else {
10498
newAbis := make([]coreTypes.Abi, 0, len(a.abis.Items))
@@ -113,8 +107,7 @@ func (a *App) ModifyAbi(modData *ModifyData) error {
113107
}
114108
a.abis.LastUpdate = time.Time{}
115109
a.abis.Items = newAbis
116-
msg := fmt.Sprintf("ModifyAbi delete: %s", modData.Address.Hex())
117-
messages.EmitMessage(a.ctx, messages.Info, &messages.MessageMsg{String1: msg})
110+
a.emitInfoMsg("ModifyAbi delete", modData.Address.Hex())
118111
return nil
119112
}
120113
}

0 commit comments

Comments
 (0)