Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions functions/api/ccd007-citycoin-stacking/get-stacker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ export async function onRequest(context: any): Promise<Response> {
if (!cycle) return createResponse('Missing cycle parameter', 400);
const userId = requestUrl.searchParams.get('userId');
if (!userId) return createResponse('Missing userId parameter', 400);
const tip = requestUrl.searchParams.get('tip');

// get result from contract
const stacker = await getStacker(cityId, cycle, userId);
const stacker = await getStacker(cityId, cycle, userId, tip ? tip : undefined);

// return result
if (!stacker) return createResponse(`Stacker not found: ${cityId} ${cycle} ${userId}`, 404);
return createResponse(stacker);
}

// returns the stacker for a given cityId, cycle, and userId
async function getStacker(cityId: string, cycle: string, userId: string) {
async function getStacker(cityId: string, cycle: string, userId: string, tip?: string) {
try {
const result = await fetchReadOnlyFunction(
{
Expand All @@ -31,6 +32,7 @@ async function getStacker(cityId: string, cycle: string, userId: string) {
functionName: 'get-stacker',
functionArgs: [uintCV(Number(cityId)), uintCV(Number(cycle)), uintCV(Number(userId))],
network: NETWORK('mainnet'),
tip: tip,
},
true
);
Expand Down
6 changes: 4 additions & 2 deletions functions/api/ccd007-citycoin-stacking/is-cycle-paid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ export async function onRequest(context: any): Promise<Response> {
if (!cityId) return createResponse('Missing cityId parameter', 400);
const cycle = requestUrl.searchParams.get('cycle');
if (!cycle) return createResponse('Missing cycle parameter', 400);
const tip = requestUrl.searchParams.get('tip');

// get result from contract
const paid = await isCyclePaid(cityId, cycle);
const paid = await isCyclePaid(cityId, cycle, tip ? tip : undefined);

// return result
if (paid === null) return createResponse(`Cycle payout information not found: ${cityId} ${cycle}`, 404);
return createResponse(paid);
}

// returns true if the cycle is paid
async function isCyclePaid(cityId: string, cycle: string) {
async function isCyclePaid(cityId: string, cycle: string, tip?: string) {
try {
const result = await fetchReadOnlyFunction(
{
Expand All @@ -29,6 +30,7 @@ async function isCyclePaid(cityId: string, cycle: string) {
functionName: 'is-cycle-paid',
functionArgs: [uintCV(Number(cityId)), uintCV(Number(cycle))],
network: NETWORK('mainnet'),
tip: tip,
},
true
);
Expand Down