Skip to content

Commit

Permalink
Change the way the total balance is calculated
Browse files Browse the repository at this point in the history
Instead of attempting to show an "how much you can spend" metric,
we're now showing a simpler "how much you have" metric instead.

- The balance now includes the on-chain balance (sum of utxos).

- It also includes funds held in channels with disconnected peers.

- It uses the total "msatoshi_to_us" instead of "spendable_msatoshi",
  which includes the channel reserve.

For more on the rational behind this changes, see:
#62 (comment)
  • Loading branch information
shesek committed Feb 25, 2019
1 parent b4febfb commit 9b500c4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions client/src/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { dbg, getChannels, formatAmt, recvAmt, combine, isConnError } from './ut
const msatbtc = big(100000000000) // msat in 1 btc

const
sumChans = chans => chans.filter(c => c.peer.connected && c.chan.state === 'CHANNELD_NORMAL')
.reduce((T, c) => T + Math.max(0, c.chan.spendable_msatoshi), 0)
sumChans = chans => chans.filter(c => c.chan.state === 'CHANNELD_NORMAL')
.reduce((T, c) => T + Math.max(0, c.chan.msatoshi_to_us), 0)

, fmtAlert = (s, unitf) => s.replace(/@\{\{(\d+)\}\}/g, (_, msat) => unitf(msat))

Expand Down Expand Up @@ -77,6 +77,7 @@ module.exports = ({ dismiss$, togExp$, togTheme$, togUnit$, page$, goHome$, goRe
.startWith(null)

// On-chain balance
// TODO: patch with known outgoing payments
, obalance$ = funds$.map(funds => funds.outputs.reduce((T, o) => T+o.value*1000, 0))
.distinctUntilChanged()

Expand Down
4 changes: 2 additions & 2 deletions client/src/views/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const layout = ({ state: S, body }) =>
, S.info ? footer(S) : ''
])

const navbar = ({ unitf, cbalance, page }) =>
const navbar = ({ unitf, cbalance, obalance, page }) =>
nav(`.navbar.navbar-dark.bg-primary.mb-3`, div('.container', [
a('.navbar-brand', { attrs: { href: '#/' } }, [
page.pathname != '/' ? span('.icon.icon-left-open') : ''
, 'Spark'
])
, cbalance != null ? span('.toggle-unit.navbar-brand.mr-0', unitf(cbalance)) : ''
, cbalance != null && obalance != null ? span('.toggle-unit.navbar-brand.mr-0', unitf(cbalance + obalance)) : ''
]))

const footer = ({ info, btcusd, msatusd, rate, conf: { unit, theme, expert } }) =>
Expand Down

0 comments on commit 9b500c4

Please sign in to comment.