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

@ -9,13 +9,15 @@ const getProviderUrl = (): string => {
const possibleProvidersUrls: { [key: string]: string } = {
Ethereum: import.meta.env.VITE_GOERLI_API_URL,
Polygon: import.meta.env.VITE_MUMBAI_API_URL,
Localhost: import.meta.env.VITE_GOERLI_API_URL
}
Localhost: import.meta.env.VITE_GOERLI_API_URL,
};
return possibleProvidersUrls[etherStore.networkName]
}
return possibleProvidersUrls[etherStore.networkName];
};
const getProvider = (): ethers.providers.Web3Provider | ethers.providers.JsonRpcProvider => {
const getProvider = ():
| ethers.providers.Web3Provider
| ethers.providers.JsonRpcProvider => {
const window_ = window as any;
const connection = window_.ethereum;
@ -49,8 +51,7 @@ const listenToWalletChange = (connection: any): void => {
connection.on("accountsChanged", async () => {
await updateWalletStatus();
});
}
};
const listenToNetworkChange = (connection: any) => {
const etherStore = useEtherStore();
@ -59,16 +60,13 @@ const listenToNetworkChange = (connection: any) => {
"0x5": NetworkEnum.ethereum,
"0x13881": NetworkEnum.polygon,
"0x7a69": NetworkEnum.localhost,
}
};
connection.on("chainChanged", (networkChain: string) => {
if (Object.keys(possibleNetworks).includes(networkChain)) {
etherStore.setNetworkName(possibleNetworks[networkChain]);
}
});
}
};
export {
getProvider,
listenToNetworkChange
}
export { getProvider, connectProvider, listenToNetworkChange };

View File

@ -1,6 +1,6 @@
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";
@ -10,8 +10,6 @@ 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);
@ -37,7 +35,4 @@ const updateWalletStatus = async () => {
etherStore.setBalance(blockchain.formatBigNumber(balance));
};
export {
updateWalletStatus,
updateWalletBalance
}
export { updateWalletStatus, updateWalletBalance };

View File

@ -3,7 +3,7 @@ import { storeToRefs } from "pinia";
import { useEtherStore } from "../store/ether";
import { ref } from "vue";
import { NetworkEnum } from "@/model/NetworkEnum";
import blockchain from "../utils/blockchain";
import { connectProvider } from "../blockchain/provider";
import ethereumImage from "../assets/ethereum.svg";
import polygonImage from "../assets/polygon.svg";
@ -20,7 +20,7 @@ const currencyMenuHoverToggle = ref<boolean>(false);
//Methods
const connectMetaMask = () => {
blockchain.connectProvider();
connectProvider();
};
const formatWalletAddress = (): string => {
@ -52,7 +52,7 @@ const getNetworkImage = (networkName: NetworkEnum) => {
let validImages = {
Ethereum: ethereumImage,
Polygon: polygonImage,
Localhost: ethereumImage
Localhost: ethereumImage,
};
return validImages[networkName];