Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
samuveth committed Nov 5, 2023
1 parent 583a62c commit 62e4747
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/composables/useWeb3.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
import { useAccount, useConnect, useDisconnect, useNetwork } from 'use-wagmi';
import { InjectedConnector } from 'use-wagmi/connectors/injected';
import { Web3Provider } from '@ethersproject/providers';
import { mainnet, goerli } from 'viem/chains';
import { Config } from 'use-wagmi';

const defaultChainId: any = import.meta.env.VITE_DEFAULT_NETWORK;

const web3ProviderRef = ref<any>(null);
const providerRef = ref<any>(null);

export function useWeb3() {
const { notify } = useFlashNotification();

const { connect } = useConnect({
connector: new InjectedConnector(),
onSuccess(connector) {
initProviders(connector.connector);
onSuccess({ connector }) {
initProviders(connector);
},
onError(e) {
notify(['red', e.message]);
}
});
const { disconnect } = useDisconnect();
const { address, isConnected, isConnecting } = useAccount();
const { address, isConnected, isConnecting } = useAccount({
// onConnect({ connector }) {
// connector?.getProvider();
// }
});
const { chain } = useNetwork();

const defaultChain = computed(() =>
defaultChainId === '1' ? mainnet : goerli
);

async function initProviders(connector) {
if (isConnected.value && connector?.getProvider) {
async function initProviders(connector: Config['connector']) {
if (connector?.getProvider) {
providerRef.value = await connector.getProvider();
web3ProviderRef.value = new Web3Provider(await connector.getProvider());
} else {
Expand Down

0 comments on commit 62e4747

Please sign in to comment.