mirror of
https://github.com/basicswap/basicswap.git
synced 2024-12-23 03:49:25 +00:00
ui: Enable/disable coins through settimgs page.
This commit is contained in:
parent
36a40b5fa3
commit
e3033799b0
3 changed files with 93 additions and 2 deletions
|
@ -4950,6 +4950,58 @@ class BasicSwap(BaseApp):
|
|||
json.dump(self.settings, fp, indent=4)
|
||||
return settings_changed
|
||||
|
||||
def enableCoin(self, coin_name):
|
||||
self.log.info('Enabling coin %s', coin_name)
|
||||
|
||||
coin_id = self.getCoinIdFromName(coin_name)
|
||||
if coin_id in (Coins.PART, Coins.PART_BLIND, Coins.PART_ANON):
|
||||
raise ValueError('Invalid coin')
|
||||
|
||||
settings_cc = self.settings['chainclients'][coin_name]
|
||||
if 'connection_type_prev' not in settings_cc:
|
||||
raise ValueError('Can\'t find previous value.')
|
||||
settings_cc['connection_type'] = settings_cc['connection_type_prev']
|
||||
del settings_cc['connection_type_prev']
|
||||
if 'manage_daemon_prev' in settings_cc:
|
||||
settings_cc['manage_daemon'] = settings_cc['manage_daemon_prev']
|
||||
del settings_cc['manage_daemon_prev']
|
||||
if 'manage_wallet_daemon_prev' in settings_cc:
|
||||
settings_cc['manage_wallet_daemon'] = settings_cc['manage_wallet_daemon_prev']
|
||||
del settings_cc['manage_wallet_daemon_prev']
|
||||
|
||||
settings_path = os.path.join(self.data_dir, cfg.CONFIG_FILENAME)
|
||||
shutil.copyfile(settings_path, settings_path + '.last')
|
||||
with open(settings_path, 'w') as fp:
|
||||
json.dump(self.settings, fp, indent=4)
|
||||
# Client must be restarted
|
||||
|
||||
def disableCoin(self, coin_name):
|
||||
self.log.info('Disabling coin %s', coin_name)
|
||||
|
||||
coin_id = self.getCoinIdFromName(coin_name)
|
||||
if coin_id in (Coins.PART, Coins.PART_BLIND, Coins.PART_ANON):
|
||||
raise ValueError('Invalid coin')
|
||||
|
||||
settings_cc = self.settings['chainclients'][coin_name]
|
||||
|
||||
if settings_cc['connection_type'] != 'rpc':
|
||||
raise ValueError('Already disabled.')
|
||||
|
||||
settings_cc['manage_daemon_prev'] = settings_cc['manage_daemon']
|
||||
settings_cc['manage_daemon'] = False
|
||||
settings_cc['connection_type_prev'] = settings_cc['connection_type']
|
||||
settings_cc['connection_type'] = 'none'
|
||||
|
||||
if 'manage_wallet_daemon' in settings_cc:
|
||||
settings_cc['manage_wallet_daemon_prev'] = settings_cc['manage_wallet_daemon']
|
||||
settings_cc['manage_wallet_daemon'] = False
|
||||
|
||||
settings_path = os.path.join(self.data_dir, cfg.CONFIG_FILENAME)
|
||||
shutil.copyfile(settings_path, settings_path + '.last')
|
||||
with open(settings_path, 'w') as fp:
|
||||
json.dump(self.settings, fp, indent=4)
|
||||
# Client must be restarted
|
||||
|
||||
def getSummary(self, opts=None):
|
||||
num_watched_outputs = 0
|
||||
for c, v in self.coin_clients.items():
|
||||
|
|
|
@ -358,17 +358,34 @@ class HttpHandler(BaseHTTPRequestHandler):
|
|||
|
||||
if swap_client.editSettings(name, data) is True:
|
||||
messages.append('Settings applied.')
|
||||
elif bytes('enable_' + name, 'utf-8') in form_data:
|
||||
swap_client.enableCoin(name)
|
||||
messages.append(name.capitalize() + ' enabled, shutting down.')
|
||||
swap_client.stopRunning()
|
||||
elif bytes('disable_' + name, 'utf-8') in form_data:
|
||||
swap_client.disableCoin(name)
|
||||
messages.append(name.capitalize() + ' disabled, shutting down.')
|
||||
swap_client.stopRunning()
|
||||
chains_formatted = []
|
||||
|
||||
for name, c in swap_client.settings['chainclients'].items():
|
||||
chains_formatted.append({
|
||||
'name': name,
|
||||
'lookups': c.get('chain_lookups', 'local')
|
||||
'lookups': c.get('chain_lookups', 'local'),
|
||||
'manage_daemon': c.get('manage_daemon', 'Unknown'),
|
||||
'connection_type': c.get('connection_type', 'Unknown'),
|
||||
})
|
||||
if name == 'monero':
|
||||
chains_formatted[-1]['fee_priority'] = c.get('fee_priority', 0)
|
||||
chains_formatted[-1]['manage_wallet_daemon'] = c.get('manage_wallet_daemon', 'Unknown')
|
||||
else:
|
||||
chains_formatted[-1]['conf_target'] = c.get('conf_target', 2)
|
||||
if name != 'particl':
|
||||
if c.get('connection_type', 'Unknown') == 'none':
|
||||
if 'connection_type_prev' in c:
|
||||
chains_formatted[-1]['can_reenable'] = True
|
||||
else:
|
||||
chains_formatted[-1]['can_disable'] = True
|
||||
|
||||
template = env.get_template('settings.html')
|
||||
return bytes(template.render(
|
||||
|
|
|
@ -11,6 +11,15 @@
|
|||
{% for c in chains %}
|
||||
<h4>{{ c.name|capitalize }}</h4>
|
||||
<table>
|
||||
{% if c.connection_type %}
|
||||
<tr><td>Connection Type</td><td>{{ c.connection_type }}</td></tr>
|
||||
{% endif %}
|
||||
{% if c.manage_daemon is defined %}
|
||||
<tr><td>Manage Daemon</td><td>{{ c.manage_daemon }}</td></tr>
|
||||
{% endif %}
|
||||
{% if c.manage_wallet_daemon is defined %}
|
||||
<tr><td>Manage Wallet Daemon</td><td>{{ c.manage_wallet_daemon }}</td></tr>
|
||||
{% endif %}
|
||||
<tr><td>Chain Lookups</td><td>
|
||||
<select name="lookups_{{ c.name }}">
|
||||
<option value="local"{% if c.lookups=='local' %} selected{% endif %}>Local Node</option>
|
||||
|
@ -27,12 +36,25 @@
|
|||
{% else %}
|
||||
<tr><td>Blocks Confirmed Target</td><td><input type="number" name="conf_target_{{ c.name }}" min="1" max="32" value="{{ c.conf_target }}"></td></tr>
|
||||
{% endif %}
|
||||
<tr><td><input type="submit" name="apply_{{ c.name }}" value="Apply"></td></tr>
|
||||
<tr><td><input type="submit" name="apply_{{ c.name }}" value="Apply">
|
||||
{% if c.can_disable == true %}
|
||||
<input type="submit" name="disable_{{ c.name }}" value="Disable" onclick="confirmPopup('Disable', '{{ c.name|capitalize }}')">
|
||||
{% endif %}
|
||||
{% if c.can_reenable == true %}
|
||||
<input type="submit" name="enable_{{ c.name }}" value="Enable" onclick="confirmPopup('Enable', '{{ c.name|capitalize }}')">
|
||||
{% endif %}
|
||||
</td></tr>
|
||||
</table>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
<input type="hidden" name="formid" value="{{ form_id }}">
|
||||
</form>
|
||||
|
||||
<p><a href="/">home</a></p>
|
||||
<script>
|
||||
function confirmPopup(action, coin_name) {
|
||||
confirm(action + " " + coin_name + "?\nWill shutdown basicswap.");
|
||||
}
|
||||
</script>
|
||||
</body></html>
|
||||
|
|
Loading…
Reference in a new issue