Skip to content

Commit

Permalink
Change contract list with UI; (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
mismirnov authored Jul 6, 2023
1 parent b0b687c commit c2ee63b
Show file tree
Hide file tree
Showing 13 changed files with 1,898 additions and 470 deletions.
6 changes: 6 additions & 0 deletions Runtime/Scripts/Tezos/ITezos.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TezosSDK.Tezos.API;
using TezosSDK.Tezos.API.Models;
using TezosSDK.Tezos.API.Models.Abstract;
Expand Down Expand Up @@ -28,5 +29,10 @@ public interface ITezos
/// Current wallet tz balance.
/// </summary>
public IEnumerator GetCurrentWalletBalance(Action<ulong> callback);

/// <summary>
/// Get all originated contracts by the account.
/// </summary>
public IEnumerator GetOriginatedContracts(Action<IEnumerable<TokenContract>> callback);
}
}
28 changes: 23 additions & 5 deletions Runtime/Scripts/Tezos/Tezos.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TezosSDK.Beacon;
using TezosSDK.Tezos.API;
using TezosSDK.Tezos.API.Models;
using TezosSDK.Tezos.API.Models.Filters;
using TezosSDK.Tezos.API.Models.Abstract;
using TezosSDK.Tezos.Wallet;
using UnityEngine;
Expand All @@ -18,7 +20,7 @@ public class Tezos : ITezos
public WalletMessageReceiver MessageReceiver { get; }
public ITezosAPI API { get; }
public IWalletProvider Wallet { get; }
public IFA2 TokenContract { get; }
public IFA2 TokenContract { get; set; }

public Tezos()
{
Expand All @@ -27,16 +29,32 @@ public Tezos()
Wallet = new WalletProvider();

MessageReceiver = Wallet.MessageReceiver;

TokenContract = PlayerPrefs.HasKey("CurrentContract")
? new TokenContract(PlayerPrefs.GetString("CurrentContract"))
: new TokenContract();

MessageReceiver.AccountConnected += _ =>
{
TokenContract = PlayerPrefs.HasKey("CurrentContract:" + Wallet.GetActiveAddress())
? new TokenContract(PlayerPrefs.GetString("CurrentContract:" + Wallet.GetActiveAddress()))
: new TokenContract();
};
}

public IEnumerator GetCurrentWalletBalance(Action<ulong> callback)
{
var address = Wallet.GetActiveAddress();
return API.GetTezosBalance(callback, address);
}

public IEnumerator GetOriginatedContracts(Action<IEnumerable<TokenContract>> callback)
{
var codeHash = Resources.Load<TextAsset>("Contracts/FA2TokenContractCodeHash")
.text;

return API.GetOriginatedContractsForOwner(
callback: callback,
creator: Wallet.GetActiveAddress(),
codeHash: codeHash,
maxItems: 1000,
orderBy: new OriginatedContractsForOwnerOrder.ByLastActivityTimeDesc(0));
}
}
}
18 changes: 17 additions & 1 deletion Runtime/Scripts/Tezos/TezosSingleton.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Beacon.Sdk.Beacon.Permission;
using TezosSDK.DesignPattern.Singleton;
using TezosSDK.Helpers;
using TezosSDK.Tezos.API;
using TezosSDK.Tezos.API.Models;
using TezosSDK.Tezos.API.Models.Filters;
using TezosSDK.Tezos.API.Models.Abstract;
using TezosSDK.Tezos.Wallet;
using UnityEngine;
using Logger = TezosSDK.Helpers.Logger;


namespace TezosSDK.Tezos
Expand Down Expand Up @@ -39,5 +42,18 @@ public IEnumerator GetCurrentWalletBalance(Action<ulong> callback)
{
return _tezos.GetCurrentWalletBalance(callback);
}

public IEnumerator GetOriginatedContracts(Action<IEnumerable<TokenContract>> callback)
{
var codeHash = Resources.Load<TextAsset>("Contracts/FA2TokenContractCodeHash")
.text;

return _tezos.API.GetOriginatedContractsForOwner(
callback: callback,
creator: Wallet.GetActiveAddress(),
codeHash: codeHash,
maxItems: 1000,
orderBy: new OriginatedContractsForOwnerOrder.ByLastActivityTimeDesc(0));
}
}
}
Loading

0 comments on commit c2ee63b

Please sign in to comment.