Skip to content

Commit f351d08

Browse files
committed
Shit
1 parent 6055f79 commit f351d08

File tree

150 files changed

+2107
-1571
lines changed

Some content is hidden

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

150 files changed

+2107
-1571
lines changed

app/app.go

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,30 @@ package app
33
import (
44
"context"
55
"encoding/json"
6+
"os"
7+
"path/filepath"
68
"sync"
79

810
"github.com/TrueBlocks/trueblocks-browse/pkg/daemons"
911
"github.com/TrueBlocks/trueblocks-browse/pkg/messages"
1012
"github.com/TrueBlocks/trueblocks-browse/pkg/types"
1113
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
1214
coreConfig "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config"
13-
configTypes "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/configtypes"
15+
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file"
1416
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
1517
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
1618
coreTypes "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
17-
coreUtils "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils"
19+
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils"
1820
sdk "github.com/TrueBlocks/trueblocks-sdk/v3"
1921
"github.com/wailsapp/wails/v2/pkg/runtime"
2022
)
2123

2224
type App struct {
2325
sdk.Globals `json:",inline"`
2426

25-
ctx context.Context
26-
cfg configTypes.Config
27-
meta coreTypes.MetaData
27+
ctx context.Context
28+
meta coreTypes.MetaData
29+
dirty bool
2830

2931
renderCtxs map[base.Address][]*output.RenderCtx
3032

@@ -35,10 +37,15 @@ type App struct {
3537
abis types.AbiContainer
3638
indexes types.IndexContainer
3739
manifests types.ManifestContainer
38-
settings types.SettingsGroup
39-
configs types.ConfigContainer
4040
status types.StatusContainer
41-
sessions types.SessionContainer
41+
settings types.SettingsGroup
42+
session types.SessionContainer
43+
config types.ConfigContainer
44+
45+
// Memory caches
46+
HistoryCache *types.HistoryMap `json:"historyCache"`
47+
EnsCache *sync.Map `json:"ensCache"`
48+
BalanceCache *sync.Map `json:"balanceCache"`
4249

4350
// Controllers
4451
ScraperController *daemons.DaemonScraper
@@ -50,9 +57,12 @@ func NewApp() *App {
5057
a := App{
5158
renderCtxs: make(map[base.Address][]*output.RenderCtx),
5259
}
60+
a.EnsCache = &sync.Map{}
61+
a.BalanceCache = &sync.Map{}
62+
a.HistoryCache = &types.HistoryMap{}
5363
a.names.NamesMap = make(map[base.Address]coreTypes.Name)
54-
a.projects = types.NewProjectContainer("Untitled.tbx", &types.HistoryMap{}, &sync.Map{}, &sync.Map{})
55-
a.sessions.LastSub = make(map[string]string)
64+
a.projects = types.NewProjectContainer("", []types.HistoryContainer{})
65+
a.session.LastSub = make(map[string]string)
5666

5767
return &a
5868
}
@@ -65,14 +75,21 @@ func (a *App) String() string {
6575
func (a *App) Startup(ctx context.Context) {
6676
a.ctx = ctx
6777
a.loadSession()
68-
69-
go a.loadHistory(a.GetAddress(), nil, nil)
78+
a.Chain = a.session.LastChain
7079

7180
a.FreshenController = daemons.NewFreshen(a, "freshen", 3000, a.IsShowing("freshen"))
7281
a.ScraperController = daemons.NewScraper(a, "scraper", 7000, a.IsShowing("scraper"))
7382
a.IpfsController = daemons.NewIpfs(a, "ipfs", 10000, a.IsShowing("ipfs"))
7483
go a.startDaemons()
7584

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
91+
}
92+
7693
logger.Info("Starting freshen process...")
7794
_ = a.Refresh()
7895
}
@@ -83,12 +100,12 @@ func (a *App) DomReady(ctx context.Context) {
83100
runtime.WindowSetSize(a.ctx, win.Width, win.Height)
84101
runtime.WindowShow(a.ctx)
85102

86-
if path, err := coreUtils.GetConfigFn("", "trueBlocks.toml"); err != nil {
103+
if path, err := utils.GetConfigFn("", "trueBlocks.toml"); err != nil {
87104
messages.EmitMessage(a.ctx, messages.Error, &messages.MessageMsg{
88105
String1: err.Error(),
89106
})
90107
} else {
91-
if err := coreConfig.ReadToml(path, &a.cfg); err != nil {
108+
if err := coreConfig.ReadToml(path, &a.config.Config); err != nil {
92109
messages.EmitMessage(a.ctx, messages.Error, &messages.MessageMsg{
93110
String1: err.Error(),
94111
})
@@ -101,18 +118,26 @@ func (a *App) Shutdown(ctx context.Context) {
101118
}
102119

103120
func (a *App) saveSession() {
104-
a.sessions.Window.X, a.sessions.Window.Y = runtime.WindowGetPosition(a.ctx)
105-
a.sessions.Window.Width, a.sessions.Window.Height = runtime.WindowGetSize(a.ctx)
106-
a.sessions.Window.Y += 38 // TODO: This is a hack to account for the menu bar - not sure why it's needed
107-
_ = a.sessions.Save()
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
125+
}
126+
_ = a.session.Save()
108127
}
109128

110129
func (a *App) loadSession() {
111-
_ = a.sessions.Load()
112-
a.sessions.CleanWindowSize(a.ctx)
113-
a.Chain = a.sessions.LastChain
130+
_ = a.session.Load()
131+
a.session.CleanWindowSize(a.ctx)
132+
a.Chain = a.session.LastChain
114133
}
115134

116135
func (a *App) Logger(msg string) {
117136
logger.Info(msg)
118137
}
138+
139+
var isTesting bool
140+
141+
func init() {
142+
isTesting = os.Getenv("TB_TEST_MODE") == "true"
143+
}

app/app_getters.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ import (
1111
)
1212

1313
func (a *App) IsShowing(which string) bool {
14-
return a.sessions.Toggles.IsOn(which)
14+
return a.session.Toggles.IsOn(which)
1515
}
1616

1717
func (a *App) GetConfig() *configTypes.Config {
18-
return &a.cfg
18+
return &a.config.Config
1919
}
2020

2121
func (a *App) GetSession() *coreTypes.Session {
22-
return &a.sessions.Session
22+
return &a.session.Session
2323
}
2424

2525
func (a *App) GetContext() context.Context {
2626
return a.ctx
2727
}
2828

2929
func (a *App) GetWindow() *coreTypes.Window {
30-
return &a.sessions.Window
30+
return &a.session.Window
3131
}
3232

3333
func (a *App) GetEnv(key string) string {
@@ -39,24 +39,24 @@ func (a *App) GetMeta() coreTypes.MetaData {
3939
}
4040

4141
func (a *App) GetAppTitle() string {
42-
return a.sessions.Window.Title
42+
return a.session.Window.Title
4343
}
4444

4545
func (a *App) GetRoute() string {
4646
if !a.IsConfigured() {
4747
return "/wizard"
4848
}
4949

50-
route := a.sessions.LastRoute
51-
if len(a.sessions.LastSub) > 0 {
52-
route += "/" + a.sessions.LastSub[route]
50+
route := a.session.LastRoute
51+
if len(a.session.LastSub) > 0 {
52+
route += "/" + a.session.LastSub[route]
5353
}
5454

5555
return route
5656
}
5757

5858
func (a *App) GetAddress() base.Address {
59-
addr := a.sessions.LastSub["/history"]
59+
addr := a.session.LastSub["/history"]
6060
return base.HexToAddress(addr)
6161
}
6262

@@ -66,7 +66,7 @@ func (a *App) GetChain() string {
6666

6767
func (a *App) GetChains() []string {
6868
ret := []string{}
69-
for _, chain := range a.cfg.Chains {
69+
for _, chain := range a.GetConfig().Chains {
7070
ret = append(ret, chain.Chain)
7171
}
7272
sort.Strings(ret)

app/app_setters.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func (a *App) SetShowing(which string, onOff bool) {
11-
a.sessions.Toggles.SetState(which, onOff)
11+
a.session.Toggles.SetState(which, onOff)
1212
a.saveSession()
1313
}
1414

@@ -17,14 +17,14 @@ func (a *App) SetEnv(key, value string) {
1717
}
1818

1919
func (a *App) SetRoute(route, subRoute string) {
20-
a.sessions.SetRoute(route, subRoute)
20+
a.session.SetRoute(route, subRoute)
2121
a.saveSession()
2222
}
2323

2424
func (a *App) SetChain(chain string, address base.Address) {
2525
a.CancelAllContexts() // cancel what's happening on the old chain
2626
a.Chain = chain
27-
a.sessions.LastChain = chain
27+
a.session.LastChain = chain
2828
a.saveSession()
2929
a.Reload(address)
3030
a.monitors = types.MonitorContainer{}

app/data_abi.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// This file is auto-generated. Edit only code inside
2+
// of ExistingCode markers (if any).
13
package app
24

35
// EXISTING_CODE
@@ -81,6 +83,7 @@ func (a *App) loadAbis(wg *sync.WaitGroup, errorChan chan error) error {
8183
a.abis.Summarize()
8284
messages.EmitMessage(a.ctx, messages.Info, &messages.MessageMsg{String1: "Loaded abis"})
8385
}
86+
8487
return nil
8588
}
8689

app/data_abi_test.go

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

app/data_config.go

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

app/data_config_test.go

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

0 commit comments

Comments
 (0)