86 lines
2.0 KiB
Vue
86 lines
2.0 KiB
Vue
<template>
|
|
<div class="address">
|
|
<hash-badge :address="address" class="hash-badge"/>
|
|
<a v-if="isFile" :href="`/api/raw/${address}`">{{ address }}</a>
|
|
<template v-else>
|
|
<router-link v-if="link" :to="{ name: 'inspect', params: { address } }">
|
|
{{ inferredId || address }}
|
|
</router-link>
|
|
<template v-else>{{ inferredId || address }}</template>
|
|
</template>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import { ListingResult } from "@/types/base";
|
|
import { fetcher } from "@/utils";
|
|
import useSWRV from "swrv";
|
|
import { computed, defineComponent } from "vue";
|
|
import HashBadge from "./HashBadge.vue";
|
|
|
|
export default defineComponent({
|
|
components: { HashBadge },
|
|
name: "Address",
|
|
props: {
|
|
address: String,
|
|
link: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
isFile: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
resolve: {
|
|
type: Boolean,
|
|
default: true
|
|
}
|
|
},
|
|
setup(props) {
|
|
const { data: addressEntries } = useSWRV<ListingResult, unknown>(
|
|
() => `/api/obj/${props.address}`,
|
|
fetcher
|
|
);
|
|
|
|
const { data: typeId } = useSWRV<ListingResult, unknown>(() => {
|
|
if (!props.isFile && props.resolve) {
|
|
const entries = Object.values(addressEntries?.value || {});
|
|
const isEntry = entries.find(
|
|
(entry) => entry.entity === props.address && entry.attribute === "IS"
|
|
);
|
|
if (isEntry) {
|
|
return `/api/obj?query=(matches "${isEntry.value.c}" "TYPE_ID" ?)`;
|
|
}
|
|
}
|
|
return null;
|
|
}, fetcher);
|
|
|
|
const inferredId = computed(() => {
|
|
const typeIdValue = Object.values(typeId?.value || {})[0];
|
|
if (typeIdValue) {
|
|
return Object.values(addressEntries?.value || []).find(
|
|
(entry) =>
|
|
entry.entity === props.address &&
|
|
entry.attribute === typeIdValue.value.c
|
|
)?.value.c;
|
|
}
|
|
});
|
|
|
|
return {
|
|
inferredId,
|
|
};
|
|
},
|
|
});
|
|
</script>
|
|
|
|
<style scoped>
|
|
.address {
|
|
font-family: var(--monospace-font);
|
|
display: flex;
|
|
}
|
|
|
|
.hash-badge {
|
|
margin-right: .5em;
|
|
}
|
|
</style>
|