|
| 1 | +<script setup lang="ts"> |
| 2 | +import { Loader } from 'lucide-vue-next'; |
| 3 | +import { ref, watch } from 'vue'; |
| 4 | +
|
| 5 | +import Button from '@/components/ui/button/Button.vue'; |
| 6 | +import Input from '@/components/ui/input/Input.vue'; |
| 7 | +import { useAccount } from '@/composables/useAccount'; |
| 8 | +import { usePopups } from '@/composables/usePopups'; |
| 9 | +import { useRegisterHandle } from '@/composables/useRegisterHandle'; |
| 10 | +import { useWallet } from '@/composables/useWallet'; |
| 11 | +import MainLayout from '@/layouts/MainLayout.vue'; |
| 12 | +import { useConfigStore } from '@/stores/useConfigStore'; |
| 13 | +import { showBroadcastingToast } from '@/utility/toast'; |
| 14 | +import HeaderBack from '@/views/ViewHeading.vue'; |
| 15 | +
|
| 16 | +const wallet = useWallet(); |
| 17 | +const popups = usePopups(); |
| 18 | +const configStore = useConfigStore(); |
| 19 | +const { data: account, isFetching } = useAccount({ address: wallet.address.value }); |
| 20 | +const { registerHandle } = useRegisterHandle(); |
| 21 | +
|
| 22 | +const handle = ref<string>(account?.value?.handle); |
| 23 | +
|
| 24 | +watch(account, (account) => { |
| 25 | + handle.value = account.handle; |
| 26 | +}); |
| 27 | +
|
| 28 | +async function onClickRegister() { |
| 29 | + // TODOs: |
| 30 | + // - Handle registration click (check handle is different than current one) |
| 31 | + // - Check handle format and show error |
| 32 | + // - Check if handle is available before triggering registration |
| 33 | +
|
| 34 | + if (configStore.config.defaultAmountEnabled) { |
| 35 | + const toastId = showBroadcastingToast('Register Handle'); |
| 36 | + try { |
| 37 | + await registerHandle({ handle: handle.value, amountAtomics: configStore.config.defaultAmountAtomics }); |
| 38 | + } finally { |
| 39 | + toast.dismiss(toastId); |
| 40 | + } |
| 41 | + } else { |
| 42 | + popups.show('registerHandle', handle.value); |
| 43 | + } |
| 44 | +} |
| 45 | +</script> |
| 46 | + |
| 47 | +<template> |
| 48 | + <MainLayout> |
| 49 | + <div class="flex flex-col flex-1"> |
| 50 | + <HeaderBack :title="$t('components.Headings.account')" /> |
| 51 | + |
| 52 | + <div class="flex flex-col text-pretty"> |
| 53 | + <div class="flex flex-col"> |
| 54 | + <span class="pt-4 pl-4 font-bold">{{ $t(`components.Settings.accountHandle`) }}</span> |
| 55 | + <p class="p-4 text-sm"> |
| 56 | + {{ $t(`components.Settings.accountHandleSummary`) }} |
| 57 | + </p> |
| 58 | + </div> |
| 59 | + |
| 60 | + <div v-if="isFetching" class="flex items-center justify-center p-4 border-b"> |
| 61 | + <Loader class="animate-spin " /> |
| 62 | + </div> |
| 63 | + <div v-else class="flex flex-col p-4 gap-4 border-b"> |
| 64 | + <div class="flex gap-2 px-8"> |
| 65 | + <div class="flex h-[40px] items-center"> |
| 66 | + <label class="text-sm font-semibold select-none" for="handler">@</label> |
| 67 | + </div> |
| 68 | + |
| 69 | + <Input id="handle" v-model.trim="handle" class="flex-1" /> |
| 70 | + |
| 71 | + <Button size="sm" class="decoration-2" variant="outline" @click="onClickRegister"> |
| 72 | + <span class="grow">{{ $t('components.Settings.accountHandleRegister') }}</span> |
| 73 | + </Button> |
| 74 | + </div> |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + </MainLayout> |
| 79 | +</template> |
0 commit comments