vechain / vechain-dapp-kit

An SDK for vechain dApp development
MIT License
1.62k stars 8 forks source link

DAppKitProvider with custom nodeUrl does not detect genesis id #235

Open ifavo opened 4 months ago

ifavo commented 4 months ago

When setting up a DAppKitProvider with react using only the nodeUrl, it will switch VeWorld to MainNet.

Example:

<DAppKitProvider
    // the network & node to connect to
    nodeUrl="https://testnet.vechain.org"
    // remember last connected address on page reload
    usePersistence={true}
>
    {children}
</DAppKitProvider>

My personal expected behavior is that it will automatically detect the network/genesis and use it, according to the nodeUrl.

If this is correct behavior, may I suggest to either detect the genesis id automatically using the given nodeUrl or make the genesis mandatory, to prevent confusion during setup?

darrenvechain commented 4 months ago

If we were able to initiate connex without the genesis block this wouldn't be a problem, as we could then (async) fetch the genesis block prior to making the wallet interaction.

Automatically detecting the network could also have a potential problem. Its an async action, as we have to fetch the genesis block. If the dapp were to automatically request a wallet interaction on page load (weird use case, but possible), that could potentially request the action before the network is detected.

One approach could be to fetch the genesis inside the DAppKitProvider and don't return the child components until we have the genesis, but this could lead to lead to a bad UX if the API call fails.

ifavo commented 4 months ago

I understand the impact on the UI, I would not want to delay a render, while a re-render might be acceptable.

In my scenario a transaction is built, which is where I am willing to pay for an additional network request before its requested for signing in the wallet.

Is the genesis id needed in other situations where a network request is not possible to lazily detect the id?