feat: integrate nebula UI with worker-assets-gen

This commit is contained in:
Prad Nukala 2024-10-07 21:15:25 -04:00
parent e926e5b9d6
commit af6e07323b
22 changed files with 114 additions and 101 deletions

View File

@ -289,11 +289,7 @@ testnet-basic: setup-testnet
sh-testnet: mod-tidy sh-testnet: mod-tidy
CHAIN_ID="sonr-testnet-1" BLOCK_TIME="1000ms" CLEAN=true sh scripts/test_node.sh CHAIN_ID="sonr-testnet-1" BLOCK_TIME="1000ms" CLEAN=true sh scripts/test_node.sh
start-hway: hway .PHONY: setup-testnet set-testnet-configs testnet testnet-basic sh-testnet
@echo "(start-proxy) Starting proxy server"
./build/hway start
.PHONY: setup-testnet set-testnet-configs testnet testnet-basic sh-testnet start-hway
############################################################################### ###############################################################################
@ -323,11 +319,13 @@ gen-pkl:
build-hway: gen-templ gen-pkl build-hway: gen-templ gen-pkl
@echo "(motr) Building Highway gateway" @echo "(motr) Building Highway gateway"
go build -o ./build/hway ./cmd/hway go run github.com/syumai/workers/cmd/workers-assets-gen@v0.23.1 -o ./web/build -mode go
GOOS=js GOARCH=wasm go build -o ./web/build/app.wasm ./web/server.go
build-motr: gen-templ gen-pkl build-motr: gen-templ gen-pkl
@echo "(dwn) Building motr.wasm -> Service Worker IPFS Vault" @echo "(dwn) Building motr.wasm -> Service Worker IPFS Vault"
GOOS=js GOARCH=wasm go build -o ./pkg/dwn/app.wasm ./cmd/motr/motr.go GOOS=js GOARCH=wasm go build -o ./pkg/dwn/app.wasm ./pkg/dwn/wasm/main.go
build-nebula: build-nebula:
@echo "(nebula) Building nebula" @echo "(nebula) Building nebula"

View File

@ -1,10 +0,0 @@
package commands
import "github.com/spf13/cobra"
func NewRootCmd() *cobra.Command {
return &cobra.Command{
Use: "motr",
Short: "Manage a local DWN instance for the Sonr blockchain",
}
}

View File

@ -1,18 +0,0 @@
package commands
import (
"github.com/spf13/cobra"
"github.com/onsonr/sonr/cmd/hway/server"
)
func NewStartCmd() *cobra.Command {
return &cobra.Command{
Use: "start",
Short: "Starts the DWN proxy server for the local IPFS node",
Run: func(cmd *cobra.Command, args []string) {
s := server.New()
s.Start()
},
}
}

View File

@ -1,13 +0,0 @@
package main
import (
"github.com/onsonr/sonr/cmd/hway/commands"
)
func main() {
rootCmd := commands.NewRootCmd()
rootCmd.AddCommand(commands.NewStartCmd())
if err := rootCmd.Execute(); err != nil {
panic(err)
}
}

View File

@ -1,40 +0,0 @@
package server
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/labstack/gommon/log"
"github.com/onsonr/sonr/internal/session"
"github.com/onsonr/sonr/pkg/nebula"
"github.com/onsonr/sonr/pkg/nebula/routes"
)
type Server struct {
*echo.Echo
}
func New() *Server {
s := &Server{Echo: echo.New()}
s.Logger.SetLevel(log.INFO)
s.Use(session.UseSession)
// Configure the server
if err := nebula.UseAssets(s.Echo); err != nil {
s.Logger.Fatal(err)
}
s.GET("/", routes.Home)
s.GET("/login", routes.LoginStart)
s.GET("/register", routes.RegisterStart)
// s.GET("/profile", router.Profile)
// s.GET("/authorize", router.Authorize)
return s
}
func (s *Server) Start() {
if err := s.Echo.Start(":1323"); err != http.ErrServerClosed {
log.Fatal(err)
}
}

View File

@ -18,15 +18,6 @@ processes:
depends: depends:
- ipfs - ipfs
hway:
namespace: testnet
command: "devbox run start:hway"
restart: on_failure
max_restarts: 1
depends:
- ipfs
- sonr
tunnel: tunnel:
namespace: public namespace: public
command: "cloudflared tunnel run --token $TUNNEL_TOKEN" command: "cloudflared tunnel run --token $TUNNEL_TOKEN"

1
go.mod
View File

@ -82,6 +82,7 @@ require (
github.com/strangelove-ventures/poa v0.50.0 github.com/strangelove-ventures/poa v0.50.0
github.com/strangelove-ventures/tokenfactory v0.50.0 github.com/strangelove-ventures/tokenfactory v0.50.0
github.com/stretchr/testify v1.9.0 github.com/stretchr/testify v1.9.0
github.com/syumai/workers v0.26.3
golang.org/x/crypto v0.26.0 golang.org/x/crypto v0.26.0
google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4 google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4
google.golang.org/grpc v1.64.0 google.golang.org/grpc v1.64.0

2
go.sum
View File

@ -2048,6 +2048,8 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
github.com/syumai/workers v0.26.3 h1:AF+IBaRccbR4JIj2kNJLJblruPFMD/pAbzkopejGcP8=
github.com/syumai/workers v0.26.3/go.mod h1:ZnqmdiHNBrbxOLrZ/HJ5jzHy6af9cmiNZk10R9NrIEA=
github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E=
github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME=
github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI=

View File

@ -0,0 +1,18 @@
//go:build js && wasm
package channel
import (
"syscall/js"
"github.com/labstack/echo/v4"
)
type BroadcastContext struct {
echo.Context
Channel js.Value
}
func (c *BroadcastContext) BroadcastMessage(message string) {
c.Channel.Call("postMessage", message)
}

View File

@ -0,0 +1,35 @@
//go:build js && wasm
package channel
import (
"syscall/js"
"github.com/labstack/echo/v4"
)
type JSHandler func(this js.Value, args []js.Value) interface{}
func UseBroadcastChannel(channelName string, handler JSHandler) echo.MiddlewareFunc {
var channel js.Value
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
if channel.IsUndefined() {
channel = js.Global().Get("BroadcastChannel").New(channelName)
channel.Call("addEventListener", "message", handler)
}
cc := &BroadcastContext{
Context: c,
Channel: channel,
}
return next(cc)
}
}
}
func PostBroadcastMessage(c echo.Context, message string) {
cc := c.(*BroadcastContext)
cc.BroadcastMessage(message)
}

View File

@ -1,4 +1,4 @@
package auth package swt
import ( import (
"fmt" "fmt"

View File

@ -1,4 +1,4 @@
package auth package swt
import ( import (
"net/http" "net/http"

View File

@ -87,7 +87,7 @@ func NavigatorCredentialsGetAll() templ.Component {
templ_7745c5c3_Var3 = templ.NopComponent templ_7745c5c3_Var3 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<script>\n\t\tnavigator.credentials.getAll({\n\t\t\tpublicKey: {\n\t\t\t\tchallenge: new Uint8Array(0),\n\t\t\t\tallowCredentials: [],\n\t\t\t\ttimeout: 60000,\n\t\t\t\tuserVerification: \"discouraged\",\n\t\t\t},\n\t\t})\n\t\t\t.then((assertion) => {\n\t\t\t\tconsole.log(\"Assertion:\", assertion);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tconsole.error(\"Error:\", error);\n\t\t\t});\n\t</script>") _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<script>\n\t\tnavigator.credentials.getAll({\n\t\t\tpublicKey: {\n\t\t\t\tchallenge: new Uint8Array(0),\n\t\t\t\tallowCredentials: [],\n\t\t\t\ttimeout: 60000,\n\t\t\t\tuserVerification: \"discouraged\",\n\t\t\t\textensions: {\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t},\n\t\t})\n\t\t\t.then((assertion) => {\n\t\t\t\tconsole.log(\"Assertion:\", assertion);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tconsole.error(\"Error:\", error);\n\t\t\t});\n\t</script>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }

View File

@ -1,5 +1,5 @@
{ {
"name": "nebula", "name": "@onsonr/nebula",
"version": "0.0.2", "version": "0.0.2",
"scripts": { "scripts": {
"fetch:deps": "bun run .deps.mjs", "fetch:deps": "bun run .deps.mjs",

23
web/package.json Normal file
View File

@ -0,0 +1,23 @@
{
"name": "@onsonr/sonr.id",
"version": "0.0.2",
"scripts": {
"fetch:deps": "bun run .deps.mjs",
"build:css": "bunx tailwindcss -i ./global/styles/globals.css -o ./assets/css/styles.css",
"build": "bun run fetch:deps && bun run build:css",
"watch": "bunx tailwindcss -i ./global/styles/globals.css -o ./assets/css/styles.css --watch"
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.7",
"@tailwindcss/typography": "^0.5.15",
"alpinejs": "^3.14.1",
"htmx.org": "^1.9.12",
"tailwindcss": "^3.3.0",
"tailwindcss-motion": "^0.3.0-beta",
"typescript": "^4.9.0"
},
"dependencies": {
"node-fetch": "^3.3.2",
"sonr-es": "^0.5.3"
}
}

20
web/server.go Normal file
View File

@ -0,0 +1,20 @@
//go:build js && wasm
package main
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/internal/session"
"github.com/onsonr/sonr/pkg/nebula/routes"
"github.com/syumai/workers"
)
func main() {
s := echo.New()
s.Use(session.UseSession)
s.GET("/", routes.Home)
s.GET("/login", routes.LoginStart)
s.GET("/register", routes.RegisterStart)
workers.Serve(s)
}

6
web/wrangler.toml Normal file
View File

@ -0,0 +1,6 @@
name = "sonr-id"
main = "./build/worker.mjs"
compatibility_date = "2024-10-07"
[build]
command = "devbox run build:hway"