Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Refactor isFulfilled check into a utils function
Sebastian Martinez committed 3 years ago
commit 4ebf073c5bfaba9a721748e9161d9d07b2647a49
parent 5cb733e73b0fee171ab621ade98bc4fef265fa78
4 files changed +16 -16
modified src/base/registrations/registrar.ts
@@ -6,7 +6,7 @@ import type { TypedDataSigner } from "@ethersproject/abstract-signer";
import * as session from "@app/session";
import { Failure } from "@app/error";
import type { Config } from "@app/config";
-
import { unixTime } from "@app/utils";
+
import { isFulfilled, unixTime } from "@app/utils";
import { assert } from "@app/error";
import { Seed, InvalidSeed } from "@app/base/seeds/Seed";
import * as cache from "@app/cache";
@@ -105,9 +105,7 @@ export async function getRegistration(
    anchorsAccount,
    twitter,
    github,
-
  ] = meta.map(r =>
-
    r.status === "fulfilled" && r.value ? r.value : undefined,
-
  );
+
  ] = meta.filter(isFulfilled).map(r => (r.value ? r.value : undefined));

  const profile: EnsProfile = {
    name,
modified src/profile.ts
@@ -9,6 +9,7 @@ import {
  parseUsername,
  AddressType,
  identifyAddress,
+
  isFulfilled,
} from "@app/utils";
import type { Config } from "@app/config";
import { cached } from "@app/cache";
@@ -215,10 +216,10 @@ export class Profile {
    const profilePromises = addressesOrNames.map(addressOrName =>
      this.lookupProfile(addressOrName, ProfileType.Minimal, config),
    );
-
    const profiles = await Promise.all(profilePromises);
-
    return profiles.map(profile => {
-
      return new Profile(profile);
-
    });
+
    const profiles = await Promise.allSettled(profilePromises);
+
    return profiles
+
      .filter(isFulfilled)
+
      .map(profile => new Profile(profile.value));
  }

  static async get(
modified src/project.ts
@@ -2,7 +2,7 @@ import { navigate } from "svelte-routing";
import { get, writable } from "svelte/store";
import { type Host, Request } from "@app/api";
import type { Commit, CommitHeader, CommitsHistory } from "@app/commit";
-
import { isOid, isRadicleId } from "@app/utils";
+
import { isFulfilled, isOid, isRadicleId } from "@app/utils";
import { Profile, ProfileType } from "@app/profile";
import { Seed } from "@app/base/seeds/Seed";
import type { Config } from "@app/config";
@@ -498,9 +498,6 @@ export class Project implements ProjectInfo {
      );
    }
    const results = await Promise.allSettled(promises);
-
    const isFulfilled = <T>(
-
      input: PromiseSettledResult<T>,
-
    ): input is PromiseFulfilledResult<T> => input.status === "fulfilled";

    return results.filter(isFulfilled).map(r => r.value);
  }
modified src/utils.ts
@@ -350,7 +350,7 @@ export function isDid(input: string): boolean {

export function isENSName(input: string, config: Config): boolean {
  const domain = config.registrar.domain.replace(".", "\\.");
-
  const regEx = new RegExp(`^[a-zA-Z0-9]+.${domain}$`);
+
  const regEx = new RegExp(`^[a-zA-Z0-9]+.(${domain}|eth)$`);
  return regEx.test(input);
}

@@ -359,6 +359,12 @@ export function isAddress(input: string): boolean {
  return ethers.utils.isAddress(input);
}

+
export function isFulfilled<T>(
+
  input: PromiseSettledResult<T>,
+
): input is PromiseFulfilledResult<T> {
+
  return input.status === "fulfilled";
+
}
+

// Get search parameters from location.
export function getSearchParam(
  key: string,
@@ -556,9 +562,7 @@ export async function resolveEnsProfile(
      const [avatar, address, seed, anchorsAccount] =
        // Just checking for r.value equal null and casting to undefined,
        // since resolver functions return null.
-
        project.map(r =>
-
          r.status === "fulfilled" && r.value ? r.value : null,
-
        );
+
        project.filter(isFulfilled).map(r => (r.value ? r.value : null));

      return {
        name,