add lxmf ticket expiry to stamp info dialog

This commit is contained in:
liamcottle 2024-09-26 16:42:13 +12:00
commit 3dfcab4857
2 changed files with 35 additions and 17 deletions

View file

@ -1083,20 +1083,29 @@ class ReticulumMeshChat:
})
# get lxmf stamp cost for the provided lxmf.delivery destination hash
@routes.get("/api/v1/destination/{destination_hash}/lxmf-stamp-cost")
@routes.get("/api/v1/destination/{destination_hash}/lxmf-stamp-info")
async def index(request):
# get path params
destination_hash = request.match_info.get("destination_hash", "")
# convert destination hash to bytes
destination_hash = bytes.fromhex(destination_hash)
# get lxmf stamp cost from announce in database
lxmf_stamp_cost = None
announce = database.Announce.get_or_none(database.Announce.destination_hash == destination_hash)
announce = database.Announce.get_or_none(database.Announce.destination_hash == destination_hash.hex())
if announce is not None:
lxmf_stamp_cost = self.parse_lxmf_stamp_cost(announce.app_data)
# get outbound ticket expiry for this lxmf destination
lxmf_outbound_ticket_expiry = self.message_router.get_outbound_ticket_expiry(destination_hash)
return web.json_response({
"lxmf_stamp_cost": lxmf_stamp_cost,
"lxmf_stamp_info": {
"stamp_cost": lxmf_stamp_cost,
"outbound_ticket_expiry": lxmf_outbound_ticket_expiry,
},
})
# get interface stats

View file

@ -20,7 +20,7 @@
<div class="text-sm">
<{{ selectedPeer.destination_hash }}>
<span v-if="selectedPeerPath" @click="onDestinationPathClick(selectedPeerPath)" class="cursor-pointer">{{ selectedPeerPath.hops }} {{ selectedPeerPath.hops === 1 ? 'hop' : 'hops' }} away</span>
<span v-if="selectedPeerLxmfStampCost"> • <span @click="onStampCostClick(selectedPeerLxmfStampCost)" class="cursor-pointer">Stamp Cost {{ selectedPeerLxmfStampCost }}</span></span>
<span v-if="selectedPeerLxmfStampInfo && selectedPeerLxmfStampInfo.stamp_cost"> • <span @click="onStampInfoClick(selectedPeerLxmfStampInfo)" class="cursor-pointer">Stamp Cost {{ selectedPeerLxmfStampInfo.stamp_cost }}</span></span>
</div>
</div>
@ -369,6 +369,7 @@ import DialogUtils from "../../js/DialogUtils";
import NotificationUtils from "../../js/NotificationUtils";
import WebSocketConnection from "../../js/WebSocketConnection";
import AddAudioButton from "./AddAudioButton.vue";
import moment from "moment";
export default {
name: 'ConversationViewer',
@ -384,7 +385,7 @@ export default {
return {
selectedPeerPath: null,
selectedPeerLxmfStampCost: null,
selectedPeerLxmfStampInfo: null,
lxmfMessagesRequestSequence: 0,
chatItems: [],
@ -460,7 +461,7 @@ export default {
}
this.getPeerPath();
this.getPeerLxmfStampCost();
this.getPeerLxmfStampInfo();
// load 1 page of previous messages
await this.loadPrevious();
@ -530,9 +531,9 @@ export default {
const json = JSON.parse(message.data);
switch(json.type){
case 'announce': {
// update stamp cost if an announce is received from the selected peer
// update stamp info if an announce is received from the selected peer
if(json.announce.destination_hash === this.selectedPeer?.destination_hash){
await this.getPeerLxmfStampCost();
await this.getPeerLxmfStampInfo();
}
break;
}
@ -641,19 +642,19 @@ export default {
}
},
async getPeerLxmfStampCost() {
async getPeerLxmfStampInfo() {
// clear previous stamp cost
this.selectedPeerLxmfStampCost = null;
// clear previous stamp info
this.selectedPeerLxmfStampInfo = null;
if(this.selectedPeer){
try {
// get lxmf stamp cost
const response = await window.axios.get(`/api/v1/destination/${this.selectedPeer.destination_hash}/lxmf-stamp-cost`);
// get lxmf stamp info
const response = await window.axios.get(`/api/v1/destination/${this.selectedPeer.destination_hash}/lxmf-stamp-info`);
// update ui
this.selectedPeerLxmfStampCost = response.data.lxmf_stamp_cost;
this.selectedPeerLxmfStampInfo = response.data.lxmf_stamp_info;
} catch(e) {
console.log(e);
@ -664,7 +665,10 @@ export default {
onDestinationPathClick(path) {
DialogUtils.alert(`${path.hops} ${ path.hops === 1 ? 'hop' : 'hops' } away via ${path.next_hop_interface}`);
},
onStampCostClick(stampCost) {
onStampInfoClick(stampInfo) {
const stampCost = stampInfo.stamp_cost;
const outboundTicketExpiry = stampInfo.outbound_ticket_expiry;
// determine estimated time to generate a stamp
var estimatedTimeForStamp = "";
@ -688,9 +692,14 @@ export default {
estimatedTimeForStamp = "0 seconds";
}
DialogUtils.alert(`This peer has enabled stamp security.\n\nYour device must solve an automated proof of work task each time you send them a message.\n\nTime per message: ${estimatedTimeForStamp}`);
// check if we have an outbound ticket available
if(outboundTicketExpiry != null){
estimatedTimeForStamp = `instant (ticket expires ${moment(outboundTicketExpiry * 1000).fromNow()})`;
}
},
DialogUtils.alert(`This peer has enabled stamp security.\n\nYour device must have a ticket, or solve an automated proof of work task each time you send them a message.\n\nTime per message: ${estimatedTimeForStamp}`);
},
scrollMessagesToBottom: function() {
// next tick waits for the ui to have the new elements added
this.$nextTick(() => {