Skip to content

Commit

Permalink
fix: ignore empty names in addressbook (#2709)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmanu authored Oct 31, 2023
1 parent 915ef37 commit 7093860
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/store/__tests__/addressBookSlice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ describe('addressBookSlice', () => {
})
})

it('should ignore empty names in the address book', () => {
const state = addressBookSlice.reducer(
initialState,
upsertAddressBookEntry({
chainId: '1',
address: '0x2',
name: '',
}),
)
expect(state).toEqual(initialState)
})

it('should edit an entry in the address book', () => {
const state = addressBookSlice.reducer(
initialState,
Expand Down
3 changes: 3 additions & 0 deletions src/store/addressBookSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export const addressBookSlice = createSlice({

upsertAddressBookEntry: (state, action: PayloadAction<{ chainId: string; address: string; name: string }>) => {
const { chainId, address, name } = action.payload
if (name.trim() === '') {
return
}
if (!state[chainId]) state[chainId] = {}
state[chainId][address] = name
},
Expand Down

0 comments on commit 7093860

Please sign in to comment.