Skip to content

Commit

Permalink
Problem: Can not query walletconnect status (fix #214, #257)
Browse files Browse the repository at this point in the history
Close:
- #214
- #257

Solutions:
- Remove AsyncTask on sendEvent
- Add internal _session_info and remove const
- Add public function: GetWalletConnectSessionInfo
  • Loading branch information
damoncro committed Feb 6, 2023
1 parent 4aa53c2 commit 4853619
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
13 changes: 7 additions & 6 deletions Source/CronosPlayUnreal/Private/PlayCppSdkActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ FWalletConnectSessionInfo::FWalletConnectSessionInfo() {

::com::crypto::game_sdk::WalletconnectClient *APlayCppSdkActor::_coreClient =
NULL;
const APlayCppSdkActor *APlayCppSdkActor::_sdk = NULL;
APlayCppSdkActor *APlayCppSdkActor::_sdk = NULL;

class UserWalletConnectCallback : public WalletConnectCallback {
public:
Expand All @@ -47,7 +47,7 @@ class UserWalletConnectCallback : public WalletConnectCallback {
void onUpdated(const WalletConnectSessionInfo &sessioninfo) const;
};

const APlayCppSdkActor *APlayCppSdkActor::getInstance() { return _sdk; }
APlayCppSdkActor *APlayCppSdkActor::getInstance() { return _sdk; }

// Sets default values
APlayCppSdkActor::APlayCppSdkActor() {
Expand Down Expand Up @@ -633,11 +633,12 @@ void APlayCppSdkActor::SignEip155Transaction(
});
}

void APlayCppSdkActor::sendEvent(FWalletConnectSessionInfo info) const {
void APlayCppSdkActor::sendEvent(FWalletConnectSessionInfo info) {

AsyncTask(ENamedThreads::GameThread, [this, info]() {
this->OnReceiveWalletconnectSessionInfoDelegate.ExecuteIfBound(info);
});
this->_session_info = info;
UE_LOG(LogTemp, Log, TEXT("send event: %s"),
*UEnum::GetValueAsString(this->_session_info.sessionstate));
this->OnReceiveWalletconnectSessionInfoDelegate.ExecuteIfBound(info);
}

void UserWalletConnectCallback::onConnected( // NOLINT : flase positive, virtual
Expand Down
17 changes: 14 additions & 3 deletions Source/CronosPlayUnreal/Public/PlayCppSdkActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ class CRONOSPLAYUNREAL_API APlayCppSdkActor : public AActor {
private:
static ::com::crypto::game_sdk::WalletconnectClient *_coreClient;

static const APlayCppSdkActor *_sdk;
static APlayCppSdkActor *_sdk;

// Internal session info, it will be updated every time walletconnect status changes
FWalletConnectSessionInfo _session_info;

// Internal session result, it will be set after successfully calling
// `EnsureSession`
Expand Down Expand Up @@ -247,7 +250,7 @@ class CRONOSPLAYUNREAL_API APlayCppSdkActor : public AActor {
FWalletconnectSessionInfoDelegate OnSetupCallbackDelegate;

public:
static const APlayCppSdkActor *getInstance();
static APlayCppSdkActor *getInstance();

// Sets default values for this actor's properties
APlayCppSdkActor();
Expand Down Expand Up @@ -279,6 +282,14 @@ class CRONOSPLAYUNREAL_API APlayCppSdkActor : public AActor {
}
const int64 GetChainId() const { return _session_result.chain_id; }

UFUNCTION(BlueprintCallable,
meta = (DisplayName = "GetWalletConnectSessionInfo",
Keywords = "PlayCppSdk"),
Category = "PlayCppSdk")
FWalletConnectSessionInfo GetWalletConnectSessionInfo() {
return _session_info;
}

protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
Expand Down Expand Up @@ -493,7 +504,7 @@ class CRONOSPLAYUNREAL_API APlayCppSdkActor : public AActor {
/**
* send wallet-connect information to unreal game thread
*/
void sendEvent(FWalletConnectSessionInfo) const;
void sendEvent(FWalletConnectSessionInfo);

static void destroyCoreClient();

Expand Down

0 comments on commit 4853619

Please sign in to comment.