mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-06 02:38:11 +01:00
ui: Split wallet cached data into balance and blockchain state.
Add XMR synced indicator.
This commit is contained in:
@@ -23,7 +23,6 @@ from .util import (
|
||||
from .chainparams import (
|
||||
Coins,
|
||||
chainparams,
|
||||
getCoinIdFromTicker,
|
||||
)
|
||||
from .basicswap_util import (
|
||||
BidStates,
|
||||
@@ -61,6 +60,7 @@ from .ui.util import (
|
||||
)
|
||||
from .ui.page_tor import page_tor
|
||||
from .ui.page_offers import page_offers, page_offer, page_newoffer
|
||||
from .ui.page_wallet import page_wallets, page_wallet
|
||||
from .ui.page_automation import (
|
||||
page_automation_strategies,
|
||||
page_automation_strategy,
|
||||
@@ -257,304 +257,6 @@ class HttpHandler(BaseHTTPRequestHandler):
|
||||
active_swaps=[(s[0].hex(), s[1], strBidState(s[2]), strTxState(s[3]), strTxState(s[4])) for s in active_swaps],
|
||||
), 'UTF-8')
|
||||
|
||||
def page_wallets(self, url_split, post_string):
|
||||
swap_client = self.server.swap_client
|
||||
|
||||
page_data = {}
|
||||
messages = []
|
||||
form_data = self.checkForm(post_string, 'wallets', messages)
|
||||
if form_data:
|
||||
for c in Coins:
|
||||
if c not in chainparams:
|
||||
continue
|
||||
cid = str(int(c))
|
||||
|
||||
if bytes('newaddr_' + cid, 'utf-8') in form_data:
|
||||
swap_client.cacheNewAddressForCoin(c)
|
||||
elif bytes('reseed_' + cid, 'utf-8') in form_data:
|
||||
try:
|
||||
swap_client.reseedWallet(c)
|
||||
messages.append('Reseed complete ' + str(c))
|
||||
except Exception as ex:
|
||||
messages.append('Reseed failed ' + str(ex))
|
||||
swap_client.updateWalletsInfo(True, c)
|
||||
elif bytes('withdraw_' + cid, 'utf-8') in form_data:
|
||||
try:
|
||||
value = form_data[bytes('amt_' + cid, 'utf-8')][0].decode('utf-8')
|
||||
page_data['wd_value_' + cid] = value
|
||||
except Exception as e:
|
||||
messages.append('Error: Missing value')
|
||||
try:
|
||||
address = form_data[bytes('to_' + cid, 'utf-8')][0].decode('utf-8')
|
||||
page_data['wd_address_' + cid] = address
|
||||
except Exception as e:
|
||||
messages.append('Error: Missing address')
|
||||
|
||||
subfee = True if bytes('subfee_' + cid, 'utf-8') in form_data else False
|
||||
page_data['wd_subfee_' + cid] = subfee
|
||||
|
||||
if c == Coins.PART:
|
||||
try:
|
||||
type_from = form_data[bytes('withdraw_type_from_' + cid, 'utf-8')][0].decode('utf-8')
|
||||
type_to = form_data[bytes('withdraw_type_to_' + cid, 'utf-8')][0].decode('utf-8')
|
||||
page_data['wd_type_from_' + cid] = type_from
|
||||
page_data['wd_type_to_' + cid] = type_to
|
||||
except Exception as e:
|
||||
messages.append('Error: Missing type')
|
||||
|
||||
if len(messages) == 0:
|
||||
ci = swap_client.ci(c)
|
||||
ticker = ci.ticker()
|
||||
if c == Coins.PART:
|
||||
try:
|
||||
txid = swap_client.withdrawParticl(type_from, type_to, value, address, subfee)
|
||||
messages.append('Withdrew {} {} ({} to {}) to address {}<br/>In txid: {}'.format(value, ticker, type_from, type_to, address, txid))
|
||||
except Exception as e:
|
||||
messages.append('Error: {}'.format(str(e)))
|
||||
else:
|
||||
try:
|
||||
txid = swap_client.withdrawCoin(c, value, address, subfee)
|
||||
messages.append('Withdrew {} {} to address {}<br/>In txid: {}'.format(value, ticker, address, txid))
|
||||
except Exception as e:
|
||||
messages.append('Error: {}'.format(str(e)))
|
||||
swap_client.updateWalletsInfo(True, c)
|
||||
|
||||
swap_client.updateWalletsInfo()
|
||||
wallets = swap_client.getCachedWalletsInfo()
|
||||
|
||||
wallets_formatted = []
|
||||
sk = sorted(wallets.keys())
|
||||
|
||||
for k in sk:
|
||||
w = wallets[k]
|
||||
if 'error' in w:
|
||||
wallets_formatted.append({
|
||||
'cid': str(int(k)),
|
||||
'error': w['error']
|
||||
})
|
||||
continue
|
||||
|
||||
if 'balance' not in w:
|
||||
wallets_formatted.append({
|
||||
'name': w['name'],
|
||||
'havedata': False,
|
||||
'updating': w['updating'],
|
||||
})
|
||||
continue
|
||||
|
||||
ci = swap_client.ci(k)
|
||||
cid = str(int(k))
|
||||
wf = {
|
||||
'name': w['name'],
|
||||
'version': w['version'],
|
||||
'ticker': ci.ticker_mainnet(),
|
||||
'cid': cid,
|
||||
'balance': w['balance'],
|
||||
'blocks': w['blocks'],
|
||||
'synced': w['synced'],
|
||||
'deposit_address': w['deposit_address'],
|
||||
'expected_seed': w['expected_seed'],
|
||||
'balance_all': float(w['balance']) + float(w['unconfirmed']),
|
||||
'updating': w['updating'],
|
||||
'lastupdated': format_timestamp(w['lastupdated']),
|
||||
'havedata': True,
|
||||
}
|
||||
if float(w['unconfirmed']) > 0.0:
|
||||
wf['unconfirmed'] = w['unconfirmed']
|
||||
|
||||
if k == Coins.PART:
|
||||
wf['stealth_address'] = w['stealth_address']
|
||||
wf['blind_balance'] = w['blind_balance']
|
||||
if float(w['blind_unconfirmed']) > 0.0:
|
||||
wf['blind_unconfirmed'] = w['blind_unconfirmed']
|
||||
wf['anon_balance'] = w['anon_balance']
|
||||
if float(w['anon_pending']) > 0.0:
|
||||
wf['anon_pending'] = w['anon_pending']
|
||||
|
||||
wallets_formatted.append(wf)
|
||||
|
||||
template = env.get_template('wallets.html')
|
||||
return bytes(template.render(
|
||||
title=self.server.title,
|
||||
h2=self.server.title,
|
||||
messages=messages,
|
||||
wallets=wallets_formatted,
|
||||
form_id=os.urandom(8).hex(),
|
||||
), 'UTF-8')
|
||||
|
||||
def page_wallet(self, url_split, post_string):
|
||||
ensure(len(url_split) > 2, 'Wallet not specified')
|
||||
wallet_ticker = url_split[2]
|
||||
swap_client = self.server.swap_client
|
||||
|
||||
coin_id = getCoinIdFromTicker(wallet_ticker)
|
||||
|
||||
page_data = {}
|
||||
messages = []
|
||||
form_data = self.checkForm(post_string, 'settings', messages)
|
||||
show_utxo_groups = False
|
||||
if form_data:
|
||||
cid = str(int(coin_id))
|
||||
|
||||
if bytes('newaddr_' + cid, 'utf-8') in form_data:
|
||||
swap_client.cacheNewAddressForCoin(coin_id)
|
||||
elif bytes('reseed_' + cid, 'utf-8') in form_data:
|
||||
try:
|
||||
swap_client.reseedWallet(coin_id)
|
||||
messages.append('Reseed complete ' + str(coin_id))
|
||||
except Exception as ex:
|
||||
messages.append('Reseed failed ' + str(ex))
|
||||
swap_client.updateWalletsInfo(True, coin_id)
|
||||
elif bytes('withdraw_' + cid, 'utf-8') in form_data:
|
||||
try:
|
||||
value = form_data[bytes('amt_' + cid, 'utf-8')][0].decode('utf-8')
|
||||
page_data['wd_value_' + cid] = value
|
||||
except Exception as e:
|
||||
messages.append('Error: Missing value')
|
||||
try:
|
||||
address = form_data[bytes('to_' + cid, 'utf-8')][0].decode('utf-8')
|
||||
page_data['wd_address_' + cid] = address
|
||||
except Exception as e:
|
||||
messages.append('Error: Missing address')
|
||||
|
||||
subfee = True if bytes('subfee_' + cid, 'utf-8') in form_data else False
|
||||
page_data['wd_subfee_' + cid] = subfee
|
||||
|
||||
if coin_id == Coins.PART:
|
||||
try:
|
||||
type_from = form_data[bytes('withdraw_type_from_' + cid, 'utf-8')][0].decode('utf-8')
|
||||
type_to = form_data[bytes('withdraw_type_to_' + cid, 'utf-8')][0].decode('utf-8')
|
||||
page_data['wd_type_from_' + cid] = type_from
|
||||
page_data['wd_type_to_' + cid] = type_to
|
||||
except Exception as e:
|
||||
messages.append('Error: Missing type')
|
||||
|
||||
if len(messages) == 0:
|
||||
ci = swap_client.ci(coin_id)
|
||||
ticker = ci.ticker()
|
||||
if coin_id == Coins.PART:
|
||||
try:
|
||||
txid = swap_client.withdrawParticl(type_from, type_to, value, address, subfee)
|
||||
messages.append('Withdrew {} {} ({} to {}) to address {}<br/>In txid: {}'.format(value, ticker, type_from, type_to, address, txid))
|
||||
except Exception as e:
|
||||
messages.append('Error: {}'.format(str(e)))
|
||||
else:
|
||||
try:
|
||||
txid = swap_client.withdrawCoin(coin_id, value, address, subfee)
|
||||
messages.append('Withdrew {} {} to address {}<br/>In txid: {}'.format(value, ticker, address, txid))
|
||||
except Exception as e:
|
||||
messages.append('Error: {}'.format(str(e)))
|
||||
swap_client.updateWalletsInfo(True, coin_id)
|
||||
elif have_data_entry(form_data, 'showutxogroups'):
|
||||
show_utxo_groups = True
|
||||
elif have_data_entry(form_data, 'create_utxo'):
|
||||
show_utxo_groups = True
|
||||
try:
|
||||
value = get_data_entry(form_data, 'utxo_value')
|
||||
page_data['utxo_value'] = value
|
||||
|
||||
ci = swap_client.ci(coin_id)
|
||||
|
||||
value_sats = ci.make_int(value)
|
||||
|
||||
txid, address = ci.createUTXO(value_sats)
|
||||
messages.append('Created new utxo of value {} and address {}<br/>In txid: {}'.format(value, address, txid))
|
||||
except Exception as e:
|
||||
messages.append('Error: {}'.format(str(e)))
|
||||
if swap_client.debug is True:
|
||||
swap_client.log.error(traceback.format_exc())
|
||||
|
||||
swap_client.updateWalletsInfo()
|
||||
wallets = swap_client.getCachedWalletsInfo({'coin_id': coin_id})
|
||||
for k in wallets.keys():
|
||||
w = wallets[k]
|
||||
if 'error' in w:
|
||||
wallet_data = {
|
||||
'cid': str(int(k)),
|
||||
'error': w['error']
|
||||
}
|
||||
continue
|
||||
|
||||
if 'balance' not in w:
|
||||
wallet_data = {
|
||||
'name': w['name'],
|
||||
'havedata': False,
|
||||
'updating': w['updating'],
|
||||
}
|
||||
continue
|
||||
|
||||
ci = swap_client.ci(k)
|
||||
fee_rate, fee_src = swap_client.getFeeRateForCoin(k)
|
||||
est_fee = swap_client.estimateWithdrawFee(k, fee_rate)
|
||||
cid = str(int(k))
|
||||
wallet_data = {
|
||||
'name': w['name'],
|
||||
'version': w['version'],
|
||||
'ticker': ci.ticker_mainnet(),
|
||||
'cid': cid,
|
||||
'fee_rate': ci.format_amount(int(fee_rate * ci.COIN())),
|
||||
'fee_rate_src': fee_src,
|
||||
'est_fee': 'Unknown' if est_fee is None else ci.format_amount(int(est_fee * ci.COIN())),
|
||||
'balance': w['balance'],
|
||||
'blocks': w['blocks'],
|
||||
'synced': w['synced'],
|
||||
'deposit_address': w['deposit_address'],
|
||||
'expected_seed': w['expected_seed'],
|
||||
'balance_all': float(w['balance']) + float(w['unconfirmed']),
|
||||
'updating': w['updating'],
|
||||
'lastupdated': format_timestamp(w['lastupdated']),
|
||||
'havedata': True,
|
||||
}
|
||||
if float(w['unconfirmed']) > 0.0:
|
||||
wallet_data['unconfirmed'] = w['unconfirmed']
|
||||
|
||||
if k == Coins.PART:
|
||||
wallet_data['stealth_address'] = w['stealth_address']
|
||||
wallet_data['blind_balance'] = w['blind_balance']
|
||||
if float(w['blind_unconfirmed']) > 0.0:
|
||||
wallet_data['blind_unconfirmed'] = w['blind_unconfirmed']
|
||||
wallet_data['anon_balance'] = w['anon_balance']
|
||||
if float(w['anon_pending']) > 0.0:
|
||||
wallet_data['anon_pending'] = w['anon_pending']
|
||||
|
||||
elif k == Coins.XMR:
|
||||
wallet_data['main_address'] = w.get('main_address', 'Refresh necessary')
|
||||
|
||||
if 'wd_type_from_' + cid in page_data:
|
||||
wallet_data['wd_type_from'] = page_data['wd_type_from_' + cid]
|
||||
if 'wd_type_to_' + cid in page_data:
|
||||
wallet_data['wd_type_to'] = page_data['wd_type_to_' + cid]
|
||||
|
||||
if 'wd_value_' + cid in page_data:
|
||||
wallet_data['wd_value'] = page_data['wd_value_' + cid]
|
||||
if 'wd_address_' + cid in page_data:
|
||||
wallet_data['wd_address'] = page_data['wd_address_' + cid]
|
||||
if 'wd_subfee_' + cid in page_data:
|
||||
wallet_data['wd_subfee'] = page_data['wd_subfee_' + cid]
|
||||
if 'utxo_value' in page_data:
|
||||
wallet_data['utxo_value'] = page_data['utxo_value']
|
||||
|
||||
if show_utxo_groups:
|
||||
utxo_groups = ''
|
||||
|
||||
unspent_by_addr = swap_client.getUnspentsByAddr(k)
|
||||
|
||||
sorted_unspent_by_addr = sorted(unspent_by_addr.items(), key=lambda x: x[1], reverse=True)
|
||||
for kv in sorted_unspent_by_addr:
|
||||
utxo_groups += kv[0] + ' ' + ci.format_amount(kv[1]) + '\n'
|
||||
|
||||
wallet_data['show_utxo_groups'] = True
|
||||
wallet_data['utxo_groups'] = utxo_groups
|
||||
|
||||
template = env.get_template('wallet.html')
|
||||
return bytes(template.render(
|
||||
title=self.server.title,
|
||||
h2=self.server.title,
|
||||
messages=messages,
|
||||
w=wallet_data,
|
||||
form_id=os.urandom(8).hex(),
|
||||
), 'UTF-8')
|
||||
|
||||
def page_settings(self, url_split, post_string):
|
||||
swap_client = self.server.swap_client
|
||||
|
||||
@@ -1000,9 +702,9 @@ class HttpHandler(BaseHTTPRequestHandler):
|
||||
if url_split[1] == 'active':
|
||||
return self.page_active(url_split, post_string)
|
||||
if url_split[1] == 'wallets':
|
||||
return self.page_wallets(url_split, post_string)
|
||||
return page_wallets(self, url_split, post_string)
|
||||
if url_split[1] == 'wallet':
|
||||
return self.page_wallet(url_split, post_string)
|
||||
return page_wallet(self, url_split, post_string)
|
||||
if url_split[1] == 'settings':
|
||||
return self.page_settings(url_split, post_string)
|
||||
if url_split[1] == 'rpc':
|
||||
|
||||
Reference in New Issue
Block a user