diff --git a/Assets/SequenceSDK/Authentication/Tests/MockLogin.cs b/Assets/SequenceSDK/Authentication/Tests/MockLogin.cs index d6d49c9a3..0af1e5914 100644 --- a/Assets/SequenceSDK/Authentication/Tests/MockLogin.cs +++ b/Assets/SequenceSDK/Authentication/Tests/MockLogin.cs @@ -91,7 +91,7 @@ public void TryToRestoreSession() } - public void GuestLogin() + public Task GuestLogin() { throw new System.NotImplementedException(); } diff --git a/Assets/SequenceSDK/Authentication/Tests/MockLoginCustomEventTiming.cs b/Assets/SequenceSDK/Authentication/Tests/MockLoginCustomEventTiming.cs index 717b38dc3..2a6cd6895 100644 --- a/Assets/SequenceSDK/Authentication/Tests/MockLoginCustomEventTiming.cs +++ b/Assets/SequenceSDK/Authentication/Tests/MockLoginCustomEventTiming.cs @@ -80,7 +80,7 @@ public void TryToRestoreSession() } - public void GuestLogin() + public Task GuestLogin() { throw new System.NotImplementedException(); } diff --git a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/BoilerplateFactory.cs b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/BoilerplateFactory.cs index 5865f87f2..b3e4c30c7 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/BoilerplateFactory.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/BoilerplateFactory.cs @@ -33,10 +33,10 @@ public static void CleanUp() /// Wallet to use for account federation. /// (Optional) Callback when the user closes this window or when an account was successfully federated. /// - public static SequenceLoginWindow OpenSequenceLoginWindow(Transform parent, IWallet wallet = null, Action onClose = null) + public static SequenceLoginWindow OpenSequenceLoginWindow(Transform parent, Action onClose = null) { return GetOrSpawnBoilerplate("Login/SequenceLoginWindow", parent, - b => b.Show(wallet, onClose)); + b => b.Show(onClose)); } /// @@ -49,10 +49,10 @@ public static SequenceLoginWindow OpenSequenceLoginWindow(Transform parent, IWal /// The symbol of your custom currency, such as 'ETH'. /// (Optional) Callback when the user closes this window. /// Instance of SequencePlayerProfile which was instantiated as a child of - 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("PlayerProfile/SequencePlayerProfile", parent, - b => b.Show(wallet, chain, currency, currencySymbol, onClose)); + b => b.Show(currency, currencySymbol, onClose)); } /// @@ -64,10 +64,10 @@ public static SequencePlayerProfile OpenSequencePlayerProfile(Transform parent, /// API Url you deployed using the server boilerplate. /// (Optional) Callback when the user closes this window. /// Instance of SequenceDailyRewards which was instantiated as a child of - 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("DailyRewards/SequenceDailyRewards", parent, - b => b.Show(wallet, chain, apiUrl, onClose)); + b => b.Show(apiUrl, onClose)); } /// @@ -79,10 +79,10 @@ public static SequenceDailyRewards OpenSequenceDailyRewards(Transform parent, IW /// The inventory will show items from these contracts. /// (Optional) Callback when the user closes this window. /// Instance of SequenceInventory which was instantiated as a child of - 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("Inventory/SequenceInventory", parent, - b => b.Show(wallet, chain, collections, onClose)); + b => b.Show(collections, onClose)); } /// @@ -96,11 +96,11 @@ public static SequenceInventory OpenSequenceInventory(Transform parent, IWallet /// Define the token Ids you want to sell from your collection. /// (Optional) Callback when the user closes this window. /// Instance of SequenceInGameShop which was instantiated as a child of - 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("InGameShop/SequenceInGameShop", parent, - b => b.Show(wallet, chain, tokenContractAddress, saleContractAddress, itemsForSale, onClose)); + b => b.Show(tokenContractAddress, saleContractAddress, itemsForSale, onClose)); } /// @@ -138,9 +138,7 @@ public static ListItemPage OpenListItemPanel(Transform parent, ICheckout checkou { return GetOrSpawnBoilerplate("Checkout/ListItemPanel", parent, b => b.Open(checkout, item)); } - - - + public static CreateOfferPage OpenCreateOfferPanel(Transform parent, ICheckout checkout, TokenBalance item, Action onClose = null) { return GetOrSpawnBoilerplate("Checkout/CreateOfferPanel", parent, b => b.Open(checkout, item)); @@ -162,10 +160,10 @@ public static SellOfferPage OpenSellOfferPanel(Transform parent, ICheckout check /// Chain used to get balances and send transactions. /// (Optional) Callback when the user closes this window. /// Instance of SequenceSignMessage which was instantiated as a child of - public static SequenceSignMessage OpenSequenceSignMessage(Transform parent, IWallet wallet, Chain chain, Action onClose = null) + public static SequenceSignMessage OpenSequenceSignMessage(Transform parent, Action onClose = null) { return GetOrSpawnBoilerplate("SignMessage/SequenceSignMessage", parent, - b => b.Show(wallet, chain, onClose)); + b => b.Show(onClose)); } private static T GetOrSpawnBoilerplate(string path, Transform parent, Action show) where T : MonoBehaviour diff --git a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/Common/BoilerplateController.cs b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/Common/BoilerplateController.cs index 787401fd4..52eaae982 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/Common/BoilerplateController.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/Common/BoilerplateController.cs @@ -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; @@ -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; @@ -40,10 +42,8 @@ public class BoilerplateController : MonoBehaviour private void Awake() { - SequenceWallet.OnFailedToRecoverSession += OnFailedToRecoverSession; SequenceWallet.OnWalletCreated += wallet => { - _wallet = wallet; ShowDefaultWindow(); if (_loginWindow) @@ -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"); } @@ -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) @@ -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() @@ -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); } } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/DailyRewards/SequenceDailyRewards.cs b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/DailyRewards/SequenceDailyRewards.cs index a5bb9b4e1..c81520150 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/DailyRewards/SequenceDailyRewards.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/DailyRewards/SequenceDailyRewards.cs @@ -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; @@ -18,8 +19,8 @@ public class SequenceDailyRewards : MonoBehaviour [SerializeField] private MessagePopup _messagePopup; [SerializeField] private GenericObjectPool _tilePool; - private IWallet _wallet; - private Chain _chain; + private readonly EmbeddedWalletAdapter _adapter = EmbeddedWalletAdapter.GetInstance(); + private string _apiUrl; private Action _onClose; private DailyRewardsStatusData _rewardsData; @@ -41,10 +42,8 @@ public void Hide() /// Chain used to get balances and send transactions. /// API Url you deployed using the server boilerplate. /// (Optional) Callback when the user closes this window. - 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); @@ -98,8 +97,8 @@ private async Task 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 { @@ -127,7 +126,7 @@ private async Task CallRewardsAsync(string method) .Distinct() .ToArray()); - var indexer = new ChainIndexer(_chain); + var indexer = new ChainIndexer(_adapter.Chain); var args = new GetTokenSuppliesMapArgs { tokenMap = dict, diff --git a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/InGameShop/SequenceInGameShop.cs b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/InGameShop/SequenceInGameShop.cs index 323d2d3da..0e11cc15c 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/InGameShop/SequenceInGameShop.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/InGameShop/SequenceInGameShop.cs @@ -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 { @@ -28,8 +26,8 @@ public class SequenceInGameShop : MonoBehaviour [Header("Tile Object Pool")] [SerializeField] private GenericObjectPool _tilePool; - private IWallet _wallet; - private Chain _chain; + private readonly EmbeddedWalletAdapter _adapter = EmbeddedWalletAdapter.GetInstance(); + private string _tokenContractAddress; private string _saleContractAddress; private int[] _itemsForSale; @@ -54,11 +52,9 @@ public void Hide() /// ERC1155 Sale Contract you deployed on Sequence's Builder. /// Define the token Ids you want to sell from your collection. /// (Optional) Callback when the user closes this window. - 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; @@ -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() @@ -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); @@ -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) diff --git a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/Inventory/SequenceInventory.cs b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/Inventory/SequenceInventory.cs index 1e90f6e55..29c32bbf8 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/Inventory/SequenceInventory.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/Inventory/SequenceInventory.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using Sequence.Adapter; using Sequence.EmbeddedWallet; using Sequence.Utils; using TMPro; @@ -27,8 +28,8 @@ public class SequenceInventory : MonoBehaviour [SerializeField] private GenericObjectPool _messagePool; [SerializeField] private GenericObjectPool _tilePool; - private IWallet _wallet; - private Chain _chain; + private readonly EmbeddedWalletAdapter _adapter = EmbeddedWalletAdapter.GetInstance(); + private string[] _collections; private Action _onClose; private TokenBalance _selectedBalance; @@ -49,10 +50,8 @@ public void Hide() /// Chain used to get balances and send transactions. /// The inventory will show items from these contracts. /// (Optional) Callback when the user closes this window. - public void Show(IWallet wallet, Chain chain, string[] collections, Action onClose = null) + public void Show(string[] collections, Action onClose = null) { - _wallet = wallet; - _chain = chain; _collections = collections; _onClose = onClose; gameObject.SetActive(true); @@ -74,7 +73,7 @@ public void SetOverviewState() public void OpenListingPanel() { - BoilerplateFactory.OpenListItemPanel(transform, new Sequence.Marketplace.Checkout(_wallet, _chain), _selectedBalance); + BoilerplateFactory.OpenListItemPanel(transform, new Sequence.Marketplace.Checkout(_adapter.Wallet, _adapter.Chain), _selectedBalance); } public async void SendToken() @@ -102,19 +101,21 @@ public async void SendToken() _loadingScreen.SetActive(true); var metadata = _selectedBalance.tokenMetadata; - var response = await _wallet.SendTransaction(_chain, new Transaction[] { - new SendERC1155(metadata.contractAddress, recipient, new [] - { - new SendERC1155Values(metadata.tokenId.ToString(), amountInput) - }) - }); + var recipientAddress = new Address(recipient); + var contractAddress = new Address(metadata.contractAddress); + var tokenId = metadata.tokenId.ToString(); + + try + { + await _adapter.SendToken(recipientAddress, amount, contractAddress, tokenId); + _messagePopup.Show("Sent successfully."); + } + catch (Exception ex) + { + _messagePopup.Show(ex.Message, true); + } _loadingScreen.SetActive(false); - - if (response is FailedTransactionReturn failed) - _messagePopup.Show(failed.error, true); - else if (response is SuccessfulTransactionReturn) - _messagePopup.Show("Sent successfully."); } private async void LoadAllCollections() @@ -123,7 +124,7 @@ private async void LoadAllCollections() _tilePool.Cleanup(); foreach (var collection in _collections) - await LoadCollection(collection); + await LoadCollection(new Address(collection)); var empty = _tilePool.Parent.childCount == 0; _messageList.SetActive(empty); @@ -134,13 +135,11 @@ private async void LoadAllCollections() _messagePool.GetObject(); } - private async Task LoadCollection(string collection) + private async Task LoadCollection(Address collection) { - var indexer = new ChainIndexer(_chain); - var args = new GetTokenBalancesArgs(_wallet.GetWalletAddress(), collection, true); - var response = await indexer.GetTokenBalances(args); + var balances = await _adapter.GetMyTokenBalances(collection); - foreach (var balance in response.balances) + foreach (var balance in balances) _tilePool.GetObject().Load(balance, () => ShowToken(balance)); } diff --git a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/Login/SequenceLoginWindow.cs b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/Login/SequenceLoginWindow.cs index 040431a1f..9b04a4fb1 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/Login/SequenceLoginWindow.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/Login/SequenceLoginWindow.cs @@ -1,6 +1,6 @@ using System; -using System.Collections; -using System.Collections.Generic; +using System.Threading.Tasks; +using Sequence.Adapter; using Sequence.Authentication; using Sequence.EmbeddedWallet; using TMPro; @@ -25,9 +25,9 @@ public class SequenceLoginWindow : MonoBehaviour [SerializeField] private MessagePopup _messagePopup; [SerializeField] private GameObject[] _socialTexts; - private IWallet _wallet; + private readonly EmbeddedWalletAdapter _adapter = EmbeddedWalletAdapter.GetInstance(); + private Action _onClose; - private SequenceLogin _loginHandler; private string _curEmail; private void Start() @@ -47,13 +47,6 @@ private void OnDisable() SequenceWallet.OnAccountFederationFailed -= AccountFederationFailed; } - private void OnDestroy() - { - _loginHandler.OnLoginSuccess -= LoginHandlerOnOnLoginSuccess; - _loginHandler.OnLoginFailed -= LoginHandlerOnOnLoginFailed; - _loginHandler.OnMFAEmailSent -= LoginHandlerOnOnMFAEmailSent; - } - /// /// This function is called when the user clicks the close button. /// @@ -66,22 +59,11 @@ public void Hide() /// /// Required function to configure this Boilerplate. /// - public void Show(IWallet wallet = null, Action onClose = null) + public void Show(Action onClose = null) { - _wallet = wallet; _onClose = onClose; - if (_loginHandler == null) - { - _loginHandler = SequenceLogin.GetInstance(); - _loginHandler.OnLoginSuccess += LoginHandlerOnOnLoginSuccess; - _loginHandler.OnLoginFailed += LoginHandlerOnOnLoginFailed; - _loginHandler.OnMFAEmailSent += LoginHandlerOnOnMFAEmailSent; - } - - if (wallet != null) - _loginHandler.SetConnectedWalletAddress(wallet.GetWalletAddress()); - var isFederating = _wallet != null; + var isFederating = _adapter.Wallet != null; _closeButton.gameObject.SetActive(isFederating); _guestLoginButton.gameObject.SetActive(!isFederating); @@ -91,6 +73,7 @@ public void Show(IWallet wallet = null, Action onClose = null) _emailCodeState.SetActive(false); _emailInput.text = string.Empty; _emailCodeErrorText.text = string.Empty; + EnableEmailButton(true); VerifyEmailInput(string.Empty); HandleSocialIconState(); @@ -99,32 +82,49 @@ public void Show(IWallet wallet = null, Action onClose = null) public void LoginWithEmail() { - SetLoading(true); - _loginHandler.Login(_curEmail); + HandleAsyncLogin(_adapter.EmailLogin(_curEmail), + () => LoginHandlerOnOnMFAEmailSent(), + () => SetLoading(false)); } public void VerifyEmailCode() { - SetLoading(true); - _loginHandler.Login(_curEmail, _emailCodeInput.text); + HandleAsyncLogin(_adapter.ConfirmEmailCode(_curEmail, _emailCodeInput.text), + () => LoginHandlerOnOnLoginSuccess(), + () => LoginHandlerOnOnLoginFailed(LoginMethod.Email)); } public void LoginWithGoogle() { - SetLoading(true); - _loginHandler.GoogleLogin(); + HandleAsyncLogin(_adapter.GoogleLogin(), + () => LoginHandlerOnOnLoginSuccess(), + () => LoginHandlerOnOnLoginFailed(LoginMethod.Google)); } public void LoginWithApple() { - SetLoading(true); - _loginHandler.AppleLogin(); + HandleAsyncLogin(_adapter.AppleLogin(), + () => LoginHandlerOnOnLoginSuccess(), + () => LoginHandlerOnOnLoginFailed(LoginMethod.Apple)); } public void LoginAsGuest() + { + HandleAsyncLogin(_adapter.GuestLogin(), + () => LoginHandlerOnOnLoginSuccess(), + () => LoginHandlerOnOnLoginFailed(LoginMethod.Guest)); + } + + private async void HandleAsyncLogin(Task task, Action onSuccess, Action onFailure) { SetLoading(true); - _loginHandler.GuestLogin(); + var result = await task; + SetLoading(false); + + if (result) + onSuccess?.Invoke(); + else + onFailure?.Invoke(); } public void EnableEmailButton(bool enable) @@ -162,28 +162,27 @@ private void SetLoading(bool loading) _loadingOverlay.SetActive(loading); } - private void LoginHandlerOnOnMFAEmailSent(string email) + private void LoginHandlerOnOnMFAEmailSent() { SetLoading(false); _loginState.SetActive(false); _emailCodeState.SetActive(true); } - private void LoginHandlerOnOnLoginSuccess(string sessionid, string walletaddress) + private void LoginHandlerOnOnLoginSuccess() { SetLoading(false); } - private void LoginHandlerOnOnLoginFailed(string error, LoginMethod method, string email, List loginmethods) + private void LoginHandlerOnOnLoginFailed(LoginMethod method) { - Debug.LogError($"Error during login: {error}"); SetLoading(false); _emailCodeInput.text = string.Empty; if (method == LoginMethod.Email) _emailCodeErrorText.text = "Invalid code."; else - _messagePopup.Show(error, true); + _messagePopup.Show($"Failed to login.", true); } private void AccountFederationFailed(string error) @@ -198,21 +197,10 @@ private void AccountFederated(Account account) Debug.Log($"Account federated, email: {account.email}"); Hide(); } - + private void OnApplicationFocus(bool hasFocus) { -#if !UNITY_IOS if (hasFocus) - { - StartCoroutine(DisableLoadingScreenIfNotLoggingIn()); - } -#endif - } - - private IEnumerator DisableLoadingScreenIfNotLoggingIn() - { - yield return new WaitForSecondsRealtime(0.1f); - if (!_loginHandler.IsLoggingIn()) SetLoading(false); } } diff --git a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/PlayerProfile/SequencePlayerProfile.cs b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/PlayerProfile/SequencePlayerProfile.cs index 0170db608..131939715 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/PlayerProfile/SequencePlayerProfile.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/PlayerProfile/SequencePlayerProfile.cs @@ -1,5 +1,6 @@ using System; using System.Numerics; +using Sequence.Adapter; using Sequence.EmbeddedWallet; using Sequence.Utils; using TMPro; @@ -23,9 +24,10 @@ public class SequencePlayerProfile : MonoBehaviour [SerializeField] private GenericObjectPool _transactionPool; [SerializeField] private GenericObjectPool _walletsPool; - private IWallet _wallet; - private Chain _chain; + private readonly EmbeddedWalletAdapter _adapter = EmbeddedWalletAdapter.GetInstance(); + private Action _onClose; + private Address _currency; private EOAWalletLinker _walletLinker; /// @@ -44,21 +46,20 @@ public void Hide() /// Chain used to get balances and send transactions. /// Define a custom ERC20 currency. Leave it null to use the chains native token. /// (Optional) Callback when the user closes this window. - public async void Show(IWallet wallet, Chain chain, Address currency = null, string currencySymbol = null, Action onClose = null) + public async void Show(Address currency = null, string currencySymbol = null, Action onClose = null) { - _wallet = wallet; - _chain = chain; _onClose = onClose; + _currency = currency ?? Address.ZeroAddress; gameObject.SetActive(true); _transactionPool.Cleanup(); SetOverviewState(); SetBalance(0, string.Empty); - var indexer = new ChainIndexer(_chain); - var walletAddress = _wallet.GetWalletAddress(); + var indexer = new ChainIndexer(_adapter.Chain); + var walletAddress = _adapter.WalletAddress; - if (currency == null) + if (_currency.IsZeroAddress()) { var balanceResponse = await indexer.GetNativeTokenBalance(walletAddress); SetNativeBalance(balanceResponse.balanceWei); @@ -80,21 +81,21 @@ public async void Show(IWallet wallet, Chain chain, Address currency = null, str public void CopyWalletAddress() { - GUIUtility.systemCopyBuffer = _wallet.GetWalletAddress(); + GUIUtility.systemCopyBuffer = _adapter.WalletAddress; _messagePopup.Show("Copied"); } public async void SignOut() { EnableLoading(true); - await _wallet.DropThisSession(); + await _adapter.SignOut(); EnableLoading(false); } public void OpenLoginWindowForFederation() { gameObject.SetActive(false); - BoilerplateFactory.OpenSequenceLoginWindow(transform.parent, _wallet, + BoilerplateFactory.OpenSequenceLoginWindow(transform.parent, () => gameObject.SetActive(true)); } @@ -102,6 +103,7 @@ public async void SendToken() { var recipient = _recipientInput.text; var input = _tokenAmountInput.text; + if (!uint.TryParse(input, out uint t)) { _messagePopup.Show("Invalid amount.", true); @@ -109,21 +111,23 @@ public async void SendToken() } EnableLoading(true); - var response = await _wallet.SendTransaction(_chain, new Transaction[] { - new RawTransaction(recipient, t.ToString()) - }); - - EnableLoading(false); - if (response is FailedTransactionReturn failed) - _messagePopup.Show(failed.error, true); - else if (response is SuccessfulTransactionReturn) + try + { + await _adapter.SendToken(recipient, t, _currency); _messagePopup.Show("Sent successfully."); + } + catch (Exception ex) + { + _messagePopup.Show(ex.Message, true); + } + + EnableLoading(false); } public async void LinkExternalWallet() { - await new EOAWalletLinker(_wallet, _chain).OpenEoaWalletLink(); + await new EOAWalletLinker(_adapter.Wallet, _adapter.Chain).OpenEoaWalletLink(); } public void SetOverviewState() @@ -137,7 +141,7 @@ public void SetOverviewState() public async void SetReceiveState() { _receiveState.SetActive(true); - await _qrImage.Show(_wallet.GetWalletAddress()); + await _qrImage.Show(_adapter.WalletAddress); } private void EnableLoading(bool enable) @@ -147,8 +151,8 @@ private void EnableLoading(bool enable) private async void LoadTransactionHistory() { - var walletAddress = _wallet.GetWalletAddress(); - var indexer = new ChainIndexer(_chain); + var walletAddress = _adapter.WalletAddress; + var indexer = new ChainIndexer(_adapter.Chain); var filter = new TransactionHistoryFilter {accountAddress = walletAddress}; var response = await indexer.GetTransactionHistory(new GetTransactionHistoryArgs(filter)); @@ -163,7 +167,7 @@ private async void LoadTransactionHistory() private async void LoadLinkedWallets() { _walletsPool.Cleanup(); - _walletLinker = new EOAWalletLinker(_wallet, _chain); + _walletLinker = new EOAWalletLinker(_adapter.Wallet, _adapter.Chain); var linkedWallets = await _walletLinker.GetLinkedWallets(); if (linkedWallets.Length == 0) @@ -181,7 +185,7 @@ private async void UnlinkWallet(LinkedWalletData wallet) private void SetNativeBalance(BigInteger balance) { - var symbol = ChainDictionaries.GasCurrencyOf[_chain]; + var symbol = ChainDictionaries.GasCurrencyOf[_adapter.Chain]; SetBalance(balance, symbol); } diff --git a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/SignMessage/SequenceSignMessage.cs b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/SignMessage/SequenceSignMessage.cs index bce4726d8..94ae62270 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/SignMessage/SequenceSignMessage.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/Scripts/SignMessage/SequenceSignMessage.cs @@ -1,5 +1,5 @@ using System; -using Sequence.EmbeddedWallet; +using Sequence.Adapter; using TMPro; using UnityEngine; using UnityEngine.UI; @@ -16,8 +16,8 @@ public class SequenceSignMessage : MonoBehaviour [SerializeField] private MessagePopup _messagePopup; [SerializeField] private string _initSignatureText; - private IWallet _wallet; - private Chain _chain; + private readonly EmbeddedWalletAdapter _adapter = EmbeddedWalletAdapter.GetInstance(); + private Action _onClose; private string _curInput; private string _curSignature; @@ -41,15 +41,10 @@ public void Hide() /// /// Required function to configure this Boilerplate. /// - /// This Wallet instance will perform transactions. - /// Chain used to get balances and send transactions. /// (Optional) Callback when the user closes this window. - public void Show(IWallet wallet, Chain chain, Action onClose = null) + public void Show(Action onClose = null) { - _wallet = wallet; - _chain = chain; _onClose = onClose; - gameObject.SetActive(true); _messagePopup.gameObject.SetActive(false); _messageInput.text = string.Empty; @@ -58,7 +53,7 @@ public void Show(IWallet wallet, Chain chain, Action onClose = null) private async void SignMessage() { - _curSignature = await _wallet.SignMessage(_chain, _curInput); + _curSignature = await _adapter.SignMessage(_curInput); _signatureText.text = _curSignature; _copyButton.interactable = true; } diff --git a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/SequenceBoilerplates.asmdef b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/SequenceBoilerplates.asmdef index dfeb1ff8b..c1662e691 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/SequenceBoilerplates.asmdef +++ b/Packages/Sequence-Unity/Sequence/SequenceBoilerplates/SequenceBoilerplates.asmdef @@ -10,7 +10,8 @@ "GUID:b4f9c0f8f363f439b9e337f79050f189", "GUID:403077141e1554429a890cbc129df651", "GUID:a67bc3d548bec4971b914c7b64c9e959", - "GUID:19b9eb7db56cc47349571a4fbb0dd677" + "GUID:19b9eb7db56cc47349571a4fbb0dd677", + "GUID:03d0ed9c50cfd4cb28a56d2d06580ffa" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter.meta b/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter.meta new file mode 100644 index 000000000..784342f5a --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2fbda8d3e94840b497881679b1ee831b +timeCreated: 1750351968 \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter/EmbeddedWalletAdapter.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter/EmbeddedWalletAdapter.cs new file mode 100644 index 000000000..db29f4f7e --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter/EmbeddedWalletAdapter.cs @@ -0,0 +1,313 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using System.Threading.Tasks; +using NUnit.Framework; +using Sequence.Authentication; +using Sequence.EmbeddedWallet; +using Sequence.Marketplace; +using Sequence.Utils; + +namespace Sequence.Adapter +{ + public class EmbeddedWalletAdapter : IEmbeddedWalletAdapter, IDisposable + { + private static EmbeddedWalletAdapter _instance; + + private IWallet _wallet; + public IWallet Wallet + { + get + { + EnsureWalletReferenceExists(); + return _wallet; + } + set => _wallet = value; + } + + public Address WalletAddress { get; private set; } + + private SequenceLogin _loginHandler; + private SequenceLogin LoginHandler + { + get + { + if (_loginHandler != null) + return _loginHandler; + + _loginHandler = SequenceLogin.GetInstance(); + _loginHandler.OnLoginSuccess += OnOnLoginSuccess; + _loginHandler.OnMFAEmailSent += OnOnMFAEmailSent; + _loginHandler.OnLoginFailed += OnLoginFailed; + _loginHandler.OnMFAEmailFailedToSend += OnOnMFAEmailFailedToSend; + + return _loginHandler; + } + } + + private Chain _chain; + public Chain Chain + { + get => _chain; + set + { + _chain = value; + _indexer = new ChainIndexer(_chain); + _swap = new CurrencySwap(_chain); + _marketplace = new MarketplaceReader(_chain); + } + } + + private ChainIndexer _indexer; + private CurrencySwap _swap; + private MarketplaceReader _marketplace; + private Checkout _checkout; + private bool _isLoggingIn; + private bool _isError; + + public static EmbeddedWalletAdapter GetInstance() + { + if (_instance != null) + return _instance; + + _instance = new EmbeddedWalletAdapter(); + _instance.Chain = Chain.TestnetArbitrumSepolia; + + return _instance; + } + + public EmbeddedWalletAdapter() + { + SequenceWallet.OnWalletCreated += UpdateWallet; + SequenceWallet.OnAccountFederated += AccountFederated; + SequenceWallet.OnAccountFederationFailed += AccountFederationFailed; + } + + public void Dispose() + { + SequenceWallet.OnWalletCreated -= UpdateWallet; + SequenceWallet.OnAccountFederated -= AccountFederated; + SequenceWallet.OnAccountFederationFailed -= AccountFederationFailed; + } + + public async Task TryRecoverWalletFromStorage() + { + var result = await LoginHandler.TryToRestoreSessionAsync(); + if (!result.StorageEnabled || result.Wallet == null) + return false; + + Wallet = result.Wallet; + return true; + } + + public async Task EmailLogin(string email) + { + SetLoginResult(true, false); + await LoginHandler.Login(email); + return !_isError; + } + + public async Task ConfirmEmailCode(string email, string code) + { + SetLoginResult(true, false); + await LoginHandler.Login(email, code); + return !_isError; + } + + public async Task GuestLogin() + { + SetLoginResult(true, false); + await LoginHandler.GuestLogin(); + return !_isError; + } + + public async Task GoogleLogin() + { + SetLoginResult(true, false); + LoginHandler.GoogleLogin(); + await WaitForLoginProcess(); + return !_isError; + } + + public async Task AppleLogin() + { + SetLoginResult(true, false); + LoginHandler.AppleLogin(); + await WaitForLoginProcess(); + return !_isError; + } + + public async Task SignOut() + { + var result = await _wallet.DropThisSession(); + if (result) + LoginHandler.RemoveConnectedWalletAddress(); + + return result; + } + + public async Task GetIdToken() + { + var response = await Wallet.GetIdToken(); + return response.IdToken; + } + + public Task SignMessage(string message) + { + return _wallet.SignMessage(_chain, message); + } + + public async Task GetMyNativeTokenBalance() + { + var result = await _indexer.GetNativeTokenBalance(Wallet.GetWalletAddress()); + return result.balanceWei; + } + + public async Task GetMyTokenBalances(string tokenAddress) + { + var args = new GetTokenBalancesArgs(Wallet.GetWalletAddress(), tokenAddress, true); + var result = await _indexer.GetTokenBalances(args); + return result.balances; + } + + public async Task GetTokenSupplies(string tokenAddress) + { + var args = new GetTokenSuppliesArgs(tokenAddress, true); + var result = await _indexer.GetTokenSupplies(args); + return result.tokenIDs; + } + + public async Task SendToken(string recipientAddress, BigInteger amount, string tokenAddress = null, string tokenId = null) + { + EnsureWalletReferenceExists(); + + Transaction transaction = null; + if (tokenAddress == null || (tokenAddress.IsAddress() && tokenAddress.IsZeroAddress())) + { + transaction = new RawTransaction(recipientAddress, amount.ToString()); + } + else + { + var suppliesArgs = new GetTokenSuppliesArgs(tokenAddress, true); + var supplies = await _indexer.GetTokenSupplies(suppliesArgs); + + transaction = supplies.contractType switch + { + ContractType.ERC20 => new SendERC20(tokenAddress, recipientAddress, amount.ToString()), + ContractType.ERC1155 => new SendERC1155(tokenAddress, recipientAddress, + new SendERC1155Values[] { new(tokenId, amount.ToString()) }), + ContractType.ERC721 => new SendERC721(tokenAddress, recipientAddress, tokenId), + _ => throw new Exception("Unknown contract type") + }; + } + + return await SendTransaction(new[] { transaction }); + } + + public async Task SwapToken(string sellToken, string buyToken, BigInteger buyAmount) + { + var walletAddress = Wallet.GetWalletAddress(); + var quote = await _swap.GetSwapQuote(walletAddress, new Address(buyToken), + new Address(sellToken), buyAmount.ToString(), true); + + return await SendTransaction(new Transaction[] + { + new RawTransaction(sellToken, string.Empty, quote.approveData), + new RawTransaction(quote.to, quote.transactionValue, quote.transactionData), + } + ); + } + + public async Task GetAllListingsFromMarketplace(string collectionAddress) + { + return await _marketplace.ListAllCollectibleListingsWithLowestPricedListingsFirst(collectionAddress); + } + + public async Task CreateListingOnMarketplace(string contractAddress, string currencyAddress, + string tokenId, BigInteger amount, BigInteger pricePerToken, DateTime expiry) + { + EnsureWalletReferenceExists(); + var steps = await _checkout.GenerateListingTransaction(new Address(contractAddress), tokenId, amount, + Marketplace.ContractType.ERC20, new Address(currencyAddress), pricePerToken, expiry); + + var transactions = steps.AsTransactionArray(); + return await SendTransaction(transactions); + } + + public async Task PurchaseOrderFromMarketplace(Order order, BigInteger amount) + { + EnsureWalletReferenceExists(); + var steps = await _checkout.GenerateBuyTransaction(order, amount); + var transactions = steps.AsTransactionArray(); + return await SendTransaction(transactions); + } + + private async Task SendTransaction(Transaction[] transactions) + { + var transactionResult = await Wallet.SendTransaction(_chain, transactions); + return transactionResult switch + { + SuccessfulTransactionReturn success => success.receipt.txnReceipt, + FailedTransactionReturn failed => throw new Exception($"Failed transaction {failed.error}"), + _ => throw new Exception("Unknown error while sending transaction.") + }; + } + + private async Task WaitForLoginProcess() + { + while (_isLoggingIn) + await Task.Yield(); + } + + private void OnLoginFailed(string error, LoginMethod method, string email, List loginMethods) + { + SetLoginResult(false, true); + } + + private void OnOnMFAEmailFailedToSend(string email, string error) + { + SetLoginResult(false, true); + + } + + private void OnOnMFAEmailSent(string email) + { + SetLoginResult(false, false); + } + + private void OnOnLoginSuccess(string sessionId, string walletAddress) + { + SetLoginResult(false, false); + } + + private void AccountFederated(Account obj) + { + SetLoginResult(false, false); + } + + private void AccountFederationFailed(string obj) + { + SetLoginResult(false, true); + } + + private void SetLoginResult(bool isLoggingIn, bool isError) + { + _isError = isError; + _isLoggingIn = isLoggingIn; + } + + private void UpdateWallet(IWallet wallet) + { + Wallet = wallet; + WalletAddress = wallet.GetWalletAddress(); + + _checkout = new Checkout(wallet, _chain); + LoginHandler.SetConnectedWalletAddress(wallet.GetWalletAddress()); + } + + private void EnsureWalletReferenceExists() + { + Assert.IsNotNull(Wallet, "Please sign in first. For example, call 'new SequenceQuickstart().GuestLogin();'"); + } + } +} \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter/EmbeddedWalletAdapter.cs.meta b/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter/EmbeddedWalletAdapter.cs.meta new file mode 100644 index 000000000..3f665db39 --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter/EmbeddedWalletAdapter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: da7ded03c99be413e8cc8f4cb9456807 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter/IEmbeddedWalletAdapter.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter/IEmbeddedWalletAdapter.cs new file mode 100644 index 000000000..f92e150d1 --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter/IEmbeddedWalletAdapter.cs @@ -0,0 +1,149 @@ +using System; +using System.Numerics; +using System.Threading.Tasks; +using Sequence.EmbeddedWallet; +using Sequence.Marketplace; + +namespace Sequence.Adapter +{ + public interface IEmbeddedWalletAdapter + { + public Chain Chain { get; } + + /// + /// The underlying Sequence Embedded Wallet reference. Use it for more control, such as transaction batches. + /// + public IWallet Wallet { get; } + + /// + /// Address of the current wallet. Returns a Zero Address if not wallet is available. + /// + public Address WalletAddress { get; } + + // ONBOARDING + + /// + /// Recover a wallet from secure storage. + /// + /// 'true' if a stored wallet was found or 'false' if not or if session recovery is disabled in your SequenceConfig file. + Task TryRecoverWalletFromStorage(); + + /// + /// Login using Email OTP. You will receive a code to your email. Use it with the 'ConfirmEmailCode' function to finish the login process. + /// + /// Email of the given user. + /// + Task EmailLogin(string email); + + /// + /// You receive a code after calling 'EmailLogin'. Use it with this function to complete the login process. + /// + /// + /// + /// + Task ConfirmEmailCode(string email, string code); + + /// + /// Login as a guest. When the user uninstall the application, they lose access to a guest wallet, unless they use our Account Federation feature to link the guest wallet to another login option. + /// + /// + Task GuestLogin(); + + /// + /// Sign In with Google. The user is redirected to an external browser. + /// + Task GoogleLogin(); + + /// + /// Sign In with Apple. The user is redirected to an external browser. On iOS, this function uses the native Sign In SDK. + /// + Task AppleLogin(); + + Task SignOut(); + + /// + /// Get an id token as a JWT you can use to verify the user on your backend. Use any JWKS library to verify this token. + /// + /// JWT Id Token + Task GetIdToken(); + + // POWER + + /// + /// Signs a given message. + /// + /// Message string to sign + /// Signature of the given message + Task SignMessage(string message); + + /// + /// Get the native token balance for your local user. For example, the native token on the Ethereum Mainnet is the amount of 'ETH' + /// + /// Balance in wei. + Task GetMyNativeTokenBalance(); + + /// + /// Get the token balances for your local user. + /// + /// Address of your token contract. This could be an ERC20, ERC1155, or ERC721 contract you deployed on https//sequence.build/ + /// Balance in wei and the token metadata. + Task GetMyTokenBalances(string tokenAddress); + + /// + /// + /// + /// + /// + Task GetTokenSupplies(string tokenAddress); + + /// + /// Send any ERC20, ERC1155 or ERC721 token to another wallet. + /// + /// The address of the wallet you want to send the token to. + /// The address of your token. For example one you have deployed through https://sequence.build/ + /// Leave it blank for ERC20 contracts. + /// Leave it blank for ERC721 contracts. + /// Transaction receipt used to check transaction information onchain. + /// + Task SendToken(string recipientAddress, BigInteger amount, string tokenAddress = null, string tokenId = null); + + // MONETIZATION + + /// + /// Swap one of your tokens to another one. Make sure you have configured enough liquidity on a DEX such as UniSwap. + /// + /// + /// + /// + /// + Task SwapToken(string sellToken, string buyToken, BigInteger buyAmount); + + /// + /// Get all listings from your Marketplace on a given collection. Please make sure you have configured your Marketplace on https://sequence.build/ + /// + /// + /// + Task GetAllListingsFromMarketplace(string collectionAddress); + + /// + /// Create a listing for a given token you own. Please make sure you have configured your Marketplace on https://sequence.build/ + /// + /// + /// + /// + /// + /// + /// + /// + Task CreateListingOnMarketplace(string contractAddress, string currencyAddress, + string tokenId, BigInteger amount, BigInteger pricePerToken, DateTime expiry); + + /// + /// Purchase an order from your Marketplace. Please make sure you have configured your Marketplace on https://sequence.build/ + /// + /// The order as returned from the 'GetAllListingsFromMarketplace' function. + /// The amount of orders you wish to purchase. + /// + Task PurchaseOrderFromMarketplace(Order order, BigInteger amount); + } +} \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter/IEmbeddedWalletAdapter.cs.meta b/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter/IEmbeddedWalletAdapter.cs.meta new file mode 100644 index 000000000..c935552eb --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter/IEmbeddedWalletAdapter.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 56129c265d66491ba5529d572d6ac2e0 +timeCreated: 1750401684 \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter/SequenceAdapter.asmdef b/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter/SequenceAdapter.asmdef new file mode 100644 index 000000000..3e434670a --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter/SequenceAdapter.asmdef @@ -0,0 +1,24 @@ +{ + "name": "SequenceAdapter", + "rootNamespace": "Sequence.Adapter", + "references": [ + "GUID:a35e3a53d4439435f8b36ed2c6158cd8", + "GUID:4e0a798abbda240658187632ae443a67", + "GUID:f7fd4ba36aabd1d499450c174865e70b", + "GUID:b4f9c0f8f363f439b9e337f79050f189", + "GUID:f78a27d6a73d94c4baf04337e0add4dc", + "GUID:403077141e1554429a890cbc129df651", + "GUID:19b9eb7db56cc47349571a4fbb0dd677", + "GUID:a67bc3d548bec4971b914c7b64c9e959", + "GUID:94b67778c44684afdab21990eebf60aa" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter/SequenceAdapter.asmdef.meta b/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter/SequenceAdapter.asmdef.meta new file mode 100644 index 000000000..566183831 --- /dev/null +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Adapter/SequenceAdapter.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 03d0ed9c50cfd4cb28a56d2d06580ffa +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/ILogin.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/ILogin.cs index 927ab6cee..2763f4c30 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/ILogin.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/Authentication/ILogin.cs @@ -95,7 +95,7 @@ public interface ILogin /// /// Login as a guest /// - public void GuestLogin(); + public Task GuestLogin(); /// /// Login with PlayFab diff --git a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SequenceLogin.cs b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SequenceLogin.cs index 293e82933..d3aabbaef 100644 --- a/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SequenceLogin.cs +++ b/Packages/Sequence-Unity/Sequence/SequenceSDK/EmbeddedWallet/SequenceLogin.cs @@ -229,9 +229,9 @@ public void TryToRestoreSession() TryToLoginWithStoredSessionWallet(); } - public void GuestLogin() + public async Task GuestLogin() { - ConnectToWaaSAsGuest(); + await ConnectToWaaSAsGuest(); } private void SetupAuthenticatorAndListeners()