update mobile

This commit is contained in:
Michel Fromme
2023-07-31 14:45:41 +02:00
parent c160b1c836
commit 2555217641
7 changed files with 91 additions and 47 deletions
+3 -2
View File
@@ -6,7 +6,7 @@ import { useWalletStore } from "./wallet";
import { useWalletStoreV2 } from "./walletV2";
import { useRoundsStore } from "@/stores/rounds";
import { multicall, getContract, fetchToken, waitForTransaction } from "@wagmi/core";
import { multicall, getContract, fetchToken, waitForTransaction, getWalletClient } from "@wagmi/core";
export const useMemeburnerStore = defineStore("memeburner", {
@@ -94,10 +94,11 @@ export const useMemeburnerStore = defineStore("memeburner", {
//todo error
console.error("amount is 0 or null or undefined");
return;
}
}
this.loading = true;
const amountDecimal = BigInt(amount * Math.pow(10, tokenStore.activeToken.decimals));
console.log("this.contract", this.contract);
console.log("amountDecimal", amountDecimal);
var hash = await this.contract.write
.sacrificeMeme([tokenStore.activeToken.contractAddress, amountDecimal])
console.log("hash", hash);
+20 -11
View File
@@ -10,7 +10,7 @@ import Meme1Json from "@/assets/contracts/Meme1.json";
import Meme2Json from "@/assets/contracts/Meme2.json";
import MemeToken from "@/assets/contracts/MemeToken.json";
import MemeBurnerJson from "@/assets/contracts/MemeBurner.json";
import { multicall, getContract, fetchToken } from "@wagmi/core";
import { multicall, getContract, fetchToken, getWalletClient, waitForTransaction } from "@wagmi/core";
export const useTokenStore = defineStore("token", {
@@ -68,18 +68,19 @@ export const useTokenStore = defineStore("token", {
},
}),
getters: {},
actions: {
actions: {
async initV2() {
console.log("-----------init token-------------");
const contracts = [];
const walletStore = useWalletStoreV2();
for (let index = 0; index < this.token.length; index++) {
const token = this.token[index];
token.contract = getContract({
token.contract = getContract({
address: token.contractAddress,
abi: token.abi,
WalletClient: walletStore.walletClient || walletStore.publicClient,
});
abi: token.abi,
walletClient: walletStore.walletClient || walletStore.publicClient,
});
console.log("token.contract", token.contract);
contracts.push({...token.contract, functionName: "decimals"})
}
@@ -144,14 +145,22 @@ export const useTokenStore = defineStore("token", {
this.loading = true;
const walletStore = useWalletStore();
const memeBurnerStore = useMemeburnerStore();
var approve = await this.contract.methods
.approve(memeBurnerStore.config.contractAddress, amount)
.send({ from: walletStore.address});
// var approve = await this.contract.methods
// .approve(memeBurnerStore.config.contractAddress, amount)
// .send({ from: walletStore.address});
var approveHash = await this.activeToken.contract.write.approve([
memeBurnerStore.config.contractAddress,
amount,
]);
console.log("approveHash", approvehash);
//todo parameter value übergeben in eth web3.utils.toHex(web3.utils.toWei(amount, 'ether'))
// .send({ from: walletStore.address, value: 0.5 });
this.activeToken.allowance = await this.allowance();
return approve;
// this.activeToken.allowance = await this.allowance();
const data = await waitForTransaction({
hash: approveHash,
});
return data;
} catch (error) {
console.error(error);
} finally {
+5
View File
@@ -12,6 +12,7 @@ import {
disconnect,
InjectedConnector,
watchAccount,
getWalletClient,
} from "@wagmi/core";
import { WalletConnectConnector } from "@wagmi/core/connectors/walletConnect";
@@ -79,6 +80,10 @@ export const useWalletStoreV2 = defineStore("walletV2", {
webSocketPublicClient,
});
this.publicClient = publicClient;
console.log("this.config", this.config);
const walletClient = await getWalletClient();
console.log("walletClient", walletClient);
// await this.isConnected();
// const goerliKey = import.meta.env.VITE_GOERLI_KEY;
// if (this.connected) {