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'
|
EJABBERD_API_URL='https://xmpp.kosmos.org/api'
|
||||||
LNDHUB_API_URL='http://10.1.1.163:3023'
|
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
|
class WalletController < ApplicationController
|
||||||
before_action :require_user_signed_in
|
before_action :require_user_signed_in
|
||||||
|
before_action :authenticate_with_lndhub
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@current_section = :wallet
|
@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)
|
qrcode = RQRCode::QRCode.new(@wallet_url)
|
||||||
@svg = qrcode.as_svg(
|
@svg = qrcode.as_svg(
|
||||||
@ -16,6 +17,37 @@ class WalletController < ApplicationController
|
|||||||
standalone: true,
|
standalone: true,
|
||||||
use_path: true
|
use_path: true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@balance = fetch_balance rescue nil
|
||||||
end
|
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
|
end
|
||||||
|
@ -1,14 +1,20 @@
|
|||||||
<section>
|
<section class="w-full grid grid-cols-1 md:grid-cols-2">
|
||||||
<h2>Wallet</h2>
|
<div>
|
||||||
<p>
|
<h2>Wallet</h2>
|
||||||
Send and receive BTC via the Lightning Network.
|
<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>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<h3>
|
<h3>Blue Wallet</h3>
|
||||||
Blue Wallet
|
|
||||||
</h3>
|
|
||||||
<p>
|
<p>
|
||||||
You can connect
|
You can connect
|
||||||
<%= link_to "Blue Wallet", "https://bluewallet.io",
|
<%= link_to "Blue Wallet", "https://bluewallet.io",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user