wallet-selector icon indicating copy to clipboard operation
wallet-selector copied to clipboard

[Research] Multiple contract support

Open austinabell opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe.

Currently, the wallet selector modal APIs do not allow for managing function call access keys. APIs might have to change in the wallet selector core APIs as well to be able to check if there is an access key for the given contract, or just to ensure they are signed into an injected wallet.

The reason this is useful/necessary is if someone wanted to interact with multiple contracts within the same frontend, they would need to sign in and generate a function call access key for each time they interact with a new contract (using a hosted wallet).

This is a problem because not only is it a bad UX, but also it charges unnecessary gas by throwing away usable function call access keys. The pattern of interact with contract A -> interact with contract B -> interact with contract A requires that you generate two function call access keys for interacting with contract A when you should only need one.

The assumption based on how the code is set up is that there is a 1:1 mapping of wallet -> contract, which is very invalid.

Describe the solution you'd like

  • Keep contractId mandatory and expose a method to switch the contract, like updateContractId as a callback (along with hide and show)
    • Alternatively: Modal show method takes a contractId parameter (optional) and make the contractId parameter of ModalOptions optional as well. Assumption is error would be thrown if neither is used. This might be able to be restricted based on TS type system (in theory it should be able to be) so that either is required.
  • Assumption that wallets maintain contract id -> access key mappings, if not, adjust the selector core APIs to convey the switch in account or expose the generated access keys from the selector. (unclear the semantics around requestSignIn , is the implication that it will force another sign in, or if it's already signed in for the account it will short-circuit?)

Describe alternatives you've considered

Acceptance criteria Allow interacting with multiple contracts with a single wallet selector

Additional context Motivation is for building a frontend that interacts with contracts dynamically at runtime.

austinabell avatar Aug 16 '22 20:08 austinabell

@austinabell This currently is not possible to add because wallets like MyNearWallet only allow you to one add access key to one contract when signing in. This will need to first be addressed on the wallet side and/or to update the near-api-js library.

Right now we call the sign in function like this: wallet.requestSignIn({ contractId, methodNames }). Maybe we can have something like this: wallet.requestSignIn([{ contractId, methodNames }, { contractId, methodNames }]); which will allow us to add multiple access keys with one approve/sign in.

Example of adding full access key to guest-book.testnet when signing in: image

In explorer you can see that we only create a full access key for guest-book.testnet. image

This looks like a big change, I am not completely sure about how to approach this. Maybe @MaximusHaximus can comment more on this.

amirsaran3 avatar Sep 29 '22 08:09 amirsaran3

Currently with MyNearWallet there is no way to generate multiple function call access keys for different contracts with one sign in. This is the limitation of some wallets that is preventing us to continue with this task.

The new Injected Wallet NEP suggests to use only one or more contract id when signing in. This will allow us to use multiple contracts.

After we align the wallet standards to be like Injected Wallets then we can integrate this feature.

amirsaran3 avatar Nov 14 '22 11:11 amirsaran3

Ammar Humackic commented:

Daryl Collins will make sure Injected Wallet NEP and Bridge Wallet NEP have this added.

exalate-issue-sync[bot] avatar Nov 14 '22 17:11 exalate-issue-sync[bot]

+1

bmeeder22 avatar Jan 12 '23 21:01 bmeeder22

Closing this as it will be covered by the work in: https://github.com/near/wallet-selector/pull/811

AmmarHumackicSQA avatar Jul 24 '23 15:07 AmmarHumackicSQA