Skip to content

Commit

Permalink
add token handling for non eth tokens (AssetIdentifier), add tron log…
Browse files Browse the repository at this point in the history
…o in settings, store zero value tx setting to local storage
  • Loading branch information
soad003 committed Dec 7, 2023
1 parent 749caa8 commit 315ce67
Show file tree
Hide file tree
Showing 36 changed files with 209 additions and 150 deletions.
6 changes: 3 additions & 3 deletions src/Config/Graph.elm
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ type alias Config =
}


init : Maybe AddressLabelType -> Maybe TxLabelType -> Maybe Bool -> Maybe Bool -> Maybe Bool -> Config
init addressLabelType txLabelType showEntityShadowLinks showAddressShadowLinks showDatesInUserLocale =
init : Maybe AddressLabelType -> Maybe TxLabelType -> Maybe Bool -> Maybe Bool -> Maybe Bool -> Maybe Bool -> Config
init addressLabelType txLabelType showEntityShadowLinks showAddressShadowLinks showDatesInUserLocale showZeroTransactions =
{ addressLabelType = addressLabelType |> Maybe.withDefault Tag
, txLabelType = txLabelType |> Maybe.withDefault Value
, maxLettersPerLabelRow = 18
Expand All @@ -148,5 +148,5 @@ init addressLabelType txLabelType showEntityShadowLinks showAddressShadowLinks s
, showEntityShadowLinks = showEntityShadowLinks |> Maybe.withDefault True
, showAddressShadowLinks = showAddressShadowLinks |> Maybe.withDefault False
, showDatesInUserLocale = showDatesInUserLocale |> Maybe.withDefault True
, showZeroTransactions = True
, showZeroTransactions = showZeroTransactions |> Maybe.withDefault True
}
4 changes: 4 additions & 0 deletions src/Config/UserSettings.elm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type alias UserSettings =
, showAddressShadowLinks : Maybe Bool
, showClusterShadowLinks : Maybe Bool
, showDatesInUserLocale : Maybe Bool
, showZeroValueTxs : Maybe Bool
}


Expand Down Expand Up @@ -139,6 +140,7 @@ decoder =
|> optional "showAddressShadowLinks" (nullable bool |> fromString) Nothing
|> optional "showClusterShadowLinks" (nullable bool |> fromString) Nothing
|> optional "showDatesInUserLocale" (nullable bool |> fromString) Nothing
|> optional "showZeroValueTxs" (nullable bool |> fromString) Nothing


encoder : UserSettings -> Json.Encode.Value
Expand All @@ -153,6 +155,7 @@ encoder settings =
, ( "showAddressShadowLinks", settings.showAddressShadowLinks |> Maybe.map Json.Encode.bool |> Maybe.withDefault Json.Encode.null )
, ( "showClusterShadowLinks", settings.showClusterShadowLinks |> Maybe.map Json.Encode.bool |> Maybe.withDefault Json.Encode.null )
, ( "showDatesInUserLocale", settings.showDatesInUserLocale |> Maybe.map Json.Encode.bool |> Maybe.withDefault Json.Encode.null )
, ( "showZeroValueTxs", settings.showZeroValueTxs |> Maybe.map Json.Encode.bool |> Maybe.withDefault Json.Encode.null )
]


Expand All @@ -167,4 +170,5 @@ default =
, showAddressShadowLinks = Nothing
, showClusterShadowLinks = Nothing
, showDatesInUserLocale = Nothing
, showZeroValueTxs = Nothing
}
14 changes: 7 additions & 7 deletions src/Effect/Api.elm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Json.Decode
import Json.Encode
import Model.Graph.Id as Id exposing (AddressId)
import Model.Graph.Layer as Layer exposing (Layer)
import Model.Graph.Id exposing (currency)


type Effect msg
Expand All @@ -28,7 +29,7 @@ type Effect msg
(Api.Data.SearchResult -> msg)
| GetStatisticsEffect (Api.Data.Stats -> msg)
| GetConceptsEffect String (List Api.Data.Concept -> msg)
| ListSupportedTokensEffect (Api.Data.TokenConfigs -> msg)
| ListSupportedTokensEffect String (Api.Data.TokenConfigs -> msg)
| GetAddressEffect
{ currency : String
, address : String
Expand Down Expand Up @@ -286,10 +287,9 @@ map mapMsg effect =
>> mapMsg
|> GetConceptsEffect eff

ListSupportedTokensEffect m ->
m
>> mapMsg
|> ListSupportedTokensEffect
ListSupportedTokensEffect eff m ->
m >> mapMsg
|> ListSupportedTokensEffect eff

GetAddressEffect eff m ->
m
Expand Down Expand Up @@ -443,8 +443,8 @@ perform apiKey wrapMsg effect =
Api.Request.Tags.listConcepts taxonomy
|> send apiKey wrapMsg effect toMsg

ListSupportedTokensEffect toMsg ->
Api.Request.Tokens.listSupportedTokens "eth"
ListSupportedTokensEffect currency toMsg ->
Api.Request.Tokens.listSupportedTokens currency
|> send apiKey wrapMsg effect toMsg

GetEntityNeighborsEffect { currency, entity, isOutgoing, pagesize, onlyIds, nextpage } toMsg ->
Expand Down
7 changes: 5 additions & 2 deletions src/Init.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Plugin.Update as Plugin exposing (Plugins)
import RemoteData exposing (RemoteData(..))
import Update exposing (updateByPluginOutMsg)
import Url exposing (Url)
import Dict


init : Plugins -> Flags -> Url -> key -> ( Model key, List Effect )
Expand Down Expand Up @@ -51,7 +52,7 @@ init plugins flags url key =
, height = flags.height
, error = ""
, statusbar = Statusbar.init
, supportedTokens = Nothing
, supportedTokens = Dict.empty
, dialog = Nothing
, plugins = pluginStates
, dirty = False
Expand All @@ -61,7 +62,9 @@ init plugins flags url key =
|> ApiEffect
, Effect.Api.GetConceptsEffect "abuse" BrowserGotAbuseTaxonomy
|> ApiEffect
, Effect.Api.ListSupportedTokensEffect BrowserGotSupportedTokens
, Effect.Api.ListSupportedTokensEffect "eth" (BrowserGotSupportedTokens "eth")
|> ApiEffect
, Effect.Api.ListSupportedTokensEffect "trx" (BrowserGotSupportedTokens "trx")
|> ApiEffect
, PluginEffect cmd
]
Expand Down
2 changes: 1 addition & 1 deletion src/Init/Graph.elm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Model.Graph.Tool exposing (Toolbox(..))

init : UserSettings -> Int -> Model
init us now =
{ config = Config.init us.addressLabel us.edgeLabel us.showClusterShadowLinks us.showAddressShadowLinks us.showDatesInUserLocale
{ config = Config.init us.addressLabel us.edgeLabel us.showClusterShadowLinks us.showAddressShadowLinks us.showDatesInUserLocale us.showZeroValueTxs
, layers = IntDict.empty
, browser = Browser.init now
, adding = Adding.init
Expand Down
3 changes: 2 additions & 1 deletion src/Init/Locale.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Msg.Locale exposing (Msg(..))
import Numeral
import Time
import Update.Locale exposing (switch)
import Dict


init : UserSettings -> ( Model, List Effect )
Expand All @@ -28,7 +29,7 @@ init uc =
, currency = uc.valueDenomination |> Maybe.withDefault Coin
, relativeTimeOptions = DateFormat.Relative.defaultRelativeOptions
, unitToString = Locale.English.unitToString
, supportedTokens = Nothing
, supportedTokens = Dict.empty
}
|> switch locale
, [ Effect.Locale.getTranslationEffect locale
Expand Down
5 changes: 3 additions & 2 deletions src/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type alias Model navigationKey =
, error : String
, statusbar : Model.Statusbar.Model
, dialog : Maybe (Model.Dialog.Model Msg)
, supportedTokens : Maybe Api.Data.TokenConfigs
, supportedTokens : Dict String Api.Data.TokenConfigs
, plugins : Plugin.ModelState --Dict String Json.Encode.Value
, dirty : Bool
}
Expand Down Expand Up @@ -88,7 +88,7 @@ type Msg
| BrowserGotEntityTaxonomy (List Api.Data.Concept)
| BrowserGotAbuseTaxonomy (List Api.Data.Concept)
| BrowserGotElementForPlugin (Result Browser.Dom.Error Browser.Dom.Element -> Plugin.Msg) (Result Browser.Dom.Error Browser.Dom.Element)
| BrowserGotSupportedTokens Api.Data.TokenConfigs
| BrowserGotSupportedTokens String Api.Data.TokenConfigs
| UserClickedStatusbar
| UserClosesDialog
| LocaleMsg Msg.Locale.Msg
Expand Down Expand Up @@ -158,4 +158,5 @@ userSettingsFromMainModel model =
, showAddressShadowLinks = Just model.graph.config.showAddressShadowLinks
, showClusterShadowLinks = Just model.graph.config.showEntityShadowLinks
, showDatesInUserLocale = Just model.graph.config.showDatesInUserLocale
, showZeroValueTxs = Just model.graph.config.showZeroTransactions
}
12 changes: 12 additions & 0 deletions src/Model/Currency.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,15 @@ import List.Extra
type Currency
= Coin
| Fiat String


type alias AssetIdentifier = { network :String, asset: String }

assetFromBase: String -> AssetIdentifier
assetFromBase network = {network=network, asset=network}

asset: String -> String -> AssetIdentifier
asset network assetName = {network=network, asset=assetName}

tokensToValue: String -> List ( String, Api.Data.Values ) -> List ( AssetIdentifier, Api.Data.Values )
tokensToValue curr tokens = tokens |> List.map (\(x, v) -> ((asset curr x), v))
7 changes: 3 additions & 4 deletions src/Model/Graph/Browser.elm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Model.Graph.Table exposing (..)
import Model.Graph.Tag as Tag
import Model.Tx as T
import Time
import Model.Currency exposing (AssetIdentifier)


type alias Model =
Expand All @@ -30,7 +31,6 @@ type alias Model =
, width : Float
}


type Type
= None
| Address (Loadable String Address) (Maybe AddressTable)
Expand All @@ -50,7 +50,6 @@ type Loadable id thing
= Loading String id
| Loaded thing


type Value msg
= String String
| Stack (List (Value msg))
Expand All @@ -65,8 +64,8 @@ type Value msg
| Transactions { noIncomingTxs : Int, noOutgoingTxs : Int }
| Usage Time.Posix Int
| Duration Int
| Value (List ( String, Api.Data.Values ))
| MultiValue String Int (List ( String, Api.Data.Values ))
| Value (List ( AssetIdentifier, Api.Data.Values ))
| MultiValue String Int (List ( AssetIdentifier, Api.Data.Values ))
| Input (String -> msg) msg String
| Select (List ( String, String )) (String -> msg) String
| Html (Html msg)
Expand Down
3 changes: 2 additions & 1 deletion src/Model/Graph/Table.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Model.Graph.Table exposing (..)

import Api.Data
import Table
import Model.Currency exposing (AssetIdentifier)


titleTx : String
Expand Down Expand Up @@ -86,7 +87,7 @@ type AddresslinkTable


type alias AllAssetsTable =
Table ( String, Api.Data.Values )
Table ( AssetIdentifier, Api.Data.Values )


type alias Table a =
Expand Down
2 changes: 2 additions & 0 deletions src/Model/Graph/Table/AddressNeighborsTable.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Config.Graph as Graph
import Model.Graph.Table as Table
import Util.Graph as Graph
import Util.Data as Data
import Model.Currency exposing (assetFromBase)
import Model.Currency exposing (AssetIdentifier)


titleLabels : String
Expand Down
5 changes: 3 additions & 2 deletions src/Model/Graph/Table/AllAssetsTable.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ module Model.Graph.Table.AllAssetsTable exposing (..)
import Api.Data
import Model.Graph.Table as Table
import Tuple exposing (first)
import Model.Currency exposing (AssetIdentifier)


filter : Table.Filter ( String, Api.Data.Values )
filter : Table.Filter ( AssetIdentifier, Api.Data.Values )
filter =
{ search =
\term a -> String.contains term (first a)
\term a -> String.contains term (first a).network || String.contains term (first a).asset
, filter = always True
}
1 change: 1 addition & 0 deletions src/Model/Graph/Table/TxsAccountTable.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Api.Data
import Config.Graph as Graph
import Model.Graph.Table as Table
import Util.Graph as Graph
import Model.Currency exposing (assetFromBase)


titleTx : String
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Locale.elm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type alias Model =
, currency : Currency
, relativeTimeOptions : DateFormat.Relative.RelativeTimeOptions
, unitToString : Int -> Locale.Durations.Unit -> String
, supportedTokens : Maybe Api.Data.TokenConfigs
, supportedTokens : Dict String Api.Data.TokenConfigs
}


Expand Down
16 changes: 13 additions & 3 deletions src/Update.elm
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ update plugins uc msg model =
}
|> n

BrowserGotSupportedTokens configs ->
BrowserGotSupportedTokens currency configs ->
let
locale =
Locale.supportedTokens configs model.locale
Locale.setSupportedTokens configs currency model.locale
in
{ model
| supportedTokens = Just configs
| supportedTokens = Dict.insert currency configs model.supportedTokens
, locale = locale
, config =
model.config
Expand Down Expand Up @@ -639,6 +639,16 @@ update plugins uc msg model =
in
( newModel, SaveUserSettingsEffect (Model.userSettingsFromMainModel newModel) :: List.map GraphEffect graphEffects )

Graph.UserClickedToggleShowZeroTransactions ->
let
( graph, graphEffects ) =
Graph.update plugins uc m model.graph

newModel =
{ model | graph = graph }
in
( newModel, SaveUserSettingsEffect (Model.userSettingsFromMainModel newModel) :: List.map GraphEffect graphEffects )

Graph.UserClickedToggleShowDatesInUserLocale ->
let
( graph, graphEffects ) =
Expand Down
14 changes: 8 additions & 6 deletions src/Update/Graph/Browser.elm
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ import View.Graph.Table.TxsUtxoTable as TxsUtxoTable
import View.Graph.Table.UserAddressTagsTable as UserAddressTagsTable
import View.Locale as Locale
import Util.Data as Data
import Model.Currency exposing (asset)
import Model.Currency exposing (tokensToValue)


loadingAddress : { currency : String, address : String } -> Model -> Model
Expand Down Expand Up @@ -347,7 +349,7 @@ createAddressTable route loadable t =
:: (a.address.totalTokensReceived
|> Maybe.map Dict.toList
|> Maybe.withDefault []
)
) |> (tokensToValue a.address.currency )

_ ->
[]
Expand All @@ -368,7 +370,7 @@ createAddressTable route loadable t =
:: (a.address.tokenBalances
|> Maybe.map Dict.toList
|> Maybe.withDefault []
)
) |> (tokensToValue a.address.currency )

_ ->
[]
Expand Down Expand Up @@ -459,7 +461,7 @@ createLinkAllAssetsTable : String -> LinkData -> AddresslinkTable
createLinkAllAssetsTable currency link =
let
assets =
case link of
(case link of
Link.LinkData { value, tokenValues } ->
( currency, value )
:: (tokenValues
Expand All @@ -468,7 +470,7 @@ createLinkAllAssetsTable currency link =
)

Link.PlaceholderLinkData ->
[]
[]) |> tokensToValue currency
in
AllAssetsTable.init
|> appendData AllAssetsTable.filter assets
Expand Down Expand Up @@ -630,7 +632,7 @@ createEntityTable route loadable t =
:: (a.entity.totalTokensReceived
|> Maybe.map Dict.toList
|> Maybe.withDefault []
)
) |> tokensToValue currency

_ ->
[]
Expand All @@ -651,7 +653,7 @@ createEntityTable route loadable t =
:: (a.entity.tokenBalances
|> Maybe.map Dict.toList
|> Maybe.withDefault []
)
) |> tokensToValue currency

_ ->
[]
Expand Down
6 changes: 3 additions & 3 deletions src/Update/Locale.elm
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,6 @@ changeValueDetail curr model =
}


supportedTokens : Api.Data.TokenConfigs -> Model -> Model
supportedTokens configs model =
{ model | supportedTokens = Just configs }
setSupportedTokens : Api.Data.TokenConfigs -> String -> Model -> Model
setSupportedTokens configs currency model =
{ model | supportedTokens = Dict.insert currency configs model.supportedTokens }
4 changes: 2 additions & 2 deletions src/Update/Statusbar.elm
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ messageFromApiEffect model effect =
)
|> Just

Api.ListSupportedTokensEffect _ ->
( "loading supported token currencies"
Api.ListSupportedTokensEffect currency _ ->
( "loading supported token currencies for " ++ currency
, []
)
|> Just
Expand Down
Loading

0 comments on commit 315ce67

Please sign in to comment.