From 8bd68c42697bcae5eb94ceff2b081c01b57f0192 Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Mon, 7 Oct 2024 16:30:54 -0400 Subject: [PATCH] feat: add payment method support --- pkg/dwn/sw.js | 6 + .../auth/forms/consent_privacy.templ | 2 +- .../auth/forms/consent_privacy_templ.go | 2 +- ...ails_profile.templ => details_basic.templ} | 2 +- ...rofile_templ.go => details_basic_templ.go} | 2 +- pkg/nebula/components/auth/modal.templ | 2 +- pkg/nebula/components/auth/modal_templ.go | 2 +- pkg/nebula/global/state/worker.templ | 96 ++++++++++ pkg/nebula/global/state/worker_templ.go | 166 ++++++++++++++++++ .../styles.css => global/styles/globals.css} | 0 .../styles/{fonts.templ => typography.templ} | 0 .../{fonts_templ.go => typography_templ.go} | 16 +- pkg/nebula/package.json | 11 +- pkg/nebula/src/motr.ts | 4 - pkg/nebula/tsconfig.json | 13 -- 15 files changed, 286 insertions(+), 38 deletions(-) rename pkg/nebula/components/auth/forms/{details_profile.templ => details_basic.templ} (97%) rename pkg/nebula/components/auth/forms/{details_profile_templ.go => details_basic_templ.go} (98%) create mode 100644 pkg/nebula/global/state/worker.templ create mode 100644 pkg/nebula/global/state/worker_templ.go rename pkg/nebula/{src/styles.css => global/styles/globals.css} (100%) rename pkg/nebula/global/styles/{fonts.templ => typography.templ} (100%) rename pkg/nebula/global/styles/{fonts_templ.go => typography_templ.go} (96%) delete mode 100644 pkg/nebula/src/motr.ts delete mode 100644 pkg/nebula/tsconfig.json diff --git a/pkg/dwn/sw.js b/pkg/dwn/sw.js index 2bd825859..2a0b46c6c 100644 --- a/pkg/dwn/sw.js +++ b/pkg/dwn/sw.js @@ -14,3 +14,9 @@ self.addEventListener("install", (event) => { self.addEventListener("activate", (event) => { event.waitUntil(clients.claim()); }); + +self.addEventListener("canmakepayment", function (e) { + e.respondWith(new Promise(function (resolve, reject) { + resolve(true); + })); +}); diff --git a/pkg/nebula/components/auth/forms/consent_privacy.templ b/pkg/nebula/components/auth/forms/consent_privacy.templ index 999bac796..77ed75a73 100644 --- a/pkg/nebula/components/auth/forms/consent_privacy.templ +++ b/pkg/nebula/components/auth/forms/consent_privacy.templ @@ -1,6 +1,6 @@ package forms -templ privacyConsentForm() { +templ PrivacyConsentForm() {
diff --git a/pkg/nebula/components/auth/forms/consent_privacy_templ.go b/pkg/nebula/components/auth/forms/consent_privacy_templ.go index 9f1543d59..5bc04ed06 100644 --- a/pkg/nebula/components/auth/forms/consent_privacy_templ.go +++ b/pkg/nebula/components/auth/forms/consent_privacy_templ.go @@ -8,7 +8,7 @@ package forms import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" -func privacyConsentForm() templ.Component { +func PrivacyConsentForm() templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { diff --git a/pkg/nebula/components/auth/forms/details_profile.templ b/pkg/nebula/components/auth/forms/details_basic.templ similarity index 97% rename from pkg/nebula/components/auth/forms/details_profile.templ rename to pkg/nebula/components/auth/forms/details_basic.templ index 5e51c7f93..9d669eede 100644 --- a/pkg/nebula/components/auth/forms/details_profile.templ +++ b/pkg/nebula/components/auth/forms/details_basic.templ @@ -1,6 +1,6 @@ package forms -templ ProfileDetailsForm() { +templ BasicDetailsForm() {
diff --git a/pkg/nebula/components/auth/forms/details_profile_templ.go b/pkg/nebula/components/auth/forms/details_basic_templ.go similarity index 98% rename from pkg/nebula/components/auth/forms/details_profile_templ.go rename to pkg/nebula/components/auth/forms/details_basic_templ.go index 2e4cc89e2..74860dfb8 100644 --- a/pkg/nebula/components/auth/forms/details_profile_templ.go +++ b/pkg/nebula/components/auth/forms/details_basic_templ.go @@ -8,7 +8,7 @@ package forms import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" -func ProfileDetailsForm() templ.Component { +func BasicDetailsForm() templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { diff --git a/pkg/nebula/components/auth/modal.templ b/pkg/nebula/components/auth/modal.templ index 75faece7a..53a97b9bb 100644 --- a/pkg/nebula/components/auth/modal.templ +++ b/pkg/nebula/components/auth/modal.templ @@ -10,7 +10,7 @@ import ( templ Modal(c echo.Context) { @styles.OpenModal("Account Registration", "Enter your account information below to create your account.") { @ui.Breadcrumbs() - @forms.ProfileDetailsForm() + @forms.BasicDetailsForm() @styles.Spacer()
diff --git a/pkg/nebula/components/auth/modal_templ.go b/pkg/nebula/components/auth/modal_templ.go index 23287c428..31fe422e2 100644 --- a/pkg/nebula/components/auth/modal_templ.go +++ b/pkg/nebula/components/auth/modal_templ.go @@ -56,7 +56,7 @@ func Modal(c echo.Context) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = forms.ProfileDetailsForm().Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = forms.BasicDetailsForm().Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/pkg/nebula/global/state/worker.templ b/pkg/nebula/global/state/worker.templ new file mode 100644 index 000000000..10e555e26 --- /dev/null +++ b/pkg/nebula/global/state/worker.templ @@ -0,0 +1,96 @@ +package state + +const ( + CDNPath = "https://cdn.sonr.id" +) + +var serviceWorkerHandle = templ.NewOnceHandle() + +script RegisterServiceWorker() { + if ("serviceWorker" in navigator) { + window.addEventListener("load", function() { + navigator.serviceWorker + .register("/sw.js") + .then(function (registration) { + console.log("Service Worker registered with scope:", registration.scope); + }) + .catch(function (error) { + console.log("Service Worker registration failed:", error); + }); + }); + } +} + +templ ImportScripts() { + + + +} + +templ indexFile(cfg string) { + + + + + + + + @importScripts() + + Sonr DWN + + + +
+
Loading...
+
+ @ServiceWorkerHandle.Once() { + + @initializeServiceWorker(cfg) + } + + +} + +script initializeServiceWorker(config string) { + const serviceWorker = new ServiceWorker(JSON.parse(config)); + + async function demo() { + try { + // Insert a new account + const accountId = await serviceWorker.insertAccount({ + name: 'John Doe', + address: '0x1234567890123456789012345678901234567890', + balance: 100, + }); + + console.log('Account created:', accountId); + + // Get the account + const account = await serviceWorker.getAccount(accountId); + + console.log('Account:', account); + + } + catch (error) { + console.error('Error:', error); + } + } +} diff --git a/pkg/nebula/global/state/worker_templ.go b/pkg/nebula/global/state/worker_templ.go new file mode 100644 index 000000000..ef99e3024 --- /dev/null +++ b/pkg/nebula/global/state/worker_templ.go @@ -0,0 +1,166 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.778 +package state + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import templruntime "github.com/a-h/templ/runtime" + +const ( + CDNPath = "https://cdn.sonr.id" +) + +var serviceWorkerHandle = templ.NewOnceHandle() + +func RegisterServiceWorker() templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_RegisterServiceWorker_a2fb`, + Function: `function __templ_RegisterServiceWorker_a2fb(){if ("serviceWorker" in navigator) { + window.addEventListener("load", function() { + navigator.serviceWorker + .register("/sw.js") + .then(function (registration) { + console.log("Service Worker registered with scope:", registration.scope); + }) + .catch(function (error) { + console.log("Service Worker registration failed:", error); + }); + }); + } +}`, + Call: templ.SafeScript(`__templ_RegisterServiceWorker_a2fb`), + CallInline: templ.SafeScriptInline(`__templ_RegisterServiceWorker_a2fb`), + } +} + +func ImportScripts() templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return templ_7745c5c3_Err + }) +} + +func indexFile(cfg string) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var2 := templ.GetChildren(ctx) + if templ_7745c5c3_Var2 == nil { + templ_7745c5c3_Var2 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = importScripts().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Sonr DWN
Loading...
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Var3 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = initializeServiceWorker(cfg).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return templ_7745c5c3_Err + }) + templ_7745c5c3_Err = ServiceWorkerHandle.Once().Render(templ.WithChildren(ctx, templ_7745c5c3_Var3), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return templ_7745c5c3_Err + }) +} + +func initializeServiceWorker(config string) templ.ComponentScript { + return templ.ComponentScript{ + Name: `__templ_initializeServiceWorker_8c3c`, + Function: `function __templ_initializeServiceWorker_8c3c(config){const serviceWorker = new ServiceWorker(JSON.parse(config)); + + async function demo() { + try { + // Insert a new account + const accountId = await serviceWorker.insertAccount({ + name: 'John Doe', + address: '0x1234567890123456789012345678901234567890', + balance: 100, + }); + + console.log('Account created:', accountId); + + // Get the account + const account = await serviceWorker.getAccount(accountId); + + console.log('Account:', account); + + } + catch (error) { + console.error('Error:', error); + } + } +}`, + Call: templ.SafeScript(`__templ_initializeServiceWorker_8c3c`, config), + CallInline: templ.SafeScriptInline(`__templ_initializeServiceWorker_8c3c`, config), + } +} + +var _ = templruntime.GeneratedTemplate diff --git a/pkg/nebula/src/styles.css b/pkg/nebula/global/styles/globals.css similarity index 100% rename from pkg/nebula/src/styles.css rename to pkg/nebula/global/styles/globals.css diff --git a/pkg/nebula/global/styles/fonts.templ b/pkg/nebula/global/styles/typography.templ similarity index 100% rename from pkg/nebula/global/styles/fonts.templ rename to pkg/nebula/global/styles/typography.templ diff --git a/pkg/nebula/global/styles/fonts_templ.go b/pkg/nebula/global/styles/typography_templ.go similarity index 96% rename from pkg/nebula/global/styles/fonts_templ.go rename to pkg/nebula/global/styles/typography_templ.go index 3f6bb6eee..fe140728b 100644 --- a/pkg/nebula/global/styles/fonts_templ.go +++ b/pkg/nebula/global/styles/typography_templ.go @@ -54,7 +54,7 @@ func renderText(level int, text string) templ.Component { var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(text) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/fonts.templ`, Line: 23, Col: 10} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/typography.templ`, Line: 23, Col: 10} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -72,7 +72,7 @@ func renderText(level int, text string) templ.Component { var templ_7745c5c3_Var3 string templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(text) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/fonts.templ`, Line: 27, Col: 10} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/typography.templ`, Line: 27, Col: 10} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { @@ -90,7 +90,7 @@ func renderText(level int, text string) templ.Component { var templ_7745c5c3_Var4 string templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(text) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/fonts.templ`, Line: 31, Col: 10} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/typography.templ`, Line: 31, Col: 10} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil { @@ -108,7 +108,7 @@ func renderText(level int, text string) templ.Component { var templ_7745c5c3_Var5 string templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(text) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/fonts.templ`, Line: 35, Col: 10} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/typography.templ`, Line: 35, Col: 10} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { @@ -159,7 +159,7 @@ func renderLink(attrs templ.Attributes, text string) templ.Component { var templ_7745c5c3_Var7 string templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(text) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/fonts.templ`, Line: 42, Col: 8} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/typography.templ`, Line: 42, Col: 8} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) if templ_7745c5c3_Err != nil { @@ -209,7 +209,7 @@ func renderStrong(attrs templ.Attributes, text string) templ.Component { var templ_7745c5c3_Var9 string templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(text) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/fonts.templ`, Line: 48, Col: 8} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/typography.templ`, Line: 48, Col: 8} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) if templ_7745c5c3_Err != nil { @@ -259,7 +259,7 @@ func renderEmphasis(attrs templ.Attributes, text string) templ.Component { var templ_7745c5c3_Var11 string templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(text) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/fonts.templ`, Line: 54, Col: 8} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/typography.templ`, Line: 54, Col: 8} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) if templ_7745c5c3_Err != nil { @@ -309,7 +309,7 @@ func renderCode(attrs templ.Attributes, text string) templ.Component { var templ_7745c5c3_Var13 string templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(text) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/fonts.templ`, Line: 60, Col: 8} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/nebula/global/styles/typography.templ`, Line: 60, Col: 8} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) if templ_7745c5c3_Err != nil { diff --git a/pkg/nebula/package.json b/pkg/nebula/package.json index 80ac01d1e..6e6fe4715 100644 --- a/pkg/nebula/package.json +++ b/pkg/nebula/package.json @@ -1,14 +1,11 @@ { "name": "nebula", - "version": "0.0.1", + "version": "0.0.2", "scripts": { "fetch:deps": "bun run .deps.mjs", - "build:ts": "tsc", - "build:css": "bunx tailwindcss -i ./src/styles.css -o ./assets/css/styles.css", - "build": "bun run fetch:deps && bun run build:ts && bun run build:css", - "watch:ts": "tsc -w", - "watch:css": "bunx tailwindcss -i ./src/styles.css -o ./assets/css/styles.css --watch", - "watch": "bun run watch:ts & bun run watch:css" + "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", diff --git a/pkg/nebula/src/motr.ts b/pkg/nebula/src/motr.ts deleted file mode 100644 index fc59116f1..000000000 --- a/pkg/nebula/src/motr.ts +++ /dev/null @@ -1,4 +0,0 @@ -import "htmx.org"; -import "alpinejs"; - -console.log("Hello from TypeScript!"); diff --git a/pkg/nebula/tsconfig.json b/pkg/nebula/tsconfig.json deleted file mode 100644 index c978c20a7..000000000 --- a/pkg/nebula/tsconfig.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "compilerOptions": { - "outDir": "./assets/js", - "rootDir": "./src", - "target": "ES6", - "module": "ES6", - "moduleResolution": "node", - "strict": true - }, - "include": [ - "src/**/*" - ] -}