Skip to content

Commit

Permalink
Fix: value inspector for rollup (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored Jul 20, 2023
1 parent 997fce1 commit 62e4238
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/components/ValueInspector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<script>
import Michelson from "@/components/Michelson.vue";
import isIpfs from "is-ipfs";
import { checkAddress } from "@/utils/tz.js";
import { checkAddress, matchAddress, isSrAddress } from "@/utils/tz.js";
import {mapActions} from "vuex";
export default {
Expand Down Expand Up @@ -118,7 +118,7 @@ export default {
checkAddress(this.value.slice("tezos-storage://".length));
},
isAddress() {
return this.prim === "address" || this.prim === "contract";
return (this.prim === "address" || this.prim === "contract") && !isSrAddress(this.value) ;
},
},
methods: {
Expand All @@ -136,7 +136,7 @@ export default {
}
},
handleAddress(span) {
const address = span.match(/(tz|KT)[1-9A-HJ-NP-Za-km-z]{34}/)[0];
const address = matchAddress(span);
const path = { path: `/${this.network}/${address}` };
if (this.sameTab) {
this.$router.push(path);
Expand All @@ -145,8 +145,11 @@ export default {
}
},
handleStorage(value) {
const address = value.match(/(KT)[1-9A-HJ-NP-Za-km-z]{34}/)[0];
const path = { path: `/${this.network}/${address}/storage` };
const address = value.match(/(KT)[1-9A-HJ-NP-Za-km-z]{34}/);
if (!address) {
return
}
const path = { path: `/${this.network}/${address[0]}/storage` };
if (this.sameTab) {
this.$router.push(path);
} else {
Expand Down
18 changes: 15 additions & 3 deletions src/utils/tz.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function shortcut(value, tail = 4) {
if (!value) return '';

let head = 0;
if (value.startsWith('tz') || value.startsWith('KT')) {
if (value.startsWith('tz') || value.startsWith('KT') || value.startsWith('sr1')) {
head = 3
} else if (value.startsWith('o')) {
head = 1;
Expand All @@ -54,7 +54,7 @@ export function shortcutOnly(value, tail = 4) {
if (!value) return '';

let head = 0;
if (value.startsWith('tz') || value.startsWith('KT')) {
if (value.startsWith('tz') || value.startsWith('KT') || value.startsWith('sr1')) {
head = 7;
} else if (value.startsWith('o')) {
head = 1;
Expand Down Expand Up @@ -162,6 +162,18 @@ export let validationRules = {
],
address: [
v => (v && v.length == 36) || 'The length of the address is 36 characters',
v => isTzAddress(v) || isKT1Address(v) || isSrAddress(v) || 'In this field you should write the address'
v => isAddress(v) || 'In this field you should write the address'
]
}

export function matchAddress(text) {
let matches = text.match(/(tz|KT|sr)[1-9A-HJ-NP-Za-km-z]{34}/);
if (!matches) {
return '';
}
return matches[0];
}

export function isAddress(v) {
return isTzAddress(v) || isKT1Address(v) || isSrAddress(v);
}

0 comments on commit 62e4238

Please sign in to comment.