diff --git a/Content/PackagedResources/index.uasset b/Content/PackagedResources/index.uasset index 6d9de32..a046481 100644 Binary files a/Content/PackagedResources/index.uasset and b/Content/PackagedResources/index.uasset differ diff --git a/Source/Immutable/Private/Immutable/Actions/ImtblConnectImxAsyncAction.cpp b/Source/Immutable/Private/Immutable/Actions/ImtblConnectImxAsyncAction.cpp index fe796c9..43648c4 100644 --- a/Source/Immutable/Private/Immutable/Actions/ImtblConnectImxAsyncAction.cpp +++ b/Source/Immutable/Private/Immutable/Actions/ImtblConnectImxAsyncAction.cpp @@ -96,6 +96,6 @@ void UImtblConnectionAsyncActions::OnConnect(FImmutablePassportResult Result) } else { - Failed.Broadcast(Result.Message); + Failed.Broadcast(Result.Error); } } diff --git a/Source/Immutable/Private/Immutable/Actions/ImtblPassportConnectEvmAsyncAction.cpp b/Source/Immutable/Private/Immutable/Actions/ImtblPassportConnectEvmAsyncAction.cpp index ac54cbb..0b0cbba 100644 --- a/Source/Immutable/Private/Immutable/Actions/ImtblPassportConnectEvmAsyncAction.cpp +++ b/Source/Immutable/Private/Immutable/Actions/ImtblPassportConnectEvmAsyncAction.cpp @@ -38,10 +38,10 @@ void UImtblPassportConnectEvmAsyncAction::OnConnectEvm(FImmutablePassportResult { if (Result.Success) { - Success.Broadcast(Result.Message); + Success.Broadcast(""); } else { - Failed.Broadcast(Result.Message); + Failed.Broadcast(Result.Error); } } diff --git a/Source/Immutable/Private/Immutable/Actions/ImtblPassportGetAccessTokenAsyncAction.cpp b/Source/Immutable/Private/Immutable/Actions/ImtblPassportGetAccessTokenAsyncAction.cpp index 7d5699e..083e710 100644 --- a/Source/Immutable/Private/Immutable/Actions/ImtblPassportGetAccessTokenAsyncAction.cpp +++ b/Source/Immutable/Private/Immutable/Actions/ImtblPassportGetAccessTokenAsyncAction.cpp @@ -38,10 +38,10 @@ void UImtblPassportGetAccessTokenAsyncAction::OnGetAccessTokenResponse(FImmutabl { if (Result.Success) { - GotAccessToken.Broadcast(TEXT(""), Result.Message); + GotAccessToken.Broadcast(TEXT(""), UImmutablePassport::GetResponseResultAsString(Result.Response)); } else { - Failed.Broadcast(Result.Message, TEXT("")); + Failed.Broadcast(Result.Error, TEXT("")); } } diff --git a/Source/Immutable/Private/Immutable/Actions/ImtblPassportGetAddressAsyncAction.cpp b/Source/Immutable/Private/Immutable/Actions/ImtblPassportGetAddressAsyncAction.cpp index dd884a1..939766b 100644 --- a/Source/Immutable/Private/Immutable/Actions/ImtblPassportGetAddressAsyncAction.cpp +++ b/Source/Immutable/Private/Immutable/Actions/ImtblPassportGetAddressAsyncAction.cpp @@ -39,10 +39,10 @@ void UImtblPassportGetAddressAsyncAction::OnGetAddressResponse(FImmutablePasspor { if (Result.Success) { - GotAddress.Broadcast(TEXT(""), Result.Message); + GotAddress.Broadcast(TEXT(""), UImmutablePassport::GetResponseResultAsString(Result.Response)); } else { - Failed.Broadcast(Result.Message, TEXT("")); + Failed.Broadcast(Result.Error, TEXT("")); } } diff --git a/Source/Immutable/Private/Immutable/Actions/ImtblPassportGetEmailAsyncAction.cpp b/Source/Immutable/Private/Immutable/Actions/ImtblPassportGetEmailAsyncAction.cpp index 5a9e0da..be993f1 100644 --- a/Source/Immutable/Private/Immutable/Actions/ImtblPassportGetEmailAsyncAction.cpp +++ b/Source/Immutable/Private/Immutable/Actions/ImtblPassportGetEmailAsyncAction.cpp @@ -39,10 +39,10 @@ void UImtblPassportGetEmailAsyncAction::OnGetEmailResponse(FImmutablePassportRes { if (Result.Success) { - GotEmail.Broadcast(TEXT(""), Result.Message); + GotEmail.Broadcast(TEXT(""), UImmutablePassport::GetResponseResultAsString(Result.Response)); } else { - Failed.Broadcast(Result.Message, TEXT("")); + Failed.Broadcast(Result.Error, TEXT("")); } } diff --git a/Source/Immutable/Private/Immutable/Actions/ImtblPassportGetIdTokenAsyncAction.cpp b/Source/Immutable/Private/Immutable/Actions/ImtblPassportGetIdTokenAsyncAction.cpp index 323a630..1728e9f 100644 --- a/Source/Immutable/Private/Immutable/Actions/ImtblPassportGetIdTokenAsyncAction.cpp +++ b/Source/Immutable/Private/Immutable/Actions/ImtblPassportGetIdTokenAsyncAction.cpp @@ -38,10 +38,10 @@ void UImtblPassportGetIdTokenAsyncAction::OnGetIdTokenResponse(FImmutablePasspor { if (Result.Success) { - GotIdToken.Broadcast(TEXT(""), Result.Message); + GotIdToken.Broadcast(TEXT(""), UImmutablePassport::GetResponseResultAsString(Result.Response)); } else { - Failed.Broadcast(Result.Message, TEXT("")); + Failed.Broadcast(Result.Error, TEXT("")); } } diff --git a/Source/Immutable/Private/Immutable/Actions/ImtblPassportHasStoredCredentialsAsyncAction.cpp b/Source/Immutable/Private/Immutable/Actions/ImtblPassportHasStoredCredentialsAsyncAction.cpp index eb431b9..25b790a 100644 --- a/Source/Immutable/Private/Immutable/Actions/ImtblPassportHasStoredCredentialsAsyncAction.cpp +++ b/Source/Immutable/Private/Immutable/Actions/ImtblPassportHasStoredCredentialsAsyncAction.cpp @@ -45,6 +45,6 @@ void UImtblPassportHasStoredCredentialsAsyncAction::OnHasStoredCredentialsRespon } else { - OnFalse.Broadcast(Result.Message); + OnFalse.Broadcast(Result.Error); } } diff --git a/Source/Immutable/Private/Immutable/Actions/ImtblPassportImxBatchNftTransferAsyncAction.cpp b/Source/Immutable/Private/Immutable/Actions/ImtblPassportImxBatchNftTransferAsyncAction.cpp index 1fac37e..543921e 100644 --- a/Source/Immutable/Private/Immutable/Actions/ImtblPassportImxBatchNftTransferAsyncAction.cpp +++ b/Source/Immutable/Private/Immutable/Actions/ImtblPassportImxBatchNftTransferAsyncAction.cpp @@ -55,6 +55,6 @@ void UImmutablePassportImxBatchNftTransferAsyncAction::OnTransferResponse(FImmut } else { - Failed.Broadcast(Result.Message, TransferIds); + Failed.Broadcast(Result.Error, TransferIds); } } diff --git a/Source/Immutable/Private/Immutable/Actions/ImtblPassportImxIsRegisteredOffchainAsyncAction.cpp b/Source/Immutable/Private/Immutable/Actions/ImtblPassportImxIsRegisteredOffchainAsyncAction.cpp index ae162d6..c1944f8 100644 --- a/Source/Immutable/Private/Immutable/Actions/ImtblPassportImxIsRegisteredOffchainAsyncAction.cpp +++ b/Source/Immutable/Private/Immutable/Actions/ImtblPassportImxIsRegisteredOffchainAsyncAction.cpp @@ -39,5 +39,5 @@ void UImtblPassportImxIsRegisteredOffchainAsyncAction::DoImxIsRegisteredOffchain void UImtblPassportImxIsRegisteredOffchainAsyncAction::OnImxIsRegisteredOffchainResponse(FImmutablePassportResult Result) { - OnComplete.Broadcast(Result.Success); + OnComplete.Broadcast(UImmutablePassport::GetResponseResultAsBool(Result.Response)); } diff --git a/Source/Immutable/Private/Immutable/Actions/ImtblPassportImxRegisterOffchainAsyncAction.cpp b/Source/Immutable/Private/Immutable/Actions/ImtblPassportImxRegisterOffchainAsyncAction.cpp index 61ba876..e5573d0 100644 --- a/Source/Immutable/Private/Immutable/Actions/ImtblPassportImxRegisterOffchainAsyncAction.cpp +++ b/Source/Immutable/Private/Immutable/Actions/ImtblPassportImxRegisterOffchainAsyncAction.cpp @@ -49,5 +49,5 @@ void UImtblPassportImxRegisterOffchainAsyncAction::OnImxRegisterOffchainResponse } } - OnFailure.Broadcast(TEXT(""), Result.Message); + OnFailure.Broadcast(TEXT(""), Result.Error); } diff --git a/Source/Immutable/Private/Immutable/Actions/ImtblPassportImxTransferAsyncAction.cpp b/Source/Immutable/Private/Immutable/Actions/ImtblPassportImxTransferAsyncAction.cpp index eaed70a..7c8253b 100644 --- a/Source/Immutable/Private/Immutable/Actions/ImtblPassportImxTransferAsyncAction.cpp +++ b/Source/Immutable/Private/Immutable/Actions/ImtblPassportImxTransferAsyncAction.cpp @@ -3,6 +3,7 @@ #include "Immutable/Actions/ImtblPassportImxTransferAsyncAction.h" #include "Immutable/ImmutablePassport.h" +#include "Immutable/ImmutableResponses.h" #include "Immutable/ImmutableSubsystem.h" #include "Immutable/Misc/ImtblLogging.h" @@ -57,6 +58,6 @@ void UImmutablePassportImxTransferAsyncAction::OnTransferResponse(FImmutablePass } else { - Failed.Broadcast(Result.Message, TEXT("")); + Failed.Broadcast(Result.Error, TEXT("")); } } diff --git a/Source/Immutable/Private/Immutable/Actions/ImtblPassportInitializationAsyncAction.cpp b/Source/Immutable/Private/Immutable/Actions/ImtblPassportInitializationAsyncAction.cpp index 1bec1ba..0123cee 100644 --- a/Source/Immutable/Private/Immutable/Actions/ImtblPassportInitializationAsyncAction.cpp +++ b/Source/Immutable/Private/Immutable/Actions/ImtblPassportInitializationAsyncAction.cpp @@ -42,10 +42,10 @@ void UImtblPassportInitializationAsyncAction::OnInitialized(FImmutablePassportRe { if (Result.Success) { - Initialized.Broadcast(Result.Message); + Initialized.Broadcast(""); } else { - Failed.Broadcast(Result.Message); + Failed.Broadcast(Result.Error); } } diff --git a/Source/Immutable/Private/Immutable/Actions/ImtblPassportLogoutAsyncAction.cpp b/Source/Immutable/Private/Immutable/Actions/ImtblPassportLogoutAsyncAction.cpp index 8937469..9ced8e5 100644 --- a/Source/Immutable/Private/Immutable/Actions/ImtblPassportLogoutAsyncAction.cpp +++ b/Source/Immutable/Private/Immutable/Actions/ImtblPassportLogoutAsyncAction.cpp @@ -42,10 +42,10 @@ void UImtblPassportLogoutAsyncAction::OnLogoutResponse(FImmutablePassportResult { if (Result.Success) { - OnSuccess.Broadcast(Result.Message); + OnSuccess.Broadcast(""); } else { - OnFailure.Broadcast(Result.Message); + OnFailure.Broadcast(Result.Error); } } diff --git a/Source/Immutable/Private/Immutable/Actions/ImtblPassportZkEvmGetBalanceAsyncAction.cpp b/Source/Immutable/Private/Immutable/Actions/ImtblPassportZkEvmGetBalanceAsyncAction.cpp index 2c0e158..cc6ecbb 100644 --- a/Source/Immutable/Private/Immutable/Actions/ImtblPassportZkEvmGetBalanceAsyncAction.cpp +++ b/Source/Immutable/Private/Immutable/Actions/ImtblPassportZkEvmGetBalanceAsyncAction.cpp @@ -30,22 +30,22 @@ void UImtblPassportZkEvmGetBalanceAsyncAction::Activate() void UImtblPassportZkEvmGetBalanceAsyncAction::DoZkEvmGetBalance(TWeakObjectPtr JSConnector) { - // Get Passport auto Passport = GetSubsystem()->GetPassport(); - // Run ZkEvmGetBalance - Passport->ZkEvmGetBalance(FImmutablePassportZkEvmGetBalanceData{Address, BlockNumberOrTag}, UImmutablePassport::FImtblPassportResponseDelegate::CreateUObject(this, &UImtblPassportZkEvmGetBalanceAsyncAction::OnZkEvmGetBalanceResponse)); + + if (Passport.IsValid()) + { + Passport->ZkEvmGetBalance(FImmutablePassportZkEvmGetBalanceData{Address, BlockNumberOrTag}, UImmutablePassport::FImtblPassportResponseDelegate::CreateUObject(this, &UImtblPassportZkEvmGetBalanceAsyncAction::OnZkEvmGetBalanceResponse)); + } } void UImtblPassportZkEvmGetBalanceAsyncAction::OnZkEvmGetBalanceResponse(FImmutablePassportResult Result) { if (Result.Success) { - IMTBL_LOG("ZkEvmGetBalance success") - GotBalance.Broadcast(TEXT(""), Result.Message); + GotBalance.Broadcast(TEXT(""), UImmutablePassport::GetResponseResultAsString(Result.Response)); } else { - IMTBL_LOG("ZkEvmGetBalance failed") - Failed.Broadcast(Result.Message, TEXT("")); + Failed.Broadcast(Result.Error, TEXT("")); } } diff --git a/Source/Immutable/Private/Immutable/Actions/ImtblPassportZkEvmGetTransactionReceiptAA.cpp b/Source/Immutable/Private/Immutable/Actions/ImtblPassportZkEvmGetTransactionReceiptAA.cpp index 288c555..563c62c 100644 --- a/Source/Immutable/Private/Immutable/Actions/ImtblPassportZkEvmGetTransactionReceiptAA.cpp +++ b/Source/Immutable/Private/Immutable/Actions/ImtblPassportZkEvmGetTransactionReceiptAA.cpp @@ -59,6 +59,6 @@ void UImtblPassportZkEvmGetTransactionReceiptAA::OnZkEvmGetTransactionReceiptRes else { IMTBL_LOG("zkEVM Transaction Receipt retrival failed") - Failed.Broadcast(Result.Message, FZkEvmTransactionReceipt()); + Failed.Broadcast(Result.Error, FZkEvmTransactionReceipt()); } } diff --git a/Source/Immutable/Private/Immutable/Actions/ImtblPassportZkEvmRequestAccountsAsyncAction.cpp b/Source/Immutable/Private/Immutable/Actions/ImtblPassportZkEvmRequestAccountsAsyncAction.cpp index cef062f..a6ebd02 100644 --- a/Source/Immutable/Private/Immutable/Actions/ImtblPassportZkEvmRequestAccountsAsyncAction.cpp +++ b/Source/Immutable/Private/Immutable/Actions/ImtblPassportZkEvmRequestAccountsAsyncAction.cpp @@ -29,22 +29,24 @@ void UImtblPassportZkEvmRequestAccountsAsyncAction::Activate() void UImtblPassportZkEvmRequestAccountsAsyncAction::DoRequestAccounts(TWeakObjectPtr JSConnector) { - // Get Passport auto Passport = GetSubsystem()->GetPassport(); - // Run ZkEvmRequestAccounts - Passport->ZkEvmRequestAccounts(UImmutablePassport::FImtblPassportResponseDelegate::CreateUObject(this, &UImtblPassportZkEvmRequestAccountsAsyncAction::OnRequestAccountsResponse)); + + if (Passport.IsValid()) + { + Passport->ZkEvmRequestAccounts(UImmutablePassport::FImtblPassportResponseDelegate::CreateUObject(this, &UImtblPassportZkEvmRequestAccountsAsyncAction::OnRequestAccountsResponse)); + } } void UImtblPassportZkEvmRequestAccountsAsyncAction::OnRequestAccountsResponse(FImmutablePassportResult Result) { - TArray StrArr; if (Result.Success) { - Result.Message.ParseIntoArray(StrArr, TEXT(",")); - GotAccounts.Broadcast(TEXT(""), StrArr); + const auto RequestAccountsData = FImmutablePassportZkEvmRequestAccountsData::FromJsonObject(Result.Response.JsonObject); + + GotAccounts.Broadcast(TEXT(""), RequestAccountsData->accounts); } else { - Failed.Broadcast(Result.Message, StrArr); + Failed.Broadcast(Result.Error, TArray()); } } diff --git a/Source/Immutable/Private/Immutable/Actions/ImtblPassportZkEvmSendTransactionAsyncAction.cpp b/Source/Immutable/Private/Immutable/Actions/ImtblPassportZkEvmSendTransactionAsyncAction.cpp index 5f4e131..c16e676 100644 --- a/Source/Immutable/Private/Immutable/Actions/ImtblPassportZkEvmSendTransactionAsyncAction.cpp +++ b/Source/Immutable/Private/Immutable/Actions/ImtblPassportZkEvmSendTransactionAsyncAction.cpp @@ -29,10 +29,12 @@ void UImtblPassportZkEvmSendTransactionAsyncAction::Activate() void UImtblPassportZkEvmSendTransactionAsyncAction::DoZkEvmSendTransaction(TWeakObjectPtr JSConnector) { - // Get Passport auto Passport = GetSubsystem()->GetPassport(); - // Run ZkEvmSendTransaction - Passport->ZkEvmSendTransaction(TransactionRequest, UImmutablePassport::FImtblPassportResponseDelegate::CreateUObject(this, &UImtblPassportZkEvmSendTransactionAsyncAction::OnZkEvmSendTransactionResponse)); + + if (Passport.IsValid()) + { + Passport->ZkEvmSendTransaction(TransactionRequest, UImmutablePassport::FImtblPassportResponseDelegate::CreateUObject(this, &UImtblPassportZkEvmSendTransactionAsyncAction::OnZkEvmSendTransactionResponse)); + } } void UImtblPassportZkEvmSendTransactionAsyncAction::OnZkEvmSendTransactionResponse(FImmutablePassportResult Result) @@ -40,12 +42,12 @@ void UImtblPassportZkEvmSendTransactionAsyncAction::OnZkEvmSendTransactionRespon if (Result.Success) { IMTBL_LOG("zkEVM Send Transaction success") - TransactionSent.Broadcast(TEXT(""), Result.Message); + TransactionSent.Broadcast(TEXT(""), UImmutablePassport::GetResponseResultAsString(Result.Response)); } else { IMTBL_LOG("zkEVM Send Transaction failed") - Failed.Broadcast(Result.Message, TEXT("")); + Failed.Broadcast(Result.Error, TEXT("")); } } @@ -105,6 +107,6 @@ void UImtblPassportZkEvmSendTransactionWithConfirmationAA::OnZkEvmSendTransactio else { IMTBL_LOG("zkEVM Send Transaction with confirmation failed") - Failed.Broadcast(Result.Message, FZkEvmTransactionReceipt()); + Failed.Broadcast(Result.Error, FZkEvmTransactionReceipt()); } } diff --git a/Source/Immutable/Private/Immutable/ImmutablePassport.cpp b/Source/Immutable/Private/Immutable/ImmutablePassport.cpp index 60f10e4..371fc9c 100644 --- a/Source/Immutable/Private/Immutable/ImmutablePassport.cpp +++ b/Source/Immutable/Private/Immutable/ImmutablePassport.cpp @@ -101,33 +101,33 @@ void UImmutablePassport::Logout(bool DoHardLogout, const FImtblPassportResponseD void UImmutablePassport::ConnectEvm(const FImtblPassportResponseDelegate& ResponseDelegate) { - CallJS(ImmutablePassportAction::ConnectEvm, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnConnectEvmResponse)); + CallJS(ImmutablePassportAction::ConnectEvm, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnBridgeCallbackResponse)); } void UImmutablePassport::ZkEvmRequestAccounts(const FImtblPassportResponseDelegate& ResponseDelegate) { - CallJS(ImmutablePassportAction::ZkEvmRequestAccounts, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnZkEvmRequestAccountsResponse)); + CallJS(ImmutablePassportAction::ZkEvmRequestAccounts, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnBridgeCallbackResponse)); } void UImmutablePassport::ZkEvmGetBalance(const FImmutablePassportZkEvmGetBalanceData& Data, const FImtblPassportResponseDelegate& ResponseDelegate) { - CallJS(ImmutablePassportAction::ZkEvmGetBalance, Data.ToJsonString(), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnZkEvmGetBalanceResponse)); + CallJS(ImmutablePassportAction::ZkEvmGetBalance, Data.ToJsonString(), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnBridgeCallbackResponse)); } void UImmutablePassport::ZkEvmSendTransaction(const FImtblTransactionRequest& Request, const FImtblPassportResponseDelegate& ResponseDelegate) { - CallJS(ImmutablePassportAction::ZkEvmSendTransaction, UStructToJsonString(Request), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnZkEvmSendTransactionResponse)); + CallJS(ImmutablePassportAction::ZkEvmSendTransaction, UStructToJsonString(Request), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnBridgeCallbackResponse)); } void UImmutablePassport::ZkEvmSendTransactionWithConfirmation(const FImtblTransactionRequest& Request, const FImtblPassportResponseDelegate& ResponseDelegate) { - CallJS(ImmutablePassportAction::zkEvmSendTransactionWithConfirmation, UStructToJsonString(Request), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnZkEvmSendTransactionWithConfirmationResponse)); + CallJS(ImmutablePassportAction::zkEvmSendTransactionWithConfirmation, UStructToJsonString(Request), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnBridgeCallbackResponse)); } void UImmutablePassport::ZkEvmGetTransactionReceipt(const FZkEvmTransactionReceiptRequest& Request, const FImtblPassportResponseDelegate& ResponseDelegate) { - CallJS(ImmutablePassportAction::ZkEvmGetTransactionReceipt, UStructToJsonString(Request), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnZkEvmGetTransactionReceiptResponse)); + CallJS(ImmutablePassportAction::ZkEvmGetTransactionReceipt, UStructToJsonString(Request), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnBridgeCallbackResponse)); } void UImmutablePassport::ConfirmCode(const FString& DeviceCode, const float Interval, const FImtblPassportResponseDelegate& ResponseDelegate) @@ -140,43 +140,43 @@ void UImmutablePassport::ConfirmCode(const FString& DeviceCode, const float Inte void UImmutablePassport::GetIdToken(const FImtblPassportResponseDelegate& ResponseDelegate) { - CallJS(ImmutablePassportAction::GetIdToken, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnGetIdTokenResponse)); + CallJS(ImmutablePassportAction::GetIdToken, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnBridgeCallbackResponse)); } void UImmutablePassport::GetAccessToken(const FImtblPassportResponseDelegate& ResponseDelegate) { - CallJS(ImmutablePassportAction::GetAccessToken, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnGetAccessTokenResponse)); + CallJS(ImmutablePassportAction::GetAccessToken, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnBridgeCallbackResponse)); } void UImmutablePassport::GetAddress(const FImtblPassportResponseDelegate& ResponseDelegate) { - CallJS(ImmutablePassportAction::GetAddress, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnGetAddressResponse)); + CallJS(ImmutablePassportAction::GetAddress, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnBridgeCallbackResponse)); } void UImmutablePassport::GetEmail(const FImtblPassportResponseDelegate& ResponseDelegate) { - CallJS(ImmutablePassportAction::GetEmail, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnGetEmailResponse)); + CallJS(ImmutablePassportAction::GetEmail, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnBridgeCallbackResponse)); } void UImmutablePassport::ImxTransfer(const FImxTransferRequest& RequestData, const FImtblPassportResponseDelegate& ResponseDelegate) { IMTBL_LOG("Tranfer Request: %s", *UStructToJsonString(RequestData)) - CallJS(ImmutablePassportAction::ImxTransfer, UStructToJsonString(RequestData), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnTransferResponse)); + CallJS(ImmutablePassportAction::ImxTransfer, UStructToJsonString(RequestData), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnBridgeCallbackResponse)); } void UImmutablePassport::ImxBatchNftTransfer(const FImxBatchNftTransferRequest& RequestData, const FImtblPassportResponseDelegate& ResponseDelegate) { - CallJS(ImmutablePassportAction::ImxBatchNftTransfer, RequestData.ToJsonString(), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnBatchNftTransferResponse)); + CallJS(ImmutablePassportAction::ImxBatchNftTransfer, RequestData.ToJsonString(), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnBridgeCallbackResponse)); } void UImmutablePassport::ImxIsRegisteredOffchain(const FImtblPassportResponseDelegate& ResponseDelegate) { - CallJS(ImmutablePassportAction::ImxIsRegisteredOffchain, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnImxIsRegisteredOffchain)); + CallJS(ImmutablePassportAction::ImxIsRegisteredOffchain, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnBridgeCallbackResponse)); } void UImmutablePassport::ImxRegisterOffchain(const FImtblPassportResponseDelegate& ResponseDelegate) { - CallJS(ImmutablePassportAction::ImxRegisterOffchain, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnImxRegisterOffchain)); + CallJS(ImmutablePassportAction::ImxRegisterOffchain, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnBridgeCallbackResponse)); } void UImmutablePassport::HasStoredCredentials(const FImtblPassportResponseDelegate& ResponseDelegate) @@ -213,6 +213,32 @@ void UImmutablePassport::HasStoredCredentials(const FImtblPassportResponseDelega })); } +FString UImmutablePassport::GetResponseResultAsString(const FImtblJSResponse& Response) +{ + if (!Response.JsonObject.IsValid()) + { + IMTBL_ERR("Response JSON data for %s is not valid", *Response.responseFor) + + return ""; + } + + return Response.JsonObject->GetStringField(TEXT("result")); + +} + +bool UImmutablePassport::GetResponseResultAsBool(const FImtblJSResponse& Response) +{ + if (!Response.JsonObject.IsValid()) + { + IMTBL_ERR("Response JSON data for %s is not valid", *Response.responseFor) + + return false; + } + + return Response.JsonObject->GetBoolField(TEXT("result")); +} + + void UImmutablePassport::Setup(const TWeakObjectPtr Connector) { IMTBL_LOG_FUNCSIG @@ -241,7 +267,7 @@ void UImmutablePassport::ReinstateConnection(FImtblJSResponse Response) const FString CallbackName = IsRelogin ? "Relogin" : "Reconnect"; UImmutableAnalytics::EEventName EventName = IsRelogin ? UImmutableAnalytics::EEventName::COMPLETE_RELOGIN : UImmutableAnalytics::EEventName::COMPLETE_RECONNECT; - if (Response.JsonObject->GetBoolField(TEXT("result"))) + if (Response.success) { SetStateFlags(IPS_CONNECTED); ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{true, "", Response}); @@ -302,7 +328,8 @@ void UImmutablePassport::OnInitializeResponse(FImtblJSResponse Response) { if (auto ResponseDelegate = GetResponseDelegate(Response)) { - FString Msg; + FString Error; + if (Response.success) { SetStateFlags(IPS_INITIALIZED); @@ -311,10 +338,10 @@ void UImmutablePassport::OnInitializeResponse(FImtblJSResponse Response) else { IMTBL_ERR("Passport initialization failed.") - Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error")); + Response.Error.IsSet() ? Error = Response.Error->ToString() : Error = Response.JsonObject->GetStringField(TEXT("error")); } Analytics->Track(UImmutableAnalytics::EEventName::INIT_PASSPORT, Response.success); - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{Response.success, Msg, Response}); + ResponseDelegate->ExecuteIfBound(FImmutablePassportResult { Response.success, Error, Response }); } } @@ -372,10 +399,8 @@ void UImmutablePassport::OnLogoutResponse(FImtblJSResponse Response) if (!IsStateFlagsSet(IPS_HARDLOGOUT)) { - Message = "Logged out without clearing browser session"; - - IMTBL_LOG("%s", *Message) - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{ true, Message }); + IMTBL_LOG("Logged out without clearing browser session") + ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{ true }); return; } @@ -413,9 +438,8 @@ void UImmutablePassport::OnLogoutResponse(FImtblJSResponse Response) return; } Analytics->Track(UImmutableAnalytics::EEventName::COMPLETE_LOGOUT); - Message = "Logged out"; - IMTBL_LOG("%s", *Message) - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{ Response.success, Message }); + IMTBL_LOG("Logged out") + ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{ Response.success }); #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC } #endif @@ -427,44 +451,6 @@ void UImmutablePassport::OnLogoutResponse(FImtblJSResponse Response) ResetStateFlags(IPS_CONNECTED); } -void UImmutablePassport::OnConnectSilentResponse(FImtblJSResponse Response) -{ - if (auto ResponseDelegate = GetResponseDelegate(Response)) - { - FString Msg; - - if (Response.success) - { - IMTBL_LOG("Reconnected.") - } - else - { - IMTBL_ERR("Failed to reconnect.") - Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error")); - } - - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{Response.success, Msg, Response}); - } -} - -void UImmutablePassport::OnConnectEvmResponse(FImtblJSResponse Response) -{ - if (auto ResponseDelegate = GetResponseDelegate(Response)) - { - FString Msg; - if (Response.success) - { - IMTBL_LOG("Connected to Evm.") - } - else - { - IMTBL_WARN("Error connecting to Evm.") - Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error")); - } - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{Response.success, Msg}); - } -} - #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC void UImmutablePassport::OnGetPKCEAuthUrlResponse(FImtblJSResponse Response) { @@ -533,178 +519,6 @@ void UImmutablePassport::OnConnectPKCEResponse(FImtblJSResponse Response) } #endif -void UImmutablePassport::OnGetIdTokenResponse(FImtblJSResponse Response) -{ - if (auto ResponseDelegate = GetResponseDelegate(Response)) - { - FString IdToken; - - Response.JsonObject->TryGetStringField(TEXT("result"), IdToken); - - if (!Response.success || IdToken.IsEmpty()) - { - IMTBL_LOG("Failed to retrieve Id Token."); - - const FString Msg = Response.JsonObject->HasField(TEXT("error")) ? Response.JsonObject->GetStringField(TEXT("error")) : "Failed to retrieve Id Token."; - - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{false, Msg, Response}); - } - else - { - IMTBL_LOG("Retrieved Id Token."); - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{true, IdToken}); - } - } -} - -void UImmutablePassport::OnGetAccessTokenResponse(FImtblJSResponse Response) -{ - if (auto ResponseDelegate = GetResponseDelegate(Response)) - { - FString AccessToken; - - Response.JsonObject->TryGetStringField(TEXT("result"), AccessToken); - - if (!Response.success || AccessToken.IsEmpty()) - { - IMTBL_LOG("Failed to retrieve Access Token"); - - const FString Msg = Response.JsonObject->HasField(TEXT("error")) ? Response.JsonObject->GetStringField(TEXT("error")) : "Failed to retrieve Access Token."; - - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{false, Msg, Response}); - } - else - { - IMTBL_LOG("Retrieved Access Token."); - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{true, AccessToken}); - } - } -} - -void UImmutablePassport::OnGetAddressResponse(FImtblJSResponse Response) -{ - if (auto ResponseDelegate = GetResponseDelegate(Response)) - { - FString Msg; - bool bSuccess = true; - - if (!Response.success || !Response.JsonObject->HasTypedField(TEXT("result"))) - { - IMTBL_WARN("Could not fetch address from Passport."); - Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error")); - bSuccess = false; - } - else - { - Msg = Response.JsonObject->GetStringField(TEXT("result")); - } - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{bSuccess, Msg, Response}); - } -} - -void UImmutablePassport::OnZkEvmRequestAccountsResponse(FImtblJSResponse Response) -{ - if (auto ResponseDelegate = GetResponseDelegate(Response)) - { - const auto RequestAccountstData = FImmutablePassportZkEvmRequestAccountsData::FromJsonObject(Response.JsonObject); - FString Msg; - bool bSuccess = true; - if (!Response.success || !Response.JsonObject->HasTypedField(TEXT("accounts"))) - { - IMTBL_WARN("Error requesting zkevm accounts.") - Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error")); - bSuccess = false; - } - else - { - const auto size = RequestAccountstData->accounts.Num(); - for (int32 Index = 0; Index != size; ++Index) - { - Msg += RequestAccountstData->accounts[Index]; - if (Index < size - 1) - { - Msg += TEXT(","); - } - } - } - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{bSuccess, Msg}); - } -} - -void UImmutablePassport::OnZkEvmGetBalanceResponse(FImtblJSResponse Response) -{ - if (auto ResponseDelegate = GetResponseDelegate(Response)) - { - FString Msg; - bool bSuccess = true; - if (!Response.success || !Response.JsonObject->HasTypedField(TEXT("result"))) - { - IMTBL_WARN("Could not get balance."); - Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error")); - bSuccess = false; - } - else - { - Msg = Response.JsonObject->GetStringField(TEXT("result")); - } - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{bSuccess, Msg, Response}); - } -} - -void UImmutablePassport::OnZkEvmSendTransactionResponse(FImtblJSResponse Response) -{ - if (auto ResponseDelegate = GetResponseDelegate(Response)) - { - FString Msg; - bool bSuccess = true; - if (!Response.success || !Response.JsonObject->HasTypedField(TEXT("result"))) - { - IMTBL_WARN("Could not fetch send transaction."); - Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error")); - bSuccess = false; - } - else - { - Msg = Response.JsonObject->GetStringField(TEXT("result")); - } - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{bSuccess, Msg}); - } -} - -void UImmutablePassport::OnZkEvmSendTransactionWithConfirmationResponse(FImtblJSResponse Response) -{ - if (auto ResponseDelegate = GetResponseDelegate(Response)) - { - FString Msg; - bool bSuccess = true; - - if (!Response.success) - { - IMTBL_WARN("zkEVM send transaction with confirmation failed."); - Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error")); - bSuccess = false; - } - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{bSuccess, Msg, Response}); - } -} - -void UImmutablePassport::OnZkEvmGetTransactionReceiptResponse(FImtblJSResponse Response) -{ - if (auto ResponseDelegate = GetResponseDelegate(Response)) - { - FString Msg; - bool bSuccess = true; - - if (!Response.success) - { - IMTBL_WARN("zkEVM transaction receipt retrieval failed."); - Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error")); - bSuccess = false; - } - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{bSuccess, Msg, Response}); - } -} - void UImmutablePassport::OnConfirmCodeResponse(FImtblJSResponse Response) { if (auto ResponseDelegate = GetResponseDelegate(Response)) @@ -729,117 +543,26 @@ void UImmutablePassport::OnConfirmCodeResponse(FImtblJSResponse Response) } } -void UImmutablePassport::OnGetEmailResponse(FImtblJSResponse Response) +void UImmutablePassport::OnBridgeCallbackResponse(FImtblJSResponse Response) { - if (auto ResponseDelegate = GetResponseDelegate(Response)) - { - FString Msg; - bool bSuccess = true; - - if (!Response.success || !Response.JsonObject->HasTypedField(TEXT("result"))) - { - IMTBL_WARN("Connect attempt failed."); - Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error")); - bSuccess = false; - } - else - { - Msg = Response.JsonObject->GetStringField(TEXT("result")); - } - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{bSuccess, Msg, Response}); - } -} - -void UImmutablePassport::OnTransferResponse(FImtblJSResponse Response) -{ - if (auto ResponseDelegate = GetResponseDelegate(Response)) - { - FString Msg; - bool bSuccess = true; - if (!Response.success) - { - IMTBL_WARN("ImxTransfer failed."); - Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error")); - bSuccess = false; - } - else - { - Msg = Response.JsonObject->GetStringField(TEXT("status")); - } - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{bSuccess, Msg, Response}); - } -} + auto ResponseDelegate = GetResponseDelegate(Response); -void UImmutablePassport::OnBatchNftTransferResponse(FImtblJSResponse Response) -{ - if (auto ResponseDelegate = GetResponseDelegate(Response)) + if (!ResponseDelegate) { - auto BatchNftTransferResponse = JsonObjectToUStruct(Response.JsonObject); - - FString Msg; - bool bSuccess = true; - if (!Response.success || !Response.JsonObject->HasTypedField(TEXT("result"))) - { - IMTBL_WARN("ImxBatchNftTransfer failed."); - Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error")); - bSuccess = false; - } - else - { - Msg = UStructToJsonString(*BatchNftTransferResponse); - } - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{bSuccess, Msg, Response}); + IMTBL_ERR("Response delegate is not assigned for %s", *Response.responseFor); + return; } -} -void UImmutablePassport::OnImxIsRegisteredOffchain(FImtblJSResponse Response) -{ - if (auto ResponseDelegate = GetResponseDelegate(Response)) + if (!Response.success) { - FString Msg; - bool bResult = false; - - if (!Response.success) - { - IMTBL_WARN("ImxIsRegisteredOffchain failed."); - Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error")); - } - else - { - bResult = Response.JsonObject->GetBoolField(TEXT("result")); - } - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{bResult, Msg, Response}); + IMTBL_LOG_FUNC("Response for %s is unsuccessfull", *Response.responseFor); } -} -void UImmutablePassport::OnImxRegisterOffchain(FImtblJSResponse Response) -{ - if (auto ResponseDelegate = GetResponseDelegate(Response)) - { - FString Msg; + FString Error; - if (!Response.success) - { - IMTBL_WARN("ImxRegisterOffchain failed."); - Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error")); - } + Response.JsonObject->TryGetStringField(TEXT("error"), Error); - ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{Response.success, Msg, Response}); - } -} - -void UImmutablePassport::LogAndIgnoreResponse(FImtblJSResponse Response) -{ - if (Response.success && !Response.Error) - { - IMTBL_LOG("Received success response from Passport for action %s", *Response.responseFor); - } - else - { - FString Msg; - Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error")); - IMTBL_WARN("Received error response from Passport for action %s -- %s", *Response.responseFor, *Msg); - } + ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{ Response.success, Error, Response }); } void UImmutablePassport::SetStateFlags(uint8 StateIn) @@ -958,6 +681,7 @@ void UImmutablePassport::CompleteLoginPKCEFlow(FString Url) void UImmutablePassport::HandleDeepLink(FString DeepLink) const { #elif PLATFORM_IOS | PLATFORM_MAC + // Called from iOS Objective C void UImmutablePassport::HandleDeepLink(NSString* sDeepLink) const { diff --git a/Source/Immutable/Public/Immutable/Actions/ImtblPassportZkEvmRequestAccountsAsyncAction.h b/Source/Immutable/Public/Immutable/Actions/ImtblPassportZkEvmRequestAccountsAsyncAction.h index 905cd07..5341653 100644 --- a/Source/Immutable/Public/Immutable/Actions/ImtblPassportZkEvmRequestAccountsAsyncAction.h +++ b/Source/Immutable/Public/Immutable/Actions/ImtblPassportZkEvmRequestAccountsAsyncAction.h @@ -24,8 +24,6 @@ class IMMUTABLE_API UImtblPassportZkEvmRequestAccountsAsyncAction : public UImtb virtual void Activate() override; private: - FImmutablePassportZkEvmRequestAccountsData RequestAccountsData; - void DoRequestAccounts(TWeakObjectPtr JSGetConnector); void OnRequestAccountsResponse(FImmutablePassportResult Result); diff --git a/Source/Immutable/Public/Immutable/ImmutableDataTypes.h b/Source/Immutable/Public/Immutable/ImmutableDataTypes.h index 818b00f..e3fdc2f 100644 --- a/Source/Immutable/Public/Immutable/ImmutableDataTypes.h +++ b/Source/Immutable/Public/Immutable/ImmutableDataTypes.h @@ -159,7 +159,7 @@ struct IMMUTABLE_API FImmutablePassportResult bool Success = false; UPROPERTY() - FString Message; + FString Error; FImtblJSResponse Response; }; diff --git a/Source/Immutable/Public/Immutable/ImmutablePassport.h b/Source/Immutable/Public/Immutable/ImmutablePassport.h index d59d389..be8ee19 100644 --- a/Source/Immutable/Public/Immutable/ImmutablePassport.h +++ b/Source/Immutable/Public/Immutable/ImmutablePassport.h @@ -54,15 +54,7 @@ class IMMUTABLE_API UImmutablePassport : public UObject DECLARE_DELEGATE_OneParam(FImtblPassportResponseDelegate, FImmutablePassportResult); -#if PLATFORM_ANDROID - void HandleDeepLink(FString DeepLink) const; - void HandleCustomTabsDismissed(FString Url); -#elif PLATFORM_IOS | PLATFORM_MAC - void HandleDeepLink(NSString* sDeepLink) const; -#endif - void Initialize(const FImmutablePassportInitData& InitData, const FImtblPassportResponseDelegate& ResponseDelegate); - void Connect(bool IsConnectImx, bool TryToRelogin, const FImtblPassportResponseDelegate& ResponseDelegate); #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC void ConnectPKCE(bool IsConnectImx, const FImtblPassportResponseDelegate& ResponseDelegate); @@ -170,72 +162,51 @@ class IMMUTABLE_API UImmutablePassport : public UObject */ void HasStoredCredentials(const FImtblPassportResponseDelegate& ResponseDelegate); + static FString GetResponseResultAsString(const FImtblJSResponse& Response); + static bool GetResponseResultAsBool(const FImtblJSResponse& Response); + +#if PLATFORM_ANDROID + void HandleDeepLink(FString DeepLink) const; + void HandleCustomTabsDismissed(FString Url); +#elif PLATFORM_IOS | PLATFORM_MAC + void HandleDeepLink(NSString* sDeepLink) const; +#endif + protected: - void Setup(TWeakObjectPtr Connector); - void ReinstateConnection(FImtblJSResponse Response); - #if PLATFORM_ANDROID DECLARE_DELEGATE(FImtblPassportOnPKCEDismissedDelegate); - - FImtblPassportOnPKCEDismissedDelegate OnPKCEDismissed; #endif - TWeakObjectPtr JSConnector; - FImmutablePassportInitData InitData; - FDelegateHandle BridgeReadyHandle; - TMap ResponseDelegates; #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC DECLARE_DELEGATE_OneParam(FImtblPassportHandleDeepLinkDelegate, FString); - - FImtblPassportHandleDeepLinkDelegate OnHandleDeepLink; - // Since the second part of PKCE is triggered by deep links, saving the - // response delegate here so it's easier to get - FImtblPassportResponseDelegate PKCEResponseDelegate; - FImtblPassportResponseDelegate PKCELogoutResponseDelegate; - // bool IsPKCEConnected = false; #endif - + + // Calls JS with the given Action and Data, and registers the given + // ResponseDelegate to be called when JS responds + void CallJS(const FString& Action, const FString& Data, const FImtblPassportResponseDelegate& ClientResponseDelegate, const FImtblJSResponseDelegate& HandleJSResponse, const bool bCheckInitialized = true); + + void Setup(TWeakObjectPtr Connector); + void ReinstateConnection(FImtblJSResponse Response); // Ensures that Passport has been initialized before calling JS bool CheckIsInitialized(const FString& Action, const FImtblPassportResponseDelegate& ResponseDelegate) const; - // Calls JS with the given Action and Data, and registers the given - // ResponseDelegate to be called when JS responds - void CallJS(const FString& Action, const FString& Data, const FImtblPassportResponseDelegate& ClientResponseDelegate, const FImtblJSResponseDelegate& HandleJSResponse, const bool bCheckInitialized = true); // Pulls the ResponseDelegate from the ResponseDelegates map and returns it TOptional GetResponseDelegate(const FImtblJSResponse& Response); void ConfirmCode(const FString& DeviceCode, const float Interval, const FImtblPassportResponseDelegate& ResponseDelegate); + // common response callback + void OnBridgeCallbackResponse(FImtblJSResponse Response); + // callbacks with custom response manipulations void OnInitializeResponse(FImtblJSResponse Response); - void OnInitDeviceFlowResponse(FImtblJSResponse Response); - void OnLogoutResponse(FImtblJSResponse Response); - void OnConnectResponse(FImtblJSResponse Response); - void OnConnectSilentResponse(FImtblJSResponse Response); - void OnConnectEvmResponse(FImtblJSResponse Response); - void OnZkEvmRequestAccountsResponse(FImtblJSResponse Response); - void OnZkEvmGetBalanceResponse(FImtblJSResponse Response); - void OnZkEvmSendTransactionResponse(FImtblJSResponse Response); - void OnZkEvmSendTransactionWithConfirmationResponse(FImtblJSResponse Response); - void OnZkEvmGetTransactionReceiptResponse(FImtblJSResponse Response); void OnConfirmCodeResponse(FImtblJSResponse Response); + + // mobile platform callbacks #if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC void OnGetPKCEAuthUrlResponse(FImtblJSResponse Response); void OnConnectPKCEResponse(FImtblJSResponse Response); -#endif - void OnGetIdTokenResponse(FImtblJSResponse Response); - void OnGetAccessTokenResponse(FImtblJSResponse Response); - void OnGetAddressResponse(FImtblJSResponse Response); - void OnGetEmailResponse(FImtblJSResponse Response); - void OnTransferResponse(FImtblJSResponse Response); - void OnBatchNftTransferResponse(FImtblJSResponse Response); - void OnImxIsRegisteredOffchain(FImtblJSResponse Response); - void OnImxRegisterOffchain(FImtblJSResponse Response); - - void LogAndIgnoreResponse(FImtblJSResponse Response); - -#if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC void OnDeepLinkActivated(FString DeepLink); - void CompleteLoginPKCEFlow(FString Url); + void CompleteLoginPKCEFlow(FString Url); #endif #if PLATFORM_ANDROID @@ -248,6 +219,26 @@ class IMMUTABLE_API UImmutablePassport : public UObject void ResetStateFlags(uint8 StateIn); bool IsStateFlagsSet(uint8 StateIn) const; +protected: + TWeakObjectPtr JSConnector; + FImmutablePassportInitData InitData; + FDelegateHandle BridgeReadyHandle; + TMap ResponseDelegates; + +#if PLATFORM_ANDROID + FImtblPassportOnPKCEDismissedDelegate OnPKCEDismissed; +#endif + +#if PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_MAC + FImtblPassportHandleDeepLinkDelegate OnHandleDeepLink; + // Since the second part of PKCE is triggered by deep links, saving the + // response delegate here so it's easier to get + FImtblPassportResponseDelegate PKCEResponseDelegate; + FImtblPassportResponseDelegate PKCELogoutResponseDelegate; + // bool IsPKCEConnected = false; +#endif + + private: void SavePassportSettings(); void LoadPassportSettings();