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:
15
src/blockchain/provider.ts
Normal file
15
src/blockchain/provider.ts
Normal 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 }
|
||||
Reference in New Issue
Block a user