Skip to content

Commit

Permalink
Merge branch 'main' into fix/active-chain-for-siwx-authenticate
Browse files Browse the repository at this point in the history
  • Loading branch information
tomiir authored Dec 18, 2024
2 parents 51b1feb + 8249314 commit fc81694
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
22 changes: 22 additions & 0 deletions .changeset/tender-plums-type.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion packages/appkit/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/utils/SafeLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const SafeLocalStorageKeys = {
export const SafeLocalStorage = {
setItem<Key extends keyof SafeLocalStorageItems>(
key: Key,
value: SafeLocalStorageItems[Key]
value?: SafeLocalStorageItems[Key]
): void {
if (isSafe() && value !== undefined) {
localStorage.setItem(key, value)
Expand Down
11 changes: 8 additions & 3 deletions packages/common/tests/SafeLocalStorage.test.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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()
Expand All @@ -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')
Expand Down

0 comments on commit fc81694

Please sign in to comment.