mirror of
https://github.com/basicswap/basicswap.git
synced 2024-12-22 19:49:20 +00:00
ui: Rates table example
This commit is contained in:
parent
412770d399
commit
80f0098a3d
4 changed files with 67 additions and 5 deletions
|
@ -5993,7 +5993,16 @@ class BasicSwap(BaseApp):
|
|||
if 'bittrex' in rv:
|
||||
js = rv['bittrex']
|
||||
rate = js['rate_last'] if 'rate_last' in js else js['rate_inferred']
|
||||
rv_array.append(('bittrex.com', ticker_from, ticker_to, '', '', js['from_btc'], js['to_btc'], format_float(float(rate))))
|
||||
rv_array.append((
|
||||
'bittrex.com',
|
||||
ticker_from,
|
||||
ticker_to,
|
||||
'',
|
||||
'',
|
||||
format_float(float(js['from_btc'])),
|
||||
format_float(float(js['to_btc'])),
|
||||
format_float(float(rate))
|
||||
))
|
||||
return rv_array
|
||||
|
||||
return rv
|
||||
|
|
|
@ -17,7 +17,6 @@ from .basicswap_util import (
|
|||
from .chainparams import (
|
||||
Coins,
|
||||
chainparams,
|
||||
getCoinIdFromTicker,
|
||||
)
|
||||
from .ui.util import (
|
||||
PAGE_LIMIT,
|
||||
|
@ -344,8 +343,8 @@ def js_rates_list(self, url_split, query_string, is_json):
|
|||
get_data = urllib.parse.parse_qs(query_string)
|
||||
|
||||
sc = self.server.swap_client
|
||||
coin_from = getCoinIdFromTicker(get_data['from'][0])
|
||||
coin_to = getCoinIdFromTicker(get_data['to'][0])
|
||||
coin_from = getCoinType(get_data['from'][0])
|
||||
coin_to = getCoinType(get_data['to'][0])
|
||||
return bytes(json.dumps(sc.lookupRates(coin_from, coin_to, True)), 'UTF-8')
|
||||
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
|
||||
<input name="continue" type="submit" value="Continue">
|
||||
<input name="check_rates" type="button" value="Lookup Rates" onclick='lookup_rates();'>
|
||||
<input name="show_rates_table" type="button" value="Show Rates Table" onclick='lookup_rates_table();'>
|
||||
<input type="hidden" name="formid" value="{{ form_id }}">
|
||||
<input type="hidden" name="step1" value="a">
|
||||
</form>
|
||||
|
@ -83,6 +84,43 @@ xhr_rate.onload = () => {
|
|||
}
|
||||
}
|
||||
|
||||
const xhr_rates_table = new XMLHttpRequest();
|
||||
xhr_rates_table.onload = () => {
|
||||
if (xhr_rates_table.status == 200) {
|
||||
const list = JSON.parse(xhr_rates_table.response);
|
||||
|
||||
headings = ['Source', 'Coin From', 'Coin To', 'Coin From USD Rate', 'Coin To USD Rate', 'Coin From BTC Rate', 'Coin To BTC Rate', 'Relative Rate'];
|
||||
table = document.createElement('table');
|
||||
headings_row = document.createElement('tr');
|
||||
for (let i = 0; i < headings.length; i++) {
|
||||
column = document.createElement('th');
|
||||
column.textContent = headings[i];
|
||||
headings_row.appendChild(column);
|
||||
}
|
||||
table.appendChild(headings_row);
|
||||
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
data_row = document.createElement('tr');
|
||||
for (let j = 0; j < list[i].length; j++) {
|
||||
column = document.createElement('td');
|
||||
column.textContent = list[i][j];
|
||||
data_row.appendChild(column);
|
||||
}
|
||||
table.appendChild(data_row);
|
||||
}
|
||||
// Clear existing
|
||||
const display_node = document.getElementById("rates_display");
|
||||
while (display_node.lastElementChild) {
|
||||
display_node.removeChild(display_node.lastElementChild);
|
||||
}
|
||||
|
||||
heading = document.createElement('h4');
|
||||
heading.textContent = 'Rates'
|
||||
display_node.appendChild(heading);
|
||||
display_node.appendChild(table);
|
||||
}
|
||||
}
|
||||
|
||||
function lookup_rates() {
|
||||
const coin_from = document.getElementById('coin_from').value;
|
||||
const coin_to = document.getElementById('coin_to').value;
|
||||
|
@ -100,6 +138,22 @@ function lookup_rates() {
|
|||
xhr_rates.send('coin_from='+coin_from+'&coin_to='+coin_to);
|
||||
}
|
||||
|
||||
function lookup_rates_table() {
|
||||
const coin_from = document.getElementById('coin_from').value;
|
||||
const coin_to = document.getElementById('coin_to').value;
|
||||
|
||||
if (coin_from == '-1' || coin_to == '-1') {
|
||||
alert('Coins from and to must be set first.');
|
||||
return;
|
||||
}
|
||||
|
||||
inner_html = '<h4>Rates</h4><p>Updating...</p>';
|
||||
document.getElementById('rates_display').innerHTML = inner_html;
|
||||
|
||||
xhr_rates_table.open('GET', '/json/rateslist?from='+coin_from+'&to='+coin_to);
|
||||
xhr_rates_table.send();
|
||||
}
|
||||
|
||||
function set_rate(value_changed) {
|
||||
const coin_from = document.getElementById('coin_from').value;
|
||||
const coin_to = document.getElementById('coin_to').value;
|
||||
|
|
|
@ -111,7 +111,7 @@ class Test(BaseTest):
|
|||
assert ('bittrex' in rv)
|
||||
|
||||
rv = read_json_api(1800, 'rateslist?from=PART&to=BTC')
|
||||
assert(len(rv) == 2)
|
||||
assert len(rv) == 2
|
||||
|
||||
def test_01_verifyrawtransaction(self):
|
||||
txn = '0200000001eb6e5c4ebba4efa32f40c7314cad456a64008e91ee30b2dd0235ab9bb67fbdbb01000000ee47304402200956933242dde94f6cf8f195a470f8d02aef21ec5c9b66c5d3871594bdb74c9d02201d7e1b440de8f4da672d689f9e37e98815fb63dbc1706353290887eb6e8f7235012103dc1b24feb32841bc2f4375da91fa97834e5983668c2a39a6b7eadb60e7033f9d205a803b28fe2f86c17db91fa99d7ed2598f79b5677ffe869de2e478c0d1c02cc7514c606382012088a8201fe90717abb84b481c2a59112414ae56ec8acc72273642ca26cc7a5812fdc8f68876a914225fbfa4cb725b75e511810ac4d6f74069bdded26703520140b27576a914207eb66b2fd6ed9924d6217efc7fa7b38dfabe666888acffffffff01e0167118020000001976a9140044e188928710cecba8311f1cf412135b98145c88ac00000000'
|
||||
|
|
Loading…
Reference in a new issue