diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index f408ac7..b23f468 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -15,7 +15,9 @@ class Admin::UsersController < Admin::BaseController end def show - @inviter = Invitation.where(invited_user_id: @user.id).first.try(:user) + if Setting.lndhub_admin_enabled? + @lndhub_user = @user.lndhub_user + end end private diff --git a/app/models/lndhub_user.rb b/app/models/lndhub_user.rb index e5645c5..f467089 100644 --- a/app/models/lndhub_user.rb +++ b/app/models/lndhub_user.rb @@ -10,6 +10,18 @@ class LndhubUser < LndhubBase foreign_key: "login" def balance - accounts.current.first.ledgers.sum("account_ledgers.amount") + accounts.current.first.ledgers.sum("account_ledgers.amount").to_i.abs + end + + def sum_outgoing + accounts.outgoing.first.ledgers.sum("account_ledgers.amount").to_i.abs + end + + def sum_incoming + accounts.incoming.first.ledgers.sum("account_ledgers.amount").to_i.abs + end + + def sum_fees + accounts.fees.first.ledgers.sum("account_ledgers.amount").to_i.abs end end diff --git a/app/views/admin/users/show.html.erb b/app/views/admin/users/show.html.erb index 2cc45c7..e4ddd66 100644 --- a/app/views/admin/users/show.html.erb +++ b/app/views/admin/users/show.html.erb @@ -56,7 +56,34 @@ + + <% if Setting.lndhub_admin_enabled? %> +
+

LndHub

+ <% if @lndhub_user %> + + + + + + + + + + + + + + + + + +
AccountBalanceIncomingOutgoingFees
<%= @user.ln_account %><%= number_with_delimiter @lndhub_user.balance %> sats<%= number_with_delimiter @lndhub_user.sum_incoming %> sats<%= number_with_delimiter @lndhub_user.sum_outgoing %> sats<%= number_with_delimiter @lndhub_user.sum_fees %> sats
+ <% else %> +

No LndHub user found for account <%= @user.ln_account %>. + <% end %>

+ <% end %> <% end %>