1
0
Fork 0
mirror of https://github.com/ACINQ/eclair.git synced 2025-02-23 14:40:34 +01:00

Display a system notification when payment sent

* send payment handler can now handle the success/failure
* paymentlifecycle send failure reason in WAITING_FOR_PAYMENT_COMPLETE
This commit is contained in:
dpad85 2017-02-08 18:31:46 +01:00
parent 54d43f03c0
commit f1227f25a9
2 changed files with 20 additions and 23 deletions

View file

@ -4,7 +4,7 @@ package fr.acinq.eclair.gui
import java.awt.TrayIcon.MessageType
import java.awt.{SystemTray, TrayIcon}
import java.io.{File, FileWriter}
import java.time.{LocalDate, LocalDateTime}
import java.time.LocalDateTime
import java.time.format.{DateTimeFormatter, FormatStyle}
import javafx.application.Platform
import javafx.scene.control.TextArea
@ -37,37 +37,30 @@ class Handlers(setup: Setup, trayIcon: TrayIcon) extends Logging {
def send(nodeId: String, rhash: String, amountMsat: String) = {
logger.info(s"sending $amountMsat to $rhash @ $nodeId")
paymentInitiator ! CreatePayment(amountMsat.toLong, BinaryData(rhash), BinaryData(nodeId))
(paymentInitiator ? CreatePayment(amountMsat.toLong, BinaryData(rhash), BinaryData(nodeId))).mapTo[String].onComplete {
case Success(s) =>
val now = LocalDateTime.now.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT,FormatStyle.SHORT))
val message = s"Date: $now\nAmount (mSat): $amountMsat\nH: $rhash"
notification("Payment Successful", message, TrayIcon.MessageType.INFO)
case Failure(t) =>
val now = LocalDateTime.now.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT,FormatStyle.SHORT))
val message = s"Date: $now\nCause: ${t.getMessage}\nAmount (mSat): $amountMsat\nH: $rhash"
notification("Payment Failed", message, TrayIcon.MessageType.WARNING)
}
}
def getH(textField: TextField): Unit = {
import akka.pattern.ask
def getPaymentRequest(amountMsat: Long, textField: TextArea) = {
(paymentHandler ? 'genh).mapTo[BinaryData].map { h =>
Platform.runLater(new Runnable() {
override def run(): Unit = {
textField.setText(h.toString())
}
override def run = textField.setText(s"${Globals.Node.id}:$amountMsat:${h.toString()}")
})
}
}
def getPaymentRequest(amountMsat: Long, textField: TextArea): Unit = {
import akka.pattern.ask
(paymentHandler ? 'genh).mapTo[BinaryData].map { h =>
Platform.runLater(new Runnable() {
override def run(): Unit = {
textField.setText(s"${Globals.Node.id}:$amountMsat:${h.toString()}")
}
})
}
}
def exportToDot(file: File) = (router ? 'dot).mapTo[String].map(
dot => printToFile(file)(writer => writer.write(dot)))
def exportToDot(file: File): Unit = {
import akka.pattern.ask
(router ? 'dot).mapTo[String].map(dot => printToFile(file)(writer => writer.write(dot)))
}
def printToFile(f: java.io.File)(op: java.io.FileWriter => Unit) {
private def printToFile(f: java.io.File)(op: java.io.FileWriter => Unit) {
val p = new FileWriter(f)
try {
op(p)

View file

@ -62,6 +62,10 @@ class PaymentLifecycle(sourceNodeId: BinaryData, router: ActorRef, currentBlockC
s ! "sent"
stop(FSM.Normal)
case Event(reason: String, WaitingForComplete(s, _)) =>
s ! Status.Failure(new RuntimeException(reason))
stop(FSM.Failure(reason))
case Event(e@PaymentFailed(_, h, reason), WaitingForComplete(s, cmd)) if h == cmd.paymentHash =>
s ! Status.Failure(new RuntimeException(reason))
stop(FSM.Failure(reason))