Skip to content

Commit

Permalink
chore: ParamXXXEditor vues now uses <script setup> syntax (#1524)
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Le Ponner <[email protected]>
  • Loading branch information
ericleponner authored Nov 28, 2024
1 parent bf0f0fb commit b973c62
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 128 deletions.
63 changes: 26 additions & 37 deletions src/components/values/abi/ParamBooleanEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,52 +30,41 @@
<!-- SCRIPT -->
<!-- --------------------------------------------------------------------------------------------------------------- -->

<script lang="ts">
<script setup lang="ts">
import {computed, defineComponent, onBeforeUnmount, onMounted, PropType, ref, watch, WatchStopHandle} from "vue";
import {computed, onBeforeUnmount, onMounted, PropType, ref, watch, WatchStopHandle} from "vue";
import {ContractParamBuilder} from "@/components/values/abi/ContractCallBuilder";
import {AppStorage} from "@/AppStorage";
export default defineComponent({
name: "ParamBooleanEditor",
components: {},
props: {
paramBuilder: {
type: Object as PropType<ContractParamBuilder>,
required: true
},
const props = defineProps({
paramBuilder: {
type: Object as PropType<ContractParamBuilder>,
required: true
},
setup(props) {
const checked = ref<boolean>(false)
const lastParamData = computed(() => {
const functionHash = props.paramBuilder.callBuilder.fragment.selector
const paramName = props.paramBuilder.paramType.name
return AppStorage.getInputParam(functionHash, paramName)
})
let watchHandle: WatchStopHandle | null = null
onMounted(() => {
checked.value = !!lastParamData.value
watchHandle = watch(checked, () => {
props.paramBuilder.paramData.value = checked.value
}, {immediate: true})
})
onBeforeUnmount(() => {
if (watchHandle !== null) {
watchHandle()
watchHandle = null
}
props.paramBuilder.paramData.value = null
checked.value = false
})
})
return {
checked
}
const checked = ref<boolean>(false)
const lastParamData = computed(() => {
const functionHash = props.paramBuilder.callBuilder.fragment.selector
const paramName = props.paramBuilder.paramType.name
return AppStorage.getInputParam(functionHash, paramName)
})
let watchHandle: WatchStopHandle | null = null
onMounted(() => {
checked.value = !!lastParamData.value
watchHandle = watch(checked, () => {
props.paramBuilder.paramData.value = checked.value
}, {immediate: true})
})
onBeforeUnmount(() => {
if (watchHandle !== null) {
watchHandle()
watchHandle = null
}
props.paramBuilder.paramData.value = null
checked.value = false
})
</script>
Expand Down
28 changes: 9 additions & 19 deletions src/components/values/abi/ParamJsonEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,29 @@

<template>
<button class="button is-white h-is-smaller" @click="jsonEditorController.visible.value = true">EDIT…</button>
<JsonEditorDialog :controller="jsonEditorController" :param-builder="paramBuilder"/>
<JsonEditorDialog :controller="jsonEditorController" :param-builder="props.paramBuilder"/>
</template>

<!-- --------------------------------------------------------------------------------------------------------------- -->
<!-- SCRIPT -->
<!-- --------------------------------------------------------------------------------------------------------------- -->

<script lang="ts">
<script setup lang="ts">
import {defineComponent, PropType} from "vue";
import {PropType} from "vue";
import {ContractParamBuilder} from "@/components/values/abi/ContractCallBuilder";
import {DialogController} from "@/components/dialog/DialogController";
import JsonEditorDialog from "@/components/values/abi/JsonEditorDialog.vue";
export default defineComponent({
name: "ParamJsonEditor",
components: {JsonEditorDialog},
props: {
paramBuilder: {
type: Object as PropType<ContractParamBuilder>,
required: true
},
const props = defineProps({
paramBuilder: {
type: Object as PropType<ContractParamBuilder>,
required: true
},
setup() {
const jsonEditorController = new DialogController()
return {
jsonEditorController
}
}
})
const jsonEditorController = new DialogController()
</script>

<!-- --------------------------------------------------------------------------------------------------------------- -->
Expand Down
61 changes: 26 additions & 35 deletions src/components/values/abi/ParamTextEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,50 +30,41 @@
<!-- SCRIPT -->
<!-- --------------------------------------------------------------------------------------------------------------- -->

<script lang="ts">
<script setup lang="ts">
import {computed, defineComponent, onBeforeUnmount, onMounted, PropType, ref, watch, WatchStopHandle} from "vue";
import {computed, onBeforeUnmount, onMounted, PropType, ref, watch, WatchStopHandle} from "vue";
import {ContractParamBuilder} from "@/components/values/abi/ContractCallBuilder";
import {AppStorage} from "@/AppStorage";
export default defineComponent({
name: "ParamTextEditor",
components: {},
props: {
paramBuilder: {
type: Object as PropType<ContractParamBuilder>,
required: true
},
const props = defineProps({
paramBuilder: {
type: Object as PropType<ContractParamBuilder>,
required: true
},
setup(props) {
const currentText = ref<string>("")
})
const lastParamData = computed(() => {
const functionHash = props.paramBuilder.callBuilder.fragment.selector
const paramName = props.paramBuilder.paramType.name
return AppStorage.getInputParam(functionHash, paramName)
})
const currentText = ref<string>("")
let watchHandle: WatchStopHandle | null = null
onMounted(() => {
currentText.value = lastParamData.value?.toString() ?? ""
watchHandle = watch(currentText, () => {
props.paramBuilder.paramData.value = currentText.value
}, {immediate: true})
})
onBeforeUnmount(() => {
if (watchHandle !== null) {
watchHandle()
watchHandle = null
}
props.paramBuilder.paramData.value = null
currentText.value = ""
})
const lastParamData = computed(() => {
const functionHash = props.paramBuilder.callBuilder.fragment.selector
const paramName = props.paramBuilder.paramType.name
return AppStorage.getInputParam(functionHash, paramName)
})
return {
currentText
}
let watchHandle: WatchStopHandle | null = null
onMounted(() => {
currentText.value = lastParamData.value?.toString() ?? ""
watchHandle = watch(currentText, () => {
props.paramBuilder.paramData.value = currentText.value
}, {immediate: true})
})
onBeforeUnmount(() => {
if (watchHandle !== null) {
watchHandle()
watchHandle = null
}
props.paramBuilder.paramData.value = null
currentText.value = ""
})
</script>
Expand Down
63 changes: 26 additions & 37 deletions src/components/values/abi/ParamTypeEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
<template>
<div>
<template v-if="needsTextEditor">
<ParamTextEditor :param-builder="paramBuilder"/>
<ParamTextEditor :param-builder="props.paramBuilder"/>
</template>
<template v-else-if="needsBooleanEditor">
<ParamBooleanEditor :param-builder="paramBuilder"/>
<ParamBooleanEditor :param-builder="props.paramBuilder"/>
</template>
<template v-else>
<ParamJsonEditor :param-builder="paramBuilder"/>
<ParamJsonEditor :param-builder="props.paramBuilder"/>
</template>
</div>
</template>
Expand All @@ -40,50 +40,39 @@
<!-- SCRIPT -->
<!-- --------------------------------------------------------------------------------------------------------------- -->

<script lang="ts">
<script setup lang="ts">
import {computed, defineComponent, PropType} from "vue";
import {computed, PropType} from "vue";
import ParamTextEditor from "@/components/values/abi/ParamTextEditor.vue";
import ParamBooleanEditor from "@/components/values/abi/ParamBooleanEditor.vue";
import ParamJsonEditor from "@/components/values/abi/ParamJsonEditor.vue";
import {ContractParamBuilder} from "@/components/values/abi/ContractCallBuilder";
export default defineComponent({
name: "ParamTypeEditor",
components: {ParamJsonEditor, ParamBooleanEditor, ParamTextEditor},
props: {
paramBuilder: {
type: Object as PropType<ContractParamBuilder>,
required: true
},
const props = defineProps({
paramBuilder: {
type: Object as PropType<ContractParamBuilder>,
required: true
},
setup(props) {
const needsBooleanEditor = computed(
() => props.paramBuilder.paramType.baseType == "bool")
})
const needsTextEditor = computed(() => {
let result: boolean
switch (clearSize(props.paramBuilder.paramType.baseType)) {
case "int":
case "uint":
case "string":
case "address":
case "bytes":
result = true
break
default:
result = false
break
}
return result
})
const needsBooleanEditor = computed(
() => props.paramBuilder.paramType.baseType == "bool")
return {
needsBooleanEditor,
needsTextEditor
}
const needsTextEditor = computed(() => {
let result: boolean
switch (clearSize(props.paramBuilder.paramType.baseType)) {
case "int":
case "uint":
case "string":
case "address":
case "bytes":
result = true
break
default:
result = false
break
}
return result
})
interface SizedType {
Expand Down

0 comments on commit b973c62

Please sign in to comment.