Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tjayrush committed Jul 19, 2024
1 parent 047c59f commit 51fa5b7
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 222 deletions.
26 changes: 26 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (
"text/template"
"time"

"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
"github.com/TrueBlocks/trueblocks-dalledress/pkg/config"
"github.com/TrueBlocks/trueblocks-dalledress/pkg/dalle"
Expand All @@ -35,6 +37,29 @@ type App struct {
Series dalle.Series `json:"series"`
names []types.Name
dalleCache map[string]*dalle.DalleDress
renderCtxs map[base.Address][]output.RenderCtx
}

func (a *App) RegisterRenderCtx(addr base.Address, ctx output.RenderCtx) {
if a.renderCtxs == nil {
a.renderCtxs = make(map[base.Address][]output.RenderCtx)
}
a.renderCtxs[addr] = append(a.renderCtxs[addr], ctx)
}

func (a *App) Cancel(addr base.Address) (int, bool) {
if len(a.renderCtxs) == 0 {
return 0, false
}
if a.renderCtxs[addr] == nil {
return 0, true
}
n := len(a.renderCtxs[addr])
for i := 0; i < len(a.renderCtxs[addr]); i++ {
a.renderCtxs[addr][i].Cancel()
}
a.renderCtxs[addr] = nil
return n, true
}

func NewApp() *App {
Expand Down Expand Up @@ -62,6 +87,7 @@ func NewApp() *App {
if a.authorTemplate, err = template.New("author").Parse(authorTemplate); err != nil {
logger.Fatal("could not create prompt template:", err)
}
logger.Info()
logger.Info("Compiled templates")

a.ReloadDatabases()
Expand Down
2 changes: 1 addition & 1 deletion app/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"sync"

"github.com/TrueBlocks/trueblocks-core/sdk"
"github.com/TrueBlocks/trueblocks-core/sdk/v3"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
"github.com/TrueBlocks/trueblocks-dalledress/pkg/dalle"
Expand Down
15 changes: 9 additions & 6 deletions app/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
)

var historyMap = map[base.Address][]types.Transaction{}
var addrToHistoryMap = map[base.Address][]types.Transaction{}

func (a *App) GetHistory(addr string, first, pageSize int) []types.Transaction {
address := base.HexToAddress(addr)
Expand All @@ -14,31 +14,34 @@ func (a *App) GetHistory(addr string, first, pageSize int) []types.Transaction {
{
TransactionIndex: 1,
BlockNumber: 1,
BlockHash: base.HexToHash("0x730724cb08a6eb17bf6b3296359d261570d343ea7944a17a9d7287d77900db01"),
},
{
TransactionIndex: 2,
BlockNumber: 2,
BlockHash: base.HexToHash("0x730724cb08a6eb17bf6b3296359d261570d343ea7944a17a9d7287d77900db02"),
},
{
TransactionIndex: 3,
BlockNumber: 3,
BlockHash: base.HexToHash("0x730724cb08a6eb17bf6b3296359d261570d343ea7944a17a9d7287d77900db03"),
},
}
}

var ret []types.Transaction
if len(historyMap[address]) == 0 {
if len(addrToHistoryMap[address]) == 0 {
return ret
}
first = base.Max(0, base.Min(first, len(historyMap[address])-1))
last := base.Min(len(historyMap[address]), first+pageSize)
return historyMap[address][first:last]
first = base.Max(0, base.Min(first, len(addrToHistoryMap[address])-1))
last := base.Min(len(addrToHistoryMap[address]), first+pageSize)
return addrToHistoryMap[address][first:last]
}

func (a *App) GetHistoryCnt(addr string) int {
address := base.HexToAddress(addr)
if address.IsZero() {
return 3
}
return len(historyMap[address])
return len(addrToHistoryMap[address])
}
2 changes: 1 addition & 1 deletion app/names.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app

import (
"github.com/TrueBlocks/trueblocks-core/sdk"
"github.com/TrueBlocks/trueblocks-core/sdk/v3"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
)
Expand Down
6 changes: 6 additions & 0 deletions frontend/wailsjs/go/app/App.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
import {base} from '../models';
import {types} from '../models';
import {config} from '../models';
import {dalle} from '../models';
import {output} from '../models';

export function Cancel(arg1:base.Address):Promise<number|boolean>;

export function GenerateEnhanced(arg1:string):Promise<string>;

Expand Down Expand Up @@ -46,6 +50,8 @@ export function LoadSeries():Promise<dalle.Series>;

export function MakeDalleDress(arg1:string):Promise<dalle.DalleDress>;

export function RegisterRenderCtx(arg1:base.Address,arg2:output.RenderCtx):Promise<void>;

export function ReloadDatabases():Promise<void>;

export function Save(arg1:string):Promise<boolean>;
Expand Down
8 changes: 8 additions & 0 deletions frontend/wailsjs/go/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT

export function Cancel(arg1) {
return window['go']['app']['App']['Cancel'](arg1);
}

export function GenerateEnhanced(arg1) {
return window['go']['app']['App']['GenerateEnhanced'](arg1);
}
Expand Down Expand Up @@ -86,6 +90,10 @@ export function MakeDalleDress(arg1) {
return window['go']['app']['App']['MakeDalleDress'](arg1);
}

export function RegisterRenderCtx(arg1, arg2) {
return window['go']['app']['App']['RegisterRenderCtx'](arg1, arg2);
}

export function ReloadDatabases() {
return window['go']['app']['App']['ReloadDatabases']();
}
Expand Down
51 changes: 0 additions & 51 deletions frontend/wailsjs/go/base/Address.d.ts

This file was deleted.

91 changes: 0 additions & 91 deletions frontend/wailsjs/go/base/Address.js

This file was deleted.

17 changes: 17 additions & 0 deletions frontend/wailsjs/go/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,23 @@ export namespace dalle {

}

export namespace output {

export class RenderCtx {


static createFrom(source: any = {}) {
return new RenderCtx(source);
}

constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);

}
}

}

export namespace types {

export class Parameter {
Expand Down
25 changes: 0 additions & 25 deletions frontend/wailsjs/go/types/Transaction.d.ts

This file was deleted.

43 changes: 0 additions & 43 deletions frontend/wailsjs/go/types/Transaction.js

This file was deleted.

Loading

0 comments on commit 51fa5b7

Please sign in to comment.