Files
radicle-explorer/src/base/resolver/Query.svelte
T
Rūdolfs Ošiņš 853ed5c053 Require using const for variables that are never modified
And disallow modifying variables that are declared using `const`.

Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
2022-08-30 12:09:27 +02:00

55 lines
1.7 KiB
Svelte

<script lang="ts">
import { onMount } from 'svelte';
import { ethers } from 'ethers';
import { navigate } from 'svelte-routing';
import type { Config } from '@app/config';
import * as utils from '@app/utils';
import Error from '@app/Error.svelte';
import Loading from '@app/Loading.svelte';
export let config: Config;
export let query: string | null;
const error = false;
onMount(async () => {
if (query) {
if (ethers.utils.isAddress(query)) {
const addressType = query && await utils.identifyAddress(query, config);
if (addressType === utils.AddressType.Org || addressType === utils.AddressType.EOA) {
navigate(`/${query}`, { replace: true });
}
} else if (utils.isRadicleId(query)) {
// Go to Radicle project.
navigate(`/projects/${query}`, { replace: true });
} else {
// Jump straight to org, if the ENS entry points to an org. Otherwise it checks if the
// address type is an EOA and jumps to the user page else it just goes to the registration.
const address = await utils.resolveLabel(query, config);
const addressType = address && await utils.identifyAddress(address, config);
if (addressType === utils.AddressType.Org || addressType === utils.AddressType.EOA) {
navigate(`/${address}`, { replace: true });
} else {
navigate(`/registrations/${query}`, { replace: true });
}
}
} else {
navigate('/');
}
});
</script>
<svelte:head>
<title>Radicle: {query}</title>
</svelte:head>
<main class="off-centered">
{#if error}
<Error on:close={() => navigate('/')}>
Invalid query string “{query}”
</Error>
{:else}
<Loading center />
{/if}
</main>