magicblock-labs / Solana.Unity-SDK

Open-Source Unity-Solana SDK with Full RPC coverage, NFT support and more
https://solana.unity-sdk.gg
MIT License
153 stars 85 forks source link

[Bug] In the example project, LoginXNFT from ModelH class don't work. #50

Closed mixmob-julio closed 1 year ago

mixmob-julio commented 1 year ago

Describe the bug The example project always fails to login when the user created/loaded a wallet already .

To Reproduce 1 - Run the example project and click in the wallet icon in the center of the screen; 2 - Load/Create a Wallet; 3 - Leave the wallet screen and go to the main screen where the wallet button is. 4 - Hit the wallet button again and expect to go direct to the wallet screen;

Expected behavior A internal logind should be done and the user should be led to the WEallet screen. But it always fails, the example project should be able to do login but it fails and always shows the login screen;

Screenshots The screenshot below shows the part of the code inside LoginScreen.cs. This part of the code is responsible for testing the login (line 92), and if success, lead the user to the Wallet screen(line 103). bug

Unity Editor :

Additional context The problem happens in the line 92 (see image above). The LoginXNFT from WalletH is not working and the entire flow is interrupted. The LoginXNFT method from WalletH creates a XNFTWallet object and the Login method from this class is probably the source of the problem.

GabrielePicco commented 1 year ago

Hi @mixmob-julio , are you trying to create the wallet inside an XNFT (running in backpack)?

With a normal flow, the creare/import wallet works and show the wallet screen afterward, you can check in the live demo here: https://garbles-labs.github.io/Solana.Unity-SDK/

For an XNFT, running inside backpack, unfortunately AFAIK there is no way to create a wallet. The LoginXNFT will be called automatically and you will be logged with backpack account. Hope this helps.

mixmob-julio commented 1 year ago

No, I'm just playing with your example project. Yes, after you load/create a wallet the app goes to the wallet screen, but this is not the problem. The real problem is in the example project in the script LoginScreen.cs. This part of the code is responsible for testing the login (line 92), if success should lead the user to the Wallet screen(line 103) directly, without a manual login or the need to load/create a new wallet. This part is not working. I think the problem is in the ModelH.instance.LoginXNFT call. The method LoginXNFT calls the login method from a fresh new XNFTWallet objected just created. This method returns nothing, triggers no error, and do nothinfg else at this time forcing the user to go to the LoginScreen everytime, and not leading the user to the WalletScreen in case of a successful login.

GabrielePicco commented 1 year ago

Hi @mixmob-julio ,

The user always perform a manual login when using an in-game wallet in the demo scene, the private key is stored encrypted, therefore the game need to ask the password at login time in order to decrypt and restore the public/private key.

It's possible to delay the login until the first transaction approval is required tough, and show the balance/wallet screen just using the public key. Is this what you are trying to achieve?

The LoginXNFT is only used for XNFT inside backpack, in which case the login is automatic and all the signing is delegated to backpack.

mixmob-julio commented 1 year ago

@GabrielePicco thansk for the clarification. I could not find a doc explaning that, nor the other kinds of logins. Are you planing to extend the current documentation?

Answering your question, for now I'm just trying to learn how the example works.

About LoginXNFT , I'm still confused. Is it a requirement? I mean, do I need to LoginXNFT once at every execution? Have you a document for that?

GabrielePicco commented 1 year ago

@mixmob-julio yes the documentation definitely needs to be expanded, there is a short description here: https://solana.unity-sdk.gg/docs/configuration . We will expand it, also fell free to contribute, this is a community driven SDK.

Docs is here: https://github.com/garbles-labs/Solana.Unity-SDK/tree/docs/src/pages/docs , the website is automatically rendered form the markdown files there.

LoginXNFT is only used when used/working when inside an XNFT (in Backpack), you can read more here: https://solana.unity-sdk.gg/docs/xnft In all the other cases LoginXNFT will just fail and users can login with standard login methods.

I will close this issue for now, as it doesn't require changes, feel free to start a discussion on Github or Discord for more details or clarification.