Merge branch 'development' of github.com:gnosis/safe-react into 139-load-create-improvements
This commit is contained in:
commit
ca9d228eb0
|
@ -6,7 +6,7 @@ import {
|
||||||
} from '~/config/names'
|
} from '~/config/names'
|
||||||
|
|
||||||
const devConfig = {
|
const devConfig = {
|
||||||
[TX_SERVICE_HOST]: 'https://safe-transaction-service.staging.gnosisdev.com/api/v1/',
|
[TX_SERVICE_HOST]: 'https://safe-transaction.staging.gnosisdev.com/api/v1/',
|
||||||
[SIGNATURES_VIA_METAMASK]: false,
|
[SIGNATURES_VIA_METAMASK]: false,
|
||||||
[RELAY_API_URL]: 'https://safe-relay.staging.gnosisdev.com/api/v1/',
|
[RELAY_API_URL]: 'https://safe-relay.staging.gnosisdev.com/api/v1/',
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import {
|
||||||
} from '~/config/names'
|
} from '~/config/names'
|
||||||
|
|
||||||
const prodConfig = {
|
const prodConfig = {
|
||||||
[TX_SERVICE_HOST]: 'https://safe-transaction-service.staging.gnosisdev.com/api/v1/',
|
[TX_SERVICE_HOST]: 'https://safe-transaction.staging.gnosisdev.com/api/v1/',
|
||||||
[SIGNATURES_VIA_METAMASK]: false,
|
[SIGNATURES_VIA_METAMASK]: false,
|
||||||
[RELAY_API_URL]: 'https://safe-relay.staging.gnosisdev.com/api/v1/',
|
[RELAY_API_URL]: 'https://safe-relay.staging.gnosisdev.com/api/v1/',
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ export const removeTokenFromStorage = async (safeAddress: string, token: Token)
|
||||||
|
|
||||||
export const removeFromActiveTokens = async (safeAddress: string, token: Token) => {
|
export const removeFromActiveTokens = async (safeAddress: string, token: Token) => {
|
||||||
const activeTokens = await getActiveTokens()
|
const activeTokens = await getActiveTokens()
|
||||||
const index = activeTokens.findIndex(activeToken => activeToken.name === token.name)
|
const index = activeTokens.findIndex((activeToken) => activeToken.name === token.name)
|
||||||
|
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
await saveActiveTokens(safeAddress, activeTokens.delete(index))
|
await saveActiveTokens(safeAddress, activeTokens.delete(index))
|
||||||
|
|
|
@ -133,7 +133,7 @@ class ManageOwners extends React.Component<Props, State> {
|
||||||
</Heading>
|
</Heading>
|
||||||
<Paragraph className={classes.annotation}>
|
<Paragraph className={classes.annotation}>
|
||||||
Add, remove and replace owners or rename existing owners. Owner names are only stored locally and never
|
Add, remove and replace owners or rename existing owners. Owner names are only stored locally and never
|
||||||
shared with Gnosis or any third parties
|
shared with Gnosis or any third parties.
|
||||||
</Paragraph>
|
</Paragraph>
|
||||||
<Table
|
<Table
|
||||||
label="Owners"
|
label="Owners"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// @flow
|
// @flow
|
||||||
import fetchSafe from '~/routes/safe/store/actions/fetchSafe'
|
import fetchSafe from '~/routes/safe/store/actions/fetchSafe'
|
||||||
import fetchTokenBalances from '~/routes/safe/store/actions/fetchTokenBalances'
|
import fetchTokenBalances from '~/routes/safe/store/actions/fetchTokenBalances'
|
||||||
|
import fetchEtherBalance from '~/routes/safe/store/actions/fetchEtherBalance'
|
||||||
import createTransaction from '~/routes/safe/store/actions/createTransaction'
|
import createTransaction from '~/routes/safe/store/actions/createTransaction'
|
||||||
import processTransaction from '~/routes/safe/store/actions/processTransaction'
|
import processTransaction from '~/routes/safe/store/actions/processTransaction'
|
||||||
import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions'
|
import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions'
|
||||||
|
@ -15,6 +16,7 @@ export type Actions = {
|
||||||
updateSafe: typeof updateSafe,
|
updateSafe: typeof updateSafe,
|
||||||
fetchTokens: typeof fetchTokens,
|
fetchTokens: typeof fetchTokens,
|
||||||
processTransaction: typeof processTransaction,
|
processTransaction: typeof processTransaction,
|
||||||
|
fetchEtherBalance: typeof fetchEtherBalance,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -25,4 +27,5 @@ export default {
|
||||||
fetchTokens,
|
fetchTokens,
|
||||||
fetchTransactions,
|
fetchTransactions,
|
||||||
updateSafe,
|
updateSafe,
|
||||||
|
fetchEtherBalance,
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ class SafeView extends React.Component<Props> {
|
||||||
|
|
||||||
fetchSafe(safeUrl)
|
fetchSafe(safeUrl)
|
||||||
fetchTokenBalances(safeUrl, activeTokens)
|
fetchTokenBalances(safeUrl, activeTokens)
|
||||||
|
|
||||||
// fetch tokens there to get symbols for tokens in TXs list
|
// fetch tokens there to get symbols for tokens in TXs list
|
||||||
fetchTokens()
|
fetchTokens()
|
||||||
|
|
||||||
|
@ -46,10 +47,11 @@ class SafeView extends React.Component<Props> {
|
||||||
|
|
||||||
checkForUpdates() {
|
checkForUpdates() {
|
||||||
const {
|
const {
|
||||||
safeUrl, activeTokens, fetchTokenBalances,
|
safeUrl, activeTokens, fetchTokenBalances, fetchEtherBalance,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
fetchTokenBalances(safeUrl, activeTokens)
|
fetchTokenBalances(safeUrl, activeTokens)
|
||||||
|
fetchEtherBalance(safeUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
// @flow
|
||||||
|
import type { Dispatch as ReduxDispatch } from 'redux'
|
||||||
|
import { type GlobalState } from '~/store/index'
|
||||||
|
import updateSafe from '~/routes/safe/store/actions/updateSafe'
|
||||||
|
import { getBalanceInEtherOf } from '~/logic/wallets/getWeb3'
|
||||||
|
|
||||||
|
const fetchEtherBalance = (safeAddress: string) => async (dispatch: ReduxDispatch<GlobalState>) => {
|
||||||
|
try {
|
||||||
|
const ethBalance = await getBalanceInEtherOf(safeAddress)
|
||||||
|
|
||||||
|
dispatch(updateSafe({ address: safeAddress, ethBalance }))
|
||||||
|
} catch (err) {
|
||||||
|
// eslint-disable-next-line
|
||||||
|
console.error('Error when fetching Ether balance:', err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default fetchEtherBalance
|
|
@ -45,7 +45,7 @@ const fetchTokenBalances = (safeAddress: string, tokens: List<Token>) => async (
|
||||||
dispatch(updateSafe({ address: safeAddress, balances: List(withBalances) }))
|
dispatch(updateSafe({ address: safeAddress, balances: List(withBalances) }))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.error('Error while loading active tokens from storage:', err)
|
console.error('Error when fetching token balances:', err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// @flow
|
// @flow
|
||||||
import type { Store, AnyAction } from 'redux'
|
import type { Store, AnyAction } from 'redux'
|
||||||
|
import { List } from 'immutable'
|
||||||
import { ADD_SAFE } from '~/routes/safe/store/actions/addSafe'
|
import { ADD_SAFE } from '~/routes/safe/store/actions/addSafe'
|
||||||
import { UPDATE_SAFE } from '~/routes/safe/store/actions/updateSafe'
|
import { UPDATE_SAFE } from '~/routes/safe/store/actions/updateSafe'
|
||||||
import { REMOVE_SAFE } from '~/routes/safe/store/actions/removeSafe'
|
import { REMOVE_SAFE } from '~/routes/safe/store/actions/removeSafe'
|
||||||
|
@ -28,6 +29,21 @@ const watchedActions = [
|
||||||
ACTIVATE_TOKEN_FOR_ALL_SAFES,
|
ACTIVATE_TOKEN_FOR_ALL_SAFES,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const recalculateActiveTokens = (state: GlobalState): void => {
|
||||||
|
const tokens = tokensSelector(state)
|
||||||
|
const activeTokenAddresses = getActiveTokensAddressesForAllSafes(state)
|
||||||
|
|
||||||
|
const activeTokens: List<Token> = tokens.withMutations((map) => {
|
||||||
|
map.forEach((token: Token) => {
|
||||||
|
if (!activeTokenAddresses.has(token.address)) {
|
||||||
|
map.remove(token.address)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
saveActiveTokens(activeTokens)
|
||||||
|
}
|
||||||
|
|
||||||
const safeStorageMware = (store: Store<GlobalState>) => (next: Function) => async (action: AnyAction) => {
|
const safeStorageMware = (store: Store<GlobalState>) => (next: Function) => async (action: AnyAction) => {
|
||||||
const handledAction = next(action)
|
const handledAction = next(action)
|
||||||
|
|
||||||
|
@ -38,21 +54,7 @@ const safeStorageMware = (store: Store<GlobalState>) => (next: Function) => asyn
|
||||||
|
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ACTIVATE_TOKEN_FOR_ALL_SAFES: {
|
case ACTIVATE_TOKEN_FOR_ALL_SAFES: {
|
||||||
let { activeTokens } = action.payload
|
recalculateActiveTokens(state)
|
||||||
if (activeTokens) {
|
|
||||||
const tokens = tokensSelector(state)
|
|
||||||
const activeTokenAddresses = getActiveTokensAddressesForAllSafes(state)
|
|
||||||
|
|
||||||
activeTokens = tokens.withMutations((map) => {
|
|
||||||
map.forEach((token: Token) => {
|
|
||||||
if (!activeTokenAddresses.has(token.address)) {
|
|
||||||
map.remove(token.address)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
saveActiveTokens(activeTokens)
|
|
||||||
}
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case ADD_SAFE: {
|
case ADD_SAFE: {
|
||||||
|
@ -61,10 +63,13 @@ const safeStorageMware = (store: Store<GlobalState>) => (next: Function) => asyn
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case UPDATE_SAFE: {
|
case UPDATE_SAFE: {
|
||||||
const { safeAddress, owners } = action.payload
|
const { safeAddress, owners, activeTokens } = action.payload
|
||||||
if (safeAddress && owners) {
|
if (safeAddress && owners) {
|
||||||
setOwners(safeAddress, owners)
|
setOwners(safeAddress, owners)
|
||||||
}
|
}
|
||||||
|
if (activeTokens) {
|
||||||
|
recalculateActiveTokens(state)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case REMOVE_SAFE: {
|
case REMOVE_SAFE: {
|
||||||
|
@ -81,7 +86,7 @@ const safeStorageMware = (store: Store<GlobalState>) => (next: Function) => asyn
|
||||||
case REMOVE_SAFE_OWNER: {
|
case REMOVE_SAFE_OWNER: {
|
||||||
const { safeAddress, ownerAddress } = action.payload
|
const { safeAddress, ownerAddress } = action.payload
|
||||||
const { owners } = safes.get(safeAddress)
|
const { owners } = safes.get(safeAddress)
|
||||||
setOwners(safeAddress, owners.filter(o => o.address.toLowerCase() !== ownerAddress.toLowerCase()))
|
setOwners(safeAddress, owners.filter((o) => o.address.toLowerCase() !== ownerAddress.toLowerCase()))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case REPLACE_SAFE_OWNER: {
|
case REPLACE_SAFE_OWNER: {
|
||||||
|
@ -92,7 +97,7 @@ const safeStorageMware = (store: Store<GlobalState>) => (next: Function) => asyn
|
||||||
setOwners(
|
setOwners(
|
||||||
safeAddress,
|
safeAddress,
|
||||||
owners
|
owners
|
||||||
.filter(o => o.address.toLowerCase() !== oldOwnerAddress.toLowerCase())
|
.filter((o) => o.address.toLowerCase() !== oldOwnerAddress.toLowerCase())
|
||||||
.push(makeOwner({ address: ownerAddress, name: ownerName })),
|
.push(makeOwner({ address: ownerAddress, name: ownerName })),
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
|
@ -100,8 +105,8 @@ const safeStorageMware = (store: Store<GlobalState>) => (next: Function) => asyn
|
||||||
case EDIT_SAFE_OWNER: {
|
case EDIT_SAFE_OWNER: {
|
||||||
const { safeAddress, ownerAddress, ownerName } = action.payload
|
const { safeAddress, ownerAddress, ownerName } = action.payload
|
||||||
const { owners } = safes.get(safeAddress)
|
const { owners } = safes.get(safeAddress)
|
||||||
const ownerToUpdateIndex = owners.findIndex(o => o.address.toLowerCase() === ownerAddress.toLowerCase())
|
const ownerToUpdateIndex = owners.findIndex((o) => o.address.toLowerCase() === ownerAddress.toLowerCase())
|
||||||
setOwners(safeAddress, owners.update(ownerToUpdateIndex, owner => owner.set('name', ownerName)))
|
setOwners(safeAddress, owners.update(ownerToUpdateIndex, (owner) => owner.set('name', ownerName)))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue