From b60e78fecb93782817eb14f76772342152f4626a Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Mon, 2 Aug 2021 11:38:28 +0200 Subject: [PATCH] Make 'SetName' support users too --- src/base/orgs/View.svelte | 2 +- src/base/users/User.ts | 25 +++++++++++++++++++++++++ src/config.json | 9 +++++++++ src/config.ts | 2 ++ src/ens/SetName.svelte | 27 ++++++++++++++++----------- 5 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 src/base/users/User.ts diff --git a/src/base/orgs/View.svelte b/src/base/orgs/View.svelte index b7ef8a083..d12029071 100644 --- a/src/base/orgs/View.svelte +++ b/src/base/orgs/View.svelte @@ -269,7 +269,7 @@ {/if} - setNameForm = null} /> + setNameForm = null} /> transferOwnerForm = null} /> {:catch err} diff --git a/src/base/users/User.ts b/src/base/users/User.ts new file mode 100644 index 000000000..70b040e85 --- /dev/null +++ b/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 { + assert(config.signer); + + const reverseRegistrar = new ethers.Contract( + config.reverseRegistrar.address, + config.abi.reverseRegistrar, + config.signer + ); + return reverseRegistrar.setName(name, this.address); + } +} diff --git a/src/config.json b/src/config.json index a7708316f..59301e616 100644 --- a/src/config.json +++ b/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)", diff --git a/src/config.ts b/src/config.ts index 4a3ed8dc8..b26f86de2 100644 --- a/src/config.ts +++ b/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 diff --git a/src/ens/SetName.svelte b/src/ens/SetName.svelte index c708e3789..e5119dccc 100644 --- a/src/ens/SetName.svelte +++ b/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 @@
- The ENS name for {org.address} was set to + The ENS name for {entity.address} was set to {name}.{config.registrar.domain}.
@@ -84,14 +89,14 @@ -{:else if state === State.Proposed} +{:else if state === State.Proposed && org}
🪴
-

The transaction to set the ENS name for {formatAddress(org.address)} +

The transaction to set the ENS name for {formatAddress(entity.address)} to {name}.{config.registrar.domain} was proposed to:

@@ -105,7 +110,7 @@ {:else if state === State.Mismatch} The name {name}.{config.registrar.domain} does not - resolve to {org.address}. Please update + resolve to {entity.address}. 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 {formatAddress(org.owner)}, please sign the transaction in your wallet. {:else} - Set an ENS name for {formatAddress(org.address)} + Set an ENS name for {formatAddress(entity.address)} {/if}