Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

#99 Refactor redux store #103

Merged
merged 52 commits into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
6e9799b
remove cookie store and session storage
Apr 8, 2019
0f7d68b
eslint fix
Apr 8, 2019
6003d8d
display all safes and not owners only in safe list
Apr 8, 2019
3b27729
load active tokens from localstorage when visiting safe view
Apr 8, 2019
8108b6b
add an action to fetch token balances
Apr 8, 2019
8a8b297
action for fetching active token balances wip
Apr 9, 2019
4f59865
reducer fix, fetching balances and updating balances fixes
Apr 9, 2019
1125536
tokens fetch fixes, disable eth switch in tokens modal
Apr 9, 2019
56c6892
split fetching tokens function
Apr 9, 2019
f598344
fix token fetch
Apr 10, 2019
93cf045
update safe and token models
Apr 10, 2019
a158fe4
add extended token selector
Apr 10, 2019
78883ea
extended token selector fix, dep bump
Apr 11, 2019
fe35b81
refactor tokens reducer
Apr 11, 2019
f94e598
balance fetch fixes
Apr 11, 2019
be295d1
tokens balance refactor wip
Apr 11, 2019
5f142bc
add eth balance to safe model
Apr 11, 2019
3530d2f
remove eth from list of active tokens
Apr 11, 2019
50a315b
show eth balance in balance tab
Apr 12, 2019
f797e2d
use addSafe instead updateSafe while adding a new safe
Apr 12, 2019
a6249de
add SafeToken record
Apr 12, 2019
49f0004
update readme
Apr 12, 2019
f8d1e68
Update safe tokens wip
Apr 12, 2019
413cfa3
reducer fix
Apr 12, 2019
595731d
fix displaying active tokens
Apr 12, 2019
910382c
Active tokens WIP, needs debugging: tokens get washed after safe update
Apr 12, 2019
f486068
rewrite fetchSafe function to support updates
mmv08 Apr 15, 2019
3c5d7fc
fix token balance updating
mmv08 Apr 15, 2019
fc3e1e4
eslint fix
mmv08 Apr 15, 2019
400a19f
fix token balance updating
mmv08 Apr 15, 2019
d7127fb
rewrite active tokens logic to use updateSafe action
mmv08 Apr 15, 2019
81e05c1
remove unused vars, add comment for generateProps func
mmv08 Apr 15, 2019
0b6be00
fix checkbox displaying in manage tokens modal
mmv08 Apr 15, 2019
2c8a79e
remove cdu, otherwise it will fail on many token updates because of i…
Apr 15, 2019
7df11f3
update fix
Apr 15, 2019
b9b936d
activeTokens refactor (again)
mmv08 Apr 16, 2019
d8fbdd3
conflict ifx
mmv08 Apr 16, 2019
76b41a4
merge fixes
mmv08 Apr 16, 2019
4c1197a
fix token balance selector
mmv08 Apr 16, 2019
3373b83
storage middleware wip, add optimization comment
Apr 16, 2019
7e49f8d
fix storing safe in localstorage
Apr 16, 2019
dc185e8
fix safe loading from storage wip
mmv08 Apr 17, 2019
e3d7984
fix safe loading from storage
mmv08 Apr 17, 2019
81fbb3b
add selector for all active tokens
mmv08 Apr 17, 2019
cdaa6c8
fix loading tokens from storage
mmv08 Apr 17, 2019
289f5f6
token redux-related stuff cleanup after refactor
mmv08 Apr 17, 2019
43e8521
eslint fix
mmv08 Apr 17, 2019
c633165
rename setActiveTokens to saveActiveTokens
mmv08 Apr 17, 2019
84af7ae
eslint fixes
mmv08 Apr 17, 2019
8f9eadb
fix updateActiveTokens action call inside Tokens modal
mmv08 Apr 18, 2019
1c95804
fix loading active tokens error
Apr 22, 2019
24b51ba
fix eslint disable statement duplication
Apr 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tokens balance refactor wip
  • Loading branch information
Mikhail Mikheev committed Apr 11, 2019
commit be295d1ef5a841c67f51e2ae2764e8d0fa709353
2 changes: 1 addition & 1 deletion src/routes/safe/container/actions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import fetchSafe from '~/routes/safe/store/actions/fetchSafe'
import loadActiveTokens from '~/logic/tokens/store/actions/loadActiveTokens'
import fetchTokenBalances from '~/logic/tokens/store/actions/fetchTokenBalances'
import fetchTokenBalances from '~/routes/safe/store/actions/fetchTokenBalances'

export type Actions = {
fetchSafe: typeof fetchSafe,
Expand Down
8 changes: 4 additions & 4 deletions src/routes/safe/container/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const TIMEOUT = process.env.NODE_ENV === 'test' ? 1500 : 15000
class SafeView extends React.Component<Props> {
componentDidMount() {
const {
fetchSafe, loadActiveTokens, activeTokens, safeUrl, fetchTokenBalances,
fetchSafe, loadActiveTokens, activeTokens, safeUrl, fetchTokenBalances, safe,
} = this.props

fetchSafe(safeUrl)
loadActiveTokens(safeUrl)
fetchTokenBalances(safeUrl, activeTokens)
fetchTokenBalances(safe, activeTokens)

this.intervalId = setInterval(() => {
// update in another function so it uses up-to-date props values
Expand All @@ -35,11 +35,11 @@ class SafeView extends React.Component<Props> {

checkForUpdates() {
const {
safeUrl, activeTokens, fetchSafe, fetchTokenBalances,
safeUrl, activeTokens, fetchSafe, fetchTokenBalances, safe,
} = this.props

fetchSafe(safeUrl)
fetchTokenBalances(safeUrl, activeTokens)
fetchTokenBalances(safe, activeTokens)
}

intervalId: IntervalID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { type GlobalState } from '~/store/index'
import { type Token } from '~/logic/tokens/store/model/token'
import { ETH_ADDRESS } from '~/logic/tokens/utils/tokenHelpers'
import { getBalanceInEtherOf } from '~/logic/wallets/getWeb3'
import { getStandardTokenContract } from './fetchTokens'
import saveTokens from './saveTokens'
import { getStandardTokenContract } from '~/logic/tokens/store/actions/fetchTokens'
import type { Safe } from '~/routes/safe/store/model/safe'
import updateSafe from './updateSafe'

export const calculateBalanceOf = async (tokenAddress: string, safeAddress: string, decimals: number = 18) => {
if (tokenAddress === ETH_ADDRESS) {
Expand All @@ -28,23 +29,24 @@ export const calculateBalanceOf = async (tokenAddress: string, safeAddress: stri
return new BigNumber(balance).div(10 ** decimals).toString()
}

const fetchTokenBalances = (safeAddress: string, tokens: List<Token>) => async (
const fetchTokenBalances = (safe: Safe, tokens: List<Token>) => async (
dispatch: ReduxDispatch<GlobalState>,
) => {
if (!safeAddress || !tokens || !tokens.size) {
if (!safe || !tokens || !tokens.size) {
return
}

try {
const withBalances = await Promise.all(
tokens.map(async token => token.set('balance', await calculateBalanceOf(token.address, safeAddress, token.decimals))),
tokens.map(async token => ({
address: token.address,
balance: await calculateBalanceOf(token.address, safe.address, token.decimals),
})),
)

const tokensMap = Map().withMutations((map) => {
withBalances.forEach(token => map.set(token.address, token))
})
const safeWithBalances = safe.set('tokens', List(withBalances))

dispatch(saveTokens(safeAddress, tokensMap))
dispatch(updateSafe(safeWithBalances))
} catch (err) {
// eslint-disable-next-line
console.error('Error while loading active tokens from storage:', err)
Expand Down
2 changes: 1 addition & 1 deletion src/routes/safe/store/model/safe.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type SafeProps = {
address: string,
threshold: number,
owners: List<Owner>,
tokens?: List<Map<string, string>>,
tokens?: List<Object>,
}

const SafeRecord: RecordFactory<SafeProps> = Record({
Expand Down
5 changes: 2 additions & 3 deletions src/routes/safe/store/reducer/safe.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export const buildSafe = (storedSafe: SafeProps) => {
address: storedSafe.address,
name: storedSafe.name,
threshold: storedSafe.threshold,
activeTokens: storedSafe.activeTokens,
balances: storedSafe.balances,
tokens: storedSafe.tokens,
owners,
}

Expand Down Expand Up @@ -58,7 +57,7 @@ export default handleActions<State, *>(
{
[UPDATE_SAFE]: (state: State, action: ActionType<Function>): State => {
const safe = action.payload
const safeAddress = safe.get('address')
const safeAddress = safe.address

const hasSafe = !!state.get(safeAddress)
if (hasSafe) {
Expand Down