Skip to content

Commit

Permalink
fix: No need to invoke switchChain on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
wenty22 committed Oct 23, 2024
1 parent 9056071 commit 5ed12f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-bikes-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-real/walletkit': patch
---

No need to invoke switchChain on mobile
22 changes: 8 additions & 14 deletions packages/walletkit/src/tron/hooks/useTronConnect.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { useWalletKit } from '@/core/index';
import { isMobile } from '@/core/index';
import { useWallet } from '@tronweb3/tronwallet-adapter-react-hooks';
import { useCallback, useState } from 'react';

export function useTronConnect() {
const { select, wallets: adapters, connected, disconnect } = useWallet();
const { select, wallets: adapters, connected } = useWallet();

const { log } = useWalletKit();
const [isConnected, setIsConnected] = useState(connected);

const connect = useCallback(
Expand All @@ -16,20 +15,15 @@ export function useTronConnect() {
const adapter = adapters.find((item) => item.adapter.name === adapterName)?.adapter;

if (adapter) {
try {
await adapter.connect();
if (finalChainId) {
await adapter?.switchChain(finalChainId);
}
setIsConnected(true);
} catch (err) {
setIsConnected(false);
disconnect();
log(err);
await adapter.connect();
setIsConnected(true);

if (finalChainId && !isMobile()) {
await adapter?.switchChain(finalChainId);
}
}
},
[adapters, disconnect, log, select],
[adapters, select],
);

return {
Expand Down

0 comments on commit 5ed12f9

Please sign in to comment.