Add listener to listen chain change and update store network name state, also start refactor with getProvider function

Co-authored-by: brunoedcf <brest.dallacosta@outlook.com>
This commit is contained in:
RcleydsonR
2023-01-12 18:08:08 -03:00
parent 62dd4349b2
commit 8b0a212b78
2 changed files with 31 additions and 6 deletions

View File

@@ -0,0 +1,15 @@
import { ethers } from "ethers";
import { useEtherStore } from "@/store/ether";
const getProvider = (): ethers.providers.Web3Provider | null => {
const etherStore = useEtherStore();
const window_ = window as any;
const connection = window_.ethereum;
if (!connection) return null;
return new ethers.providers.Web3Provider(connection);
};
export { getProvider }