Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit eaaac80

Browse files
authored
Merge pull request #25 from tronprotocol/release/v1.1.8
fix(tronlink): fix TronLink disconnect incorrectly after connection
2 parents 6b98b67 + aeb168e commit eaaac80

File tree

7 files changed

+28
-22
lines changed

7 files changed

+28
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tronwallet-adapter",
33
"description": "wallet adapters for TRON blockchain",
4-
"version": "1.1.7",
4+
"version": "1.1.8",
55
"main": "index.js",
66
"sideEffects": false,
77
"private": true,

packages/adapters/adapters/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tronweb3/tronwallet-adapters",
3-
"version": "1.1.6",
3+
"version": "1.1.7",
44
"description": "Wallet adapters to help developers interact with Tron wallets using consistent API.",
55
"keywords": [
66
"TRON",

packages/adapters/tronlink/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tronweb3/tronwallet-adapter-tronlink",
3-
"version": "1.1.6",
3+
"version": "1.1.7",
44
"description": "Wallet adapter for TronLink Wallet extension and TronLink app.",
55
"keywords": [
66
"TRON",

packages/adapters/tronlink/src/adapter.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,15 +440,16 @@ export class TronLinkAdapter extends Adapter {
440440
this.emit('chainChanged', data);
441441
};
442442

443-
private _onAccountsChanged: TronAccountsChangedCallback = (data) => {
443+
private _onAccountsChanged: TronAccountsChangedCallback = () => {
444444
const preAddr = this.address || '';
445-
if (!data?.length) {
445+
const curAddr = (this._wallet?.tronWeb && this._wallet?.tronWeb.defaultAddress?.base58) || '';
446+
if (!curAddr) {
446447
// change to a new address and if it's disconnected, data will be empty
447448
// tronlink will emit accountsChanged many times, only process when connected
448449
this.setAddress(null);
449450
this.setState(AdapterState.Disconnect);
450451
} else {
451-
const address = data[0] as string;
452+
const address = curAddr as string;
452453
this.setAddress(address);
453454
this.setState(AdapterState.Connected);
454455
}

packages/adapters/tronlink/tests/units/adapter-tron.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,23 @@ describe('events should work fine', () => {
226226
adapter.on('connect', _onConnect);
227227
adapter.on('disconnect', _onDisconnect);
228228
adapter.on('accountsChanged', _onAccountsChanged);
229+
tron._setAddress('address2');
229230
tron._emit('accountsChanged', ['address2']);
230231
await wait();
231232
expect(_onConnect).not.toHaveBeenCalled();
232233
expect(_onAccountsChanged).toHaveBeenCalledTimes(1);
233234
expect(_onAccountsChanged).toHaveBeenCalledWith('address2', 'address');
234235
expect(adapter.address).toEqual('address2');
235236

237+
tron._setAddress('address3');
236238
tron._emit('accountsChanged', ['address3']);
237239
await wait();
238240
expect(_onAccountsChanged).toHaveBeenCalledTimes(2);
239241
expect(_onAccountsChanged).toHaveBeenLastCalledWith('address3', 'address2');
240242
expect(_onConnect).not.toHaveBeenCalled();
241243
expect(adapter.address).toEqual('address3');
242244

245+
tron._setAddress('');
243246
tron._emit('accountsChanged', []);
244247
await wait();
245248
expect(adapter.address).toEqual(null);
@@ -253,6 +256,7 @@ describe('events should work fine', () => {
253256
adapter = new TronLinkAdapter();
254257
const _onConnect = jest.fn();
255258
adapter.on('connect', _onConnect);
259+
tron._setAddress('address2');
256260
tron._emit('accountsChanged', ['address2']);
257261
expect(_onConnect).toHaveBeenCalledTimes(1);
258262
expect(_onConnect).toHaveBeenCalledWith('address2');
@@ -262,6 +266,7 @@ describe('events should work fine', () => {
262266
tron._setAddress('address');
263267
const _onDisconnect = jest.fn();
264268
adapter.on('disconnect', _onDisconnect);
269+
tron._setAddress('');
265270
tron._emit('accountsChanged', []);
266271
expect(_onDisconnect).toHaveBeenCalledTimes(1);
267272
});

packages/react/react-hooks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tronweb3/tronwallet-adapter-react-hooks",
3-
"version": "1.1.4",
3+
"version": "1.1.5",
44
"description": "A `useWallet()` hook to make it easy to interact with Tron wallets.",
55
"keywords": [
66
"TRON",

pnpm-lock.yaml

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)