save default safe to storage
This commit is contained in:
parent
b3840b17b2
commit
05059dd8aa
|
@ -34,11 +34,11 @@ const useStyles = makeStyles({
|
|||
paddingTop: 0,
|
||||
paddingBottom: 0,
|
||||
'&:hover $makeDefaultBtn': {
|
||||
visibility: 'initial'
|
||||
visibility: 'initial',
|
||||
},
|
||||
'&:focus $makeDefaultBtn': {
|
||||
visibility: 'initial'
|
||||
}
|
||||
visibility: 'initial',
|
||||
},
|
||||
},
|
||||
safeName: {
|
||||
color: secondary,
|
||||
|
|
|
@ -6,6 +6,7 @@ import { loadFromStorage, saveToStorage, removeFromStorage } from '~/utils/stora
|
|||
export const SAFES_KEY = 'SAFES'
|
||||
export const TX_KEY = 'TX'
|
||||
export const OWNERS_KEY = 'OWNERS'
|
||||
export const DEFAULT_SAFE_KEY = 'DEFAULT_SAFE'
|
||||
|
||||
export const getSafeName = async (safeAddress: string) => {
|
||||
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()
|
||||
}
|
||||
|
||||
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> => {
|
||||
try {
|
||||
await removeFromStorage(`${OWNERS_KEY}-${safeAddress}`)
|
||||
} catch (err) {
|
||||
// eslint-disable-next-line
|
||||
console.log('Error removing owners from localstorage')
|
||||
console.error('Error removing owners from localstorage: ', err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 { EDIT_SAFE_OWNER } from '~/routes/safe/store/actions/editSafeOwner'
|
||||
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 { getActiveTokensAddressesForAllSafes } from '~/routes/safe/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 { saveActiveTokens } from '~/logic/tokens/utils/tokensStorage'
|
||||
import { ACTIVATE_TOKEN_FOR_ALL_SAFES } from '~/routes/safe/store/actions/activateTokenForAllSafes'
|
||||
import { SET_DEFAULT_SAFE } from '~/routes/safe/store/actions/setDefaultSafe'
|
||||
|
||||
const watchedActions = [
|
||||
ADD_SAFE,
|
||||
|
@ -27,6 +30,7 @@ const watchedActions = [
|
|||
REPLACE_SAFE_OWNER,
|
||||
EDIT_SAFE_OWNER,
|
||||
ACTIVATE_TOKEN_FOR_ALL_SAFES,
|
||||
SET_DEFAULT_SAFE,
|
||||
]
|
||||
|
||||
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)))
|
||||
break
|
||||
}
|
||||
case SET_DEFAULT_SAFE: {
|
||||
if (action.payload) {
|
||||
saveDefaultSafe(action.payload)
|
||||
break
|
||||
}
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue