BTCPay settings, admin page, and new Lightning balance API #147

Merged
raucao merged 12 commits from feature/btcpay_configs into master 2023-09-26 10:13:09 +00:00
3 changed files with 6 additions and 4 deletions
Showing only changes of commit 1949f1876f - Show all commits

View File

@ -1,7 +1,7 @@
module BtcpayManager
class FetchLightningWalletBalance < BtcpayManagerService
def call
res = get "stores/#{@store_id}/lightning/BTC/balance"
res = get "stores/#{store_id}/lightning/BTC/balance"
{
balance: res["offchain"]["local"].to_i / 1000 # msats to sats

View File

@ -1,7 +1,7 @@
module BtcpayManager
class FetchOnchainWalletBalance < BtcpayManagerService
def call
res = get "stores/#{@store_id}/payment-methods/onchain/BTC/wallet"
res = get "stores/#{store_id}/payment-methods/onchain/BTC/wallet"
{
balance: (res["balance"].to_f * 100000000).to_i, # BTC to sats

View File

@ -2,6 +2,8 @@
# API Docs: https://docs.btcpayserver.org/API/Greenfield/v1/
#
class BtcpayManagerService < ApplicationService
raucao marked this conversation as resolved Outdated

< LdapService

Oops.

> < LdapService Oops.
attr_reader :base_url, :store_id, :auth_token
def initialize
@base_url = Setting.btcpay_api_url
raucao marked this conversation as resolved
Review

I'd use attr_readers here then it is a bit clearer that those are also potentially used from the outside/from inheriting classes

I'd use attr_readers here then it is a bit clearer that those are also potentially used from the outside/from inheriting classes
@store_id = Setting.btcpay_store_id
@ -11,10 +13,10 @@ class BtcpayManagerService < ApplicationService
private
def get(endpoint)
res = Faraday.get("#{@base_url}/#{endpoint}", {}, {
res = Faraday.get("#{base_url}/#{endpoint}", {}, {
"Content-Type" => "application/json",
"Accept" => "application/json",
"Authorization" => "token #{@auth_token}"
"Authorization" => "token #{auth_token}"
})
JSON.parse(res.body)