这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public static Web3AuthApi getInstance()

public IEnumerator authorizeSession(string key, Action<StoreApiResponse> callback)
{
// Wait for a single frame
yield return 0;
//var requestURL = $"{baseAddress}/store/get?key={key}";
//var request = UnityWebRequest.Get(requestURL);
WWWForm data = new WWWForm();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,13 @@ private void authorizeSession(string newSessionId)
this.Enqueue(() => this.onLogin?.Invoke(this.web3AuthResponse));
}
}

else
{
this.Enqueue(() => this.onLogin?.Invoke(new Web3AuthResponse
{
error = "Failed to connect, session null."
}));
}
})));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public class Web3AuthConnectionProvider : RestorableConnectionProvider, ILogoutH

[NonSerialized] private bool _rememberMe;

public int Priority => 0;

public override bool IsAvailable => true;

#if UNITY_WEBGL && !UNITY_EDITOR
Expand Down Expand Up @@ -250,6 +248,11 @@ public Task OnWeb3Initialized(Web3 web3)
_web3AuthWalletGui.Initialize(walletGuiConfig);
}

if (_modal != null)
{
_modal?.Close();
}

return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void HideLoading()

public void Close()
{
_cancellationTokenSource.Cancel();
_cancellationTokenSource?.Cancel();

gameObject.SetActive(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,15 @@ private void Cancel()

private void OnLogin(Web3AuthResponse response)
{
_connectTcs.SetResult(response);
if (string.IsNullOrEmpty(response.error))
{
_connectTcs.SetResult(response);
}

else
{
_connectTcs.SetException(new Web3Exception(response.error));
}
}

/// <summary>
Expand Down
105 changes: 105 additions & 0 deletions Packages/io.chainsafe.web3-unity/Runtime/Prefabs/Web3Unity.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &9007579812972099230
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8519303782652390544}
- component: {fileID: 5008553068369276269}
- component: {fileID: 29625373239180716}
- component: {fileID: 6268052643211326401}
- component: {fileID: 153625530502621119}
- component: {fileID: 8371115045377063251}
m_Layer: 0
m_Name: Web3Unity
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8519303782652390544
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9007579812972099230}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5008553068369276269
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9007579812972099230}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b5a2f51f95094c949a28c71dc8658551, type: 3}
m_Name:
m_EditorClassIdentifier:
providers:
- {fileID: 11400000, guid: 835338196b5038d4b9351fadba9dac38, type: 2}
- {fileID: 11400000, guid: e5b50e2ca9fe0504daf70376bceb84ac, type: 2}
- {fileID: 11400000, guid: 0d7bd7ae4b3e79d489bbc54514343f5c, type: 2}
- {fileID: 11400000, guid: e56cb66917f860e489d3ed4480b4681c, type: 2}
--- !u!114 &29625373239180716
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9007579812972099230}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 96ece91a37dec784f8c42b19da0bbaae, type: 3}
m_Name:
m_EditorClassIdentifier:
connectModalPrefab: {fileID: 4706621120835174763, guid: 2dd57b774deda1948bd97dcb6d6e9fb4, type: 3}
--- !u!114 &6268052643211326401
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9007579812972099230}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 722440245baf97c4f8da707286230694, type: 3}
m_Name:
m_EditorClassIdentifier:
gelatoApiKey: 7MFQqyGS1Iui_e_MgmFW1BfbFeJ06g8nnL2oUTlIJug_
--- !u!114 &153625530502621119
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9007579812972099230}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9bddd0599e4c6ca4a8a476d02011f3cc, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &8371115045377063251
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9007579812972099230}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0d30a4f4c7d578c42beeecc2e2bbd394, type: 3}
m_Name:
m_EditorClassIdentifier:

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
@@ -1,4 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ChainSafe.Gaming.Web3.Build;
Expand All @@ -15,7 +15,7 @@ public class ConnectionHandler : MonoBehaviour, IConnectionHandler, IWeb3Builder
// Handed in ConnectionHandlerEditor
[HideInInspector, SerializeField] private ConnectionProvider[] providers;

public IWeb3BuilderServiceAdapter[] Web3BuilderServiceAdapters { get; private set; }
public HashSet<IWeb3BuilderServiceAdapter> Web3BuilderServiceAdapters { get; private set; }

public ConnectionProvider[] Providers => providers;

Expand All @@ -24,8 +24,9 @@ public class ConnectionHandler : MonoBehaviour, IConnectionHandler, IWeb3Builder
/// </summary>
public async Task Initialize()
{
Web3BuilderServiceAdapters = GetComponents<IWeb3BuilderServiceAdapter>();

Web3BuilderServiceAdapters = GetComponentsInChildren<IWeb3BuilderServiceAdapter>(true)
.Concat(FindObjectsOfType<Web3BuilderServiceAdapter>()).ToHashSet();

foreach (var provider in Providers)
{
await provider.Initialize();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using ChainSafe.Gaming.UnityPackage.Connection;
using ChainSafe.Gaming.Web3.Build;

Expand Down Expand Up @@ -25,7 +26,7 @@ public static Web3Builder ConfigureServices(this Web3Builder web3Builder, IWeb3B
/// <param name="web3Builder">Web3Builder instance to be configured.</param>
/// <param name="adapters">Multiple <see cref="IWeb3BuilderServiceAdapter"/> to be added to <see cref="Web3Builder"/>.</param>
/// <returns>Configured <see cref="Web3Builder"/>.</returns>
public static Web3Builder ConfigureServices(this Web3Builder web3Builder, IWeb3BuilderServiceAdapter[] adapters)
public static Web3Builder ConfigureServices(this Web3Builder web3Builder, HashSet<IWeb3BuilderServiceAdapter> adapters)
{
foreach (var adapter in adapters)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using ChainSafe.Gaming.Connection;
using ChainSafe.Gaming.Evm.Contracts;
using ChainSafe.Gaming.Evm.JsonRpc;
using ChainSafe.Gaming.Marketplace.Extensions;
using ChainSafe.Gaming.MultiCall;
using ChainSafe.Gaming.Web3;
using ChainSafe.Gaming.Web3.Build;
using ChainSafe.Gaming.Web3.Unity;
using ChainSafe.GamingSdk.Gelato;
using Microsoft.Extensions.DependencyInjection;
using Scripts.EVM.Token;
using CWeb3 = ChainSafe.Gaming.Web3.Web3;
Expand All @@ -23,7 +20,7 @@ public interface IConnectionHandler
/// <summary>
/// All service providers used for configuring <see cref="Web3"/> instance services.
/// </summary>
public IWeb3BuilderServiceAdapter[] Web3BuilderServiceAdapters { get; }
public HashSet<IWeb3BuilderServiceAdapter> Web3BuilderServiceAdapters { get; }

/// <summary>
/// Login by Building a <see cref="Web3"/> Instance.
Expand All @@ -44,7 +41,7 @@ private async Task OnWeb3Initialized(CWeb3 web3)
{
var web3InitializedHandlers = web3.ServiceProvider.GetServices<IWeb3InitializedHandler>();

foreach (var web3InitializedHandler in web3InitializedHandlers.OrderBy(w => w.Priority))
foreach (var web3InitializedHandler in web3InitializedHandlers)
{
await web3InitializedHandler.OnWeb3Initialized(web3);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ namespace ChainSafe.Gaming.UnityPackage.Connection
/// </summary>
public interface IWeb3InitializedHandler
{
/// <summary>
/// Determines order of execution for <see cref="IWeb3InitializedHandler"/>s.
/// </summary>
public int Priority { get; }

/// <summary>
/// Called when Web3 Instance in <see cref="IConnectionHandler"/> is initialized.
/// </summary>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using ChainSafe.Gaming.Web3.Build;
using UnityEngine;

namespace ChainSafe.Gaming.UnityPackage.Connection
{
/// <summary>
/// A MonoBehaviour implementation of <see cref="IWeb3BuilderServiceAdapter"/>.
/// If your MonoBehaviour can't be attached to the GameObject containing <see cref="Web3Unity"/> then inherit from this class instead of implementing <see cref="IWeb3ServiceCollection"/>.
/// </summary>
public abstract class Web3BuilderServiceAdapter : MonoBehaviour, IWeb3BuilderServiceAdapter
{
public abstract Web3Builder ConfigureServices(Web3Builder web3Builder);
}
}

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 @@ -33,9 +33,6 @@ public class StoredConnectionProviderData : IStorable, IWeb3InitializedHandler,
[JsonIgnore]
public Type Type => string.IsNullOrEmpty(TypeName) ? null : Type.GetType(TypeName);

[JsonIgnore]
public int Priority => 0;

public async Task OnWeb3Initialized(CWeb3 web3)
{
_localStorage = web3.ServiceProvider.GetService<ILocalStorage>();
Expand Down
11 changes: 5 additions & 6 deletions Packages/io.chainsafe.web3-unity/Runtime/Scripts/Web3Unity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ public static ConnectModal ConnectModal
/// </summary>
public static bool Connected => Web3 != null;

/// <summary>
/// Execution priority for <see cref="IWeb3InitializedHandler"/>.
/// Lower than other so it can be executed first.
/// </summary>
public int Priority => -1;

/// <summary>
/// Public key (address) of connected wallet.
/// </summary>
Expand Down Expand Up @@ -243,6 +237,11 @@ public Task OnWeb3Initialized(CWeb3 web3)
{
_web3 = web3;

if (_connectModal != null)
{
_connectModal.Close();
}

return Task.CompletedTask;
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading