Skip to content

Commit

Permalink
adding nodes to graph
Browse files Browse the repository at this point in the history
  • Loading branch information
myrho committed Apr 12, 2024
1 parent 4dddfb6 commit ef040df
Show file tree
Hide file tree
Showing 22 changed files with 542 additions and 109 deletions.
7 changes: 6 additions & 1 deletion src/Config/View.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Config.View exposing (Config)
module Config.View exposing (Config, getUnit)

import Model.Graph.Coords exposing (BBox)
import Model.Locale as Locale
Expand All @@ -13,3 +13,8 @@ type alias Config =
, lightmode : Bool
, size : Maybe BBox -- position and size of the main pane
}


getUnit : Config -> Float
getUnit { theme } =
theme.pathfinder.addressRadius * 2
5 changes: 5 additions & 0 deletions src/Css/Pathfinder.elm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ address vc =
vc.theme.pathfinder.address


addressHandle : View.Config -> List Style
addressHandle vc =
vc.theme.pathfinder.addressHandle



-- helpers

Expand Down
13 changes: 12 additions & 1 deletion src/Effect.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Effect exposing (n, perform)
module Effect exposing (n, and, perform)

--import Plugin.Effect

Expand Down Expand Up @@ -26,6 +26,17 @@ n m =
( m, [] )


and : (m -> ( m, List eff )) -> ( m, List eff ) -> ( m, List eff )
and update ( m, eff ) =
let
( m2, eff2 ) =
update m
in
( m2
, eff ++ eff2
)


perform : Plugins -> Nav.Key -> Maybe String -> String -> Effect -> Cmd Msg
perform plugins key statusbarToken apiKey effect =
case effect of
Expand Down
23 changes: 19 additions & 4 deletions src/Effect/Api.elm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Http
import IntDict exposing (IntDict)
import Json.Decode
import Json.Encode
import Model.Direction exposing (Direction(..))
import Model.Graph.Id as Id exposing (AddressId, currency)
import Model.Graph.Layer as Layer exposing (Layer)

Expand Down Expand Up @@ -76,6 +77,7 @@ type Effect msg
| GetAddressTxsEffect
{ currency : String
, address : String
, direction : Maybe Direction
, pagesize : Int
, nextpage : Maybe String
}
Expand Down Expand Up @@ -136,6 +138,7 @@ type Effect msg
{ currency : String
, txHash : String
, tokenTxId : Maybe Int
, includeIo : Bool
}
(Api.Data.Tx -> msg)
| GetTxUtxoAddressesEffect
Expand Down Expand Up @@ -488,8 +491,20 @@ perform apiKey wrapMsg effect =
Api.Request.Addresses.getAddressEntity currency address
|> send apiKey wrapMsg effect toMsg

GetAddressTxsEffect { currency, address, pagesize, nextpage } toMsg ->
Api.Request.Addresses.listAddressTxs currency address Nothing Nothing Nothing Nothing nextpage (Just pagesize)
GetAddressTxsEffect { currency, address, direction, pagesize, nextpage } toMsg ->
let
dir =
case direction of
Nothing ->
Nothing

Just Incoming ->
Just Api.Request.Addresses.DirectionIn

Just Outgoing ->
Just Api.Request.Addresses.DirectionOut
in
Api.Request.Addresses.listAddressTxs currency address dir Nothing Nothing Nothing nextpage (Just pagesize)
|> send apiKey wrapMsg effect toMsg

GetAddresslinkTxsEffect { currency, source, target, pagesize, nextpage } toMsg ->
Expand Down Expand Up @@ -524,8 +539,8 @@ perform apiKey wrapMsg effect =
Api.Request.Blocks.listBlockTxs currency block
|> send apiKey wrapMsg effect toMsg

GetTxEffect { currency, txHash, tokenTxId } toMsg ->
Api.Request.Txs.getTx currency txHash (Just False) tokenTxId
GetTxEffect { currency, txHash, tokenTxId, includeIo } toMsg ->
Api.Request.Txs.getTx currency txHash (Just includeIo) tokenTxId
|> send apiKey wrapMsg effect toMsg

GetTxUtxoAddressesEffect { currency, txHash, isOutgoing } toMsg ->
Expand Down
6 changes: 3 additions & 3 deletions src/Init/Pathfinder/Address.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import Model.Pathfinder.Id exposing (Id)
import RemoteData exposing (RemoteData(..))


init : Id -> Api.Data.Address -> Coords -> Address
init id data { x, y } =
init : Id -> Coords -> Address
init id { x, y } =
{ x = x
, y = y
, id = id
, transactions = NotAsked
, data = data
, data = NotAsked
}
16 changes: 16 additions & 0 deletions src/Model/Direction.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Model.Direction exposing (..)

type Direction
= Incoming
| Outgoing


toString : Direction -> String
toString dir =
case dir of
Incoming ->
"incoming"
Outgoing ->
"outgoing"


17 changes: 4 additions & 13 deletions src/Model/Pathfinder.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Model.Pathfinder.History.Entry as Entry
import Model.Pathfinder.Id exposing (Id)
import Model.Pathfinder.Network exposing (Network)
import Model.Search as Search
import RecordSetter exposing (s_detailsViewState, s_selection)


type alias Model =
Expand Down Expand Up @@ -71,26 +72,16 @@ setViewState fn model =
{ model | view = fn model.view }


setSelection : Selection -> Model -> Model
setSelection val model =
{ model | selection = val }


setDetailsViewState : DetailsViewState -> ViewState -> ViewState
setDetailsViewState val model =
{ model | detailsViewState = val }


closeDetailsView : Model -> Model
closeDetailsView =
(setViewState <| setDetailsViewState NoDetails) >> setSelection NoSelection
(setViewState <| s_detailsViewState NoDetails) >> s_selection NoSelection


toggleAddressDetailsTable : Model -> Model
toggleAddressDetailsTable m =
case m.view.detailsViewState of
AddressDetails id ad ->
(setViewState <| setDetailsViewState (AddressDetails id { ad | addressTableOpen = not ad.addressTableOpen })) m
(setViewState <| s_detailsViewState (AddressDetails id { ad | addressTableOpen = not ad.addressTableOpen })) m

_ ->
m
Expand All @@ -100,7 +91,7 @@ toggleTransactionDetailsTable : Model -> Model
toggleTransactionDetailsTable m =
case m.view.detailsViewState of
AddressDetails id ad ->
(setViewState <| setDetailsViewState (AddressDetails id { ad | transactionsTableOpen = not ad.transactionsTableOpen })) m
(setViewState <| s_detailsViewState (AddressDetails id { ad | transactionsTableOpen = not ad.transactionsTableOpen })) m

_ ->
m
2 changes: 1 addition & 1 deletion src/Model/Pathfinder/Address.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ type alias Address =
, y : Float
, id : Id
, transactions : WebData (Set String)
, data : Api.Data.Address
, data : WebData Api.Data.Address
}
2 changes: 2 additions & 0 deletions src/Model/Pathfinder/Error.elm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Model.Pathfinder.Error exposing (..)

import Model.Direction exposing (Direction)
import Model.Pathfinder.Id exposing (Id)


Expand All @@ -10,3 +11,4 @@ type Error

type InternalError
= AddressNotFoundInDict Id
| TxValuesEmpty Direction Id
10 changes: 0 additions & 10 deletions src/Model/Pathfinder/Input.elm

This file was deleted.

10 changes: 0 additions & 10 deletions src/Model/Pathfinder/Output.elm

This file was deleted.

81 changes: 70 additions & 11 deletions src/Model/Pathfinder/Tx.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ module Model.Pathfinder.Tx exposing (..)
import Api.Data
import Dict exposing (Dict)
import Dict.Nonempty as NDict exposing (NonemptyDict)
import Init.Pathfinder.Id as Id
import List.Nonempty as NList
import Model.Direction exposing (Direction(..))
import Model.Graph.Coords as Coords exposing (Coords)
import Model.Pathfinder.Address exposing (Address)
import Model.Pathfinder.Error exposing (..)
import Model.Pathfinder.Id exposing (Id)
import Model.Pathfinder.Input exposing (Input)
import Model.Pathfinder.Output exposing (Output)
import Tuple exposing (first)
import Util.Pathfinder exposing (getAddress)


type alias Tx =
Expand All @@ -32,8 +33,8 @@ type alias AccontTx =


type alias UtxoTx =
{ inputs : NonemptyDict Id Input
, outputs : NonemptyDict Id Output
{ inputs : NonemptyDict Id Api.Data.Values
, outputs : NonemptyDict Id Api.Data.Values
}


Expand Down Expand Up @@ -113,13 +114,71 @@ avg field items =
|> Ok


getAddress : Dict Id Address -> Id -> Result Error Address
getAddress addresses id =
Dict.get id addresses
|> Maybe.map Ok
|> Maybe.withDefault (AddressNotFoundInDict id |> InternalError |> Err)


addressToCoords : Address -> Coords
addressToCoords { x, y } =
Coords x y


fromData : Api.Data.Tx -> Result Error Tx
fromData data =
case data of
Api.Data.TxTxAccount t ->
let
id =
Id.init t.currency t.txHash
in
Ok
{ id = id
, type_ =
Account
{ from = Id.init t.currency t.fromAddress
, to = Id.init t.currency t.toAddress
, value = t.value
}
}

Api.Data.TxTxUtxo t ->
let
id =
Id.init t.currency t.txHash

fn direction =
let
field =
case direction of
Incoming ->
.inputs

Outgoing ->
.outputs

toPair : Api.Data.TxValue -> Maybe ( Id, Api.Data.Values )
toPair { address, value } =
-- TODO what to do with multisig?
List.head address
|> Maybe.map (\a -> ( Id.init t.currency a, value ))
in
field t
|> Maybe.map (List.filterMap toPair)
|> Maybe.andThen NList.fromList
|> Maybe.map (NDict.fromNonemptyList >> Ok)
|> Maybe.withDefault (InternalError (TxValuesEmpty direction id) |> Err)

inputs =
fn Incoming

outputs =
fn Outgoing
in
Result.map2
(\in_ out ->
{ id = id
, type_ =
Utxo
{ inputs = in_
, outputs = out
}
}
)
inputs
outputs
6 changes: 5 additions & 1 deletion src/Msg/Pathfinder.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Msg.Pathfinder exposing (..)

import Api.Data
import Model.Direction exposing (Direction)
import Model.Graph exposing (Dragging)
import Model.Graph.Coords exposing (Coords)
import Model.Pathfinder.Id exposing (Id)
Expand All @@ -22,7 +23,10 @@ type Msg
| UserClosedDetailsView
| UserClickedToggleAddressDetailsTable
| UserClickedToggleTransactionDetailsTable
| BrowserGotAddress Id Api.Data.Address
| BrowserGotNewAddress Id Api.Data.Address
| UserClickedAddressExpandHandle Id Direction
| PluginMsg Plugin.Msg
| SearchMsg Search.Msg
| NoOp
| BrowserGotRecentTx Id Direction Api.Data.AddressTxs
| BrowserGotTxForAddress Id Direction Api.Data.Tx
4 changes: 4 additions & 0 deletions src/Theme/Pathfinder.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import Css exposing (Style)
type alias Pathfinder =
{ root : List Style
, address : List Style
, addressHandle : List Style
, addressRadius : Float
}


default : Pathfinder
default =
{ root = []
, address = []
, addressHandle = []
, addressRadius = 10
}
Loading

0 comments on commit ef040df

Please sign in to comment.