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

Problem: Function RestoreClient is not aysnc (fix #244, #255) #256

Merged
merged 2 commits into from
Feb 2, 2023

Conversation

damoncro
Copy link
Contributor

@damoncro damoncro commented Feb 1, 2023

👮🏻👮🏻👮🏻 !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! 👮🏻👮🏻👮🏻

PR Checklist:

Thank you for your code, it's appreciated! :)

@damoncro damoncro requested a review from a team as a code owner February 1, 2023 07:56
Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does RestoreClient need to be async? To my understanding, it'll just load the session file (which ok, it could be async, but in general, sync should be fast?) and open a websocket connection (but that happens in a background)... is it just for the case to have a notification back to the game if the connection failed to be established?

@damoncro
Copy link
Contributor Author

damoncro commented Feb 1, 2023

why does RestoreClient need to be async? To my understanding, it'll just load the session file (which ok, it could be async, but in general, sync should be fast?) and open a websocket connection (but that happens in a background)... is it just for the case to have a notification back to the game if the connection failed to be established?

Because it has noticeable blocking experience when I call it in ue 5.1, it has to be async. But previously when I tested on ue 4.27, not much blocking experience.

@damoncro
Copy link
Contributor Author

damoncro commented Feb 1, 2023

why does RestoreClient need to be async? To my understanding, it'll just load the session file (which ok, it could be async, but in general, sync should be fast?) and open a websocket connection (but that happens in a background)... is it just for the case to have a notification back to the game if the connection failed to be established?

Two events for notifications are another purpose: One is FOnNewSessionReady, the other is FOnRestoreSessionReady. Those are very important to be used to hide the QR code and return session info to users (either reject or accept). This should fix #244 as well.

If connection failed, no events but errors.

@damoncro damoncro changed the title Problem: Function RestoreClient is not aysnc (fix #255) Problem: Function RestoreClient is not aysnc (fix #244, #255) Feb 1, 2023
Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I haven't tested it, but if laggy/blocking in 5.1, ok to make it async

Comment on lines +234 to +241
/**
* Used for `ConnectWalletConnect`
*/
FString _description;
FString _url;
TArray<FString> _icon_urls;
FString _name;
int64 _chain_id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should those be moved to be private fields instead of public fields? and perhaps grouped in a class/struct with a constructor that will initialise them, so that within the actor, it's guaranteed they are initialised?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yes, should be in private.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked, already in private section:

private:
static ::com::crypto::game_sdk::WalletconnectClient *_coreClient;
static const APlayCppSdkActor *_sdk;
// Internal session result, it will be set after successfully calling
// `EnsureSession`
FWalletConnectEnsureSessionResult _session_result;
/**
* RestoreClient delegate, called after calling
* `RestoreClient`
*/
FRestoreClientDelegate OnRestoreClientDelegate;
/**
* InitializeWalletConnect delegate, called after calling
* `InitializeWalletConnect`
*/
FInitializeWalletConnectDelegate OnInitializeWalletConnectDelegate;
/**
* EnsureSession delegate, called after calling `EnsureSession`
*/
FEnsureSessionDelegate OnEnsureSessionDelegate;
/**
* Used for `ConnectWalletConnect`
*/
FString _description;
FString _url;
TArray<FString> _icon_urls;
FString _name;
int64 _chain_id;
EConnectionType _connection_type = EConnectionType::URI_STRING;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values are only used for function ConnectWalletConnect for users to configure when they call it:
image, seems grouping them is inconvenient for users to set them (they need to make a struct first).

Copy link
Contributor Author

@damoncro damoncro Feb 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They would be initialised when users call ConnectWalletConnect, empty by default except Connection Type.

Copy link
Contributor Author

@damoncro damoncro Feb 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's messy, so far I haven't found a better way to pass those values from ConnectWalletConnect to callback functions or functions called in callback functions, except private values.

Copy link
Collaborator

@leejw51crypto leejw51crypto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@leejw51crypto leejw51crypto merged commit 4aa53c2 into main Feb 2, 2023
@damoncro damoncro deleted the bug/async_restore_client branch February 2, 2023 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants