-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show previous allocated amounts by connected address
- Loading branch information
1 parent
7bc7b57
commit 7bf503b
Showing
3 changed files
with
90 additions
and
6 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
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { gql, request } from "graphql-request"; | ||
|
||
export const useAllocation = ( | ||
council: `0x${string}` | undefined, | ||
councilMember: `0x${string}` | undefined, | ||
) => { | ||
const url = | ||
"https://api.goldsky.com/api/public/project_cm10r8z66lbri01se6301ddxj/subgraphs/councilhaus/0.0.1/gn"; | ||
const query = gql` | ||
query LastAllocation($council: String, $councilMember: String) { | ||
allocations( | ||
first: 1 | ||
where: { council: $council, councilMember: $councilMember } | ||
orderBy: allocatedAt | ||
orderDirection: desc | ||
) { | ||
grantees { | ||
id | ||
} | ||
amounts | ||
} | ||
} | ||
`; | ||
const { data, isLoading } = useQuery<{ | ||
allocations: { | ||
grantees: { id: string }[]; | ||
amounts: string[]; | ||
}[]; | ||
}>({ | ||
queryKey: ["allocation"], | ||
async queryFn() { | ||
return await request(url, query, { | ||
council: council?.toLowerCase(), | ||
councilMember: councilMember?.toLowerCase(), | ||
}); | ||
}, | ||
enabled: !!council && !!councilMember, | ||
}); | ||
const allocation = data?.allocations?.[0]; | ||
if (!allocation) { | ||
return { data: undefined, isLoading }; | ||
} | ||
const formattedAllocation: { [grantee: `0x${string}`]: number } = | ||
Object.fromEntries( | ||
allocation.grantees.map((g, index) => [ | ||
g.id as `0x${string}`, | ||
Number(allocation.amounts[index]), | ||
]), | ||
); | ||
return { | ||
data: formattedAllocation, | ||
isLoading, | ||
}; | ||
}; |