aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/redux/reducer.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-11-10 06:20:06 +0800
committerFabio Berger <me@fabioberger.com>2018-11-10 06:20:06 +0800
commit773cf3cd143769a93cea66b30d46cb9f4620b74d (patch)
tree549d12546b0076d5e69d1a4570ca7a42b628c5c1 /packages/instant/src/redux/reducer.ts
parent53d0f5b98ebd132d51b1fdf463fe57481c895ec4 (diff)
parentb4a11de097258d37fa9271e64fc28a1d012a8d26 (diff)
downloaddexon-sol-tools-773cf3cd143769a93cea66b30d46cb9f4620b74d.tar
dexon-sol-tools-773cf3cd143769a93cea66b30d46cb9f4620b74d.tar.gz
dexon-sol-tools-773cf3cd143769a93cea66b30d46cb9f4620b74d.tar.bz2
dexon-sol-tools-773cf3cd143769a93cea66b30d46cb9f4620b74d.tar.lz
dexon-sol-tools-773cf3cd143769a93cea66b30d46cb9f4620b74d.tar.xz
dexon-sol-tools-773cf3cd143769a93cea66b30d46cb9f4620b74d.tar.zst
dexon-sol-tools-773cf3cd143769a93cea66b30d46cb9f4620b74d.zip
Merge branch 'development' into fixOrderValidation
* development: (25 commits) Publish Updated CHANGELOGS fix(instant): fix bug where we potentially fetch balance for the wrong account fix: Lock Ledger hw-transport to 4.24.0 fix: wrong prop names used chore: PR feedback fix: broken features because of merge fix: remove default props, fix lint problems chore: convert payment method to stateless component feat: add boxShadow on dropdown hover fix: various style issues fix: remove all:initial rule from all div based ui compoennts fix: token selector scrolling container height chore(instant): fix lint errors feat(instant): fetch balance at startup feat(instant): fetch account address at startup and drive account state changes chore: cleanup fix: restore button to previous state feat: implement copy-to-clipboard feat: add MetaMask sign, refactor Circle ...
Diffstat (limited to 'packages/instant/src/redux/reducer.ts')
-rw-r--r--packages/instant/src/redux/reducer.ts43
1 files changed, 42 insertions, 1 deletions
diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts
index 4a939839a..a5a1b6f7d 100644
--- a/packages/instant/src/redux/reducer.ts
+++ b/packages/instant/src/redux/reducer.ts
@@ -4,8 +4,12 @@ import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as _ from 'lodash';
+import { ERROR_ACCOUNT, LOADING_ACCOUNT, LOCKED_ACCOUNT } from '../constants';
import { assetMetaDataMap } from '../data/asset_meta_data_map';
import {
+ Account,
+ AccountReady,
+ AccountState,
AffiliateInfo,
Asset,
AssetMetaData,
@@ -57,6 +61,32 @@ export const DEFAULT_STATE: DefaultState = {
export const createReducer = (initialState: State) => {
const reducer = (state: State = initialState, action: Action): State => {
switch (action.type) {
+ case ActionTypes.SET_ACCOUNT_STATE_LOADING:
+ return reduceStateWithAccount(state, LOADING_ACCOUNT);
+ case ActionTypes.SET_ACCOUNT_STATE_LOCKED:
+ return reduceStateWithAccount(state, LOCKED_ACCOUNT);
+ case ActionTypes.SET_ACCOUNT_STATE_ERROR:
+ return reduceStateWithAccount(state, ERROR_ACCOUNT);
+ case ActionTypes.SET_ACCOUNT_STATE_READY: {
+ const account: AccountReady = {
+ state: AccountState.Ready,
+ address: action.data,
+ };
+ return reduceStateWithAccount(state, account);
+ }
+ case ActionTypes.UPDATE_ACCOUNT_ETH_BALANCE: {
+ const { address, ethBalanceInWei } = action.data;
+ const currentAccount = state.providerState.account;
+ if (currentAccount.state !== AccountState.Ready || currentAccount.address !== address) {
+ return state;
+ } else {
+ const newAccount: AccountReady = {
+ ...currentAccount,
+ ethBalanceInWei,
+ };
+ return reduceStateWithAccount(state, newAccount);
+ }
+ }
case ActionTypes.UPDATE_ETH_USD_PRICE:
return {
...state,
@@ -80,7 +110,6 @@ export const createReducer = (initialState: State) => {
} else {
return state;
}
-
case ActionTypes.SET_QUOTE_REQUEST_STATE_PENDING:
return {
...state,
@@ -191,6 +220,18 @@ export const createReducer = (initialState: State) => {
return reducer;
};
+const reduceStateWithAccount = (state: State, account: Account) => {
+ const oldProviderState = state.providerState;
+ const newProviderState: ProviderState = {
+ ...oldProviderState,
+ account,
+ };
+ return {
+ ...state,
+ providerState: newProviderState,
+ };
+};
+
const doesBuyQuoteMatchState = (buyQuote: BuyQuote, state: State): boolean => {
const selectedAssetIfExists = state.selectedAsset;
const selectedAssetAmountIfExists = state.selectedAssetAmount;