From 75df42541b58043a70bdc6001f15cd69943f221f Mon Sep 17 00:00:00 2001 From: kunal528 Date: Sat, 25 Mar 2023 01:41:13 +0530 Subject: [PATCH] metamask integration at last completed at 1:41 pm --- MetaMask/Runtime/MetaMaskWallet.cs | 16 ++--- .../Samples/Main/Scenes/MetaMaskMain.unity | 39 ++++++++++++ MetaMask/Samples/Main/Scripts/MetaMaskDemo.cs | 11 ++-- MetaMask/Scripts/MetaMaskUnity.cs | 3 + Scenes/MainScene.unity | 60 ++++++++++++++++++- Scripts/ButtonHandler.cs | 5 +- Scripts/CameraController.cs | 1 + Scripts/CounterController.cs | 16 +++-- Scripts/DetailController.cs | 1 + Scripts/GetContract.cs | 15 +++-- Scripts/PanelController.cs | 35 +++++++---- 11 files changed, 165 insertions(+), 37 deletions(-) diff --git a/MetaMask/Runtime/MetaMaskWallet.cs b/MetaMask/Runtime/MetaMaskWallet.cs index 0de3992..4c7a207 100644 --- a/MetaMask/Runtime/MetaMaskWallet.cs +++ b/MetaMask/Runtime/MetaMaskWallet.cs @@ -606,19 +606,21 @@ protected void OnEthereumEventReceived(JsonElement data) protected void OnAccountsChanged(JsonElement accounts) { MetaMaskDebug.Log("Account changed"); - try - { + this.selectedAddress = accounts[0].ToString(); + MetaMaskDebug.Log(accounts[0]); + MetaMaskDebug.Log(accounts); + MetaMaskDebug.Log(this.selectedAddress); AccountChanged?.Invoke(this, EventArgs.Empty); if (this.paused) { OnWalletReady(); } - } - catch - { - this.selectedAddress = string.Empty; - } + //} + //catch + //{ + // this.selectedAddress = string.Empty; + //} } /// Handles the event that is fired when an Chain ID changed event is received. diff --git a/MetaMask/Samples/Main/Scenes/MetaMaskMain.unity b/MetaMask/Samples/Main/Scenes/MetaMaskMain.unity index c9485d9..4f83fb9 100644 --- a/MetaMask/Samples/Main/Scenes/MetaMaskMain.unity +++ b/MetaMask/Samples/Main/Scenes/MetaMaskMain.unity @@ -5280,6 +5280,7 @@ GameObject: m_Component: - component: {fileID: 990788811} - component: {fileID: 990788810} + - component: {fileID: 990788812} m_Layer: 0 m_Name: WebSocket Dispatcher m_TagString: Untagged @@ -5314,6 +5315,18 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 10 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &990788812 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 990788809} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6d84adc1622094a29b4ac495436769e6, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &1000082875 GameObject: m_ObjectHideFlags: 0 @@ -10972,6 +10985,7 @@ GameObject: m_Component: - component: {fileID: 1920087936} - component: {fileID: 1920087935} + - component: {fileID: 1920087937} m_Layer: 0 m_Name: MetaMaskUnityTransportBroadcaster m_TagString: Untagged @@ -11008,6 +11022,18 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 9 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1920087937 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1920087934} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6d84adc1622094a29b4ac495436769e6, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &1979139653 GameObject: m_ObjectHideFlags: 0 @@ -11680,6 +11706,7 @@ GameObject: m_Component: - component: {fileID: 2036012899} - component: {fileID: 2036012898} + - component: {fileID: 2036012900} m_Layer: 0 m_Name: MetaMaskUnity m_TagString: Untagged @@ -11716,6 +11743,18 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 8 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &2036012900 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2036012897} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6d84adc1622094a29b4ac495436769e6, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &2039765033 GameObject: m_ObjectHideFlags: 0 diff --git a/MetaMask/Samples/Main/Scripts/MetaMaskDemo.cs b/MetaMask/Samples/Main/Scripts/MetaMaskDemo.cs index bdf4ef8..6dbd01d 100644 --- a/MetaMask/Samples/Main/Scripts/MetaMaskDemo.cs +++ b/MetaMask/Samples/Main/Scripts/MetaMaskDemo.cs @@ -13,7 +13,8 @@ using Nethereum.Contracts; using Nethereum.ABI.Model; using System.Numerics; -using Nethereum.Contracts; +using Nethereum.Util; + @@ -88,8 +89,8 @@ public void TransactionResult(object sender, MetaMaskEthereumRequestResultEventA /// Raised when the wallet is connected. private void walletConnected(object sender, EventArgs e) { - SceneManager.LoadScene("MainScene"); onWalletConnected?.Invoke(this, EventArgs.Empty); + SceneManager.LoadScene("MainScene"); } /// Raised when the wallet is disconnected. @@ -203,12 +204,12 @@ public async void GetNFT(string id) if (data != null) { var owner = await indiCultureNFTConsole.GetOwnerOf(id); - NFTData nftData = new NFTData(Int16.Parse(data.TokenId.ToString()), owner, indiCultre.ConvertWei(data.BidAmount), data.Bidder, data.EndTimestamp.ToString() + "000"); + NFTData nftData = new NFTData(Int16.Parse(data.TokenId.ToString()), owner.ToLower(), indiCultre.ConvertWei(data.BidAmount), data.Bidder.ToLower(), data.EndTimestamp.ToString() + "000"); MetaState.nft = nftData; } } - public async void Collect(string id) + public async void Collect(int id) { TransactionInput input = new IndiCultre.IndiCultreConsole().Collect(id, MetaMaskUnity.Instance.Wallet.SelectedAddress); TransactionData transactionData = new TransactionData(input.To, input.From, input.Data, "0x0"); @@ -221,7 +222,7 @@ public async void Collect(string id) await MetaMaskUnity.Instance.Wallet.Request(request); } - public async void Bid(string id, BigInteger amount) + public async void Bid(string id,BigDecimal amount) { TransactionInput input = new IndiCultre.IndiCultreConsole().Bid(id, MetaMaskUnity.Instance.Wallet.SelectedAddress, amount); TransactionData transactionData = new TransactionData(input.To, input.From, input.Data, input.Value.HexValue); diff --git a/MetaMask/Scripts/MetaMaskUnity.cs b/MetaMask/Scripts/MetaMaskUnity.cs index eb4780f..33f3e76 100644 --- a/MetaMask/Scripts/MetaMaskUnity.cs +++ b/MetaMask/Scripts/MetaMaskUnity.cs @@ -58,6 +58,7 @@ public static MetaMaskUnity Instance if (instance == null) { var instances = FindObjectsOfType(); + print(instances); if (instances.Length > 1) { Debug.LogError("There are more than 1 instances of " + nameof(MetaMaskUnity) + " inside the scene, there should be only one."); @@ -191,6 +192,8 @@ public void Initialize(MetaMaskConfig config, IMetaMaskTransport transport, IMet // Load and configure the session LoadSession(); + MetaMaskDebug.Log("Metamask Instanitialize"); + // Setup the wallet this.wallet = new MetaMaskWallet(this.session, transport, socket, this.config.SocketUrl); this.wallet.AnalyticsPlatform = "unity"; diff --git a/Scenes/MainScene.unity b/Scenes/MainScene.unity index fde3b02..0c32c37 100644 --- a/Scenes/MainScene.unity +++ b/Scenes/MainScene.unity @@ -1288,6 +1288,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &166533681 MeshRenderer: m_ObjectHideFlags: 0 @@ -1389,6 +1391,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &177512989 MeshRenderer: m_ObjectHideFlags: 0 @@ -2059,6 +2063,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &236544194 MeshRenderer: m_ObjectHideFlags: 0 @@ -2604,6 +2610,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &287698324 MeshRenderer: m_ObjectHideFlags: 0 @@ -3246,6 +3254,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &341972815 MeshRenderer: m_ObjectHideFlags: 0 @@ -4400,7 +4410,7 @@ MeshRenderer: m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: - - {fileID: 3107459617028279915, guid: 4d70977260a4df64d9088a29dc5ad759, type: 2} + - {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_StaticBatchInfo: firstSubMesh: 0 subMeshCount: 0 @@ -4999,6 +5009,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &431786744 MeshRenderer: m_ObjectHideFlags: 0 @@ -5100,6 +5112,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &443112732 MeshRenderer: m_ObjectHideFlags: 0 @@ -6708,6 +6722,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &566356015 MeshRenderer: m_ObjectHideFlags: 0 @@ -9747,6 +9763,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!4 &753600592 stripped Transform: m_CorrespondingSourceObject: {fileID: 430272, guid: a8af4b644620845289b210a472d4cf80, type: 3} @@ -9816,6 +9834,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &761562281 MeshRenderer: m_ObjectHideFlags: 0 @@ -10348,6 +10368,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &809099391 MeshRenderer: m_ObjectHideFlags: 0 @@ -11192,6 +11214,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!1001 &892784754 PrefabInstance: m_ObjectHideFlags: 0 @@ -13116,7 +13140,7 @@ MeshRenderer: m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: - - {fileID: 7998390759824753287, guid: fea538ba0ea812a4aacf1dd48c93ffab, type: 2} + - {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_StaticBatchInfo: firstSubMesh: 0 subMeshCount: 0 @@ -14588,6 +14612,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &1046970506 MeshRenderer: m_ObjectHideFlags: 0 @@ -14689,6 +14715,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &1048313269 MeshRenderer: m_ObjectHideFlags: 0 @@ -15987,6 +16015,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &1180408071 MeshRenderer: m_ObjectHideFlags: 0 @@ -18591,6 +18621,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &1327659950 MeshRenderer: m_ObjectHideFlags: 0 @@ -19353,6 +19385,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &1409011437 MeshRenderer: m_ObjectHideFlags: 0 @@ -19454,6 +19488,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &1411626055 MeshRenderer: m_ObjectHideFlags: 0 @@ -19993,6 +20029,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &1436108480 MeshRenderer: m_ObjectHideFlags: 0 @@ -20094,6 +20132,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &1436413227 MeshRenderer: m_ObjectHideFlags: 0 @@ -21080,6 +21120,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &1542126579 MeshRenderer: m_ObjectHideFlags: 0 @@ -21275,6 +21317,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &1558056549 MeshRenderer: m_ObjectHideFlags: 0 @@ -21376,6 +21420,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &1558276253 MeshRenderer: m_ObjectHideFlags: 0 @@ -23016,6 +23062,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &1693615294 MeshRenderer: m_ObjectHideFlags: 0 @@ -24110,6 +24158,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &1746023676 MeshRenderer: m_ObjectHideFlags: 0 @@ -25626,6 +25676,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &1873394699 MeshRenderer: m_ObjectHideFlags: 0 @@ -26032,6 +26084,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &1918314211 MeshRenderer: m_ObjectHideFlags: 0 @@ -26133,6 +26187,8 @@ MonoBehaviour: m_EditorClassIdentifier: details: {fileID: 28876496010075788} language: english + panelOpen: 0 + timer: 0 --- !u!23 &1921090930 MeshRenderer: m_ObjectHideFlags: 0 diff --git a/Scripts/ButtonHandler.cs b/Scripts/ButtonHandler.cs index d8b11c0..95541e9 100644 --- a/Scripts/ButtonHandler.cs +++ b/Scripts/ButtonHandler.cs @@ -5,6 +5,7 @@ using UnityEngine.UI; using System; using System.Numerics; +using Nethereum.Util; public class ButtonHandler : MonoBehaviour { @@ -26,7 +27,7 @@ public void onBidOrWithdraw() { if (name == "Bid") { inputForm.SetActive(true); } else if (name == "Collect") { - GameObject.FindObjectOfType().Collect(MetaState.token_id.ToString()); + GameObject.FindObjectOfType().Collect(MetaState.token_id); /*#if !UNITY_EDITOR Withdraw(MetaState.token_id); #endif*/ @@ -41,7 +42,7 @@ public void onBidOrWithdraw() { } public void onBid() { - GameObject.FindObjectOfType().Bid(MetaState.token_id.ToString(), new BigInteger(Double.Parse(MetaState.bid))); + GameObject.FindObjectOfType().Bid(MetaState.token_id.ToString(), new BigDecimal(new Decimal(Double.Parse(MetaState.bid)))); /*#if !UNITY_EDITOR Bid(data); #endif*/ diff --git a/Scripts/CameraController.cs b/Scripts/CameraController.cs index 6b21e7a..e5b1e3f 100644 --- a/Scripts/CameraController.cs +++ b/Scripts/CameraController.cs @@ -15,6 +15,7 @@ public class CameraController : MonoBehaviour private void Start() { + print(GameObject.FindObjectOfType().getUser()); //var arts = GameObject.FindObjectsOfType(); //string data = "sep=@\nToken Id, Name, Description\n"; //for (int i = 0; i < arts.Length; i++) diff --git a/Scripts/CounterController.cs b/Scripts/CounterController.cs index 8c4b417..54a2d36 100644 --- a/Scripts/CounterController.cs +++ b/Scripts/CounterController.cs @@ -16,6 +16,7 @@ private void Start() { } public void ChangeTime(string time, int id) { + System.DateTime epochStart = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc); epochStart = epochStart.ToLocalTime(); Int64 cur_time = (Int64)((System.DateTime.Now - epochStart).TotalSeconds * 1000); @@ -48,7 +49,8 @@ public void SetTimer(string value) { System.DateTime epochStart = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc); epochStart = epochStart.ToLocalTime(); Int64 cur_time = (Int64)((System.DateTime.Now - epochStart).TotalSeconds * 1000); - if (Int64.Parse(MetaState.nft.end_timestamp) > cur_time && MetaState.nft.owner == MetaState.user) + var user = GameObject.FindObjectOfType().getUser(); + if (Int64.Parse(MetaState.nft.end_timestamp) > cur_time && MetaState.nft.owner == user) { button.GetComponentInChildren().text = "Resale"; button.GetComponent