mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-12 02:30:35 +08:00
Don't get registration owner when not needed
Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
import Error from '@app/Error.svelte';
|
||||
import { isAddressEqual, isReverseRecordSet } from '@app/utils';
|
||||
|
||||
import { getRegistration } from './registrar';
|
||||
import { getRegistration, getOwner } from './registrar';
|
||||
import type { EnsRecord } from './resolver';
|
||||
import type { Registration } from './registrar';
|
||||
import Update from './Update.svelte';
|
||||
@@ -27,7 +27,7 @@
|
||||
type State =
|
||||
{ status: Status.Loading }
|
||||
| { status: Status.NotFound }
|
||||
| { status: Status.Found; registration: Registration }
|
||||
| { status: Status.Found; registration: Registration; owner: string }
|
||||
| { status: Status.Failed; error: string };
|
||||
|
||||
export let subdomain: string;
|
||||
@@ -49,11 +49,12 @@
|
||||
if (r.profile.address) {
|
||||
reverseRecord = await isReverseRecordSet(r.profile.address, name, config);
|
||||
}
|
||||
const owner = await getOwner(name, config);
|
||||
|
||||
fields = [
|
||||
{ name: "owner", validate: "address", placeholder: "",
|
||||
description: "The owner and controller of this name.",
|
||||
value: r.owner, resolve: true, editable: false },
|
||||
value: owner, resolve: true, editable: false },
|
||||
{ name: "address", validate: "address", placeholder: "Ethereum address, eg. 0x4a9cf21...bc91",
|
||||
description: "The address this name resolves to. " + (
|
||||
reverseRecord
|
||||
@@ -84,7 +85,7 @@
|
||||
description: "The Device ID of a Radicle Link node that hosts entities associated with this name.",
|
||||
value: r.profile.seedId, editable: true },
|
||||
];
|
||||
state = { status: Status.Found, registration: r };
|
||||
state = { status: Status.Found, registration: r, owner };
|
||||
} else {
|
||||
state = { status: Status.NotFound };
|
||||
}
|
||||
@@ -104,8 +105,8 @@
|
||||
});
|
||||
};
|
||||
|
||||
$: isOwner = (registration: Registration): boolean => {
|
||||
return $session ? isAddressEqual(registration.owner, $session.address) : false;
|
||||
$: isOwner = (owner: string): boolean => {
|
||||
return $session ? isAddressEqual(owner, $session.address) : false;
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -154,7 +155,7 @@
|
||||
<header>
|
||||
<h1 class="bold">{subdomain}.{config.registrar.domain}</h1>
|
||||
<button
|
||||
class="tiny primary" class:active={editable} disabled={!isOwner(state.registration)}
|
||||
class="tiny primary" class:active={editable} disabled={!isOwner(state.owner)}
|
||||
on:click={() => editable = !editable}>
|
||||
Edit
|
||||
</button>
|
||||
|
||||
@@ -10,7 +10,6 @@ import { unixTime } from '@app/utils';
|
||||
import { assert } from '@app/error';
|
||||
|
||||
export interface Registration {
|
||||
owner: string;
|
||||
profile: EnsProfile;
|
||||
resolver: EnsResolver;
|
||||
}
|
||||
@@ -66,7 +65,6 @@ export async function getRegistration(name: string, config: Config): Promise<Reg
|
||||
return null;
|
||||
}
|
||||
|
||||
const owner = await getOwner(name, config);
|
||||
const meta = await Promise.allSettled([
|
||||
resolver.getAddress(),
|
||||
resolver.getText('avatar'),
|
||||
@@ -81,7 +79,6 @@ export async function getRegistration(name: string, config: Config): Promise<Reg
|
||||
meta.map(r => r.status == "fulfilled" ? r.value : null);
|
||||
|
||||
return {
|
||||
owner,
|
||||
resolver,
|
||||
profile: {
|
||||
name,
|
||||
@@ -278,7 +275,7 @@ function makeCommitment(name: string, owner: string, salt: Uint8Array): string {
|
||||
return ethers.utils.keccak256(bytes);
|
||||
}
|
||||
|
||||
async function getOwner(name: string, config: Config): Promise<string> {
|
||||
export async function getOwner(name: string, config: Config): Promise<string> {
|
||||
const ensAddr = config.provider.network.ensAddress;
|
||||
if (! ensAddr) {
|
||||
throw new Error("ENS address is not defined");
|
||||
|
||||
Reference in New Issue
Block a user