Skip to content

Commit

Permalink
✨ Add product name to reward history
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed Nov 5, 2024
1 parent 05cc480 commit a1f0cda
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/ponder/src/api/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ ponder.get("/interactions/:wallet", async (ctx) => {
}

// Get the tables we will query
const { InteractionEvent, ProductInteractionContract } = ctx.tables;
const { InteractionEvent, ProductInteractionContract, Product } =
ctx.tables;

// Perform the sql query
const interactions = await ctx.db
Expand All @@ -28,12 +29,17 @@ ponder.get("/interactions/:wallet", async (ctx) => {
type: InteractionEvent.type,
timestamp: InteractionEvent.timestamp,
productId: ProductInteractionContract.productId,
productName: Product.name,
})
.from(InteractionEvent)
.innerJoin(
ProductInteractionContract,
eq(ProductInteractionContract.id, InteractionEvent.interactionId)
)
.innerJoin(
Product,
eq(Product.id, ProductInteractionContract.productId)
)
.where(eq(InteractionEvent.user, wallet))
.limit(100)
.orderBy(desc(InteractionEvent.timestamp));
Expand Down
15 changes: 13 additions & 2 deletions packages/ponder/src/api/rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ ponder.get("/rewards/:wallet/history", async (ctx) => {
const walletfilter = `%${wallet}`;

// Get the tables we will query
const { RewardAddedEvent, RewardClaimedEvent, BankingContract, Reward } =
ctx.tables;
const {
RewardAddedEvent,
RewardClaimedEvent,
BankingContract,
Reward,
Product,
} = ctx.tables;

// Perform the sql query
const rewardAddedPromise = ctx.db
Expand All @@ -70,10 +75,13 @@ ponder.get("/rewards/:wallet/history", async (ctx) => {
txHash: RewardAddedEvent.txHash,
timestamp: RewardAddedEvent.timestamp,
token: BankingContract.tokenId,
productId: BankingContract.productId,
productName: Product.name,
})
.from(RewardAddedEvent)
.innerJoin(Reward, eq(Reward.id, RewardAddedEvent.rewardId))
.innerJoin(BankingContract, eq(BankingContract.id, Reward.contractId))
.innerJoin(Product, eq(Product.id, BankingContract.productId))
.where(like(RewardAddedEvent.rewardId, walletfilter))
.limit(100)
.orderBy(desc(RewardAddedEvent.timestamp));
Expand All @@ -85,10 +93,13 @@ ponder.get("/rewards/:wallet/history", async (ctx) => {
txHash: RewardClaimedEvent.txHash,
timestamp: RewardClaimedEvent.timestamp,
token: BankingContract.tokenId,
productId: BankingContract.productId,
productName: Product.name,
})
.from(RewardClaimedEvent)
.innerJoin(Reward, eq(Reward.id, RewardClaimedEvent.rewardId))
.innerJoin(BankingContract, eq(BankingContract.id, Reward.contractId))
.innerJoin(Product, eq(Product.id, BankingContract.productId))
.where(like(RewardClaimedEvent.rewardId, walletfilter))
.limit(100)
.orderBy(desc(RewardClaimedEvent.timestamp));
Expand Down

0 comments on commit a1f0cda

Please sign in to comment.