Add notification mailer, make wallet notifications configurable
This commit is contained in:
@@ -12,22 +12,28 @@ class WebhooksController < ApplicationController
|
||||
end
|
||||
|
||||
user = User.find_by!(ln_account: payload[:user_login])
|
||||
|
||||
# TODO make configurable
|
||||
notify_xmpp(user.address, payload[:amount], payload[:memo])
|
||||
notify = user.preferences.dig("lightning", "notify_sats_received")
|
||||
case notify
|
||||
when "xmpp"
|
||||
notify_xmpp(user.address, payload[:amount], payload[:memo])
|
||||
when "email"
|
||||
NotificationMailer.with(user: user, amount_sats: payload[:amount])
|
||||
.lightning_sats_received.deliver_later
|
||||
end
|
||||
|
||||
head :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# TODO refactor into mailer-like generic class/service
|
||||
def notify_xmpp(address, amt_sats, memo)
|
||||
payload = {
|
||||
type: "normal",
|
||||
from: "kosmos.org", # TODO domain config
|
||||
to: address,
|
||||
subject: "Sats received!",
|
||||
body: "#{amt_sats} sats received in your Lightning wallet:\n> #{memo}"
|
||||
body: "#{helpers.number_with_delimiter amt_sats} sats received in your Lightning wallet:\n> #{memo}"
|
||||
}
|
||||
XmppSendMessageJob.perform_later(payload)
|
||||
end
|
||||
|
||||
8
app/mailers/notification_mailer.rb
Normal file
8
app/mailers/notification_mailer.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class NotificationMailer < ApplicationMailer
|
||||
def lightning_sats_received
|
||||
@user = params[:user]
|
||||
@amount_sats = params[:amount_sats]
|
||||
@subject = "Sats received"
|
||||
mail to: @user.email, subject: @subject
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
You just received <%= number_with_delimiter @amount_sats %> sats in your Lightning account (<%= @user.address %>). Check your wallet app, or open the account page for details:
|
||||
|
||||
<%= wallet_transactions_url %>
|
||||
Reference in New Issue
Block a user