Skip to content

Commit

Permalink
Feat/api (#8)
Browse files Browse the repository at this point in the history
* added viem

* updated mint

* contract and api

* Update MintNFT.sol

Signed-off-by: Afolabi <[email protected]>

---------

Signed-off-by: Afolabi <[email protected]>
Co-authored-by: Afo <[email protected]>
Co-authored-by: tarun gupta <[email protected]>
Co-authored-by: Afolabi <[email protected]>
  • Loading branch information
4 people authored Jul 4, 2024
1 parent 81fc049 commit abb6373
Show file tree
Hide file tree
Showing 7 changed files with 2,598 additions and 4,415 deletions.
8 changes: 5 additions & 3 deletions client/app/frames/calculate/route.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react/jsx-key */
import { Button } from "frames.js/next";

import { calculateGreenWill } from "../../../modules/graphql";
import { frames } from "../frames";

const PASSING_SCORE = 40;
Expand All @@ -18,8 +18,10 @@ function scoreMessage(score: number) {
}

export const POST = frames(async (ctx) => {
const greenWillScore = 50; /// TODO: Update with function returning score

console.log("CTX ID is", ctx.message?.requesterFid)
// const greenWillScore = 50; /// TODO: Update with function returning score
const greenWillScore = await calculateGreenWill(ctx.message?.requesterFid);
console.log("Your greenWill Score is ", greenWillScore);
const canClaim = greenWillScore > PASSING_SCORE;

const updatedState = {
Expand Down
2 changes: 1 addition & 1 deletion client/app/frames/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const handleRequest = frames(async (ctx) => {
Check Your GreenWill!
{/* <img
alt="Green Pill"
src="/pill.png"
src="../../public/pill.png"
className="aspect-square w-1/2 h-1/2"
/> */}
</div>
Expand Down
136 changes: 110 additions & 26 deletions client/modules/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import { request, gql } from "graphql-request";

const AIRSTACK_API = "https://grants-stack-indexer-v2.gitcoin.co/graphql";
const AIRSTACK_API = "https://api.airstack.xyz/graphql";
const GRANTS_STACK_API = "https://grants-stack-indexer-v2.gitcoin.co/graphql";

const map = new Map();
map.set("owocki", true);
map.set("jimicohen", true);
map.set("luciano", true);

const queryGreenWill = gql`
query GetFollowers {
const mapFollowers = new Map<string, boolean>([["owocki", true], ["jimicohen", true], ["luciano", true]]);


const mapFollowings = new Map<string, boolean>([["owocki", true], ["jimicohen", true], ["luciano", true], ["octant", true], ["sophia", true], ["jessepollak", true]]);

const mapChannels = new Map<string, boolean>([["Green-pill", true], ["Regen", true], ["Greenpill", true]]);

const queryFollowers = gql`
query GetFarcasterFollowers($user: Identity!) {
SocialFollowers(
input: {
filter: {
identity: { _eq: "fc_fname:wusp" }
dappName: { _eq: farcaster }
}
blockchain: ALL
limit: 50
}
input: {filter: {identity: {_eq: $user}, dappName: {_eq: farcaster}}, blockchain: ALL, limit: 50}
) {
Follower {
dappName
Expand All @@ -34,6 +30,39 @@ const queryGreenWill = gql`
}
`;


const queryFollowings = gql`
query GetFarcasterFollowings($user: Identity!) {
SocialFollowings(
input: {filter: {identity: {_eq: $user}, dappName: {_eq: farcaster}}, blockchain: ALL, limit: 50}
) {
Following {
followingAddress {
socials(input: {filter: {dappName: {_eq: farcaster}}}) {
profileName
}
}
}
}
}
`;

const queryRegenTokens = gql`
query GetRegenTokensForWusp($user: Identity!) {
Socials(input: {filter: {profileName: {_eq: $user}}, blockchain: ALL}) {
Social {
dappName
profileName
userAddressDetails {
tokenBalances(input: {filter: {tokenAddress: {_eq: "0xEc482De9569a5EA3Dd9779039b79e53F15791fDE"}}, limit: 50}) {
amount
}
}
}
}
}
`;

const queryGrants = gql`
query QueryRound($id: String!, $chainId: Int!) {
round(chainId: $chainId, id: $id) {
Expand All @@ -45,23 +74,78 @@ const queryGrants = gql`
}
`;

export async function calculateGreenWill() {
const data = await request<{ rounds: any[] }>(AIRSTACK_API, queryGreenWill);
let followers = [];
const temp = data.data.SocialFollowers.Follower;
for (let i = 0; i < temp.length; i++) {
for (let j = 0; j < temp[i].followerAddress.socials.length; j++) {
followers.push(temp[i].followerAddress.socials[j].profileName);
const queryChannels = gql`
query GetFarcasterChannelsSubscribedByWusp($user: Identity!) {
FarcasterChannelParticipants(
input: {filter: {participant: {_eq: $user}}, blockchain: ALL, limit: 50}
) {
FarcasterChannelParticipant {
channelId
channelName
channel {
createdAtTimestamp
description
imageUrl
}
channelActions
}
}
console.log(followers);
}
`;

export async function calculateGreenWill(userId: string) {

let score = 0;
for (let i = 0; i < followers.length; i++) {
if (map.get(followers[i]) === true) {
score++;
// get the score from followers
const dataFollowers = await request<{ data: any }>(AIRSTACK_API, queryFollowers, {
user: "fc_fid:" + userId
});

let followers = []
const temp = dataFollowers.SocialFollowers.Follower;
for(let i = 0; i < temp.length; i++) {
for(let j = 0; j < temp[i].followerAddress.socials.length; j++) {
followers.push(temp[i].followerAddress.socials[j].profileName);
}
}
const followersCount = followers.filter(follower => mapFollowers.get(follower)).length;
if (followersCount >= 1) score += 10;

//get the score from followings
const dataFollowings = await request<{ data: any }>(AIRSTACK_API, queryFollowings, {
user: "fc_fid:" + userId
});
let followings = []
const temp2 = dataFollowings.SocialFollowings.Following;
for(let i = 0; i < temp2.length; i++) {
for(let j = 0; j < temp2[i].followingAddress.socials.length; j++) {
followings.push(temp2[i].followingAddress.socials[j].profileName);
}
}
const followingCount = followings.filter(following => mapFollowings.get(following)).length;
if (followingCount >= 5) score += 5;


//get the score from regen tokens
// const dataRegenTokens = await request<{data: any}>(AIRSTACK_API, queryRegenTokens);
// const tokens = dataRegenTokens.Socials.Social.userAddressDetails.tokenBalances.amount;
// if(tokens > 0) score += 5;


//get the score from channel subscriptions
const dataChannels = await request<{data: any}>(AIRSTACK_API, queryChannels, {
user: "fc_fid:" + userId
});

let subscribedChannels = [];
const tempChannels = dataChannels.FarcasterChannelParticipants.FarcasterChannelParticipant;
for (let i = 0; i < tempChannels.length; i++) {
subscribedChannels.push(tempChannels[i].channelName);
}

const subscribedChannelsCount = subscribedChannels.filter(channel => mapChannels.get(channel)).length;
if (subscribedChannelsCount >= 1) score += 10;
return score;
}

export async function fetchGrants(id: string) {
Expand Down
4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"frames.js": "^0.17.0",
"next": "^14.1.4",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"viem": "2.16.5"
},
"devDependencies": {
"@frames.js/debugger": "^0.3.0",
"@types/node": "^18.17.0",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0",
"@frames.js/debugger": "^0.3.0",
"autoprefixer": "^10.0.1",
"concurrently": "^8.2.2",
"dotenv": "^16.4.5",
Expand Down
Loading

0 comments on commit abb6373

Please sign in to comment.