From b95af71f33c3ed13557e462cf38afce628b3b5a9 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Wed, 22 Sep 2021 15:44:55 +0200 Subject: [PATCH] Don't get registration owner when not needed Signed-off-by: Alexis Sellier --- src/base/registrations/View.svelte | 15 ++++++++------- src/base/registrations/registrar.ts | 5 +---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/base/registrations/View.svelte b/src/base/registrations/View.svelte index abf22058c..aa7795e8c 100644 --- a/src/base/registrations/View.svelte +++ b/src/base/registrations/View.svelte @@ -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; }; @@ -154,7 +155,7 @@

{subdomain}.{config.registrar.domain}

diff --git a/src/base/registrations/registrar.ts b/src/base/registrations/registrar.ts index 3a07fb9bd..8bc478594 100644 --- a/src/base/registrations/registrar.ts +++ b/src/base/registrations/registrar.ts @@ -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 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 { +export async function getOwner(name: string, config: Config): Promise { const ensAddr = config.provider.network.ensAddress; if (! ensAddr) { throw new Error("ENS address is not defined");