mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-15 19:30:38 +08:00
Refactor isFulfilled check into a utils function
Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
@@ -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,
|
||||
|
||||
+5
-4
@@ -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(
|
||||
|
||||
+1
-4
@@ -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);
|
||||
}
|
||||
|
||||
+8
-4
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user