Skip to content

Commit

Permalink
New API version (#562)
Browse files Browse the repository at this point in the history
* Remove useless code + refactoring network's tables

* Contract model changes

* Change opg requests

* Refactoring MenuToolbar + fix code smell

* Review fixes

* Return MetadataTab position

* Fix contractInfo
  • Loading branch information
GusevPM authored Oct 15, 2023
1 parent 5e1d0d5 commit 4888b0d
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 138 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NODE_ENV=development
VUE_APP_API_URI=https://sharm.better-call.dev/v1
VUE_APP_API_URI=https://hope.better-call.dev/v1
VUE_APP_IPFS_NODE=https://cloudflare-ipfs.com/
VUE_APP_SEARCH_SERVICE_URI=https://search.dipdup.net
VUE_APP_TOKEN_METADATA_API=https://metadata.dipdup.net
Expand Down
57 changes: 2 additions & 55 deletions src/api/bcd.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,39 +90,6 @@ export class BetterCallApi {
})
}

getContractOperations(network, address, last_id = "", from = 0, to = 0, statuses = [], entrypoints = [], with_storage_diff = true) {
let params = {}
if (last_id != "") {
params.last_id = last_id
}
if (from !== 0) {
params.from = from
}
if (to !== 0) {
params.to = to
}
if (statuses.length > 0 && statuses.length < 4) {
params.status = statuses.join(',')
}
if (entrypoints.length > 0) {
params.entrypoints = entrypoints.join(',')
}
params.with_storage_diff = with_storage_diff

return getCancellable(this.api, `/contract/${network}/${address}/operations`, {
params: params,
})
.then((res) => {
if (!res) {
return res;
}
if (res.status !== 200) {
throw new RequestFailedError(res);
}
return res.data
})
}

getAccountOperationGroups(network, address, last_id = 0, size = 10) {
let params = {}
if (last_id > 0) {
Expand Down Expand Up @@ -408,19 +375,6 @@ export class BetterCallApi {
});
}

getContractsCount(network) {
return getCancellable(this.api, `/stats/${network}/contracts_count`, {})
.then((res) => {
if (!res) {
return res;
}
if (res.status !== 200) {
throw new RequestFailedError(res);
}
return res.data
});
}

getContractBigMapDiffsCount(network, ptr) {
return getCancellable(this.api, `/bigmap/${network}/${ptr}/count`, {})
.then((res) => {
Expand Down Expand Up @@ -519,10 +473,7 @@ export class BetterCallApi {
if (with_storage_diff) {
params.with_storage_diff = with_storage_diff;
}
if (network) {
params.network = network
}
return getCancellable(this.api, `/opg/${hash}`, {
return getCancellable(this.api, `/opg/${network}/${hash}`, {
params: params,
})
.then((res) => {
Expand Down Expand Up @@ -554,11 +505,7 @@ export class BetterCallApi {
}

getOperationsByHashAndCounter(hash, counter, network=null) {
let params = {};
if (network) {
params['network'] = network;
}
return getCancellable(this.api, `/opg/${hash}/${counter}`, params)
return getCancellable(this.api, `/opg/${network}/${hash}/${counter}`, {})
.then((res) => {
if (res.status != 200) {
throw new RequestFailedError(res);
Expand Down
47 changes: 31 additions & 16 deletions src/components/Tables/GlobalConstantsRegistry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
hide-default-footer
:page.sync="page"
:options="{itemsPerPage}"
no-data-text="No global constants found"
no-results-text="No global constants found"
:server-items-length="constantsNumber"
:footer-props="{
itemsPerPageOptions: []
}"
}"
>
<template v-slot:item="{item}">
<tr class="table-row" :key="item.address">
Expand All @@ -36,10 +39,11 @@
</template>
<template v-slot:footer>
<div class="footer-pagination">
<v-btn icon @click="changePage(page - 1)" :disabled="page === 0">
<span class="caption grey--text mr-2">{{ (page - 1) * itemsPerPage + 1 }} - {{ nextPageCount }} of {{ constantsNumber }}</span>
<v-btn icon @click="changePage(page - 1)" :disabled="page === 1">
<v-icon>mdi-chevron-left</v-icon>
</v-btn>
<v-btn icon @click="changePage(page + 1)" :disabled="isLastPage">
<v-btn icon @click="changePage(page + 1)" :disabled="constantsNumber <= itemsPerPage * page">
<v-icon>mdi-chevron-right</v-icon>
</v-btn>
</div>
Expand All @@ -56,6 +60,7 @@ export default {
name: "GlobalConstantsRegistry",
props: {
network: String,
constantsNumber: Number,
hidePaginationCount: {
type: Boolean,
default: false,
Expand All @@ -71,22 +76,29 @@ export default {
},
methods: {
init() {
this.page = 0
this.globalConstantsItems = [];
if (!this.network)
return;
this.recentlyCalledContracts = [];
this.page = 1;
this.fetchConstants();
},
changePage(newPageNum) {
this.page = newPageNum;
this.fetchConstants();
// previousPage(newPage) {
// const offset = (newPage - 1) * this.itemsPerPage;
// this.changePage(newPage, offset)
// },
// nextPage(newPage) {
// this.changePage(newPage, offset)
// },
changePage(newPage) {
const offset = (newPage - 1) * this.itemsPerPage;
this.page = newPage;
this.fetchConstants(offset);
},
async fetchConstants() {
async fetchConstants(offset = 0) {
this.loadingGlobalConstantsStatus = DATA_LOADING_STATUSES.PROGRESS;
const offset = this.page * this.itemsPerPage;
const constants = await this.api.getGlobalConstants(this.network, offset, this.itemsPerPage);
this.globalConstantsItems = [...constants];
this.isLastPage = this.globalConstantsItems.length < this.itemsPerPage;
this.globalConstantsItems = await this.api.getGlobalConstants(this.network, offset, this.itemsPerPage);
this.loadingGlobalConstantsStatus = DATA_LOADING_STATUSES.SUCCESS;
Expand All @@ -96,6 +108,10 @@ export default {
isGlobalConstantsLoading() {
return this.loadingRecentlyCalledContractsStatus === DATA_LOADING_STATUSES.PROGRESS;
},
nextPageCount() {
const count = this.page * this.itemsPerPage;
return this.constantsNumber > 0 && count < this.constantsNumber ? count : this.constantsNumber;
},
},
watch: {
network: {
Expand All @@ -108,8 +124,7 @@ export default {
data() {
return {
aliasMaxLength: 24,
page: 0,
isLastPage: true,
page: 1,
loadingGlobalConstantsStatus: DATA_LOADING_STATUSES.NOTHING,
globalConstantsTableHeaders: [
{
Expand Down
37 changes: 15 additions & 22 deletions src/components/Tables/RecentlyCalledContracts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
loading-text="Loading recently called contracts... Please wait"
no-data-text="No called contracts found"
no-results-text="No called contracts found"
:server-items-length="totalItems"
:server-items-length="contractsNumber"
:footer-props="{
itemsPerPageOptions: []
}"
Expand All @@ -29,17 +29,17 @@
item.alias.length > aliasMaxLength
? item.alias.slice(0, aliasMaxLength).trim()
: item.alias
}}<em
v-if="item.alias.length > aliasMaxLength"
class="v-icon notranslate mdi mdi-dots-horizontal"
style="font-size: 16px;"
/>
}}
<em v-if="item.alias.length > aliasMaxLength"
class="v-icon notranslate mdi mdi-dots-horizontal"
style="font-size: 16px;"
/>
</span>
<Shortcut v-else :str="item.address"/>
</v-btn>
</td>
<td>
<span class="text--secondary">{{ item.tx_count }}</span>
<span class="text--secondary">{{ item.operations_count }}</span>
</td>
<td>
<span class="text--secondary">{{ helpers.formatDatetime(item.last_action) }}</span>
Expand All @@ -48,11 +48,11 @@
</template>
<template v-slot:footer v-if="pageable">
<div class="footer-pagination">
<span class="caption grey--text mr-2">{{ (page - 1) * itemsPerPage+1 }} - {{ nextPageCount }} of {{ totalItems }}</span>
<v-btn icon @click="changePage(page-1)" :disabled="page === 1">
<span class="caption grey--text mr-2">{{ (page - 1) * itemsPerPage + 1 }} - {{ nextPageCount }} of {{ contractsNumber }}</span>
<v-btn icon @click="changePage(page - 1)" :disabled="page === 1">
<v-icon>mdi-chevron-left</v-icon>
</v-btn>
<v-btn icon @click="changePage(page+1)" :disabled="(totalItems / itemsPerPage) < page">
<v-btn icon @click="changePage(page + 1)" :disabled="contractsNumber <= itemsPerPage * page">
<v-icon>mdi-chevron-right</v-icon>
</v-btn>
</div>
Expand All @@ -67,10 +67,7 @@ export default {
name: "RecentlyCalledContracts",
props: {
network: String,
updateable: {
type: Boolean,
default: true,
},
contractsNumber: Number,
hidePaginationCount: {
type: Boolean,
default: false,
Expand All @@ -90,26 +87,23 @@ export default {
},
nextPageCount() {
const count = this.page * this.itemsPerPage;
return this.totalItems > 0 && count < this.totalItems ? count : this.totalItems;
return this.contractsNumber > 0 && count < this.contractsNumber ? count : this.contractsNumber;
}
},
mounted() {
this.init();
},
methods: {
changePage(page) {
const offset = this.page * this.itemsPerPage;
this.page = page;
changePage(newPage) {
const offset = (newPage - 1) * this.itemsPerPage;
this.page = newPage;
this.requestRecentlyCalledContracts(offset);
},
async init() {
if (!this.network)
return;
this.requestRecentlyCalledContracts();
if (!this.updateable) {
this.totalItems = Number((await this.api.getContractsCount(this.network)));
}
},
requestRecentlyCalledContracts(offset = 0) {
if (this.loading)
Expand Down Expand Up @@ -142,7 +136,6 @@ export default {
return {
aliasMaxLength: 24,
page: 1,
totalItems: -1,
loading: false,
recentlyCalledTableHeaders: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/views/contract/Contract.vue
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export default {
.getContract(this.network, this.address)
.then((res) => {
if (!res) return;
this.contract = res;
this.contract = {...this.contractInfo, ...res};
})
.catch((err) => {
if (err.code === 204) {
Expand Down
15 changes: 11 additions & 4 deletions src/views/contract/InfoSection/ContractInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item v-if="balance">
<v-list-item>
<v-list-item-content>
<v-list-item-subtitle class="overline"
>Balance</v-list-item-subtitle
Expand All @@ -49,13 +49,15 @@
<AccountBox
v-if="contract.manager"
title="Deployed by"
:key="contract.address"
:address="contract.manager"
:network="contract.network"
gutters
/>
<AccountBox
v-if="contract.delegate"
title="Delegated to"
:key="contract.address"
:address="contract.delegate"
:network="contract.network"
gutters
Expand Down Expand Up @@ -104,9 +106,6 @@ export default {
isPaidUsedLoading: true,
paidUsed: null,
}),
mounted() {
this.getInfo();
},
computed: {
isLoading() {
return this.isUsedBytesLoading || this.isPaidUsedLoading
Expand Down Expand Up @@ -134,5 +133,13 @@ export default {
.finally(() => (this.isPaidUsedLoading = false))
},
},
watch: {
address: {
immediate: true,
handler() {
this.getInfo();
},
},
},
};
</script>
Loading

0 comments on commit 4888b0d

Please sign in to comment.