Skip to content

Commit

Permalink
[DX-2975] feat: get linked addresses (#93)
Browse files Browse the repository at this point in the history
* feat: added get linked addresses method

* feat: added get linked addresses node to sample blueprints

* refactor: joined token blueprint node implementations

* fix: updated get token nodes in sample blueprints
  • Loading branch information
YermekG authored Jul 8, 2024
1 parent f9b32f4 commit 8c94880
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 163 deletions.
Binary file not shown.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Fill out your copyright notice in the Description page of Project Settings.

#include "Immutable/Actions/ImtblPassportGetLinkedAddressesAsyncAction.h"

#include "Immutable/ImmutablePassport.h"
#include "Immutable/ImmutableSubsystem.h"
#include "Immutable/Misc/ImtblLogging.h"

UImtblPassportGetLinkedAddressesAsyncAction* UImtblPassportGetLinkedAddressesAsyncAction::GetLinkedAddresses(UObject* WorldContextObject)
{
UImtblPassportGetLinkedAddressesAsyncAction* Node = NewObject<UImtblPassportGetLinkedAddressesAsyncAction>();

Node->WorldContextObject = WorldContextObject;

return Node;
}

void UImtblPassportGetLinkedAddressesAsyncAction::Activate()
{
if (!WorldContextObject || !WorldContextObject->GetWorld())
{
FString Err = "GetLinkedAddresses failed due to missing world or world context object.";

IMTBL_WARN("%s", *Err)
Failed.Broadcast(Err, TArray<FString>());

return;
}

GetSubsystem()->WhenReady(this, &UImtblPassportGetLinkedAddressesAsyncAction::DoGetLinkedAddresses);
}

void UImtblPassportGetLinkedAddressesAsyncAction::DoGetLinkedAddresses(TWeakObjectPtr<UImtblJSConnector> JSConnector)
{
auto Passport = GetSubsystem()->GetPassport();

if (Passport.IsValid())
{
Passport->GetLinkedAddresses(UImmutablePassport::FImtblPassportResponseDelegate::CreateUObject(this, &UImtblPassportGetLinkedAddressesAsyncAction::OnGetLinkedAddressesResponse));
}
}

void UImtblPassportGetLinkedAddressesAsyncAction::OnGetLinkedAddressesResponse(FImmutablePassportResult Result)
{
if (Result.Success)
{
Success.Broadcast(TEXT(""), UImmutablePassport::GetResponseResultAsStringArray(Result.Response));
}
else
{
Failed.Broadcast(Result.Error, TArray<FString>());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Fill out your copyright notice in the Description page of Project Settings.

#include "Immutable/Actions/ImtblPassportGetTokenAsyncAction.h"

#include "Immutable/ImmutablePassport.h"
#include "Immutable/ImmutableSubsystem.h"
#include "Immutable/Misc/ImtblLogging.h"

UImtblPassportGetTokenAsyncAction* UImtblPassportGetTokenAsyncAction::GetAccessToken(UObject* WorldContextObject)
{
UImtblPassportGetTokenAsyncAction* Node = NewObject<UImtblPassportGetTokenAsyncAction>();

Node->WorldContextObject = WorldContextObject;
Node->Type = ACCESS;

return Node;
}

UImtblPassportGetTokenAsyncAction* UImtblPassportGetTokenAsyncAction::GetIdToken(UObject* WorldContextObject)
{
UImtblPassportGetTokenAsyncAction* Node = NewObject<UImtblPassportGetTokenAsyncAction>();

Node->WorldContextObject = WorldContextObject;
Node->Type = ID;

return Node;
}

void UImtblPassportGetTokenAsyncAction::Activate()
{
if (!WorldContextObject || !WorldContextObject->GetWorld())
{
FString Err = "Get Token failed due to missing world or world context object.";
IMTBL_WARN("%s", *Err)
Failed.Broadcast(Err, TEXT(""));
return;
}


GetSubsystem()->WhenReady(this, &UImtblPassportGetTokenAsyncAction::DoGetToken);
}

void UImtblPassportGetTokenAsyncAction::DoGetToken(TWeakObjectPtr<UImtblJSConnector> JSConnector)
{
auto Passport = GetSubsystem()->GetPassport();

if (Passport.IsValid())
{
switch(Type)
{
case ID:
Passport->GetIdToken(UImmutablePassport::FImtblPassportResponseDelegate::CreateUObject(this, &UImtblPassportGetTokenAsyncAction::OnGetTokenResponse));
break;
case ACCESS:
Passport->GetAccessToken(UImmutablePassport::FImtblPassportResponseDelegate::CreateUObject(this, &UImtblPassportGetTokenAsyncAction::OnGetTokenResponse));
break;
}
}
}

void UImtblPassportGetTokenAsyncAction::OnGetTokenResponse(FImmutablePassportResult Result)
{
if (Result.Success)
{
Success.Broadcast(TEXT(""), UImmutablePassport::GetResponseResultAsString(Result.Response));
}
else
{
Failed.Broadcast(Result.Error, TEXT(""));
}
}
25 changes: 24 additions & 1 deletion Source/Immutable/Private/Immutable/ImmutablePassport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ void UImmutablePassport::GetEmail(const FImtblPassportResponseDelegate& Response
CallJS(ImmutablePassportAction::GetEmail, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnBridgeCallbackResponse));
}

void UImmutablePassport::GetLinkedAddresses(const FImtblPassportResponseDelegate& ResponseDelegate)
{
CallJS(ImmutablePassportAction::GetLinkedAddresses, TEXT(""), ResponseDelegate, FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::OnBridgeCallbackResponse));
}

void UImmutablePassport::ImxTransfer(const FImxTransferRequest& RequestData, const FImtblPassportResponseDelegate& ResponseDelegate)
{
IMTBL_LOG("Tranfer Request: %s", *UStructToJsonString(RequestData))
Expand Down Expand Up @@ -223,7 +228,6 @@ FString UImmutablePassport::GetResponseResultAsString(const FImtblJSResponse& Re
}

return Response.JsonObject->GetStringField(TEXT("result"));

}

bool UImmutablePassport::GetResponseResultAsBool(const FImtblJSResponse& Response)
Expand All @@ -238,6 +242,25 @@ bool UImmutablePassport::GetResponseResultAsBool(const FImtblJSResponse& Respons
return Response.JsonObject->GetBoolField(TEXT("result"));
}

TArray<FString> UImmutablePassport::GetResponseResultAsStringArray(const FImtblJSResponse& Response)
{
if (!Response.JsonObject.IsValid())
{
IMTBL_ERR("Response JSON data for %s is not valid", *Response.responseFor)

return TArray<FString>();
}

TArray<FString> StringArray;

for (const TSharedPtr<FJsonValue>& Value : Response.JsonObject->GetArrayField(TEXT("result")))
{
StringArray.Add(Value->AsString());
}

return StringArray;
}


void UImmutablePassport::Setup(const TWeakObjectPtr<UImtblJSConnector> Connector)
{
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "ImtblBlueprintAsyncAction.h"

#include "ImtblPassportGetLinkedAddressesAsyncAction.generated.h"

/**
* The Blueprint node retrieves a list of wallet addresses linked to the passport wallet.
*/
UCLASS()
class IMMUTABLE_API UImtblPassportGetLinkedAddressesAsyncAction : public UImtblBlueprintAsyncAction
{
GENERATED_BODY()

DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FPassportGetLinkedAddressesOutputPin, FString, ErrorMessage, const TArray<FString> &, Addresses);

public:
UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", BlueprintInternalUseOnly = "true"), Category = "Immutable")
static UImtblPassportGetLinkedAddressesAsyncAction* GetLinkedAddresses(UObject* WorldContextObject);

virtual void Activate() override;

private:
void DoGetLinkedAddresses(TWeakObjectPtr<class UImtblJSConnector> JSGetConnector);
void OnGetLinkedAddressesResponse(struct FImmutablePassportResult Result);

UPROPERTY(BlueprintAssignable)
FPassportGetLinkedAddressesOutputPin Success;
UPROPERTY(BlueprintAssignable)
FPassportGetLinkedAddressesOutputPin Failed;
};
Loading

0 comments on commit 8c94880

Please sign in to comment.