mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-10-28 07:50:47 +08:00
50 lines
1.4 KiB
Svelte
50 lines
1.4 KiB
Svelte
<script lang="typescript">
|
|
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';
|
|
|
|
export let config: Config;
|
|
export let query: string | null;
|
|
|
|
let error = false;
|
|
|
|
onMount(async () => {
|
|
if (query) {
|
|
if (ethers.utils.isAddress(query)) {
|
|
// Go to org.
|
|
navigate(`/orgs/${query}`, { replace: true });
|
|
} else if (utils.isRadicleId(query)) {
|
|
// Go to Radicle entity.
|
|
alert("Radicle IDs are not yet supported");
|
|
} else {
|
|
let label = utils.parseEnsLabel(query, config);
|
|
if (label.includes(".")) {
|
|
error = true;
|
|
} else {
|
|
// Jump straight to org, if the ENS entry points to an org. Otherwise just go to the
|
|
// registration.
|
|
const address = await utils.resolveLabel(label, config);
|
|
if (address && await utils.identifyAddress(address, config) === utils.AddressType.Org) {
|
|
navigate(`/orgs/${address}`, { replace: true });
|
|
} else {
|
|
navigate(`/registrations/${label}`, { replace: true });
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
navigate('/');
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<main>
|
|
{#if error}
|
|
<Error on:close={() => navigate('/')}>
|
|
Invalid query string “{query}”
|
|
</Error>
|
|
{/if}
|
|
</main>
|