mirror of
				https://github.com/Instadapp/assembly.git
				synced 2024-07-29 22:37:06 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			36 lines
		
	
	
		
			1008 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			1008 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { useWeb3 } from "@instadapp/vue-web3";
 | |
| import { injected, gnosisSafe } from "../connectors";
 | |
| import { onMounted, ref, watch, watchEffect } from "@nuxtjs/composition-api";
 | |
| import { useSafeAppConnection } from "./useSafeAppConnection";
 | |
| 
 | |
| export function useEagerConnect() {
 | |
|   const { activate, active } = useWeb3();
 | |
|   const { tried: triedToConnectToSafe } = useSafeAppConnection(gnosisSafe);
 | |
|   const tried = ref(false);
 | |
| 
 | |
|   watchEffect(() => {
 | |
|     if (triedToConnectToSafe.value && !active.value) {
 | |
|       injected.isAuthorized().then((isAuthorized: boolean) => {
 | |
|         if (isAuthorized) {
 | |
|           activate(injected, undefined, true).catch(() => {
 | |
|             tried.value = true;
 | |
|           });
 | |
|         } else {
 | |
|           tried.value = true;
 | |
|         }
 | |
|       });
 | |
|     }
 | |
|   });
 | |
| 
 | |
|   // if the connection worked, wait until we get confirmation of that to flip the flag
 | |
|   watch([tried, active], () => {
 | |
|     if (!tried.value && active.value) {
 | |
|       tried.value = true;
 | |
|     }
 | |
|   });
 | |
| 
 | |
|   return {
 | |
|     tried
 | |
|   };
 | |
| }
 | 
