update cycleview, pageview + profileview
This commit is contained in:
+113
-16
@@ -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;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user