Skip to content
This repository was archived by the owner on Feb 12, 2026. It is now read-only.

Commit f0f8da3

Browse files
committed
create immutable X sample game
1 parent 4e46334 commit f0f8da3

9 files changed

Lines changed: 371 additions & 348 deletions

File tree

Assets/Shared/Scripts/UI/LevelCompleteScreen.cs

Lines changed: 7 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
using System;
77
using System.Collections.Generic;
88
using Immutable.Passport;
9-
using Cysharp.Threading.Tasks;
10-
using System.Numerics;
11-
using System.Net.Http;
129

1310
namespace HyperCasual.Runner
1411
{
@@ -106,7 +103,7 @@ public int CoinCount
106103
}
107104
}
108105

109-
public async void OnEnable()
106+
public void OnEnable()
110107
{
111108
// Set listener to 'Next' button
112109
m_NextButton.RemoveListener(OnNextButtonClicked);
@@ -120,79 +117,10 @@ public async void OnEnable()
120117
m_TryAgainButton.RemoveListener(OnTryAgainButtonClicked);
121118
m_TryAgainButton.AddListener(OnTryAgainButtonClicked);
122119

123-
ShowError(false);
124-
ShowLoading(false);
125-
126-
// If player is logged into Passport mint coins to player
127-
if (SaveManager.Instance.IsLoggedIn)
128-
{
129-
// Mint collected coins to player
130-
await MintCoins();
131-
}
132-
else
133-
{
134-
// Show 'Next' button if player is already logged into Passport
135-
ShowNextButton(SaveManager.Instance.IsLoggedIn);
136-
// Show "Continue with Passport" button if the player is not logged into Passport
137-
ShowContinueWithPassportButton(!SaveManager.Instance.IsLoggedIn);
138-
}
139-
}
140-
141-
/// <summary>
142-
/// Mints collected coins (i.e. Immutable Runner Token) to the player's wallet
143-
/// </summary>
144-
private async UniTask MintCoins()
145-
{
146-
// This function is similar to MintCoins() in MintScreen.cs. Consider refactoring duplicate code in production.
147-
Debug.Log("Minting coins...");
148-
bool success = false;
149-
150-
// Show loading
151-
ShowLoading(true);
152-
ShowNextButton(false);
153-
ShowError(false);
154-
155-
try
156-
{
157-
// Don't mint any coins if player did not collect any
158-
if (m_CoinCount == 0)
159-
{
160-
success = true;
161-
}
162-
else
163-
{
164-
// Get the player's wallet address to mint the coins to
165-
List<string> accounts = await Passport.Instance.ZkEvmRequestAccounts();
166-
string address = accounts[0];
167-
if (address != null)
168-
{
169-
// Calculate the quantity to mint
170-
// Need to take into account Immutable Runner Token decimal value i.e. 18
171-
BigInteger quantity = BigInteger.Multiply(new BigInteger(m_CoinCount), BigInteger.Pow(10, 18));
172-
Debug.Log($"Quantity: {quantity}");
173-
var nvc = new List<KeyValuePair<string, string>>
174-
{
175-
// Set 'to' to the player's wallet address
176-
new KeyValuePair<string, string>("to", address),
177-
// Set 'quanity' to the number of coins collected
178-
new KeyValuePair<string, string>("quantity", quantity.ToString())
179-
};
180-
using var client = new HttpClient();
181-
string url = $"http://localhost:3000/mint/token"; // Endpoint to mint token
182-
using var req = new HttpRequestMessage(HttpMethod.Post, url) { Content = new FormUrlEncodedContent(nvc) };
183-
using var res = await client.SendAsync(req);
184-
success = res.IsSuccessStatusCode;
185-
}
186-
}
187-
}
188-
catch (Exception ex)
189-
{
190-
Debug.Log($"Failed to mint coins: {ex.Message}");
191-
}
192-
193-
ShowLoading(false);
194-
ShowNextButton(success);
195-
ShowError(!success);
120+
// Show 'Next' button if player is already logged into Passport
121+
ShowNextButton(SaveManager.Instance.IsLoggedIn);
122+
// Show "Continue with Passport" button if the player is not logged into Passport
123+
ShowContinueWithPassportButton(!SaveManager.Instance.IsLoggedIn);
196124
}
197125

198126
private async void OnContinueWithPassportButtonClicked()
@@ -204,11 +132,7 @@ private async void OnContinueWithPassportButtonClicked()
204132
ShowLoading(true);
205133

206134
// Log into Passport
207-
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
208-
await Passport.Instance.LoginPKCE();
209-
#else
210135
await Passport.Instance.Login();
211-
#endif
212136

213137
// Successfully logged in
214138
// Save a persistent flag in the game that the player is logged in
@@ -228,9 +152,8 @@ private async void OnContinueWithPassportButtonClicked()
228152
}
229153
}
230154

231-
private async void OnTryAgainButtonClicked()
155+
private void OnTryAgainButtonClicked()
232156
{
233-
await MintCoins();
234157
}
235158

236159
private void OnNextButtonClicked()
@@ -287,4 +210,4 @@ void DisplayCoins(int count)
287210
}
288211
}
289212
}
290-
}
213+
}

Assets/Shared/Scripts/UI/MainMenu.cs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,7 @@ async void OnEnable()
4040
// Initialise Passport
4141
string clientId = "YOUR_IMMUTABLE_CLIENT_ID";
4242
string environment = Immutable.Passport.Model.Environment.SANDBOX;
43-
string redirectUri = null;
44-
string logoutUri = null;
45-
46-
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
47-
redirectUri = "immutablerunner://callback";
48-
logoutUri = "immutablerunner://logout";
49-
#endif
50-
passport = await Passport.Init(clientId, environment, redirectUri, logoutUri);
43+
passport = await Passport.Init(clientId, environment);
5144

5245
// Check if the player is supposed to be logged in and if there are credentials saved
5346
if (SaveManager.Instance.IsLoggedIn && await Passport.Instance.HasCredentialsSaved())
@@ -56,20 +49,20 @@ async void OnEnable()
5649
bool success = await Passport.Instance.Login(useCachedSession: true);
5750
// Update the login flag
5851
SaveManager.Instance.IsLoggedIn = success;
52+
5953
// Set up wallet if successful
6054
if (success)
6155
{
62-
await Passport.Instance.ConnectEvm();
63-
await Passport.Instance.ZkEvmRequestAccounts();
56+
await Passport.Instance.ConnectImx();
6457
}
65-
}
66-
else
67-
{
58+
} else {
6859
// No saved credentials to re-login the player, reset the login flag
6960
SaveManager.Instance.IsLoggedIn = false;
7061
}
7162

7263
ShowLoading(false);
64+
ShowStartButton(true);
65+
7366
// Show the logout button if the player is logged in
7467
ShowLogoutButton(SaveManager.Instance.IsLoggedIn);
7568
}
@@ -95,11 +88,7 @@ async void OnLogoutButtonClick()
9588
ShowLoading(true);
9689

9790
// Logout
98-
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
99-
await passport.LogoutPKCE();
100-
#else
10191
await passport.Logout();
102-
#endif
10392

10493
// Reset the login flag
10594
SaveManager.Instance.IsLoggedIn = false;

0 commit comments

Comments
 (0)