Commit 3b1b864c authored by Cédric F.'s avatar Cédric F.

Keep lines below 100 characters long

parent b6001e18
Pipeline #13792626 passed with stage
in 1 minute and 23 seconds
......@@ -58,7 +58,11 @@ view model =
details model =
if missingTransactions model then
[ div [ class "alert alert-warning" ]
[ text <| "Only the " ++ toString maxTransactionCount ++ " most recent transactions are shown below." ]
[ text <|
"Only the "
++ toString maxTransactionCount
++ " most recent transactions are shown below."
]
]
else
[ dlBuilder <|
......@@ -67,6 +71,25 @@ view model =
, ( "balance", Maybe.map formatAmount <| balance model )
]
]
transactions model =
model.transactions
|> List.map
(\tx ->
tr []
[ td [] [ a [ href tx.hash ] [ text <| shortHash tx.hash ] ]
, td [] [ text tx.type_ ]
, td []
[ (Transaction.sentToAddress model.address tx
|> Maybe.map formatAmount
|> Maybe.withDefault
(span [] [ text "?" ])
)
]
, td [] [ text <| Transaction.formatTime tx ]
, td [] [ text <| toString tx.confirmations ]
]
)
in
div [ class "row" ]
[ div [ class "col-8 offset-2" ]
......@@ -81,7 +104,11 @@ view model =
, div [ class "row" ]
[ div [ class "col" ]
[ h4 [ class "text-center" ]
[ span [ class "badge badge-pill badge-info" ] [ text <| toString (List.length model.transactions) ++ " transactions" ]
[ span [ class "badge badge-pill badge-info" ]
[ text <|
toString (List.length model.transactions)
++ " transactions"
]
]
, table [ class "table table-dark table-striped" ]
[ thead []
......@@ -90,27 +117,11 @@ view model =
, th [] [ text "type" ]
, th [] [ text "credit" ]
, th [] [ text "time" ]
, th [] [ abbr [ title "confirmations" ] [ text "conf." ] ]
, th []
[ abbr [ title "confirmations" ] [ text "conf." ] ]
]
]
, tbody [] <|
List.map
(\tx ->
tr []
[ td [] [ a [ href tx.hash ] [ text <| shortHash tx.hash ] ]
, td [] [ text tx.type_ ]
, td []
[ (Transaction.sentToAddress model.address tx
|> Maybe.map formatAmount
|> Maybe.withDefault
(span [] [ text "?" ])
)
]
, td [] [ text <| Transaction.formatTime tx ]
, td [] [ text <| toString tx.confirmations ]
]
)
model.transactions
, tbody [] <| transactions model
]
]
]
......@@ -232,6 +243,10 @@ totalSent model =
|> Just
--- FIXME: should not be a Maybe
balance : Model -> Maybe Float
balance model =
Maybe.map2 (-) (totalReceived model) (totalSent model)
......@@ -102,6 +102,8 @@ view model =
[ a
[ class "btn btn-secondary"
, href "javascript:void(0)"
-- FIXME: prevblock
, onClick (GetBlock "000000000000006fa9bf10d4a39d0cbc6ef8dc2f2db3e7841fd33b7ad973811a")
]
[ text "<" ]
......@@ -167,15 +169,7 @@ update msg model =
Ok jsonModel ->
let
previousBlockHash =
case jsonModel.previousBlockHash of
Just hash ->
if hash /= "0000000000000000000000000000000000000000000000000000000000000000" then
Just hash
else
Nothing
Nothing ->
Nothing
zeroesToNothing jsonModel.previousBlockHash
in
( { model
| height = jsonModel.height
......@@ -245,8 +239,12 @@ decodeGetBlock =
|> Pipeline.optionalAt [ "result", "sbits" ] (Decode.maybe Decode.float) Nothing
|> Pipeline.requiredAt [ "result", "tx" ] (Decode.list Decode.string)
|> Pipeline.optionalAt [ "result", "stx" ] (Decode.list Decode.string) []
|> Pipeline.optionalAt [ "result", "previousblockhash" ] (Decode.maybe Decode.string) Nothing
|> Pipeline.optionalAt [ "result", "nextblockhash" ] (Decode.maybe Decode.string) Nothing
|> Pipeline.optionalAt [ "result", "previousblockhash" ]
(Decode.maybe Decode.string)
Nothing
|> Pipeline.optionalAt [ "result", "nextblockhash" ]
(Decode.maybe Decode.string)
Nothing
decodeGetBlockHash : Decode.Decoder String
......
......@@ -144,7 +144,9 @@ view model =
, div []
[ (case vIn.txId of
Just hash ->
a [ href hash ] [ text <| "Transaction " ++ shortHash hash ]
a
[ href hash ]
[ text <| "Transaction " ++ shortHash hash ]
Nothing ->
span [] []
......@@ -177,17 +179,23 @@ view model =
[ p [ class "card-text" ]
[ dl [ class "row" ]
[ dt [ class "col-3 text-right" ] [ text "type" ]
, dd [ class "col-9" ] [ formatType model.type_ ]
, dd [ class "col-9" ]
[ formatType model.type_ ]
, dt [ class "col-3 text-right" ] [ text "confirmations" ]
, dd [ class "col-9" ] [ text <| toString model.confirmations ]
, dd [ class "col-9" ]
[ text <| toString model.confirmations ]
, dt [ class "col-3 text-right" ] [ text "time" ]
, dd [ class "col-9" ] [ text <| formatTime model ]
, dd [ class "col-9" ]
[ text <| formatTime model ]
, dt [ class "col-3 text-right" ] [ text "block" ]
, dd [ class "col-9" ] [ formatBlock model.blockHash model.blockHeight ]
, dd [ class "col-9" ]
[ formatBlock model.blockHash model.blockHeight ]
, dt [ class "col-3 text-right" ] [ text "size" ]
, dd [ class "col-9" ] [ text <| toString model.size ++ " bytes" ]
, dd [ class "col-9" ]
[ text <| toString model.size ++ " bytes" ]
, dt [ class "col-3 text-right" ] [ text "total sent" ]
, dd [ class "col-9" ] [ formatAmount (totalSent model) ]
, dd [ class "col-9" ]
[ formatAmount (totalSent model) ]
, dt [ class "col-3 text-right" ] [ text "fee" ]
, dd [ class "col-9" ]
[ formatAmount (fee model)
......@@ -204,14 +212,16 @@ view model =
[ span [ class "badge badge-pill badge-info" ]
[ text <| pluralize (List.length model.vIn) "input" ]
]
, ul [ class "list-group list-group-flush" ] <| formatVIn model.vIn
, ul [ class "list-group list-group-flush" ] <|
formatVIn model.vIn
]
, div [ class "col" ]
[ h4 [ class "text-center" ]
[ span [ class "badge badge-pill badge-info" ]
[ text <| pluralize (List.length model.vOut) "output" ]
]
, ul [ class "list-group list-group-flush" ] <| formatVOut model.vOut
, ul [ class "list-group list-group-flush" ] <|
formatVOut model.vOut
]
]
]
......@@ -276,29 +286,15 @@ decodeGetRawTransaction prefix =
|> Pipeline.requiredAt (path "vout") (Decode.list decodeVOut)
zeroToNothing : Maybe String -> Decode.Decoder (Maybe String)
zeroToNothing maybe =
let
zero =
"0000000000000000000000000000000000000000000000000000000000000000"
in
Decode.succeed <|
case maybe of
Just string ->
if string == zero then
Nothing
else
maybe
Nothing ->
maybe
decodeVIn : Decode.Decoder VIn
decodeVIn =
Pipeline.decode VIn
-- no txid for coinbase txs
|> Pipeline.optionalAt [ "txid" ] (Decode.maybe Decode.string |> Decode.andThen zeroToNothing) Nothing
|> Pipeline.optionalAt [ "txid" ]
(Decode.maybe Decode.string
|> Decode.andThen (\txid -> zeroesToNothing txid |> Decode.succeed)
)
Nothing
|> Pipeline.optionalAt [ "coinbase" ] (Decode.maybe Decode.string) Nothing
|> Pipeline.optionalAt [ "amountin" ] Decode.float 0
|> Pipeline.optionalAt [ "blockheight" ] (Decode.maybe Decode.int) Nothing
......@@ -335,7 +331,8 @@ computeType jsonModel =
List.map (\i -> i.scriptPubKey.type_) jsonModel.vOut
|> List.member type_
in
--- XXX: simplified detection (full rules can be found in dcrd/blockchain/stake/staketx.go)
--- XXX: simplified detection
--- full rules can be found in dcrd/blockchain/stake/staketx.go
if hasVOutType "stakesubmission" jsonModel then
"Ticket"
else if hasVOutType "stakegen" jsonModel then
......@@ -428,16 +425,6 @@ sentToAddress address model =
Just <| vOutToAddress address model
-- vOutToAddressUnspent : String -> Model -> Float
-- vOutToAddressUnspent address model =
-- model.vOut
-- |> List.filter
-- (\vOut -> List.member address vOut.scriptPubKey.addresses)
-- |> List.map .value
-- |> List.sum
totalVIn : Model -> Float
totalVIn model =
List.map .amountIn model.vIn |> List.sum
......
--- FIXME: unused?
module Lib.HtmlAttributesExtra exposing (..)
import Html exposing (Attribute)
......
......@@ -36,7 +36,10 @@ parseError : Http.Error -> Maybe String
parseError error =
case error of
Http.BadStatus response ->
Just ("Backend error " ++ toString response.status.code ++ response.status.message)
Just <|
"Backend error "
++ toString response.status.code
++ response.status.message
Http.BadPayload message response ->
Just <| decodeError response.body
......@@ -45,7 +48,12 @@ parseError error =
Just (toString error)
post : String -> Json.Encode.Value -> (Result Http.Error a -> msg) -> Json.Decode.Decoder a -> Cmd msg
post :
String
-> Json.Encode.Value
-> (Result Http.Error a -> msg)
-> Json.Decode.Decoder a
-> Cmd msg
post method params result decoder =
Http.send result <|
Http.request <|
......
......@@ -58,3 +58,20 @@ dcrDataLink path =
, href <| "https://explorer.dcrdata.org/explorer/" ++ path
]
[ span [ class "oi oi-external-link" ] [] ]
zeroesToNothing : Maybe String -> Maybe String
zeroesToNothing maybe =
let
zeroes =
"0000000000000000000000000000000000000000000000000000000000000000"
in
case maybe of
Just string ->
if string == zeroes then
Nothing
else
maybe
Nothing ->
Nothing
......@@ -77,6 +77,7 @@ update action model =
Query query ->
let
--- FIXME: add BTC genesis?
genesis =
"298e5cc3d985bfe7f81dc135f360abe089edd4396b86d2de66b0cef42b21d980"
......@@ -85,10 +86,12 @@ update action model =
-- XXX: Remove a few zeros in the future... 00000000
possibleBlockHash query =
(String.length query == 64 && String.left 8 query == "00000000") || query == genesis
(String.length query == 64 && String.left 8 query == "00000000")
|| (query == genesis)
possibleTransaction query =
String.length query == 64 && String.left 8 query /= "00000000" && query /= genesis
(String.length query == 64 && String.left 8 query /= "00000000")
&& (query /= genesis)
updatedModel =
{ model | query = query, error = Nothing }
......
......@@ -63,8 +63,9 @@ searchView model =
[ input
[ id "query"
, name "query"
, placeholder "Search for blocks, transactions, addresses, particles, etc."
, class "form-control form-control-lg text-center mt-2 mb-4"
, placeholder
"Search for blocks, transactions, addresses, particles, etc."
, onInput Query
, value model.query
]
......
......@@ -18,7 +18,11 @@ suite =
\() ->
let
result =
Decode.decodeString (Address.decodeSearchRawTransactions "Dcur2mcGjmENx4DhNqDctW5wJCVyT3Qeqkx") searchRawTransactionsFixture
Decode.decodeString
(Address.decodeSearchRawTransactions
"Dcur2mcGjmENx4DhNqDctW5wJCVyT3Qeqkx"
)
searchRawTransactionsFixture
model =
case result of
......@@ -33,7 +37,10 @@ suite =
, describe "Block"
[ test "decodeGetBlockHash" <|
\() ->
Expect.equal (Ok "deadbeef") <| Decode.decodeString Block.decodeGetBlockHash "{\"result\":\"deadbeef\"}"
Expect.equal (Ok "deadbeef") <|
Decode.decodeString
Block.decodeGetBlockHash
"{\"result\":\"deadbeef\"}"
]
, describe "Transaction"
[ test "decodeGetRawTransaction with a confirmed transaction" <|
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment