Skip to content

Commit c531182

Browse files
feat: marketplace swap sample widget (#3532)
1 parent d072f0c commit c531182

File tree

5 files changed

+34
-21
lines changed

5 files changed

+34
-21
lines changed
File renamed without changes.
Binary file not shown.
Binary file not shown.

Source/Immutable/Private/Immutable/Marketplace/ImtblSwapRequest.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,24 @@
44

55
FString FImtblSwapRequestQueryParams::GetPercentEncodedUrl() const
66
{
7-
return FString::Printf
8-
(
9-
TEXT("%s=%s&%s=%s&%s=%s"),
10-
TEXT("publishableKey"), *FGenericPlatformHttp::UrlEncode(PublishableKey),
11-
TEXT("fromTokenAddress"), *FGenericPlatformHttp::UrlEncode(FromTokenAddress),
12-
TEXT("toTokenAddress"), *FGenericPlatformHttp::UrlEncode(ToTokenAddress)
13-
);
7+
TArray<FString> QueryParams;
8+
9+
if (!PublishableKey.IsEmpty())
10+
{
11+
QueryParams.Add(FString::Printf(TEXT("%s=%s"), TEXT("publishableKey"), *FGenericPlatformHttp::UrlEncode(PublishableKey)));
12+
}
13+
14+
if (!FromTokenAddress.IsEmpty())
15+
{
16+
QueryParams.Add(FString::Printf(TEXT("%s=%s"), TEXT("fromTokenAddress"), *FGenericPlatformHttp::UrlEncode(FromTokenAddress)));
17+
}
18+
19+
if (!ToTokenAddress.IsEmpty())
20+
{
21+
QueryParams.Add(FString::Printf(TEXT("%s=%s"), TEXT("toTokenAddress"), *FGenericPlatformHttp::UrlEncode(ToTokenAddress)));
22+
}
23+
24+
return FString::Join(QueryParams, TEXT("&"));
1425
}
1526

1627
bool UImtblSwapRequest::GetBaseUrl(EImtblEnvironment Environment, FString& BaseUrl) const
@@ -37,7 +48,7 @@ bool UImtblSwapRequest::GetApiKey(EImtblEnvironment Environment, FString& ApiKey
3748
return false;
3849
}
3950

40-
bool UImtblSwapRequest::ComputePath(EImtblEnvironment Environment, FString FromTokenAddress, FString ToTokenAddress, FString& ComputedPath) const
51+
bool UImtblSwapRequest::ComputePath(FString& ComputedPath, EImtblEnvironment Environment, FString FromTokenAddress, FString ToTokenAddress) const
4152
{
4253
FString BaseUrl;
4354
bool bFoundBaseUrl = GetBaseUrl(Environment, BaseUrl);
@@ -64,8 +75,10 @@ bool UImtblSwapRequest::ComputePath(EImtblEnvironment Environment, FString FromT
6475

6576
ComputedPath = FString::Printf
6677
(
67-
TEXT("%s?%s"),
68-
*BaseUrl, *QueryParamsPercentEncodedUrl
78+
TEXT("%s%s%s"),
79+
*BaseUrl,
80+
!QueryParamsPercentEncodedUrl.IsEmpty() ? TEXT("?") : TEXT(""),
81+
*QueryParamsPercentEncodedUrl
6982
);
7083

7184
return true;

Source/Immutable/Public/Immutable/Marketplace/ImtblSwapRequest.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ struct FImtblSwapRequestQueryParams
2929
/**
3030
* Functionality to generate swap requests
3131
*/
32-
// UCLASS(BlueprintType, Config = "Immutable", DefaultConfig)
33-
UCLASS(BlueprintType, Config = "Immutable")
32+
UCLASS(BlueprintType, Config = "Immutable", DefaultConfig)
3433
class IMMUTABLE_API UImtblSwapRequest : public UObject
3534
{
3635
GENERATED_BODY()
@@ -39,7 +38,7 @@ class IMMUTABLE_API UImtblSwapRequest : public UObject
3938
/**
4039
* Finds the base url associated with the environment.
4140
*
42-
* @param Environment The environment that will be used to look the value up.
41+
* @param Environment The environment that will be used to look the value up. Only sandbox and production environment are supported.
4342
* @param BaseUrl The base url associated with the key.
4443
* @return True if an item was found (False indicates nothing in the map uses the provided environment).
4544
*/
@@ -49,24 +48,25 @@ class IMMUTABLE_API UImtblSwapRequest : public UObject
4948
/**
5049
* Finds the api key associated with the provided key.
5150
*
52-
* @param Environment The environment that will be used to look the value up.
51+
* @param Environment The environment that will be used to look the value up. Only sandbox and production environment are supported.
5352
* @param ApiKey The api key associated with the key.
5453
* @return True if an item was found (False indicates nothing in the map uses the provided environment).
5554
*/
5655
UFUNCTION(BlueprintPure, Category = "Immutable")
5756
bool GetApiKey(EImtblEnvironment Environment, FString& ApiKey) const;
5857

5958
/**
60-
* Generates a path link for the swap flow.
59+
* Generates a link for the swap flow.
6160
*
62-
* @param Environment The environment that will be used to compute the path.
63-
* @param ToTokenAddress The address of the token being swapped from. Also known as the token contract address.
64-
* @param FromTokenAddress The address of the token being swapped to. Also known as the token contract address.
65-
* @param ComputedPath [OUT] The address of the token being swapped to. Also known as the token contract address.
66-
* @return True if path was computed (False indicates path failed to compute).
61+
* @param ComputedPath [Out] The generated link.
62+
* @param Environment [In] The environment for which the path is being computed for (e.g. sandbox, production).
63+
* @param ToTokenAddress [Optional] The token address of the token being swapped from. Default value is an empty string.
64+
* @param FromTokenAddress [Optional] The token address of the token being swapped to. Default value is an empty string.
65+
*
66+
* @return True if path was computed (False indicates link failed to compute).
6767
*/
6868
UFUNCTION(BlueprintCallable, BlueprintPure = "False", Category = "Immutable")
69-
bool ComputePath(EImtblEnvironment Environment, FString FromTokenAddress, FString ToTokenAddress, FString& ComputedPath) const;
69+
bool ComputePath(FString& ComputedPath, EImtblEnvironment Environment, FString FromTokenAddress = TEXT(""), FString ToTokenAddress = TEXT("")) const;
7070

7171
public:
7272
UPROPERTY(Config, EditDefaultsOnly, BlueprintReadOnly, Category = "Immutable")

0 commit comments

Comments
 (0)