-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b6ac9f
commit f873cb4
Showing
10 changed files
with
306 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
dist | ||
testPlayground.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"Socials": { | ||
"Social": [ | ||
{ | ||
"userId": "11244", | ||
"userAddressDetails": { | ||
"addresses": [ | ||
"0x92622c2d23fdf169f312c61aa47eba16b4c12e0b" | ||
], | ||
"blockchain": "ethereum" | ||
}, | ||
"profileDisplayName": "BFG 🎩↑🌱", | ||
"profileName": "bfg", | ||
"userAddress": "0x92622c2d23fdf169f312c61aa47eba16b4c12e0b", | ||
"connectedAddresses": [ | ||
{ | ||
"address": "0xa2746b2a56f9886925c03af1d1e10b8b3dfbbe29", | ||
"blockchain": "ethereum" | ||
} | ||
], | ||
"followerCount": 9084, | ||
"followingCount": 930, | ||
"profileImage": "https://res.cloudinary.com/merkle-manufactory/image/fetch/c_fill,f_gif,w_112,h_112/https://imagedelivery.net/BXluQx4ige9GuW0Ia56BHw/9834b977-ec60-45b4-16ba-533ad68b8200/original", | ||
"isFarcasterPowerUser": true | ||
} | ||
] | ||
}, | ||
"Following": { | ||
"Following": null | ||
}, | ||
"Followedby": { | ||
"Following": null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,85 @@ | ||
import { Service } from ".."; | ||
import { User, Cast } from "../../playground"; | ||
import { init, fetchQuery } from "@airstack/node"; | ||
import { | ||
castByHashQuery, | ||
castByUrlQuery, | ||
userByFidQuery, | ||
userByUsernameQuery, | ||
} from "./utils"; | ||
import fs from "fs"; | ||
import { AirstackUserFetchResult } from "./types"; | ||
|
||
export const airstackService: Service = { | ||
name: "airstack", | ||
export class airstackService { | ||
private apiKey: string; | ||
constructor(apiKey: string) { | ||
this.apiKey = apiKey; | ||
init(this.apiKey); | ||
} | ||
|
||
private getUserFromAirstackSociaslResult(data: AirstackUserFetchResult["Socials"]) { | ||
const userDetails = data.Social[0]; | ||
const userAddresses = this.getUserAddresses(userDetails.connectedAddresses); | ||
const convertedUser: User = { | ||
fid: Number(userDetails.userId), | ||
username: userDetails.profileName, | ||
displayName: userDetails.profileDisplayName, | ||
pfpUrl: userDetails.profileImage, | ||
followerCount: userDetails.followerCount, | ||
followingCount: userDetails.followingCount, | ||
powerBadge: userDetails.isFarcasterPowerUser, | ||
bio: userDetails.profileBio, | ||
ethAddresses: [...userAddresses.ethAddresses, userDetails.userAddress], | ||
solAddresses: [...userAddresses.solAddresses], | ||
}; | ||
return convertedUser; | ||
} | ||
|
||
private getUserAddresses( | ||
userAddresses: { address: string; blockchain: string }[] | ||
) { | ||
const ethAddresses: string[] = []; | ||
const solAddresses: string[] = []; | ||
for (const address of userAddresses) { | ||
if (address.blockchain === "ethereum") { | ||
ethAddresses.push(address.address); | ||
} | ||
if (address.blockchain === "solana") { | ||
solAddresses.push(address.address); | ||
} | ||
} | ||
return { ethAddresses, solAddresses }; | ||
} | ||
|
||
async getUserByFid(fid: number, viewerFid: number): Promise<User> { | ||
return new Promise((resolve, reject) => { | ||
reject("Not implemented"); | ||
}); | ||
}, | ||
const query = userByFidQuery(fid, viewerFid); | ||
const { data, error } = await fetchQuery(query); | ||
const returnedData = data as AirstackUserFetchResult; | ||
const user = this.getUserFromAirstackSociaslResult(returnedData.Socials); | ||
const viewerContext = { | ||
following: !!returnedData.Following.Following, | ||
followedBy: !!returnedData.Followedby.Following, | ||
} | ||
user.viewerContext = viewerContext; | ||
return user; | ||
} | ||
|
||
async getUserByUsername(username: string, viewerFid: number): Promise<User> { | ||
return new Promise((resolve, reject) => { | ||
reject("Not implemented"); | ||
}); | ||
}, | ||
async getUserByUsername(username: string): Promise<User> { | ||
const query = userByUsernameQuery(username); | ||
const { data, error } = await fetchQuery(query); | ||
const returnedData = data as Omit<AirstackUserFetchResult, "Following" | "Followedby">; | ||
return this.getUserFromAirstackSociaslResult(returnedData.Socials); | ||
} | ||
|
||
async getCastByHash(hash: string, viewerFid: number): Promise<Cast> { | ||
return new Promise((resolve, reject) => { | ||
reject("Not implemented"); | ||
}); | ||
}, | ||
} | ||
|
||
async getCastByUrl(url: string, viewerFid: number): Promise<Cast> { | ||
return new Promise((resolve, reject) => { | ||
reject("Not implemented"); | ||
}); | ||
}, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// ------------------------------------ | ||
|
||
// GENERATED TYPES FOR AIRSTACK QUERIES | ||
|
||
// ------------------------------------ | ||
|
||
export interface AirstackUserFetchResult { | ||
Socials: Socials; | ||
Following: Follow; | ||
Followedby: Follow; | ||
} | ||
|
||
export interface Follow { | ||
Following: any; | ||
} | ||
|
||
export interface Socials { | ||
Social: Social[]; | ||
} | ||
|
||
export interface Social { | ||
userId: string; | ||
userAddress: string; | ||
profileDisplayName: string; | ||
profileName: string; | ||
connectedAddresses: ConnectedAddress[]; | ||
followerCount: number; | ||
followingCount: number; | ||
profileImage: string; | ||
profileBio: string; | ||
isFarcasterPowerUser: boolean; | ||
} | ||
|
||
export interface ConnectedAddress { | ||
address: string; | ||
blockchain: string; | ||
} | ||
|
||
export interface UserAddressDetails { | ||
addresses: string[]; | ||
blockchain: string; | ||
} |
Oops, something went wrong.