phantom/docs

Eagerly connecting from an untrusted client should return not throw

fredguest opened this issue · 0 comments

Right now his method:

window.solana.connect({ onlyIfTrusted: true });

throws a funky error that does not look to be by design:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '_bn')

It's tough to diagnose since Phantom does not seem to be open source (?), but that looks like the connect method itself is not catching an internal async error, rather than intentionally throwing a designed error. What would be even better than throwing a designed error though, is just returning a message code to the client without throwing at all.

As it stands, if the client attempts to eagerly connect but is not yet trusted, because of that uncaught async error within the connect method, the client cannot continue execution. So if, for example, you want to toggle a piece of client side state to indicate that an attempt was made to eagerly connect, you can't.

Calling connect({ onlyIfTrusted: true }) from an untrusted client is obviously an expected usage, so it should not result in an uncaught async error, or a designed thrown error, but simply a message code that indicates the client is not yet trusted. This would be much easier to handle from the client, and allow for better UX implementations.