update menu
This commit is contained in:
+77
-76
@@ -1,6 +1,8 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { markRaw } from "vue";
|
||||
import { useTokenStore } from "./tokens";
|
||||
import { useRewardLockerStore } from "./rewardlocker";
|
||||
import MemeToken from "@/assets/contracts/MemeToken.json";
|
||||
|
||||
import {
|
||||
createConfig,
|
||||
@@ -11,8 +13,9 @@ import {
|
||||
disconnect,
|
||||
InjectedConnector,
|
||||
watchAccount,
|
||||
getWalletClient,
|
||||
fetchBalance
|
||||
getWalletClient,
|
||||
fetchBalance,
|
||||
multicall,
|
||||
} from "@wagmi/core";
|
||||
|
||||
import { WalletConnectConnector } from "@wagmi/core/connectors/walletConnect";
|
||||
@@ -30,27 +33,29 @@ export const useWalletStoreV2 = defineStore("walletV2", {
|
||||
alchemy: null,
|
||||
connected: false,
|
||||
address: null,
|
||||
provider: null,
|
||||
client: null,
|
||||
publicClient: null,
|
||||
walletClient: null,
|
||||
config: null,
|
||||
chain: null,
|
||||
provider: null,
|
||||
client: null,
|
||||
publicClient: null,
|
||||
walletClient: null,
|
||||
config: null,
|
||||
chain: null,
|
||||
token: [],
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
async init() {
|
||||
|
||||
console.log("wallet init");
|
||||
const goerliKey = import.meta.env.VITE_GOERLI_KEY;
|
||||
const projectId = "d8e5ecb0353c02e21d4c0867d4473ac5";
|
||||
|
||||
getters: {
|
||||
sacrificeToken: (state) => state.token.filter((obj) => obj.contractAddress !== MemeToken.contractAddress),
|
||||
memeToken: (state) => state.token.find((obj) => obj.contractAddress === MemeToken.contractAddress),
|
||||
},
|
||||
actions: {
|
||||
async init() {
|
||||
console.log("wallet init");
|
||||
const goerliKey = import.meta.env.VITE_GOERLI_KEY;
|
||||
const projectId = "d8e5ecb0353c02e21d4c0867d4473ac5";
|
||||
|
||||
const { chains, publicClient, webSocketPublicClient } = configureChains(
|
||||
[goerli, mainnet],
|
||||
[alchemyProvider({ apiKey: goerliKey }), publicProvider()]
|
||||
);
|
||||
);
|
||||
|
||||
|
||||
this.config = createConfig({
|
||||
autoConnect: true,
|
||||
connectors: [
|
||||
@@ -77,71 +82,67 @@ export const useWalletStoreV2 = defineStore("walletV2", {
|
||||
],
|
||||
publicClient,
|
||||
webSocketPublicClient,
|
||||
});
|
||||
this.publicClient = publicClient;
|
||||
|
||||
console.log("this.config", this.config);
|
||||
const walletClient = await getWalletClient();
|
||||
console.log("walletClient", walletClient);
|
||||
});
|
||||
this.publicClient = publicClient;
|
||||
|
||||
console.log("this.config", this.config);
|
||||
const walletClient = await getWalletClient();
|
||||
console.log("walletClient", walletClient);
|
||||
},
|
||||
async connectWallet(connector) {
|
||||
console.log("connector.name", connector.name);
|
||||
// if (!account.isConnected) {
|
||||
const connection = await connect({
|
||||
async connectWallet(connector) {
|
||||
console.log("connector.name", connector.name);
|
||||
// if (!account.isConnected) {
|
||||
const connection = await connect({
|
||||
chainId: goerli.id,
|
||||
connector: connector,
|
||||
});
|
||||
|
||||
console.log("connection", connection);
|
||||
// this.address = connection.account;
|
||||
});
|
||||
|
||||
console.log("connection", connection);
|
||||
// this.address = connection.account;
|
||||
},
|
||||
async getTokenBalance(token) {
|
||||
console.log("token", token);
|
||||
console.log("address", this.address);
|
||||
// const result = await token.contract.read.balanceOf([this.address]);
|
||||
// return result;
|
||||
async getTokenBalance(token) {
|
||||
console.log("token", token);
|
||||
console.log("address", this.address);
|
||||
const result = await token.contract.read.balanceOf([this.address]);
|
||||
return result;
|
||||
},
|
||||
|
||||
async getTokenBalances() {
|
||||
console.log("getTokenBalances");
|
||||
const tokenStore = useTokenStore();
|
||||
console.log("tokenStore.token.length", tokenStore.token.length);
|
||||
var contracts = [];
|
||||
for (let index = 0; index < tokenStore.token.length; index++) {
|
||||
const token = tokenStore.token[index];
|
||||
contracts.push({ ...token.contract, functionName: "balanceOf", args: [this.address] });
|
||||
}
|
||||
|
||||
const data = await multicall({
|
||||
contracts,
|
||||
});
|
||||
console.log("data", data);
|
||||
for (let index = 0; index < tokenStore.token.length; index++) {
|
||||
const token = tokenStore.token[index];
|
||||
const balanceOfDecimal = data[index].result / BigInt(Math.pow(10, token.decimals));
|
||||
this.token.push({
|
||||
contractAddress: token.contractAddress,
|
||||
balanceOf: Number(balanceOfDecimal),
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
async getTokenBalances() {
|
||||
//todo
|
||||
async loadWalletData() {
|
||||
const rewardlockerStore = useRewardLockerStore();
|
||||
|
||||
await this.getTokenBalances();
|
||||
|
||||
//MemeToken Staked
|
||||
const tokenStore = useTokenStore();
|
||||
|
||||
const staked = await rewardlockerStore.getStaked(this.address);
|
||||
|
||||
this.memeToken.staked = Number(staked / BigInt(Math.pow(10, tokenStore.memeToken.decimals)));
|
||||
|
||||
}
|
||||
// async isConnected() {
|
||||
// try {
|
||||
// this.loading = true;
|
||||
// if (!window.ethereum) {
|
||||
// console.warn("Metamask not installed"), (this.connected = false);
|
||||
// return;
|
||||
// }
|
||||
// const accounts = await window.ethereum.request({ method: "eth_accounts" });
|
||||
// if (accounts.length) {
|
||||
// this.connected = true;
|
||||
// this.address = accounts[0];
|
||||
// console.log(`You're connected to: ${accounts[0]}`);
|
||||
// // const web3 = new Web3(window.ethereum);
|
||||
// // const tokenStore = useTokenStore();
|
||||
// // console.log("tokenStore.activeToken", tokenStore.activeToken);
|
||||
// // if (tokenStore.activeToken.contractAddress) {
|
||||
// // tokenStore.activeToken.balance = await this.getTokenBalance(
|
||||
// // tokenStore.activeToken
|
||||
// // );
|
||||
// // tokenStore.activeToken.allowance = await tokenStore.allowance();
|
||||
// // }
|
||||
// // tokenStore.memeBurner.contract = new web3.eth.Contract(
|
||||
// // tokenStore.memeBurner.config.abi,
|
||||
// // tokenStore.memeBurner.config.contractAddress
|
||||
// // );
|
||||
// } else {
|
||||
// console.log("Metamask is not connected");
|
||||
// this.connected = false;
|
||||
// }
|
||||
// } catch (error) {
|
||||
// console.log("error", error);
|
||||
// } finally {
|
||||
// this.loading = false;
|
||||
// return this.connected;
|
||||
// }
|
||||
// },
|
||||
},
|
||||
persist: true,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user