This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from gnosis/feature/WA-230-display-eth-funds
WA-230 Display and update ETH funds
- Loading branch information
Showing
25 changed files
with
385 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// @flow | ||
import fetchBalance from '~/routes/safe/store/actions/fetchBalance' | ||
|
||
export type Actions = { | ||
fetchBalance: typeof fetchBalance, | ||
} | ||
|
||
export default { | ||
fetchBalance, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
// @flow | ||
import { createStructuredSelector } from 'reselect' | ||
import { safeSelector, type SafeSelectorProps } from '~/routes/safe/store/selectors' | ||
import { balanceSelector, safeSelector, type SafeSelectorProps } from '~/routes/safe/store/selectors' | ||
import { providerNameSelector } from '~/wallets/store/selectors/index' | ||
|
||
export type SelectorProps = { | ||
safe: SafeSelectorProps, | ||
provider: string, | ||
balance: string, | ||
} | ||
|
||
export default createStructuredSelector({ | ||
safe: safeSelector, | ||
provider: providerNameSelector, | ||
balance: balanceSelector, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// @flow | ||
import { createAction } from 'redux-actions' | ||
|
||
export const ADD_BALANCE = 'ADD_BALANCE' | ||
|
||
type BalanceProps = { | ||
safeAddress: string, | ||
funds: string, | ||
} | ||
|
||
const addBalance = createAction( | ||
ADD_BALANCE, | ||
(safeAddress: string, funds: string): BalanceProps => ({ | ||
safeAddress, | ||
funds, | ||
}), | ||
) | ||
|
||
export default addBalance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// @flow | ||
import type { Dispatch as ReduxDispatch } from 'redux' | ||
import { getBalanceInEtherOf } from '~/wallets/getWeb3' | ||
import { type GlobalState } from '~/store/index' | ||
import addBalance from './addBalance' | ||
|
||
export default (safeAddress: string) => async (dispatch: ReduxDispatch<GlobalState>) => { | ||
const balance = await getBalanceInEtherOf(safeAddress) | ||
|
||
return dispatch(addBalance(safeAddress, balance)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// @flow | ||
import { Map } from 'immutable' | ||
import { handleActions, type ActionType } from 'redux-actions' | ||
import addBalance, { ADD_BALANCE } from '~/routes/safe/store/actions/addBalance' | ||
|
||
export const BALANCE_REDUCER_ID = 'balances' | ||
|
||
export type State = Map<string, string> | ||
|
||
export default handleActions({ | ||
[ADD_BALANCE]: (state: State, action: ActionType<typeof addBalance>): State => | ||
state.set(action.payload.safeAddress, action.payload.funds), | ||
}, Map()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// @flow | ||
import { BALANCE_REDUCER_ID } from '~/routes/safe/store/reducer/balances' | ||
import fetchBalance from '~/routes/safe/store/actions/fetchBalance' | ||
import { aNewStore } from '~/store' | ||
import { getWeb3 } from '~/wallets/getWeb3' | ||
import { promisify } from '~/utils/promisify' | ||
import { aDeployedSafe } from './builder/deployedSafe.builder' | ||
|
||
const addEtherTo = async (address: string, eth: string) => { | ||
const web3 = getWeb3() | ||
const accounts = await promisify(cb => web3.eth.getAccounts(cb)) | ||
const txData = { from: accounts[0], to: address, value: web3.toWei(eth, 'ether') } | ||
return promisify(cb => web3.eth.sendTransaction(txData, cb)) | ||
} | ||
|
||
const balanceReducerTests = () => { | ||
describe('Safe Actions[fetchBalance]', () => { | ||
let store | ||
beforeEach(async () => { | ||
store = aNewStore() | ||
}) | ||
|
||
it('reducer should return 0 to just deployed safe', async () => { | ||
// GIVEN | ||
const safeTx = await aDeployedSafe(store) | ||
const address = safeTx.contractAddress | ||
|
||
// WHEN | ||
await store.dispatch(fetchBalance(address)) | ||
|
||
// THEN | ||
const balances = store.getState()[BALANCE_REDUCER_ID] | ||
expect(balances).not.toBe(undefined) | ||
expect(balances.get(address)).toBe('0') | ||
}) | ||
|
||
it('reducer should return 1.3456 ETH as funds to safe with 1 ETH', async () => { | ||
// GIVEN | ||
const safeTx = await aDeployedSafe(store) | ||
const address = safeTx.contractAddress | ||
|
||
// WHEN | ||
await addEtherTo(address, '1.3456') | ||
await store.dispatch(fetchBalance(address)) | ||
|
||
// THEN | ||
const balances = store.getState()[BALANCE_REDUCER_ID] | ||
expect(balances).not.toBe(undefined) | ||
expect(balances.get(address)).toBe('1.3456') | ||
}) | ||
}) | ||
} | ||
|
||
export default balanceReducerTests |
Oops, something went wrong.