Browse Source

lnworker: rename can_send to num_sats_can_send

hard-fail-on-bad-server-string
SomberNight 5 years ago
parent
commit
79d202485e
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 2
      electrum/gui/kivy/uix/dialogs/invoice_dialog.py
  2. 13
      electrum/gui/kivy/uix/dialogs/lightning_channels.py
  3. 9
      electrum/gui/kivy/uix/dialogs/request_dialog.py
  4. 7
      electrum/gui/qt/channels_list.py
  5. 6
      electrum/lnworker.py

2
electrum/gui/kivy/uix/dialogs/invoice_dialog.py

@ -105,7 +105,7 @@ class InvoiceDialog(Factory.Popup):
self.status_color = pr_color[self.status]
self.can_pay = self.status in [PR_UNPAID, PR_FAILED]
if self.can_pay and self.is_lightning and self.app.wallet.lnworker:
if self.amount and self.amount > self.app.wallet.lnworker.can_send():
if self.amount and self.amount > self.app.wallet.lnworker.num_sats_can_send():
self.warning = _('Warning') + ': ' + _('This amount exceeds the maximum you can currently send with your channels')
def on_dismiss(self):

13
electrum/gui/kivy/uix/dialogs/lightning_channels.py

@ -1,14 +1,21 @@
import asyncio
import binascii
from typing import TYPE_CHECKING
from kivy.lang import Builder
from kivy.factory import Factory
from kivy.uix.popup import Popup
from kivy.clock import Clock
from electrum.util import bh2u
from electrum.lnutil import LOCAL, REMOTE, format_short_channel_id
from electrum.gui.kivy.i18n import _
from .question import Question
if TYPE_CHECKING:
from ...main_window import ElectrumWindow
Builder.load_string(r'''
<LightningChannelItem@CardItem>
details: {}
@ -267,7 +274,7 @@ class ChannelDetailsPopup(Popup):
class LightningChannelsDialog(Factory.Popup):
def __init__(self, app):
def __init__(self, app: 'ElectrumWindow'):
super(LightningChannelsDialog, self).__init__()
self.clocks = []
self.app = app
@ -321,5 +328,5 @@ class LightningChannelsDialog(Factory.Popup):
def update_can_send(self):
lnworker = self.app.wallet.lnworker
self.can_send = self.app.format_amount_and_units(lnworker.can_send())
self.can_receive = self.app.format_amount_and_units(lnworker.can_receive())
self.can_send = self.app.format_amount_and_units(lnworker.num_sats_can_send())
self.can_receive = self.app.format_amount_and_units(lnworker.num_sats_can_receive())

9
electrum/gui/kivy/uix/dialogs/request_dialog.py

@ -1,3 +1,5 @@
from typing import TYPE_CHECKING
from kivy.factory import Factory
from kivy.lang import Builder
from kivy.core.clipboard import Clipboard
@ -8,6 +10,9 @@ from electrum.gui.kivy.i18n import _
from electrum.util import pr_tooltips, pr_color, get_request_status
from electrum.util import PR_UNKNOWN, PR_UNPAID, PR_FAILED, PR_TYPE_LN
if TYPE_CHECKING:
from ...main_window import ElectrumWindow
Builder.load_string('''
<RequestDialog@Popup>
@ -84,7 +89,7 @@ class RequestDialog(Factory.Popup):
def __init__(self, title, data, key, *, is_lightning=False):
self.status = PR_UNKNOWN
Factory.Popup.__init__(self)
self.app = App.get_running_app()
self.app = App.get_running_app() # type: ElectrumWindow
self.title = title
self.data = data
self.key = key
@ -107,7 +112,7 @@ class RequestDialog(Factory.Popup):
self.status, self.status_str = get_request_status(req)
self.status_color = pr_color[self.status]
if self.status == PR_UNPAID and self.is_lightning and self.app.wallet.lnworker:
if self.amount and self.amount > self.app.wallet.lnworker.can_receive():
if self.amount and self.amount > self.app.wallet.lnworker.num_sats_can_receive():
self.warning = _('Warning') + ': ' + _('This amount exceeds the maximum you can currently receive with your channels')
def on_dismiss(self):

7
electrum/gui/qt/channels_list.py

@ -14,6 +14,7 @@ from electrum.i18n import _
from electrum.lnchannel import Channel, peer_states
from electrum.wallet import Abstract_Wallet
from electrum.lnutil import LOCAL, REMOTE, format_short_channel_id, LN_MAX_FUNDING_SAT
from electrum.lnworker import LNWallet
from .util import (MyTreeView, WindowModalDialog, Buttons, OkButton, CancelButton,
EnterButton, WaitingDialog, MONOSPACE_FONT, ColorScheme)
@ -224,10 +225,10 @@ class ChannelsList(MyTreeView):
item.setBackground(self._default_item_bg_brush)
item.setToolTip("")
def update_can_send(self, lnworker):
msg = _('Can send') + ' ' + self.parent.format_amount(lnworker.can_send())\
def update_can_send(self, lnworker: LNWallet):
msg = _('Can send') + ' ' + self.parent.format_amount(lnworker.num_sats_can_send())\
+ ' ' + self.parent.base_unit() + '; '\
+ _('can receive') + ' ' + self.parent.format_amount(lnworker.can_receive())\
+ _('can receive') + ' ' + self.parent.format_amount(lnworker.num_sats_can_receive())\
+ ' ' + self.parent.base_unit()
self.can_send_label.setText(msg)

6
electrum/lnworker.py

@ -7,7 +7,7 @@ import os
from decimal import Decimal
import random
import time
from typing import Optional, Sequence, Tuple, List, Dict, TYPE_CHECKING, NamedTuple
from typing import Optional, Sequence, Tuple, List, Dict, TYPE_CHECKING, NamedTuple, Union
import threading
import socket
import json
@ -1314,11 +1314,11 @@ class LNWallet(LNWorker):
with self.lock:
return Decimal(sum(chan.balance(LOCAL) if not chan.is_closed() else 0 for chan in self.channels.values()))/1000
def can_send(self):
def num_sats_can_send(self) -> Union[Decimal, int]:
with self.lock:
return Decimal(max(chan.available_to_spend(LOCAL) if chan.is_open() else 0 for chan in self.channels.values()))/1000 if self.channels else 0
def can_receive(self):
def num_sats_can_receive(self) -> Union[Decimal, int]:
with self.lock:
return Decimal(max(chan.available_to_spend(REMOTE) if chan.is_open() else 0 for chan in self.channels.values()))/1000 if self.channels else 0

Loading…
Cancel
Save