GigaDAO / wasi-sol

💳 A Solana Wallet adapter for WASM frameworks (WIP).
https://wasi-sol.netlify.app/
MIT License
18 stars 4 forks source link

Connect to uninstalled Phantom wallet panics #13

Closed painedpineapple closed 2 months ago

painedpineapple commented 3 months ago

I noticed in the dioxus example that you shared on x that the app panics when you attempt to connect to the phantom wallet and that wallet is not installed. I haven't dug into this yet but am assuming the way to resolve this is to check for available wallets before rendering the buttons, or raise the error to the UI level. I'll touch base here once I've had the opportunity to integrate wasi-sol. This may not be an issue for the lib at all but just the example, but I do think it would be helpful to have a way to detect wallets that are installed if that's not already implemented.

wiseaidev commented 3 months ago

Thanks for filing this issue, @painedpineapple!

The reason for the panic is because the bindgen method currently returns a Promise and not a Result:

https://github.com/GigaDAO/wasi-sol/blob/bae5ba6ba67842514aee77a6ddef7088fd166977/src/core/wallet.rs#L134 https://github.com/GigaDAO/wasi-sol/blob/bae5ba6ba67842514aee77a6ddef7088fd166977/src/adapter/phantom.rs#L50-L51

One way to fix this is by checking if the wallet object exists before invoking connect/sign_in methods:

https://github.com/GigaDAO/wasi-sol/blob/bae5ba6ba67842514aee77a6ddef7088fd166977/src/core/wallet.rs#L128-L132

Similar to what is already implemented to discover whether or not the wallet is installed:

https://github.com/GigaDAO/wasi-sol/blob/bae5ba6ba67842514aee77a6ddef7088fd166977/src/forms/yew/login.rs#L112-L117

I hope this clarifies the reason for this issue. We welcome PRs, so feel free to contribute if you'd like. Otherwise, I will tackle it this weekend.

Best!