Skip to content

Commit

Permalink
Merge pull request #29 from avolabs-io/wyn1
Browse files Browse the repository at this point in the history
  • Loading branch information
JasoonS authored Mar 7, 2021
2 parents 3fa70a6 + 2df1e2d commit f460b35
Show file tree
Hide file tree
Showing 7 changed files with 979 additions and 314 deletions.
155 changes: 155 additions & 0 deletions backend/hasura-actions/src/PaymentStreamManager.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 87 additions & 0 deletions backend/hasura-actions/src/PaymentStreamManager.res
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,90 @@ let createStream = Serbet.endpoint({
)
}),
})

let addPaymentEntry = (~streamID, ~timestamp, ~amount) => {
gqlClient.mutate(
~mutation=module(Query.AddPaymentEntry),
Query.AddPaymentEntry.makeVariables(
~streamID,
~paymentTimestamp=timestamp,
~paymentState="PENDING",
~paymentAmount=amount,
(),
),
)
->JsPromise.map(result =>
switch result {
| Ok({data}) => Js.log2("success payment added", data.insert_payments_one)
| Error(error) => Js.log2("error payment added: ", error)
}
)
->ignore
}

let updatePaymentEntry = (~paymentID, ~state) => {
gqlClient.mutate(
~mutation=module(Query.UpdatePaymentEntry),
Query.UpdatePaymentEntry.makeVariables(~paymentID, ~paymentState=state, ()),
)
->JsPromise.map(result =>
switch result {
| Ok(_result) => Js.log2("success update payment: ", state)
| Error(error) => Js.log3("error update payment: ", state, error)
}
)
->ignore
}

let updateStreamEntry = (~streamID, ~totalPaymentsMade, ~nextPayment, ~lastPayment) => {
gqlClient.mutate(
~mutation=module(Query.UpdateStreamEntry),
Query.UpdateStreamEntry.makeVariables(
~id=streamID,
~paymentsMade=totalPaymentsMade,
~nextPayment,
~lastPayment,
(),
),
)
->JsPromise.map(result =>
switch result {
| Ok(_result) => Js.log3("success payment made: ", totalPaymentsMade, nextPayment)
| Error(error) => Js.log2("error payment made: ", error)
}
)
->ignore
}

let closeStreamEntry = (~streamID, ~totalPaymentsMade) => {
gqlClient.mutate(
~mutation=module(Query.CloseStreamEntry),
Query.CloseStreamEntry.makeVariables(
~id=streamID,
~paymentsMade=totalPaymentsMade,
~state="CLOSED",
(),
),
)
->JsPromise.map(result =>
switch result {
| Ok(_result) => Js.log("success close entry: CLOSED")
| Error(error) => Js.log2("error close entry: ", error)
}
)
->ignore
}

let addUser = (~username, ~ethAddress, ~description) => {
gqlClient.mutate(
~mutation=module(Query.AddUser),
Query.AddUser.makeVariables(~name=username, ~address=ethAddress, ~description, ()),
)
->JsPromise.map(result =>
switch result {
| Ok(_result) => Js.log("success user added")
| Error(error) => Js.log2("error user added: ", error)
}
)
->ignore
}
Loading

0 comments on commit f460b35

Please sign in to comment.