Skip to content

Commit 0812272

Browse files
YermekGImmutableJeffrey
authored andcommitted
feat: added application configuration utilities (#151)
* feat: added utilities to simplify managing immutable configurations * chore: added missing commets
1 parent 1d589a8 commit 0812272

File tree

7 files changed

+244
-0
lines changed

7 files changed

+244
-0
lines changed

Source/Immutable/Immutable.Build.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public Immutable(ReadOnlyTargetRules Target) : base(Target)
3333
"Json",
3434
"UMG",
3535
"Projects",
36+
"DeveloperSettings",
3637
}
3738
);
3839

Source/Immutable/Private/Immutable/ImmutablePassport.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "Immutable/ImtblJSConnector.h"
99
#include "JsonObjectConverter.h"
1010
#include "Immutable/ImmutableSaveGame.h"
11+
#include "Immutable/ImmutableUtilities.h"
1112
#include "Kismet/GameplayStatics.h"
1213
#include "Policies/CondensedJsonPrintPolicy.h"
1314

@@ -45,6 +46,36 @@ void UImmutablePassport::Initialize(const FImmutablePassportInitData& Data, cons
4546
CallJS(ImmutablePassportAction::INIT, InitData.ToJsonString(), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnInitializeResponse), false);
4647
}
4748

49+
void UImmutablePassport::Initialize(const FImtblPassportResponseDelegate& ResponseDelegate)
50+
{
51+
check(JSConnector.IsValid());
52+
53+
UApplicationConfig* ApplicationConfig = FImmutableUtilities::GetDefaultApplicationConfig();
54+
55+
if (!ApplicationConfig)
56+
{
57+
ResponseDelegate.ExecuteIfBound(FImmutablePassportResult{false, "Failed to retrieve default application configuration for Passport initialization"});
58+
59+
return;
60+
}
61+
62+
InitData.clientId = ApplicationConfig->GetClientID();
63+
InitData.environment = ApplicationConfig->GetEnvironment();
64+
InitData.redirectUri = ApplicationConfig->GetRedirectURL();
65+
InitData.logoutRedirectUri = ApplicationConfig->GetLogoutURL();
66+
67+
LoadPassportSettings();
68+
// we check saved settings in case if player has not logged out properly
69+
if (InitData.logoutRedirectUri.IsEmpty() && IsStateFlagsSet(IPS_PKCE))
70+
{
71+
IMTBL_ERR("Logout URI is empty. Previously logged in via PKCE.")
72+
ResetStateFlags(IPS_PKCE);
73+
SavePassportSettings();
74+
}
75+
76+
CallJS(ImmutablePassportAction::INIT, InitData.ToJsonString(), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnInitializeResponse), false);
77+
}
78+
4879
void UImmutablePassport::Connect(bool IsConnectImx, bool TryToRelogin, const FImtblPassportResponseDelegate& ResponseDelegate)
4980
{
5081
SetStateFlags(IPS_CONNECTING);

Source/Immutable/Private/Immutable/ImmutableUtilities.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "Immutable/ImmutableUtilities.h"
22

3+
#include "Immutable/ImmutablePluginSettings.h"
34
#include "Immutable/Misc/ImtblLogging.h"
45
#include "Interfaces/IPluginManager.h"
56
#include "Misc/FileHelper.h"
@@ -19,3 +20,15 @@ bool FImmutableUtilities::LoadGameBridge(FString& GameBridge)
1920

2021
return false;
2122
}
23+
24+
UApplicationConfig* FImmutableUtilities::GetDefaultApplicationConfig()
25+
{
26+
auto Settings = GetDefault<UImmutablePluginSettings>();
27+
28+
if (!Settings)
29+
{
30+
return nullptr;
31+
}
32+
33+
return Settings->DefaultApplicationConfig.GetDefaultObject();
34+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#pragma once
2+
3+
#include "ApplicationConfig.generated.h"
4+
5+
/**
6+
* @class UApplicationConfig
7+
* @brief Configuration settings for Passport and various APIs.
8+
* @details This class stores configuration settings such as URLs, chain names, contract addresses,
9+
* client IDs, and environment settings for the zkEVM API, Orderbook API, and Passport.
10+
*/
11+
UCLASS(Abstract, Blueprintable, ClassGroup = Immutable)
12+
class UApplicationConfig : public UObject
13+
{
14+
GENERATED_BODY()
15+
16+
public:
17+
/**
18+
* Retrieves URL for the zkEVM API.
19+
*
20+
* @return A constant reference to an FString containing the name of the chain.
21+
*/
22+
const FString& GetzkEVMAPIURL()
23+
{
24+
return zkEVMAPIURL;
25+
}
26+
27+
/**
28+
* Retrieves the name of the chain used to pass to the zkEVM API.
29+
*
30+
* @return A constant reference to an FString containing the name of the chain.
31+
*/
32+
const FString& GetzkEVMAPIChainName()
33+
{
34+
return zkEVMAPIChainName;
35+
}
36+
37+
/**
38+
* Retrieves URL for the Orderbook API.
39+
*
40+
* @return A constant reference to an FString containing the name of the chain.
41+
*/
42+
const FString& GetOrderbookAPIURL()
43+
{
44+
return OrederbookAPIURL;
45+
}
46+
47+
/**
48+
* Retrieves the name of the chain used to pass to the Orderbook API.
49+
*
50+
* @return A constant reference to an FString containing the name of the chain.
51+
*/
52+
const FString& GetOrderbookAPIChainName()
53+
{
54+
return OrderbookAPIChainName;
55+
}
56+
57+
/**
58+
* @brief Retrieves the cryptocurrency contract address associated with the user's wallet balance.
59+
*
60+
* @return A string representing the contract address.
61+
*/
62+
const FString& GetTokenBalanceContractAddress()
63+
{
64+
return TokenBalanceContractAddress;
65+
}
66+
67+
/**
68+
* Retrieves the list of NFT contracts used in the APIs' queries.
69+
*
70+
* @return A constant reference to an array of strings representing the contracts.
71+
*/
72+
const TArray<FString>& GetNFTContractAddresses()
73+
{
74+
return NFTContractAddress;
75+
}
76+
77+
/**
78+
* Retrieves the Client ID used for Passport initialization.
79+
*
80+
* @return A constant reference to an FString containing the Client ID.
81+
*/
82+
const FString& GetClientID()
83+
{
84+
return ClientID;
85+
}
86+
87+
/**
88+
* Retrieves the environment configuration used for Passport initialization.
89+
*
90+
* @return A constant reference to an FString representing the environment.
91+
*/
92+
const FString& GetEnvironment()
93+
{
94+
return Environment;
95+
}
96+
97+
/**
98+
* Retrieves the URL where the browser will redirect after successful authentication.
99+
* @note This is only used for Android, iOS, and macOS.
100+
*
101+
* @return A constant reference to an FString containing the redirect URL.
102+
*/
103+
const FString& GetRedirectURL()
104+
{
105+
return RedirectURL;
106+
}
107+
108+
/**
109+
* Retrieves the URL used for logging out.
110+
*
111+
* @return A constant reference to an FString containing the logout URL.
112+
*/
113+
const FString& GetLogoutURL()
114+
{
115+
return LogoutURL;
116+
}
117+
118+
protected:
119+
/** The URL for the zkEVM API. */
120+
UPROPERTY(EditDefaultsOnly, Category = "zkEVM API")
121+
FString zkEVMAPIURL;
122+
123+
/** The name of the API chain used by the zkEVM API. */
124+
UPROPERTY(EditDefaultsOnly, Category = "zkEVM API")
125+
FString zkEVMAPIChainName;
126+
127+
/** The URL for the Orderbook API. */
128+
UPROPERTY(EditDefaultsOnly, Category = "Orderbook API")
129+
FString OrederbookAPIURL;
130+
131+
/** The name of the API chain used by Orderbook API. */
132+
UPROPERTY(EditDefaultsOnly, Category = "Orderbook API")
133+
FString OrderbookAPIChainName;
134+
135+
/** The address of the cryptocurrency contract in the blockchain. */
136+
UPROPERTY(EditDefaultsOnly, Category = "Contracts")
137+
FString TokenBalanceContractAddress;
138+
139+
/** An array of NFT contract addresses used for searching NFTs in the marketplace or displaying them in the player's inventory. */
140+
UPROPERTY(EditDefaultsOnly, Category = "Contracts")
141+
TArray<FString> NFTContractAddress;
142+
143+
/** Passport Client ID. */
144+
UPROPERTY(EditDefaultsOnly, Category = "Passport")
145+
FString ClientID;
146+
147+
/** Environment used to initialize passport. Ex. sandbox or production */
148+
UPROPERTY(EditDefaultsOnly, Category = "Passport")
149+
FString Environment;
150+
151+
/**
152+
* (Android, iOS, and macOS only)
153+
* The URL where the browser will redirect after successful authentication.
154+
*/
155+
UPROPERTY(EditDefaultsOnly, Category = "Passport")
156+
FString RedirectURL;
157+
158+
/** The URL where the browser will redirect after logout is complete. */
159+
UPROPERTY(EditDefaultsOnly, Category = "Passport")
160+
FString LogoutURL;
161+
162+
};

Source/Immutable/Public/Immutable/ImmutablePassport.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ class IMMUTABLE_API UImmutablePassport : public UObject
8080
*/
8181
void Initialize(const FImmutablePassportInitData& InitData, const FImtblPassportResponseDelegate& ResponseDelegate);
8282

83+
/**
84+
* Initialises passport. This sets up the Passport instance, configures the web browser, and waits for the ready signal.
85+
* @details The functionality is the same with Initilize above except it obtains Passport initilization data from ApplicationConfig asset
86+
* @see UApplicationConfig
87+
*
88+
* @param ResponseDelegate Callback delegate.
89+
*/
90+
void Initialize(const FImtblPassportResponseDelegate& ResponseDelegate);
91+
8392
/**
8493
* Logs the user into Passport via device code auth and sets up the Immutable X provider.
8594
*
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
#include "Engine/DeveloperSettings.h"
4+
#include "ApplicationConfig.h"
5+
6+
#include "ImmutablePluginSettings.generated.h"
7+
8+
9+
/**
10+
* ImmutablePluginSettings is a configuration class for the Immutable plugin.
11+
* This class contains settings that can be adjusted to control the behavior
12+
* of the Immutable plugin within the Unreal Engine environment.
13+
*/
14+
UCLASS(config = Game, defaultconfig, meta = (DisplayName = "Immutable Plugin Settings"))
15+
class IMMUTABLE_API UImmutablePluginSettings : public UDeveloperSettings
16+
{
17+
GENERATED_BODY()
18+
19+
public:
20+
/// The default application configuration class.
21+
/// This property holds a reference to a subclass of UApplicationConfig,
22+
/// which will be used as the default configuration for the application.
23+
UPROPERTY(Config, EditAnywhere, BlueprintReadOnly, Category = "General")
24+
TSubclassOf<UApplicationConfig> DefaultApplicationConfig;
25+
};

Source/Immutable/Public/Immutable/ImmutableUtilities.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
2+
#include "ApplicationConfig.h"
23

34

45
/** A wrapper struct around various Immutable namespace utility and support methods. */
@@ -12,4 +13,6 @@ struct IMMUTABLE_API FImmutableUtilities
1213
* @return True if the game bridge content was sucessfully retrieved. Otherwise, false.
1314
*/
1415
static bool LoadGameBridge(FString& GameBridge);
16+
17+
static UApplicationConfig* GetDefaultApplicationConfig();
1518
};

0 commit comments

Comments
 (0)