diff --git a/Assets/Shared/Scripts/UI/MintScreen.cs b/Assets/Shared/Scripts/UI/MintScreen.cs index c13f50f8..7179fb53 100644 --- a/Assets/Shared/Scripts/UI/MintScreen.cs +++ b/Assets/Shared/Scripts/UI/MintScreen.cs @@ -5,6 +5,9 @@ using System; using System.Collections.Generic; using System.Threading; +using System.Net.Http; +using Immutable.Passport; +using Cysharp.Threading.Tasks; namespace HyperCasual.Runner { @@ -50,7 +53,7 @@ public void OnEnable() Mint(); } - private void Mint() + private async void Mint() { try { @@ -60,11 +63,15 @@ private void Mint() ShowNextButton(false); // Mint + bool mintedFox = await MintFox(); - ShowMintedMessage(); + if (mintedFox) + { + ShowMintedMessage(); + } ShowLoading(false); - ShowError(false); - ShowNextButton(true); + ShowError(!mintedFox); + ShowNextButton(mintedFox); } catch (Exception ex) { @@ -76,6 +83,42 @@ private void Mint() } } + /// + /// Gets the wallet address of the player. + /// + private async UniTask GetWalletAddress() + { + List accounts = await Passport.Instance.ZkEvmRequestAccounts(); + return accounts[0]; // Get the first wallet address + } + + /// + /// Mints a fox (i.e. Immutable Runner Fox) to the player's wallet + /// + /// True if minted a fox successfully to player's wallet. Otherwise, false. + private async UniTask MintFox() + { + Debug.Log("Minting fox..."); + // Get the player's wallet address to mint the fox to + string address = await GetWalletAddress(); + + if (address != null) + { + var nvc = new List> + { + // Set 'to' to the player's wallet address + new KeyValuePair("to", address) + }; + using var client = new HttpClient(); + string url = $"http://localhost:3000/mint/fox"; // Endpoint to mint a fox + using var req = new HttpRequestMessage(HttpMethod.Post, url) { Content = new FormUrlEncodedContent(nvc) }; + using var res = await client.SendAsync(req); + return res.IsSuccessStatusCode; + } + + return false; + } + private void OnNextButtonClicked() { m_NextEvent.Raise(); diff --git a/Assets/Shared/Scripts/UI/SetupWalletScreen.cs b/Assets/Shared/Scripts/UI/SetupWalletScreen.cs index 13a27153..b8722cc5 100644 --- a/Assets/Shared/Scripts/UI/SetupWalletScreen.cs +++ b/Assets/Shared/Scripts/UI/SetupWalletScreen.cs @@ -76,7 +76,7 @@ private async void SetupWallet() private void OnNextButtonClicked() { - m_NextEvent.Raise(); + m_MintEvent.Raise(); } private void ShowNextButton(bool show)