Skip to content

Commit

Permalink
Add tickets tab (#522)
Browse files Browse the repository at this point in the history
* Add tickets tab

* Fix: html injection

* Tickets tab order

* Some beautifies
  • Loading branch information
aopoltorzhicky authored Apr 28, 2023
1 parent f680bde commit 0fbb4b6
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/api/bcd.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,4 +738,17 @@ export class BetterCallApi {
return this.api.post(`/helpers/approve/data`, data)
.then(this.returnResponseData);
}

listTicketUpdates(network, address, offset, size=10) {
let params = {
size
}

if (offset > 0) {
params['offset'] = offset
}

return this.api.get(`/contract/${network}/${address}/ticket_updates`, {params})
.then(this.returnResponseData);
}
}
7 changes: 7 additions & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import TransfersTab from '@/views/contract/TransfersTab/TransfersTab.vue'
import MetadataTab from '@/views/contract/MetadataTab/MetadataTab.vue'
import ForkTab from '@/views/contract/ForkTab.vue'
import EventsTab from '@/views/contract/EventsTab/EventsTab.vue'
import TicketTab from '@/views/contract/TicketTab/TicketTab.vue'

import OperationGroup from '@/views/opg/OperationGroup.vue'
import OpgContents from '@/views/opg/ContentsTab.vue'
Expand Down Expand Up @@ -164,6 +165,12 @@ export function newRouter(networks) {
component: EventsTab,
props: true
},
{
path: 'ticket_updates',
name: 'ticket_updates',
component: TicketTab,
props: true
},
{
path: 'interact/:entrypoint?',
name: 'interact',
Expand Down
3 changes: 3 additions & 0 deletions src/views/contract/MenuToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
>
<v-icon left small>mdi-transfer</v-icon>Transfers
</v-tab>
<v-tab :to="pushTo({ name: 'ticket_updates' })" replace v-if="contract.has_ticket_updates">
<v-icon left small>mdi-ticket-outline</v-icon>Tickets
</v-tab>
<v-tab
:to="pushTo({ name: 'metadata' })"
replace
Expand Down
169 changes: 169 additions & 0 deletions src/views/contract/TicketTab/TicketTab.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<template>
<v-container class="canvas fill-canvas pa-8 ma-0" fluid>
<v-row class="px-8 pt-4">
<v-col cols="3" class="pl-4">
<v-list-item-group v-model="selected" class="pt-0 pb-0 themed-border radius-1" mandatory>
<template v-for="(update, idx) in updates">
<v-list-item :key="idx">
<v-list-item-content>
<v-list-item-title>
<Shortcut :str="update.address"/>&nbsp;
<span class="text--secondary">with amount</span>&nbsp;
<span class="text--primary">{{ update.amount }}</span>
</v-list-item-title>
<v-list-item-subtitle class="text--secondary">{{ update.timestamp | fromNow }}</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-divider v-if="idx !== updates.length -1" :key="'d' + idx"></v-divider>
</template>
</v-list-item-group>
</v-col>
<v-col cols="9" class="pr-4">
<v-card class="sticky-card" flat outlined width="95%" v-if="item">
<v-card-text class="data pa-0 pb-0">
<v-list class="py-0">
<v-list-item two-line :to="`/${network}/${item.ticketer}`" exact>
<v-list-item-avatar>
<v-icon class="text--secondary">mdi-ticket-confirmation</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>Ticketer</v-list-item-title>
<v-list-item-subtitle class="hash">
{{ item.ticketer }}
</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action class="justify-end">
<v-list-item-action-text class="caption">{{ item.timestamp | formatShortTime}}</v-list-item-action-text>
<v-list-item-action-text class="caption">Block {{ item.level }}</v-list-item-action-text>
</v-list-item-action>
</v-list-item>
<v-list-item two-line exact :to="`/${network}/${item.address}`">
<v-list-item-avatar>
<v-icon class="text--secondary">mdi-wallet-outline</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>Account</v-list-item-title>
<v-list-item-subtitle class="hash">
{{ item.address }}
</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-list-item two-line>
<v-list-item-avatar>
<v-icon class="text--secondary">mdi-circle-multiple-outline</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>Amount</v-list-item-title>
<v-list-item-subtitle class="hash">
{{ item.amount }}
</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-list-item two-line exact :to="`/${network}/opg/${item.operation_hash}`">
<v-list-item-avatar>
<v-icon class="text--secondary">mdi-swap-horizontal</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>Operation Hash</v-list-item-title>
<v-list-item-subtitle>
{{ item.operation_hash }}
</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
</v-list>
<v-divider></v-divider>
<v-row no-gutters>
<v-col cols="6">
<TypeDef
:typedef="item.content_type"
first="ticket type"
class="pt-6 px-6 pb-5"
style="opacity: 0.8"
/>
</v-col>
<v-divider cols="1" vertical></v-divider>
<v-col cols="5">
<MiguelTreeView
class="pt-6 pb-5"
:address="address"
:miguel="item.content"
:network="network"
openAll />
</v-col>
</v-row>
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-container>
</template>

<script>
import { mapActions } from "vuex";
import MiguelTreeView from "@/components/MiguelTreeView.vue";
import TypeDef from "@/views/contract/TypeDef.vue";
import Shortcut from "@/components/Shortcut.vue";
export default {
name: "TicketTab",
props: {
network: String,
address: String
},
components: {
MiguelTreeView,
TypeDef,
Shortcut
},
computed: {
item() {
if (!this.updates || this.updates.length === 0) return null;
return this.updates[this.selected];
}
},
data: () => ({
loading: false,
updates: [],
selected: 0
}),
methods: {
...mapActions(["showError", "hideError"]),
async listTicketUpdates(network, address) {
if (this.loading) return;
this.loading = true;
this.api.listTicketUpdates(network, address, this.updates.length, 10)
.then(result => {
this.updates.push(...result);
})
.catch(err => {
console.log(err);
this.showError(err);
})
.finally(() => {this.loading = false;})
}
},
mounted () {
this.listTicketUpdates(this.network, this.address)
},
watch: {
'address': function(newAddress){
this.updates = [];
this.loading = false;
this.listTicketUpdates(this.network, newAddress);
},
'network': function(newNetwork){
this.updates = [];
this.loading = false;
this.listTicketUpdates(newNetwork, this.address);
}
}
}
</script>

<style scoped>
.sticky-card {
position: sticky;
top: 100px;
}
</style>

0 comments on commit 0fbb4b6

Please sign in to comment.