Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 4.26 support to transak widget #156

Merged
merged 14 commits into from
Dec 19, 2024
Merged
Prev Previous commit
Next Next commit
refactor: apply formatting
  • Loading branch information
ImmutableJeffrey authored and YermekG committed Dec 19, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 336d0d0f12c3bb6c739a946c7b08ea8149043e56
174 changes: 87 additions & 87 deletions Source/Immutable/Private/Immutable/Transak/TransakWebBrowser.cpp
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ FDelegateHandle UTransakWebBrowser::CallAndRegister_OnWhenReady(FOnWhenReady::FD

TSharedRef<SWidget> UTransakWebBrowser::RebuildWidget()
{
if ( IsDesignTime() )
if (IsDesignTime())
{
return SNew(SBox)
.HAlign(HAlign_Center)
@@ -78,99 +78,99 @@ void UTransakWebBrowser::HandleOnUrlChanged(const FText& Text)

void UTransakWebBrowser::Load(const FString& WalletAddress, const FString& Email, const FString& ProductsAvailed, const FString& ScreenTitle)
{
if (!WebBrowserWidget.IsValid())
{
return;
}
FString UrlToLoad = ComputePath(WalletAddress, Email, ProductsAvailed, ScreenTitle);

if (bIsReady)
{
if (!WebBrowserWidget.IsValid())
{
return;
}

FString UrlToLoad = ComputePath(WalletAddress, Email, ProductsAvailed, ScreenTitle);

if (bIsReady)
{
#if (ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1)
WebBrowserWidget->LoadURL(UrlToLoad);
WebBrowserWidget->LoadURL(UrlToLoad);
#endif
}
else
{
FDelegateHandle OnWhenReadyHandle = CallAndRegister_OnWhenReady(UTransakWebBrowser::FOnWhenReady::FDelegate::CreateWeakLambda(this, [this, UrlToLoad, OnWhenReadyHandle]()
{
}
else
{
FDelegateHandle OnWhenReadyHandle = CallAndRegister_OnWhenReady(UTransakWebBrowser::FOnWhenReady::FDelegate::CreateWeakLambda(this, [this, UrlToLoad, OnWhenReadyHandle]()
{
#if (ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1)
WebBrowserWidget->LoadURL(UrlToLoad);
WebBrowserWidget->LoadURL(UrlToLoad);
#else
WebBrowserWidget->LoadURL(UrlToLoad);
#endif
OnWhenReady.Remove(OnWhenReadyHandle);
}));
}
OnWhenReady.Remove(OnWhenReadyHandle);
}));
}
}

FString UTransakWebBrowser::ComputePath(const FString& WalletAddress, const FString& Email, const FString& ProductsAvailed, const FString& ScreenTitle)
{
UTransakConfig* TransakConfig = FImmutableUtilities::GetDefaultTransakConfig();

if (!TransakConfig)
{
return "";
}

FString Path = TransakConfig->GetURL();
TArray<FString> QueryParams;
QueryParams.Add(FString(TEXT("apiKey=")) + FPlatformHttp::UrlEncode(TransakConfig->GetAPIKey()));
QueryParams.Add(FString(TEXT("email=")) + FPlatformHttp::UrlEncode(Email));
QueryParams.Add(FString(TEXT("walletAddress=")) + FPlatformHttp::UrlEncode(WalletAddress));
QueryParams.Add(FString(TEXT("themeColor=")) + FPlatformHttp::UrlEncode(TransakConfig->GetThemeColor().ToString()));
QueryParams.Add(FString(TEXT("isAutoFillUserData=")) + FPlatformHttp::UrlEncode(TransakConfig->IsAutoFillUserData() ? TEXT("true") : TEXT("false")));
QueryParams.Add(FString(TEXT("disableWalletAddressForm=")) + FPlatformHttp::UrlEncode(TransakConfig->DisableWalletAddressForm() ? TEXT("true") : TEXT("false")));

if (!TransakConfig->GetNetwork().IsEmpty())
{
QueryParams.Add(FString(TEXT("network=")) + FPlatformHttp::UrlEncode(TransakConfig->GetNetwork()));
}
if (!ProductsAvailed.IsEmpty())
{
QueryParams.Add(FString(TEXT("productsAvailed=")) + FPlatformHttp::UrlEncode(ProductsAvailed));
}
if (!ScreenTitle.IsEmpty())
{
QueryParams.Add(FString(TEXT("exchangeScreenTitle=")) + FPlatformHttp::UrlEncode(ScreenTitle));
}
if (!TransakConfig->GetDefaultCryptoCurrency().IsEmpty())
{
QueryParams.Add(FString(TEXT("defaultCryptoCurrency=")) + FPlatformHttp::UrlEncode(TransakConfig->GetDefaultCryptoCurrency()));
}

if (!TransakConfig->GetDefaultFiatAmount().IsEmpty())
{
QueryParams.Add(FString(TEXT("defaultFiatAmount=")) + FPlatformHttp::UrlEncode(TransakConfig->GetDefaultFiatAmount()));
}
if (!TransakConfig->GetDefaultFiatCurrency().IsEmpty())
{
QueryParams.Add(FString(TEXT("defaultFiatCurrency=")) + FPlatformHttp::UrlEncode(TransakConfig->GetDefaultFiatCurrency()));
}

if (!TransakConfig->GetDefaultPaymentMethod().IsEmpty())
{
QueryParams.Add(FString(TEXT("defaultPaymentMethod=")) + FPlatformHttp::UrlEncode(TransakConfig->GetDefaultPaymentMethod()));
}

if (TransakConfig->GetCryptoCurrencyList().Num() > 0)
{
QueryParams.Add(FString(TEXT("cryptoCurrencyList=")) + FPlatformHttp::UrlEncode(FString::Join(TransakConfig->GetCryptoCurrencyList(), TEXT(","))));
}
if (TransakConfig->GetDisablePaymentMethods().Num() > 0)
{
QueryParams.Add(FString(TEXT("disablePaymentMethods=")) + FPlatformHttp::UrlEncode(FString::Join(TransakConfig->GetDisablePaymentMethods(), TEXT(","))));
}
Path += TEXT("?");
Path += FString::Join(QueryParams, TEXT("&"));

return Path;
}
UTransakConfig* TransakConfig = FImmutableUtilities::GetDefaultTransakConfig();

if (!TransakConfig)
{
return "";
}

FString Path = TransakConfig->GetURL();
TArray<FString> QueryParams;

QueryParams.Add(FString(TEXT("apiKey=")) + FPlatformHttp::UrlEncode(TransakConfig->GetAPIKey()));
QueryParams.Add(FString(TEXT("email=")) + FPlatformHttp::UrlEncode(Email));
QueryParams.Add(FString(TEXT("walletAddress=")) + FPlatformHttp::UrlEncode(WalletAddress));
QueryParams.Add(FString(TEXT("themeColor=")) + FPlatformHttp::UrlEncode(TransakConfig->GetThemeColor().ToString()));
QueryParams.Add(FString(TEXT("isAutoFillUserData=")) + FPlatformHttp::UrlEncode(TransakConfig->IsAutoFillUserData() ? TEXT("true") : TEXT("false")));
QueryParams.Add(FString(TEXT("disableWalletAddressForm=")) + FPlatformHttp::UrlEncode(TransakConfig->DisableWalletAddressForm() ? TEXT("true") : TEXT("false")));

if (!TransakConfig->GetNetwork().IsEmpty())
{
QueryParams.Add(FString(TEXT("network=")) + FPlatformHttp::UrlEncode(TransakConfig->GetNetwork()));
}

if (!ProductsAvailed.IsEmpty())
{
QueryParams.Add(FString(TEXT("productsAvailed=")) + FPlatformHttp::UrlEncode(ProductsAvailed));
}

if (!ScreenTitle.IsEmpty())
{
QueryParams.Add(FString(TEXT("exchangeScreenTitle=")) + FPlatformHttp::UrlEncode(ScreenTitle));
}

if (!TransakConfig->GetDefaultCryptoCurrency().IsEmpty())
{
QueryParams.Add(FString(TEXT("defaultCryptoCurrency=")) + FPlatformHttp::UrlEncode(TransakConfig->GetDefaultCryptoCurrency()));
}

if (!TransakConfig->GetDefaultFiatAmount().IsEmpty())
{
QueryParams.Add(FString(TEXT("defaultFiatAmount=")) + FPlatformHttp::UrlEncode(TransakConfig->GetDefaultFiatAmount()));
}

if (!TransakConfig->GetDefaultFiatCurrency().IsEmpty())
{
QueryParams.Add(FString(TEXT("defaultFiatCurrency=")) + FPlatformHttp::UrlEncode(TransakConfig->GetDefaultFiatCurrency()));
}

if (!TransakConfig->GetDefaultPaymentMethod().IsEmpty())
{
QueryParams.Add(FString(TEXT("defaultPaymentMethod=")) + FPlatformHttp::UrlEncode(TransakConfig->GetDefaultPaymentMethod()));
}

if (TransakConfig->GetCryptoCurrencyList().Num() > 0)
{
QueryParams.Add(FString(TEXT("cryptoCurrencyList=")) + FPlatformHttp::UrlEncode(FString::Join(TransakConfig->GetCryptoCurrencyList(), TEXT(","))));
}

if (TransakConfig->GetDisablePaymentMethods().Num() > 0)
{
QueryParams.Add(FString(TEXT("disablePaymentMethods=")) + FPlatformHttp::UrlEncode(FString::Join(TransakConfig->GetDisablePaymentMethods(), TEXT(","))));
}

Path += TEXT("?");
Path += FString::Join(QueryParams, TEXT("&"));

return Path;
}