mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-16 03:40:37 +08:00
Further optimize profile requests
Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
+20
-13
@@ -1,9 +1,9 @@
|
||||
import type { EnsProfile } from "@app/base/registrations/registrar";
|
||||
import type { BasicProfile } from "@ceramicstudio/idx-constants";
|
||||
import {
|
||||
formatCAIP10Address, formatIpfsFile, resolveEnsProfile, resolveIdxProfile, parseUsername,
|
||||
isAddress, formatCAIP10Address, formatIpfsFile, resolveEnsProfile, resolveIdxProfile, parseUsername,
|
||||
} from "@app/utils";
|
||||
import type { Config } from "./config";
|
||||
import type { Config } from "@app/config";
|
||||
|
||||
export interface IProfile {
|
||||
address: string;
|
||||
@@ -99,20 +99,27 @@ export class Profile {
|
||||
profileType: ProfileType,
|
||||
config: Config
|
||||
): Promise<IProfile> {
|
||||
const address = await config.provider.resolveName(addressOrName);
|
||||
const profile: IProfile = { address, ens: null, idx: null };
|
||||
const ens = await resolveEnsProfile(addressOrName, profileType, config);
|
||||
|
||||
try {
|
||||
profile.ens = await resolveEnsProfile(addressOrName, profileType, config);
|
||||
|
||||
if (! profile.ens) {
|
||||
profile.idx = await resolveIdxProfile(formatCAIP10Address(address, "eip155", config.network.chainId), config);
|
||||
if (ens) {
|
||||
if (ens.address) {
|
||||
return { address: ens.address, ens, idx: null };
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
throw new Error(`No address set for ${addressOrName}`);
|
||||
|
||||
return profile;
|
||||
} else if (isAddress(addressOrName)) {
|
||||
const address = addressOrName;
|
||||
|
||||
try {
|
||||
const idx = await resolveIdxProfile(
|
||||
formatCAIP10Address(address, "eip155", config.network.chainId), config
|
||||
);
|
||||
return { address, ens: null, idx };
|
||||
} catch {
|
||||
return { address, ens: null, idx: null };
|
||||
}
|
||||
}
|
||||
throw new Error(`Name ${addressOrName} was not found`);
|
||||
}
|
||||
|
||||
static async getMulti(addresses: string[], config: Config): Promise<Profile[]> {
|
||||
|
||||
+18
-19
@@ -270,38 +270,37 @@ export async function resolveEnsProfile(addressOrName: string, profileType: Prof
|
||||
if (registration) {
|
||||
return registration.profile;
|
||||
}
|
||||
} else if (profileType === ProfileType.Project) {
|
||||
const project = await Promise.allSettled([
|
||||
} else {
|
||||
const promises = [
|
||||
getAvatar(name, config, resolver),
|
||||
getSeed(name, config, resolver)
|
||||
]);
|
||||
];
|
||||
|
||||
const [avatar, seedHost] =
|
||||
if (addressOrName === name) {
|
||||
promises.push(resolver.getAddress());
|
||||
} else {
|
||||
promises.push(Promise.resolve(addressOrName));
|
||||
}
|
||||
|
||||
if (profileType === ProfileType.Project) {
|
||||
promises.push(getSeed(name, config, resolver));
|
||||
} else if (profileType === ProfileType.Minimal) {
|
||||
promises.push(Promise.resolve(null));
|
||||
}
|
||||
|
||||
const project = await Promise.allSettled(promises);
|
||||
const [avatar, address, seedHost] =
|
||||
project.map(r => r.status == "fulfilled" ? r.value : null);
|
||||
|
||||
return {
|
||||
name,
|
||||
avatar,
|
||||
address: null,
|
||||
address,
|
||||
seedHost,
|
||||
url: null,
|
||||
seedId: null,
|
||||
twitter: null,
|
||||
github: null,
|
||||
};
|
||||
} else if (profileType === ProfileType.Minimal) {
|
||||
const avatar = await getAvatar(name, config, resolver);
|
||||
|
||||
return {
|
||||
name,
|
||||
avatar,
|
||||
address: null,
|
||||
url: null,
|
||||
seedId: null,
|
||||
seedHost: null,
|
||||
twitter: null,
|
||||
github: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user