Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Don't get registration owner when not needed
Alexis Sellier committed 4 years ago
commit b95af71f33c3ed13557e462cf38afce628b3b5a9
parent 432f50e05512a51dd10d1169309a24a9ca1beb06
2 files changed +9 -11
modified 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;
  };
</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>
modified 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<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");