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
+74 -16
View File
@@ -2,7 +2,9 @@ import { defineStore } from "pinia";
import RewardLockerJson from "@/assets/contracts/RewardLocker.json";
import { useTokenStore } from "./tokens";
import { useWalletStoreV2 } from "./walletV2";
import { multicall, getContract } from "@wagmi/core";
import { useRoundsStore } from "@/stores/rounds";
import { createPermitObject, getSignatureRSV } from "@/helper/blockchain.js";
import { multicall, getContract, signTypedData, getAccount, waitForTransaction } from "@wagmi/core";
export const useRewardLockerStore = defineStore("rewardlocker", {
@@ -14,9 +16,9 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
getters: {},
actions: {
async init() {
console.log("-----------init rewardlocker-------------");
const walletStore = useWalletStoreV2();
this.contract = getContract({
console.log("-----------init rewardlocker-------------");
const walletStore = useWalletStoreV2();
this.contract = getContract({
address: this.config.contractAddress,
abi: this.config.abi,
walletClient: walletStore.walletClient || walletStore.publicClient,
@@ -35,21 +37,21 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
console.log("getRewardsForAllToken");
const tokenStore = useTokenStore();
const walletStore = useWalletStoreV2();
const contracts = [];
const contracts = [];
for (let index = 0; index < tokenStore.sacrificeToken.length; index++) {
const token = tokenStore.sacrificeToken[index];
const token = tokenStore.sacrificeToken[index];
// calls.push(this.contract.methods.rewards(walletStore.address, roundNumber, token.contractAddress));
contracts.push({
...this.contract,
functionName: "rewards",
args: [walletStore.address, roundNumber, token.contractAddress],
});
}
const data = await multicall({
contracts,
});
}
const data = await multicall({
contracts,
});
// const multicallStore = useMultiCallStore();
return data
return data;
},
async getSacrificedTokenCoefficient(roundNumber, sacrificedToken) {
return await this.contract.read.getSacrificedTokenCoefficient([roundNumber, sacrificedToken]);
@@ -57,19 +59,75 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
async lastCompletedRound() {
return await this.contract.read.lastCompletedRound();
},
async claim(round) {
console.log("claim");
async claim(round) {
console.log("claim");
const walletStore = useWalletStoreV2();
// return await this.contract.methods.claim(round).call();
console.log(this.contract.methods.claim(round));
// return await this.contract.methods.claim(round).send({from: walletStore.address, to: this.contractAddress});
return await this.contract.write.claim([round]);
console.log(this.contract.methods.claim(round));
// return await this.contract.methods.claim(round).send({from: walletStore.address, to: this.contractAddress});
return await this.contract.write.claim([round]);
},
async claimAll() {
console.log("claimAll");
const roundsStore = useRoundsStore();
const account = getAccount();
console.log("acocunt", account);
const rounds = await roundsStore.getFinshedRoundNumbers();
return await this.contract.write.claim([[1, 2]]);
},
async getTotalRewardsOf(address, rounds) {
return await this.contract.read.getTotalRewardsOf([address, rounds]);
},
async getTotalRewards(address) {
console.log("this.contract", this.contract);
const roundsStore = useRoundsStore();
const rounds = await roundsStore.getFinshedRoundNumbers();
return await this.contract.read.getTotalRewardsOf([address, rounds]);
},
async getStaked(address) {
return await this.contract.read.staked([address]);
},
async orderUnstake() {
try {
return await this.contract.write.orderUnstake();
} catch (error) {
return;
}
},
async unstake(unstakeRound) {
return await this.contract.write.unstake([unstakeRound]);
},
async stakeBloodline(tokenNumber) {
console.log("tokenNumber", tokenNumber);
const walletStore = useWalletStoreV2();
const tokenStore = useTokenStore();
const fromAddress = walletStore.address;
const spender = this.config.contractAddress;
const deadline = Date.now() + 20 * 60;
const decimals = tokenStore.getToken(walletStore.memeToken.contractAddress).decimals;
const value = (tokenNumber * Math.pow(10, decimals)).toString();
const nonce = await tokenStore.memeToken.contract.read.nonces([fromAddress]);
console.log("nonce", nonce);
const { types, message, domain, primaryType } = createPermitObject(fromAddress, spender, nonce, deadline, value);
const signature = await signTypedData({
domain: domain,
message: message,
primaryType: primaryType,
types: types,
});
const { r, s, v } = getSignatureRSV(signature);
const hash = await this.contract.write.stakeToBeSecured([value, deadline, v, r, s]);
console.log("hash", hash);
const data = await waitForTransaction({
hash: hash,
});
console.log("data", data);
}
},
});