Types
This commit is contained in:
parent
5c00d51c3c
commit
caa94c879b
|
@ -17,17 +17,20 @@ import { buildSafe } from 'src/routes/safe/store/actions/fetchSafe'
|
||||||
import { history } from 'src/store'
|
import { history } from 'src/store'
|
||||||
import { loadFromStorage } from 'src/utils/storage'
|
import { loadFromStorage } from 'src/utils/storage'
|
||||||
import { Dispatch } from 'redux'
|
import { Dispatch } from 'redux'
|
||||||
|
import { SafeOwner, SafeRecordProps } from '../../safe/store/models/safe'
|
||||||
|
import { List } from 'immutable'
|
||||||
|
|
||||||
export const loadSafe = async (
|
export const loadSafe = async (
|
||||||
safeName: string,
|
safeName: string,
|
||||||
safeAddress: string,
|
safeAddress: string,
|
||||||
owners: any,
|
owners: List<SafeOwner>,
|
||||||
addSafe: Dispatch<any>,
|
addSafe: Dispatch<any>,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const safeProps = await buildSafe(safeAddress, safeName)
|
const safeProps = await buildSafe(safeAddress, safeName)
|
||||||
safeProps.owners = owners
|
safeProps.owners = owners
|
||||||
|
|
||||||
const storedSafes = (await loadFromStorage(SAFES_KEY)) || {}
|
const storedSafes: SafeRecordProps = (await loadFromStorage(SAFES_KEY)) || {}
|
||||||
|
|
||||||
storedSafes[safeAddress] = safeProps
|
storedSafes[safeAddress] = safeProps
|
||||||
|
|
||||||
await saveSafes(storedSafes)
|
await saveSafes(storedSafes)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { List } from 'immutable'
|
import { List } from 'immutable'
|
||||||
|
|
||||||
import { makeOwner } from 'src/routes/safe/store/models/owner'
|
import { makeOwner } from 'src/routes/safe/store/models/owner'
|
||||||
|
import { SafeOwner } from '../../safe/store/models/safe'
|
||||||
|
|
||||||
export const getAccountsFrom = (values) => {
|
export const getAccountsFrom = (values) => {
|
||||||
const accounts = Object.keys(values)
|
const accounts = Object.keys(values)
|
||||||
|
@ -18,7 +19,7 @@ export const getNamesFrom = (values) => {
|
||||||
return accounts.map((account) => values[account]).slice(0, values.owners)
|
return accounts.map((account) => values[account]).slice(0, values.owners)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getOwnersFrom = (names, addresses) => {
|
export const getOwnersFrom = (names, addresses): List<SafeOwner> => {
|
||||||
const owners = names.map((name, index) => makeOwner({ name, address: addresses[index] }))
|
const owners = names.map((name, index) => makeOwner({ name, address: addresses[index] }))
|
||||||
|
|
||||||
return List(owners)
|
return List(owners)
|
||||||
|
|
|
@ -13,6 +13,7 @@ import updateSafe from 'src/routes/safe/store/actions/updateSafe'
|
||||||
import { makeOwner } from 'src/routes/safe/store/models/owner'
|
import { makeOwner } from 'src/routes/safe/store/models/owner'
|
||||||
|
|
||||||
import { checksumAddress } from 'src/utils/checksumAddress'
|
import { checksumAddress } from 'src/utils/checksumAddress'
|
||||||
|
import { SafeOwner } from '../models/safe'
|
||||||
|
|
||||||
const buildOwnersFrom = (
|
const buildOwnersFrom = (
|
||||||
safeOwners,
|
safeOwners,
|
||||||
|
@ -51,7 +52,7 @@ export const buildSafe = async (safeAdd, safeName, latestMasterContractVersion?:
|
||||||
|
|
||||||
const threshold = Number(thresholdStr)
|
const threshold = Number(thresholdStr)
|
||||||
const nonce = Number(nonceStr)
|
const nonce = Number(nonceStr)
|
||||||
const owners = List(buildOwnersFrom(remoteOwners, localSafe))
|
const owners = List<SafeOwner>(buildOwnersFrom(remoteOwners, localSafe))
|
||||||
const needsUpdate = safeNeedsUpdate(currentVersion, latestMasterContractVersion)
|
const needsUpdate = safeNeedsUpdate(currentVersion, latestMasterContractVersion)
|
||||||
const featuresEnabled = enabledFeatures(currentVersion)
|
const featuresEnabled = enabledFeatures(currentVersion)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
import { List, Map, Record, RecordOf, Set } from 'immutable'
|
import { List, Map, Record, RecordOf, Set } from 'immutable'
|
||||||
|
|
||||||
|
export type SafeOwner = {
|
||||||
|
name: string
|
||||||
|
address: string
|
||||||
|
}
|
||||||
|
|
||||||
export type SafeRecordProps = {
|
export type SafeRecordProps = {
|
||||||
name: string
|
name: string
|
||||||
address: string
|
address: string
|
||||||
|
|
|
@ -10,7 +10,7 @@ export const storage = new ImmortalStorage(stores)
|
||||||
|
|
||||||
const PREFIX = `v2_${getNetwork()}`
|
const PREFIX = `v2_${getNetwork()}`
|
||||||
|
|
||||||
export const loadFromStorage = async (key) => {
|
export const loadFromStorage = async (key: string) => {
|
||||||
try {
|
try {
|
||||||
const stringifiedValue = await storage.get(`${PREFIX}__${key}`)
|
const stringifiedValue = await storage.get(`${PREFIX}__${key}`)
|
||||||
if (stringifiedValue === null || stringifiedValue === undefined) {
|
if (stringifiedValue === null || stringifiedValue === undefined) {
|
||||||
|
|
Loading…
Reference in New Issue