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 @@ -33,10 +33,10 @@ public static void CleanUp()
/// <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>
Expand All @@ -49,10 +49,10 @@ public static SequenceLoginWindow OpenSequenceLoginWindow(Transform parent, IWal
/// <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>
Expand All @@ -64,10 +64,10 @@ public static SequencePlayerProfile OpenSequencePlayerProfile(Transform parent,
/// <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>
Expand All @@ -79,10 +79,10 @@ public static SequenceDailyRewards OpenSequenceDailyRewards(Transform parent, IW
/// <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>
Expand All @@ -96,11 +96,11 @@ public static SequenceInventory OpenSequenceInventory(Transform parent, IWallet
/// <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 +138,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 +160,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 readonly EmbeddedWalletAdapter _adapter = EmbeddedWalletAdapter.GetInstance();

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 Down Expand Up @@ -100,9 +100,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 +210,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 +247,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 +287,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,8 +19,8 @@ public class SequenceDailyRewards : MonoBehaviour
[SerializeField] private MessagePopup _messagePopup;
[SerializeField] private GenericObjectPool<SequenceDailyRewardTile> _tilePool;

private IWallet _wallet;
private Chain _chain;
private readonly EmbeddedWalletAdapter _adapter = EmbeddedWalletAdapter.GetInstance();

private string _apiUrl;
private Action _onClose;
private DailyRewardsStatusData _rewardsData;
Expand All @@ -41,10 +42,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 +97,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 +126,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
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
using System.Collections;
using System.Numerics;
using System.Threading.Tasks;
using Sequence.Adapter;
using Sequence.Contracts;
using Sequence.EmbeddedWallet;
using Sequence.Marketplace;
using Sequence.Pay;
using Sequence.Provider;
using Sequence.Utils;
using TMPro;
using UnityEngine;
using UnityEngine.Assertions;

namespace Sequence.Boilerplates.InGameShop
{
Expand All @@ -28,8 +26,8 @@ public class SequenceInGameShop : MonoBehaviour
[Header("Tile Object Pool")]
[SerializeField] private GenericObjectPool<SequenceInGameShopTile> _tilePool;

private IWallet _wallet;
private Chain _chain;
private readonly EmbeddedWalletAdapter _adapter = EmbeddedWalletAdapter.GetInstance();

private string _tokenContractAddress;
private string _saleContractAddress;
private int[] _itemsForSale;
Expand All @@ -54,11 +52,9 @@ public void Hide()
/// <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>
public void Show(IWallet wallet, Chain chain, string tokenContractAddress, string saleContractAddress,
public void Show(string tokenContractAddress, string saleContractAddress,
int[] itemsForSale, Action onClose = null)
{
_wallet = wallet;
_chain = chain;
_tokenContractAddress = tokenContractAddress;
_saleContractAddress = saleContractAddress;
_itemsForSale = itemsForSale;
Expand All @@ -69,23 +65,22 @@ public void Show(IWallet wallet, Chain chain, string tokenContractAddress, strin
_messagePopup.gameObject.SetActive(false);
_qrCodeView.gameObject.SetActive(false);

Assert.IsNotNull(_wallet, "Could not get a SequenceWallet reference from the UIPage.Open() arguments.");

RefreshState();
}

public async void OpenQrCodeView()
{
_qrCodeView.gameObject.SetActive(true);
var destinationAddress = _wallet.GetWalletAddress();
var destinationAddress = _adapter.Wallet.GetWalletAddress();
await _qrCodeView.Show(_saleState.PaymentToken, destinationAddress, "1e2");
}

public void OpenInventory()
{
SetLoading(true);
BoilerplateFactory.OpenSequenceInventory(transform.parent, _wallet, _chain,
new [] {_tokenContractAddress}, () => SetLoading(false));

var collections = new[] { _tokenContractAddress };
BoilerplateFactory.OpenSequenceInventory(transform.parent, collections, () => SetLoading(false));
}

public async void RefreshState()
Expand All @@ -98,8 +93,8 @@ public async void RefreshState()
await _saleState.Construct(
new Address(_saleContractAddress),
new Address(_tokenContractAddress),
_wallet,
_chain,
_adapter.Wallet,
_adapter.Chain,
_itemsForSale);

SetLoading(false);
Expand Down Expand Up @@ -150,17 +145,18 @@ private async Task PurchaseToken(BigInteger tokenId, int amount)

private async Task AdditionalCheckoutOptions(BigInteger tokenId, ulong amount)
{
var chain = _adapter.Chain;
ERC1155 collection = new ERC1155(_tokenContractAddress);
string uri = await collection.URI(new SequenceEthClient(_chain), tokenId);
string uri = await collection.URI(new SequenceEthClient(chain), tokenId);
Sprite collectibleImage = await AssetHandler.GetSpriteAsync(uri);
ERC1155Sale sale = new ERC1155Sale(_saleContractAddress);

ICheckoutHelper checkoutHelper = await ERC1155SaleCheckout.Create(sale,
new ERC1155(_tokenContractAddress), tokenId.ToString(), amount, _chain, _wallet,
new ERC1155(_tokenContractAddress), tokenId.ToString(), amount, chain, _adapter.Wallet,
"Demo Primary Sale Checkout", _paymentTokenIconUrl, collectibleImage);

BoilerplateFactory.OpenCheckoutPanel(transform.parent, _chain, checkoutHelper,
new SequenceCheckout(_wallet, _chain, sale, collection, tokenId.ToString(), amount));
BoilerplateFactory.OpenCheckoutPanel(transform.parent, chain, checkoutHelper,
new SequenceCheckout(_adapter.Wallet, chain, sale, collection, tokenId.ToString(), amount));
}

private void SetLoading(bool loading)
Expand Down
Loading