Skip to content
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/components/DomainPayment.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
years += amount;
}

async function handleApproveError(error: Error) {
async function handleApproveError(error: unknown) {
let message;
if (error instanceof InsufficientBalanceError)
message = {
Expand Down
14 changes: 14 additions & 0 deletions src/routes/DomainSearch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +18,10 @@
let isLoading: boolean = false;
let debounceTimer: ReturnType<typeof setTimeout>;
let requestId = 0;
// Cache for domain search results to prevent redundant API calls
const cache = new Map<string, DomainModel | null | undefined>();

onDestroy(() => clearTimeout(debounceTimer));

$: errors = invalid ? validator.getErrors() : [];
$: invalid = domainName !== '' && !validator.validate(domainName, { raiseError: false });
Expand All @@ -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;
}
Expand Down