Show available balance on wallet page
This commit is contained in:
parent
3c350155de
commit
884070a3cb
@ -1,2 +1,3 @@
|
||||
EJABBERD_API_URL='https://xmpp.kosmos.org/api'
|
||||
LNDHUB_API_URL='http://10.1.1.163:3023'
|
||||
LNDHUB_PUBLIC_URL='https://lndhub.kosmos.org'
|
||||
|
@ -2,11 +2,12 @@ require "rqrcode"
|
||||
|
||||
class WalletController < ApplicationController
|
||||
before_action :require_user_signed_in
|
||||
before_action :authenticate_with_lndhub
|
||||
|
||||
def index
|
||||
@current_section = :wallet
|
||||
|
||||
@wallet_url = "lndhub://#{current_user.ln_login}:#{current_user.ln_password}@https://lndhub.kosmos.org"
|
||||
@wallet_url = "lndhub://#{current_user.ln_login}:#{current_user.ln_password}@#{ENV['LNDHUB_PUBLIC_URL']}"
|
||||
|
||||
qrcode = RQRCode::QRCode.new(@wallet_url)
|
||||
@svg = qrcode.as_svg(
|
||||
@ -16,6 +17,37 @@ class WalletController < ApplicationController
|
||||
standalone: true,
|
||||
use_path: true
|
||||
)
|
||||
|
||||
@balance = fetch_balance rescue nil
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def authenticate_with_lndhub
|
||||
if session["ln_auth_token"].present?
|
||||
@ln_auth_token = session["ln_auth_token"]
|
||||
else
|
||||
res = Faraday.post("#{ENV["LNDHUB_API_URL"]}/auth?type=auth",
|
||||
{ login: current_user.ln_login, password: current_user.ln_password }.to_json,
|
||||
"Content-Type" => "application/json",
|
||||
"Accept" => "application/json")
|
||||
|
||||
credentials = JSON.parse(res.body)
|
||||
session["ln_auth_token"] = credentials["access_token"]
|
||||
@ln_auth_token = credentials["access_token"]
|
||||
end
|
||||
rescue
|
||||
# TODO add exception tracking
|
||||
end
|
||||
|
||||
def fetch_balance
|
||||
res = Faraday.get("#{ENV["LNDHUB_API_URL"]}/balance", {}, {
|
||||
"Content-Type" => "application/json",
|
||||
"Accept" => "application/json",
|
||||
"Authorization" => "Bearer #{@ln_auth_token}"
|
||||
})
|
||||
|
||||
data = JSON.parse(res.body)
|
||||
data["BTC"]["AvailableBalance"]
|
||||
end
|
||||
end
|
||||
|
@ -1,14 +1,20 @@
|
||||
<section>
|
||||
<section class="w-full grid grid-cols-1 md:grid-cols-2">
|
||||
<div>
|
||||
<h2>Wallet</h2>
|
||||
<p>
|
||||
Send and receive BTC via the Lightning Network.
|
||||
</p>
|
||||
</div>
|
||||
<p class="font-mono mt-4 md:text-right md:mt-0">
|
||||
<% if @balance %>
|
||||
<span class="text-xl"><%= @balance %> sats</span><br>
|
||||
<span class="text-sm text-gray-500">Available balance</span>
|
||||
<% end %>
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h3>
|
||||
Blue Wallet
|
||||
</h3>
|
||||
<h3>Blue Wallet</h3>
|
||||
<p>
|
||||
You can connect
|
||||
<%= link_to "Blue Wallet", "https://bluewallet.io",
|
||||
|
Loading…
x
Reference in New Issue
Block a user