Skip to content

Debugger popups instead of console logs #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2023
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
552 changes: 552 additions & 0 deletions Assets/Thirdweb/Examples/Scenes/Scene_Prefabs.unity

Large diffs are not rendered by default.

20 changes: 8 additions & 12 deletions Assets/Thirdweb/Examples/Scripts/Prefabs/Prefab_Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ public async void GetEvents()
EventQueryOptions options = new EventQueryOptions(filters);

List<ContractEvent<TransferEvent>> allEvents = await contract.events.Get<TransferEvent>("Transfer", options);
Debug.Log($"[Get Events] Get - TransferEvent:\n{allEvents.ToString()}");
foreach (ContractEvent<TransferEvent> contractEvent in allEvents)
Debug.Log($"--[Get Events] ContractEvent:\n{contractEvent.ToString()}\n");
Debugger.Instance.Log("[Get Events] Get - TransferEvent #1", allEvents[0].ToString());
}
catch (System.Exception e)
{
Debug.Log($"Error: {e.Message}");
Debugger.Instance.Log("[Get Events] Error", e.Message);
}
}

Expand All @@ -57,13 +55,11 @@ public async void GetAllEvents()
EventQueryOptions options = new EventQueryOptions(null, 0, 16500000, "desc");

List<ContractEvent<object>> allContractEvents = await contract.events.GetAll(options);
Debug.Log($"[Get All Events] GetAll:\n{allContractEvents.ToString()}");
foreach (ContractEvent<object> contractEvent in allContractEvents)
Debug.Log($"--[Get All Events] ContractEvent:\n{contractEvent.ToString()}\n");
Debugger.Instance.Log("[Get All Events] Get - ContractEvent #1", allContractEvents[0].ToString());
}
catch (System.Exception e)
{
Debug.Log($"Error: {e.Message}");
Debugger.Instance.Log("[Get All Events] Error", e.Message);
}
}

Expand All @@ -73,7 +69,7 @@ public void ListenToAllEvents()
{
Contract contract = new Contract("goerli", "0x2e01763fA0e15e07294D74B63cE4b526B321E389");
contract.events.ListenToAll((ContractEvent<object> anyEvent) => OnEventTriggered(anyEvent));
Debug.Log("Listening to all events!");
Debugger.Instance.Log("Listening to all events!", "Try to trigger an event on the specified contract to get a callback.");
}

public async void RemoveAllEventListeners()
Expand All @@ -82,16 +78,16 @@ public async void RemoveAllEventListeners()
{
Contract contract = new Contract("goerli", "0x2e01763fA0e15e07294D74B63cE4b526B321E389");
await contract.events.RemoveAllListeners();
Debug.Log("Removed all event listeners!");
Debugger.Instance.Log("Removed all event listeners!", "Events emitted will not trigger callbacks anymore.");
}
catch (System.Exception e)
{
Debug.Log($"Error: {e.Message}");
Debugger.Instance.Log("[Remove All Event Listeners] Error", e.Message);
}
}

public void OnEventTriggered<T>(ContractEvent<T> contractEvent)
{
Debug.Log($"[EventListener] OnEventTriggered: An event was just emitted!\n{contractEvent.ToString()}");
Debugger.Instance.Log("[EventListener] OnEventTriggered", $"An event was just emitted!\n{contractEvent.ToString()}");
}
}
16 changes: 8 additions & 8 deletions Assets/Thirdweb/Examples/Scripts/Prefabs/Prefab_Miscellaneous.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public async void GetBalance()
try
{
CurrencyValue balance = await ThirdwebManager.Instance.SDK.wallet.GetBalance();
Debug.Log($"[Get Balance] Native Balance:\n{balance.ToString()}");
Debugger.Instance.Log("[Get Balance] Native Balance", balance.ToString());
}
catch (System.Exception e)
{
Debug.Log($"Error: {e.Message}");
Debugger.Instance.Log("[Get Balance] Error", e.Message);
}
}

Expand All @@ -27,7 +27,7 @@ public async void CustomCall()
Debug.Log($"[Custom Call] Read Custom URI:\n{uri}");

TransactionResult transactionResult = await contract.Write("claimKitten");
Debug.Log($"[Custom Call] Write Successful:\n{transactionResult}");
Debugger.Instance.Log("[Custom Call] Write Successful", transactionResult.ToString());

// With Transaction Overrides:
// await contract.Write("claim", new TransactionRequest
Expand All @@ -37,7 +37,7 @@ public async void CustomCall()
}
catch (System.Exception e)
{
Debug.Log($"Error: {e.Message}");
Debugger.Instance.Log("[Custom Call] Error", e.Message);
}
}

Expand All @@ -46,11 +46,11 @@ public async void Authenticate()
try
{
LoginPayload data = await ThirdwebManager.Instance.SDK.wallet.Authenticate("example.com");
Debug.Log($"[Authenticate] Successful:\n{data.ToString()}");
Debugger.Instance.Log("[Authenticate] Successful", data.ToString());
}
catch (System.Exception e)
{
Debug.Log($"Error: {e.Message}");
Debugger.Instance.Log("[Authenticate] Error", e.Message);
}
}

Expand All @@ -65,11 +65,11 @@ public async void Deploy()
primary_sale_recipient = await ThirdwebManager.Instance.SDK.wallet.GetAddress(),
}
);
Debug.Log($"[Deploy] Successful: At {address}");
Debugger.Instance.Log("[Deploy] Successful", $"Address: {address}");
}
catch (System.Exception e)
{
Debug.Log($"Error: {e.Message}");
Debugger.Instance.Log("[Deploy] Error", e.Message);
}
}

Expand Down
36 changes: 12 additions & 24 deletions Assets/Thirdweb/Examples/Scripts/Prefabs/Prefab_Reading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ public async void FetchERC20()
Contract contract = new Contract("goerli", "0xB4870B21f80223696b68798a755478C86ce349bE");

Currency currencyInfo = await contract.ERC20.Get();
Debug.Log($"[Fetch ERC20] Currency:\n{currencyInfo.ToString()}");
Debugger.Instance.Log("[Fetch ERC20] Get", currencyInfo.ToString());

CurrencyValue currencyValue = await contract.ERC20.TotalSupply();
Debug.Log($"[Fetch ERC20] Total Supply:\n{currencyValue.ToString()}");
// CurrencyValue currencyValue = await contract.ERC20.TotalSupply();
}
catch (System.Exception e)
{
Debug.Log($"Error: {e.Message}");
Debugger.Instance.Log("[Fetch ERC20] Error", e.Message);
}
}

Expand All @@ -30,20 +29,14 @@ public async void FetchERC721()
Contract contract = new Contract("goerli", "0x2e01763fA0e15e07294D74B63cE4b526B321E389");

NFT getResult = await contract.ERC721.Get("1");
Debug.Log($"[Fetch ERC721] Get:\n{getResult.ToString()}");

List<NFT> getAllResult = await contract.ERC721.GetAll(new Thirdweb.QueryAllParams() { start = 0, count = 10 });
Debug.Log($"[Fetch ERC721] GetAll:\n{getAllResult.ToString()}");
foreach (NFT nft in getAllResult)
Debug.Log($"--[Fetch ERC721] NFT:\n{nft.ToString()}\n");

string tokenURI = await contract.Read<string>("tokenURI", "1");
Debug.Log($"[Fetch ERC721] Custom Call - tokenURI(1): {tokenURI}");
Debugger.Instance.Log("[Fetch ERC721] Get", getResult.ToString());

// List<NFT> getAllResult = await contract.ERC721.GetAll(new Thirdweb.QueryAllParams() { start = 0, count = 10 });
// List<NFT> getOwnedResult = await contract.ERC721.GetOwned("someAddress");
}
catch (System.Exception e)
{
Debug.Log($"Error: {e.Message}");
Debugger.Instance.Log("[Fetch ERC721] Error", e.Message);
}
}

Expand All @@ -54,16 +47,13 @@ public async void FetchERC1155()
Contract contract = new Contract("goerli", "0x86B7df0dc0A790789D8fDE4C604EF8187FF8AD2A");

NFT getResult = await contract.ERC1155.Get("1");
Debug.Log($"[Fetch ERC1155] Get:\n{getResult.ToString()}");
Debugger.Instance.Log("[Fetch ERC1155] Get", getResult.ToString());

List<NFT> getAllResult = await contract.ERC1155.GetAll(new Thirdweb.QueryAllParams() { start = 0, count = 10 });
Debug.Log($"[Fetch ERC1155] GetAll:\n{getAllResult.ToString()}");
foreach (NFT nft in getAllResult)
Debug.Log($"--[Fetch ERC1155] NFT:\n{nft.ToString()}\n");
// List<NFT> getAllResult = await contract.ERC1155.GetAll(new Thirdweb.QueryAllParams() { start = 0, count = 10 });
}
catch (System.Exception e)
{
Debug.Log($"Error: {e.Message}");
Debugger.Instance.Log("[Fetch ERC1155] Error", e.Message);
}
}

Expand All @@ -75,13 +65,11 @@ public async void FetchListings()
Marketplace marketplace = contract.marketplace;

List<Listing> getAllListingsResult = await marketplace.GetAllListings();
Debug.Log($"[Fetch Listings] GetAllListings:\n{getAllListingsResult.ToString()}");
foreach (Listing listing in getAllListingsResult)
Debug.Log($"--[Fetch Listings] Listing:\n{listing.ToString()}\n");
Debugger.Instance.Log("[Fetch Listings] Listing #1", getAllListingsResult[0].ToString());
}
catch (System.Exception e)
{
Debug.Log($"Error: {e.Message}");
Debugger.Instance.Log("[Fetch Listings] Error", e.Message);
}
}
}
21 changes: 9 additions & 12 deletions Assets/Thirdweb/Examples/Scripts/Prefabs/Prefab_Writing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public async void MintERC20()
Contract contract = new Contract("goerli", "0xB4870B21f80223696b68798a755478C86ce349bE");

TransactionResult transactionResult = await contract.ERC20.Mint("1.2");
Debug.Log($"[Mint ERC20] Successful:\n{transactionResult.ToString()}");
Debugger.Instance.Log("[Mint ERC20] Successful", transactionResult.ToString());

// Signature Minting
// var payload = new ERC20MintPayload("0xE79ee09bD47F4F5381dbbACaCff2040f2FbC5803", "3.2");
Expand All @@ -21,7 +21,7 @@ public async void MintERC20()
}
catch (System.Exception e)
{
Debug.Log($"Error: {e.Message}");
Debugger.Instance.Log("[Mint ERC20] Error", e.Message);
}
}

Expand All @@ -43,15 +43,15 @@ public async void MintERC721()
ERC721SignedPayload signedPayload = await contract.ERC721.signature.Generate(payload); // Typically generated on the backend

TransactionResult transactionResult = await contract.ERC721.signature.Mint(signedPayload);
Debug.Log($"[Mint ERC721] Successful:\n{transactionResult.ToString()}");
Debugger.Instance.Log("[Mint ERC721] Successful", transactionResult.ToString());

// NFT Drop Claiming
// var result = await contract.ERC721.Claim(1);
// Debug.Log("claimed tokenId: " + result[0].id);
}
catch (System.Exception e)
{
Debug.Log($"Error: {e.Message}");
Debugger.Instance.Log("[Mint ERC721] Error", e.Message);
}
}

Expand All @@ -65,15 +65,12 @@ public async void MintERC1155()
bool canClaim = await contract.ERC1155.claimConditions.CanClaim("0", 1);
if (!canClaim)
{
Debug.Log("[Mint ERC1155] Cannot claim!");
Debugger.Instance.Log("[Mint ERC721] Cannot Claim", "Connected wallet not eligible to claim.");
return;
}

TransactionResult transactionResult = await contract.ERC1155.Claim("0", 1);
Debug.Log($"[Mint ERC1155] Successful:\n{transactionResult.ToString()}");

int newSupply = await contract.ERC1155.TotalSupply("0");
Debug.Log($"[Mint ERC1155] New Supply: {newSupply}");
Debugger.Instance.Log("[Mint ERC1155] Successful", transactionResult.ToString());

// Edition Drop - Signature minting additional supply
// var payload = new ERC1155MintAdditionalPayload("0xE79ee09bD47F4F5381dbbACaCff2040f2FbC5803", "1");
Expand All @@ -84,7 +81,7 @@ public async void MintERC1155()
}
catch (System.Exception e)
{
Debug.Log($"Error: {e.Message}");
Debugger.Instance.Log("[Mint ERC1155] Error", e.Message);
}
}

Expand All @@ -96,11 +93,11 @@ public async void BuyListing()
Marketplace marketplace = contract.marketplace;

TransactionResult transactionResult = await marketplace.BuyListing("0", 1);
Debug.Log($"[Buy Listing] Successful:\n{transactionResult.ToString()}");
Debugger.Instance.Log("[Buy Listing] Successful", transactionResult.ToString());
}
catch (System.Exception e)
{
Debug.Log($"Error: {e.Message}");
Debugger.Instance.Log("[Buy Listing] Error", e.Message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void Awake()
if (Instance == null)
Instance = this;
else
Destroy(gameObject);
Destroy(this.gameObject);

#if !UNITY_EDITOR
SDK = new ThirdwebSDK(chainIdentifiers[chain]);
Expand Down
31 changes: 31 additions & 0 deletions Assets/Thirdweb/Examples/Scripts/Utils/Debugger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using UnityEngine;
using TMPro;

public class Debugger : MonoBehaviour
{
public GameObject debuggerPanel;
public TMP_Text titleText;
public TMP_Text descriptionText;

public static Debugger Instance;

private void Awake()
{
if (Instance == null)
Instance = this;
else
Destroy(this.gameObject);
}

private void Start()
{
debuggerPanel.SetActive(false);
}

public void Log(string title, string description)
{
debuggerPanel.SetActive(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't tested this yet, but is this debugger popup dismissable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is

titleText.text = title;
descriptionText.text = description;
}
}
11 changes: 11 additions & 0 deletions Assets/Thirdweb/Examples/Scripts/Utils/Debugger.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.