From bbb093b17194e498ca525017efdf8c75fddcada0 Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Mon, 9 Dec 2024 15:21:02 -0500 Subject: [PATCH] refactor: remove profile card component --- pkg/blocks/cards/profile.templ | 38 ------ pkg/blocks/cards/profile_templ.go | 108 ----------------- pkg/blocks/forms/register_passkey.templ | 5 - pkg/blocks/forms/register_passkey_templ.go | 132 ++++++++++++++++----- pkg/blocks/layout/layout.templ | 11 ++ pkg/blocks/layout/layout_templ.go | 2 +- 6 files changed, 116 insertions(+), 180 deletions(-) delete mode 100644 pkg/blocks/cards/profile.templ delete mode 100644 pkg/blocks/cards/profile_templ.go diff --git a/pkg/blocks/cards/profile.templ b/pkg/blocks/cards/profile.templ deleted file mode 100644 index 904246483..000000000 --- a/pkg/blocks/cards/profile.templ +++ /dev/null @@ -1,38 +0,0 @@ -package cards - -// Helper function to shorten address -func shortenAddress(address string) string { - if len(address) <= 20 { - return address - } - return address[:16] + "..." + address[len(address)-4:] -} - -templ SonrProfile(addr string, name string, handle string, creationBlock string) { -
-
-
-
-

sonr-testnet-1

-

{ handle }

-
-
- -
-
-
- { shortenAddress(addr) } -
-
-
-

Block Created

-

#{ creationBlock }

-
-
-

Issued to

-

{ name }

-
-
-
-
-} diff --git a/pkg/blocks/cards/profile_templ.go b/pkg/blocks/cards/profile_templ.go deleted file mode 100644 index bfbf9231b..000000000 --- a/pkg/blocks/cards/profile_templ.go +++ /dev/null @@ -1,108 +0,0 @@ -// Code generated by templ - DO NOT EDIT. - -// templ: version: v0.2.793 -package cards - -//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" - -type SonrProfileData struct { - Address string - Handle string - Name string - ChainID string - CreationBlock string -} - -// Helper function to shorten address -func shortenAddress(address string) string { - if len(address) <= 20 { - return address - } - return address[:16] + "..." + address[len(address)-4:] -} - -func SonrProfile(addr string, name string, handle string, creationBlock 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_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("

sonr-testnet-1

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var2 string - templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(handle) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/blocks/cards/profile.templ`, Line: 25, Col: 43} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) - 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 - } - var templ_7745c5c3_Var3 string - templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(shortenAddress(addr)) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/blocks/cards/profile.templ`, Line: 32, Col: 58} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Block Created

#") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var4 string - templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(creationBlock) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/blocks/cards/profile.templ`, Line: 37, Col: 55} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Issued to

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var5 string - templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(name) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/blocks/cards/profile.templ`, Line: 41, Col: 32} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) - 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 - }) -} - -var _ = templruntime.GeneratedTemplate diff --git a/pkg/blocks/forms/register_passkey.templ b/pkg/blocks/forms/register_passkey.templ index f7f0f873a..7681e8ad2 100644 --- a/pkg/blocks/forms/register_passkey.templ +++ b/pkg/blocks/forms/register_passkey.templ @@ -43,11 +43,6 @@ templ passkeyDropzone(addr string, userHandle string, challenge string) { } -script base64URLEncode(buffer) { - const base64 = btoa(String.fromCharCode(...new Uint8Array(buffer))); - return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''); -} - script createPasskey(userId string, userHandle string, challenge string) { const publicKey = { challenge: Uint8Array.from(challenge, (c) => c.charCodeAt(0)), diff --git a/pkg/blocks/forms/register_passkey_templ.go b/pkg/blocks/forms/register_passkey_templ.go index 73c1b355d..9e1b924f2 100644 --- a/pkg/blocks/forms/register_passkey_templ.go +++ b/pkg/blocks/forms/register_passkey_templ.go @@ -8,8 +8,6 @@ package forms import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" -import "github.com/onsonr/sonr/pkg/blocks/cards" - type RegisterPasskeyData struct { Address string Handle string @@ -55,17 +53,17 @@ func RegisterPasskey(action, method string, data RegisterPasskeyData) templ.Comp var templ_7745c5c3_Var3 string templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(method) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/blocks/forms/register_passkey.templ`, Line: 14, Col: 55} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/blocks/forms/register_passkey.templ`, Line: 12, Col: 55} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" id=\"passkey-form\">
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = cards.SonrProfile(data.Address, data.Name, data.Handle, data.CreationBlock).Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = sonrProfile(data.Address, data.Name, data.Handle, data.CreationBlock).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -106,15 +104,11 @@ func passkeyDropzone(addr string, userHandle string, challenge string) templ.Com templ_7745c5c3_Var4 = 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 = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, createPasskey(addr, userHandle, challenge)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Link a passkey to your vault
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"> Register Passkey") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -133,8 +127,8 @@ func passkeyDropzone(addr string, userHandle string, challenge string) templ.Com func createPasskey(userId string, userHandle string, challenge string) templ.ComponentScript { return templ.ComponentScript{ - Name: `__templ_createPasskey_6e79`, - Function: `function __templ_createPasskey_6e79(userId, userHandle, challenge){const publicKey = { + Name: `__templ_createPasskey_d562`, + Function: `function __templ_createPasskey_d562(userId, userHandle, challenge){const publicKey = { challenge: Uint8Array.from(challenge, (c) => c.charCodeAt(0)), rp: { name: "Sonr.ID", @@ -170,26 +164,108 @@ func createPasskey(userId string, userHandle string, challenge string) templ.Com navigator.credentials .create({ publicKey }) .then((newCredentialInfo) => { - // Convert credential to base64 string - const credentialJSON = JSON.stringify({ - id: newCredentialInfo.id, - rawId: Array.from(new Uint8Array(newCredentialInfo.rawId)), - response: { - attestationObject: Array.from(new Uint8Array(newCredentialInfo.response.attestationObject)), - clientDataJSON: Array.from(new Uint8Array(newCredentialInfo.response.clientDataJSON)) - }, - type: newCredentialInfo.type - }); + const credentialJSON = JSON.stringify(newCredentialInfo); document.getElementById('credential-data').value = btoa(credentialJSON); - }) + document.getElementById('passkey-form').submit(); + ) .catch((err) => { - console.error(err); - // No acceptable authenticator or user refused consent. Handle appropriately. + console.error(err); + alert('Failed to create passkey. Please try again.'); }); + } }`, - Call: templ.SafeScript(`__templ_createPasskey_6e79`, userId, userHandle, challenge), - CallInline: templ.SafeScriptInline(`__templ_createPasskey_6e79`, userId, userHandle, challenge), + Call: templ.SafeScript(`__templ_createPasskey_d562`, userId, userHandle, challenge), + CallInline: templ.SafeScriptInline(`__templ_createPasskey_d562`, userId, userHandle, challenge), } } +func sonrProfile(addr string, name string, handle string, creationBlock 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_Var6 := templ.GetChildren(ctx) + if templ_7745c5c3_Var6 == nil { + templ_7745c5c3_Var6 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

sonr-testnet-1

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var7 string + templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(handle) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/blocks/forms/register_passkey.templ`, Line: 100, Col: 43} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) + 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 + } + var templ_7745c5c3_Var8 string + templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(shortenAddress(addr)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/blocks/forms/register_passkey.templ`, Line: 107, Col: 58} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Block Created

#") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var9 string + templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(creationBlock) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/blocks/forms/register_passkey.templ`, Line: 112, Col: 55} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Issued to

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var10 string + templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(name) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/blocks/forms/register_passkey.templ`, Line: 116, Col: 32} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) + 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 + }) +} + +// Helper function to shorten address +func shortenAddress(address string) string { + if len(address) <= 20 { + return address + } + return address[:16] + "..." + address[len(address)-4:] +} + var _ = templruntime.GeneratedTemplate diff --git a/pkg/blocks/layout/layout.templ b/pkg/blocks/layout/layout.templ index 7b8977c82..f9b93f650 100644 --- a/pkg/blocks/layout/layout.templ +++ b/pkg/blocks/layout/layout.templ @@ -57,6 +57,17 @@ templ Head(title string, nebulaVersion string) { } templ Body(align Alignment, screenWidth ScreenWidth) { +
{ children... } diff --git a/pkg/blocks/layout/layout_templ.go b/pkg/blocks/layout/layout_templ.go index 64fe26d6d..62c53434b 100644 --- a/pkg/blocks/layout/layout_templ.go +++ b/pkg/blocks/layout/layout_templ.go @@ -176,7 +176,7 @@ func Body(align Alignment, screenWidth ScreenWidth) templ.Component { templ_7745c5c3_Var4 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }