anza-xyz / wallet-adapter

Modular TypeScript wallet adapters and components for Solana applications.
https://anza-xyz.github.io/wallet-adapter/
Apache License 2.0
1.61k stars 964 forks source link

(typing) Allow readonly array of wallets for WalletProvider #1015

Open dearlordylord opened 3 months ago

dearlordylord commented 3 months ago

In mine and some other codebases, immutability goes by default.

The adapter doesn't like it, so the type like const wallets: readonly [PhantomWalletAdapter, SolflareWalletAdapter] won't work:

const useWallets = () => {
  const phantomWallet = new PhantomWalletAdapter();
  const solflareWallet = new SolflareWalletAdapter();
  return useMemo(() => [phantomWallet, solflareWallet] as const, [phantomWallet, solflareWallet]);
}

...

const wallets = useWallets();
<WalletProvider wallets={wallets}/>

I have to either cast or re-construct <WalletProvider wallets={[...wallets]}/>, which is undesirable.

This PR allows readonly arrays as wallets prop, as well as keeps mutable arrays backwards-compatible.