Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#774 | The contract tab keeps selected after the user logs in #774

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 55 additions & 13 deletions src/components/ContractTab/ContractTab.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { ref, computed } from 'vue';
import { ref, computed, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';

import ContractSource from 'components/ContractTab/ContractSource.vue';
import ContractInterface from 'components/ContractTab/ContractInterface.vue';
Expand All @@ -12,9 +13,33 @@ const props = defineProps({
},
});

const source = ref(props.contract.abi?.length > 0);
const route = useRoute();
const router = useRouter();

const source = ref(true);
const write = ref(false);

type TabValue = 'source' | 'read' | 'write';

// Set initial values based on URL query
onMounted(() => {
const subtab = route.query.subtab as string || 'source';
switch (subtab) {
case 'read':
source.value = false;
write.value = false;
break;
case 'write':
source.value = false;
write.value = true;
break;
default:
source.value = true;
write.value = false;
break;
}
});

const verified = computed(() => props.contract.verified);
const abi = computed(() => {
if (!props.contract.abi || !Array.isArray(props.contract.abi)) {
Expand All @@ -27,11 +52,29 @@ const codeSelected = computed(() => source.value === true);
const readSelected = computed(() => source.value === false && write.value === false);
const writeSelected = computed(() => source.value === false && write.value === true);

const selectTab = (tab: TabValue) => {
switch (tab) {
case 'read':
source.value = false;
write.value = false;
break;
case 'write':
source.value = false;
write.value = true;
break;
default:
source.value = true;
write.value = false;
break;
}
router.push({ query: { ...route.query, subtab: tab } });
};

</script>

<template>
<q-card>
<div v-if="abi" :key="contract.address + abi.length" class="c-contract">
<div class="c-contract">
<div v-if="abi" :key="contract.address + abi.length">
<div class="flex justify-between items-center">
<div class="c-contract__tab-container">
<q-btn
Expand All @@ -40,23 +83,23 @@ const writeSelected = computed(() => source.value === false && write.value === t
'c-contract__tab': true,
'c-contract__tab--active': codeSelected,
}"
@click="source = true; write = false"
@click="selectTab('source')"
/>
<q-btn
:label="$t('components.contract_tab.read')"
:class="{
'c-contract__tab': true,
'c-contract__tab--active': readSelected,
}"
@click="source = false; write = false"
@click="selectTab('read')"
/>
<q-btn
:label="$t('components.contract_tab.write')"
:class="{
'c-contract__tab': true,
'c-contract__tab--active': writeSelected,
}"
@click="source = false; write = true"
@click="selectTab('write')"
/>
</div>
<CopyButton
Expand All @@ -72,29 +115,28 @@ const writeSelected = computed(() => source.value === false && write.value === t
:contract="contract"
/>
</div>
</q-card>

</div>
</template>

<style lang='scss' scoped>
.c-contract{
.c-contract {
padding-top: 1rem;
padding-left: 1rem;
padding-right: 1rem;

&__tab-container{
&__tab-container {
display: inline-flex;
gap: .5rem;
}

&__tab{
&__tab {
cursor: pointer;
border-radius: 5px;
color: var(--text-color);
text-transform: capitalize !important;
background-color: var(--tab-bg-color);

&:hover{
&:hover {
color: var(--text-color);
}

Expand Down
Loading