All files / src/boot web3.ts

0% Statements 0/6
100% Branches 0/0
100% Functions 0/0
0% Lines 0/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46                                                                                           
import { Web3Class } from "src/helper/class/Web3Class";
// @ts-ignore
import store from "src/store";
import { BootInput } from "../types/boot";
 
let web3Instance: Web3Class;
let currentWeb3Address = "";
 
// leave the export, even if you don't use it
export default async ({ Vue }: BootInput) => {
  web3Instance = new Web3Class();
  // Vuex Watch for sign in
 
  // let tempAccInterval: any = null;
  // store.watch(
  //   (newValue: any, oldValue: any) => {
  //     if (!(oldValue.web3 && newValue.web3.status === oldValue.web3.status)) {
  //       // if account switch
  //       if (newValue.web3.status === "login") {
  //         const checkAccInterval = () =>
  //           setInterval(async () => {
  //             const addresses = await web3Instance.getAvailableAddress();
  //             const needUpdate =
  //               currentWeb3Address !== addresses[0] &&
  //               currentWeb3Address !== "";
  //             currentWeb3Address = addresses[0];
  //             const newAddress = newValue.contract.address;
  //             if (needUpdate && newAddress !== currentWeb3Address) {
  //               // If Metamask account change, reload.
  //               location.reload();
  //             }
  //           }, 2000);
  //         tempAccInterval = checkAccInterval();
  //       } else if (newValue.web3.status === "logout") {
  //         if (tempAccInterval !== null) {
  //           clearInterval(tempAccInterval);
  //         }
  //       }
  //     }
  //   },
  //   () => {}
  // );
};
 
export { web3Instance };