diff --git a/public/index.css b/public/index.css index 4934fe73e..2c6b5fda7 100644 --- a/public/index.css +++ b/public/index.css @@ -149,7 +149,8 @@ button.small { } button.tiny { min-width: 0; - padding: 0.125rem 0.75rem; + padding: 0 0.75rem; + height: 2rem; } a { diff --git a/src/base/orgs/Org.ts b/src/base/orgs/Org.ts index 4cfb8128b..34dd06434 100644 --- a/src/base/orgs/Org.ts +++ b/src/base/orgs/Org.ts @@ -11,7 +11,10 @@ const orgFactoryAbi = [ "event OrgCreated(address, address)", ]; -const orgAbi = ["function owner() view returns (address)"]; +const orgAbi = [ + "function owner() view returns (address)", + "function setName(string, address) returns (bytes32)", +]; export class Org { address: string @@ -28,6 +31,16 @@ export class Org { return await config.provider.lookupAddress(this.address); } + async setName(name: string, config: Config): Promise { + const org = new ethers.Contract( + this.address, + orgAbi, + config.signer + ); + return org.setName(name, config.provider.network.ensAddress, + { gasLimit: 200_000 }); + } + static fromReceipt(receipt: ContractReceipt): Org | null { let event = receipt.events?.find(e => e.event === 'OrgCreated'); diff --git a/src/base/orgs/Profile.svelte b/src/base/orgs/Profile.svelte index d2f6ba54a..24de126c4 100644 --- a/src/base/orgs/Profile.svelte +++ b/src/base/orgs/Profile.svelte @@ -1,28 +1,42 @@
@@ -113,17 +78,13 @@
-
- - .{config.registrar.domain} -
+
{#if !inputValue} +
+ +{:else} + +
+ {#if mismatchError} + 🦉 + {:else} + 🖊️ + {/if} +
+ +
+ {#if mismatchError} +
+ The name {name}.{config.registrar.domain} does not + resolve to {formatAddress(org.address)}. Please update + The ENS record for {name}.{config.registrar.domain} to + point to the correct address. +
+ {:else if state == State.Signing} + Please confirm the transaction in your wallet. + {:else if state == State.Pending} + Transaction is being processed by the network... + {:else} + Set an ENS name for {formatAddress(org.address)} + {/if} +
+ +
+ {#if state === State.Idle || state === State.Checking} + mismatchError = false} + autofocus disabled={state !== State.Idle} bind:value={name} /> + {:else} + + {/if} +
+ +
+ {#if state == State.Signing} + + {:else if state == State.Pending} + + {:else} + + + + {/if} +
+
+{/if} diff --git a/src/utils.ts b/src/utils.ts index 6e49e4b60..ecb9ef760 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,6 @@ import { ethers } from "ethers"; import type { BigNumber } from "ethers"; +import type { Config } from '@app/config'; export function formatBalance(n: BigNumber) { return ethers.utils.commify(parseFloat(ethers.utils.formatUnits(n)).toFixed(2)); @@ -15,3 +16,10 @@ export function capitalize(s: string) { if (s === "") return s; return s[0].toUpperCase() + s.substr(1); } + +// Takes a domain name, eg. 'cloudhead.radicle.eth' and +// returns the label, eg. 'cloudhead'. +export function parseEnsLabel(name: string, config: Config) { + let domain = config.registrar.domain.replace(".", "\\."); + return name.replace(new RegExp(`\\.${domain}$`), ""); +}