fix connect provider call and lint

Co-authored-by: brunoedcf <brest.dallacosta@outlook.com>
This commit is contained in:
RcleydsonR
2023-01-12 19:47:11 -03:00
parent f8e1b888ba
commit a5d5c0dde3
3 changed files with 85 additions and 92 deletions

View File

@@ -1,43 +1,38 @@
import { ethers } from "ethers";
import { getProvider } from "./provider";
import blockchain from "../utils/blockchain"
import blockchain from "../utils/blockchain";
import { useEtherStore } from "@/store/ether";
import mockToken from "../utils/smart_contract_files/MockToken.json";
import addresses from "../utils/smart_contract_files/localhost.json";
const updateWalletStatus = async () => {
const etherStore = useEtherStore();
const provider = getProvider();
if (!provider) return;
const signer = provider.getSigner();
const contract = new ethers.Contract(addresses.token, mockToken.abi, signer);
const walletAddress = await provider.send("eth_requestAccounts", []);
const balance = await contract.balanceOf(walletAddress[0]);
etherStore.setBalance(blockchain.formatBigNumber(balance));
etherStore.setWalletAddress(ethers.utils.getAddress(walletAddress[0]));
};
const updateWalletBalance = async () => {
const etherStore = useEtherStore();
const provider = getProvider();
if (!provider) return;
const signer = provider.getSigner();
const contract = new ethers.Contract(addresses.token, mockToken.abi, signer);
const walletAddress = await provider.send("eth_requestAccounts", []);
const balance = await contract.balanceOf(walletAddress[0]);
etherStore.setBalance(blockchain.formatBigNumber(balance));
};
const etherStore = useEtherStore();
const provider = getProvider();
export {
updateWalletStatus,
updateWalletBalance
}
const signer = provider.getSigner();
const contract = new ethers.Contract(addresses.token, mockToken.abi, signer);
const walletAddress = await provider.send("eth_requestAccounts", []);
const balance = await contract.balanceOf(walletAddress[0]);
etherStore.setBalance(blockchain.formatBigNumber(balance));
etherStore.setWalletAddress(ethers.utils.getAddress(walletAddress[0]));
};
const updateWalletBalance = async () => {
const etherStore = useEtherStore();
const provider = getProvider();
if (!provider) return;
const signer = provider.getSigner();
const contract = new ethers.Contract(addresses.token, mockToken.abi, signer);
const walletAddress = await provider.send("eth_requestAccounts", []);
const balance = await contract.balanceOf(walletAddress[0]);
etherStore.setBalance(blockchain.formatBigNumber(balance));
};
export { updateWalletStatus, updateWalletBalance };