Closed xiaoai7904 closed 1 year ago
+1 same problem without using react
disconnect
event is triggered when TronLink emits accountsChanged
with empty accounts. It seems that TronLink extension has changed their events.
Does the bug occurs in production ? We can publish a hot fix if necessary.
yes, the error appeared after updating the tronLink extension. fixes are needed. thank you!
+1, accountsChanged
and disconnect
are triggered after connect
.
Sorry for any inconvenience. v1.1.8
has fixed this error.
v1.1.8 still not fixed
v1.1.8 still not fixed
I have checked the adapter with the latest TronLink extension(v4.1.3) and it work fine. When i first call adapter.connect()
, it will not disconnect then. Could you please describe the detail of the bug? Thank you!
Sure, Here is my code: @tronweb3/tronwallet-adapters@1.1.8 tronlink extension v4.1.3
const tronLinkAdapter = new TronLinkAdapter();
let address = "";
let chainId = 0;
await tronLinkAdapter.connect();
if (tronLinkAdapter.address) {
address = tronLinkAdapter.address;
try {
const network = await tronLinkAdapter.network(); // call this will throw issue
chainId = parseInt(network.chainId);
} catch (e) {
// catch error here
}
}
Error message:
WalletDisconnectedError: The wallet is disconnected. Please connect first.
Adapter object:
{
_readyState: "Found",
_state: "Connected"
}
Note that It just happen for some times, not always.
Thank you
It seems that TronLink has an issue that when first connect to TronLink, window.tron.tronWeb
is not available immediately. setTimeout
should work fine.
network()
method depends window.tron.tronWeb
to get network information. So error occurs.
You can use the following code when tron.tronWeb
is available.
const chainIdNetworkMap = {
'0x2b6653dc': 'Mainnet',
'0x94a9059e': 'Shasta',
'0xcd8690dc': 'Nile',
};
async function getNetworkInfo() {
const tronWeb = window.tron.tronWeb;
const { blockID = '' } = await tronWeb.trx.getBlockByNumber(0);
const chainId = `0x${blockID.slice(-8)}`;
return {
networkType: chainIdNetworkMap[chainId],
chainId,
fullNode: tronWeb.fullNode?.host || '',
solidityNode: tronWeb.solidityNode?.host || '',
eventServer: tronWeb.eventServer?.host || '',
};
}
"@tronweb3/tronwallet-adapter-react-hooks": "^1.1.4", "@tronweb3/tronwallet-adapter-react-ui": "^1.1.5", "@tronweb3/tronwallet-adapters": "^1.1.6"
Clear the cache and initialize the connection exception for the first time The wallet is successfully connected, but the disconnect event will be triggered at the end, and the address will be assigned a null value, resulting in an abnormal page display