Ejemplo n.º 1
0
        private async Task MetaMaskLogin()
        {
            ShowMetaMaskMessage = false;
            Error = null;

            bool hasMetaMask = await MetaMaskService.HasMetaMask();

            if (!hasMetaMask)
            {
                ShowMetaMaskMessage = true;
            }
            else
            {
                try
                {
                    bool isSiteConnected = await MetaMaskService.IsSiteConnected();

                    MetaMaskLogin?storedLogin = null;
                    if (!isSiteConnected)
                    {
                        storedLogin = await GetAndStoreHash();
                    }
                    else
                    {
                        string address = await MetaMaskService.GetSelectedAddress();

                        storedLogin = await MetaMaskStorageService.GetStoredhash(address);

                        if (storedLogin == null)
                        {
                            storedLogin = await GetAndStoreHash();
                        }
                    }

                    SkyDocsService.Login(storedLogin.address, storedLogin.hash, isMetaMaskLogin: true);
                    DialogService.Close();
                }
                catch (NoMetaMaskException)
                {
                    ShowMetaMaskMessage = true;
                }
                catch (UserDeniedException)
                {
                    Error = "MetaMask not allowed to connect to SkyDocs. Please try again.";
                }
                catch (Exception ex)
                {
                    Error = "Failed to sign message. Please try again.";
                    Console.WriteLine(ex);
                }
            }
        }
Ejemplo n.º 2
0
        protected override async Task OnInitializedAsync()
        {
            //Subscribe to events
            MetaMaskService.AccountChangedEvent += MetaMaskService_AccountChangedEvent;
            MetaMaskService.NetworkChangedEvent += MetaMaskService_NetworkChangedEvent;

            HasMetaMask = await MetaMaskService.HasMetaMask();

            if (HasMetaMask)
            {
                await MetaMaskService.ListenToEvents();
            }

            bool isSiteConnected = await MetaMaskService.IsSiteConnected();

            if (isSiteConnected)
            {
                await GetSelectedAddress();
                await GetSelectedNetwork();
            }
        }