Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added feature to track xp on SUI wallets #41

Merged
merged 1 commit into from
Dec 17, 2024
Merged
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
34 changes: 27 additions & 7 deletions db-manager/tasks/genericTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// balanced related data (collateral, loans, etc) from
// the blockchain and updating the database with the
// latest amounts.
const { chains } = require("../common/utils/config");
const { chains, tasks: TASKS_LABELS } = require("../common/utils/config");
const {
userService,
taskService,
Expand Down Expand Up @@ -172,13 +172,11 @@ async function genericTask(taskInput, db, seedId, callback) {
for (const xChainWallet of linkedWallets) {
if (xChainWallet.type === "evm") {
for (const chain of chains.evm) {
const userWallet = `${chain}/${xChainWallet.address}`;
const userTaskDoc = userTaskDocArr.filter((doc) => {
return (
doc.walletAddress === `${chain}/${xChainWallet.address}`
);
return doc.walletAddress === userWallet;
});

const userWallet = `${chain}/${xChainWallet.address}`;
console.log(`--- xChainWallet found: ${userWallet}`);
await userTaskMainLogic(
userTaskDoc,
Expand All @@ -192,6 +190,28 @@ async function genericTask(taskInput, db, seedId, callback) {
db,
);
}
} else if (["sui", "stellar"].includes(xChainWallet.type)) {
const userWallet = `${xChainWallet.type}/${xChainWallet.address}`;
const userTaskDoc = userTaskDocArr.filter((doc) => {
return doc.walletAddress === userWallet;
});

console.log(`--- xChainWallet found: ${userWallet}`);
await userTaskMainLogic(
userTaskDoc[0],
targetTask,
prepTerm,
validUser,
activeSeason,
callback,
height,
userWallet,
db,
);
} else {
console.log(
`--- xChainWallet type ${xChainWallet.type} not supported`,
);
}
}
// if the task is referral, do nothing
Expand Down Expand Up @@ -255,7 +275,7 @@ async function userReferralTaskMainLogic(
) {
try {
const xpArray = [];
if (targetTask.seedId === "t8") {
if (targetTask.seedId === TASKS_LABELS.usingReferralCode) {
// this is the task for the case when this user is
// the one using a referral code
//
Expand Down Expand Up @@ -351,7 +371,7 @@ async function userReferralTaskMainLogic(
);
return;
}
} else if (targetTask.seedId === "t9") {
} else if (targetTask.seedId === TASKS_LABELS.referringUser) {
// this is the task for the case when this user is
// the one who has a referral code being used by
// another user
Expand Down
10 changes: 9 additions & 1 deletion nestjs-rest-server/src/shared/utils/xp-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ export function sumXp24hrs(
if (arrayOfTasks.length === 0) {
return 0;
}
return arrayOfTasks.reduce((a, b) => a + b.xp.xpEarned[b.xp.xpEarned.length - 1].xp, 0);
return arrayOfTasks.reduce((a, b) => {
let bValidated = 0;
if (b.xp.xpEarned.length > 0) {
if (b.xp.xpEarned[b.xp.xpEarned.length - 1].xp != null) {
bValidated = b.xp.xpEarned[b.xp.xpEarned.length - 1].xp ?? 0;
}
}
return a + bValidated;
}, 0);
}

export function calculateTaskTotalXp(userTasks: (UserTaskDocument | FormattedUserTask)[] | null): number {
Expand Down