Skip to content
Open
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
2 changes: 1 addition & 1 deletion Assets/SequenceSDK/Authentication/Tests/MockLogin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void TryToRestoreSession()

}

public void GuestLogin()
public Task GuestLogin()
{
throw new System.NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void TryToRestoreSession()

}

public void GuestLogin()
public Task GuestLogin()
{
throw new System.NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,77 +30,68 @@ public static void CleanUp()
/// Open the Login UI Boilerplate from a Prefab inside the Resources folder.
/// </summary>
/// <param name="parent">Transform inside of a Canvas object.</param>
/// <param name="wallet">Wallet to use for account federation.</param>
/// <param name="onClose">(Optional) Callback when the user closes this window or when an account was successfully federated.</param>
/// <returns></returns>
public static SequenceLoginWindow OpenSequenceLoginWindow(Transform parent, IWallet wallet = null, Action onClose = null)
public static SequenceLoginWindow OpenSequenceLoginWindow(Transform parent, Action onClose = null)
{
return GetOrSpawnBoilerplate<SequenceLoginWindow>("Login/SequenceLoginWindow", parent,
b => b.Show(wallet, onClose));
b => b.Show(onClose));
}

/// <summary>
/// Open the Player Profile UI Boilerplate from a Prefab inside the Resources folder.
/// </summary>
/// <param name="parent">Transform inside of a Canvas object.</param>
/// <param name="wallet">This Wallet instance will perform transactions.</param>
/// <param name="chain">Chain used to get balances and send transactions.</param>
/// <param name="currency">Define a custom ERC20 currency. Leave it null to use the chains native token.</param>
/// <param name="currencySymbol">The symbol of your custom currency, such as 'ETH'.</param>
/// <param name="onClose">(Optional) Callback when the user closes this window.</param>
/// <returns>Instance of SequencePlayerProfile which was instantiated as a child of <paramref name="parent"/></returns>
public static SequencePlayerProfile OpenSequencePlayerProfile(Transform parent, IWallet wallet, Chain chain, Address currency = null, string currencySymbol = null, Action onClose = null)
public static SequencePlayerProfile OpenSequencePlayerProfile(Transform parent, Address currency = null, string currencySymbol = null, Action onClose = null)
{
return GetOrSpawnBoilerplate<SequencePlayerProfile>("PlayerProfile/SequencePlayerProfile", parent,
b => b.Show(wallet, chain, currency, currencySymbol, onClose));
b => b.Show(currency, currencySymbol, onClose));
}

/// <summary>
/// Open the Daily Rewards UI Boilerplate from a Prefab inside the Resources folder.
/// </summary>
/// <param name="parent">Transform inside of a Canvas object.</param>
/// <param name="wallet">This Wallet instance will perform transactions.</param>
/// <param name="chain">Chain used to get balances and send transactions.</param>
/// <param name="apiUrl">API Url you deployed using the server boilerplate.</param>
/// <param name="onClose">(Optional) Callback when the user closes this window.</param>
/// <returns>Instance of SequenceDailyRewards which was instantiated as a child of <paramref name="parent"/></returns>
public static SequenceDailyRewards OpenSequenceDailyRewards(Transform parent, IWallet wallet, Chain chain, string apiUrl, Action onClose = null)
public static SequenceDailyRewards OpenSequenceDailyRewards(Transform parent, string apiUrl, Action onClose = null)
{
return GetOrSpawnBoilerplate<SequenceDailyRewards>("DailyRewards/SequenceDailyRewards", parent,
b => b.Show(wallet, chain, apiUrl, onClose));
b => b.Show(apiUrl, onClose));
}

/// <summary>
/// Open the Inventory UI Boilerplate from a Prefab inside the Resources folder.
/// </summary>
/// <param name="parent">Transform inside of a Canvas object.</param>
/// <param name="wallet">This Wallet instance will perform transactions.</param>
/// <param name="chain">Chain used to get balances and send transactions.</param>
/// <param name="collections">The inventory will show items from these contracts.</param>
/// <param name="onClose">(Optional) Callback when the user closes this window.</param>
/// <returns>Instance of SequenceInventory which was instantiated as a child of <paramref name="parent"/></returns>
public static SequenceInventory OpenSequenceInventory(Transform parent, IWallet wallet, Chain chain, string[] collections, Action onClose = null)
public static SequenceInventory OpenSequenceInventory(Transform parent, string[] collections, Action onClose = null)
{
return GetOrSpawnBoilerplate<SequenceInventory>("Inventory/SequenceInventory", parent,
b => b.Show(wallet, chain, collections, onClose));
b => b.Show(collections, onClose));
}

/// <summary>
/// Open the In-Game Shop UI Boilerplate from a Prefab inside the Resources folder.
/// </summary>
/// <param name="parent">Transform inside of a Canvas object.</param>
/// <param name="wallet">This Wallet instance will perform transactions.</param>
/// <param name="chain">Chain used to get balances and send transactions.</param>
/// <param name="tokenContractAddress">ERC1155 Contract you deployed on Sequence's Builder.</param>
/// <param name="saleContractAddress">ERC1155 Sale Contract you deployed on Sequence's Builder.</param>
/// <param name="itemsForSale">Define the token Ids you want to sell from your collection.</param>
/// <param name="onClose">(Optional) Callback when the user closes this window.</param>
/// <returns>Instance of SequenceInGameShop which was instantiated as a child of <paramref name="parent"/></returns>
public static SequenceInGameShop OpenSequenceInGameShop(Transform parent, IWallet wallet, Chain chain,
string tokenContractAddress, string saleContractAddress, int[] itemsForSale, Action onClose = null)
public static SequenceInGameShop OpenSequenceInGameShop(Transform parent, string tokenContractAddress,
string saleContractAddress, int[] itemsForSale, Action onClose = null)
{
return GetOrSpawnBoilerplate<SequenceInGameShop>("InGameShop/SequenceInGameShop", parent,
b => b.Show(wallet, chain, tokenContractAddress, saleContractAddress, itemsForSale, onClose));
b => b.Show(tokenContractAddress, saleContractAddress, itemsForSale, onClose));
}

/// <summary>
Expand Down Expand Up @@ -138,9 +129,7 @@ public static ListItemPage OpenListItemPanel(Transform parent, ICheckout checkou
{
return GetOrSpawnBoilerplate<ListItemPage>("Checkout/ListItemPanel", parent, b => b.Open(checkout, item));
}




public static CreateOfferPage OpenCreateOfferPanel(Transform parent, ICheckout checkout, TokenBalance item, Action onClose = null)
{
return GetOrSpawnBoilerplate<CreateOfferPage>("Checkout/CreateOfferPanel", parent, b => b.Open(checkout, item));
Expand All @@ -162,10 +151,10 @@ public static SellOfferPage OpenSellOfferPanel(Transform parent, ICheckout check
/// <param name="chain">Chain used to get balances and send transactions.</param>
/// <param name="onClose">(Optional) Callback when the user closes this window.</param>
/// <returns>Instance of SequenceSignMessage which was instantiated as a child of <paramref name="parent"/></returns>
public static SequenceSignMessage OpenSequenceSignMessage(Transform parent, IWallet wallet, Chain chain, Action onClose = null)
public static SequenceSignMessage OpenSequenceSignMessage(Transform parent, Action onClose = null)
{
return GetOrSpawnBoilerplate<SequenceSignMessage>("SignMessage/SequenceSignMessage", parent,
b => b.Show(wallet, chain, onClose));
b => b.Show(onClose));
}

private static T GetOrSpawnBoilerplate<T>(string path, Transform parent, Action<T> show) where T : MonoBehaviour
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using Sequence.Adapter;
using Sequence.Boilerplates.Login;
using Sequence.Boilerplates.PlayerProfile;
using Sequence.Contracts;
Expand Down Expand Up @@ -30,7 +31,8 @@ public class BoilerplateController : MonoBehaviour
[SerializeField] private string _marketplaceDescription = "Browse and interact with listings on a Peer-to-Peer, Secondary Sales marketplace.";
[SerializeField] private string _checkoutDescription = "Buy an ERC1155 token via a Primary Sales contract using the Checkout Panel - pay with crypto or fiat.";

private IWallet _wallet;
private EmbeddedWalletAdapter _adapter;

private SequenceLoginWindow _loginWindow;
private SequencePlayerProfile _playerProfile;
private Chain _chain;
Expand All @@ -40,10 +42,8 @@ public class BoilerplateController : MonoBehaviour

private void Awake()
{
SequenceWallet.OnFailedToRecoverSession += OnFailedToRecoverSession;
SequenceWallet.OnWalletCreated += wallet =>
{
_wallet = wallet;
ShowDefaultWindow();

if (_loginWindow)
Expand All @@ -60,6 +60,8 @@ private void Awake()
}
};
};

_adapter = EmbeddedWalletAdapter.GetInstance();
}

private void Start()
Expand Down Expand Up @@ -100,9 +102,8 @@ private async void TryRecoverSessionToOpenLoginWindow()
{
HideFeatureSelection();

var loginHandler = SequenceLogin.GetInstance();
var (storageEnabled, wallet) = await loginHandler.TryToRestoreSessionAsync();
if (!storageEnabled)
var recovered = await _adapter.TryRecoverWalletFromStorage();
if (!recovered)
OnFailedToRecoverSession("Secure storage is disabled");
}

Expand Down Expand Up @@ -211,32 +212,32 @@ private void ShowPrimarySaleButton(PrimarySaleConfig sale)
private void OpenPlayerProfilePanel()
{
HideFeatureSelection();
_playerProfile = BoilerplateFactory.OpenSequencePlayerProfile(transform, _wallet, _chain, new Address("0x85acb5646a9d73952347174ef928c2c9a174156f"), "STB", ShowDefaultWindow);
_playerProfile = BoilerplateFactory.OpenSequencePlayerProfile(transform, new Address("0x85acb5646a9d73952347174ef928c2c9a174156f"), "STB", ShowDefaultWindow);
}

private void OpenDailyRewardsPanel()
{
HideFeatureSelection();
BoilerplateFactory.OpenSequenceDailyRewards(transform, _wallet, _chain, _config.rewardsApi, ShowDefaultWindow);
BoilerplateFactory.OpenSequenceDailyRewards(transform, _config.rewardsApi, ShowDefaultWindow);
}

private void OpenInventoryPanel()
{
HideFeatureSelection();
BoilerplateFactory.OpenSequenceInventory(transform, _wallet, _chain, _config.collections, ShowDefaultWindow);
BoilerplateFactory.OpenSequenceInventory(transform, _config.collections, ShowDefaultWindow);
}

private void OpenInGameShopPanel(PrimarySaleConfig sale)
{
HideFeatureSelection();
BoilerplateFactory.OpenSequenceInGameShop(transform, _wallet, _chain, sale.collectionAddress,
BoilerplateFactory.OpenSequenceInGameShop(transform, sale.collectionAddress,
sale.saleAddress, sale.itemsForSale, ShowDefaultWindow);
}

private void OpenSignMessage()
{
HideFeatureSelection();
BoilerplateFactory.OpenSequenceSignMessage(transform, _wallet, _chain, ShowDefaultWindow);
BoilerplateFactory.OpenSequenceSignMessage(transform, ShowDefaultWindow);
}

public void OpenCheckoutPanel(ICheckoutHelper checkoutHelper, IFiatCheckout fiatCheckout)
Expand All @@ -248,7 +249,7 @@ public void OpenCheckoutPanel(ICheckoutHelper checkoutHelper, IFiatCheckout fiat
public void OpenViewMarketplaceListingsPage()
{
HideFeatureSelection();
BoilerplateFactory.OpenViewMarketplaceListingsPanel(transform, _wallet, _marketplaceChain, new Address(_marketplaceCollectionAddress), ShowDefaultWindow);
BoilerplateFactory.OpenViewMarketplaceListingsPanel(transform, _adapter.Wallet, _marketplaceChain, new Address(_marketplaceCollectionAddress), ShowDefaultWindow);
}

public void OpenCheckoutPanel()
Expand Down Expand Up @@ -288,13 +289,13 @@ private async void DoShowCheckoutPanel()
string imageUrl = metadata.image.Replace(".webp", ".png");
Sprite collectibleImage = await AssetHandler.GetSpriteAsync(imageUrl);
ICheckoutHelper checkoutHelper = await ERC1155SaleCheckout.Create(saleContract, collection, "1", 1, Chain.Polygon,
_wallet, "Demo Token Sale",
_adapter.Wallet, "Demo Token Sale",
"https://cryptologos.cc/logos/usd-coin-usdc-logo.png",
collectibleImage);

HideLoadingScreen();
BoilerplateFactory.OpenCheckoutPanel(transform, _chain, checkoutHelper,
new SequenceCheckout(_wallet, Chain.Polygon, saleContract, collection, "1", 1), ShowDefaultWindow);
new SequenceCheckout(_adapter.Wallet, Chain.Polygon, saleContract, collection, "1", 1), ShowDefaultWindow);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Sequence.Adapter;
using Sequence.EmbeddedWallet;
using Sequence.Utils;
using UnityEngine;
Expand All @@ -18,13 +19,18 @@ public class SequenceDailyRewards : MonoBehaviour
[SerializeField] private MessagePopup _messagePopup;
[SerializeField] private GenericObjectPool<SequenceDailyRewardTile> _tilePool;

private IWallet _wallet;
private Chain _chain;
private EmbeddedWalletAdapter _adapter;

private string _apiUrl;
private Action _onClose;
private DailyRewardsStatusData _rewardsData;
private Dictionary<string, TokenSupply[]> _supplies;

private void Awake()
{
_adapter = EmbeddedWalletAdapter.GetInstance();
}

/// <summary>
/// This function is called when the user clicks the close button.
/// </summary>
Expand All @@ -41,10 +47,8 @@ public void Hide()
/// <param name="chain">Chain used to get balances and send transactions.</param>
/// <param name="apiUrl">API Url you deployed using the server boilerplate.</param>
/// <param name="onClose">(Optional) Callback when the user closes this window.</param>
public void Show(IWallet wallet, Chain chain, string apiUrl, Action onClose = null)
public void Show(string apiUrl, Action onClose = null)
{
_wallet = wallet;
_chain = chain;
_apiUrl = apiUrl;
_onClose = onClose;
gameObject.SetActive(true);
Expand Down Expand Up @@ -98,8 +102,8 @@ private async Task<bool> CallRewardsAsync(string method)
var request = UnityWebRequest.Get(_apiUrl);
request.method = method;

var idToken = await _wallet.GetIdToken();
request.SetRequestHeader("Authorization", $"Bearer {idToken.IdToken}");
var idToken = await _adapter.GetIdToken();
request.SetRequestHeader("Authorization", $"Bearer {idToken}");

try
{
Expand Down Expand Up @@ -127,7 +131,7 @@ private async Task<bool> CallRewardsAsync(string method)
.Distinct()
.ToArray());

var indexer = new ChainIndexer(_chain);
var indexer = new ChainIndexer(_adapter.Chain);
var args = new GetTokenSuppliesMapArgs
{
tokenMap = dict,
Expand Down
Loading