init functions for the storage
This commit is contained in:
@@ -3,14 +3,21 @@ import RewardLockerJson from "@/assets/contracts/RewardLocker.json";
|
||||
import { useTokenStore } from "./tokens";
|
||||
import { useMultiCallStore } from "./multicall";
|
||||
import { useWalletStore } from "./wallet";
|
||||
import { ethers } from "ethers";
|
||||
|
||||
export const useRewardLockerStore = defineStore("rewardlocker", {
|
||||
state: () => ({
|
||||
config: RewardLockerJson,
|
||||
contract: null,
|
||||
ethcontract: null,
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
async init() {
|
||||
console.log("-----------init rewardlocker-------------");
|
||||
const walletStore = useWalletStore();
|
||||
this.contract = new walletStore.web3.eth.Contract(this.config.abi, this.config.contractAddress);
|
||||
},
|
||||
/*
|
||||
* @param {*} walletAddress
|
||||
* @param {*} roundNumber
|
||||
@@ -20,23 +27,31 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
|
||||
async getRewards(walletAddress, roundNumber, tokenAddress) {
|
||||
return await this.contract.methods.rewards(walletAddress, roundNumber, tokenAddress).call();
|
||||
},
|
||||
async getRewardsForAllToken(roundNumber) {
|
||||
console.log("getRewardsForAllToken");
|
||||
const tokenStore = useTokenStore();
|
||||
const walletStore = useWalletStore();
|
||||
async getRewardsForAllToken(roundNumber) {
|
||||
console.log("getRewardsForAllToken");
|
||||
const tokenStore = useTokenStore();
|
||||
const walletStore = useWalletStore();
|
||||
const calls = [];
|
||||
for (let index = 0; index < tokenStore.token.length; index++) {
|
||||
const token = tokenStore.token[index];
|
||||
const token = tokenStore.token[index];
|
||||
var test = this.contract.methods.rewards(walletStore.address, roundNumber, token.contractAddress);
|
||||
console.log("test123", test);
|
||||
calls.push(this.contract.methods.rewards(walletStore.address, roundNumber, token.contractAddress));
|
||||
}
|
||||
const multicallStore = useMultiCallStore();
|
||||
return await multicallStore.aggregate(calls);
|
||||
return await multicallStore.aggregate(calls);
|
||||
},
|
||||
async getSacrificedTokenCoefficient(roundNumber, sacrificedToken) {
|
||||
return await this.contract.methods.getSacrificedTokenCoefficient(roundNumber, sacrificedToken).call();
|
||||
},
|
||||
async lastCompletedRound() {
|
||||
return await this.contract.methods.lastCompletedRound().call();
|
||||
},
|
||||
async claim(round) {
|
||||
return await this.contract.methods.claim(round).call();
|
||||
async claim(round) {
|
||||
const walletStore = useWalletStore();
|
||||
// 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});
|
||||
},
|
||||
async getTotalRewardsOf(address, rounds) {
|
||||
return await this.contract.methods.getTotalRewardsOf(address, rounds).call();
|
||||
|
||||
Reference in New Issue
Block a user