-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/shapeshift_member_uri'
# Conflicts: # Implementations/API/package-lock.json # Implementations/API/yarn.lock
- Loading branch information
Showing
6 changed files
with
3,243 additions
and
3,128 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
Implementations/API/backend/functions/boardroom/getMembers.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,64 @@ | ||
import { APIGatewayProxyHandlerV2 } from "aws-lambda"; | ||
import { BoardroomAddressKeyConfig, shapeshiftApiConfig } from "../config"; | ||
import fetch, { RequestInit } from "node-fetch"; | ||
import { utils } from "ethers"; | ||
|
||
function apiRequest(path: string, method: "GET" | "POST", data?: any) { | ||
const payload: RequestInit = { | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
method, | ||
redirect: "follow", | ||
}; | ||
if (method === "POST") payload.body = JSON.stringify(data); | ||
return fetch(path, payload).then((res) => res.json()); | ||
} | ||
|
||
export const handler: APIGatewayProxyHandlerV2 = async (event) => { | ||
const network = event?.pathParameters?.network; | ||
if (!network) return { statusCode: 400, message: "Missing network" }; | ||
|
||
const path = shapeshiftApiConfig[network]; | ||
if (!path) return { statusCode: 400, message: "Missing config for network" }; | ||
|
||
const eventId = event?.pathParameters?.id; | ||
if (!eventId) return { statusCode: 400, message: "Missing id" }; | ||
|
||
const template = { | ||
"@context": { | ||
"@vocab": "http://daostar.org/", | ||
}, | ||
type: "DAO", | ||
name: eventId, | ||
}; | ||
|
||
const address = utils.getAddress(eventId); | ||
|
||
const queryPath = | ||
path + "/voters" + "?limit=50&key=" + BoardroomAddressKeyConfig[address]; | ||
|
||
const res = (await apiRequest(queryPath, "GET")) as any; | ||
|
||
if (!res.data) return { statusCode: 404, message: "DAO not found" }; | ||
const voters = res.data; | ||
|
||
const membersFormatted = voters.map((a: any) => { | ||
return { | ||
id: a.address, | ||
type: "EthereumAddress", | ||
}; | ||
}); | ||
|
||
const transformed = { members: membersFormatted, ...template }; | ||
|
||
return transformed | ||
? { | ||
statusCode: 200, | ||
body: JSON.stringify(transformed), | ||
} | ||
: { | ||
statusCode: 404, | ||
body: JSON.stringify({ error: true }), | ||
}; | ||
}; |
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
Oops, something went wrong.