Skip to content

Commit

Permalink
fix GetChainId method for WebGL builds (#64)
Browse files Browse the repository at this point in the history
* fix GetChainId method for WebGL builds

* move chain id logic

* remove unused import
  • Loading branch information
alecananian authored May 28, 2024
1 parent e8b2dd3 commit 407487f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
10 changes: 10 additions & 0 deletions Assets/Treasure/TDK/Runtime/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,15 @@ public static class Constants
{ ChainId.ArbitrumSepolia, "arbitrum-sepolia" },
{ ChainId.TreasureRuby, "treasure-ruby" },
};

public static Dictionary<string, ChainId> NameToChainId = new Dictionary<string, ChainId>()
{
{ "unknown", ChainId.Unknown },
{ "ethereum", ChainId.Mainnet },
{ "sepolia", ChainId.Sepolia },
{ "arbitrum", ChainId.Arbitrum },
{ "arbitrum-sepolia", ChainId.ArbitrumSepolia },
{ "treasure-ruby", ChainId.TreasureRuby },
};
}
}
11 changes: 8 additions & 3 deletions Assets/Treasure/TDK/Runtime/Connect/Modals/LoginModal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private async void ConnectSocial(SocialAuthProvider provider)
catch (Exception ex)
{
Debug.LogError(ex.Message);
}
}
}

private void SetupFromSettings()
Expand Down Expand Up @@ -133,8 +133,13 @@ private async void OnClickConnectwithEmail()
catch (Exception e)
{
TDKLogger.LogError($"[LoginModal:OnClickConnectwithEmail] {e.Message}");
errorText.text = e.Message;
errorText.gameObject.SetActive(true);

// Ignore error display if user purposely closed the verification modal
if (e.Message != "User closed modal")
{
errorText.text = e.Message;
errorText.gameObject.SetActive(true);
}
}

connectButton.GetComponent<LoadingButton>().SetLoading(false);
Expand Down
12 changes: 11 additions & 1 deletion Assets/Treasure/TDK/Runtime/Connect/TDK.Connect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,17 @@ public async Task<ChainId> GetChainId()
if (_chainId == ChainId.Unknown)
{
#if TDK_THIRDWEB
_chainId = (ChainId)(int)await TDKServiceLocator.GetService<TDKThirdwebService>().Wallet.GetChainId();
// WebGL version of the Thirdweb SDK requires a wallet to be connected to call GetChainId()
var isConnected = await IsWalletConnected();
if (Utils.IsWebGLBuild() && !isConnected)
{
var defaultChainIdentifier = TDK.Instance.AppConfig.GetModuleConfig<TDKThirdwebConfig>().DefaultChainIdentifier;
_chainId = Constants.NameToChainId[defaultChainIdentifier];
}
else
{
_chainId = (ChainId)(int)await TDKServiceLocator.GetService<TDKThirdwebService>().Wallet.GetChainId();
}
#else
_chainId = ChainId.Arbitrum;
#endif
Expand Down
5 changes: 3 additions & 2 deletions ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ PlayerSettings:
openGLRequireES31: 0
openGLRequireES31AEP: 0
openGLRequireES32: 0
m_TemplateCustomTags: {}
m_TemplateCustomTags:
HIDE_FULL_SCREEN_BUTTON:
mobileMTRendering:
Android: 1
iPhone: 1
Expand Down Expand Up @@ -822,7 +823,7 @@ PlayerSettings:
webGLDebugSymbols: 0
webGLEmscriptenArgs:
webGLModulesDirectory:
webGLTemplate: APPLICATION:Default
webGLTemplate: PROJECT:Thirdweb
webGLAnalyzeBuildSize: 0
webGLUseEmbeddedResources: 0
webGLCompressionFormat: 1
Expand Down

0 comments on commit 407487f

Please sign in to comment.