-
Notifications
You must be signed in to change notification settings - Fork 58
Add icons and highlight successful rebalances #356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
proof-of-reality
wants to merge
10
commits into
cryptosharks131:v1.10.0
Choose a base branch
from
proof-of-reality:rebalancing/add-icons-highlight-row
base: v1.10.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6b19454
Add `RapidFire` visual context and highlight successful rebalances
proof-of-reality bdee4a1
Add `RapidFire` dependency to other rebalances table
proof-of-reality bcf08ef
Fix highlight when background color is set
proof-of-reality 0c97275
Add icons to rebalance statuses
proof-of-reality f46bc12
Fix duration message
proof-of-reality be9f3a0
Resolve conflicts
proof-of-reality bb4a1da
Resolve conflicts
proof-of-reality 8c6991e
Resolve conflicts
proof-of-reality bc92815
Fix merge issue
proof-of-reality 70c7344
Fix variable name
proof-of-reality File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| {% extends "base.html" %} | ||
| {% block title %} {{ block.super }} - Rebalances{% endblock %} | ||
| {% block content %} | ||
| {% include 'rebalances_table.html' with count=20 status=1 load_count=20 title='Rebalance Requests' %} | ||
| {% include 'rebalances_table.html' with count=20 status=0 load_count=20 title='Rebalance Requests' %} | ||
| {% include 'rebalances_table.html' with count=20 status=2 load_count=20 title='Rebalance Requests' %} | ||
| {% include 'rebalances_table.html' with count=50 load_count=50 title='Rebalance Requests' %} | ||
| {% include 'rebalances_table.html' with target_time=target_time count=20 status=1 load_count=20 title='Rebalance Requests' %} | ||
| {% include 'rebalances_table.html' with target_time=target_time count=20 status=2 load_count=20 title='Rebalance Requests' %} | ||
| {% include 'rebalances_table.html' with target_time=target_time count=20 status=0 load_count=20 title='Rebalance Requests' %} | ||
| {% include 'rebalances_table.html' with target_time=target_time count=50 load_count=50 title='Rebalance Requests' %} | ||
| {% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,115 +1,144 @@ | ||
| {% load humanize %} | ||
| <div id="rebalances_div_{{status}}" class="w3-container w3-padding-small"> | ||
| <h2>{% if status == 2 %}Successful{% elif status == 0 %}Pending{% elif status == 1 %}In-Flight{% else %}Last{% endif %} {{title}}</h2> | ||
| <table id="rebalsTable_{{status}}" class="w3-table-all w3-centered w3-hoverable"> | ||
| <tr> | ||
| <th>Requested</th> | ||
| <th>Start</th> | ||
| <th>Stop</th> | ||
| <th>Scheduled for</th> | ||
| <th>Elapsed</th> | ||
| <th>Value</th> | ||
| <th>Fee Limit</th> | ||
| <th>Target PPM</th> | ||
| <th>Fees Paid</th> | ||
| <th>Last Hop</th> | ||
| <th>Status</th> | ||
| <th>Hash</th> | ||
| <th>Action</th> | ||
| <h2>{% if status == 2 %}Successful{% elif status == 0 %}Pending{% elif status == 1 %}In-Flight{% else %}Last{% endif %} {{title}}</h2> | ||
| <table id="rebalsTable_{{status}}" class="w3-table-all w3-centered w3-hoverable"> | ||
| <tr> | ||
| <th>Requested</th> | ||
| <th>Start</th> | ||
| <th>Stop</th> | ||
| <th>Scheduled for</th> | ||
| <th>Elapsed</th> | ||
| <th>Value</th> | ||
| <th>Fee Limit</th> | ||
| <th>Target PPM</th> | ||
| <th>Fees Paid</th> | ||
| <th>Last Hop</th> | ||
| <th>Status</th> | ||
| <th>Hash</th> | ||
| <th>Action</th> | ||
| </tr> | ||
| <tbody id="rebalances_{{status}}"> | ||
| </tbody> | ||
| <tfoot id="loadMoreRebals_{{status}}"> | ||
| <tr style="background-color:transparent;cursor:pointer;"> | ||
| <td colspan="13"> | ||
| <a onclick='loadRebals_{{status}}()'>Load More</a> | ||
| </td> | ||
| </tr> | ||
| <tbody id="rebalances_{{status}}"> | ||
| </tbody> | ||
| <tfoot id="loadMoreRebals_{{status}}"> | ||
| <tr style="background-color:transparent;cursor:pointer;"> | ||
| <td colspan="13"> | ||
| <a onclick='loadRebals_{{status}}()'>Load More</a> | ||
| </td> | ||
| </tr> | ||
| </tfoot> | ||
| </table> | ||
| </div> | ||
| <script> | ||
| function formatDuration(duration){ | ||
| return `${duration} minute${duration === 1 ? 's':''}` | ||
| } | ||
| statuses = {0: 'Pending', 1: 'In-Flight', 2: 'Successful', 3: 'Timeout', 4: 'No-Route', 5: 'Error', 6: 'Incorrect-Payment-Details', 7: 'Insufficient-Balance', 400: 'Rebalancer-Request-Failed', 406: 'No-Sources', 408: 'Rebalancer-Request-Timeout', 499: 'Cancelled'} | ||
| transformations = { | ||
| 'requested': rebalance => ({innerHTML: formatDate(rebalance.requested), title: adjustTZ(rebalance.requested)}), | ||
| 'start': rebalance => ({innerHTML: formatDate(rebalance.start), title: rebalance.start ? adjustTZ(rebalance.start) : '---'}), | ||
| 'stop': rebalance => ({innerHTML: formatDate(rebalance.stop), title: rebalance.stop ? adjustTZ(rebalance.stop) : '---'}), | ||
| 'duration': rebalance => ({innerHTML: formatDuration(rebalance.duration)}), | ||
| 'elapsed': rebalance => ({innerHTML: formatDate(rebalance.start, rebalance.stop).replace(" ago", "")}), | ||
| 'value': rebalance => ({innerHTML: Number(rebalance.value).toLocaleString()}), | ||
| 'fee_limit': rebalance => ({innerHTML: Number(rebalance.fee_limit).toLocaleString()}), | ||
| 'ppm': rebalance => ({innerHTML: Math.round(rebalance.fee_limit*1000000/rebalance.value).toLocaleString()}), | ||
| 'fees_paid': rebalance => ({innerHTML: rebalance.status == 2 ? Number(rebalance.fees_paid).toLocaleString() : '---'}), | ||
| 'target_alias': rebalance => ({innerHTML: rebalance.target_alias !== '' ? rebalance.target_alias : '---'}), | ||
| 'status': rebalance => ({innerHTML: statuses[rebalance.status], title: rebalance.status}), | ||
| 'payment_hash': rebalance => ({innerHTML: (rebalance.payment_hash || '').length == 0 ? '---' : | ||
| `<a href="/route?=${rebalance.payment_hash}" target="_blank">${rebalance.payment_hash.substring(0,7)}</a>`}), | ||
| 'action': rebalance => { | ||
| const input = document.createElement("button") | ||
| if (rebalance.status != 0){ | ||
| input.innerHTML = "🔂" | ||
| input.title="Repeat this request" | ||
| input.onclick = async function(){ | ||
| const {value, fee_limit, outgoing_chan_ids, last_hop_pubkey, duration, target_alias, manual} = rebalance | ||
| if (last_hop_pubkey.length === 0){ | ||
| var new_rebal = {value, fee_limit, outgoing_chan_ids, duration, manual} | ||
| }else{ | ||
| var new_rebal = {value, fee_limit, outgoing_chan_ids, last_hop_pubkey, duration, target_alias, manual} | ||
| } | ||
| const response = await POST('rebalancer', {body: new_rebal}) | ||
| const table = input.parentElement.parentElement.parentElement | ||
| table.prepend(use(transformations).render(response)) | ||
| } | ||
| } | ||
| else { | ||
| input.innerHTML = "❌" | ||
| input.title="Cancel this request" | ||
| input.onclick = async function(){ | ||
| const response = await PUT(`rebalancer/${rebalance.id}`, {body: {status: 499}}) | ||
|
|
||
| const table = input.parentElement.parentElement.parentElement | ||
| const index = input.parentElement.parentElement.rowIndex -1 | ||
| table.deleteRow(index) | ||
| use(transformations).render(response, table.insertRow(index)) | ||
| </tfoot> | ||
| </table> | ||
| </div> | ||
| <script> | ||
| var rapidFire = 'rapidFire', target_time = {{target_time}} | ||
| function formatDuration(duration) { | ||
| return `${duration} minute${duration > 1 ? 's':''}` | ||
| } | ||
| statuses = { 0: 'Pending ⏳', 1: 'In-Flight 🚀', 2: 'Successful ✅', 3: 'Timeout ⏱️', 4: 'No-Route ⭕', 5: 'Error ⛔', 6: 'Incorrect-Payment-Detail❗', 7: 'Insufficient-Balance💸', 400: 'Rebalancer-Failed', 406: 'No-Sources ⛽', 408: 'Rebalancer-Timeout ⏱️', 499: 'Cancelled ✖️' } | ||
| template = { | ||
| 'requested': rebalance => ({ innerHTML: formatDate(rebalance.requested), title: adjustTZ(rebalance.requested) }), | ||
| 'start': rebalance => ({ innerHTML: formatDate(rebalance.start), title: rebalance.start ? adjustTZ(rebalance.start) : '---' }), | ||
| 'stop': rebalance => ({ innerHTML: formatDate(rebalance.stop), title: rebalance.stop ? adjustTZ(rebalance.stop) : '---' }), | ||
| 'duration': rebalance => ({ innerHTML: formatDuration(rebalance.duration) }), | ||
| 'elapsed': rebalance => ({ innerHTML: formatDate(rebalance.start, rebalance.stop).replace(" ago", "") }), | ||
| 'value': rebalance => ({ innerHTML: Number(rebalance.value).toLocaleString() }), | ||
| 'fee_limit': rebalance => ({ innerHTML: Number(rebalance.fee_limit).toLocaleString() }), | ||
| 'ppm': rebalance => ({ innerHTML: Math.round(rebalance.fee_limit * 1000000 / rebalance.value).toLocaleString() }), | ||
| 'fees_paid': rebalance => ({ innerHTML: rebalance.status == 2 ? Number(rebalance.fees_paid).toLocaleString() : '---' }), | ||
| 'target_alias': rebalance => ({ innerHTML: rebalance.target_alias !== '' ? rebalance.target_alias : '---' }), | ||
| 'status': rebalance => ({ innerHTML: statuses[rebalance.status], title: rebalance.status }), | ||
| 'payment_hash': rebalance => ({ innerHTML: (rebalance.payment_hash || '').length == 0 ? '---' : | ||
| `<a href="/route?=${rebalance.payment_hash}" target="_blank">${rebalance.payment_hash.substring(0, 7)}</a>` }), | ||
| 'action': rebalance => { | ||
| const input = document.createElement("button") | ||
| if (rebalance.status != 0) { | ||
| input.innerHTML = "🔂" | ||
| input.title = "Repeat this request" | ||
| input.onclick = async function() { | ||
| const { value, fee_limit, outgoing_chan_ids, last_hop_pubkey, duration, target_alias, manual } = rebalance | ||
| let new_rebal = { value, fee_limit, outgoing_chan_ids, duration, manual } | ||
| if(last_hop_pubkey.length !== 0){ | ||
| new_rebal['last_hop_pubkey'] = last_hop_pubkey | ||
| new_rebal['target_alias'] = target_alias | ||
| } | ||
| } | ||
| return {innerHTML: input} | ||
| } | ||
| }; | ||
| async function buildTable(){ | ||
| const res = await GET('rebalancer', {data: {limit: '{{count}}', status: '{{status}}', payment_hash: '{{payment_hash}}', last_hop_pubkey: '{% if last_hop_pubkey %}{{last_hop_pubkey}}{%else%}{{request.GET.last_hop_pubkey}}{%endif%}' }}) | ||
| if(res.errors) return | ||
| if(res.results.length == 0){ | ||
| document.getElementById("rebalances_div_{{status}}").innerHTML = `<center><h1>You dont have any ${'{{status}}'=='' ? '' : statuses['{{status}}'].toLowerCase()} rebalance request</h1></center>` | ||
| return | ||
| const response = await POST('rebalancer', { body: new_rebal }) | ||
| const table = input.parentElement.parentElement.parentElement | ||
| table.prepend(use(template).render(response)) | ||
| } | ||
| } | ||
| else { | ||
| input.innerHTML = "🛑" | ||
| input.title = "Cancel this request" | ||
| input.onclick = async function() { | ||
| const response = await PUT(`rebalancer/${rebalance.id}`, { body: { status: 499 } }) | ||
| const table = input.parentElement.parentElement.parentElement | ||
| const index = input.parentElement.parentElement.rowIndex - 1 | ||
| table.deleteRow(index) | ||
| use(template).render(response, table.insertRow(index)) | ||
| } | ||
| } | ||
| return { innerHTML: input } | ||
| } | ||
| }; | ||
| function markRapidFire(tr, index) { | ||
| const duration = tr.cells['duration'] | ||
| duration.innerHTML += ` 🔥` | ||
| duration.title = `+${index} RapidFire🔥 rebalances:\nWhen the previous rebalance is successful, LNDg tries new 1min-long rebalances as a lift to quicker fulfill the AR target amount.` | ||
| } | ||
| async function buildTable(ev) { | ||
| const res = await GET('rebalancer', { data: { limit: '{{count}}', status: '{{status}}', payment_hash: '{{payment_hash}}', last_hop_pubkey: '{% if last_hop_pubkey %}{{last_hop_pubkey}}{%else%}{{request.GET.last_hop_pubkey}}{%endif%}' } }) | ||
| if (res.errors) return | ||
| if (res.results.length == 0) { | ||
| byId("rebalances_div_{{status}}").innerHTML = `<center><h1>You dont have any ${'{{status}}' == '' ? '' : statuses['{{status}}'].toLowerCase()} rebalance request</h1></center>` | ||
| return | ||
| } | ||
|
|
||
| const table = document.getElementById("rebalances_{{status}}"), template = use(transformations) | ||
| table.innerHTML = null | ||
| res.results.forEach(rebalance => table.append(template.render(rebalance))); | ||
| const table = byId("rebalances_{{status}}"), renderer = use(template) | ||
| table.innerHTML = null | ||
| for (const rebalance of res.results) { | ||
| const tr = renderer.render(rebalance), isRapidFire = rebalance.duration === 1 && target_time !== 1 | ||
| table.append(tr) | ||
| tr.setAttribute(rapidFire, +isRapidFire) | ||
|
|
||
| await auto_refresh(buildTable) | ||
| if(rebalance.status == 2) tr.style.backgroundColor = green | ||
| if(isRapidFire) continue | ||
| var i = tr.rowIndex -2, prev = table.rows[i] | ||
| while(prev && parseInt(prev.getAttribute(rapidFire))){ | ||
| markRapidFire(prev, tr.rowIndex - prev.rowIndex) | ||
| prev = table.rows[--i] | ||
| } | ||
| } | ||
|
|
||
| document.addEventListener('DOMContentLoaded', buildTable); | ||
| await auto_refresh(buildTable) | ||
| } | ||
|
|
||
| document.addEventListener('DOMContentLoaded', buildTable); | ||
|
|
||
| async function loadRebals_{{status}}(){ | ||
| const status = "{{ status }}" | ||
| const rebalsTable = byId('rebalsTable_'+status) | ||
| const lastId = rebalsTable.tBodies[1].lastChild.objId | ||
| const rebals_task = GET('rebalancer', {data: {last_hop_pubkey: "{{ last_hop_pubkey }}", id__lt: lastId, status: status, limit: "{{ load_count }}"} }) | ||
| build_rebals(rebals_task, rebalsTable, status) | ||
| async function loadRebals_{{status}}(){ | ||
| const status = "{{ status }}" | ||
| const rebalsTable = byId('rebalsTable_' + status) | ||
| const lastId = rebalsTable.tBodies[1].lastChild.objId | ||
| const rebals_task = GET('rebalancer', { data: { last_hop_pubkey: "{{ last_hop_pubkey }}", id__lt: lastId, status: status, limit: "{{ load_count }}" } }) | ||
| build_rebals(rebals_task, rebalsTable, status) | ||
| } | ||
| async function build_rebals(rebals_task, rebalsTable, status) { | ||
| let next_rebals = (await rebals_task).results | ||
| if (next_rebals.length == 0) { | ||
| byId("loadMoreRebals_" + status).style.display = "none" | ||
| return | ||
| } | ||
| async function build_rebals(rebals_task, rebalsTable, status){ | ||
| let next_rebals = (await rebals_task).results | ||
| if(next_rebals.length==0){ | ||
| byId("loadMoreRebals_"+status).style.display = "none" | ||
| return | ||
| } | ||
| const tableBody = rebalsTable.tBodies[1] | ||
| next_rebals.forEach(rebalance => tableBody.append(use(transformations).render(rebalance))) | ||
| const tableBody = rebalsTable.tBodies[1], renderer = use(template) | ||
| for (const rebalance of next_rebals) { | ||
| const tr = renderer.render(rebalance), isRapidFire = rebalance.duration === 1 && target_time !== 1 | ||
| tableBody.append(tr) | ||
| tr.setAttribute(rapidFire, +isRapidFire) | ||
|
|
||
| if(rebalance.status == 2) tr.style.backgroundColor = green | ||
| if(isRapidFire) continue | ||
| var i = tr.rowIndex -2, prev = tableBody.rows[i] | ||
| while(prev && parseInt(prev.getAttribute(rapidFire))){ | ||
| markRapidFire(prev, tr.rowIndex - prev.rowIndex) | ||
| prev = tableBody.rows[--i] | ||
| } | ||
| } | ||
| </script> | ||
| } | ||
| </script> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.