Skip to content

Commit 92d9303

Browse files
committed
refactor: replace address truncation with name resolution for user visibility
1 parent 0175a2d commit 92d9303

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

packages/r/karma1337/geo-resto/renderer.gno

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"time"
77

88
"chain/runtime"
9+
10+
"gno.land/r/sys/users"
911
)
1012

1113
// Renderer handles the display and formatting of geographic data for web interface
@@ -69,7 +71,7 @@ func (r *Renderer) RenderMainPage() string {
6971
for _, visit := range recentVisits {
7072
location := locationManager.GetLocation(visit.LocationID)
7173
if location != nil {
72-
sb.WriteString("- " + r.truncateAddress(visit.UserAddress) + " visited **" + location.Name + "** " + r.timeAgo(visit.Timestamp) + "\n")
74+
sb.WriteString("- " + r.resolveName(visit.UserAddress) + " visited **" + location.Name + "** " + r.timeAgo(visit.Timestamp) + "\n")
7375
}
7476
}
7577
}
@@ -125,7 +127,7 @@ func (r *Renderer) RenderLocation(locationID string) string {
125127
sb.WriteString("**Description**: " + location.Description + "\n")
126128
sb.WriteString("**Category**: " + location.Category + "\n")
127129
sb.WriteString("**Coordinates**: " + strconv.FormatFloat(location.Latitude, 'f', 6, 64) + ", " + strconv.FormatFloat(location.Longitude, 'f', 6, 64) + "\n")
128-
sb.WriteString("**Created by**: " + r.truncateAddress(location.Creator.String()) + "\n")
130+
sb.WriteString("**Created by**: " + r.resolveName(location.Creator.String()) + "\n")
129131
sb.WriteString("**Created**: " + r.formatTimestamp(location.CreatedAt) + "\n")
130132
sb.WriteString("**Total Visits**: " + strconv.Itoa(location.VisitCount) + "\n")
131133
if location.Verified {
@@ -160,7 +162,7 @@ func (r *Renderer) RenderLocation(locationID string) string {
160162

161163
for i := len(visits) - limit; i < len(visits); i++ {
162164
visit := visits[i]
163-
sb.WriteString("- " + r.truncateAddress(visit.UserAddress) + " - " + r.formatTimestamp(visit.Timestamp))
165+
sb.WriteString("- " + r.resolveName(visit.UserAddress) + " - " + r.formatTimestamp(visit.Timestamp))
164166
if visit.Verified {
165167
sb.WriteString(" ✅")
166168
}
@@ -184,7 +186,7 @@ func (r *Renderer) RenderLocation(locationID string) string {
184186
func (r *Renderer) RenderUserVisits(userAddress string) string {
185187
var sb strings.Builder
186188

187-
sb.WriteString("# 👤 User Visits: " + r.truncateAddress(userAddress) + "\n\n")
189+
sb.WriteString("# 👤 User Visits: " + r.resolveName(userAddress) + "\n\n")
188190

189191
visits := visitManager.GetUserVisits(userAddress)
190192
if len(visits) == 0 {
@@ -230,7 +232,7 @@ func (r *Renderer) RenderRecentVisits() string {
230232
for _, visit := range visits {
231233
location := locationManager.GetLocation(visit.LocationID)
232234
if location != nil {
233-
sb.WriteString("- **" + location.Name + "** visited by " + r.truncateAddress(visit.UserAddress) + " " + r.timeAgo(visit.Timestamp))
235+
sb.WriteString("- **" + location.Name + "** visited by " + r.resolveName(visit.UserAddress) + " " + r.timeAgo(visit.Timestamp))
234236
if visit.Verified {
235237
sb.WriteString(" ✅")
236238
}
@@ -284,7 +286,7 @@ func (r *Renderer) RenderEvent(eventID string) string {
284286
}
285287
sb.WriteString("\n")
286288

287-
sb.WriteString("**Created by**: " + r.truncateAddress(event.Creator.String()) + "\n")
289+
sb.WriteString("**Created by**: " + r.resolveName(event.Creator.String()) + "\n")
288290
sb.WriteString("**Start Time**: " + r.formatTimestamp(event.StartTime) + "\n")
289291
sb.WriteString("**End Time**: " + r.formatTimestamp(event.EndTime) + "\n")
290292
sb.WriteString("**Participants**: " + strconv.Itoa(len(event.Participants)))
@@ -342,7 +344,7 @@ func (r *Renderer) RenderEvent(eventID string) string {
342344
if len(event.VerifiedAttendees) > 0 {
343345
sb.WriteString("### ✅ Verified Attendees\n\n")
344346
for _, attendee := range event.VerifiedAttendees {
345-
sb.WriteString("- " + r.truncateAddress(attendee) + "\n")
347+
sb.WriteString("- " + r.resolveName(attendee) + "\n")
346348
}
347349
sb.WriteString("\n")
348350
}
@@ -353,7 +355,7 @@ func (r *Renderer) RenderEvent(eventID string) string {
353355
if len(event.Participants) > 0 {
354356
sb.WriteString("## 👥 Participants\n\n")
355357
for i, participant := range event.Participants {
356-
sb.WriteString(strconv.Itoa(i+1) + ". " + r.truncateAddress(participant) + "\n")
358+
sb.WriteString(strconv.Itoa(i+1) + ". " + r.resolveName(participant) + "\n")
357359
}
358360
}
359361

@@ -431,6 +433,20 @@ func (r *Renderer) truncateAddress(address string) string {
431433
return address[:6] + "..." + address[len(address)-6:]
432434
}
433435

436+
func (r *Renderer) resolveName(addr string) string {
437+
// Try to resolve a human-readable username for the given address.
438+
data := users.ResolveAddress(address(addr))
439+
if data != nil {
440+
name := data.Name()
441+
if name != "" {
442+
return name
443+
}
444+
}
445+
// If no username is registered, return the full address so users can
446+
// identify or copy it for registration. Previously we truncated here.
447+
return addr
448+
}
449+
434450
func (r *Renderer) formatTimestamp(timestamp int64) string {
435451
t := time.Unix(timestamp, 0)
436452
return t.Format("2006-01-02 15:04:05")

0 commit comments

Comments
 (0)