Fix addressbook type errors

This commit is contained in:
Mikhail Mikheev 2020-06-23 17:33:57 +04:00
parent 18f03b8bc1
commit e7c012d5d1
3 changed files with 17 additions and 9 deletions

View File

@ -1,6 +1,12 @@
import { Record } from 'immutable'
export const makeAddressBookEntry = Record({
export interface AddressBookEntryProps {
address: string
name: string
isOwner: boolean
}
export const makeAddressBookEntry = Record<AddressBookEntryProps>({
address: '',
name: '',
isOwner: false,

View File

@ -1,4 +1,4 @@
import { List, Map } from 'immutable'
import { List } from 'immutable'
import { loadAddressBook } from 'src/logic/addressBook/store/actions/loadAddressBook'
import { buildAddressBook } from 'src/logic/addressBook/store/reducer/addressBook'
@ -8,11 +8,12 @@ import { safesListSelector } from 'src/routes/safe/store/selectors'
const loadAddressBookFromStorage = () => async (dispatch, getState) => {
try {
const state = getState()
let addressBook = await getAddressBookFromStorage()
if (!addressBook) {
addressBook = Map([])
let storedAdBk = await getAddressBookFromStorage()
if (!storedAdBk) {
storedAdBk = []
}
addressBook = buildAddressBook(addressBook)
let addressBook = buildAddressBook(storedAdBk)
// Fetch all the current safes, in case that we don't have a safe on the adbk, we add it
const safes = safesListSelector(state)
const adbkEntries = addressBook.keySeq().toArray()

View File

@ -1,11 +1,12 @@
import { loadFromStorage, saveToStorage } from 'src/utils/storage'
import { AddressBookEntryProps } from './../model/addressBook'
const ADDRESS_BOOK_STORAGE_KEY = 'ADDRESS_BOOK_STORAGE_KEY'
export const getAddressBookFromStorage = async () => {
const data = await loadFromStorage(ADDRESS_BOOK_STORAGE_KEY)
export const getAddressBookFromStorage = async (): Promise<Array<AddressBookEntryProps> | undefined> => {
const data = await loadFromStorage<Array<AddressBookEntryProps>>(ADDRESS_BOOK_STORAGE_KEY)
return data || []
return data
}
export const saveAddressBook = async (addressBook) => {