forked from 5afe/safe-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: set empty names as shortened address (5afe#3794)
* fix: update empty names + fallback to address * fix: shorten fallback * fix: temp dispatch to fix empty names * fix: move dispatch * fix: add tests * fix: add test * fix: reduce truncation length * fix: add return type
- Loading branch information
Showing
4 changed files
with
227 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
304 changes: 199 additions & 105 deletions
304
src/logic/addressBook/store/__tests__/addressBookReducer.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,208 @@ | ||
import { CHAIN_ID } from 'src/config/chain.d' | ||
import { batchLoadEntries } from '../reducer' | ||
import { addressBookFixEmptyNames } from '../actions' | ||
import addressBookReducer, { batchLoadEntries } from '../reducer' | ||
|
||
describe('Test AddressBook BatchLoadEntries Reducer', () => { | ||
it('returns an addressbook array', () => { | ||
const addressBookEntries = [ | ||
{ | ||
address: '0x4462527986c3fD47f498eF25B4D01e6AAD7aBcb2', | ||
name: 'Entry 1', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
{ | ||
address: '0x918925e548C7208713a965A8cdA0287e5FF9d96F', | ||
name: 'Entry 2', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
] | ||
const currentState = [] | ||
const action = { | ||
type: 'addressBook/import', | ||
payload: addressBookEntries, | ||
} | ||
const newState = batchLoadEntries(currentState, action) | ||
expect(newState).toStrictEqual(addressBookEntries) | ||
}) | ||
describe('batchLoadEntries', () => { | ||
it('returns an addressbook array', () => { | ||
const addressBookEntries = [ | ||
{ | ||
address: '0x4462527986c3fD47f498eF25B4D01e6AAD7aBcb2', | ||
name: 'Entry 1', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
{ | ||
address: '0x918925e548C7208713a965A8cdA0287e5FF9d96F', | ||
name: 'Entry 2', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
] | ||
const currentState = [] | ||
const action = { | ||
type: 'addressBook/import', | ||
payload: addressBookEntries, | ||
} | ||
const newState = batchLoadEntries(currentState, action) | ||
expect(newState).toStrictEqual(addressBookEntries) | ||
}) | ||
|
||
it('merges entries from different chains', () => { | ||
const addressBookEntries = [ | ||
{ | ||
address: '0x4462527986c3fD47f498eF25B4D01e6AAD7aBcb2', | ||
name: 'Entry 1', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
{ | ||
address: '0x918925e548C7208713a965A8cdA0287e5FF9d96F', | ||
name: 'Entry 2', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
] | ||
const initialState = [ | ||
{ | ||
address: '0x4462527986c3fD47f498eF25B4D01e6AAD7aBcb2', | ||
name: 'Entry 1', | ||
chainId: CHAIN_ID.VOLTA, | ||
}, | ||
{ | ||
address: '0x918925e548C7208713a965A8cdA0287e5FF9d96F', | ||
name: 'Entry 2', | ||
chainId: CHAIN_ID.VOLTA, | ||
}, | ||
] | ||
const action = { | ||
type: 'addressBook/import', | ||
payload: addressBookEntries, | ||
} | ||
const newState = batchLoadEntries(initialState, action) | ||
expect(newState).toStrictEqual(initialState.concat(addressBookEntries)) | ||
}) | ||
it('merges entries from different chains', () => { | ||
const addressBookEntries = [ | ||
{ | ||
address: '0x4462527986c3fD47f498eF25B4D01e6AAD7aBcb2', | ||
name: 'Entry 1', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
{ | ||
address: '0x918925e548C7208713a965A8cdA0287e5FF9d96F', | ||
name: 'Entry 2', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
] | ||
const initialState = [ | ||
{ | ||
address: '0x4462527986c3fD47f498eF25B4D01e6AAD7aBcb2', | ||
name: 'Entry 1', | ||
chainId: CHAIN_ID.VOLTA, | ||
}, | ||
{ | ||
address: '0x918925e548C7208713a965A8cdA0287e5FF9d96F', | ||
name: 'Entry 2', | ||
chainId: CHAIN_ID.VOLTA, | ||
}, | ||
] | ||
const action = { | ||
type: 'addressBook/import', | ||
payload: addressBookEntries, | ||
} | ||
const newState = batchLoadEntries(initialState, action) | ||
expect(newState).toStrictEqual(initialState.concat(addressBookEntries)) | ||
}) | ||
|
||
it('skips entries with wrong name format', () => { | ||
const addressBookEntries = [ | ||
{ | ||
address: '0x4462527986c3fD47f498eF25B4D01e6AAD7aBcb2', | ||
name: 'OWNER # 1', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
{ | ||
address: '0x918925e548C7208713a965A8cdA0287e5FF9d96F', | ||
name: 'OWNER # 2', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
] | ||
const initialState = [] | ||
const action = { | ||
type: 'addressBook/import', | ||
payload: addressBookEntries, | ||
} | ||
const newState = batchLoadEntries(initialState, action) | ||
expect(newState).toStrictEqual(initialState) | ||
}) | ||
|
||
it('replaces name when entries share address and chain', () => { | ||
const addressBookEntries = [ | ||
{ | ||
address: '0x4462527986c3fD47f498eF25B4D01e6AAD7aBcb2', | ||
name: 'NewEntry 1', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
{ | ||
address: '0x918925e548C7208713a965A8cdA0287e5FF9d96F', | ||
name: 'New Entry 2', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
] | ||
const initialState = [ | ||
{ | ||
address: '0x4462527986c3fD47f498eF25B4D01e6AAD7aBcb2', | ||
name: 'Entry 1', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
{ | ||
address: '0x918925e548C7208713a965A8cdA0287e5FF9d96F', | ||
name: 'Entry 2', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
] | ||
const action = { | ||
type: 'addressBook/import', | ||
payload: addressBookEntries, | ||
} | ||
const newState = batchLoadEntries(initialState, action) | ||
expect(newState).toStrictEqual(addressBookEntries) | ||
}) | ||
|
||
it('skips entries with wrong name format', () => { | ||
const addressBookEntries = [ | ||
{ | ||
address: '0x4462527986c3fD47f498eF25B4D01e6AAD7aBcb2', | ||
name: 'OWNER # 1', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
{ | ||
address: '0x918925e548C7208713a965A8cdA0287e5FF9d96F', | ||
name: 'OWNER # 2', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
] | ||
const initialState = [] | ||
const action = { | ||
type: 'addressBook/import', | ||
payload: addressBookEntries, | ||
} | ||
const newState = batchLoadEntries(initialState, action) | ||
expect(newState).toStrictEqual(initialState) | ||
it('fixes empty names upon import', () => { | ||
const addressBookEntries = [ | ||
{ | ||
address: '0x4462527986c3fD47f498eF25B4D01e6AAD7aBcb2', | ||
name: '0x4462...Bcb2', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
{ | ||
address: '0x918925e548C7208713a965A8cdA0287e5FF9d96F', | ||
name: '0x9189...d96F', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
] | ||
const initialState = [ | ||
{ | ||
address: '0x4462527986c3fD47f498eF25B4D01e6AAD7aBcb2', | ||
name: '', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
{ | ||
address: '0x918925e548C7208713a965A8cdA0287e5FF9d96F', | ||
name: '', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
] | ||
const action = { | ||
type: 'addressBook/import', | ||
payload: addressBookEntries, | ||
} | ||
const newState = batchLoadEntries(initialState, action) | ||
expect(newState).toStrictEqual(addressBookEntries) | ||
}) | ||
}) | ||
|
||
it('replaces name when entries share address and chain', () => { | ||
const addressBookEntries = [ | ||
{ | ||
address: '0x4462527986c3fD47f498eF25B4D01e6AAD7aBcb2', | ||
name: 'NewEntry 1', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
{ | ||
address: '0x918925e548C7208713a965A8cdA0287e5FF9d96F', | ||
name: 'New Entry 2', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
] | ||
const initialState = [ | ||
{ | ||
address: '0x4462527986c3fD47f498eF25B4D01e6AAD7aBcb2', | ||
name: 'Entry 1', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
{ | ||
address: '0x918925e548C7208713a965A8cdA0287e5FF9d96F', | ||
name: 'Entry 2', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
] | ||
const action = { | ||
type: 'addressBook/import', | ||
payload: addressBookEntries, | ||
} | ||
const newState = batchLoadEntries(initialState, action) | ||
expect(newState).toStrictEqual(addressBookEntries) | ||
describe('addressBookFixEmptyNames', () => { | ||
it('fixes empty names', () => { | ||
const prevState = [ | ||
{ | ||
address: '0x4462527986c3fD47f498eF25B4D01e6AAD7aBcb2', | ||
name: '', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
{ | ||
address: '0x918925e548C7208713a965A8cdA0287e5FF9d96F', | ||
name: '', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
] | ||
|
||
expect(addressBookReducer(prevState, addressBookFixEmptyNames())).toEqual([ | ||
{ | ||
address: '0x4462527986c3fD47f498eF25B4D01e6AAD7aBcb2', | ||
name: '0x4462...Bcb2', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
{ | ||
address: '0x918925e548C7208713a965A8cdA0287e5FF9d96F', | ||
name: '0x9189...d96F', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
]) | ||
}) | ||
|
||
it("doesn't 'fix' named contacts", () => { | ||
const prevState = [ | ||
{ | ||
address: '0x4462527986c3fD47f498eF25B4D01e6AAD7aBcb2', | ||
name: 'test', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
{ | ||
address: '0x918925e548C7208713a965A8cdA0287e5FF9d96F', | ||
name: '', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
] | ||
|
||
expect(addressBookReducer(prevState, addressBookFixEmptyNames())).toEqual([ | ||
{ | ||
address: '0x4462527986c3fD47f498eF25B4D01e6AAD7aBcb2', | ||
name: 'test', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
{ | ||
address: '0x918925e548C7208713a965A8cdA0287e5FF9d96F', | ||
name: '0x9189...d96F', | ||
chainId: CHAIN_ID.RINKEBY, | ||
}, | ||
]) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.