diff --git a/package.json b/package.json
index 891e70de..16ecabd9 100644
--- a/package.json
+++ b/package.json
@@ -80,9 +80,9 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-final-form": "^4.1.0",
- "react-hot-loader": "^4.8.2",
+ "react-hot-loader": "4.8.4",
"react-infinite-scroll-component": "^4.5.2",
- "react-redux": "^6.0.1",
+ "react-redux": "7.0.2",
"react-router-dom": "^4.3.1",
"recompose": "^0.30.0",
"redux": "^4.0.1",
@@ -117,11 +117,11 @@
"@babel/preset-flow": "^7.0.0-beta.40",
"@babel/preset-react": "^7.0.0-beta.40",
"@sambego/storybook-state": "^1.0.7",
- "@storybook/addon-actions": "^5.0.6",
- "@storybook/addon-knobs": "^5.0.6",
- "@storybook/addon-links": "^5.0.6",
- "@storybook/react": "^5.0.6",
- "autoprefixer": "^9.4.10",
+ "@storybook/addon-actions": "5.0.9",
+ "@storybook/addon-knobs": "5.0.9",
+ "@storybook/addon-links": "5.0.9",
+ "@storybook/react": "5.0.9",
+ "autoprefixer": "9.5.1",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.1.0",
@@ -134,38 +134,38 @@
"detect-port": "^1.2.2",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
- "eslint-plugin-flowtype": "^3.4.2",
- "eslint-plugin-import": "^2.9.0",
+ "eslint-plugin-flowtype": "3.6.1",
+ "eslint-plugin-import": "2.17.2",
"eslint-plugin-jest": "^22.3.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.7.0",
"ethereumjs-abi": "^0.6.7",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"file-loader": "^3.0.1",
- "flow-bin": "0.96.0",
+ "flow-bin": "0.97.0",
"fs-extra": "^7.0.1",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.0.4",
"jest": "^24.1.0",
"json-loader": "^0.5.7",
- "mini-css-extract-plugin": "^0.5.0",
+ "mini-css-extract-plugin": "0.6.0",
"postcss-loader": "^3.0.0",
"postcss-mixins": "^6.2.0",
"postcss-simple-vars": "^5.0.2",
"pre-commit": "^1.2.2",
"prettier-eslint-cli": "^4.7.1",
- "run-with-testrpc": "^0.3.0",
+ "run-with-testrpc": "0.3.1",
"storybook-host": "^5.0.3",
"storybook-router": "^0.3.3",
"style-loader": "^0.23.1",
- "truffle": "^5.0.10",
+ "truffle": "5.0.12",
"truffle-contract": "^4.0.11",
- "truffle-solidity-loader": "^0.1.10",
+ "truffle-solidity-loader": "0.1.12",
"uglifyjs-webpack-plugin": "^2.1.2",
"webpack": "^4.1.1",
- "webpack-bundle-analyzer": "^3.1.0",
+ "webpack-bundle-analyzer": "3.3.2",
"webpack-cli": "^3.2.3",
- "webpack-dev-server": "^3.1.0",
+ "webpack-dev-server": "3.3.1",
"webpack-manifest-plugin": "^2.0.0-rc.2"
}
}
diff --git a/readme.md b/readme.md
index 2101aecc..3cc96031 100644
--- a/readme.md
+++ b/readme.md
@@ -11,12 +11,14 @@ These instructions will get you a copy of the project up and running on your loc
What things you need to install the software and how to install them
```
-npm install truffle // recommended usage of -g flag
-npm install ganache-cli // recommended usage of -g flag
-npm install flow-type // recommended usage of -g flag
+yarn add truffle // recommended usage of -g flag
+yarn add ganache-cli // recommended usage of -g flag
+yarn add flow-type // recommended usage of -g flag
git clone https://github.com/gnosis/safe-contracts.git
```
+We use [yarn](https://yarnpkg.com) in our infrastacture, so we decided to go with yarn in the README
+
### Installing
A step by step series of examples that tell you have to get a development env running
@@ -29,14 +31,14 @@ ganache-cli -b 3
Start the project in the other one
```
cd safe-contracts && truffle compile && truffle migrate && cd ..
-npm install
-npm start
+yarn install
+yarn start
```
## Running the tests
```
-npm test
+yarn test
```
diff --git a/src/index.js b/src/index.js
index 4b31cb2e..9b33ff72 100644
--- a/src/index.js
+++ b/src/index.js
@@ -6,7 +6,9 @@ import ReactDOM from 'react-dom'
import Root from '~/components/Root'
import { store } from '~/store'
import loadSafesFromStorage from '~/routes/safe/store/actions/loadSafesFromStorage'
+import loadActiveTokens from '~/logic/tokens/store/actions/loadActiveTokens'
+store.dispatch(loadActiveTokens())
store.dispatch(loadSafesFromStorage())
ReactDOM.render(, document.getElementById('root'))
diff --git a/src/logic/safe/safeFrontendOperations.js b/src/logic/safe/safeFrontendOperations.js
index 6e30b687..8a3cfc57 100644
--- a/src/logic/safe/safeFrontendOperations.js
+++ b/src/logic/safe/safeFrontendOperations.js
@@ -1,10 +1,10 @@
// @flow
import { List } from 'immutable'
-import { type Transaction } from '~/routes/safe/store/model/transaction'
+import { type Transaction } from '~/routes/safe/store/models/transaction'
import { executeTransaction, approveTransaction } from '~/logic/safe/safeBlockchainOperations'
import { EMPTY_DATA } from '~/logic/wallets/ethTransactions'
import { getWeb3 } from '~/logic/wallets/getWeb3'
-import { type Safe } from '~/routes/safe/store/model/safe'
+import { type Safe } from '~/routes/safe/store/models/safe'
import { getGnosisSafeContract } from '~/logic/contracts/safeContracts'
import { storeSubject } from '~/utils/storage/transactions'
diff --git a/src/logic/safe/utils/safeStorage.js b/src/logic/safe/utils/safeStorage.js
index b8fac592..2301a5e1 100644
--- a/src/logic/safe/utils/safeStorage.js
+++ b/src/logic/safe/utils/safeStorage.js
@@ -1,5 +1,5 @@
// @flow
-import { type Owner } from '~/routes/safe/store/model/owner'
+import { type Owner } from '~/routes/safe/store/models/owner'
import { List, Map } from 'immutable'
import { loadFromStorage, saveToStorage } from '~/utils/storage'
diff --git a/src/logic/tokens/store/actions/addToken.js b/src/logic/tokens/store/actions/addToken.js
index 601f241d..6d3fe9e4 100644
--- a/src/logic/tokens/store/actions/addToken.js
+++ b/src/logic/tokens/store/actions/addToken.js
@@ -1,9 +1,9 @@
// @flow
import { createAction } from 'redux-actions'
import { type Token } from '~/logic/tokens/store/model/token'
-import { setActiveTokens, getActiveTokens, setToken } from '~/logic/tokens/utils/tokensStorage'
+import { saveActiveTokens, getActiveTokens, setToken } from '~/logic/tokens/utils/tokensStorage'
import type { Dispatch as ReduxDispatch } from 'redux'
-import { type GlobalState } from '~/store/index'
+import { type GlobalState } from '~/store/'
export const ADD_TOKEN = 'ADD_TOKEN'
@@ -14,17 +14,16 @@ type AddTokenProps = {
export const addToken = createAction(
ADD_TOKEN,
- (safeAddress: string, token: Token): AddTokenProps => ({
- safeAddress,
+ (token: Token): AddTokenProps => ({
token,
}),
)
const saveToken = (safeAddress: string, token: Token) => async (dispatch: ReduxDispatch) => {
- dispatch(addToken(safeAddress, token))
+ dispatch(addToken(token))
const activeTokens = await getActiveTokens(safeAddress)
- await setActiveTokens(safeAddress, activeTokens.push(token.toJS()))
+ await saveActiveTokens(safeAddress, activeTokens.push(token.toJS()))
setToken(safeAddress, token)
}
diff --git a/src/logic/tokens/store/actions/disableToken.js b/src/logic/tokens/store/actions/disableToken.js
deleted file mode 100644
index ceafec7c..00000000
--- a/src/logic/tokens/store/actions/disableToken.js
+++ /dev/null
@@ -1,21 +0,0 @@
-// @flow
-import { createAction } from 'redux-actions'
-import { type Token } from '~/logic/tokens/store/model/token'
-import type { Dispatch as ReduxDispatch } from 'redux'
-import { type GlobalState } from '~/store/index'
-import { removeFromActiveTokens } from '~/logic/tokens/utils/tokensStorage'
-
-export const DISABLE_TOKEN = 'DISABLE_TOKEN'
-
-export const disableToken = createAction(DISABLE_TOKEN, (safeAddress: string, token: Token) => ({
- safeAddress,
- token,
-}))
-
-const hideToken = (safeAddress: string, token: Token) => async (dispatch: ReduxDispatch) => {
- dispatch(disableToken(safeAddress, token))
-
- await removeFromActiveTokens(safeAddress, token)
-}
-
-export default hideToken
diff --git a/src/logic/tokens/store/actions/enableToken.js b/src/logic/tokens/store/actions/enableToken.js
deleted file mode 100644
index 055433db..00000000
--- a/src/logic/tokens/store/actions/enableToken.js
+++ /dev/null
@@ -1,22 +0,0 @@
-// @flow
-import { createAction } from 'redux-actions'
-import type { Dispatch as ReduxDispatch } from 'redux'
-import { type GlobalState } from '~/store/index'
-import { type Token } from '~/logic/tokens/store/model/token'
-import { setActiveTokens, getActiveTokens } from '~/logic/tokens/utils/tokensStorage'
-
-export const ENABLE_TOKEN = 'ENABLE_TOKEN'
-
-export const enableToken = createAction(ENABLE_TOKEN, (safeAddress: string, token: Token) => ({
- safeAddress,
- token,
-}))
-
-const setTokenEnabled = (safeAddress: string, token: Token) => async (dispatch: ReduxDispatch) => {
- dispatch(enableToken(safeAddress, token))
-
- const activeTokens = await getActiveTokens(safeAddress)
- await setActiveTokens(safeAddress, activeTokens.push(token))
-}
-
-export default setTokenEnabled
diff --git a/src/logic/tokens/store/actions/fetchTokens.js b/src/logic/tokens/store/actions/fetchTokens.js
index 4c68ce33..82385118 100644
--- a/src/logic/tokens/store/actions/fetchTokens.js
+++ b/src/logic/tokens/store/actions/fetchTokens.js
@@ -1,17 +1,14 @@
// @flow
-import { List, Map } from 'immutable'
+import { List } from 'immutable'
import contract from 'truffle-contract'
import axios from 'axios'
-import { BigNumber } from 'bignumber.js'
import type { Dispatch as ReduxDispatch } from 'redux'
import StandardToken from '@gnosis.pm/util-contracts/build/contracts/GnosisStandardToken.json'
import HumanFriendlyToken from '@gnosis.pm/util-contracts/build/contracts/HumanFriendlyToken.json'
import { getWeb3 } from '~/logic/wallets/getWeb3'
import { type GlobalState } from '~/store/index'
-import { makeToken, type Token, type TokenProps } from '~/logic/tokens/store/model/token'
+import { makeToken, type TokenProps } from '~/logic/tokens/store/model/token'
import { ensureOnce } from '~/utils/singleton'
-import { getActiveTokens, getTokens } from '~/logic/tokens/utils/tokensStorage'
-import { getSafeEthToken } from '~/logic/tokens/utils/tokenHelpers'
import saveTokens from './saveTokens'
import { getRelayUrl } from '~/config/index'
@@ -34,66 +31,28 @@ export const getHumanFriendlyToken = ensureOnce(createHumanFriendlyTokenContract
export const getStandardTokenContract = ensureOnce(createStandardTokenContract)
-export const calculateBalanceOf = async (tokenAddress: string, address: string, decimals: number) => {
- const erc20Token = await getStandardTokenContract()
- let balance = 0
-
- try {
- const token = await erc20Token.at(tokenAddress)
- balance = await token.balanceOf(address)
- } catch (err) {
- console.error('Failed to fetch token balances: ', err)
- }
-
- return new BigNumber(balance).div(10 ** decimals).toString()
-}
-
-export const fetchTokensData = async () => {
+const fetchTokenList = async () => {
const apiUrl = getRelayUrl()
const url = `${apiUrl}/tokens`
const errMsg = 'Error querying safe balances'
return axios.get(url, errMsg)
}
-export const fetchTokens = (safeAddress: string) => async (dispatch: ReduxDispatch) => {
- const tokens: List = await getActiveTokens(safeAddress)
- const ethBalance = await getSafeEthToken(safeAddress)
- const customTokens = await getTokens(safeAddress)
- const {
- data: { results },
- } = await fetchTokensData()
-
+export const fetchTokens = () => async (dispatch: ReduxDispatch) => {
try {
- const balancesRecords = await Promise.all(
- results.map(async (item: TokenProps) => {
- const status = tokens.findIndex(activeToken => activeToken.name === item.name) !== -1
- const funds = status ? await calculateBalanceOf(item.address, safeAddress, item.decimals) : '0'
+ const {
+ data: { results: tokenList },
+ } = await fetchTokenList()
- return makeToken({ ...item, status, funds })
- }),
- )
+ const tokens = List(tokenList.map((token: TokenProps) => makeToken(token)))
- const customTokenRecords = await Promise.all(
- customTokens.map(async (item: TokenProps) => {
- const status = tokens.findIndex(activeToken => activeToken.name === item.name) !== -1
- const funds = status ? await calculateBalanceOf(item.address, safeAddress, item.decimals) : '0'
-
- return makeToken({ ...item, status, funds })
- }),
- )
-
- const balances: Map = Map().withMutations((map) => {
- balancesRecords.forEach(record => map.set(record.address, record))
- customTokenRecords.forEach(record => map.set(record.address, record))
-
- map.set(ethBalance.address, ethBalance)
- })
-
- return dispatch(saveTokens(safeAddress, balances))
+ dispatch(saveTokens(tokens))
} catch (err) {
// eslint-disable-next-line
- console.log('Error fetching tokens... ' + err)
+ console.log('Error fetching token list ' + err)
return Promise.resolve()
}
}
+
+export default fetchTokens
diff --git a/src/logic/tokens/store/actions/loadActiveTokens.js b/src/logic/tokens/store/actions/loadActiveTokens.js
new file mode 100644
index 00000000..2037c7e6
--- /dev/null
+++ b/src/logic/tokens/store/actions/loadActiveTokens.js
@@ -0,0 +1,24 @@
+// @flow
+import type { Dispatch as ReduxDispatch } from 'redux'
+import { Map, List } from 'immutable'
+import { type TokenProps, type Token, makeToken } from '~/logic/tokens/store/model/token'
+import { type GlobalState } from '~/store/index'
+import { getActiveTokens } from '~/logic/tokens/utils/tokensStorage'
+import saveTokens from './saveTokens'
+
+const loadActiveTokens = () => async (dispatch: ReduxDispatch) => {
+ try {
+ const tokens: Map = await getActiveTokens()
+
+ const tokenRecordsList: List = List(
+ Object.values(tokens).map(token => makeToken(token)),
+ )
+
+ dispatch(saveTokens(tokenRecordsList))
+ } catch (err) {
+ // eslint-disable-next-line
+ console.error('Error while loading active tokens from storage:', err)
+ }
+}
+
+export default loadActiveTokens
diff --git a/src/logic/tokens/store/actions/saveTokens.js b/src/logic/tokens/store/actions/saveTokens.js
index f2399b85..bc2a3800 100644
--- a/src/logic/tokens/store/actions/saveTokens.js
+++ b/src/logic/tokens/store/actions/saveTokens.js
@@ -1,37 +1,19 @@
// @flow
-import { Map, List } from 'immutable'
+import { Map } from 'immutable'
import { createAction } from 'redux-actions'
-import type { Dispatch as ReduxDispatch } from 'redux'
import { type Token } from '~/logic/tokens/store/model/token'
-import { ensureOnceAsync } from '~/utils/singleton'
-import { type GlobalState } from '~/store/index'
-import { setActiveTokens } from '~/logic/tokens/utils/tokensStorage'
-import { calculateActiveErc20TokensFrom } from '~/logic/tokens/utils/tokenHelpers'
export const ADD_TOKENS = 'ADD_TOKENS'
-const setTokensOnce = ensureOnceAsync(setActiveTokens)
-
type TokenProps = {
- safeAddress: string,
tokens: Map,
}
-export const addTokens = createAction(
+const addTokens = createAction(
ADD_TOKENS,
- (safeAddress: string, tokens: Map): TokenProps => ({
- safeAddress,
+ (tokens: Map): TokenProps => ({
tokens,
}),
)
-const saveTokens = (safeAddress: string, tokens: Map) => async (
- dispatch: ReduxDispatch,
-) => {
- dispatch(addTokens(safeAddress, tokens))
-
- const activeAddresses: List = calculateActiveErc20TokensFrom(tokens.toList())
- await setTokensOnce(safeAddress, activeAddresses)
-}
-
-export default saveTokens
+export default addTokens
diff --git a/src/logic/tokens/store/model/token.js b/src/logic/tokens/store/model/token.js
index 7705ce8a..bbe9ce3f 100644
--- a/src/logic/tokens/store/model/token.js
+++ b/src/logic/tokens/store/model/token.js
@@ -8,9 +8,7 @@ export type TokenProps = {
symbol: string,
decimals: number,
logoUri: string,
- funds: string,
- status: boolean,
- removable: boolean,
+ balance: string,
}
export const makeToken: RecordFactory = Record({
@@ -19,9 +17,9 @@ export const makeToken: RecordFactory = Record({
symbol: '',
decimals: 0,
logoUri: '',
- funds: '0',
- status: true,
- removable: false,
+ balance: undefined,
})
+// balance is only set in extendedSafeTokensSelector when we display user's token balances
+
export type Token = RecordOf
diff --git a/src/logic/tokens/store/reducer/tokens.js b/src/logic/tokens/store/reducer/tokens.js
index 70f87bcd..1bec30e9 100644
--- a/src/logic/tokens/store/reducer/tokens.js
+++ b/src/logic/tokens/store/reducer/tokens.js
@@ -5,8 +5,6 @@ import { type Token } from '~/logic/tokens/store/model/token'
import { ADD_TOKEN } from '~/logic/tokens/store/actions/addToken'
import { REMOVE_TOKEN } from '~/logic/tokens/store/actions/removeToken'
import { ADD_TOKENS } from '~/logic/tokens/store/actions/saveTokens'
-import { DISABLE_TOKEN } from '~/logic/tokens/store/actions/disableToken'
-import { ENABLE_TOKEN } from '~/logic/tokens/store/actions/enableToken'
export const TOKEN_REDUCER_ID = 'tokens'
@@ -15,39 +13,27 @@ export type State = Map>
export default handleActions(
{
[ADD_TOKENS]: (state: State, action: ActionType): State => {
- const { safeAddress, tokens } = action.payload
+ const { tokens } = action.payload
- return state.update(safeAddress, (prevSafe: Map) => {
- if (!prevSafe) {
- return tokens
- }
-
- return prevSafe.equals(tokens) ? prevSafe : tokens
+ const newState = state.withMutations((map) => {
+ tokens.forEach((token) => {
+ map.set(token.address, token)
+ })
})
+
+ return newState
},
[ADD_TOKEN]: (state: State, action: ActionType): State => {
- const { safeAddress, token } = action.payload
+ const { token } = action.payload
const { address: tokenAddress } = token
- return state.setIn([safeAddress, tokenAddress], token)
+ return state.set(tokenAddress, token)
},
[REMOVE_TOKEN]: (state: State, action: ActionType): State => {
- const { safeAddress, token } = action.payload
+ const { token } = action.payload
const { address: tokenAddress } = token
- return state.removeIn([safeAddress, tokenAddress])
- },
- [DISABLE_TOKEN]: (state: State, action: ActionType): State => {
- const { safeAddress, token } = action.payload
- const { address: tokenAddress } = token
-
- return state.setIn([safeAddress, tokenAddress, 'status'], false)
- },
- [ENABLE_TOKEN]: (state: State, action: ActionType): State => {
- const { safeAddress, token } = action.payload
- const { address: tokenAddress } = token
-
- return state.setIn([safeAddress, tokenAddress, 'status'], true)
+ return state.remove(tokenAddress)
},
},
Map(),
diff --git a/src/logic/tokens/store/selectors/index.js b/src/logic/tokens/store/selectors/index.js
index ad403dde..30ab6b48 100644
--- a/src/logic/tokens/store/selectors/index.js
+++ b/src/logic/tokens/store/selectors/index.js
@@ -1,45 +1,19 @@
// @flow
import { List, Map } from 'immutable'
import { createSelector, type Selector } from 'reselect'
-import { safeParamAddressSelector, type RouterProps } from '~/routes/safe/store/selectors'
+import { type RouterProps } from '~/routes/safe/store/selectors'
import { type GlobalState } from '~/store'
import { TOKEN_REDUCER_ID } from '~/logic/tokens/store/reducer/tokens'
import { type Token } from '~/logic/tokens/store/model/token'
-const balancesSelector = (state: GlobalState) => state[TOKEN_REDUCER_ID]
+export const tokensSelector = (state: GlobalState) => state[TOKEN_REDUCER_ID]
-export const tokensSelector: Selector> = createSelector(
- balancesSelector,
- safeParamAddressSelector,
- (tokens: Map>, address: string) => {
- if (!address) {
- return Map()
- }
-
- return tokens.get(address) || Map()
- },
-)
-
-export const tokenListSelector = createSelector(
+export const tokenListSelector: Selector, List> = createSelector(
tokensSelector,
(tokens: Map) => tokens.toList(),
)
-export const activeTokensSelector = createSelector(
- tokenListSelector,
- (tokens: List) => tokens.filter((token: Token) => token.get('status')),
-)
-
-export const orderedTokenListSelector = createSelector(
+export const orderedTokenListSelector: Selector> = createSelector(
tokenListSelector,
(tokens: List) => tokens.sortBy((token: Token) => token.get('symbol')),
)
-
-export const tokenAddressesSelector = createSelector(
- tokenListSelector,
- (balances: List) => {
- const addresses = List().withMutations(list => balances.map(token => list.push(token.address)))
-
- return addresses
- },
-)
diff --git a/src/logic/tokens/utils/tokenHelpers.js b/src/logic/tokens/utils/tokenHelpers.js
index 3265af2b..a7aecd2f 100644
--- a/src/logic/tokens/utils/tokenHelpers.js
+++ b/src/logic/tokens/utils/tokenHelpers.js
@@ -1,29 +1,26 @@
// @flow
import { List } from 'immutable'
import logo from '~/assets/icons/icon_etherTokens.svg'
-import { getBalanceInEtherOf } from '~/logic/wallets/getWeb3'
import { makeToken, type Token } from '~/logic/tokens/store/model/token'
-export const ETH_ADDRESS = '0'
+export const ETH_ADDRESS = '0x000'
export const isEther = (symbol: string) => symbol === 'ETH'
-export const getSafeEthToken = async (safeAddress: string) => {
- const balance = await getBalanceInEtherOf(safeAddress)
-
- const ethBalance = makeToken({
- address: '0',
+export const getEthAsToken = (balance: string) => {
+ const eth = makeToken({
+ address: ETH_ADDRESS,
name: 'Ether',
symbol: 'ETH',
decimals: 18,
logoUri: logo,
- funds: balance,
+ balance,
})
- return ethBalance
+ return eth
}
export const calculateActiveErc20TokensFrom = (tokens: List) => {
- const addresses = List().withMutations(list => tokens.forEach((token: Token) => {
+ const activeTokens = List().withMutations(list => tokens.forEach((token: Token) => {
const isDeactivated = isEther(token.symbol) || !token.status
if (isDeactivated) {
return
@@ -32,5 +29,5 @@ export const calculateActiveErc20TokensFrom = (tokens: List) => {
list.push(token)
}))
- return addresses
+ return activeTokens
}
diff --git a/src/logic/tokens/utils/tokensStorage.js b/src/logic/tokens/utils/tokensStorage.js
index 02805649..b2b4a3b0 100644
--- a/src/logic/tokens/utils/tokensStorage.js
+++ b/src/logic/tokens/utils/tokensStorage.js
@@ -1,44 +1,41 @@
// @flow
-import { List } from 'immutable'
+import { List, Map } from 'immutable'
import { type Token, type TokenProps } from '~/logic/tokens/store/model/token'
import { loadFromStorage, saveToStorage } from '~/utils/storage'
export const ACTIVE_TOKENS_KEY = 'ACTIVE_TOKENS'
-export const TOKENS_KEY = 'TOKENS'
+export const CUSTOM_TOKENS_KEY = 'CUSTOM_TOKENS'
-const getActiveTokensKey = (safeAddress: string) => `${ACTIVE_TOKENS_KEY}-${safeAddress}`
-const getTokensKey = (safeAddress: string) => `${TOKENS_KEY}-${safeAddress}`
+// Tokens which are active at least in one of used safes in the app should be saved to localstorage
+// to avoid iterating a large amount of data of tokens from the backend
+// Custom tokens should be saved too unless they're deleted (marking them as inactive doesn't count)
-export const setActiveTokens = async (safeAddress: string, tokens: List) => {
+export const saveActiveTokens = async (tokens: Map) => {
try {
- const key = getActiveTokensKey(safeAddress)
- await saveToStorage(key, tokens.toJS())
+ await saveToStorage(ACTIVE_TOKENS_KEY, tokens.toJS())
} catch (err) {
// eslint-disable-next-line
console.log('Error storing tokens in localstorage')
}
}
-export const getActiveTokens = async (safeAddress: string): Promise> => {
- const key = getActiveTokensKey(safeAddress)
- const data = await loadFromStorage(key)
+export const getActiveTokens = async (): Promise