Skip to content

Commit

Permalink
wwallet: truncate long strings
Browse files Browse the repository at this point in the history
  • Loading branch information
dessaya committed Oct 2, 2020
1 parent e615fbe commit 85eba8b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
9 changes: 9 additions & 0 deletions packages/dashboard/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import (
"time"
)

const maxLength = 150

func Trim(s string) string {
if len(s) > maxLength {
return s[0:maxLength] + "..."
}
return s
}

func FormatTimestamp(ts interface{}) string {
t, ok := ts.(time.Time)
if !ok {
Expand Down
3 changes: 2 additions & 1 deletion tools/wwallet/dashboard/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type NavPage struct {
func MakeTemplate(parts ...string) *template.Template {
t := template.New("").Funcs(template.FuncMap{
"formatTimestamp": dashboard.FormatTimestamp,
"trim": dashboard.Trim,
"exploreAddressUrl": dashboard.ExploreAddressUrl(
dashboard.ExploreAddressUrlFromGoshimmerUri(config.GoshimmerApi()),
),
Expand Down Expand Up @@ -90,7 +91,7 @@ const TplSCInfo = `
<summary>Smart contract details</summary>
<p>SC address: {{template "address" .Status.SCAddress}}</p>
<p>Program hash: <code>{{.Status.ProgramHash}}</code></p>
<p>Description of the instance: <code>{{.Status.Description}}</code></p>
<p>Description of the instance: <code>{{trim .Status.Description}}</code></p>
<p>Owner address: {{template "address" .Status.OwnerAddress}}</p>
<p>Minimum node reward (fee): <code>{{.Status.MinimumReward}}</code></p>
<p>Color: <code>{{.Config.BootupData.Color}}</code></p>
Expand Down
2 changes: 1 addition & 1 deletion tools/wwallet/sc/dwf/dwfdashboard/dwfdashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const tplDwf = `
<h4>Log (latest first)</h4>
{{range $i, $di := .Status.LastRecordsDesc}}
<details>
<summary>{{$di.Seq}}: {{$di.Feedback}}</summary>
<summary>{{$di.Seq}}: {{trim $di.Feedback}}</summary>
<p>Sender: {{template "address" $di.Sender}}</p>
<p>Amount: <code>{{$di.Amount}} IOTAs</code></p>
<p>When: <code>{{formatTimestamp $di.When}}</code></p>
Expand Down
2 changes: 1 addition & 1 deletion tools/wwallet/sc/fa/fadashboard/fadashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const tplFairAuction = `
<div>
{{range $color, $auction := .Status.Auctions}}
<details>
<summary>{{$auction.Description}}</summary>
<summary>{{trim $auction.Description}}</summary>
<p>For sale: <code>{{$auction.NumTokens}}</code> tokens of color <a href="/tr/{{$color}}"><code>{{$color}}</code></a></p>
<p>Owner: {{template "address" $auction.AuctionOwner}}</p>
<p>Started at: <code>{{formatTimestamp $auction.WhenStarted}}</code></p>
Expand Down
4 changes: 2 additions & 2 deletions tools/wwallet/sc/tr/trdashboard/trdashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const tplTokenRegistry = `
<div>
{{range $color, $tm := .Status.Registry}}
<details>
<summary>{{$tm.Description}}</summary>
<summary>{{trim $tm.Description}}</summary>
<p>Color: <code>{{$color}}</code></p>
{{template "tmdetails" $tm}}
</details>
Expand All @@ -114,7 +114,7 @@ const tplTokenRegistry = `
{{if .Color}}
{{if .QueryResult}}
<h3>{{.QueryResult.Description}}</h3>
<h3>{{trim .QueryResult.Description}}</h3>
<p>Color: <code>{{.Color}}</code></p>
{{template "tmdetails" .QueryResult}}
{{else}}
Expand Down

0 comments on commit 85eba8b

Please sign in to comment.