Skip to content

Commit

Permalink
add total received address label type in graph configuration, fix #438
Browse files Browse the repository at this point in the history
  • Loading branch information
myrho committed Jan 12, 2024
1 parent ee5582e commit cfd4f67
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 43 deletions.
36 changes: 36 additions & 0 deletions src/Config/Graph.elm
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ minGapBetweenLayers =
type AddressLabelType
= ID
| Balance
| TotalReceived
| Tag


Expand All @@ -131,6 +132,41 @@ type TxLabelType
| Value


addressLabelToString : AddressLabelType -> String
addressLabelToString c =
case c of
ID ->
"id"

Balance ->
"balance"

TotalReceived ->
"total received"

Tag ->
"tag"


stringToAddressLabel : String -> Maybe AddressLabelType
stringToAddressLabel s =
case s of
"id" ->
Just ID

"balance" ->
Just Balance

"tag" ->
Just Tag

"total received" ->
Just TotalReceived

_ ->
Nothing


type alias Config =
{ addressLabelType : AddressLabelType
, txLabelType : TxLabelType
Expand Down
33 changes: 2 additions & 31 deletions src/Config/UserSettings.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Config.UserSettings exposing (..)

import Config.Graph exposing (AddressLabelType(..), TxLabelType(..))
import Config.Graph exposing (AddressLabelType(..), TxLabelType(..), addressLabelToString, stringToAddressLabel)
import Json.Decode as Decode exposing (Decoder, bool, nullable, string)
import Json.Decode.Extra
import Json.Decode.Pipeline exposing (optional, required)
Expand Down Expand Up @@ -66,35 +66,6 @@ stringToCurrency s =
Fiat x


addressLabelToString : AddressLabelType -> String
addressLabelToString c =
case c of
ID ->
"id"

Balance ->
"balance"

Tag ->
"tag"


stringToAddressLabel : String -> AddressLabelType
stringToAddressLabel s =
case s of
"id" ->
ID

"balance" ->
Balance

"tag" ->
Tag

_ ->
ID


edgeLabelToString : TxLabelType -> String
edgeLabelToString c =
case c of
Expand Down Expand Up @@ -135,7 +106,7 @@ decoder =
|> optional "lightMode" (nullable bool |> fromString) Nothing
|> optional "valueDetail" (Decode.string |> Decode.map stringToValueDetail |> nullable) Nothing
|> optional "valueDenomination" (Decode.string |> Decode.map stringToCurrency |> nullable) Nothing
|> optional "addressLabel" (Decode.string |> Decode.map stringToAddressLabel |> nullable) Nothing
|> optional "addressLabel" (Decode.string |> Decode.map stringToAddressLabel) Nothing
|> optional "edgeLabel" (Decode.string |> Decode.map stringToEdgeLabel |> nullable) Nothing
|> optional "showAddressShadowLinks" (nullable bool |> fromString) Nothing
|> optional "showClusterShadowLinks" (nullable bool |> fromString) Nothing
Expand Down
14 changes: 2 additions & 12 deletions src/Update/Graph.elm
Original file line number Diff line number Diff line change
Expand Up @@ -1687,18 +1687,8 @@ updateByMsg plugins uc msg model =
| config =
model.config
|> s_addressLabelType
(case at of
"id" ->
Config.Graph.ID

"balance" ->
Config.Graph.Balance

"tag" ->
Config.Graph.Tag

_ ->
model.config.addressLabelType
(Config.Graph.stringToAddressLabel at
|> Maybe.withDefault model.config.addressLabelType
)
}
|> n
Expand Down
6 changes: 6 additions & 0 deletions src/View/Graph/Address.elm
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ getLabel vc gc addr =
Label.normalizeValues gc (Id.currency addr.id) addr.address.balance addr.address.tokenBalances
|> Locale.currency vc.locale

TotalReceived ->
Label.normalizeValues gc (Id.currency addr.id) addr.address.totalReceived addr.address.totalTokensReceived
|> Debug.log "values"
|> Locale.currency vc.locale
|> Debug.log "curr"

Tag ->
addr.userTag
|> Maybe.map .label
Expand Down
7 changes: 7 additions & 0 deletions src/View/Graph/Configuration.elm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ configuration vc config =
[ Locale.string vc.locale "Balance"
|> text
]
, option
[ value "total received"
, config.addressLabelType == Graph.TotalReceived |> selected
]
[ Locale.string vc.locale "Total received"
|> text
]
, option
[ value "tag"
, config.addressLabelType == Graph.Tag |> selected
Expand Down

0 comments on commit cfd4f67

Please sign in to comment.