Add wallet transactions
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
cf62bfc5c2
commit
78c243c985
@ -23,7 +23,7 @@ class WalletController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def transactions
|
def transactions
|
||||||
|
@transactions = fetch_transactions
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -41,13 +41,41 @@ class WalletController < ApplicationController
|
|||||||
# TODO add exception tracking
|
# TODO add exception tracking
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_current_section
|
||||||
|
@current_section = :wallet
|
||||||
|
end
|
||||||
|
|
||||||
def fetch_balance
|
def fetch_balance
|
||||||
lndhub = Lndhub.new
|
lndhub = Lndhub.new
|
||||||
data = lndhub.balance @ln_auth_token
|
data = lndhub.balance @ln_auth_token
|
||||||
@balance = data["BTC"]["AvailableBalance"] rescue nil
|
@balance = data["BTC"]["AvailableBalance"] rescue nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_current_section
|
def fetch_transactions
|
||||||
@current_section = :wallet
|
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
|
||||||
end
|
end
|
||||||
|
@ -46,6 +46,14 @@ class Lndhub
|
|||||||
get "balance", user_token || auth_token
|
get "balance", user_token || auth_token
|
||||||
end
|
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)
|
def addinvoice(payload)
|
||||||
invoice = post "addinvoice", {
|
invoice = post "addinvoice", {
|
||||||
amt: payload[:amount],
|
amt: payload[:amount],
|
||||||
|
@ -1 +1 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link-2"><path d="M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3"></path><line x1="8" y1="12" x2="16" y2="12"></line></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link-2 <%= custom_class %>"><path d="M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3"></path><line x1="8" y1="12" x2="16" y2="12"></line></svg>
|
||||||
|
Before Width: | Height: | Size: 355 B After Width: | Height: | Size: 376 B |
@ -1 +1 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link <%= custom_class %>"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>
|
||||||
|
Before Width: | Height: | Size: 371 B After Width: | Height: | Size: 392 B |
@ -1 +1 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-zap"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"></polygon></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-zap <%= custom_class %>"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"></polygon></svg>
|
||||||
|
Before Width: | Height: | Size: 282 B After Width: | Height: | Size: 303 B |
@ -4,8 +4,45 @@
|
|||||||
<%= render WalletSummaryComponent.new(balance: @balance) %>
|
<%= render WalletSummaryComponent.new(balance: @balance) %>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<h3>Transactions</h3>
|
<h3 class="hidden">Transactions</h3>
|
||||||
|
|
||||||
<p>Foo</p>
|
<% if @transactions.any? %>
|
||||||
|
<ul class="list-none">
|
||||||
|
<% @transactions.each do |tx| %>
|
||||||
|
<li class="py-4 md:py-4 grid gap-y-1 gap-x-2 grid-cols-4 border-b border-dotted border-gray-300">
|
||||||
|
<h3 class="col-span-2 md:col-span-3 mb-0">
|
||||||
|
<% if tx["type"] == "bitcoind_tx" %>
|
||||||
|
<span class="inline-block">
|
||||||
|
<%= render partial: "icons/link-2", locals: { custom_class: "text-emerald-500 h-4 w-4 mr-0.5" } %>
|
||||||
|
</span>
|
||||||
|
<% else %>
|
||||||
|
<span class="inline-block">
|
||||||
|
<%= render partial: "icons/zap", locals: { custom_class: "text-amber-500 h-4 w-4 mr-0.5" } %>
|
||||||
|
</span>
|
||||||
|
<% end %>
|
||||||
|
<%= tx["title"] %>
|
||||||
|
</h3>
|
||||||
|
<p class="col-span-2 md:col-span-1 mb-0 text-right">
|
||||||
|
<span class="text-xl font-mono <%= tx["received"] ? "text-emerald-600" : "" %>">
|
||||||
|
<%= tx["received"] ? "+" : "" %><%= number_with_delimiter tx["amount_sats"] %>
|
||||||
|
<span class="hidden md:inline">sats</span>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
<p class="col-span-4 md:col-span-3 mb-0 text-gray-500">
|
||||||
|
<%= tx["description"].present? ? tx["description"] : raw("<span class='text-gray-400'>No memo</span>") %>
|
||||||
|
</p>
|
||||||
|
<p class="col-span-4 md:col-span-1 md:text-right mb-0">
|
||||||
|
<span class="col-span-2 md:col-span-1 text-sm text-gray-500">
|
||||||
|
<%= tx["datetime"].strftime("%B %e, %H:%M") %>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
<% else %>
|
||||||
|
<p class="text-gray-500">
|
||||||
|
No transactions to show.
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
</section>
|
</section>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user