diff --git a/.changeset/tender-plums-type.md b/.changeset/tender-plums-type.md new file mode 100644 index 0000000000..cf13a01400 --- /dev/null +++ b/.changeset/tender-plums-type.md @@ -0,0 +1,22 @@ +--- +'@reown/appkit': patch +'@reown/appkit-common': patch +'@reown/appkit-adapter-ethers': patch +'@reown/appkit-adapter-ethers5': patch +'@reown/appkit-adapter-solana': patch +'@reown/appkit-adapter-wagmi': patch +'@reown/appkit-utils': patch +'@reown/appkit-cdn': patch +'@reown/appkit-cli': patch +'@reown/appkit-core': patch +'@reown/appkit-experimental': patch +'@reown/appkit-polyfills': patch +'@reown/appkit-scaffold-ui': patch +'@reown/appkit-siwe': patch +'@reown/appkit-siwx': patch +'@reown/appkit-ui': patch +'@reown/appkit-wallet': patch +'@reown/appkit-wallet-button': patch +--- + +Fixes issue where undefined address would throw an error polluting logs diff --git a/packages/appkit/src/client.ts b/packages/appkit/src/client.ts index 7738ccac83..5189c3cfac 100644 --- a/packages/appkit/src/client.ts +++ b/packages/appkit/src/client.ts @@ -1519,7 +1519,7 @@ export class AppKit { const chainIdToUse = chainId || activeChainId // Only update state when needed - if (address.toLowerCase() !== AccountController.state.address?.toLowerCase()) { + if (address?.toLowerCase() !== AccountController.state.address?.toLowerCase()) { this.setCaipAddress(`${chainNamespace}:${chainId}:${address}`, chainNamespace) await this.syncIdentity({ address, chainId, chainNamespace }) } diff --git a/packages/common/src/utils/SafeLocalStorage.ts b/packages/common/src/utils/SafeLocalStorage.ts index 45b3da68e5..3342085656 100644 --- a/packages/common/src/utils/SafeLocalStorage.ts +++ b/packages/common/src/utils/SafeLocalStorage.ts @@ -39,7 +39,7 @@ export const SafeLocalStorageKeys = { export const SafeLocalStorage = { setItem( key: Key, - value: SafeLocalStorageItems[Key] + value?: SafeLocalStorageItems[Key] ): void { if (isSafe() && value !== undefined) { localStorage.setItem(key, value) diff --git a/packages/common/tests/SafeLocalStorage.test.ts b/packages/common/tests/SafeLocalStorage.test.ts index e209844773..7fca38b9c9 100644 --- a/packages/common/tests/SafeLocalStorage.test.ts +++ b/packages/common/tests/SafeLocalStorage.test.ts @@ -1,4 +1,4 @@ -import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest' +import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest' import { SafeLocalStorage } from '../src/utils/SafeLocalStorage' @@ -34,11 +34,11 @@ describe('SafeLocalStorage safe', () => { let setItem = vi.fn() let removeItem = vi.fn() - beforeAll(() => { + beforeEach(() => { Object.assign(globalThis, { window: {}, localStorage: { getItem, setItem, removeItem } }) }) - afterAll(() => { + afterEach(() => { getItem.mockClear() setItem.mockClear() removeItem.mockClear() @@ -49,6 +49,11 @@ describe('SafeLocalStorage safe', () => { expect(setItem).toHaveBeenCalledWith('@appkit/wallet_id', 'test') }) + it('should not setItem if value is undefined', () => { + expect(SafeLocalStorage.setItem('@appkit/wallet_id', undefined)).toBe(undefined) + expect(setItem).not.toHaveBeenCalled() + }) + it('should getItem ', () => { expect(SafeLocalStorage.getItem('@appkit/wallet_id')).toEqual('test') expect(getItem).toHaveBeenCalledWith('@appkit/wallet_id')