Skip to content

Commit

Permalink
fetch supported token currencies from rest api
Browse files Browse the repository at this point in the history
  • Loading branch information
myrho committed Feb 1, 2023
1 parent 78c1e77 commit 32b5b79
Show file tree
Hide file tree
Showing 17 changed files with 260 additions and 52 deletions.
1 change: 1 addition & 0 deletions openapi/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ src/Api/Request/Entities.elm
src/Api/Request/General.elm
src/Api/Request/Rates.elm
src/Api/Request/Tags.elm
src/Api/Request/Tokens.elm
src/Api/Request/Txs.elm
src/Api/Time.elm
81 changes: 79 additions & 2 deletions openapi/src/Api/Data.elm
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ module Api.Data exposing
, Stats
, Tag
, Taxonomy
, TokenConfig
, TokenConfigs
, Tx(..)
, TxAccount
, TxSummary
Expand Down Expand Up @@ -85,6 +87,8 @@ module Api.Data exposing
, encodeStats
, encodeTag
, encodeTaxonomy
, encodeTokenConfig
, encodeTokenConfigs
, encodeTx
, encodeTxAccount
, encodeTxSummary
Expand Down Expand Up @@ -123,6 +127,8 @@ module Api.Data exposing
, statsDecoder
, tagDecoder
, taxonomyDecoder
, tokenConfigDecoder
, tokenConfigsDecoder
, txDecoder
, txAccountDecoder
, txSummaryDecoder
Expand Down Expand Up @@ -438,14 +444,27 @@ type alias Taxonomy =
}


type alias TokenConfig =
{ decimals : Int
, pegCurrency : Maybe String
, ticker : String
}


type alias TokenConfigs =
{ tokenConfigs : List (TokenConfig)
}


type Tx
= TxTxAccount TxAccount
| TxTxUtxo TxUtxo



type alias TxAccount =
{ currency : String
{ contractCreation : Maybe Bool
, currency : String
, fromAddress : String
, height : Int
, timestamp : Int
Expand Down Expand Up @@ -1276,6 +1295,48 @@ encodeTaxonomyPairs model =
pairs


encodeTokenConfig : TokenConfig -> Json.Encode.Value
encodeTokenConfig =
encodeObject << encodeTokenConfigPairs


encodeTokenConfigWithTag : ( String, String ) -> TokenConfig -> Json.Encode.Value
encodeTokenConfigWithTag (tagField, tag) model =
encodeObject (encodeTokenConfigPairs model ++ [ encode tagField Json.Encode.string tag ])


encodeTokenConfigPairs : TokenConfig -> List EncodedField
encodeTokenConfigPairs model =
let
pairs =
[ encode "decimals" Json.Encode.int model.decimals
, maybeEncode "peg_currency" Json.Encode.string model.pegCurrency
, encode "ticker" Json.Encode.string model.ticker
]
in
pairs


encodeTokenConfigs : TokenConfigs -> Json.Encode.Value
encodeTokenConfigs =
encodeObject << encodeTokenConfigsPairs


encodeTokenConfigsWithTag : ( String, String ) -> TokenConfigs -> Json.Encode.Value
encodeTokenConfigsWithTag (tagField, tag) model =
encodeObject (encodeTokenConfigsPairs model ++ [ encode tagField Json.Encode.string tag ])


encodeTokenConfigsPairs : TokenConfigs -> List EncodedField
encodeTokenConfigsPairs model =
let
pairs =
[ encode "token_configs" (Json.Encode.list encodeTokenConfig) model.tokenConfigs
]
in
pairs


encodeTx : Tx -> Json.Encode.Value
encodeTx model =
case model of
Expand All @@ -1302,7 +1363,8 @@ encodeTxAccountPairs : TxAccount -> List EncodedField
encodeTxAccountPairs model =
let
pairs =
[ encode "currency" Json.Encode.string model.currency
[ maybeEncode "contract_creation" Json.Encode.bool model.contractCreation
, encode "currency" Json.Encode.string model.currency
, encode "from_address" Json.Encode.string model.fromAddress
, encode "height" Json.Encode.int model.height
, encode "timestamp" Json.Encode.int model.timestamp
Expand Down Expand Up @@ -1777,6 +1839,20 @@ taxonomyDecoder =
|> decode "uri" Json.Decode.string


tokenConfigDecoder : Json.Decode.Decoder TokenConfig
tokenConfigDecoder =
Json.Decode.succeed TokenConfig
|> decode "decimals" Json.Decode.int
|> maybeDecode "peg_currency" Json.Decode.string Nothing
|> decode "ticker" Json.Decode.string


tokenConfigsDecoder : Json.Decode.Decoder TokenConfigs
tokenConfigsDecoder =
Json.Decode.succeed TokenConfigs
|> decode "token_configs" (Json.Decode.list tokenConfigDecoder)


txDecoder : Json.Decode.Decoder Tx
txDecoder =
Json.Decode.field "tx_type" Json.Decode.string
Expand All @@ -1800,6 +1876,7 @@ txTagDecoder tag =
txAccountDecoder : Json.Decode.Decoder TxAccount
txAccountDecoder =
Json.Decode.succeed TxAccount
|> maybeDecode "contract_creation" Json.Decode.bool Nothing
|> decode "currency" Json.Decode.string
|> decode "from_address" Json.Decode.string
|> decode "height" Json.Decode.int
Expand Down
38 changes: 38 additions & 0 deletions openapi/src/Api/Request/Tokens.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{-
GraphSense API
GraphSense API provides programmatic access to various ledgers' addresses, entities, blocks, transactions and tags for automated and highly efficient forensics tasks.
The version of the OpenAPI document: 1.1.1
Contact: [email protected]
NOTE: This file is auto generated by the openapi-generator.
https://github.com/openapitools/openapi-generator.git
DO NOT EDIT THIS FILE MANUALLY.
For more info on generating Elm code, see https://eriktim.github.io/openapi-elm/
-}


module Api.Request.Tokens exposing (..)

import Api
import Api.Data
import Dict
import Http
import Json.Decode
import Json.Encode



listSupportedTokens : (String) -> Api.Request Api.Data.TokenConfigs
listSupportedTokens currency_path =
Api.request
"GET"
"/{currency}/supported_tokens"
[ ( "currency", identity currency_path ) ]
[]
[]
Nothing
Api.Data.tokenConfigsDecoder

1 change: 1 addition & 0 deletions public/lang/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,4 @@ no: nein
"there are typos": "Es gibt Tippfehler"
smart contract: Smart contract
"token transactions of {0} ({1})": Token-Transaktionen von {0} ({1})
"loading supported token currencies": lade unterstützte Token-Währungen
11 changes: 11 additions & 0 deletions src/Effect/Api.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Api.Request.Entities
import Api.Request.General
import Api.Request.MyBulk
import Api.Request.Tags
import Api.Request.Tokens
import Api.Request.Txs
import Dict exposing (Dict)
import Http
Expand All @@ -26,6 +27,7 @@ type Effect msg
}
(Api.Data.SearchResult -> msg)
| GetConceptsEffect String (List Api.Data.Concept -> msg)
| ListSupportedTokensEffect (Api.Data.TokenConfigs -> msg)
| GetAddressEffect
{ currency : String
, address : String
Expand Down Expand Up @@ -268,6 +270,11 @@ map mapMsg effect =
>> mapMsg
|> GetConceptsEffect eff

ListSupportedTokensEffect m ->
m
>> mapMsg
|> ListSupportedTokensEffect

GetAddressEffect eff m ->
m
>> mapMsg
Expand Down Expand Up @@ -406,6 +413,10 @@ perform apiKey wrapMsg effect =
Api.Request.Tags.listConcepts taxonomy
|> send apiKey wrapMsg effect toMsg

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

GetEntityNeighborsEffect { currency, entity, isOutgoing, pagesize, onlyIds, includeLabels, nextpage } toMsg ->
let
direction =
Expand Down
3 changes: 3 additions & 0 deletions src/Init.elm
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ init plugins flags url key =
, height = flags.height
, error = ""
, statusbar = Statusbar.init
, supportedTokens = Nothing
, dialog = Nothing
, plugins = pluginStates
}
Expand All @@ -55,6 +56,8 @@ init plugins flags url key =
|> ApiEffect
, Effect.Api.GetConceptsEffect "abuse" BrowserGotAbuseTaxonomy
|> ApiEffect
, Effect.Api.ListSupportedTokensEffect BrowserGotSupportedTokens
|> ApiEffect
, PluginEffect cmd
]
)
Expand Down
1 change: 1 addition & 0 deletions src/Init/Locale.elm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ init { locale } =
, currency = Coin
, relativeTimeOptions = DateFormat.Relative.defaultRelativeOptions
, unitToString = Locale.English.unitToString
, supportedTokens = Nothing
}
|> switch locale
, [ Effect.Locale.getTranslationEffect locale
Expand Down
2 changes: 2 additions & 0 deletions src/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type alias Model navigationKey =
, error : String
, statusbar : Model.Statusbar.Model
, dialog : Maybe (Model.Dialog.Model Msg)
, supportedTokens : Maybe Api.Data.TokenConfigs
, plugins : Plugin.ModelState --Dict String Json.Encode.Value
}

Expand Down Expand Up @@ -87,6 +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
| UserClickedStatusbar
| UserClosesDialog
| LocaleMsg Msg.Locale.Msg
Expand Down
2 changes: 2 additions & 0 deletions src/Model/Locale.elm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Model.Locale exposing (..)

import Api.Data
import DateFormat.Language
import DateFormat.Relative
import Dict exposing (Dict)
Expand Down Expand Up @@ -41,4 +42,5 @@ type alias Model =
, currency : Currency
, relativeTimeOptions : DateFormat.Relative.RelativeTimeOptions
, unitToString : Int -> Locale.Durations.Unit -> String
, supportedTokens : Maybe Api.Data.TokenConfigs
}
46 changes: 38 additions & 8 deletions src/RecordSetter.elm
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,6 @@ s_caseInsensitive value__ record__ =
{ record__ | caseInsensitive = value__ }


s_casemgm_preview : a -> { b | casemgm_preview : a } -> { b | casemgm_preview : a }
s_casemgm_preview value__ record__ =
{ record__ | casemgm_preview = value__ }


s_categories : a -> { b | categories : a } -> { b | categories : a }
s_categories value__ record__ =
{ record__ | categories = value__ }
Expand Down Expand Up @@ -749,6 +744,11 @@ s_contentType value__ record__ =
{ record__ | contentType = value__ }


s_contents : a -> { b | contents : a } -> { b | contents : a }
s_contents value__ record__ =
{ record__ | contents = value__ }


s_context : a -> { b | context : a } -> { b | context : a }
s_context value__ record__ =
{ record__ | context = value__ }
Expand All @@ -764,6 +764,11 @@ s_contextStack value__ record__ =
{ record__ | contextStack = value__ }


s_contractCreation : a -> { b | contractCreation : a } -> { b | contractCreation : a }
s_contractCreation value__ record__ =
{ record__ | contractCreation = value__ }


s_coords : a -> { b | coords : a } -> { b | coords : a }
s_coords value__ record__ =
{ record__ | coords = value__ }
Expand Down Expand Up @@ -1664,9 +1669,9 @@ s_graph value__ record__ =
{ record__ | graph = value__ }


s_graphRoot : a -> { b | graphRoot : a } -> { b | graphRoot : a }
s_graphRoot value__ record__ =
{ record__ | graphRoot = value__ }
s_graphNavbarLeft : a -> { b | graphNavbarLeft : a } -> { b | graphNavbarLeft : a }
s_graphNavbarLeft value__ record__ =
{ record__ | graphNavbarLeft = value__ }


s_green : a -> { b | green : a } -> { b | green : a }
Expand Down Expand Up @@ -2554,6 +2559,11 @@ s_logo_lightmode value__ record__ =
{ record__ | logo_lightmode = value__ }


s_logout : a -> { b | logout : a } -> { b | logout : a }
s_logout value__ record__ =
{ record__ | logout = value__ }


s_logoutButton : a -> { b | logoutButton : a } -> { b | logoutButton : a }
s_logoutButton value__ record__ =
{ record__ | logoutButton = value__ }
Expand Down Expand Up @@ -3444,6 +3454,11 @@ s_pattern value__ record__ =
{ record__ | pattern = value__ }


s_pegCurrency : a -> { b | pegCurrency : a } -> { b | pegCurrency : a }
s_pegCurrency value__ record__ =
{ record__ | pegCurrency = value__ }


s_ph : a -> { b | ph : a } -> { b | ph : a }
s_ph value__ record__ =
{ record__ | ph = value__ }
Expand Down Expand Up @@ -4364,6 +4379,11 @@ s_suffix value__ record__ =
{ record__ | suffix = value__ }


s_supportedTokens : a -> { b | supportedTokens : a } -> { b | supportedTokens : a }
s_supportedTokens value__ record__ =
{ record__ | supportedTokens = value__ }


s_svgRoot : a -> { b | svgRoot : a } -> { b | svgRoot : a }
s_svgRoot value__ record__ =
{ record__ | svgRoot = value__ }
Expand Down Expand Up @@ -4634,6 +4654,11 @@ s_tickLength value__ record__ =
{ record__ | tickLength = value__ }


s_ticker : a -> { b | ticker : a } -> { b | ticker : a }
s_ticker value__ record__ =
{ record__ | ticker = value__ }


s_time : a -> { b | time : a } -> { b | time : a }
s_time value__ record__ =
{ record__ | time = value__ }
Expand Down Expand Up @@ -4724,6 +4749,11 @@ s_tokenBalances value__ record__ =
{ record__ | tokenBalances = value__ }


s_tokenConfigs : a -> { b | tokenConfigs : a } -> { b | tokenConfigs : a }
s_tokenConfigs value__ record__ =
{ record__ | tokenConfigs = value__ }


s_tokenTxId : a -> { b | tokenTxId : a } -> { b | tokenTxId : a }
s_tokenTxId value__ record__ =
{ record__ | tokenTxId = value__ }
Expand Down
Loading

0 comments on commit 32b5b79

Please sign in to comment.