Skip to content

Commit

Permalink
Big map search (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored Jul 7, 2022
1 parent 6f95eb1 commit 04a4bc8
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 163 deletions.
11 changes: 11 additions & 0 deletions src/api/bcd.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,17 @@ export class BetterCallApi {
})
}

getBigMapKeyState(network, ptr, key_hash) {
return getCancellable(this.api, `/bigmap/${network}/${ptr}/keys/${key_hash}/state`, {})
.then((res) => {
if (!res) { return res; }
if (res.status != 200) {
throw new RequestFailedError(res);
}
return res.data
})
}

getContractBigMapKeys(network, ptr, q = '', offset = 0) {
return getCancellable(this.api, `/bigmap/${network}/${ptr}/keys?q=${q}&offset=${offset}`, {})
.then((res) => {
Expand Down
15 changes: 13 additions & 2 deletions src/api/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class SearchService {
};
return this.api.post(
`/v1/search`, request

).then(this.parseResponse)
}

Expand All @@ -36,7 +35,19 @@ export class SearchService {
}
return this.api.post(
`/v1/search`, request

).then(this.parseResponse)
}

bigMapKeys(text, filters, size = 0, offset = 0) {
return this.api.post(
`/v1/search`, {
query: text,
size: size ? size : 10,
offset: offset,
filters: {
big_maps: filters,
}
}
).then(this.parseResponse)
}

Expand Down
3 changes: 2 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,15 @@ Vue.filter('snakeToCamel', (str) => {
let config = {
API_URI: process.env.VUE_APP_API_URI || `${window.location.protocol}//${window.location.host}/v1`,
HOME_PAGE: 'home',
SEARCH_SERVICE_URI: process.env.SEARCH_SERVICE_URI || 'https://search.dipdup.net'
TOKEN_METADATA_API: process.env.TOKEN_METADATA_API || "https://metadata.dipdup.net",
IPFS_NODE: process.env.IPFS_NODE || "https://ipfs.io",
METADATA_API_URI: process.env.METADATA_API_URI || "https://metadata.dipdup.net"
}

let api = new BetterCallApi(config.API_URI);
let bookmarks = new Bookmarks();
let searchService = new SearchService(process.env.SEARCH_SERVICE_URI || 'https://search.dipdup.net')
let searchService = new SearchService(config.SEARCH_SERVICE_URI);
let tokenMetadata = new TokenMetadataApi(config.TOKEN_METADATA_API);
let metadataAPI = new MetadataAPI(config.METADATA_API_URI);

Expand Down
86 changes: 33 additions & 53 deletions src/views/big_map/BigMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item v-if="!isNaN(totalBytes)">
<v-list-item-content>
<v-list-item-subtitle class="overline">Total size</v-list-item-subtitle>
<v-list-item-title class="body-2">
<span>{{ parseInt(totalBytes).toLocaleString('en-US') }} bytes</span>
</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item>
<v-list-item-content>
<v-list-item-subtitle class="overline">Active / total keys</v-list-item-subtitle>
Expand All @@ -28,63 +36,24 @@
</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item v-if="!isNaN(totalBytes)">
<v-list-item v-if="bigmap.typedef">
<v-list-item-content>
<v-list-item-subtitle class="overline">Total size</v-list-item-subtitle>
<v-list-item-title class="body-2">
<span>{{ parseInt(totalBytes).toLocaleString('en-US') }} bytes</span>
<v-list-item-subtitle class="overline">Type</v-list-item-subtitle>
<v-list-item-title>
<TypeDef
:typedef="bigmap.typedef"
:first="bigMapName"
style="opacity: 1"
/>
</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
<v-list class="bigmap-sidebar-list mt-2">
<template v-for="(item, idx) in actions">
<v-divider v-if="idx > 0" :key="'divider' + idx"></v-divider>
<v-list-item :key="idx">
<v-list-item-content>
<v-list-item-title class="hash">
<span class="mr-2">{{ item.action }}</span>
<template v-if="item.action == 'copy'">
<span
class="text--secondary font-weight-light"
v-if="item.destination_ptr"
>to</span>
<span
class="text--secondary font-weight-light"
v-else-if="item.source_ptr"
>from</span>
</template>
</v-list-item-title>
<v-list-item-subtitle>
<span class="overline">{{ helpers.formatDatetime(item.timestamp) }}</span>
</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-list-item-action-text v-if="item.action == 'copy'">
<v-btn
:to="`/${network}/big_map/${item.destination_ptr}`"
class="text--primary"
text
small
v-if="item.destination_ptr"
>
<v-icon small class="mr-1 text--secondary">mdi-link-variant</v-icon>
Big Map {{ item.destination_ptr }}
</v-btn>
<v-btn
:to="`/${network}/big_map/${item.source_ptr}`"
class="text--primary"
text
small
v-else-if="item.source_ptr"
>
<v-icon small class="mr-1 text--secondary">mdi-link-variant</v-icon>
Big Map {{ item.source_ptr }}
</v-btn>
</v-list-item-action-text>
</v-list-item-action>
</v-list-item>
</template>
<v-list class="bigmap-sidebar-list mt-2" v-if="actions.length > 0">
<div v-for="(item, idx) in actions" :key="idx">
<v-divider v-if="idx > 0"></v-divider>
<BigMapAction :item="item"/>
</div>
</v-list>
</v-col>
</v-row>
Expand All @@ -94,13 +63,19 @@
<script>
import { mapActions } from "vuex";
import {shortcutOnly} from "../../utils/tz";
import BigMapAction from '@/views/big_map/BigMapAction.vue';
import TypeDef from "@/views/contract/TypeDef.vue";
export default {
name: "BigMap",
props: {
network: String,
ptr: String,
},
components: {
BigMapAction,
TypeDef
},
computed: {
keyhash() {
return this.$route.params.keyhash;
Expand All @@ -111,6 +86,12 @@ export default {
address() {
return this.bigmap.address;
},
bigMapName() {
if (this.bigmap.typedef && this.bigmap.typedef[0]) {
return this.bigmap.typedef[0].name || 'bigmap'
}
return 'bigmap';
}
},
data: () => ({
bigmap: {},
Expand Down Expand Up @@ -143,7 +124,6 @@ export default {
this.api
.getContractBigMapActions(this.network, this.ptr)
.then((res) => {
console.log('res: ', res);
if (!res) return;
if (!res.items) return;
this.actions = res.items;
Expand Down
55 changes: 55 additions & 0 deletions src/views/big_map/BigMapAction.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<template>
<v-list-item>
<v-list-item-content>
<v-list-item-title class="hash">
<span class="mr-2">{{ item.action }}</span>
<template v-if="item.action == 'copy'">
<span
class="text--secondary font-weight-light"
v-if="item.destination_ptr"
>to</span>
<span
class="text--secondary font-weight-light"
v-else-if="item.source_ptr"
>from</span>
</template>
</v-list-item-title>
<v-list-item-subtitle>
<span class="overline">{{ helpers.formatDatetime(item.timestamp) }}</span>
</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-list-item-action-text v-if="item.action == 'copy'">
<v-btn
:to="`/${network}/big_map/${item.destination_ptr}`"
class="text--primary"
text
small
v-if="item.destination_ptr"
>
<v-icon small class="mr-1 text--secondary">mdi-link-variant</v-icon>
Big Map {{ item.destination_ptr }}
</v-btn>
<v-btn
:to="`/${network}/big_map/${item.source_ptr}`"
class="text--primary"
text
small
v-else-if="item.source_ptr"
>
<v-icon small class="mr-1 text--secondary">mdi-link-variant</v-icon>
Big Map {{ item.source_ptr }}
</v-btn>
</v-list-item-action-text>
</v-list-item-action>
</v-list-item>
</template>

<script>
export default {
name: "BigMapAction",
props: {
item: Object
}
}
</script>
Loading

0 comments on commit 04a4bc8

Please sign in to comment.