mirror of
https://github.com/Instadapp/assembly.git
synced 2024-07-29 22:37:06 +00:00
Update useWeb3.ts
This commit is contained in:
parent
c19e09c363
commit
ddbd31f241
|
@ -1,6 +1,6 @@
|
|||
import { computed, onMounted, ref, watch } from "@nuxtjs/composition-api";
|
||||
import Web3 from "web3";
|
||||
import { SafeAppWeb3Modal } from '@gnosis.pm/safe-apps-web3modal'
|
||||
import { SafeAppWeb3Modal } from "@gnosis.pm/safe-apps-web3modal";
|
||||
import { Network } from "./useNetwork";
|
||||
|
||||
let web3Modal: SafeAppWeb3Modal;
|
||||
|
@ -23,7 +23,7 @@ const chains = [
|
|||
];
|
||||
|
||||
const active = ref(false);
|
||||
const chainId = ref<1|137>();
|
||||
const chainId = ref<1 | 137>();
|
||||
const networkName = computed<Network>(
|
||||
() => chains.find(c => c.chainId === chainId.value)?.name || Network.Mainnet
|
||||
);
|
||||
|
@ -49,6 +49,10 @@ export function useWeb3() {
|
|||
if (web3Modal.cachedProvider) {
|
||||
await activate();
|
||||
}
|
||||
|
||||
if (await web3Modal.isSafeApp()) {
|
||||
await activate();
|
||||
}
|
||||
});
|
||||
|
||||
const activate = async () => {
|
||||
|
@ -60,7 +64,7 @@ export function useWeb3() {
|
|||
account.value = web3Provider.accounts[0];
|
||||
}
|
||||
let newWeb3 = new Web3(web3Provider);
|
||||
//@ts-ignore
|
||||
//@ts-ignore
|
||||
chainId.value = await newWeb3.eth.getChainId();
|
||||
web3.value = newWeb3;
|
||||
|
||||
|
@ -119,18 +123,18 @@ export function useWeb3() {
|
|||
return;
|
||||
}
|
||||
let newWeb3 = new Web3(web3Provider);
|
||||
//@ts-ignore
|
||||
//@ts-ignore
|
||||
chainId.value = await newWeb3.eth.getChainId();
|
||||
web3.value = newWeb3;
|
||||
};
|
||||
|
||||
const setWeb3 = (newWeb3: Web3) => {
|
||||
web3.value = newWeb3;
|
||||
}
|
||||
};
|
||||
|
||||
watch(web3, () => {
|
||||
window.web3 = web3.value;
|
||||
})
|
||||
});
|
||||
|
||||
return {
|
||||
account,
|
||||
|
@ -141,6 +145,6 @@ export function useWeb3() {
|
|||
deactivate,
|
||||
networkName,
|
||||
refreshWeb3,
|
||||
setWeb3,
|
||||
setWeb3
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user