|
|
@ -22,7 +22,9 @@ |
|
|
|
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
|
|
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
|
|
# SOFTWARE. |
|
|
|
|
|
|
|
import webbrowser |
|
|
|
from enum import IntEnum |
|
|
|
|
|
|
|
from electrum.i18n import _ |
|
|
|
from electrum.util import block_explorer_URL |
|
|
@ -32,11 +34,21 @@ from electrum.wallet import InternalAddressCorruption |
|
|
|
|
|
|
|
from .util import * |
|
|
|
|
|
|
|
|
|
|
|
class AddressList(MyTreeView): |
|
|
|
filter_columns = [0, 1, 2, 3] # Type, Address, Label, Balance |
|
|
|
|
|
|
|
class Columns(IntEnum): |
|
|
|
TYPE = 0 |
|
|
|
ADDRESS = 1 |
|
|
|
LABEL = 2 |
|
|
|
COIN_BALANCE = 3 |
|
|
|
FIAT_BALANCE = 4 |
|
|
|
NUM_TXS = 5 |
|
|
|
|
|
|
|
filter_columns = [Columns.TYPE, Columns.ADDRESS, Columns.LABEL, Columns.COIN_BALANCE] |
|
|
|
|
|
|
|
def __init__(self, parent=None): |
|
|
|
super().__init__(parent, self.create_menu, 2) |
|
|
|
super().__init__(parent, self.create_menu, stretch_column=self.Columns.LABEL) |
|
|
|
self.setSelectionMode(QAbstractItemView.ExtendedSelection) |
|
|
|
self.setSortingEnabled(True) |
|
|
|
self.show_change = 0 |
|
|
@ -64,11 +76,17 @@ class AddressList(MyTreeView): |
|
|
|
config.set_key('show_toolbar_addresses', state) |
|
|
|
|
|
|
|
def refresh_headers(self): |
|
|
|
headers = [_('Type'), _('Address'), _('Label'), _('Balance')] |
|
|
|
fx = self.parent.fx |
|
|
|
if fx and fx.get_fiat_address_config(): |
|
|
|
headers.extend([_(fx.get_currency()+' Balance')]) |
|
|
|
headers.extend([_('Tx')]) |
|
|
|
ccy = fx.get_currency() |
|
|
|
else: |
|
|
|
ccy = _('Fiat') |
|
|
|
headers = [_('Type'), |
|
|
|
_('Address'), |
|
|
|
_('Label'), |
|
|
|
_('Balance'), |
|
|
|
ccy + ' ' + _('Balance'), |
|
|
|
_('Tx')] |
|
|
|
self.update_headers(headers) |
|
|
|
|
|
|
|
def toggle_change(self, state): |
|
|
@ -85,7 +103,7 @@ class AddressList(MyTreeView): |
|
|
|
|
|
|
|
def update(self): |
|
|
|
self.wallet = self.parent.wallet |
|
|
|
current_address = self.current_item_user_role(col=2) |
|
|
|
current_address = self.current_item_user_role(col=self.Columns.LABEL) |
|
|
|
if self.show_change == 1: |
|
|
|
addr_list = self.wallet.get_receiving_addresses() |
|
|
|
elif self.show_change == 2: |
|
|
@ -113,45 +131,48 @@ class AddressList(MyTreeView): |
|
|
|
if fx and fx.get_fiat_address_config(): |
|
|
|
rate = fx.exchange_rate() |
|
|
|
fiat_balance = fx.value_str(balance, rate) |
|
|
|
labels = ['', address, label, balance_text, fiat_balance, "%d"%num] |
|
|
|
address_item = [QStandardItem(e) for e in labels] |
|
|
|
else: |
|
|
|
labels = ['', address, label, balance_text, "%d"%num] |
|
|
|
address_item = [QStandardItem(e) for e in labels] |
|
|
|
fiat_balance = '' |
|
|
|
labels = ['', address, label, balance_text, fiat_balance, "%d"%num] |
|
|
|
address_item = [QStandardItem(e) for e in labels] |
|
|
|
# align text and set fonts |
|
|
|
for i, item in enumerate(address_item): |
|
|
|
item.setTextAlignment(Qt.AlignVCenter) |
|
|
|
if i not in (0, 2): |
|
|
|
if i not in (self.Columns.TYPE, self.Columns.LABEL): |
|
|
|
item.setFont(QFont(MONOSPACE_FONT)) |
|
|
|
item.setEditable(i in self.editable_columns) |
|
|
|
if fx and fx.get_fiat_address_config(): |
|
|
|
address_item[4].setTextAlignment(Qt.AlignRight | Qt.AlignVCenter) |
|
|
|
address_item[self.Columns.FIAT_BALANCE].setTextAlignment(Qt.AlignRight | Qt.AlignVCenter) |
|
|
|
# setup column 0 |
|
|
|
if self.wallet.is_change(address): |
|
|
|
address_item[0].setText(_('change')) |
|
|
|
address_item[0].setBackground(ColorScheme.YELLOW.as_color(True)) |
|
|
|
address_item[self.Columns.TYPE].setText(_('change')) |
|
|
|
address_item[self.Columns.TYPE].setBackground(ColorScheme.YELLOW.as_color(True)) |
|
|
|
else: |
|
|
|
address_item[0].setText(_('receiving')) |
|
|
|
address_item[0].setBackground(ColorScheme.GREEN.as_color(True)) |
|
|
|
address_item[2].setData(address, Qt.UserRole) |
|
|
|
address_item[self.Columns.TYPE].setText(_('receiving')) |
|
|
|
address_item[self.Columns.TYPE].setBackground(ColorScheme.GREEN.as_color(True)) |
|
|
|
address_item[self.Columns.LABEL].setData(address, Qt.UserRole) |
|
|
|
# setup column 1 |
|
|
|
if self.wallet.is_frozen(address): |
|
|
|
address_item[1].setBackground(ColorScheme.BLUE.as_color(True)) |
|
|
|
address_item[self.Columns.ADDRESS].setBackground(ColorScheme.BLUE.as_color(True)) |
|
|
|
if self.wallet.is_beyond_limit(address): |
|
|
|
address_item[1].setBackground(ColorScheme.RED.as_color(True)) |
|
|
|
address_item[self.Columns.ADDRESS].setBackground(ColorScheme.RED.as_color(True)) |
|
|
|
# add item |
|
|
|
count = self.model().rowCount() |
|
|
|
self.model().insertRow(count, address_item) |
|
|
|
address_idx = self.model().index(count, 2) |
|
|
|
address_idx = self.model().index(count, self.Columns.LABEL) |
|
|
|
if address == current_address: |
|
|
|
set_address = QPersistentModelIndex(address_idx) |
|
|
|
self.set_current_idx(set_address) |
|
|
|
# show/hide columns |
|
|
|
if fx and fx.get_fiat_address_config(): |
|
|
|
self.showColumn(self.Columns.FIAT_BALANCE) |
|
|
|
else: |
|
|
|
self.hideColumn(self.Columns.FIAT_BALANCE) |
|
|
|
|
|
|
|
def create_menu(self, position): |
|
|
|
from electrum.wallet import Multisig_Wallet |
|
|
|
is_multisig = isinstance(self.wallet, Multisig_Wallet) |
|
|
|
can_delete = self.wallet.can_delete_address() |
|
|
|
selected = self.selected_in_column(1) |
|
|
|
selected = self.selected_in_column(self.Columns.ADDRESS) |
|
|
|
if not selected: |
|
|
|
return |
|
|
|
multi_select = len(selected) > 1 |
|
|
@ -165,8 +186,8 @@ class AddressList(MyTreeView): |
|
|
|
return |
|
|
|
addr = addrs[0] |
|
|
|
|
|
|
|
addr_column_title = self.model().horizontalHeaderItem(2).text() |
|
|
|
addr_idx = idx.sibling(idx.row(), 2) |
|
|
|
addr_column_title = self.model().horizontalHeaderItem(self.Columns.LABEL).text() |
|
|
|
addr_idx = idx.sibling(idx.row(), self.Columns.LABEL) |
|
|
|
|
|
|
|
column_title = self.model().horizontalHeaderItem(col).text() |
|
|
|
copy_text = self.model().itemFromIndex(idx).text() |
|
|
|