diff --git a/app/controllers/wallet_controller.rb b/app/controllers/wallet_controller.rb index 466e782..4990894 100644 --- a/app/controllers/wallet_controller.rb +++ b/app/controllers/wallet_controller.rb @@ -23,7 +23,7 @@ class WalletController < ApplicationController end def transactions - + @transactions = fetch_transactions end private @@ -41,13 +41,41 @@ class WalletController < ApplicationController # TODO add exception tracking end + def set_current_section + @current_section = :wallet + end + def fetch_balance lndhub = Lndhub.new data = lndhub.balance @ln_auth_token @balance = data["BTC"]["AvailableBalance"] rescue nil end - def set_current_section - @current_section = :wallet + def fetch_transactions + lndhub = Lndhub.new + txs = lndhub.gettxs @ln_auth_token + invoices = lndhub.getuserinvoices(@ln_auth_token).select{|i| i["ispaid"]} + + process_transactions(txs + invoices) + end + + def process_transactions(txs) + txs.collect do |tx| + if tx["type"] == "bitcoind_tx" + tx["amount_sats"] = (tx["amount"] * 100000000).to_i + tx["datetime"] = Time.at(tx["time"].to_i) + tx["title"] = "Received" + tx["description"] = "On-chain topup" + tx["received"] = true + else + tx["amount_sats"] = tx["value"] || tx["amt"] + tx["datetime"] = Time.at(tx["timestamp"].to_i) + tx["title"] = tx["type"] == "paid_invoice" ? "Sent" : "Received" + tx["description"] = tx["memo"] || tx["description"] + tx["received"] = tx["type"] == "user_invoice" + end + end + + txs.sort{ |a,b| b["datetime"] <=> a["datetime"] } end end diff --git a/app/services/lndhub.rb b/app/services/lndhub.rb index 01f7abf..bd3670a 100644 --- a/app/services/lndhub.rb +++ b/app/services/lndhub.rb @@ -46,6 +46,14 @@ class Lndhub get "balance", user_token || auth_token end + def gettxs(user_token) + get "gettxs", user_token || auth_token + end + + def getuserinvoices(user_token) + get "getuserinvoices", user_token || auth_token + end + def addinvoice(payload) invoice = post "addinvoice", { amt: payload[:amount], diff --git a/app/views/icons/_link-2.html.erb b/app/views/icons/_link-2.html.erb index 8cc7f6d..4bfc68c 100644 --- a/app/views/icons/_link-2.html.erb +++ b/app/views/icons/_link-2.html.erb @@ -1 +1 @@ - \ No newline at end of file + diff --git a/app/views/icons/_link.html.erb b/app/views/icons/_link.html.erb index c89dd41..965e681 100644 --- a/app/views/icons/_link.html.erb +++ b/app/views/icons/_link.html.erb @@ -1 +1 @@ - \ No newline at end of file + diff --git a/app/views/icons/_zap.html.erb b/app/views/icons/_zap.html.erb index 8fdafa9..f809708 100644 --- a/app/views/icons/_zap.html.erb +++ b/app/views/icons/_zap.html.erb @@ -1 +1 @@ - \ No newline at end of file + diff --git a/app/views/wallet/transactions.html.erb b/app/views/wallet/transactions.html.erb index 184a3a4..b1abc40 100644 --- a/app/views/wallet/transactions.html.erb +++ b/app/views/wallet/transactions.html.erb @@ -4,8 +4,45 @@ <%= render WalletSummaryComponent.new(balance: @balance) %>
-

Transactions

+ -

Foo

+ <% if @transactions.any? %> + + <% else %> +

+ No transactions to show. +

+ <% end %>
<% end %>