mirror of
https://github.com/status-im/safe-react.git
synced 2025-02-25 16:05:25 +00:00
rewrite fetchSafe function to support updates
This commit is contained in:
parent
910382c5f2
commit
f486068778
@ -80,9 +80,9 @@
|
|||||||
"react": "^16.8.6",
|
"react": "^16.8.6",
|
||||||
"react-dom": "^16.8.6",
|
"react-dom": "^16.8.6",
|
||||||
"react-final-form": "^4.1.0",
|
"react-final-form": "^4.1.0",
|
||||||
"react-hot-loader": "4.8.3",
|
"react-hot-loader": "4.8.4",
|
||||||
"react-infinite-scroll-component": "^4.5.2",
|
"react-infinite-scroll-component": "^4.5.2",
|
||||||
"react-redux": "7.0.1",
|
"react-redux": "7.0.2",
|
||||||
"react-router-dom": "^4.3.1",
|
"react-router-dom": "^4.3.1",
|
||||||
"recompose": "^0.30.0",
|
"recompose": "^0.30.0",
|
||||||
"redux": "^4.0.1",
|
"redux": "^4.0.1",
|
||||||
@ -142,7 +142,7 @@
|
|||||||
"ethereumjs-abi": "^0.6.7",
|
"ethereumjs-abi": "^0.6.7",
|
||||||
"extract-text-webpack-plugin": "^4.0.0-beta.0",
|
"extract-text-webpack-plugin": "^4.0.0-beta.0",
|
||||||
"file-loader": "^3.0.1",
|
"file-loader": "^3.0.1",
|
||||||
"flow-bin": "0.96.0",
|
"flow-bin": "0.97.0",
|
||||||
"fs-extra": "^7.0.1",
|
"fs-extra": "^7.0.1",
|
||||||
"html-loader": "^0.5.5",
|
"html-loader": "^0.5.5",
|
||||||
"html-webpack-plugin": "^3.0.4",
|
"html-webpack-plugin": "^3.0.4",
|
||||||
|
@ -15,12 +15,12 @@ import { FIELD_LOAD_NAME, FIELD_LOAD_ADDRESS } from '../components/fields'
|
|||||||
type Props = SelectorProps & Actions
|
type Props = SelectorProps & Actions
|
||||||
|
|
||||||
export const loadSafe = async (safeName: string, safeAddress: string, addSafe: Function) => {
|
export const loadSafe = async (safeName: string, safeAddress: string, addSafe: Function) => {
|
||||||
const safeRecord = await buildSafe(safeAddress, safeName)
|
const safeProps = await buildSafe(safeAddress, safeName)
|
||||||
|
|
||||||
await addSafe(safeRecord)
|
await addSafe(safeProps)
|
||||||
|
|
||||||
const storedSafes = (await loadFromStorage(SAFES_KEY)) || {}
|
const storedSafes = (await loadFromStorage(SAFES_KEY)) || {}
|
||||||
storedSafes[safeAddress] = safeRecord.toJSON()
|
storedSafes[safeAddress] = safeProps
|
||||||
|
|
||||||
saveSafes(storedSafes)
|
saveSafes(storedSafes)
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,15 @@ import type { Dispatch as ReduxDispatch } from 'redux'
|
|||||||
import { List, Map } from 'immutable'
|
import { List, Map } from 'immutable'
|
||||||
import { type GlobalState } from '~/store/index'
|
import { type GlobalState } from '~/store/index'
|
||||||
import { makeOwner } from '~/routes/safe/store/models/owner'
|
import { makeOwner } from '~/routes/safe/store/models/owner'
|
||||||
import SafeRecord, { type SafeProps } from '~/routes/safe/store/models/safe'
|
import { type SafeProps } from '~/routes/safe/store/models/safe'
|
||||||
import { addSafe } from '~/routes/safe/store/actions/addSafe'
|
import { addSafe } from '~/routes/safe/store/actions/addSafe'
|
||||||
import { getOwners, getSafeName } from '~/logic/safe/utils'
|
import { getOwners, getSafeName } from '~/logic/safe/utils'
|
||||||
import { getGnosisSafeContract } from '~/logic/contracts/safeContracts'
|
import { getGnosisSafeContract } from '~/logic/contracts/safeContracts'
|
||||||
import { getWeb3, getBalanceInEtherOf } from '~/logic/wallets/getWeb3'
|
import { getWeb3, getBalanceInEtherOf } from '~/logic/wallets/getWeb3'
|
||||||
import updateSafe from '~/routes/safe/store/actions/updateSafe'
|
import updateSafe from '~/routes/safe/store/actions/updateSafe'
|
||||||
|
|
||||||
|
// eslint-disable-next-line
|
||||||
|
// eslint-disable-next-line
|
||||||
const buildOwnersFrom = (
|
const buildOwnersFrom = (
|
||||||
safeOwners: string[],
|
safeOwners: string[],
|
||||||
storedOwners: Map<string, string>, // eslint-disable-next-line
|
storedOwners: Map<string, string>, // eslint-disable-next-line
|
||||||
@ -35,18 +37,18 @@ export const buildSafe = async (safeAddress: string, safeName: string) => {
|
|||||||
ethBalance,
|
ethBalance,
|
||||||
}
|
}
|
||||||
|
|
||||||
return SafeRecord(safe)
|
return safe
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (safeAddress: string, update: boolean = false) => async (dispatch: ReduxDispatch<GlobalState>) => {
|
export default (safeAddress: string, update: boolean = false) => async (dispatch: ReduxDispatch<GlobalState>) => {
|
||||||
try {
|
try {
|
||||||
const safeName = (await getSafeName(safeAddress)) || 'LOADED SAFE'
|
const safeName = (await getSafeName(safeAddress)) || 'LOADED SAFE'
|
||||||
const safe = await buildSafe(safeAddress, safeName)
|
const safeProps: SafeProps = await buildSafe(safeAddress, safeName)
|
||||||
console.log(safe.toJS())
|
|
||||||
if (update) {
|
if (update) {
|
||||||
dispatch(updateSafe(safe))
|
dispatch(updateSafe(safeProps))
|
||||||
} else {
|
} else {
|
||||||
dispatch(addSafe(safe))
|
dispatch(addSafe(safeProps))
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
|
@ -66,7 +66,11 @@ export default handleActions<State, *>(
|
|||||||
[ADD_SAFE]: (state: State, action: ActionType<Function>): State => {
|
[ADD_SAFE]: (state: State, action: ActionType<Function>): State => {
|
||||||
const { safe }: { safe: Safe } = action.payload
|
const { safe }: { safe: Safe } = action.payload
|
||||||
|
|
||||||
return state.set(safe.address, safe)
|
// if you add a new safe it needs to be set as a record
|
||||||
|
// in case of update it shouldn't, because a record would be initialized
|
||||||
|
// with initial props and it would overwrite existing ones
|
||||||
|
|
||||||
|
return state.set(safe.address, SafeRecord(safe))
|
||||||
},
|
},
|
||||||
[UPDATE_SAFE_TOKENS]: (state: State, action: ActionType<Function>): State => {
|
[UPDATE_SAFE_TOKENS]: (state: State, action: ActionType<Function>): State => {
|
||||||
const { safeAddress, token: updatedToken } = action.payload
|
const { safeAddress, token: updatedToken } = action.payload
|
||||||
|
Loading…
x
Reference in New Issue
Block a user