Concordium / concordium-dapp-libraries

A coherent set of building blocks for making it as easy as possible for developers to build web-based dApps.
Apache License 2.0
7 stars 5 forks source link

useConnect: Make connect function undefined until connector is ready #60

Closed bisgardo closed 3 months ago

bisgardo commented 3 months ago

This prevents the connect function from being called before WalletConnectionProps.activeConnector is ready as the call would then fail. The expectation is that the button/function invoking connect checks that doing so is valid. With this change that check is now more direct and less error-prone.

This a only barely a breaking change because the expected usage of passing the function to onClick of a button keeps working without modification. The difference is that now the click is a noop if the call is invaild instead of an exception being thrown. And checking validity is just the truthiness value of connect. In other words you can now just do

<Button type="button" onClick={connect} disabled={!connect}>Connect</Button>

Nice and simple.

An alternative solution would be to return an additional boolean isReadyToConnect, but that would not allow the type system to prevent the call like it does with this one.