Skip to content

Commit

Permalink
Merge pull request #36 from TreasureProject/develop
Browse files Browse the repository at this point in the history
v0.2.6
  • Loading branch information
alecananian authored Apr 12, 2024
2 parents 63050e3 + 9a220f9 commit 14691d6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
25 changes: 20 additions & 5 deletions Assets/Treasure/Example/Scripts/HarvesterUI.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Numerics;
using System.Threading.Tasks;


#if TDK_THIRDWEB
using Thirdweb;
Expand All @@ -23,6 +25,7 @@ public class HarvesterUI : MonoBehaviour
public TMP_Text InfoText;

private Harvester _harvester;
private HarvesterCorruptionRemoval _harvesterCorruptionRemoval;
private BigInteger _magicAmount = BigInteger.Parse(Utils.ToWei("1000"));

void Start()
Expand All @@ -33,26 +36,38 @@ void Start()
private async void refreshHarvester()
{
#if TDK_THIRDWEB
_harvester = await TDK.Bridgeworld.GetHarvester(Treasure.Contract.HarvesterEmberwing);
var harvesterTask = TDK.Bridgeworld.GetHarvester(Treasure.Contract.HarvesterEmberwing);
var harvesterCorruptionRemovalTask = TDK.Bridgeworld.GetHarvesterCorruptionRemoval(Treasure.Contract.HarvesterEmberwing);

await Task.WhenAll(harvesterTask, harvesterCorruptionRemovalTask);

_harvester = harvesterTask.Result;
_harvesterCorruptionRemoval = harvesterCorruptionRemovalTask.Result;

string smartAccountAddress = null;
if (TDK.Identity.IsAuthenticated)
{
smartAccountAddress = await TDK.Identity.GetWalletAddress();
}

InfoText.text = $@"Smart Account: {(smartAccountAddress != null ? smartAccountAddress : '-')}
InfoText.text = $@"
Smart Account: {(smartAccountAddress != null ? smartAccountAddress : '-')}
{Utils.ToEth(_harvester.userMagicBalance.ToString())} MAGIC balance
{_harvester.userPermitsBalance} Ancient Permits
Harvester: {_harvester.id}
Harvester Details
Global Details
Mining Power: {_harvester.totalBoost}X
Corruption: {Utils.ToEth(_harvester.totalCorruption.ToString())} / {Utils.ToEth(_harvester.corruptionMaxGenerated.ToString())}
{Utils.ToEth(_harvester.totalMagicStaked.ToString())} MAGIC staked
User Details
Corruption Removal
{_harvesterCorruptionRemoval.corruptionRemovalRecipes.Count} recipe(s) available
Harvester User Details
Mining Power: {_harvester.userTotalBoost}X
{_harvester.userPermitsStaked} Ancient Permits staked
{Utils.ToEth(_harvester.userMagicMaxStakeable.ToString())} MAGIC max stakeable
Expand Down
8 changes: 7 additions & 1 deletion Assets/Treasure/TDK/Runtime/API/Corruption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public struct HarvesterCorruptionRemoval
{
public List<CorruptionRemovalRecipe> corruptionRemovalRecipes;
public List<InventoryToken> userInventoryCorruptionRemovalRecipeItems;
public List<Dictionary<string, Approval>> userApprovalsCorruptionRemovalRecipeItems;
public Dictionary<string, Approval> userApprovalsCorruptionRemovalRecipeItems;
public List<CorruptionRemoval> userCorruptionRemovals;
}

Expand All @@ -51,5 +51,11 @@ public async Task<HarvesterCorruptionRemoval> GetHarvesterCorruptionRemoval(stri
var response = await Get($"/harvesters/{id}/corruption-removal");
return JsonConvert.DeserializeObject<HarvesterCorruptionRemoval>(response);
}

public async Task<HarvesterCorruptionRemoval> GetHarvesterCorruptionRemoval(Contract contract)
{
var chainId = await TDK.Identity.GetChainId();
return await GetHarvesterCorruptionRemoval(Constants.ContractAddresses[chainId][contract]);
}
}
}
7 changes: 6 additions & 1 deletion Assets/Treasure/TDK/Runtime/Bridgeworld/TDK.Bridgeworld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ private void InitBridgeworld()
}
}

public class Bridgeworld
public partial class Bridgeworld
{
public Bridgeworld() { }

public async Task<Harvester> GetHarvester(Contract contract)
{
return await TDK.API.GetHarvester(contract);
}

public async Task<HarvesterCorruptionRemoval> GetHarvesterCorruptionRemoval(Contract contract)
{
return await TDK.API.GetHarvesterCorruptionRemoval(contract);
}
}

public partial class Harvester
Expand Down
2 changes: 1 addition & 1 deletion Assets/Treasure/TDK/Runtime/TDKVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public static class TDKVersion
{
public static string name = "tdk-unity";
public static string version = "0.2.5";
public static string version = "0.2.6";
}
}

0 comments on commit 14691d6

Please sign in to comment.