Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init connection event sequence exception #24

Closed
xiaoai7904 opened this issue Jul 31, 2023 · 9 comments
Closed

Init connection event sequence exception #24

xiaoai7904 opened this issue Jul 31, 2023 · 9 comments

Comments

@xiaoai7904
Copy link

image image image image

"@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

@pdazcom
Copy link

pdazcom commented Aug 1, 2023

+1
same problem without using react

@way2ex
Copy link
Contributor

way2ex commented Aug 2, 2023

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.

@pdazcom
Copy link

pdazcom commented Aug 2, 2023

yes, the error appeared after updating the tronLink extension. fixes are needed. thank you!

@alienzhangyw
Copy link

+1, accountsChanged and disconnect are triggered after connect.

@way2ex
Copy link
Contributor

way2ex commented Aug 22, 2023

Sorry for any inconvenience. v1.1.8 has fixed this error.

@lytieuphong
Copy link

lytieuphong commented Oct 10, 2023

v1.1.8 still not fixed

@way2ex
Copy link
Contributor

way2ex commented Oct 11, 2023

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!

@lytieuphong
Copy link

lytieuphong commented Oct 11, 2023

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
      }
    }
  1. Connect success
  2. Lock wallet from Tron Link extension
  3. Reload Dapp then click connect to TronLink

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

@way2ex
Copy link
Contributor

way2ex commented Oct 11, 2023

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.
image

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 || '',
    };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants