svelte-on-solana / wallet-adapter

Svelte wallet adapter for Solana Dapps
https://solana-svelte-counter.netlify.app/
Apache License 2.0
61 stars 24 forks source link

Wallet Store vs. Workspace Store #43

Closed gaylonalfano closed 2 years ago

gaylonalfano commented 2 years ago

Hi there! Fantastic adapter and thank you so much for putting this together! I didn't know where best to reach out (if there is a Discord server or something, please let me know). A few quick questions for you:

  1. It seems like I can access the same info using either the Wallet Store or the Workspace Store (via provider.wallet). Is there a difference that I'm missing?
  2. When building our Anchor/Mocha tests for our program, we often need to pass the Wallet Keypair as the signer (e.g., program.methods.my_function().accounts().signers([wallet]).rpc();). However, I didn't have to do that in the frontend at all. Is that expected? Only after I removed the .signers() call did it transact with my on-chain program.
  3. Related to #2, how would I access (or am I not suppose to) the connected wallet's Keypair object? Can this be done or is it hidden for security purposes from the Phantom wallet?

Again, thank you so much for this helpful package and thanks for clarifying these questions for me.

Cheers!

silvestrevivo commented 2 years ago

Hi @gaylonalfano my apologies for my late reaction, I was some days off because vacations. Thanks so much for reaching me out, I will try to explain one by one your questions:

  1. walletStore it not the same than workSpace. Both are Svelte stores but the first is the wallet itself, or in other words, the store is loaded every time you connect your wallet. The second one is a store mounted after the connection too, but with some useful data to be shared among your components. Why are they separated? workSpace store is different when you work with Anchor or Solana, and I didn't want to contaminate the walletStore with data with another purpose.
  2. I don't understand very well your question, but it seems that is outside the scope of the wallet. When you test with Anchor/Mocha, you don't need to use the keypair coming from the wallet installed, or at least is not mandatory.
  3. This is solved with the last update I made today. It should work everything ok.

Please, let me know if you have more questions. You can find me on Discord too silvestrevivo#8027

gaylonalfano commented 2 years ago

Thank you for the reply! I've been experimenting with this for the past few days and have gradually learned the differences between the two, but thank you for clarifying!

One question I have for you is how would you recommend using this wallet adapter when dealing with multiple Anchor programs inside a single repo?

Here's my working example for reference but just curious if this is a good approach. You'll see I've cloned your other project dapp-scaffold-svelte into a starter Anchor project (anchor init). I then created multiple generic programs using anchor new [program-name]. I had to reset the AnchorConnectionProvider inside new routes to update the Anchor workspace. So far it seems to work just fine, but curious if this is how you'd do something like this?

I really love the simplicity of Svelte for my simple needs, so thank you again for integrating it so nicely with Anchor! Really has sped up my development. Ciao for now!

silvestrevivo commented 2 years ago

I think your approach is correct, but if I am not wrong, you can not use at the same time different anchor programs injected in the front end. The way to switch between contracts in the frontend is importing the IDL of each of the contracts. Does that make sense for your problem?

gaylonalfano commented 2 years ago

Yes, this is what I've been experimenting with and so far it's working well swapping in/out IDLs. I'm not sure if this is a sound approach, but it's working well and it's nice for me to experiment with various simple programs via the frontend/UI.

Again, thank you so much for your contributions! It's very educational for me reading through your code!