update safe and token models

This commit is contained in:
Mikhail Mikheev 2019-04-10 17:24:32 +04:00
parent f5983447ee
commit 93cf045c00
7 changed files with 17 additions and 19 deletions

View File

@ -8,9 +8,6 @@ export type TokenProps = {
symbol: string,
decimals: number,
logoUri: string,
funds: string,
status: boolean,
removable: boolean,
}
export const makeToken: RecordFactory<TokenProps> = Record({
@ -19,9 +16,6 @@ export const makeToken: RecordFactory<TokenProps> = Record({
symbol: '',
decimals: 0,
logoUri: '',
funds: '0',
status: true,
removable: false,
})
export type Token = RecordOf<TokenProps>

View File

@ -1,7 +1,7 @@
// @flow
import { List } from 'immutable'
import { createAction } from 'redux-actions'
import { type Safe, makeSafe } from '~/routes/safe/store/model/safe'
import SafeRecord, { type Safe } from '~/routes/safe/store/model/safe'
import { saveSafes, setOwners } from '~/logic/safe/utils'
import { makeOwner, type Owner } from '~/routes/safe/store/model/owner'
import type { Dispatch as ReduxDispatch, GetState } from 'redux'
@ -37,7 +37,7 @@ const saveSafe = (
const owners: List<Owner> = buildOwnersFrom(ownersName, ownersAddress)
const state: GlobalState = getState()
const safe: Safe = makeSafe({
const safe: Safe = SafeRecord({
name,
address,
threshold,

View File

@ -3,7 +3,7 @@ import type { Dispatch as ReduxDispatch } from 'redux'
import { List, Map } from 'immutable'
import { type GlobalState } from '~/store/index'
import { makeOwner } from '~/routes/safe/store/model/owner'
import { type SafeProps, makeSafe } from '~/routes/safe/store/model/safe'
import SafeRecord, { type SafeProps } from '~/routes/safe/store/model/safe'
import updateSafe from '~/routes/safe/store/actions/updateSafe'
import { getOwners, getSafeName } from '~/logic/safe/utils'
import { getGnosisSafeContract } from '~/logic/contracts/safeContracts'
@ -29,7 +29,7 @@ export const buildSafe = async (safeAddress: string, safeName: string) => {
owners,
}
return makeSafe(safe)
return SafeRecord(safe)
}
export default (safeAddress: string) => async (dispatch: ReduxDispatch<GlobalState>) => {

View File

@ -1,5 +1,5 @@
// @flow
import { List, Record } from 'immutable'
import { List, Record, Map } from 'immutable'
import type { RecordFactory, RecordOf } from 'immutable'
import type { Owner } from '~/routes/safe/store/model/owner'
@ -8,15 +8,17 @@ export type SafeProps = {
address: string,
threshold: number,
owners: List<Owner>,
activeTokensBalances: Map<String, String>,
}
export const makeSafe: RecordFactory<SafeProps> = Record({
const SafeRecord: RecordFactory<SafeProps> = Record({
name: '',
address: '',
threshold: 0,
owners: List([]),
activeTokensBalances: Map([]),
})
export type Safe = RecordOf<SafeProps>
// Useage const someRecord: Safe = makeSafe({ name: ... })
export default SafeRecord

View File

@ -2,7 +2,7 @@
import { Map } from 'immutable'
import { handleActions, type ActionType } from 'redux-actions'
import { ADD_SAFE, buildOwnersFrom } from '~/routes/safe/store/actions/addSafe'
import { type Safe, type SafeProps, makeSafe } from '~/routes/safe/store/model/safe'
import SafeRecord, { type Safe, type SafeProps } from '~/routes/safe/store/model/safe'
import { type OwnerProps } from '~/routes/safe/store/model/owner'
import { loadFromStorage } from '~/utils/storage'
import { SAFES_KEY } from '~/logic/safe/utils'
@ -21,10 +21,12 @@ export const buildSafe = (storedSafe: SafeProps) => {
address: storedSafe.address,
name: storedSafe.name,
threshold: storedSafe.threshold,
activeTokens: storedSafe.activeTokens,
balances: storedSafe.balances,
owners,
}
return makeSafe(safe)
return SafeRecord(safe)
}
const buildSafesFrom = (loadedSafes: Object): Map<string, Safe> => {

View File

@ -1,12 +1,12 @@
// @flow
import { makeSafe, type Safe } from '~/routes/safe/store/model/safe'
import SafeRecord, { type Safe } from '~/routes/safe/store/model/safe'
import { buildOwnersFrom } from '~/routes/safe/store/actions/addSafe'
class SafeBuilder {
safe: Safe
constructor() {
this.safe = makeSafe()
this.safe = SafeRecord()
}
withAddress(address: string) {

View File

@ -1,5 +1,5 @@
// @flow
import { makeSafe, type Safe } from '~/routes/safe/store/model/safe'
import SafeRecord, { type Safe } from '~/routes/safe/store/model/safe'
import addSafe, { buildOwnersFrom } from '~/routes/safe/store/actions/addSafe'
import {
FIELD_NAME,
@ -18,7 +18,7 @@ class SafeBuilder {
safe: Safe
constructor() {
this.safe = makeSafe()
this.safe = SafeRecord()
}
withAddress(address: string) {