diff --git a/.github/workflows/branch-name.yml b/.github/workflows/branch-name.yml index 57bf7a2..804238f 100644 --- a/.github/workflows/branch-name.yml +++ b/.github/workflows/branch-name.yml @@ -9,7 +9,6 @@ jobs: - uses: deepakputhraya/action-branch-name@master with: regex: '([a-z])*\/?([a-z0-9.-])+' - allowed_prefixes: 'feat,fix,build,chore,ci,docs,style,refactor,perf,test,revert,release' ignore: main min_length: 5 max_length: 50 diff --git a/Source/Immutable/Immutable.Build.cs b/Source/Immutable/Immutable.Build.cs index a9079a6..dc08b2d 100644 --- a/Source/Immutable/Immutable.Build.cs +++ b/Source/Immutable/Immutable.Build.cs @@ -30,6 +30,7 @@ public Immutable(ReadOnlyTargetRules Target) : base(Target) PrivateDependencyModuleNames.AddRange( new string[] { + "BluExtension", "CoreUObject", "Engine", "Slate", diff --git a/Source/Immutable/Private/Immutable/Transak/TransakWebBrowser.cpp b/Source/Immutable/Private/Immutable/Transak/TransakWebBrowser.cpp index 3f417d8..1f2d148 100644 --- a/Source/Immutable/Private/Immutable/Transak/TransakWebBrowser.cpp +++ b/Source/Immutable/Private/Immutable/Transak/TransakWebBrowser.cpp @@ -1,12 +1,39 @@ #include "Immutable/Transak/TransakWebBrowser.h" #include "PlatformHttp.h" + #include "Immutable/ImmutableUtilities.h" #include "Immutable/TransakConfig.h" + +#if (ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1) +#include "SWebBrowser.h" + #include "Immutable/Misc/ImtblLogging.h" +#else +#include "UserInterface/BluWebBrowser.h" +#endif + +#define LOCTEXT_NAMESPACE "TransakWebBrowser" + +bool UTransakWebBrowser::IsReady() const +{ + return bIsReady; +} +void UTransakWebBrowser::Load(const FString& WalletAddress, const FString& Email, const FString& ProductsAvailed, const FString& ScreenTitle) +{ + if (!WebBrowserWidget.IsValid()) + { + return; + } -#define LOCTEXT_NAMESPACE "Immutable" + FString UrlToLoad = ComputePath(WalletAddress, Email, ProductsAvailed, ScreenTitle); + FDelegateHandle OnWhenReadyHandle = CallAndRegister_OnWhenReady(UTransakWebBrowser::FOnWhenReady::FDelegate::CreateWeakLambda(this, [this, UrlToLoad, OnWhenReadyHandle]() + { + WebBrowserWidget->LoadURL(UrlToLoad); + OnWhenReady.Remove(OnWhenReadyHandle); + })); +} FDelegateHandle UTransakWebBrowser::CallAndRegister_OnWhenReady(FOnWhenReady::FDelegate Delegate) { @@ -20,7 +47,7 @@ FDelegateHandle UTransakWebBrowser::CallAndRegister_OnWhenReady(FOnWhenReady::FD TSharedRef UTransakWebBrowser::RebuildWidget() { - if ( IsDesignTime() ) + if (IsDesignTime()) { return SNew(SBox) .HAlign(HAlign_Center) @@ -34,7 +61,7 @@ TSharedRef UTransakWebBrowser::RebuildWidget() { #if (ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1) WebBrowserWidget = SNew(SWebBrowser) - .InitialURL(TEXT("about:blank")) + .InitialURL(InitialURL) .ShowControls(false) .SupportsTransparency(false) .OnUrlChanged(BIND_UOBJECT_DELEGATE(FOnTextChanged, HandleOnUrlChanged)) @@ -42,21 +69,94 @@ TSharedRef UTransakWebBrowser::RebuildWidget() .OnConsoleMessage(BIND_UOBJECT_DELEGATE(FOnConsoleMessageDelegate, HandleOnConsoleMessage)); return WebBrowserWidget.ToSharedRef(); #else - return SNullWidget::NullWidget; + WebBrowserWidget = SNew(SBluWebBrowser) + .InitialURL(InitialURL) + .OnUrlChanged(BIND_UOBJECT_DELEGATE(FOnTextChanged, HandleOnUrlChanged)); + return WebBrowserWidget.ToSharedRef(); #endif } } -#if (ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1) +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 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; +} + void UTransakWebBrowser::HandleOnUrlChanged(const FText& Text) { - if (Text.EqualToCaseIgnored(FText::FromString(TEXT("about:blank")))) + if (Text.EqualToCaseIgnored(FText::FromString(InitialURL))) { bIsReady = true; OnWhenReady.Broadcast(); } } +#if (ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1) void UTransakWebBrowser::HandleOnConsoleMessage(const FString& Message, const FString& Source, int32 Line, EWebBrowserConsoleLogSeverity Severity) { IMTBL_LOG("Transak Web Browser console message: %s, Source: %s, Line: %d", *Message, *Source, Line); @@ -66,101 +166,4 @@ bool UTransakWebBrowser::HandleOnBeforePopup(FString URL, FString Frame) { return false; } -#endif - -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 (ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1) - WebBrowserWidget->LoadURL(UrlToLoad); -#endif - } - 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); -#endif - 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 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; -} +#endif \ No newline at end of file diff --git a/Source/Immutable/Public/Immutable/Transak/TransakWebBrowser.h b/Source/Immutable/Public/Immutable/Transak/TransakWebBrowser.h index 7dcdb30..f543e84 100644 --- a/Source/Immutable/Public/Immutable/Transak/TransakWebBrowser.h +++ b/Source/Immutable/Public/Immutable/Transak/TransakWebBrowser.h @@ -2,11 +2,15 @@ #include "Components/Widget.h" +#include "TransakWebBrowser.generated.h" + #if (ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1) -#include "SWebBrowser.h" -#endif +enum class EWebBrowserConsoleLogSeverity; -#include "TransakWebBrowser.generated.h" +class SWebBrowser; +#else +class SBluWebBrowser; +#endif /** * @@ -18,12 +22,14 @@ class IMMUTABLE_API UTransakWebBrowser : public UWidget public: DECLARE_MULTICAST_DELEGATE(FOnWhenReady); - + +public: + UFUNCTION(BlueprintPure) + bool IsReady() const; + UFUNCTION(BlueprintCallable) void Load(const FString& WalletAddress, const FString& Email, const FString& ProductsAvailed, const FString& ScreenTitle); - bool IsReady() const { return bIsReady; }; - FDelegateHandle CallAndRegister_OnWhenReady(FOnWhenReady::FDelegate Delegate); protected: @@ -31,24 +37,27 @@ class IMMUTABLE_API UTransakWebBrowser : public UWidget virtual TSharedRef RebuildWidget() override; // End of UWidget interface -private: +protected: FString ComputePath(const FString& WalletAddress, const FString& Email, const FString& ProductsAvailed, const FString& ScreenTitle); + void HandleOnUrlChanged(const FText& Text); #if (ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1) void HandleOnConsoleMessage(const FString& Message, const FString& Source, int32 Line, EWebBrowserConsoleLogSeverity Severity); - void HandleOnUrlChanged(const FText& Text); bool HandleOnBeforePopup(FString URL, FString Frame); #endif protected: + /** URL that the browser will initially navigate to. The URL should include the protocol, eg http:// */ + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly) + FString InitialURL = TEXT("about:blank"); + #if (ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1) TSharedPtr WebBrowserWidget; #else - TSharedPtr WebBrowserWidget; + TSharedPtr WebBrowserWidget; #endif FOnWhenReady OnWhenReady; -private: +protected: bool bIsReady = false; - -}; +}; \ No newline at end of file