Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dearlordylord
Copy link

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.

@@ -49,7 +49,7 @@ export function WalletProvider({
onError,
}: WalletProviderProps) {
const { connection } = useConnection();
const adaptersWithStandardAdapters = useStandardWalletAdapters(adapters);
const adaptersWithStandardAdapters = useStandardWalletAdapters(adapters as Adapter[]);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would require same improvement for useStandardWalletAdapters of @solana/wallet-standard-wallet-adapter-react

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant