fix connect provider call and lint
Co-authored-by: brunoedcf <brest.dallacosta@outlook.com>
This commit is contained in:
parent
f8e1b888ba
commit
a5d5c0dde3
@ -9,13 +9,15 @@ const getProviderUrl = (): string => {
|
|||||||
const possibleProvidersUrls: { [key: string]: string } = {
|
const possibleProvidersUrls: { [key: string]: string } = {
|
||||||
Ethereum: import.meta.env.VITE_GOERLI_API_URL,
|
Ethereum: import.meta.env.VITE_GOERLI_API_URL,
|
||||||
Polygon: import.meta.env.VITE_MUMBAI_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 window_ = window as any;
|
||||||
const connection = window_.ethereum;
|
const connection = window_.ethereum;
|
||||||
|
|
||||||
@ -49,8 +51,7 @@ const listenToWalletChange = (connection: any): void => {
|
|||||||
connection.on("accountsChanged", async () => {
|
connection.on("accountsChanged", async () => {
|
||||||
await updateWalletStatus();
|
await updateWalletStatus();
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
const listenToNetworkChange = (connection: any) => {
|
const listenToNetworkChange = (connection: any) => {
|
||||||
const etherStore = useEtherStore();
|
const etherStore = useEtherStore();
|
||||||
@ -59,16 +60,13 @@ const listenToNetworkChange = (connection: any) => {
|
|||||||
"0x5": NetworkEnum.ethereum,
|
"0x5": NetworkEnum.ethereum,
|
||||||
"0x13881": NetworkEnum.polygon,
|
"0x13881": NetworkEnum.polygon,
|
||||||
"0x7a69": NetworkEnum.localhost,
|
"0x7a69": NetworkEnum.localhost,
|
||||||
}
|
};
|
||||||
|
|
||||||
connection.on("chainChanged", (networkChain: string) => {
|
connection.on("chainChanged", (networkChain: string) => {
|
||||||
if (Object.keys(possibleNetworks).includes(networkChain)) {
|
if (Object.keys(possibleNetworks).includes(networkChain)) {
|
||||||
etherStore.setNetworkName(possibleNetworks[networkChain]);
|
etherStore.setNetworkName(possibleNetworks[networkChain]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
export {
|
export { getProvider, connectProvider, listenToNetworkChange };
|
||||||
getProvider,
|
|
||||||
listenToNetworkChange
|
|
||||||
}
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { ethers } from "ethers";
|
import { ethers } from "ethers";
|
||||||
import { getProvider } from "./provider";
|
import { getProvider } from "./provider";
|
||||||
import blockchain from "../utils/blockchain"
|
import blockchain from "../utils/blockchain";
|
||||||
import { useEtherStore } from "@/store/ether";
|
import { useEtherStore } from "@/store/ether";
|
||||||
|
|
||||||
import mockToken from "../utils/smart_contract_files/MockToken.json";
|
import mockToken from "../utils/smart_contract_files/MockToken.json";
|
||||||
@ -10,8 +10,6 @@ const updateWalletStatus = async () => {
|
|||||||
const etherStore = useEtherStore();
|
const etherStore = useEtherStore();
|
||||||
const provider = getProvider();
|
const provider = getProvider();
|
||||||
|
|
||||||
if (!provider) return;
|
|
||||||
|
|
||||||
const signer = provider.getSigner();
|
const signer = provider.getSigner();
|
||||||
const contract = new ethers.Contract(addresses.token, mockToken.abi, signer);
|
const contract = new ethers.Contract(addresses.token, mockToken.abi, signer);
|
||||||
|
|
||||||
@ -37,7 +35,4 @@ const updateWalletStatus = async () => {
|
|||||||
etherStore.setBalance(blockchain.formatBigNumber(balance));
|
etherStore.setBalance(blockchain.formatBigNumber(balance));
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export { updateWalletStatus, updateWalletBalance };
|
||||||
updateWalletStatus,
|
|
||||||
updateWalletBalance
|
|
||||||
}
|
|
||||||
|
@ -3,7 +3,7 @@ import { storeToRefs } from "pinia";
|
|||||||
import { useEtherStore } from "../store/ether";
|
import { useEtherStore } from "../store/ether";
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { NetworkEnum } from "@/model/NetworkEnum";
|
import { NetworkEnum } from "@/model/NetworkEnum";
|
||||||
import blockchain from "../utils/blockchain";
|
import { connectProvider } from "../blockchain/provider";
|
||||||
import ethereumImage from "../assets/ethereum.svg";
|
import ethereumImage from "../assets/ethereum.svg";
|
||||||
import polygonImage from "../assets/polygon.svg";
|
import polygonImage from "../assets/polygon.svg";
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ const currencyMenuHoverToggle = ref<boolean>(false);
|
|||||||
|
|
||||||
//Methods
|
//Methods
|
||||||
const connectMetaMask = () => {
|
const connectMetaMask = () => {
|
||||||
blockchain.connectProvider();
|
connectProvider();
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatWalletAddress = (): string => {
|
const formatWalletAddress = (): string => {
|
||||||
@ -52,7 +52,7 @@ const getNetworkImage = (networkName: NetworkEnum) => {
|
|||||||
let validImages = {
|
let validImages = {
|
||||||
Ethereum: ethereumImage,
|
Ethereum: ethereumImage,
|
||||||
Polygon: polygonImage,
|
Polygon: polygonImage,
|
||||||
Localhost: ethereumImage
|
Localhost: ethereumImage,
|
||||||
};
|
};
|
||||||
|
|
||||||
return validImages[networkName];
|
return validImages[networkName];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user