update profilepage

This commit is contained in:
EmberSpirit
2023-09-08 23:05:34 +02:00
parent cd773e16c9
commit dfd208e075
26 changed files with 2155 additions and 600 deletions
+149 -120
View File
@@ -8,136 +8,165 @@ import { multicall } from "@wagmi/core";
export const useRoundsStore = defineStore("rounds", {
state: () => ({
rounds: [
],
activeRound: null,
currentRound: null
rounds: [],
activeRound: null,
currentRound: null,
}),
getters: {
getRoundWinner() {
const goal = this.getCurrentRoundData?.goal;
const winnerCoin = this.rounds[this.activeRound]?.token.find((token) => token.amount === goal)
if (winnerCoin) {
return winnerCoin;
} else {
return false;
}
},
getCurrentRoundData() {
return this.rounds[this.activeRound];
}
},
actions: {
async init() {
//fill initial round
},
async loadRewardsRounds() {
const walletStore = useWalletStoreV2();
const rewardLockerStore = useRewardLockerStore();
getters: {
getRoundWinner() {
const goal = this.getCurrentRoundData?.goal;
console.log("goal", goal);
if (!goal) {
return;
}
const winnerCoin = this.rounds[this.activeRound]?.token.find((token) => token.amount === goal);
if (winnerCoin) {
return winnerCoin;
} else {
return false;
}
},
getCurrentRoundData() {
console.log("this.rounds", this.rounds);
return this.rounds[this.activeRound];
},
},
actions: {
async init() {
//fill initial round
},
async loadRewardsRounds() {
const walletStore = useWalletStoreV2();
const rewardLockerStore = useRewardLockerStore();
console.log("this.currentRound", this.currentRound);
const contracts = []
for (let index = 0; index < this.currentRound; index++) {
console.log("load round: " + index);
// await this.fillRound(index)
console.log({index, address: walletStore.address});
contracts.push({
console.log("this.currentRound", this.currentRound);
const contracts = [];
for (let index = 0; index < this.currentRound; index++) {
console.log("load round: " + index);
// await this.fillRound(index)
console.log({ index, address: walletStore.address });
contracts.push({
...rewardLockerStore.contract,
functionName: "getTotalRewardsOf",
args: [walletStore.address, [index +1]],
args: [walletStore.address, [index + 1]],
});
}
}
const data = await multicall({
const data = await multicall({
contracts,
});
console.log("data123abc", data);
// var test = await rewardLockerStore.getTotalRewardsOf(walletStore.address, rounds)
for (let index = 0; index < data.length; index++) {
const element = data[index];
if (!this.rounds[index]) {
this.rounds[index] = {};
}
this.rounds[index].round = index + 1
this.rounds[index].rewards_total = element.result
}
},
async updateCurrentRound(sacrificedToken) {
const tokenStore = useTokenStore();
const memeBurnerStore = useMemeburnerStore();
var data = await memeBurnerStore.getSacrificedRound(this.currentRound);
console.log("data123", data);
var tokenIndex = this.rounds[this.currentRound].token.findIndex((tokenData) => tokenData.contractAddress === sacrificedToken);
this.rounds[this.currentRound].token[tokenIndex].amount = data[tokenIndex].result[1];
});
console.log("data123abc", data);
// var test = await rewardLockerStore.getTotalRewardsOf(walletStore.address, rounds)
for (let index = 0; index < data.length; index++) {
const element = data[index];
if (!this.rounds[index]) {
this.rounds[index] = {};
}
this.rounds[index].round = index + 1;
this.rounds[index].rewards_total = element.result;
}
},
async updateCurrentRound(sacrificedToken) {
const tokenStore = useTokenStore();
const memeBurnerStore = useMemeburnerStore();
var data = await memeBurnerStore.getSacrificedRound(this.currentRound);
console.log("data123", data);
var tokenIndex = this.rounds[this.currentRound].token.findIndex(
(tokenData) => tokenData.contractAddress === sacrificedToken
);
this.rounds[this.currentRound].token[tokenIndex].amount = data[tokenIndex].result[1];
},
async fillRound(roundNumber) {
console.log("fillRound");
const memeBurnerStore = useMemeburnerStore();
const tokenStore = useTokenStore();
const walletStore = useWalletStoreV2();
const rewardLockerStore = useRewardLockerStore();
},
async fillRound(roundNumber) {
console.log("fillRound");
const memeBurnerStore = useMemeburnerStore();
const tokenStore = useTokenStore();
const walletStore = useWalletStoreV2();
const rewardLockerStore = useRewardLockerStore();
// if (this.activeRound === this.currentRound) {
// console.log("activeRound is not completed");
// } else
if (!this.rounds[roundNumber]?.goal) {
console.log("round not filled --> fill round");
console.log("vor error");
var data = await memeBurnerStore.getSacrificedRound(roundNumber);
let rewardData = null;
if (walletStore.connected) {
console.log("hier1");
rewardData = await rewardLockerStore.getRewardsForAllToken(roundNumber);
console.log("hier2", rewardData);
}
console.log("rewardData123", rewardData);
// if (this.activeRound === this.currentRound) {
// console.log("activeRound is not completed");
// } else
if (!this.rounds[roundNumber]?.goal) {
console.log("round not filled --> fill round");
console.log("vor error");
var data = await memeBurnerStore.getSacrificedRound(roundNumber)
let rewardData = null;
if (walletStore.connected) {
rewardData = await rewardLockerStore.getRewardsForAllToken(roundNumber);
}
console.log("rewardData123", rewardData);
var goal = await memeBurnerStore.getGoal(roundNumber);
console.log("goal", goal);
var tokenArray = []
var rewards_clan = 0
var rewards_sacrifice = 0
for (let index = 0; index < data.length; index++) {
var tokenData = {};
const token = tokenStore.token[index];
var testcoef = await rewardLockerStore.getSacrificedTokenCoefficient(roundNumber, token.contractAddress);
var goal = await memeBurnerStore.getGoal(roundNumber);
console.log("goal", goal);
var tokenArray = [];
var rewards_clan = 0;
var rewards_sacrifice = 0;
for (let index = 0; index < data.length; index++) {
var tokenData = {};
const token = tokenStore.token[index];
var testcoef = await rewardLockerStore.getSacrificedTokenCoefficient(
roundNumber,
token.contractAddress
);
tokenData.name = token.name;
tokenData.contractAddress = token.contractAddress;
tokenData.vamplogo = token.vamp.logo;
tokenData.vampname = token.vamp.name;
tokenData.amount = data[index].result[1];
tokenData.getAmountToReachGoal= await memeBurnerStore.getAmountToReachGoal(token.contractAddress);
if (this.currentRound !== roundNumber && walletStore.connected) {
const clanwin = (Number(testcoef) / 10000 - 1) * Number(rewardData[index].result);
const sacrificeRewards = Number(rewardData[index].result) - clanwin;
tokenData.name = token.name;
tokenData.contractAddress = token.contractAddress;
tokenData.vamplogo = token.vamp.logo;
tokenData.vampname = token.vamp.name;
tokenData.amount = data[index].result[1];
tokenData.getAmountToReachGoal = await memeBurnerStore.getAmountToReachGoal(token.contractAddress);
if (this.currentRound !== roundNumber && walletStore.connected) {
const clanwin = (Number(testcoef) / 10000 - 1) * Number(rewardData[index].result);
const sacrificeRewards = Number(rewardData[index].result) - clanwin;
tokenData.rewards_ges = BigInt(rewardData[index].result);
tokenData.rewards_clan = BigInt(clanwin);
tokenData.rewards_sacrifice = BigInt(sacrificeRewards);
tokenData.rewards_ges = BigInt(rewardData[index].result);
tokenData.rewards_clan = BigInt(clanwin);
tokenData.rewards_sacrifice = BigInt(sacrificeRewards);
rewards_clan = rewards_clan + (clanwin / Math.pow(10, token.decimals));
rewards_sacrifice =
rewards_sacrifice + sacrificeRewards / Math.pow(10, token.decimals);
}
tokenArray.push(tokenData);
}
const goalInBLD = await memeBurnerStore.getGoalInBLD(roundNumber);
this.rounds[roundNumber] = {
goal: goal[0],
goalInBLD: goalInBLD / BigInt(Math.pow(10, tokenStore.memeToken.decimals)),
expirationTimestamp: goal[1],
rewards_clan: BigInt(rewards_clan),
rewards_sacrifice: BigInt(rewards_sacrifice),
rewards_total: BigInt(rewards_clan + rewards_sacrifice),
token: tokenArray,
};
console.log("this.rounds[roundNumber]", this.rounds[roundNumber]);
} else {
console.log("round already filled");
}
console.log("this.rounds123", this.rounds);
},
},
rewards_clan = rewards_clan + clanwin / Math.pow(10, token.decimals);
rewards_sacrifice = rewards_sacrifice + sacrificeRewards / Math.pow(10, token.decimals);
}
tokenArray.push(tokenData);
}
const goalInBLD = await memeBurnerStore.getGoalInBLD(roundNumber);
this.rounds[roundNumber] = {
goal: goal[0],
goalInBLD: goalInBLD / BigInt(Math.pow(10, tokenStore.memeToken.decimals)),
expirationTimestamp: goal[1],
rewards_clan: BigInt(rewards_clan),
rewards_sacrifice: BigInt(rewards_sacrifice),
rewards_total: BigInt(rewards_clan + rewards_sacrifice),
token: tokenArray,
};
console.log("this.rounds[roundNumber]", this.rounds[roundNumber]);
} else {
console.log("round already filled");
}
console.log("this.rounds123", this.rounds);
},
async getFinshedRoundNumbers() {
const array = [];
const rewardLockerStore = useRewardLockerStore();
const lastCompletedRound = await rewardLockerStore.lastCompletedRound();
for (let index = 1; index <= Number(lastCompletedRound) + 1; index++) {
array.push(index);
}
return array;
},
/**
* function to get finished rounds, active round and the next round to check if there is a round the user called unstakeOrdered.
* with Backend it would be much easier because we could store the event data in the database
*/
async getRoundsNumberWithNext() {
const array = [];
const rewardLockerStore = useRewardLockerStore();
const lastCompletedRound = await rewardLockerStore.lastCompletedRound();
for (let index = 1; index <= Number(lastCompletedRound) + 1; index++) {
array.push(index);
}
return array;
},
},
});