web3.unity icon indicating copy to clipboard operation
web3.unity copied to clipboard

Wallet Connection Prefab

Open rob1997 opened this issue 1 year ago • 8 comments

Summary We currently have multiple wallet connection providers [Wallet Connect, MetaMask, Web3Auth, HyperPlay] and use single scenes for each, we can unify these providers into one prefab

Suggested features or ways to address the summary We can have ILoginProviders added to this prefab to load providers during runtime.

Motivation Easier for User to simply drag prefab into their scene for usage We can have handle different wallet connections via an abstraction

Acceptance Criteria We can use multiple wallet connection providers from a single scene using a single prefab.

Blockers (OPTIONAL) [Do you see any blocker that needs to be done before implementing this feature?]

Dependencies (OPTIONAL) [Do you know about dependencies that directly affect this issue?]

Additional Context (OPTIONAL) [Add any other context, files, images (screenshots/videos), diagrams, or documents about the feature request here.]

Final Steps

  • Give it one of these labels Type: Feature Type: Enhancement
  • Add your estimation

Estimations

| 5 | Moderate efort | A few days | Mediium complexity | Moderate |

rob1997 avatar Jun 10 '24 10:06 rob1997

UI Flow

wallet_prefab_ui_flow

rob1997 avatar Jul 02 '24 06:07 rob1997

Work Breakdown

PR 1

Refactor Web3Auth to use WalletProvider

  • Refactor InProcessSigner and InProcessTransactionExecutor to be injected instead of initialized in Web3AuthWalllet
  • Refactor Web3AuthWallet -> Web3AuthProvider : WalletProvider
  • IWeb3 wrapper that can injected to pass web3 initialized with a private key
  • cleanup more of Web3Auth GUI (multiple input handling) and move Web3AuthTransactionHandler to Web3AuthTransactionExecutor and Web3AuthProvider

PR 2

Create prefab Visuals

  • Connection Overlay, Loading Overlay, Error modal and a way to list out providers as Prefabs

PR 3

  • Refactor LoginProvider to be ConnectionProvider that can support connection providers as IWeb3BuilderServiceAdapter
  • Connect Providers/Login provider to Prefab, Have a custom editor for Login Provider that can add/remove providers as IWeb3BuilderServiceAdapter
  • Handle WalletConnection to work with the loading overlay and other parts of the Wallet prefab

PR 4

    • Create WalletConnection which can be restored for restorable providers, Add WalletConnection IWalletProvider.Restore() and have IWalletProvider.Connect() return WalletConnection
  • Have IWalletProviderConfig handle restoring sessions for providers
  • Remove previous LoginProviders to replace with ConnectionProviders
  • Make sure all providers work
  • Create a disconnect/logout prefab with an optional display for account (with a copy option) that's instantiated on Login [optional]

rob1997 avatar Jul 02 '24 06:07 rob1997

Restorable providers -> The ones that can remember the session? I am not sure if any of the providers we currently have can't save the session? But good to think in advance :D

kantagara avatar Jul 02 '24 10:07 kantagara

I like everything you have wrote Rob! LGTM 👍

kantagara avatar Jul 02 '24 10:07 kantagara

Good work, Rob. Yet there are points I want to discuss.

  1. We create Web3 before "Provider prompts connection". This operation is a consequence of creating (Launching) a web3 instance.
  2. What is the purpose of Logout prefab? Why not let users call a public method to logout?
  3. IWeb3 wrapper that can injected to pass web3 initialized with a private key

  4. What do you mean here? What is the function of IWeb3 wrapper and what is its relationship with other parts of the system?
  5. Please describe the entity (service, class) the developer is going to interact with to show the overlay, how it will be configured, and how it would relate to the existing Web3Builder/Web3 systems.
  6. The current LoginProvider implementation is cumbersome. If we're going to refactor this part of the project heavily, then it would be nice to see the whole inheritance hierarchy removed in favor of composition-based code.

oleksandrchainsafe avatar Jul 02 '24 13:07 oleksandrchainsafe

Good work, Rob. Yet there are points I want to discuss.

  1. We create Web3 before "Provider prompts connection". This operation is a consequence of creating (Launching) a web3 instance.
  2. What is the purpose of Logout prefab? Why not let users call a public method to logout?
  3. IWeb3 wrapper that can injected to pass web3 initialized with a private key

  4. What do you mean here? What is the function of IWeb3 wrapper and what is its relationship with other parts of the system?
  5. Please describe the entity (service, class) the developer is going to interact with to show the overlay, how it will be configured, and how it would relate to the existing Web3Builder/Web3 systems.
  6. The current LoginProvider implementation is cumbersome. If we're going to refactor this part of the project heavily, then it would be nice to see the whole inheritance hierarchy removed in favor of composition-based code.
  1. I don't follow
  2. We will have that but this would be a good feature to have it as an option
  3. It's for process signer and txn executor, a way to abstract the private key, it's NEthereum's web3 not ours
  4. It's going to be a refactor of the already existing LoginProvider and it'll work the same with a few modifications I mentioned above
  5. That's probably how's it's going to end up since current concrete implementations are gonna end up being IWeb3BuilderServiceAdapter

rob1997 avatar Jul 02 '24 13:07 rob1997

  1. Sorry. I was referring to your diagram. There is a step "Provider prompts connection" and it comes before we build Web3. Prompting connection is currently a part of Web3 initialization flow. It is invoked when you build Web3 instance.
  2. Yeah, but what is that prefab for? What functionality does it provide?
  3. Can you elaborate more?

4-5. I see. Then we need to have a dependency diagram describing new/refactored components, before proceeding. It's hard to see what you're proposing without it.

oleksandrchainsafe avatar Jul 02 '24 14:07 oleksandrchainsafe

  1. Sorry. I was referring to your diagram. There is a step "Provider prompts connection" and it comes before we build Web3. Prompting connection is currently a part of Web3 initialization flow. It is invoked when you build Web3 instance.
  2. Yeah, but what is that prefab for? What functionality does it provide?
  3. Can you elaborate more?

4-5. I see. Then we need to have a dependency diagram describing new/refactored components, before proceeding. It's hard to see what you're proposing without it.

  1. Yep, that's what I mean
  2. Just Logging out/disconnect and displaying public address
  3. Currently we use private key for In Process signer and txn executor, and we initialize a web3 object for both using the private key, 2 issues here are 1, easy access to private key (public property) 2, NEthereum's web3 object is being created more than once, we can create one instance and reference/inject it where we need it
  4. Sure I'll get to that when I reach PR 3

rob1997 avatar Jul 02 '24 16:07 rob1997

connection @oleksandrchainsafe here's the class diagram for PR3, I've also updated PR4 by moving session restoration form PR3 to PR4

rob1997 avatar Jul 10 '24 12:07 rob1997

Looks good, yet hard to envision the final result IMO.

Please make sure users can manage: a) time of initialization of web3, b) where web3 is stored (not force them into using Web3Accessor), c) which modules are used for the particular web3 instance from code (do not restrict them into using inspector only).

oleksandrchainsafe avatar Jul 17 '24 13:07 oleksandrchainsafe

Looks good, yet hard to envision the final result IMO.

Please make sure users can manage: a) time of initialization of web3, b) where web3 is stored (not force them into using Web3Accessor), c) which modules are used for the particular web3 instance from code (do not restrict them into using inspector only).

I've already implemented this since last week here

a) could you elaborate more b) we actually have further plans for Web3Accessor and we're going to expand on it here so we're keeping it in core pkg but I can have ConnectionHandler.TryConnect return Web3 object c) Inspector window?? we have a custom editor for adding/removing providers but devs can also implement their own providers

rob1997 avatar Jul 17 '24 15:07 rob1997