WIP Add wallet transactions route, view
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Adds a new component for the wallet summary as well, and makes the component tests work with RSpec.
This commit is contained in:
parent
10f179a095
commit
cf62bfc5c2
18
app/components/wallet_summary_component.html.erb
Normal file
18
app/components/wallet_summary_component.html.erb
Normal file
@ -0,0 +1,18 @@
|
||||
<section class="w-full grid grid-cols-1 md:grid-cols-12 md:mb-0">
|
||||
<div class="md:col-span-8">
|
||||
<p>
|
||||
Send and receive sats via the Bitcoin Lightning Network.
|
||||
</p>
|
||||
</div>
|
||||
<div class="md:col-span-4 mt-4 md:mt-0">
|
||||
<p class="font-mono md:text-right mb-0 p-4 border border-gray-300 rounded-lg overflow-hidden">
|
||||
<% if @balance %>
|
||||
<span class="text-xl"><%= number_with_delimiter @balance %> sats</span><br>
|
||||
<span class="text-sm text-gray-500">Available balance</span>
|
||||
<% else %>
|
||||
<span class="text-xl">n/a sats</span><br>
|
||||
<span class="text-sm text-gray-500">Balance unavailable</span>
|
||||
<% end %>
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
8
app/components/wallet_summary_component.rb
Normal file
8
app/components/wallet_summary_component.rb
Normal file
@ -0,0 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class WalletSummaryComponent < ViewComponent::Base
|
||||
def initialize(balance:)
|
||||
@balance = balance
|
||||
end
|
||||
|
||||
end
|
@ -3,10 +3,10 @@ require "rqrcode"
|
||||
class WalletController < ApplicationController
|
||||
before_action :require_user_signed_in
|
||||
before_action :authenticate_with_lndhub
|
||||
before_action :set_current_section
|
||||
before_action :fetch_balance
|
||||
|
||||
def index
|
||||
@current_section = :wallet
|
||||
|
||||
@wallet_url = "lndhub://#{current_user.ln_login}:#{current_user.ln_password}@#{ENV['LNDHUB_PUBLIC_URL']}"
|
||||
|
||||
qrcode = RQRCode::QRCode.new(@wallet_url)
|
||||
@ -20,8 +20,10 @@ class WalletController < ApplicationController
|
||||
class: 'inline-block'
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
def transactions
|
||||
|
||||
@balance = fetch_balance rescue nil
|
||||
end
|
||||
|
||||
private
|
||||
@ -42,6 +44,10 @@ class WalletController < ApplicationController
|
||||
def fetch_balance
|
||||
lndhub = Lndhub.new
|
||||
data = lndhub.balance @ln_auth_token
|
||||
data["BTC"]["AvailableBalance"]
|
||||
@balance = data["BTC"]["AvailableBalance"] rescue nil
|
||||
end
|
||||
|
||||
def set_current_section
|
||||
@current_section = :wallet
|
||||
end
|
||||
end
|
||||
|
@ -1,24 +1,7 @@
|
||||
<%= render HeaderComponent.new(title: "Wallet") %>
|
||||
|
||||
<%= render MainSimpleComponent.new do %>
|
||||
<section class="w-full grid grid-cols-1 md:grid-cols-12 md:mb-0">
|
||||
<div class="md:col-span-8">
|
||||
<p>
|
||||
Send and receive sats via the Bitcoin Lightning Network.
|
||||
</p>
|
||||
</div>
|
||||
<div class="md:col-span-4 mt-4 md:mt-0">
|
||||
<p class="font-mono md:text-right mb-0 p-4 border border-gray-300 rounded-lg overflow-hidden">
|
||||
<% if @balance %>
|
||||
<span class="text-xl"><%= number_with_delimiter @balance %> sats</span><br>
|
||||
<span class="text-sm text-gray-500">Available balance</span>
|
||||
<% else %>
|
||||
<span class="text-xl">n/a sats</span><br>
|
||||
<span class="text-sm text-gray-500">Balance unavailable</span>
|
||||
<% end %>
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
<%= render WalletSummaryComponent.new(balance: @balance) %>
|
||||
|
||||
<section>
|
||||
<h3>Lightning Address</h3>
|
||||
|
11
app/views/wallet/transactions.html.erb
Normal file
11
app/views/wallet/transactions.html.erb
Normal file
@ -0,0 +1,11 @@
|
||||
<%= render HeaderComponent.new(title: "Wallet") %>
|
||||
|
||||
<%= render MainSimpleComponent.new do %>
|
||||
<%= render WalletSummaryComponent.new(balance: @balance) %>
|
||||
|
||||
<section>
|
||||
<h3>Transactions</h3>
|
||||
|
||||
<p>Foo</p>
|
||||
</section>
|
||||
<% end %>
|
@ -20,6 +20,7 @@ Rails.application.routes.draw do
|
||||
resources :donations
|
||||
|
||||
get 'wallet', to: 'wallet#index'
|
||||
get 'wallet/transactions', to: 'wallet#transactions'
|
||||
|
||||
get 'lnurlpay/:address', to: 'lnurlpay#index', constraints: { address: /[^\/]+/}
|
||||
get 'lnurlpay/:address/invoice', to: 'lnurlpay#invoice', constraints: { address: /[^\/]+/}
|
||||
|
11
spec/components/wallet_summary_component_spec.rb
Normal file
11
spec/components/wallet_summary_component_spec.rb
Normal file
@ -0,0 +1,11 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe WalletSummaryComponent, type: :component do
|
||||
it "renders the balance as a human-readable number" do
|
||||
expect(
|
||||
render_inline(described_class.new(balance: 2301000)) {}.css("section").to_html
|
||||
).to include(
|
||||
"2,301,000 sats"
|
||||
)
|
||||
end
|
||||
end
|
@ -10,6 +10,8 @@ require 'capybara'
|
||||
require 'devise'
|
||||
require 'support/controller_macros'
|
||||
require 'support/database_cleaner'
|
||||
require "view_component/test_helpers"
|
||||
require "capybara/rspec"
|
||||
|
||||
# Requires supporting ruby files with custom matchers and macros, etc, in
|
||||
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
||||
@ -70,5 +72,8 @@ RSpec.configure do |config|
|
||||
config.include Warden::Test::Helpers
|
||||
config.include FactoryBot::Syntax::Methods
|
||||
config.include ActiveJob::TestHelper, type: :job
|
||||
config.include ViewComponent::TestHelpers, type: :component
|
||||
config.include Capybara::RSpecMatchers, type: :component
|
||||
|
||||
config.extend ControllerMacros, :type => :controller
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user