Skip to content

Commit

Permalink
fix: Fix trust issue
Browse files Browse the repository at this point in the history
  • Loading branch information
wenty22 committed Nov 25, 2024
1 parent 5ebd8ce commit 11da348
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 74 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-guests-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-real/walletkit': patch
---

Fix trust issue
5 changes: 0 additions & 5 deletions packages/walletkit/__dev__/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ function ConnectButton() {
const { publicKey, disconnect: solanaDisconnect } = useSolanaWallet();
const { address: tronAddress, disconnect: tronDisconnect } = useTronWallet();

useEffect(() => {
console.log(window.ethereum);
console.log(window.solana);
}, []);

return (
<>
<button
Expand Down
24 changes: 11 additions & 13 deletions packages/walletkit/src/evm/wallets/injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export type InjectedParameters = {
unstable_shimAsyncInject?: boolean | number | undefined;
};

const notRevokePermissionWallets = ['trust'];
function getRecentConnectorId() {
if (typeof window === 'undefined') return;
const recentConnectorId = window.localStorage.getItem('wagmi.recentConnectorId');
if (recentConnectorId) return JSON.parse(recentConnectorId);
}

injected.type = 'injected' as const;
export function injected(parameters: InjectedParameters = {}) {
Expand Down Expand Up @@ -218,7 +222,7 @@ export function injected(parameters: InjectedParameters = {}) {
try {
// Adding timeout as not all wallets support this method and can hang
// https://github.com/wevm/wagmi/issues/4064
if (!notRevokePermissionWallets.includes(this.id)) {
if (this.id !== 'trust') {
await withTimeout(
() =>
// TODO: Remove explicit type for viem@3
Expand Down Expand Up @@ -279,18 +283,9 @@ export function injected(parameters: InjectedParameters = {}) {
},
async isAuthorized() {
try {
let isRecentConnected = false;
if (typeof window !== 'undefined') {
const recentConnectorId = window.localStorage.getItem('wagmi.recentConnectorId');
if (recentConnectorId) {
isRecentConnected = JSON.parse(recentConnectorId) === this.id;
} else {
return false;
}
}

const isRecentConnector = getRecentConnectorId() === this.id;
const disconnected = await config.storage?.getItem(`${this.id}.disconnected`);
const isDisconnected = !shimDisconnect || !isRecentConnected || disconnected === true;
const isDisconnected = !shimDisconnect || !isRecentConnector || disconnected === true;

if (isDisconnected) return false;

Expand Down Expand Up @@ -446,6 +441,9 @@ export function injected(parameters: InjectedParameters = {}) {
}
},
async onAccountsChanged(accounts) {
const isRecentConnector = getRecentConnectorId() === this.id;
if (this.id === 'trust' && !isRecentConnector) return;

// Disconnect if there are no accounts
if (accounts.length === 0) this.onDisconnect();
// Connect if emitter is listening for connect event (e.g. is disconnected and connects through wallet interface)
Expand Down

This file was deleted.

0 comments on commit 11da348

Please sign in to comment.