vechain-dapp-kit
vechain-dapp-kit copied to clipboard
DAppKitProvider with custom nodeUrl does not detect genesis id
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>
- Creating a transaction request within the providers context using the thor client from
useConnex()
will automatically switch to MainNet. - When the genesis is explicitly defined
genesis="test"
, it will switch to TestNet.
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?
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.
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?