Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Make 'SetName' support users too
Alexis Sellier committed 4 years ago
commit b60e78fecb93782817eb14f76772342152f4626a
parent adec1dedf0a3847ee210a9f94f0f0632a68de3e5
5 files changed +53 -12
modified src/base/orgs/View.svelte
@@ -269,7 +269,7 @@
      </span>
    </Modal>
  {/if}
-
  <svelte:component this={setNameForm} {org} {config} on:close={() => setNameForm = null} />
+
  <svelte:component this={setNameForm} entity={org} {config} on:close={() => setNameForm = null} />
  <svelte:component this={transferOwnerForm} {org} {config} on:close={() => transferOwnerForm = null} />
{:catch err}
  <Error error={err} />
added src/base/users/User.ts
@@ -0,0 +1,25 @@
+
import * as ethers from 'ethers';
+
import type { Config } from '@app/config';
+
import { assert } from '@app/error';
+
import type { TransactionResponse } from '@ethersproject/providers';
+

+
export class User {
+
  address: string;
+

+
  constructor(address: string) {
+
    assert(ethers.utils.isAddress(address), "address must be valid");
+

+
    this.address = address.toLowerCase(); // Don't store address checksum.
+
  }
+

+
  async setName(name: string, config: Config): Promise<TransactionResponse> {
+
    assert(config.signer);
+

+
    const reverseRegistrar = new ethers.Contract(
+
      config.reverseRegistrar.address,
+
      config.abi.reverseRegistrar,
+
      config.signer
+
    );
+
    return reverseRegistrar.setName(name, this.address);
+
  }
+
}
modified src/config.json
@@ -18,6 +18,9 @@
      "api": "https://safe-transaction.gnosis.io",
      "viewer": "https://gnosis-safe.io/app/#/safes"
    },
+
    "reverseRegistrar": {
+
      "address": "0x084b1c3C81545d370f3634392De611CaaBFf8148"
+
    },
    "tokens": []
  },
  "rinkeby": {
@@ -39,6 +42,9 @@
      "api": "https://safe-transaction.rinkeby.gnosis.io",
      "viewer": "https://rinkeby.gnosis-safe.io/app/#/safes"
    },
+
    "reverseRegistrar": {
+
      "address": "0x6F628b68b30Dc3c17f345c9dbBb1E483c2b7aE5c"
+
    },
    "tokens": []
  },
  "alchemy": { "key": "cQFlLK8EokIGlJhd_soImwEyUoC7Ec8r" },
@@ -75,6 +81,9 @@
      "function createOrg(address[], uint256) returns (address)",
      "event OrgCreated(address, address)"
    ],
+
    "reverseRegistrar": [
+
      "function setName(string) returns (bytes32)"
+
    ],
    "org": [
      "function owner() view returns (address)",
      "function anchors(bytes32) view returns (uint32, bytes)",
modified src/config.ts
@@ -17,6 +17,7 @@ export class Config {
  registrar: { address: string; domain: string };
  radToken: { address: string };
  orgFactory: { address: string };
+
  reverseRegistrar: { address: string };
  orgs: { subgraph: string; contractHash: string };
  gasLimits: { createOrg: number };
  provider: ethers.providers.JsonRpcProvider;
@@ -62,6 +63,7 @@ export class Config {
    this.registrar = cfg.registrar;
    this.radToken = cfg.radToken;
    this.orgFactory = cfg.orgFactory;
+
    this.reverseRegistrar = cfg.reverseRegistrar;
    this.orgs = cfg.orgs;
    this.safe = cfg.safe;
    this.safe.client = this.safe.api
modified src/ens/SetName.svelte
@@ -5,7 +5,8 @@
  import type { Config } from '@app/config';
  import { formatAddress, isAddressEqual } from '@app/utils';
  import DomainInput from '@app/ens/DomainInput.svelte';
-
  import type { Org } from '@app/base/orgs/Org';
+
  import { Org } from '@app/base/orgs/Org';
+
  import type { User } from '@app/base/users/User';
  import Loading from '@app/Loading.svelte';
  import Error from '@app/Error.svelte';
  import Address from '@app/Address.svelte';
@@ -13,9 +14,13 @@

  const dispatch = createEventDispatcher();

-
  export let org: Org;
+
  export let entity: Org | User;
  export let config: Config;

+
  const org = Org.hasOwnProperty.call(entity, "owner")
+
    ? entity as Org
+
    : null;
+

  enum State {
    Idle,
    Checking,
@@ -43,15 +48,15 @@
    let domain = `${name}.${config.registrar.domain}`;
    let resolved = await config.provider.resolveName(domain);

-
    if (resolved && isAddressEqual(resolved, org.address)) {
+
    if (resolved && isAddressEqual(resolved, entity.address)) {
      try {
-
        if (await utils.isSafe(org.owner, config)) {
+
        if (org && await utils.isSafe(org.owner, config)) {
          state = State.Proposing;
          await org.setNameMultisig(domain, config);
          state = State.Proposed;
        } else {
          state = State.Signing;
-
          let tx = await org.setName(domain, config);
+
          let tx = await entity.setName(domain, config);
          state = State.Pending;
          await tx.wait();
          state = State.Success;
@@ -74,7 +79,7 @@
    </div>

    <div slot="subtitle">
-
      The ENS name for {org.address} was set to
+
      The ENS name for {entity.address} was set to
      <strong>{name}.{config.registrar.domain}</strong>.
    </div>

@@ -84,14 +89,14 @@
      </button>
    </div>
  </Modal>
-
{:else if state === State.Proposed}
+
{:else if state === State.Proposed && org}
  <Modal floating>
    <div slot="title">
      ðŸŠī
    </div>

    <div slot="subtitle">
-
      <p>The transaction to set the ENS name for <strong>{formatAddress(org.address)}</strong>
+
      <p>The transaction to set the ENS name for <strong>{formatAddress(entity.address)}</strong>
      to <strong>{name}.{config.registrar.domain}</strong> was proposed to:</p>
      <p><Address address={org.owner} {config} compact /></p>
    </div>
@@ -105,7 +110,7 @@
{:else if state === State.Mismatch}
  <Error floating title="🖊ïļ" on:close>
    The name <strong>{name}.{config.registrar.domain}</strong> does not
-
    resolve to <strong>{org.address}</strong>. Please update
+
    resolve to <strong>{entity.address}</strong>. Please update
    the ENS record for {name}.{config.registrar.domain} to
    point to the correct address and try again.

@@ -132,12 +137,12 @@
        Please confirm the transaction in your wallet.
      {:else if state == State.Pending}
        Waiting for transaction to be processed...
-
      {:else if state == State.Proposing}
+
      {:else if state == State.Proposing && org}
        Proposal is being submitted to the safe
        <strong>{formatAddress(org.owner)}</strong>,
        please sign the transaction in your wallet.
      {:else}
-
        Set an ENS name for <strong>{formatAddress(org.address)}</strong>
+
        Set an ENS name for <strong>{formatAddress(entity.address)}</strong>
      {/if}
    </div>