From df28fcc31fe1558d49b352f815d45cbf4725ce56 Mon Sep 17 00:00:00 2001 From: Tasos Bitsios Date: Fri, 17 Jan 2025 13:10:45 +0100 Subject: [PATCH] Fix: participation key rendering from base64url to base64 --- .../testdata/Test_Snapshot/InfoModal.golden | 28 +++++++++---------- ui/modals/info/info.go | 6 ++-- .../testdata/Test_Snapshot/Visible.golden | 6 ++-- ui/utils/utils.go | 7 +++++ 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/ui/modal/testdata/Test_Snapshot/InfoModal.golden b/ui/modal/testdata/Test_Snapshot/InfoModal.golden index 3e28416a..59f5c983 100644 --- a/ui/modal/testdata/Test_Snapshot/InfoModal.golden +++ b/ui/modal/testdata/Test_Snapshot/InfoModal.golden @@ -31,20 +31,20 @@ - ╭──Key Information────────────╮ - │ │ - │ Account: ABC │ - │ Participation ID: 123 │ - │ │ - │ Vote Key: VEVTVEtFWQ │ - │ Selection Key: VEVTVEtFWQ │ - │ State Proof Key: VEVTVEtFWQ │ - │ │ - │ Vote First Valid: 0 │ - │ Vote Last Valid: 30000 │ - │ Vote Key Dilution: 100 │ - │ │ - ╰──( (d)elete | (o)nline )────╯ + ╭──Key Information──────────────╮ + │ │ + │ Account: ABC │ + │ Participation ID: 123 │ + │ │ + │ Vote Key: VEVTVEtFWQ== │ + │ Selection Key: VEVTVEtFWQ== │ + │ State Proof Key: VEVTVEtFWQ== │ + │ │ + │ Vote First Valid: 0 │ + │ Vote Last Valid: 30000 │ + │ Vote Key Dilution: 100 │ + │ │ + ╰───( (d)elete | (o)nline )─────╯ diff --git a/ui/modals/info/info.go b/ui/modals/info/info.go index fa9b2073..44a95a14 100644 --- a/ui/modals/info/info.go +++ b/ui/modals/info/info.go @@ -92,9 +92,9 @@ func (m ViewModel) View() string { } account := style.Cyan.Render("Account: ") + m.Participation.Address id := style.Cyan.Render("Participation ID: ") + m.Participation.Id - selection := style.Yellow.Render("Selection Key: ") + *utils.UrlEncodeBytesPtrOrNil(m.Participation.Key.SelectionParticipationKey[:]) - vote := style.Yellow.Render("Vote Key: ") + *utils.UrlEncodeBytesPtrOrNil(m.Participation.Key.VoteParticipationKey[:]) - stateProof := style.Yellow.Render("State Proof Key: ") + *utils.UrlEncodeBytesPtrOrNil(*m.Participation.Key.StateProofKey) + selection := style.Yellow.Render("Selection Key: ") + *utils.Base64EncodeBytesPtrOrNil(m.Participation.Key.SelectionParticipationKey[:]) + vote := style.Yellow.Render("Vote Key: ") + *utils.Base64EncodeBytesPtrOrNil(m.Participation.Key.VoteParticipationKey[:]) + stateProof := style.Yellow.Render("State Proof Key: ") + *utils.Base64EncodeBytesPtrOrNil(*m.Participation.Key.StateProofKey) voteFirstValid := style.Purple("Vote First Valid: ") + utils.IntToStr(m.Participation.Key.VoteFirstValid) voteLastValid := style.Purple("Vote Last Valid: ") + utils.IntToStr(m.Participation.Key.VoteLastValid) voteKeyDilution := style.Purple("Vote Key Dilution: ") + utils.IntToStr(m.Participation.Key.VoteKeyDilution) diff --git a/ui/modals/info/testdata/Test_Snapshot/Visible.golden b/ui/modals/info/testdata/Test_Snapshot/Visible.golden index e8bc0e8d..911e4260 100644 --- a/ui/modals/info/testdata/Test_Snapshot/Visible.golden +++ b/ui/modals/info/testdata/Test_Snapshot/Visible.golden @@ -2,9 +2,9 @@ Account: ABC Participation ID: 123 -Vote Key: VEVTVEtFWQ -Selection Key: VEVTVEtFWQ -State Proof Key: VEVTVEtFWQ +Vote Key: VEVTVEtFWQ== +Selection Key: VEVTVEtFWQ== +State Proof Key: VEVTVEtFWQ== Vote First Valid: 0 Vote Last Valid: 30000 diff --git a/ui/utils/utils.go b/ui/utils/utils.go index af9d89fa..ac569ed9 100644 --- a/ui/utils/utils.go +++ b/ui/utils/utils.go @@ -7,6 +7,13 @@ import ( func toPtr[T any](constVar T) *T { return &constVar } +func Base64EncodeBytesPtrOrNil(b []byte) *string { + if b == nil || len(b) == 0 || isZeros(b) { + return nil + } + return toPtr(base64.StdEncoding.EncodeToString(b)) +} + func UrlEncodeBytesPtrOrNil(b []byte) *string { if b == nil || len(b) == 0 || isZeros(b) { return nil