Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
return Promise<> and have working sample :)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelLHuber committed Mar 13, 2024
1 parent 1c9af63 commit 7c62fc4
Showing 1 changed file with 17 additions and 32 deletions.
49 changes: 17 additions & 32 deletions src/functions/getConnectedAddresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,24 @@ export const getConnectedAddresses = (
fid: number,
ethereum?: boolean,
solana?: boolean
): ConnectedAddresses => {
let addresses: ConnectedAddresses;

): Promise<ConnectedAddresses> => {
if (provider instanceof HubProvider) {
if (provider.psqlUrl)
addresses = getConnectedAddressesFromReplicator(
return getConnectedAddressesFromReplicator(
provider.psqlUrl,
fid,
ethereum,
solana
);
else
addresses = getConnectedAddressesFromHub(
return getConnectedAddressesFromHub(
provider.hubUrl,
fid,
ethereum,
solana
);
} else if (provider instanceof NeynarProvider) {
addresses = getConnectedAddressesFromNeynar(
return getConnectedAddressesFromNeynar(
provider,
fid,
ethereum,
Expand All @@ -37,21 +35,14 @@ export const getConnectedAddresses = (
} else {
throw new Error('Provider not supported');
}

return addresses;
}

function getConnectedAddressesFromReplicator(
psqlUrl: string,
fid: number,
ethereum?: boolean,
solana?: boolean
): ConnectedAddresses {
let addresses: ConnectedAddresses = {
all: [],
ethereum: [],
solana: [],
};
): Promise<ConnectedAddresses> {
// ...
throw new Error('Not implemented');
}
Expand All @@ -70,15 +61,16 @@ function getConnectedAddressesFromHub(
fid: number,
ethereum?: boolean,
solana?: boolean
): ConnectedAddresses {
let addresses: ConnectedAddresses = {
all: [],
ethereum: [],
solana: [],
};
): Promise<ConnectedAddresses> {

try {
const fetchVerificationsByFid = async (fid: string): Promise<ConnectedAddresses> => {
let addresses: ConnectedAddresses = {
all: [],
ethereum: [],
solana: [],
};

if(process.env.DEBUG) { console.log('fetching Verifications from hub:', hubUrl); }
const response = await fetch(
`${hubUrl}/v1/verificationsByFid?fid=${fid}`
Expand Down Expand Up @@ -120,7 +112,7 @@ function getConnectedAddressesFromHub(
return addresses;
};

addresses = queryClient.fetchQuery({
return queryClient.fetchQuery({
queryKey: ['verificationsByFid', fid],
queryFn: () => fetchVerificationsByFid(fid.toString()),
}).then( (res) => { return res; });
Expand All @@ -129,20 +121,14 @@ function getConnectedAddressesFromHub(
console.error(e);
throw new Error('Error getting verifications from hub');
}
return addresses;
}

function getConnectedAddressesFromNeynar(
provider: NeynarProvider,
fid: number,
ethereum?: boolean,
solana?: boolean
): ConnectedAddresses {
let addresses: ConnectedAddresses = {
all: [],
ethereum: [],
solana: [],
};
): Promise<ConnectedAddresses> {

try {
const fetchVerificationsByFid = async (fid: string): Promise<ConnectedAddresses> => {
Expand All @@ -151,6 +137,7 @@ function getConnectedAddressesFromNeynar(
ethereum: [],
solana: [],
};

if(process.env.DEBUG) { console.log('fetching Verifications from neynar:', provider.endPoint); }
const response = await fetch(
`${provider.endPoint}/v2//farcaster/user/bulk?fids=${fid}`,
Expand All @@ -176,15 +163,13 @@ function getConnectedAddressesFromNeynar(
return addresses;
};

addresses = queryClient.fetchQuery({
return queryClient.fetchQuery({
queryKey: ['verificationsByFid', fid],
queryFn: () => fetchVerificationsByFid(fid.toString()),
}).then( (res) => { return res; });
});

} catch (e) {
console.error(e);
throw new Error('Error getting verifications from hub');
}

return addresses;
}

0 comments on commit 7c62fc4

Please sign in to comment.