save default safe to storage

This commit is contained in:
Mikhail Mikheev 2019-09-19 12:36:09 +04:00
parent b3840b17b2
commit 05059dd8aa
3 changed files with 31 additions and 5 deletions

View File

@ -34,11 +34,11 @@ const useStyles = makeStyles({
paddingTop: 0, paddingTop: 0,
paddingBottom: 0, paddingBottom: 0,
'&:hover $makeDefaultBtn': { '&:hover $makeDefaultBtn': {
visibility: 'initial' visibility: 'initial',
}, },
'&:focus $makeDefaultBtn': { '&:focus $makeDefaultBtn': {
visibility: 'initial' visibility: 'initial',
} },
}, },
safeName: { safeName: {
color: secondary, color: secondary,

View File

@ -6,6 +6,7 @@ import { loadFromStorage, saveToStorage, removeFromStorage } from '~/utils/stora
export const SAFES_KEY = 'SAFES' export const SAFES_KEY = 'SAFES'
export const TX_KEY = 'TX' export const TX_KEY = 'TX'
export const OWNERS_KEY = 'OWNERS' export const OWNERS_KEY = 'OWNERS'
export const DEFAULT_SAFE_KEY = 'DEFAULT_SAFE'
export const getSafeName = async (safeAddress: string) => { export const getSafeName = async (safeAddress: string) => {
const safes = await loadFromStorage(SAFES_KEY) const safes = await loadFromStorage(SAFES_KEY)
@ -42,11 +43,26 @@ export const getOwners = async (safeAddress: string): Promise<Map<string, string
return data ? Map(data) : Map() return data ? Map(data) : Map()
} }
export const getDefaultSafe = async (): Promise<string> => {
const defaultSafe = await loadFromStorage(DEFAULT_SAFE_KEY)
return defaultSafe || ''
}
export const saveDefaultSafe = async (safeAddress: string): Promise<void> => {
try {
await saveToStorage(DEFAULT_SAFE_KEY, safeAddress)
} catch (err) {
// eslint-disable-next-line
console.error('Error saving default save to storage: ', err)
}
}
export const removeOwners = async (safeAddress: string): Promise<void> => { export const removeOwners = async (safeAddress: string): Promise<void> => {
try { try {
await removeFromStorage(`${OWNERS_KEY}-${safeAddress}`) await removeFromStorage(`${OWNERS_KEY}-${safeAddress}`)
} catch (err) { } catch (err) {
// eslint-disable-next-line // eslint-disable-next-line
console.log('Error removing owners from localstorage') console.error('Error removing owners from localstorage: ', err)
} }
} }

View File

@ -9,7 +9,9 @@ import { REMOVE_SAFE_OWNER } from '~/routes/safe/store/actions/removeSafeOwner'
import { REPLACE_SAFE_OWNER } from '~/routes/safe/store/actions/replaceSafeOwner' import { REPLACE_SAFE_OWNER } from '~/routes/safe/store/actions/replaceSafeOwner'
import { EDIT_SAFE_OWNER } from '~/routes/safe/store/actions/editSafeOwner' import { EDIT_SAFE_OWNER } from '~/routes/safe/store/actions/editSafeOwner'
import { type GlobalState } from '~/store/' import { type GlobalState } from '~/store/'
import { saveSafes, setOwners, removeOwners } from '~/logic/safe/utils' import {
saveSafes, setOwners, removeOwners, saveDefaultSafe,
} from '~/logic/safe/utils'
import { safesMapSelector } from '~/routes/safeList/store/selectors' import { safesMapSelector } from '~/routes/safeList/store/selectors'
import { getActiveTokensAddressesForAllSafes } from '~/routes/safe/store/selectors' import { getActiveTokensAddressesForAllSafes } from '~/routes/safe/store/selectors'
import { tokensSelector } from '~/logic/tokens/store/selectors' import { tokensSelector } from '~/logic/tokens/store/selectors'
@ -17,6 +19,7 @@ import type { Token } from '~/logic/tokens/store/model/token'
import { makeOwner } from '~/routes/safe/store/models/owner' import { makeOwner } from '~/routes/safe/store/models/owner'
import { saveActiveTokens } from '~/logic/tokens/utils/tokensStorage' import { saveActiveTokens } from '~/logic/tokens/utils/tokensStorage'
import { ACTIVATE_TOKEN_FOR_ALL_SAFES } from '~/routes/safe/store/actions/activateTokenForAllSafes' import { ACTIVATE_TOKEN_FOR_ALL_SAFES } from '~/routes/safe/store/actions/activateTokenForAllSafes'
import { SET_DEFAULT_SAFE } from '~/routes/safe/store/actions/setDefaultSafe'
const watchedActions = [ const watchedActions = [
ADD_SAFE, ADD_SAFE,
@ -27,6 +30,7 @@ const watchedActions = [
REPLACE_SAFE_OWNER, REPLACE_SAFE_OWNER,
EDIT_SAFE_OWNER, EDIT_SAFE_OWNER,
ACTIVATE_TOKEN_FOR_ALL_SAFES, ACTIVATE_TOKEN_FOR_ALL_SAFES,
SET_DEFAULT_SAFE,
] ]
const recalculateActiveTokens = (state: GlobalState): void => { const recalculateActiveTokens = (state: GlobalState): void => {
@ -109,6 +113,12 @@ const safeStorageMware = (store: Store<GlobalState>) => (next: Function) => asyn
setOwners(safeAddress, owners.update(ownerToUpdateIndex, (owner) => owner.set('name', ownerName))) setOwners(safeAddress, owners.update(ownerToUpdateIndex, (owner) => owner.set('name', ownerName)))
break break
} }
case SET_DEFAULT_SAFE: {
if (action.payload) {
saveDefaultSafe(action.payload)
break
}
}
default: default:
break break
} }