diff --git a/src/components/DomainPayment.svelte b/src/components/DomainPayment.svelte index e04970d..aa60faf 100644 --- a/src/components/DomainPayment.svelte +++ b/src/components/DomainPayment.svelte @@ -51,7 +51,7 @@ years += amount; } - async function handleApproveError(error: Error) { + async function handleApproveError(error: unknown) { let message; if (error instanceof InsufficientBalanceError) message = { diff --git a/src/routes/DomainSearch.svelte b/src/routes/DomainSearch.svelte index 53d006f..606934d 100644 --- a/src/routes/DomainSearch.svelte +++ b/src/routes/DomainSearch.svelte @@ -7,6 +7,7 @@ import IconButton from '@smui/icon-button'; import { metaNamesSdk } from '$lib/stores/sdk'; import { goto } from '$app/navigation'; + import { onDestroy } from 'svelte'; import Icon from 'src/components/Icon.svelte'; const validator = $metaNamesSdk.domainRepository.domainValidator; @@ -17,6 +18,10 @@ let isLoading: boolean = false; let debounceTimer: ReturnType; let requestId = 0; + // Cache for domain search results to prevent redundant API calls + const cache = new Map(); + + onDestroy(() => clearTimeout(debounceTimer)); $: errors = invalid ? validator.getErrors() : []; $: invalid = domainName !== '' && !validator.validate(domainName, { raiseError: false }); @@ -42,11 +47,20 @@ const currentRequestId = ++requestId; nameSearched = domainName.toLocaleLowerCase(); + + // Check cache first to avoid unnecessary network request + if (cache.has(nameSearched)) { + domain = cache.get(nameSearched); + isLoading = false; + return; + } + isLoading = true; const result = await $metaNamesSdk.domainRepository.find(domainName); if (currentRequestId === requestId) { + cache.set(nameSearched, result); domain = result; isLoading = false; }