Skip to content

Commit

Permalink
Merge pull request #38 from blinklabs-io/feat/swap-icons
Browse files Browse the repository at this point in the history
feat: swap icons
  • Loading branch information
wolf31o2 authored Dec 14, 2023
2 parents dca2ce8 + f8ca7b8 commit b856d81
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ module github.com/blinklabs-io/txtop
go 1.20

require (
github.com/blinklabs-io/cardano-models v0.2.0
github.com/blinklabs-io/gouroboros v0.67.1
github.com/fxamacker/cbor/v2 v2.5.0
github.com/gdamore/tcell/v2 v2.7.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/rivo/tview v0.0.0-20230928053139-9bc1d28d88a9
)

require (
github.com/fxamacker/cbor/v2 v2.5.0 // indirect
github.com/gdamore/encoding v1.0.0 // indirect
github.com/jinzhu/copier v0.4.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/blinklabs-io/cardano-models v0.2.0 h1:fQ2vkvMLFgQodtFpYE73i+6+eNN5vaIB3GBIys8FsyI=
github.com/blinklabs-io/cardano-models v0.2.0/go.mod h1:iH8IqSca4WzFQIAT3Ssd3TviILfoCgaJQ8mc3JrIvwE=
github.com/blinklabs-io/gouroboros v0.67.1 h1:SyzxCIEa2rph3KQr1D+PgqsPNFORN/OdwNtrL0h42g8=
github.com/blinklabs-io/gouroboros v0.67.1/go.mod h1:Q154NJPs7gB93Tggt8ts9RGIlW2kkknr6M90Q3jh0s4=
github.com/fxamacker/cbor/v2 v2.5.0 h1:oHsG0V/Q6E/wqTS2O1Cozzsy69nqCiguo5Q1a1ADivE=
Expand Down
42 changes: 40 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
"strings"
"time"

"github.com/blinklabs-io/cardano-models"
ouroboros "github.com/blinklabs-io/gouroboros"
"github.com/blinklabs-io/gouroboros/ledger"
"github.com/fxamacker/cbor/v2"
"github.com/gdamore/tcell/v2"
"github.com/kelseyhightower/envconfig"
"github.com/rivo/tview"
Expand Down Expand Up @@ -191,7 +193,9 @@ func GetTransactions(oConn *ouroboros.Connection) string {
}
var sb strings.Builder
// sb.WriteString(" [white]Transactions:\n")
sb.WriteString(fmt.Sprintf(" [white]%-20s %s\n", "Size:", "TxHash:"))
sb.WriteString(
fmt.Sprintf(" [white]%-10s %-10s %s\n", "Size:", "Icon:", "TxHash:"),
)
for {
txRawBytes, err := oConn.LocalTxMonitor().Client.NextTx()
if err != nil {
Expand All @@ -212,8 +216,42 @@ func GetTransactions(oConn *ouroboros.Connection) string {
sb.WriteString(fmt.Sprintf(" [red]ERROR: Tx: %s\n", err))
return fmt.Sprint(sb.String())
}
// Check if Tx has metadata and compare against our list
var icon string
if tx.Metadata() != nil {
mdCbor := tx.Metadata().Cbor()
var msgMetadata models.Cip20Metadata
_ = cbor.Unmarshal(mdCbor, &msgMetadata)
if msgMetadata.Num674.Msg != nil {
// Only check first line
switch msgMetadata.Num674.Msg[0] {
case "Dexhunter Trade":
icon = "🐉"
case "Minswap: Deposit Order",
"Minswap: MasterChef",
"Minswap: Order Executed",
"Minswap: Swap Exact In Order",
"Minswap: V2 Harvest reward",
"Minswap: V2 Stake liquidity",
"Minswap: Zap Order":
icon = "🐱"
case "SSP: Swap Request":
icon = "🍨"
}
}
}

spaces := "10"
if icon != "" {
spaces = "9"
}
sb.WriteString(
fmt.Sprintf(" [white]%-20d [blue]%s[white]\n", size, tx.Hash()),
fmt.Sprintf(
" [white]%-10d %-"+spaces+"s [blue]%s[white]\n",
size,
icon,
tx.Hash(),
),
)
}
return fmt.Sprint(sb.String())
Expand Down

0 comments on commit b856d81

Please sign in to comment.