Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
sneakzttv committed Jun 24, 2024
1 parent feb4948 commit 7f313b4
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 10 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,19 @@ MonoBehaviour:
Provider: 3
- Button: {fileID: 7400892925769233044}
Provider: 4
web3AuthWalletGUIPrefab: {fileID: 2911816339710442984, guid: b394e6c49b9bd734089cea0293265bd3, type: 3}
enableWalletGUI: 1
displayWalletIcon: 1
autoConfirmTransactions: 1
autoPopUpWalletOnTx: 0
walletIcon: {fileID: 21300000, guid: 55a46a48cd53d834f99fda690cfea4b1, type: 3}
walletLogo: {fileID: 21300000, guid: ab400fd9b39316240b30631965553264, type: 3}
displayFont: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
primaryBackgroundColour: {r: 0, g: 0, b: 0, a: 0.8627451}
menuBackgroundColour: {r: 0.05490196, g: 0.05490196, b: 0.05490196, a: 1}
primaryTextColour: {r: 1, g: 1, b: 1, a: 1}
secondaryTextColour: {r: 0.38549072, g: 0.7169812, b: 0.28746888, a: 1}
borderButtonColour: {r: 1, g: 1, b: 1, a: 1}
--- !u!114 &1679801101
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ChainSafe.Gaming.UnityPackage;
using ChainSafe.Gaming.UnityPackage.Common;
using ChainSafe.Gaming.Web3.Analytics;
using ChainSafe.Gaming.Web3.Build;
using ChainSafe.GamingSdk.Web3Auth;
using Scenes;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Network = Web3Auth.Network;
Expand All @@ -32,11 +34,22 @@ public struct ProviderAndButtonPair
[SerializeField] private Network network;
[Header("UI")]
[SerializeField] private List<ProviderAndButtonPair> providerAndButtonPairs;

[Header("Wallet GUI Options")]
[SerializeField] private GameObject web3AuthWalletGUIPrefab;
[SerializeField] private bool enableWalletGUI;
[SerializeField] private bool displayWalletIcon;
[SerializeField] private bool autoConfirmTransactions;
[SerializeField] private bool autoPopUpWalletOnTx;
[SerializeField] private Sprite walletIcon;
[SerializeField] private Sprite walletLogo;
[SerializeField] public TMP_FontAsset displayFont;
[SerializeField] private Color primaryBackgroundColour;
[SerializeField] private Color menuBackgroundColour;
[SerializeField] private Color primaryTextColour;
[SerializeField] private Color secondaryTextColour;
[SerializeField] private Color borderButtonColour;
private bool useProvider;

private Provider selectedProvider;

private bool rememberMe;

public void SetRememberMe(bool rememberMe)
Expand All @@ -59,15 +72,12 @@ protected override async void Initialize()
if (!string.IsNullOrEmpty(uri.Fragment))
{
useProvider = false;

await TryLogin();

}
#else
if (!string.IsNullOrEmpty(KeyStoreManagerUtils.getPreferencesData(KeyStoreManagerUtils.SESSION_ID)))
if (!string.IsNullOrEmpty(KeyStoreManagerUtils.getPreferencesData(KeyStoreManagerUtils.SESSION_ID)) && rememberMe)
{
useProvider = false;
rememberMe = true;
await TryLogin();
Debug.Log("Restoring existing Web3Auth session (Remember Me");
}
Expand All @@ -81,10 +91,44 @@ private async void LoginWithWeb3Auth(Provider provider)
useProvider = true;
}
selectedProvider = provider;

await TryLogin();
LogAnalytics(provider);
}

public override async Task TryLogin()
{
try
{
await (this as ILoginProvider).Login();
EnableWalletGUI();
}
catch (Exception e)
{
Debug.LogError($"Login failed, please try again\n{e.Message} (see console for more details)");
throw;
}
}

private void EnableWalletGUI()
{
if (!enableWalletGUI) return;
var w3aWalletGuiConfig = new Web3AuthWalletGUI.Web3AuthWalletConfig
{
DisplayWalletIcon = displayWalletIcon,
AutoPopUpWalletOnTx = autoPopUpWalletOnTx,
AutoConfirmTransactions = autoConfirmTransactions,
WalletIcon = walletIcon,
WalletLogo = walletLogo,
DisplayFont = displayFont,
PrimaryBackgroundColour = primaryBackgroundColour,
MenuBackgroundColour = menuBackgroundColour,
PrimaryTextColour = primaryTextColour,
SecondaryTextColour = secondaryTextColour,
BorderButtonColour = borderButtonColour
};
var web3AuthWalletInstance = Instantiate(web3AuthWalletGUIPrefab);
web3AuthWalletInstance.GetComponent<Web3AuthWalletGUI>().Initialize(w3aWalletGuiConfig);
}

private void LogAnalytics(Provider provider)
{
Expand Down Expand Up @@ -128,4 +172,4 @@ public Web3Builder ConfigureServices(Web3Builder web3Builder)
services.UseWeb3AuthWallet(web3AuthConfig);
});
}
}
}

0 comments on commit 7f313b4

Please sign in to comment.