Skip to content

Commit

Permalink
Feature: repeat operation (#435)
Browse files Browse the repository at this point in the history
* Feature: repeat operation

* Fixes
  • Loading branch information
aopoltorzhicky authored Jul 7, 2022
1 parent 2601210 commit e126169
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/api/bcd.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,23 @@ export class BetterCallApi {
})
}

getContractEntrypointSchema(network, address, entrypoint, fill_type = 'empty') {
return this.api.get(`/contract/${network}/${address}/entrypoints/schema?fill_type=${fill_type}&entrypoint=${entrypoint}`)
getContractEntrypointSchema(network, address, entrypoint, fill_type = 'empty', hash = undefined, counter = undefined) {
let params = {}
if (fill_type) {
params['fill_type'] = fill_type;
}
if (entrypoint) {
params['entrypoint'] = entrypoint;
}
if (hash) {
params['hash'] = hash;
}
if (counter) {
params['counter'] = counter;
}
return this.api.get(`/contract/${network}/${address}/entrypoints/schema`, {
params: params,
})
.then((res) => {
if (res.status !== 200) {
throw new RequestFailedError(res);
Expand Down
32 changes: 32 additions & 0 deletions src/components/InternalOperation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,31 @@
<InfoItem title="Storage limit" :subtitle="(data.storage_limit) || 0 | bytes" />
</v-col>
<v-col cols="2" v-if="address" class="py-0 d-flex justify-end align-center">
<v-tooltip top v-if="isReplayable">
<template v-slot:activator="{ on }">
<v-btn
v-on="on"
icon
target="_blank"
class="mr-2 text--secondary"
:to="{
name: 'interact',
params: {
network: data.network,
address: data.destination,
entrypoint: data.entrypoint,
},
query: {
hash: data.hash,
counter: data.counter
}
}"
>
<v-icon>mdi-repeat</v-icon>
</v-btn>
</template>
<span>Repeat operation group</span>
</v-tooltip>
<v-tooltip top>
<template v-slot:activator="{ on }">
<v-btn v-on="on" icon class="mr-2 text--secondary" @click="showRaw = true">
Expand Down Expand Up @@ -352,6 +377,13 @@ export default {
}
return val;
},
isReplayable() {
return !this.data.mempool &&
this.data.hash &&
this.data.destination &&
this.data.entrypoint &&
this.data.status === 'applied';
}
},
methods: {
...mapActions(["showClipboardOK", "showError"]),
Expand Down
6 changes: 6 additions & 0 deletions src/components/schema/Schema.vue
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,12 @@ export default {
},
},
watch: {
value: {
deep: true,
handler: function(newValue) {
this.model = newValue;
}
},
execution: function (newValue) {
if (newValue) {
this.injectedOpHash = null;
Expand Down
1 change: 0 additions & 1 deletion src/components/schema/schemaForm/SchemaForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ name: "SchemaForm",
if (value.length == 0) {
return 'Nat field is required';
}
console.log(value);
let nat = parseInt(value);
if (nat < 0) {
return 'Nat must be positive';
Expand Down
28 changes: 27 additions & 1 deletion src/views/contract/InteractTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
:name="selectedItem.name"
:network="network"
:address="address"
:alias="contract.alias"
:alias="contract && contract.alias ? contract.alias : ''"
/>
<div v-else></div>
</v-skeleton-loader>
Expand Down Expand Up @@ -72,6 +72,7 @@
<script>
import { mapActions } from "vuex";
import { applyStyles } from '@/utils/styles.js';
import { isOperationHash } from '@/utils/tz.js';
import Schema from "@/components/schema/Schema.vue";
import TypeDef from "@/views/contract/TypeDef";
Expand All @@ -91,6 +92,8 @@ export default {
selected: -1,
model: {},
contract: null,
hash: undefined,
counter: undefined
}),
computed: {
isShareable() {
Expand All @@ -108,13 +111,36 @@ export default {
},
},
created() {
this.hash = this.$route.query.hash;
this.counter = this.$route.query.counter;
const entrypoint = this.$route.params.entrypoint || this.$route.query.entrypoint;
this.api
.getContract(this.network, this.address)
.then((contract) => {
this.contract = contract;
});
this.getEntrypoints(entrypoint);
if (this.$route.query.hash && isOperationHash(this.$route.query.hash) && this.$route.query.counter) {
this.api.
getContractEntrypointSchema(
this.network,
this.address,
entrypoint,
'operation',
this.$route.query.hash,
this.$route.query.counter)
.then(res=> {
let withoutName = res.default_model[entrypoint];
if (typeof withoutName === 'object' && !Array.isArray(withoutName))
this.model = withoutName;
else this.model = res.default_model;
})
.catch(err => {
console.log(err)
})
}
},
destroyed() {
this.$router.push({path: this.$route.path, query: { ...this.$route.query, entrypoint: undefined }})
Expand Down

0 comments on commit e126169

Please sign in to comment.