| | 1 | | using System; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public delegate void OnSearchResultDelegate (string searchInput, UserProfileModel[] profiles); |
| | 6 | |
|
| | 7 | | public interface IUsersSearchBridge |
| | 8 | | { |
| | 9 | | event OnSearchResultDelegate OnSearchResult; |
| | 10 | | } |
| | 11 | |
|
| | 12 | | public class UsersSearchBridge : MonoBehaviour, IUsersSearchBridge |
| | 13 | | { |
| | 14 | | public event OnSearchResultDelegate OnSearchResult; |
| | 15 | |
|
| 0 | 16 | | public static UsersSearchBridge i { get; private set; } |
| | 17 | |
|
| | 18 | | void Awake() |
| | 19 | | { |
| 52 | 20 | | if (i != null) |
| | 21 | | { |
| 0 | 22 | | Utils.SafeDestroy(this); |
| 0 | 23 | | return; |
| | 24 | | } |
| | 25 | |
|
| 52 | 26 | | i = this; |
| 52 | 27 | | } |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// Called by kernel when a query for ENS owners has finished |
| | 31 | | /// </summary> |
| | 32 | | /// <param name="payload">query result sent by kernel</param> |
| | 33 | | public void SetENSOwnerQueryResult(string payload) |
| | 34 | | { |
| 0 | 35 | | ResultPayload result = Utils.SafeFromJson<ResultPayload>(payload); |
| | 36 | |
|
| 0 | 37 | | UserProfileModel[] profiles = null; |
| 0 | 38 | | if (result.success && result.profiles.Length > 0) |
| | 39 | | { |
| 0 | 40 | | profiles = result.profiles; |
| | 41 | | } |
| 0 | 42 | | OnSearchResult?.Invoke(result.searchInput, profiles); |
| 0 | 43 | | } |
| | 44 | |
|
| | 45 | | [Serializable] |
| | 46 | | class ResultPayload |
| | 47 | | { |
| | 48 | | public string searchInput; |
| | 49 | | public bool success; |
| | 50 | | public UserProfileModel[] profiles; |
| | 51 | | } |
| | 52 | | } |