Proposal about how to connect DApp with Injected Wallet in Solana

There are several requirements:

  1. sol-wallet-adapter can be used for both web wallet (ex: sollet.io) and injected wallet (chrome extension & App) so that DApp do not need to change any code for web wallet or injected wallet.

  2. Injected wallet should not block the web wallet, so that user can select the wallet preferred. If only match the injected object window.solana exist, the injected wallet will take control even if the user's selection is a web wallet, and will block the web wallet.

Code PR

https://github.com/project-serum/sol-wallet-adapter/pull/8/files

The mainly change for this PR is to compare:
window.solana.providerUrl.origin === this._providerUrl.origin

window.solana.providerUrl is from the injected wallet.
this._providerUrl is from the DApp fronend.

Only if they are the same, the injected wallet will take control.

Injected Wallet Needs To

Injected wallet does not need to update any code in sol-wallet-adapter.
Injected wallet needs to add below object in their own injected solana object.

For example:
solana.providerUrl = new URL("https://www.mathwallet.org");

DApp Needs To

  1. Install latest version of sol-wallet-adapter
    https://github.com/project-serum/sol-wallet-adapter

  2. Add supported wallet to the wallet list and the url value for injected wallet should match the url provided by injected wallet. (Normally the wallets will submit PR to the DApp repo, and DApp just need to approve the PR)

For example:
https://github.com/mathwallet/oyster-swap/blob/master/src/utils/wallet.tsx

export const WALLET_PROVIDERS = [
{ name: "sollet.io", url: "https://www.sollet.io" },
{ name: "solongwallet.com", url: "http://solongwallet.com" },
{ name: "solflare.com", url: "https://solflare.com/access-wallet" },
{ name: "mathwallet.org", url: "https://www.mathwallet.org" },
];