Skip to content

Commit

Permalink
metamask integration at last completed at 1:41 pm
Browse files Browse the repository at this point in the history
  • Loading branch information
kunal528 committed Mar 24, 2023
1 parent 4b775fe commit 75df425
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 37 deletions.
16 changes: 9 additions & 7 deletions MetaMask/Runtime/MetaMaskWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
//}
}

/// <summary>Handles the event that is fired when an Chain ID changed event is received.</summary>
Expand Down
39 changes: 39 additions & 0 deletions MetaMask/Samples/Main/Scenes/MetaMaskMain.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions MetaMask/Samples/Main/Scripts/MetaMaskDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
using Nethereum.Contracts;
using Nethereum.ABI.Model;
using System.Numerics;
using Nethereum.Contracts;
using Nethereum.Util;




Expand Down Expand Up @@ -88,8 +89,8 @@ public void TransactionResult(object sender, MetaMaskEthereumRequestResultEventA
/// <summary>Raised when the wallet is connected.</summary>
private void walletConnected(object sender, EventArgs e)
{
SceneManager.LoadScene("MainScene");
onWalletConnected?.Invoke(this, EventArgs.Empty);
SceneManager.LoadScene("MainScene");
}

/// <summary>Raised when the wallet is disconnected.</summary>
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions MetaMask/Scripts/MetaMaskUnity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public static MetaMaskUnity Instance
if (instance == null)
{
var instances = FindObjectsOfType<MetaMaskUnity>();
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.");
Expand Down Expand Up @@ -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";
Expand Down
Loading

0 comments on commit 75df425

Please sign in to comment.