UNPKG

@moonwell-fi/moonwell-sdk

Version:

TypeScript Interface for Moonwell

37 lines 1.35 kB
import { Amount, getEnvironmentFromArgs } from "../../common/index.js"; import { fetchUserVoteReceipt } from "./governor-api-client.js"; export async function getUserVoteReceipt(client, args) { const { proposalId, userAddress } = args; const environment = getEnvironmentFromArgs(client, args); if (!environment) { return []; } try { const apiVoteReceipts = await fetchUserVoteReceipt(environment, `${proposalId}`, userAddress); if (apiVoteReceipts.length === 0) { return [ { chainId: environment.chainId, proposalId, account: userAddress, voted: false, option: 0, votes: new Amount(0, 18), }, ]; } return apiVoteReceipts.map((apiReceipt) => ({ chainId: apiReceipt.chainId, proposalId, account: userAddress, voted: true, option: apiReceipt.voteValue, votes: new Amount(BigInt(apiReceipt.votes), 18), })); } catch (error) { const message = error instanceof Error ? error.message : String(error); throw new Error(`Failed to fetch user vote receipt: ${message}`); } } //# sourceMappingURL=getUserVoteReceipt.js.map