update cycleview, pageview + profileview

This commit is contained in:
EmberSpirit
2023-08-30 18:08:51 +02:00
parent c8f7c7cd5e
commit cd773e16c9
19 changed files with 2093 additions and 20238 deletions
+113 -16
View File
@@ -5,11 +5,19 @@ import { useTokenStore } from "@/stores/tokens";
import { useContractStore } from "@/stores/contracts";
import { useMemeburnerStore } from "@/stores/memeburner";
import { useRewardLockerStore } from "@/stores/rewardlocker";
import { useMultiCallStore } from "@/stores/multicall";
import { useRoundsStore } from "@/stores/rounds";
import {ref} from "vue"
import {
watchAccount,
watchNetwork,
watchContractEvent,
watchWalletClient,
getAccount,
getNetwork,
getPublicClient,
getWalletClient,
} from "@wagmi/core";
const router = createRouter({
@@ -40,12 +48,18 @@ const router = createRouter({
},
{
path: "/profile",
name: "Profile",
name: "profile",
meta: {
middleware: ["connected"],
},
component: () => import("../views/ProfileView.vue"),
},
{
path: "/cycle",
name: "Cycle",
name: "cycle",
meta: {
middleware: ["connected"],
},
component: () => import("../views/CycleView.vue"),
},
],
@@ -53,27 +67,110 @@ const router = createRouter({
router.beforeEach(async (to, from) => {
//init
const showPanel = ref(false);
const eventWatch = ref(null);
const netWorkEvent = ref(null);
const memeSacrificedEvent = ref(null);
const clientClientEvent = ref(null);
console.log("beforeEach");
const tokenStore = useTokenStore();
const memeBurnerStore = useMemeburnerStore();
const rewardLockerStore = useRewardLockerStore();
const roundsStore = useRoundsStore();
const walletStore = useWalletStoreV2();
console.log("walletStore.publicClient", walletStore.publicClient);
if (!walletStore.initialized) {
walletStore.initialized = true
console.log("hier");
await walletStore.init();
await tokenStore.initV2();
await memeBurnerStore.init();
await rewardLockerStore.init();
await memeBurnerStore.init();
console.log("init router");
console.log("roundsStore.currentRound", roundsStore.currentRound);
if (!roundsStore.currentRound) {
roundsStore.currentRound = parseInt(await memeBurnerStore.getCurrentRound());
console.log("roundsStore.currentRound", roundsStore.currentRound);
roundsStore.activeRound = roundsStore.currentRound;
}
//events
eventWatch.value = watchAccount(async (account) => {
console.log("account123", account);
const publicClient = getPublicClient();
console.log("publicClient", publicClient);
// {chainId: }
console.log("walletClient", walletClient);
if (account.address) {
walletStore.address = account.address;
walletStore.connected = true;
let chainObject = walletStore.chain;
if (!walletStore.chain) {
const { chain, chains } = getNetwork();
chainObject = chain;
}
var walletClient = await getWalletClient({
account: account.address,
chainId: chainObject.id,
});
walletStore.walletClient = walletClient;
// walletStore.getTokenBalances()
await memeBurnerStore.init();
console.log("hierabc");
await tokenStore.initV2();
} else {
walletStore.address = null;
walletStore.connected = false;
walletStore.walletClient = null;
}
});
netWorkEvent.value = watchNetwork((network) => {
console.log("network123", network);
if (network.chain) {
walletStore.chain = network.chain;
clientClientEvent.value = watchWalletClient(
{
chainId: network.chain.id,
},
(walletClient) => {
walletStore.walletClient = walletClient;
console.log("wc123", walletClient);
}
);
}
});
memeSacrificedEvent.value = watchContractEvent(
{
address: memeBurnerStore.config.contractAddress,
abi: memeBurnerStore.config.abi,
eventName: "MemeSacrificed",
},
async (log) => {
console.log("memeSacrificedEvent", log);
const token = log[0].args.sacrificedToken;
await roundsStore.updateCurrentRound(token);
}
);
await roundsStore.fillRound(roundsStore.activeRound);
await walletStore.loadWalletData();
}
if (!walletStore.publicClient) {
await walletStore.init();
await tokenStore.initV2();
await memeBurnerStore.init();
await rewardLockerStore.init();
await memeBurnerStore.init();
if (!roundsStore.currentRound) {
roundsStore.currentRound = parseInt(await memeBurnerStore.getCurrentRound());
console.log("roundsStore.currentRound", roundsStore.currentRound);
roundsStore.activeRound = roundsStore.currentRound;
//middleware
if (to.meta.middleware) {
if (!walletStore.connected) {
return false;
}
}
// initContracts
return true;
});