Skip to content

Commit

Permalink
Improve lottery service
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpolman committed Jun 7, 2024
1 parent 5a1f7c5 commit f331f1f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
24 changes: 12 additions & 12 deletions apps/api/src/app/controllers/lotteries/list.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ const lotteries = [
description:
'In the realms of Forest Knight, many items are digital collectibles allowing the players a full ownership. You as a player can decide what you want to do with them, use them, trade them or combine them! A new frontier of gaming is here.',
participantCount: 100,
winners: {
THX02G6NMUMU0052024: Rewards.ForestKnight.RunestoneOfTheEclipse,
THXSUR9F62ZRE052024: Rewards.ForestKnight.RunestoneOfTheEclipse,
THXT51NWPZY0Z052024: Rewards.ForestKnight.RunestoneOfTheEclipse,
THXH7TQX5FETL052024: Rewards.ForestKnight.RunestoneOfTheEclipse,
THXMYH9D2GFAI052024: Rewards.ForestKnight.RunestoneOfTheEclipse,
THXNDZDDSSI3O052024: Rewards.ForestKnight.RunestoneOfTheEclipse,
THXEUIAY54H01052024: Rewards.ForestKnight.RunestoneOfTheEclipse,
THXV1BVL7XZBF052024: Rewards.ForestKnight.RunestoneOfTheEclipse,
THXBI11LY2C2P052024: Rewards.ForestKnight.RunestoneOfTheEclipse,
THXNT5QAUHBNN052024: Rewards.ForestKnight.RunestoneOfTheEclipse,
},
winners: [
{ code: 'THX02G6NMUMU0052024', reward: Rewards.ForestKnight.RunestoneOfTheEclipse },
{ code: 'THXSUR9F62ZRE052024', reward: Rewards.ForestKnight.RunestoneOfTheEclipse },
{ code: 'THXT51NWPZY0Z052024', reward: Rewards.ForestKnight.RunestoneOfTheEclipse },
{ code: 'THXH7TQX5FETL052024', reward: Rewards.ForestKnight.BigBagOfKnight },
{ code: 'THXMYH9D2GFAI052024', reward: Rewards.ForestKnight.BigBagOfKnight },
{ code: 'THXNDZDDSSI3O052024', reward: Rewards.ForestKnight.BigBagOfKnight },
{ code: 'THXEUIAY54H01052024', reward: Rewards.ForestKnight.BigBagOfKnight },
{ code: 'THXV1BVL7XZBF052024', reward: Rewards.ForestKnight.ClockworkCodex },
{ code: 'THXBI11LY2C2P052024', reward: Rewards.ForestKnight.ClockworkCodex },
{ code: 'THXNT5QAUHBNN052024', reward: Rewards.ForestKnight.ClockworkCodex },
],
},
];

Expand Down
11 changes: 6 additions & 5 deletions apps/api/src/app/services/LotteryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export default class LotteryService {
lotteries.map(async (lottery) => {
try {
// Get CouponCode for winning codes
const codes = await CouponCode.find({ code: { $in: lottery.winners } });
const codes = await CouponCode.find({
code: { $in: lottery.winners.map((winner) => winner.code) },
});

// Get subs for winning codes
const subs = codes.map((code) => code.sub);
Expand All @@ -44,16 +46,15 @@ export default class LotteryService {

return {
...lottery,
winners: lottery.winners.map((winner: string) => {
const code = codes.find(({ code }) => code === winner);
winners: lottery.winners.map((winner) => {
const code = codes.find(({ code }) => code === winner.code);
const account = accounts.find((a) => a.sub === code.sub);
return {
code,
...winner,
account: {
avatarURL: account.profileImg,
username: account.username,
},
reward: Rewards.ForestKnight.RunestoneOfTheEclipse,
};
}),
};
Expand Down
1 change: 0 additions & 1 deletion apps/app/src/components/button/BaseButtonLiquidityLock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { useVeStore } from '@thxnetwork/app/stores/VE';
import { useAccountStore } from '@thxnetwork/app/stores/Account';
import { contractNetworks } from '../../config/constants';
import { ChainId } from '@thxnetwork/common/enums';
import { track } from '@thxnetwork/common/mixpanel';
export default defineComponent({
name: 'BaseButtonLiquidityLock',
Expand Down
2 changes: 1 addition & 1 deletion apps/app/src/components/card/BaseCardLottery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<b-collapse v-model="isCollapsed">
<b-row>
<b-col v-for="winner of lottery.winners" lg="6">
<BaseCardLotteryWinner v-if="winner.account" class="mb-3" :winner="winner" />
<BaseCardLotteryWinner class="mb-3" :winner="winner" />
</b-col>
</b-row>
</b-collapse>
Expand Down
2 changes: 1 addition & 1 deletion apps/app/src/components/card/BaseCardLotteryWinner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<i class="fas fa-tags me-2 text-opaque" />
<span class="">{{ winner.code }}</span>
</b-badge>
<div class="d-flex mt-3 align-items-center ms-auto">
<div v-if="winner.account" class="d-flex mt-3 align-items-center ms-auto">
<b-avatar :src="winner.account.avatarURL" size="1.5rem" class="me-2" />
<span>{{ winner.account.username }}</span>
</div>
Expand Down

0 comments on commit f331f1f

Please sign in to comment.