Add lamassu-admin-elm to this repo (#185)

This commit is contained in:
Rafael Taranto 2018-10-08 16:29:06 -03:00 committed by Josh Harvey
parent 5ee7e40872
commit f4fc9d6328
134 changed files with 28171 additions and 83 deletions

View file

@ -0,0 +1,102 @@
module Transaction.Decoder exposing (..)
import Json.Decode exposing (..)
import Json.Decode.Extra exposing (date, fromResult)
import Json.Decode.Pipeline exposing (decode, required, optional, hardcoded)
import Common.TransactionTypes exposing (..)
import String
mapCryptoCode : String -> Decoder CryptoCode
mapCryptoCode code =
case code of
"BTC" -> succeed BTC
"BCH" -> succeed BCH
"ETH" -> succeed ETH
"ZEC" -> succeed ZEC
"DASH" -> succeed DASH
"LTC" -> succeed LTC
_ -> fail ("No such cryptocurrency: " ++ code)
cryptoCodeDecoder : Decoder CryptoCode
cryptoCodeDecoder =
string
|> andThen mapCryptoCode
txDecode : String -> Decoder Tx
txDecode txClass =
case txClass of
"cashIn" ->
map CashInTx cashInTxDecoder
"cashOut" ->
map CashOutTx cashOutTxDecoder
_ ->
fail ("Unknown tx class: " ++ txClass)
txsDecoder : Decoder (List Tx)
txsDecoder =
(field "transactions" (list txDecoder))
txDecoder : Decoder Tx
txDecoder =
(field "txClass" string)
|> andThen txDecode
floatString : Decoder Float
floatString =
string |> andThen (String.toFloat >> fromResult)
intString : Decoder Int
intString =
string |> andThen (String.toInt >> fromResult)
cashInTxDecoder : Decoder CashInTxRec
cashInTxDecoder =
decode CashInTxRec
|> required "id" string
|> required "machineName" string
|> required "toAddress" string
|> required "cryptoAtoms" intString
|> required "cryptoCode" cryptoCodeDecoder
|> required "fiat" floatString
|> required "fiatCode" string
|> required "txHash" (nullable string)
|> required "phone" (nullable string)
|> required "error" (nullable string)
|> required "operatorCompleted" bool
|> required "send" bool
|> required "sendConfirmed" bool
|> required "expired" bool
|> required "created" date
confirmedDecoder : Decoder Bool
confirmedDecoder =
map (Maybe.map (always True) >> Maybe.withDefault False)
(nullable string)
cashOutTxDecoder : Decoder CashOutTxRec
cashOutTxDecoder =
decode CashOutTxRec
|> required "id" string
|> required "machineName" string
|> required "toAddress" string
|> required "cryptoAtoms" intString
|> required "cryptoCode" cryptoCodeDecoder
|> required "fiat" floatString
|> required "fiatCode" string
|> required "status" string
|> required "dispense" bool
|> required "notified" bool
|> required "redeem" bool
|> required "phone" (nullable string)
|> required "error" (nullable string)
|> required "created" date
|> required "confirmedAt" confirmedDecoder

View file

@ -0,0 +1,31 @@
module Transaction.Rest exposing (..)
import RemoteData exposing (..)
import HttpBuilder exposing (..)
import Http
import HttpBuilder exposing (..)
import BasicTypes exposing (..)
import Common.TransactionTypes exposing (..)
import Transaction.Types exposing (..)
import Transaction.Decoder exposing (txDecoder)
toModel : SavingStatus -> Tx -> SubModel
toModel status tx =
{ status = status, tx = tx }
getForm : String -> Cmd Msg
getForm txId =
get ("/api/transaction/" ++ txId)
|> withExpect (Http.expectJson txDecoder)
|> send (Result.map (toModel NotSaving) >> RemoteData.fromResult)
|> Cmd.map Load
cancel : String -> Cmd Msg
cancel txId =
patch ("/api/transaction/" ++ txId ++ "?cancel=true")
|> withExpect (Http.expectJson txDecoder)
|> send (Result.map (toModel NotSaving) >> RemoteData.fromResult)
|> Cmd.map Load

View file

@ -0,0 +1,34 @@
module Transaction.State exposing (..)
import RemoteData exposing (..)
import Transaction.Types exposing (..)
import Transaction.Rest exposing (..)
import BasicTypes exposing (..)
init : Model
init =
NotAsked
load : String -> ( Model, Cmd Msg )
load txId =
( Loading, getForm txId )
txUpdate : SubModel -> ( SubModel, Cmd Msg )
txUpdate model =
model ! []
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Load newModel ->
RemoteData.update txUpdate newModel
Cancel txId ->
model ! [ cancel txId ]
HideSaveIndication ->
RemoteData.update (\subModel -> { subModel | status = NotSaving } ! []) model

View file

@ -0,0 +1,21 @@
module Transaction.Types exposing (..)
import RemoteData exposing (..)
import BasicTypes exposing (..)
import Common.TransactionTypes exposing (..)
type alias SubModel =
{ status : SavingStatus
, tx : Tx
}
type alias Model =
RemoteData.WebData SubModel
type Msg
= Load Model
| Cancel String
| HideSaveIndication

View file

@ -0,0 +1,94 @@
module Transaction.View exposing (..)
import Html exposing (..)
import Html.Events exposing (onClick)
import RemoteData exposing (..)
import Common.TransactionTypes exposing (..)
import Transaction.Types exposing (..)
import Numeral exposing (format)
-- import Css.Admin exposing (..)
-- import Css.Classes as C
cashInTxView : CashInTxRec -> Html Msg
cashInTxView tx =
let
cancelStatus =
if tx.operatorCompleted then
"Cancelled"
else if tx.sendConfirmed then
"Sent"
else if tx.expired then
"Expired"
else
"Pending"
cancellable =
not (tx.operatorCompleted || tx.sendConfirmed || tx.expired)
cancelButtonDiv =
if cancellable then
div []
[ button [ onClick (Cancel tx.id) ] [ text "Cancel transaction" ]
]
else
div [] []
error =
Maybe.withDefault "Successful" tx.error
in
div []
[ div [] [ text tx.id ]
, div [] [ text "This is a cash-in transaction" ]
, div [] [ text ("Fiat: " ++ (format "0,0.00" tx.fiat)) ]
, div [] [ text ("Status: " ++ cancelStatus) ]
, div [] [ text error ]
, cancelButtonDiv
]
cashOutTxView : CashOutTxRec -> Html Msg
cashOutTxView tx =
let
error =
case tx.error of
Nothing ->
"No errors"
Just err ->
"Error: " ++ err
in
div []
[ div [] [ text tx.id ]
, div [] [ text "This is a cash-out transaction" ]
, div [] [ text ("Fiat: " ++ (format "0,0.00" tx.fiat)) ]
, div [] [ text error ]
]
txView : SubModel -> Html Msg
txView subModel =
case subModel.tx of
CashInTx cashInTxRec ->
cashInTxView cashInTxRec
CashOutTx cashOutTxRec ->
cashOutTxView cashOutTxRec
view : Model -> Html Msg
view model =
case model of
NotAsked ->
div [] []
Loading ->
div [] [ text "Loading..." ]
Failure err ->
div [] [ text (toString err) ]
Success subModel ->
txView subModel