Refactor isFulfilled check into a utils function

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez
2022-09-15 12:55:46 +02:00
committed by Alexis Sellier
parent 5cb733e73b
commit 4ebf073c5b
4 changed files with 16 additions and 16 deletions
+8 -4
View File
@@ -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,