Skip to content

Commit

Permalink
Mixpanel test
Browse files Browse the repository at this point in the history
  • Loading branch information
skibitsky committed Aug 14, 2024
1 parent c4e912d commit 70ec6c8
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 25 deletions.

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 @@ -107,6 +107,7 @@ private static void InjectSecrets(Dictionary<string, string> options)
{
var mixpanelSettings = MixpanelSettings.Instance;
mixpanelSettings.RuntimeToken = mixpanelToken;
mixpanelSettings.DebugToken = mixpanelToken;
EditorUtility.SetDirty(mixpanelSettings);
}

Expand Down
8 changes: 4 additions & 4 deletions Samples/AppKit Sample/Assets/Resources/Mixpanel.asset
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5e37f1d599a72b64eba3799d826c755b, type: 3}
m_Name: Mixpanel
m_EditorClassIdentifier:
ShowDebug: 1
ShowDebug: 0
ManualInitialization: 0
APIHostAddress: https://api.mixpanel.com/
RuntimeToken:
DebugToken:
FlushInterval: 60
RuntimeToken: cd255a5aa17bf3793b5272a99f25594c
DebugToken: cd255a5aa17bf3793b5272a99f25594c
FlushInterval: 10
UseIpAddressForGeolocation: 1
36 changes: 36 additions & 0 deletions Samples/AppKit Sample/Assets/Scripts/AppInit.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using System.Collections;
using mixpanel;
using Skibitsky.Unity;
using UnityEngine;
using UnityEngine.SceneManagement;
using WalletConnectSharp.Storage;
using WalletConnectUnity.Core;

namespace WalletConnect.Web3Modal.Sample
{
Expand All @@ -14,6 +18,7 @@ public class AppInit : MonoBehaviour
private void Start()
{
InitDebugConsole();
ConfigureMixpanel();
SceneManager.LoadScene(_mainScene);
}

Expand All @@ -24,5 +29,36 @@ private void InitDebugConsole()
_debugConsole.SetActive(true);
#endif
}

private async void ConfigureMixpanel()
{
// PlayerPrefs.DeleteAll();
// var path = $"{Application.persistentDataPath}/WalletConnect/mixpanel.json";
// Debug.Log($"Mixpanel storage path: {path}");
// var storage = new AsyncMixpanelStorage(path);
// await storage.Init();
// MixpanelStorage.SetPreferencesSource(storage);
//
// UnityEventsDispatcher.Instance.StartCoroutine(SaveStorageInterval(storage));

Application.logMessageReceived += (logString, stackTrace, type) =>
{
var props = new Value
{
["type"] = type.ToString()
};
Mixpanel.Track(logString, props);
};
}

private IEnumerator SaveStorageInterval(AsyncMixpanelStorage storage)
{
var interval = new WaitForSeconds(2);
for (;;)
{
storage.Save();
yield return interval;
}
}
}
}
40 changes: 24 additions & 16 deletions Samples/AppKit Sample/Assets/Scripts/Dapp.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using mixpanel;
using Nethereum.ABI.EIP712;
using Nethereum.JsonRpc.Client;
using Nethereum.Web3;
Expand Down Expand Up @@ -40,7 +41,14 @@ private async void Start()
Notification.ShowMessage("Web3Modal is not initialized. Please initialize Web3Modal first.");
return;
}


var wc = WalletConnectConnector.WalletConnectInstance;
if (wc is { IsInitialized: true })
{
var clientId = await wc.SignClient.Core.Crypto.GetClientId();
Mixpanel.Identify(clientId);
}

try
{
_initializingLabel.gameObject.SetActive(false);
Expand Down Expand Up @@ -92,7 +100,7 @@ private async void Start()
};

_resumed = await Web3Modal.ConnectorController.TryResumeSessionAsync();

_networkButton.interactable = true;
_connectButton.interactable = !_resumed;
_accountButton.interactable = _resumed;
Expand Down Expand Up @@ -149,15 +157,15 @@ public async void OnGetBalanceButton()
public async void OnPersonalSignButton()
{
Debug.Log("[Web3Modal Sample] OnPersonalSignButton");

try
{
var account = await Web3Modal.GetAccountAsync();

const string message = "Hello from Unity!";
var signature = await Web3Modal.Evm.SignMessageAsync(message);
var isValid = await Web3Modal.Evm.VerifyMessageSignatureAsync(account.Address, message, signature);

Notification.ShowMessage($"Signature valid: {isValid}");
}
catch (RpcResponseException e)
Expand Down Expand Up @@ -187,13 +195,13 @@ public async void OnDisconnectButton()
public async void OnSendTransactionButton()
{
Debug.Log("[Web3Modal Sample] OnSendTransactionButton");

const string toAddress = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";

try
{
Notification.ShowMessage("Sending transaction...");

var value = Web3.Convert.ToWei(0.001);
var result = await Web3Modal.Evm.SendTransactionAsync(toAddress, value);
Debug.Log("Transaction hash: " + result);
Expand Down Expand Up @@ -248,13 +256,13 @@ public async void OnSignTypedDataV4Button()
typedData.SetMessage(mail);

var jsonMessage = typedData.ToJson();

try
{
{
var signature = await Web3Modal.Evm.SignTypedDataAsync(jsonMessage);

var isValid = await Web3Modal.Evm.VerifyTypedDataSignatureAsync(account.Address, jsonMessage, signature);

Notification.ShowMessage($"Signature valid: {isValid}");
}
catch (Exception e)
Expand All @@ -263,21 +271,21 @@ public async void OnSignTypedDataV4Button()
Debug.LogException(e, this);
}
}

public async void OnReadContractClicked()
{
if (Web3Modal.NetworkController.ActiveChain.ChainId != "1")
{
Notification.ShowMessage("Please switch to Ethereum mainnet.");
return;
}

const string contractAddress = "0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb"; // on Ethereum mainnet
const string yugaLabsAddress = "0xA858DDc0445d8131daC4d1DE01f834ffcbA52Ef1";
const string abi = CryptoPunksAbi;

Notification.ShowMessage("Reading smart contract state...");

try
{
var tokenName = await Web3Modal.Evm.ReadContractAsync<string>(contractAddress, abi, "name");
Expand All @@ -288,7 +296,7 @@ public async void OnReadContractClicked()
yugaLabsAddress
});
var result = $"Yuga Labs owns: {balance} {tokenName} tokens active chain.";

Notification.ShowMessage(result);
}
catch (Exception e)
Expand All @@ -313,7 +321,7 @@ private TypedData<Domain> GetMailTypedDefinition()
PrimaryType = nameof(Mail)
};
}

public const string CryptoPunksAbi =
@"[{""constant"":true,""inputs"":[{""name"":""_owner"",""type"":""address""}],""name"":""balanceOf"",""outputs"":[{""name"":""balance"",""type"":""uint256""}],""payable"":false,""stateMutability"":""view"",""type"":""function""},
{""constant"":true,""inputs"":[],""name"":""name"",""outputs"":[{""name"":"""",""type"":""string""}],""payable"":false,""stateMutability"":""view"",""type"":""function""}]";
Expand Down
8 changes: 5 additions & 3 deletions Samples/AppKit Sample/Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"com.mixpanel.unity": "3.5.2",
"com.bgtools.playerprefseditor": "1.2.2",
"com.skibitsky.scene-reference": "1.1.1",
"com.unity.ide.rider": "3.0.31",
"com.unity.ide.visualstudio": "2.0.22",
Expand Down Expand Up @@ -44,13 +44,15 @@
"com.unity.modules.video": "1.0.0",
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.wind": "1.0.0",
"com.unity.modules.xr": "1.0.0"
"com.unity.modules.xr": "1.0.0",
"com.mixpanel.unity": "3.5.2"
},
"scopedRegistries": [
{
"name": "package.openupm.com",
"url": "https://package.openupm.com",
"scopes": [
"com.bgtools.playerprefseditor",
"com.mixpanel.unity",
"com.nethereum.unity",
"com.openupm",
Expand All @@ -61,4 +63,4 @@
]
}
]
}
}
7 changes: 7 additions & 0 deletions Samples/AppKit Sample/Packages/packages-lock.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"dependencies": {
"com.bgtools.playerprefseditor": {
"version": "1.2.2",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://package.openupm.com"
},
"com.mixpanel.unity": {
"version": "3.5.2",
"depth": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ MonoBehaviour:
m_Name: package.openupm.com
m_Url: https://package.openupm.com
m_Scopes:
- com.bgtools.playerprefseditor
- com.mixpanel.unity
- com.nethereum.unity
- com.openupm
Expand All @@ -45,6 +46,6 @@ MonoBehaviour:
m_RegistryInfoDraft:
m_Modified: 0
m_ErrorMessage:
m_UserModificationsInstanceId: -852
m_OriginalInstanceId: -856
m_UserModificationsInstanceId: -834
m_OriginalInstanceId: -838
m_LoadAssets: 0

0 comments on commit 70ec6c8

Please sign in to comment.