diff --git a/package.json b/package.json index 1e969774..b027b1ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "safe-react", - "version": "2.3.1", + "version": "2.4.0", "description": "Allowing crypto users manage funds in a safer way", "website": "https://github.com/gnosis/safe-react#readme", "bugs": { diff --git a/src/logic/addressBook/model/addressBook.ts b/src/logic/addressBook/model/addressBook.ts index fb4fd19f..f051fe18 100644 --- a/src/logic/addressBook/model/addressBook.ts +++ b/src/logic/addressBook/model/addressBook.ts @@ -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({ address: '', name: '', isOwner: false, diff --git a/src/logic/addressBook/store/actions/loadAddressBookFromStorage.ts b/src/logic/addressBook/store/actions/loadAddressBookFromStorage.ts index 20cfe570..88009c78 100644 --- a/src/logic/addressBook/store/actions/loadAddressBookFromStorage.ts +++ b/src/logic/addressBook/store/actions/loadAddressBookFromStorage.ts @@ -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() diff --git a/src/logic/addressBook/utils/index.ts b/src/logic/addressBook/utils/index.ts index b0131480..7fb48374 100644 --- a/src/logic/addressBook/utils/index.ts +++ b/src/logic/addressBook/utils/index.ts @@ -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 | undefined> => { + const data = await loadFromStorage>(ADDRESS_BOOK_STORAGE_KEY) - return data || [] + return data } export const saveAddressBook = async (addressBook) => { diff --git a/src/logic/safe/utils/safeStorage.ts b/src/logic/safe/utils/safeStorage.ts index 34446b8b..868bf207 100644 --- a/src/logic/safe/utils/safeStorage.ts +++ b/src/logic/safe/utils/safeStorage.ts @@ -27,8 +27,8 @@ export const getLocalSafe = async (safeAddress) => { return storedSafes[safeAddress] } -export const getDefaultSafe = async () => { - const defaultSafe = await loadFromStorage(DEFAULT_SAFE_KEY) +export const getDefaultSafe = async (): Promise => { + const defaultSafe = await loadFromStorage(DEFAULT_SAFE_KEY) return defaultSafe || '' } diff --git a/src/logic/tokens/store/actions/loadActiveTokens.ts b/src/logic/tokens/store/actions/loadActiveTokens.ts index c384bd4e..7b4ae61b 100644 --- a/src/logic/tokens/store/actions/loadActiveTokens.ts +++ b/src/logic/tokens/store/actions/loadActiveTokens.ts @@ -7,7 +7,7 @@ import { getActiveTokens } from 'src/logic/tokens/utils/tokensStorage' const loadActiveTokens = () => async (dispatch) => { try { - const tokens = await getActiveTokens() + const tokens = (await getActiveTokens()) || {} // The filter of strings was made because of the issue #751. Please see: https://github.com/gnosis/safe-react/pull/755#issuecomment-612969340 const tokenRecordsList = List( Object.values(tokens) diff --git a/src/logic/tokens/store/actions/removeToken.ts b/src/logic/tokens/store/actions/removeToken.ts deleted file mode 100644 index d6aab7bc..00000000 --- a/src/logic/tokens/store/actions/removeToken.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { createAction } from 'redux-actions' - -import { removeFromActiveTokens, removeTokenFromStorage } from 'src/logic/tokens/utils/tokensStorage' - -export const REMOVE_TOKEN = 'REMOVE_TOKEN' - -export const removeToken = createAction(REMOVE_TOKEN, (safeAddress, token) => ({ - safeAddress, - token, -})) - -const deleteToken = (safeAddress, token) => async (dispatch) => { - dispatch(removeToken(safeAddress, token)) - - await removeFromActiveTokens(safeAddress, token) - await removeTokenFromStorage(safeAddress, token) -} - -export default deleteToken diff --git a/src/logic/tokens/store/reducer/tokens.ts b/src/logic/tokens/store/reducer/tokens.ts index 418da6b0..50dc1def 100644 --- a/src/logic/tokens/store/reducer/tokens.ts +++ b/src/logic/tokens/store/reducer/tokens.ts @@ -2,7 +2,6 @@ import { Map } from 'immutable' import { handleActions } from 'redux-actions' import { ADD_TOKEN } from 'src/logic/tokens/store/actions/addToken' -import { REMOVE_TOKEN } from 'src/logic/tokens/store/actions/removeToken' import { ADD_TOKENS } from 'src/logic/tokens/store/actions/saveTokens' import { makeToken } from 'src/logic/tokens/store/model/token' @@ -27,12 +26,6 @@ export default handleActions( return state.set(tokenAddress, makeToken(token)) }, - [REMOVE_TOKEN]: (state, action) => { - const { token } = action.payload - const { address: tokenAddress } = token - - return state.remove(tokenAddress) - }, }, Map(), ) diff --git a/src/logic/tokens/utils/tokenHelpers.ts b/src/logic/tokens/utils/tokenHelpers.ts index eab9ec7e..4fab2c79 100644 --- a/src/logic/tokens/utils/tokenHelpers.ts +++ b/src/logic/tokens/utils/tokenHelpers.ts @@ -1,4 +1,3 @@ -import memoize from 'lodash.memoize' import logo from 'src/assets/icons/icon_etherTokens.svg' import generateBatchRequests from 'src/logic/contracts/generateBatchRequests' import { @@ -26,7 +25,7 @@ export const getEthAsToken = (balance: string): Token => { }) } -export const isAddressAToken = async (tokenAddress): Promise => { +export const isAddressAToken = async (tokenAddress: string): Promise => { // SECOND APPROACH: // They both seem to work the same // const tokenContract = await getStandardTokenContract() @@ -45,36 +44,49 @@ export const isTokenTransfer = (tx: any): boolean => { } export const isSendERC721Transaction = (tx: any, txCode: string, knownTokens: any) => { + // "0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85" - ens token contract, includes safeTransferFrom + // but no proper ERC721 standard implemented return ( - (txCode && txCode.includes(SAFE_TRANSFER_FROM_WITHOUT_DATA_HASH)) || + (txCode && + txCode.includes(SAFE_TRANSFER_FROM_WITHOUT_DATA_HASH) && + tx.to !== '0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85') || (isTokenTransfer(tx) && !knownTokens.get(tx.to)) ) } -export const getERC721Symbol = memoize( - async (contractAddress: string): Promise => { +export const getERC721Symbol = async (contractAddress: string): Promise => { + let tokenSymbol = 'UNKNOWN' + try { const ERC721token = await getERC721TokenContract() const tokenInstance = await ERC721token.at(contractAddress) - return tokenInstance.symbol() - }, -) + tokenSymbol = tokenInstance.symbol() + } catch (err) { + console.error(`Failed to retrieve token symbol for ERC721 token ${contractAddress}`) + } + return tokenSymbol +} export const getERC20DecimalsAndSymbol = async ( tokenAddress: string, ): Promise<{ decimals: number; symbol: string }> => { - const tokenInfos = await getTokenInfos(tokenAddress) + const tokenInfo = { decimals: 18, symbol: 'UNKNOWN' } + try { + const storedTokenInfo = await getTokenInfos(tokenAddress) - if (tokenInfos === null) { - const [tokenDecimals, tokenSymbol] = await generateBatchRequests({ - abi: ALTERNATIVE_TOKEN_ABI, - address: tokenAddress, - methods: ['decimals', 'symbol'], - }) + if (storedTokenInfo === null) { + const [tokenDecimals, tokenSymbol] = await generateBatchRequests({ + abi: ALTERNATIVE_TOKEN_ABI, + address: tokenAddress, + methods: ['decimals', 'symbol'], + }) - return { decimals: Number(tokenDecimals), symbol: tokenSymbol } + return { decimals: Number(tokenDecimals), symbol: tokenSymbol } + } + } catch (err) { + console.error(`Failed to retrieve token info for ERC20 token ${tokenAddress}`) } - return { decimals: Number(tokenInfos.decimals), symbol: tokenInfos.symbol } + return tokenInfo } export const isSendERC20Transaction = async ( diff --git a/src/logic/tokens/utils/tokensStorage.ts b/src/logic/tokens/utils/tokensStorage.ts index c34d7c04..27364f24 100644 --- a/src/logic/tokens/utils/tokensStorage.ts +++ b/src/logic/tokens/utils/tokensStorage.ts @@ -1,6 +1,7 @@ -import { List } from 'immutable' +import { Map } from 'immutable' import { loadFromStorage, saveToStorage } from 'src/utils/storage' +import { TokenProps, Token } from './../store/model/token' export const ACTIVE_TOKENS_KEY = 'ACTIVE_TOKENS' export const CUSTOM_TOKENS_KEY = 'CUSTOM_TOKENS' @@ -9,42 +10,16 @@ export const CUSTOM_TOKENS_KEY = 'CUSTOM_TOKENS' // to avoid iterating a large amount of data of tokens from the backend // Custom tokens should be saved too unless they're deleted (marking them as inactive doesn't count) -export const saveActiveTokens = async (tokens) => { +export const saveActiveTokens = async (tokens: Map): Promise => { try { - await saveToStorage(ACTIVE_TOKENS_KEY, tokens.toJS()) + await saveToStorage(ACTIVE_TOKENS_KEY, tokens.toJS() as Record) } catch (err) { console.error('Error storing tokens in localstorage', err) } } -export const getActiveTokens = async () => { - const data = await loadFromStorage(ACTIVE_TOKENS_KEY) +export const getActiveTokens = async (): Promise | undefined> => { + const data = await loadFromStorage>(ACTIVE_TOKENS_KEY) - return data || {} -} - -export const getCustomTokens = async () => { - const data = await loadFromStorage(CUSTOM_TOKENS_KEY) - - return data ? List(data) : List() -} - -export const removeTokenFromStorage = async (safeAddress, token) => { - const data = await getCustomTokens() - - try { - const index = data.indexOf(token) - await saveToStorage(CUSTOM_TOKENS_KEY, data.remove(index)) - } catch (err) { - console.error('Error removing token in localstorage', err) - } -} - -export const removeFromActiveTokens = async (safeAddress, token) => { - const activeTokens = await getActiveTokens() - const index = activeTokens.findIndex((activeToken) => activeToken.name === token.name) - - if (index !== -1) { - await saveActiveTokens(safeAddress) - } + return data } diff --git a/src/logic/wallets/store/middlewares/providerWatcher.ts b/src/logic/wallets/store/middlewares/providerWatcher.ts index 16c43aa5..0dedb32d 100644 --- a/src/logic/wallets/store/middlewares/providerWatcher.ts +++ b/src/logic/wallets/store/middlewares/providerWatcher.ts @@ -10,10 +10,10 @@ const watchedActions = [ADD_PROVIDER, REMOVE_PROVIDER] const LAST_USED_PROVIDER_KEY = 'LAST_USED_PROVIDER' -export const loadLastUsedProvider = async () => { - const lastUsedProvider = await loadFromStorage(LAST_USED_PROVIDER_KEY) +export const loadLastUsedProvider = async (): Promise => { + const lastUsedProvider = await loadFromStorage(LAST_USED_PROVIDER_KEY) - return lastUsedProvider || '' + return lastUsedProvider } let watcherInterval = null diff --git a/src/routes/index.tsx b/src/routes/index.tsx index e8b8e6a9..b9776171 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -7,6 +7,7 @@ import { LOAD_ADDRESS, OPEN_ADDRESS, SAFELIST_ADDRESS, SAFE_PARAM_ADDRESS, WELCO import Loader from 'src/components/Loader' import { defaultSafeSelector } from 'src/routes/safe/store/selectors' import { useAnalytics } from 'src/utils/googleAnalytics' +import { DEFAULT_SAFE_INITIAL_STATE } from 'src/routes/safe/store/reducer/safe' const Welcome = React.lazy(() => import('./welcome/container')) @@ -44,7 +45,7 @@ const Routes = ({ location }) => { return } - if (typeof defaultSafe === 'undefined') { + if (defaultSafe === DEFAULT_SAFE_INITIAL_STATE) { return } diff --git a/src/routes/load/container/Load.tsx b/src/routes/load/container/Load.tsx index 0fb69162..ff96a306 100644 --- a/src/routes/load/container/Load.tsx +++ b/src/routes/load/container/Load.tsx @@ -16,17 +16,25 @@ import { SAFELIST_ADDRESS } from 'src/routes/routes' import { buildSafe } from 'src/routes/safe/store/actions/fetchSafe' import { history } from 'src/store' import { loadFromStorage } from 'src/utils/storage' +import { Dispatch } from 'redux' +import { SafeOwner } from '../../safe/store/models/safe' +import { List } from 'immutable' -export const loadSafe = async (safeName, safeAddress, owners, addSafe) => { +export const loadSafe = async ( + safeName: string, + safeAddress: string, + owners: List, + addSafe: Dispatch, +): Promise => { const safeProps = await buildSafe(safeAddress, safeName) safeProps.owners = owners - await addSafe(safeProps) - const storedSafes = (await loadFromStorage(SAFES_KEY)) || {} + storedSafes[safeAddress] = safeProps - saveSafes(storedSafes) + await saveSafes(storedSafes) + await addSafe(safeProps) } class Load extends React.Component { diff --git a/src/routes/open/container/Open.tsx b/src/routes/open/container/Open.tsx index 7c8f2f28..f489fbe3 100644 --- a/src/routes/open/container/Open.tsx +++ b/src/routes/open/container/Open.tsx @@ -103,7 +103,7 @@ const Open = ({ addSafe, network, provider, userAccount }) => { // check if there is a safe being created useEffect(() => { const load = async () => { - const pendingCreation = await loadFromStorage(SAFE_PENDING_CREATION_STORAGE_KEY) + const pendingCreation = await loadFromStorage<{ txHash: string }>(SAFE_PENDING_CREATION_STORAGE_KEY) if (pendingCreation && pendingCreation.txHash) { setSafeCreationPendingInfo(pendingCreation) setShowProgress(true) @@ -133,7 +133,7 @@ const Open = ({ addSafe, network, provider, userAccount }) => { } const onSafeCreated = async (safeAddress) => { - const pendingCreation = await loadFromStorage(SAFE_PENDING_CREATION_STORAGE_KEY) + const pendingCreation = await loadFromStorage<{ txHash: string }>(SAFE_PENDING_CREATION_STORAGE_KEY) const name = getSafeNameFrom(pendingCreation) const ownersNames = getNamesFrom(pendingCreation) @@ -167,7 +167,7 @@ const Open = ({ addSafe, network, provider, userAccount }) => { } const onRetry = async () => { - const values = await loadFromStorage(SAFE_PENDING_CREATION_STORAGE_KEY) + const values = await loadFromStorage<{ txHash: string }>(SAFE_PENDING_CREATION_STORAGE_KEY) delete values.txHash await saveToStorage(SAFE_PENDING_CREATION_STORAGE_KEY, values) setSafeCreationPendingInfo(values) diff --git a/src/routes/open/utils/safeDataExtractor.ts b/src/routes/open/utils/safeDataExtractor.ts index 32b1193b..855c674f 100644 --- a/src/routes/open/utils/safeDataExtractor.ts +++ b/src/routes/open/utils/safeDataExtractor.ts @@ -1,6 +1,7 @@ import { List } from 'immutable' import { makeOwner } from 'src/routes/safe/store/models/owner' +import { SafeOwner } from '../../safe/store/models/safe' export const getAccountsFrom = (values) => { const accounts = Object.keys(values) @@ -18,7 +19,7 @@ export const getNamesFrom = (values) => { return accounts.map((account) => values[account]).slice(0, values.owners) } -export const getOwnersFrom = (names, addresses) => { +export const getOwnersFrom = (names, addresses): List => { const owners = names.map((name, index) => makeOwner({ name, address: addresses[index] })) return List(owners) diff --git a/src/routes/safe/components/Apps/index.tsx b/src/routes/safe/components/Apps/index.tsx index b4039f88..949e37f2 100644 --- a/src/routes/safe/components/Apps/index.tsx +++ b/src/routes/safe/components/Apps/index.tsx @@ -21,7 +21,7 @@ import { } from 'src/routes/safe/store/selectors' import { loadFromStorage, saveToStorage } from 'src/utils/storage' import { isSameHref } from 'src/utils/url' -import { SafeApp } from './types' +import { SafeApp, StoredSafeApp } from './types' const APPS_STORAGE_KEY = 'APPS_STORAGE_KEY' const APPS_LEGAL_DISCLAIMER_STORAGE_KEY = 'APPS_LEGAL_DISCLAIMER_STORAGE_KEY' @@ -195,7 +195,7 @@ function Apps({ closeModal, closeSnackbar, enqueueSnackbar, openModal }) { setAppList(copyAppList) // update storage list - const persistedAppList = (await loadFromStorage(APPS_STORAGE_KEY)) || [] + const persistedAppList = (await loadFromStorage(APPS_STORAGE_KEY)) || [] let storageApp = persistedAppList.find((a) => a.url === app.url) if (!storageApp) { @@ -303,7 +303,7 @@ function Apps({ closeModal, closeSnackbar, enqueueSnackbar, openModal }) { // recover apps from storage: // * third-party apps added by the user // * disabled status for both static and third-party apps - const persistedAppList = (await loadFromStorage(APPS_STORAGE_KEY)) || [] + const persistedAppList = (await loadFromStorage(APPS_STORAGE_KEY)) || [] const list = [...persistedAppList] staticAppsList.forEach((staticApp) => { diff --git a/src/routes/safe/components/Apps/types.d.ts b/src/routes/safe/components/Apps/types.d.ts index 635ba78f..8a8ead9b 100644 --- a/src/routes/safe/components/Apps/types.d.ts +++ b/src/routes/safe/components/Apps/types.d.ts @@ -6,3 +6,8 @@ export type SafeApp = { disabled?: boolean error: boolean } + +export type StoredSafeApp = { + url: string + disabled?: boolean +} diff --git a/src/routes/safe/components/Apps/utils.ts b/src/routes/safe/components/Apps/utils.ts index b39862da..d6611f87 100644 --- a/src/routes/safe/components/Apps/utils.ts +++ b/src/routes/safe/components/Apps/utils.ts @@ -18,12 +18,9 @@ export const staticAppsList: Array<{ url: string; disabled: boolean }> = [ // request { url: `${process.env.REACT_APP_IPFS_GATEWAY}/QmQapdJP6zERqpDKKPECNeMDDgwmGUqbKk1PjHpYj8gfDJ`, disabled: false }, // Aave - // { url: `${process.env.REACT_APP_IPFS_GATEWAY}/QmUfgEqdJ5kVjWTQofnDmvxdhDLBAaejiHkhQhfw6aYvBg`, disabled: false }, + { url: `${process.env.REACT_APP_IPFS_GATEWAY}/QmfHFQHCSyaSL8Aq4eWZeB3buy4neiUCPchob2pYdV9gJT`, disabled: false }, { url: `${gnosisAppsUrl}/compound`, disabled: false }, { url: `${gnosisAppsUrl}/tx-builder`, disabled: false }, - { url: `${gnosisAppsUrl}/pool-together`, disabled: false }, - { url: `${gnosisAppsUrl}/open-zeppelin`, disabled: false }, - { url: `${gnosisAppsUrl}/synthetix`, disabled: false }, ] export const getAppInfoFromOrigin = (origin) => { diff --git a/src/routes/safe/store/actions/fetchSafe.ts b/src/routes/safe/store/actions/fetchSafe.ts index 1fed7731..ed8dca20 100644 --- a/src/routes/safe/store/actions/fetchSafe.ts +++ b/src/routes/safe/store/actions/fetchSafe.ts @@ -13,6 +13,7 @@ import updateSafe from 'src/routes/safe/store/actions/updateSafe' import { makeOwner } from 'src/routes/safe/store/models/owner' import { checksumAddress } from 'src/utils/checksumAddress' +import { SafeOwner } from '../models/safe' const buildOwnersFrom = ( safeOwners, @@ -51,7 +52,7 @@ export const buildSafe = async (safeAdd, safeName, latestMasterContractVersion?: const threshold = Number(thresholdStr) const nonce = Number(nonceStr) - const owners = List(buildOwnersFrom(remoteOwners, localSafe)) + const owners = List(buildOwnersFrom(remoteOwners, localSafe)) const needsUpdate = safeNeedsUpdate(currentVersion, latestMasterContractVersion) const featuresEnabled = enabledFeatures(currentVersion) diff --git a/src/routes/safe/store/actions/transactions/utils/transactionHelpers.ts b/src/routes/safe/store/actions/transactions/utils/transactionHelpers.ts index b5b7db88..ba8de692 100644 --- a/src/routes/safe/store/actions/transactions/utils/transactionHelpers.ts +++ b/src/routes/safe/store/actions/transactions/utils/transactionHelpers.ts @@ -253,7 +253,20 @@ export const buildTx = async ({ const refundParams = await getRefundParams(tx, getERC20DecimalsAndSymbol) const decodedParams = getDecodedParams(tx) const confirmations = getConfirmations(tx) - const { decimals = 18, symbol = 'ETH' } = isSendERC20Tx ? await getERC20DecimalsAndSymbol(tx.to) : {} + + let tokenDecimals = 18 + let tokenSymbol = 'ETH' + try { + if (isSendERC20Tx) { + const { decimals, symbol } = await getERC20DecimalsAndSymbol(tx.to) + tokenDecimals = decimals + tokenSymbol = symbol + } else if (isSendERC721Tx) { + tokenSymbol = await getERC721Symbol(tx.to) + } + } catch (err) { + console.log(`Failed to retrieve token data from ${tx.to}`) + } const txToStore = makeTransaction({ baseGas: tx.baseGas, @@ -263,7 +276,7 @@ export const buildTx = async ({ creationTx: tx.creationTx, customTx: isCustomTx, data: tx.data ? tx.data : EMPTY_DATA, - decimals, + decimals: tokenDecimals, decodedParams, executionDate: tx.executionDate, executionTxHash: tx.transactionHash, @@ -286,7 +299,7 @@ export const buildTx = async ({ safeTxGas: tx.safeTxGas, safeTxHash: tx.safeTxHash, submissionDate: tx.submissionDate, - symbol: isSendERC721Tx ? await getERC721Symbol(tx.to) : symbol, + symbol: tokenSymbol, upgradeTx: isUpgradeTx, value: tx.value.toString(), }) diff --git a/src/routes/safe/store/middleware/notificationsMiddleware.ts b/src/routes/safe/store/middleware/notificationsMiddleware.ts index a28d76c7..48b752ae 100644 --- a/src/routes/safe/store/middleware/notificationsMiddleware.ts +++ b/src/routes/safe/store/middleware/notificationsMiddleware.ts @@ -38,7 +38,7 @@ const sendAwaitingTransactionNotification = async ( return } - let lastTimeUserLoggedInForSafes = (await loadFromStorage(LAST_TIME_USED_LOGGED_IN_ID)) || [] + let lastTimeUserLoggedInForSafes = (await loadFromStorage>(LAST_TIME_USED_LOGGED_IN_ID)) || {} const lastTimeUserLoggedIn = lastTimeUserLoggedInForSafes && lastTimeUserLoggedInForSafes[safeAddress] ? lastTimeUserLoggedInForSafes[safeAddress] diff --git a/src/routes/safe/store/models/safe.ts b/src/routes/safe/store/models/safe.ts index 40eb1621..50b7b10f 100644 --- a/src/routes/safe/store/models/safe.ts +++ b/src/routes/safe/store/models/safe.ts @@ -1,10 +1,15 @@ import { List, Map, Record, RecordOf, Set } from 'immutable' +export type SafeOwner = { + name: string + address: string +} + export type SafeRecordProps = { name: string address: string threshold: number - ethBalance: number + ethBalance: string owners: List<{ name: string; address: string }> activeTokens: Set activeAssets: Set @@ -23,7 +28,7 @@ const makeSafe = Record({ name: '', address: '', threshold: 0, - ethBalance: 0, + ethBalance: '0', owners: List([]), activeTokens: Set(), activeAssets: Set(), diff --git a/src/routes/safe/store/reducer/safe.ts b/src/routes/safe/store/reducer/safe.ts index 73e9c55e..8b3e23ec 100644 --- a/src/routes/safe/store/reducer/safe.ts +++ b/src/routes/safe/store/reducer/safe.ts @@ -16,6 +16,7 @@ import makeSafe from 'src/routes/safe/store/models/safe' import { checksumAddress } from 'src/utils/checksumAddress' export const SAFE_REDUCER_ID = 'safes' +export const DEFAULT_SAFE_INITIAL_STATE = 'NOT_ASKED' export const buildSafe = (storedSafe) => { const names = storedSafe.owners.map((owner) => owner.name) @@ -125,10 +126,8 @@ export default handleActions( [SET_LATEST_MASTER_CONTRACT_VERSION]: (state, action) => state.set('latestMasterContractVersion', action.payload), }, Map({ - // $FlowFixMe - defaultSafe: undefined, + defaultSafe: DEFAULT_SAFE_INITIAL_STATE, safes: Map(), - // $FlowFixMe latestMasterContractVersion: '', }), ) diff --git a/src/utils/storage/index.ts b/src/utils/storage/index.ts index 127db6f7..bf0e8fce 100644 --- a/src/utils/storage/index.ts +++ b/src/utils/storage/index.ts @@ -10,7 +10,7 @@ export const storage = new ImmortalStorage(stores) const PREFIX = `v2_${getNetwork()}` -export const loadFromStorage = async (key) => { +export const loadFromStorage = async (key: string): Promise => { try { const stringifiedValue = await storage.get(`${PREFIX}__${key}`) if (stringifiedValue === null || stringifiedValue === undefined) { @@ -24,7 +24,10 @@ export const loadFromStorage = async (key) => { } } -export const saveToStorage = async (key, value) => { +export const saveToStorage = async ( + key: string, + value: Record | boolean | string | number | Array, +): Promise => { try { const stringifiedValue = JSON.stringify(value) await storage.set(`${PREFIX}__${key}`, stringifiedValue) @@ -33,7 +36,7 @@ export const saveToStorage = async (key, value) => { } } -export const removeFromStorage = async (key) => { +export const removeFromStorage = async (key: string): Promise => { try { await storage.remove(`${PREFIX}__${key}`) } catch (err) {