Skip to content

Commit

Permalink
Improved address pretty render (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
hrajchert authored Oct 27, 2023
1 parent bfe11f2 commit 02d2955
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
40 changes: 40 additions & 0 deletions changelog.d/20231027_140636_hrajchert_fix_addr_show.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Removed
- A bullet item for the Removed category.
-->
### Added

- Change the way addresses are summarised to make testnet ones easy to tell apart by showing both prefix and suffix.

<!--
### Changed
- A bullet item for the Changed category.
-->
<!--
### Deprecated
- A bullet item for the Deprecated category.
-->
<!--
### Fixed
- A bullet item for the Fixed category.
-->
<!--
### Security
- A bullet item for the Security category.
-->
6 changes: 1 addition & 5 deletions marlowe-playground-client/src/Page/Simulation/View.purs
Original file line number Diff line number Diff line change
Expand Up @@ -687,16 +687,12 @@ participant metadata state party actionInputs =
[ h6_
[ em [ classNames [ "mr-1" ] ]
[ text "Participant "
, strong_ [ text partyName ]
, strong_ [ renderPrettyParty metadata party ]
]
, partyHint
]
]

partyName = case party of
(Address name) -> name
(Role name) -> name

choiceRef :: String -> ChoiceId -> String
choiceRef prefix (ChoiceId choiceName choiceOwner) = intercalate "-"
[ prefix, choiceName, choiceOwnerStr ]
Expand Down
9 changes: 7 additions & 2 deletions marlowe-playground-client/src/Pretty.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ import Data.Numbers.Natural as N
import Data.String as String
import Halogen.HTML (HTML, abbr, text)
import Halogen.HTML.Properties (title)
import Language.Marlowe.Core.V1.Semantics.Types (Party(..), Payee(..))
import Language.Marlowe.Core.V1.Semantics.Types (Address, Party(..), Payee(..))
import Language.Marlowe.Extended.V1.Metadata.Types (MetaData, NumberFormat(..))

prettyAddress :: Address -> String
prettyAddress addr = String.take 9 addr <> "..." <> takeEnd 5 addr
where
takeEnd n str = String.drop (String.length str - n) str

renderPrettyParty :: forall p i. MetaData -> Party -> HTML p i
renderPrettyParty _ (Address addr) =
if String.length addr > 10 then abbr [ title $ "address " <> addr ]
[ text $ String.take 10 addr ]
[ text $ prettyAddress addr ]
else text addr

renderPrettyParty metadata (Role role) = abbr
Expand Down

0 comments on commit 02d2955

Please sign in to comment.