Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/95 frontend create contract functionality #98

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion app/elm/Commands.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Commands exposing (..)

import Models exposing (Address, Wei, PartyModel, BrehonModel)
import Models exposing (Address, Wei, PartyModel, BrehonModel, ContractCreatorModel)
import Task exposing (perform)
import Time as Time exposing (Time, now)
import Msgs exposing (Msg)
Expand Down Expand Up @@ -86,6 +86,7 @@ raiseAppeal : Address -> Cmd Msg
raiseAppeal addr =
requestRaiseAppeal addr


raiseSecondAppeal : Address -> Cmd Msg
raiseSecondAppeal addr =
requestRaiseSecondAppeal addr
Expand All @@ -97,6 +98,15 @@ adjudicate addr awardPartyA awardPartyB =



{- Contract creator commands -}


createContract : ContractCreatorModel -> Cmd Msg
createContract model =
requestCreateContract model



{- For Debugging purposes -}


Expand Down
29 changes: 11 additions & 18 deletions app/elm/Main.elm
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
port module Main exposing (..)

import Html exposing (Html, div, text, program)
import Msgs exposing (Msg)
import Models exposing (Model, Party, zeroWei, initContractInfo, Brehon, PartyModel, BrehonModel, ContractInfo, Stage(..))
import Models exposing (Model, Party, zeroWei, initContractModel, initContractCreatorModel, Brehon, PartyModel, BrehonModel, ContractInfo, Stage(..))
import Time exposing (every, minute, second)
import View exposing (view)
import Update exposing (update)
import Web3.BrehonAPI exposing (..)
import Commands exposing (..)
import Navigation
import UrlParser as Url
import UrlParsing exposing (..)


-- MODEL


init : ( Model, Cmd Msg )
init =
init : Navigation.Location -> ( Model, Cmd Msg )
init location =
( Model
initContractInfo
0
[]
Nothing
zeroWei
zeroWei
zeroWei
zeroWei
(PartyModel (Party Nothing zeroWei False))
(PartyModel (Party Nothing zeroWei False))
(BrehonModel (Brehon Nothing False zeroWei zeroWei) Nothing)
(BrehonModel (Brehon Nothing False zeroWei zeroWei) Nothing)
(BrehonModel (Brehon Nothing False zeroWei zeroWei) Nothing)
[ Url.parseHash route location ]
(Just Create)
initContractCreatorModel
initContractModel
, Cmd.batch
[ loadWeb3Accounts
, loadContractInfo
Expand Down Expand Up @@ -72,7 +65,7 @@ subscriptions model =

main : Program Never Model Msg
main =
program
Navigation.program Msgs.UrlChange
{ init = init
, view = view
, update = update
Expand Down
52 changes: 52 additions & 0 deletions app/elm/Models.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,69 @@ module Models exposing (..)

import Time.DateTime as DateTime exposing (DateTime, dateTime)
import Time as Time exposing (Time, now)
import UrlParsing exposing (Route)


zeroWei : Wei
zeroWei =
"0"


initContractModel : ContractModel
initContractModel =
ContractModel
initContractInfo
0
[]
Nothing
zeroWei
zeroWei
zeroWei
zeroWei
(PartyModel (Party Nothing zeroWei False))
(PartyModel (Party Nothing zeroWei False))
(BrehonModel (Brehon Nothing False zeroWei zeroWei) Nothing)
(BrehonModel (Brehon Nothing False zeroWei zeroWei) Nothing)
(BrehonModel (Brehon Nothing False zeroWei zeroWei) Nothing)


initContractInfo : ContractInfo
initContractInfo =
ContractInfo Nothing Negotiation zeroWei zeroWei False False Nothing Nothing Nothing 0 False Nothing Nothing


initContractCreatorModel : ContractCreatorModel
initContractCreatorModel =
ContractCreatorModel
(Party (Just "0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1") "0" False)
(Party (Just "0xffcf8fdee72ac11b5c542428b35eef5769c409f0") "0" False)
"500"
"Party A agrees to sell Party B a 1996 Rolex watch for 500 Wei."
(Brehon (Just "0x22d491bde2303f2f43325b2108d26f1eaba1e32b") False "10" "100")
(Brehon (Just "0xe11ba2b4d45eaed5996cd0823791e0c93114882d") False "10" "100")
(Brehon (Just "0xd03ea8624c8c5987235048901fb614fdca89b117") False "10" "100")


type alias Model =
{ history : List (Maybe Route)
, currentRoute : Maybe Route
, creatorModel : ContractCreatorModel
, contractModel : ContractModel
}


type alias ContractCreatorModel =
{ partyA : Party
, partyB : Party
, transactionAmount : Wei
, termsAndConditions : String
, primaryBrehon : Brehon
, secondaryBrehon : Brehon
, tertiaryBrehon : Brehon
}


type alias ContractModel =
{ contractInfo : ContractInfo
, currentTimestamp : Time
, eventLog : List Event
Expand Down Expand Up @@ -124,6 +174,7 @@ type Stage
| SecondAppeal
| Completed


type Event
= ExecutionStartedEvent Int Address Address Wei
| SettlementProposedEvent Int Address Address Wei Wei
Expand All @@ -134,6 +185,7 @@ type Event
| SecondAppealRaisedEvent Address Address
| FundsClaimedEvent Address Wei


type AppealLevel
= First
| Second
20 changes: 19 additions & 1 deletion app/elm/Msgs.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ import Models
, Parties
, Brehons
, Event
, ContractCreatorModel
)
import Navigation


type Msg
= LoadAccounts (List Address)
= UrlChange Navigation.Location
| LoadAccounts (List Address)
| LoadContractInfo ( Address, Int, Wei, Wei, Int, Address, Maybe Awards )
| LoadAllParties Parties
| LoadAllBrehons Brehons
Expand Down Expand Up @@ -47,4 +50,19 @@ type Msg
| RaiseSecondAppeal Address
| Adjudicate BrehonModel
| WithdrawFunds Address
-- ContractCreator Msgs
| PartyAAddrChanged String
| PartyBAddrChanged String
| TxAmountChanged Wei
| TermsChanged String
| PrimaryBrehonAddrChanged String
| PrimaryBrehonFixedFeeChanged Wei
| PrimaryBrehonDisputeFeeChanged Wei
| SecondaryBrehonAddrChanged String
| SecondaryBrehonFixedFeeChanged Wei
| SecondaryBrehonDisputeFeeChanged Wei
| TertiaryBrehonAddrChanged String
| TertiaryBrehonFixedFeeChanged Wei
| TertiaryBrehonDisputeFeeChanged Wei
| CreateContract ContractCreatorModel
| None
Loading