MetaMask / metamask-snaps-beta

Fork of MetaMask that supports plugins! Read the Wiki!
https://github.com/MetaMask/metamask-snaps-beta/wiki
MIT License
143 stars 57 forks source link

Snap installation configuration #156

Closed mpetrunic closed 2 years ago

mpetrunic commented 4 years ago

What problem are you trying to solve? Snap for different chains should be configurable for different networks (testnet1, testnet2, mainnet).

Describe the solution you'd like I would propose adding params to snap installation on app side:

        await ethereum.send({
          method: 'wallet_enable',
          params: [{
            [snapId]: {
                params: {
                       network: "testnet1"
                }
            }
          }]
        });

And on snap side:

wallet.onInstall(params) {
   if(params.network === "testnet1) {
     wallet.updatePluginState({
         rpcUrl: "wss://testnet1.rpc.com"
     })
  }
}

Additional context It would probably be best if Metamask would wait till onInstall callback finishes before resolving enable function (which would allow us to throw rpc errors in case of invalid configuration).

rekmarks commented 2 years ago

I don't think this is relevant for the current state of the system, and any configuration internal to a snap should be handled by the snap itself after being enabled via its own JSON-RPC interface.