aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/redux
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-01-30 20:26:46 +0800
committerFabio Berger <me@fabioberger.com>2018-01-30 20:26:46 +0800
commitc6dece6bd1e5f5afa56b290557eb7a6245c76cb6 (patch)
treead7a33ffe5d80c0eb41ae10fbc8314f193e52383 /packages/website/ts/redux
parent93a5b3f457c1211676296840c285759007a55500 (diff)
downloaddexon-sol-tools-c6dece6bd1e5f5afa56b290557eb7a6245c76cb6.tar
dexon-sol-tools-c6dece6bd1e5f5afa56b290557eb7a6245c76cb6.tar.gz
dexon-sol-tools-c6dece6bd1e5f5afa56b290557eb7a6245c76cb6.tar.bz2
dexon-sol-tools-c6dece6bd1e5f5afa56b290557eb7a6245c76cb6.tar.lz
dexon-sol-tools-c6dece6bd1e5f5afa56b290557eb7a6245c76cb6.tar.xz
dexon-sol-tools-c6dece6bd1e5f5afa56b290557eb7a6245c76cb6.tar.zst
dexon-sol-tools-c6dece6bd1e5f5afa56b290557eb7a6245c76cb6.zip
Add config file specifically in prettier command and fix files
Diffstat (limited to 'packages/website/ts/redux')
-rw-r--r--packages/website/ts/redux/dispatcher.ts452
-rw-r--r--packages/website/ts/redux/reducer.ts738
2 files changed, 595 insertions, 595 deletions
diff --git a/packages/website/ts/redux/dispatcher.ts b/packages/website/ts/redux/dispatcher.ts
index 19300e242..42989e5e1 100644
--- a/packages/website/ts/redux/dispatcher.ts
+++ b/packages/website/ts/redux/dispatcher.ts
@@ -2,235 +2,235 @@ import { BigNumber } from '@0xproject/utils';
import { Dispatch } from 'redux';
import { State } from 'ts/redux/reducer';
import {
- ActionTypes,
- AssetToken,
- BlockchainErrs,
- Order,
- ProviderType,
- ScreenWidths,
- Side,
- SignatureData,
- Token,
- TokenStateByAddress,
+ ActionTypes,
+ AssetToken,
+ BlockchainErrs,
+ Order,
+ ProviderType,
+ ScreenWidths,
+ Side,
+ SignatureData,
+ Token,
+ TokenStateByAddress,
} from 'ts/types';
export class Dispatcher {
- private _dispatch: Dispatch<State>;
- constructor(dispatch: Dispatch<State>) {
- this._dispatch = dispatch;
- }
- // Portal
- public resetState() {
- this._dispatch({
- type: ActionTypes.ResetState,
- });
- }
- public updateNodeVersion(nodeVersion: string) {
- this._dispatch({
- data: nodeVersion,
- type: ActionTypes.UpdateNodeVersion,
- });
- }
- public updateScreenWidth(screenWidth: ScreenWidths) {
- this._dispatch({
- data: screenWidth,
- type: ActionTypes.UpdateScreenWidth,
- });
- }
- public swapAssetTokenSymbols() {
- this._dispatch({
- type: ActionTypes.SwapAssetTokens,
- });
- }
- public updateOrderSalt(salt: BigNumber) {
- this._dispatch({
- data: salt,
- type: ActionTypes.UpdateOrderSalt,
- });
- }
- public updateUserSuppliedOrderCache(order: Order) {
- this._dispatch({
- data: order,
- type: ActionTypes.UpdateUserSuppliedOrderCache,
- });
- }
- public updateShouldBlockchainErrDialogBeOpen(shouldBeOpen: boolean) {
- this._dispatch({
- data: shouldBeOpen,
- type: ActionTypes.UpdateShouldBlockchainErrDialogBeOpen,
- });
- }
- public updateChosenAssetToken(side: Side, token: AssetToken) {
- this._dispatch({
- data: {
- side,
- token,
- },
- type: ActionTypes.UpdateChosenAssetToken,
- });
- }
- public updateChosenAssetTokenAddress(side: Side, address: string) {
- this._dispatch({
- data: {
- address,
- side,
- },
- type: ActionTypes.UpdateChosenAssetTokenAddress,
- });
- }
- public updateOrderTakerAddress(address: string) {
- this._dispatch({
- data: address,
- type: ActionTypes.UpdateOrderTakerAddress,
- });
- }
- public updateUserAddress(address: string) {
- this._dispatch({
- data: address,
- type: ActionTypes.UpdateUserAddress,
- });
- }
- public updateOrderExpiry(unixTimestampSec: BigNumber) {
- this._dispatch({
- data: unixTimestampSec,
- type: ActionTypes.UpdateOrderExpiry,
- });
- }
- public encounteredBlockchainError(err: BlockchainErrs) {
- this._dispatch({
- data: err,
- type: ActionTypes.BlockchainErrEncountered,
- });
- }
- public updateBlockchainIsLoaded(isLoaded: boolean) {
- this._dispatch({
- data: isLoaded,
- type: ActionTypes.UpdateBlockchainIsLoaded,
- });
- }
- public addTokenToTokenByAddress(token: Token) {
- this._dispatch({
- data: token,
- type: ActionTypes.AddTokenToTokenByAddress,
- });
- }
- public removeTokenToTokenByAddress(token: Token) {
- this._dispatch({
- data: token,
- type: ActionTypes.RemoveTokenFromTokenByAddress,
- });
- }
- public clearTokenByAddress() {
- this._dispatch({
- type: ActionTypes.ClearTokenByAddress,
- });
- }
- public updateTokenByAddress(tokens: Token[]) {
- this._dispatch({
- data: tokens,
- type: ActionTypes.UpdateTokenByAddress,
- });
- }
- public updateTokenStateByAddress(tokenStateByAddress: TokenStateByAddress) {
- this._dispatch({
- data: tokenStateByAddress,
- type: ActionTypes.UpdateTokenStateByAddress,
- });
- }
- public removeFromTokenStateByAddress(tokenAddress: string) {
- this._dispatch({
- data: tokenAddress,
- type: ActionTypes.RemoveFromTokenStateByAddress,
- });
- }
- public replaceTokenAllowanceByAddress(address: string, allowance: BigNumber) {
- this._dispatch({
- data: {
- address,
- allowance,
- },
- type: ActionTypes.ReplaceTokenAllowanceByAddress,
- });
- }
- public replaceTokenBalanceByAddress(address: string, balance: BigNumber) {
- this._dispatch({
- data: {
- address,
- balance,
- },
- type: ActionTypes.ReplaceTokenBalanceByAddress,
- });
- }
- public updateTokenBalanceByAddress(address: string, balanceDelta: BigNumber) {
- this._dispatch({
- data: {
- address,
- balanceDelta,
- },
- type: ActionTypes.UpdateTokenBalanceByAddress,
- });
- }
- public updateSignatureData(signatureData: SignatureData) {
- this._dispatch({
- data: signatureData,
- type: ActionTypes.UpdateOrderSignatureData,
- });
- }
- public updateUserEtherBalance(balance: BigNumber) {
- this._dispatch({
- data: balance,
- type: ActionTypes.UpdateUserEtherBalance,
- });
- }
- public updateNetworkId(networkId: number) {
- this._dispatch({
- data: networkId,
- type: ActionTypes.UpdateNetworkId,
- });
- }
- public updateOrderFillAmount(amount: BigNumber) {
- this._dispatch({
- data: amount,
- type: ActionTypes.UpdateOrderFillAmount,
- });
- }
+ private _dispatch: Dispatch<State>;
+ constructor(dispatch: Dispatch<State>) {
+ this._dispatch = dispatch;
+ }
+ // Portal
+ public resetState() {
+ this._dispatch({
+ type: ActionTypes.ResetState,
+ });
+ }
+ public updateNodeVersion(nodeVersion: string) {
+ this._dispatch({
+ data: nodeVersion,
+ type: ActionTypes.UpdateNodeVersion,
+ });
+ }
+ public updateScreenWidth(screenWidth: ScreenWidths) {
+ this._dispatch({
+ data: screenWidth,
+ type: ActionTypes.UpdateScreenWidth,
+ });
+ }
+ public swapAssetTokenSymbols() {
+ this._dispatch({
+ type: ActionTypes.SwapAssetTokens,
+ });
+ }
+ public updateOrderSalt(salt: BigNumber) {
+ this._dispatch({
+ data: salt,
+ type: ActionTypes.UpdateOrderSalt,
+ });
+ }
+ public updateUserSuppliedOrderCache(order: Order) {
+ this._dispatch({
+ data: order,
+ type: ActionTypes.UpdateUserSuppliedOrderCache,
+ });
+ }
+ public updateShouldBlockchainErrDialogBeOpen(shouldBeOpen: boolean) {
+ this._dispatch({
+ data: shouldBeOpen,
+ type: ActionTypes.UpdateShouldBlockchainErrDialogBeOpen,
+ });
+ }
+ public updateChosenAssetToken(side: Side, token: AssetToken) {
+ this._dispatch({
+ data: {
+ side,
+ token,
+ },
+ type: ActionTypes.UpdateChosenAssetToken,
+ });
+ }
+ public updateChosenAssetTokenAddress(side: Side, address: string) {
+ this._dispatch({
+ data: {
+ address,
+ side,
+ },
+ type: ActionTypes.UpdateChosenAssetTokenAddress,
+ });
+ }
+ public updateOrderTakerAddress(address: string) {
+ this._dispatch({
+ data: address,
+ type: ActionTypes.UpdateOrderTakerAddress,
+ });
+ }
+ public updateUserAddress(address: string) {
+ this._dispatch({
+ data: address,
+ type: ActionTypes.UpdateUserAddress,
+ });
+ }
+ public updateOrderExpiry(unixTimestampSec: BigNumber) {
+ this._dispatch({
+ data: unixTimestampSec,
+ type: ActionTypes.UpdateOrderExpiry,
+ });
+ }
+ public encounteredBlockchainError(err: BlockchainErrs) {
+ this._dispatch({
+ data: err,
+ type: ActionTypes.BlockchainErrEncountered,
+ });
+ }
+ public updateBlockchainIsLoaded(isLoaded: boolean) {
+ this._dispatch({
+ data: isLoaded,
+ type: ActionTypes.UpdateBlockchainIsLoaded,
+ });
+ }
+ public addTokenToTokenByAddress(token: Token) {
+ this._dispatch({
+ data: token,
+ type: ActionTypes.AddTokenToTokenByAddress,
+ });
+ }
+ public removeTokenToTokenByAddress(token: Token) {
+ this._dispatch({
+ data: token,
+ type: ActionTypes.RemoveTokenFromTokenByAddress,
+ });
+ }
+ public clearTokenByAddress() {
+ this._dispatch({
+ type: ActionTypes.ClearTokenByAddress,
+ });
+ }
+ public updateTokenByAddress(tokens: Token[]) {
+ this._dispatch({
+ data: tokens,
+ type: ActionTypes.UpdateTokenByAddress,
+ });
+ }
+ public updateTokenStateByAddress(tokenStateByAddress: TokenStateByAddress) {
+ this._dispatch({
+ data: tokenStateByAddress,
+ type: ActionTypes.UpdateTokenStateByAddress,
+ });
+ }
+ public removeFromTokenStateByAddress(tokenAddress: string) {
+ this._dispatch({
+ data: tokenAddress,
+ type: ActionTypes.RemoveFromTokenStateByAddress,
+ });
+ }
+ public replaceTokenAllowanceByAddress(address: string, allowance: BigNumber) {
+ this._dispatch({
+ data: {
+ address,
+ allowance,
+ },
+ type: ActionTypes.ReplaceTokenAllowanceByAddress,
+ });
+ }
+ public replaceTokenBalanceByAddress(address: string, balance: BigNumber) {
+ this._dispatch({
+ data: {
+ address,
+ balance,
+ },
+ type: ActionTypes.ReplaceTokenBalanceByAddress,
+ });
+ }
+ public updateTokenBalanceByAddress(address: string, balanceDelta: BigNumber) {
+ this._dispatch({
+ data: {
+ address,
+ balanceDelta,
+ },
+ type: ActionTypes.UpdateTokenBalanceByAddress,
+ });
+ }
+ public updateSignatureData(signatureData: SignatureData) {
+ this._dispatch({
+ data: signatureData,
+ type: ActionTypes.UpdateOrderSignatureData,
+ });
+ }
+ public updateUserEtherBalance(balance: BigNumber) {
+ this._dispatch({
+ data: balance,
+ type: ActionTypes.UpdateUserEtherBalance,
+ });
+ }
+ public updateNetworkId(networkId: number) {
+ this._dispatch({
+ data: networkId,
+ type: ActionTypes.UpdateNetworkId,
+ });
+ }
+ public updateOrderFillAmount(amount: BigNumber) {
+ this._dispatch({
+ data: amount,
+ type: ActionTypes.UpdateOrderFillAmount,
+ });
+ }
- // Docs
- public updateCurrentDocsVersion(version: string) {
- this._dispatch({
- data: version,
- type: ActionTypes.UpdateLibraryVersion,
- });
- }
- public updateAvailableDocVersions(versions: string[]) {
- this._dispatch({
- data: versions,
- type: ActionTypes.UpdateAvailableLibraryVersions,
- });
- }
+ // Docs
+ public updateCurrentDocsVersion(version: string) {
+ this._dispatch({
+ data: version,
+ type: ActionTypes.UpdateLibraryVersion,
+ });
+ }
+ public updateAvailableDocVersions(versions: string[]) {
+ this._dispatch({
+ data: versions,
+ type: ActionTypes.UpdateAvailableLibraryVersions,
+ });
+ }
- // Shared
- public showFlashMessage(msg: string | React.ReactNode) {
- this._dispatch({
- data: msg,
- type: ActionTypes.ShowFlashMessage,
- });
- }
- public hideFlashMessage() {
- this._dispatch({
- type: ActionTypes.HideFlashMessage,
- });
- }
- public updateProviderType(providerType: ProviderType) {
- this._dispatch({
- type: ActionTypes.UpdateProviderType,
- data: providerType,
- });
- }
- public updateInjectedProviderName(injectedProviderName: string) {
- this._dispatch({
- type: ActionTypes.UpdateInjectedProviderName,
- data: injectedProviderName,
- });
- }
+ // Shared
+ public showFlashMessage(msg: string | React.ReactNode) {
+ this._dispatch({
+ data: msg,
+ type: ActionTypes.ShowFlashMessage,
+ });
+ }
+ public hideFlashMessage() {
+ this._dispatch({
+ type: ActionTypes.HideFlashMessage,
+ });
+ }
+ public updateProviderType(providerType: ProviderType) {
+ this._dispatch({
+ type: ActionTypes.UpdateProviderType,
+ data: providerType,
+ });
+ }
+ public updateInjectedProviderName(injectedProviderName: string) {
+ this._dispatch({
+ type: ActionTypes.UpdateInjectedProviderName,
+ data: injectedProviderName,
+ });
+ }
}
diff --git a/packages/website/ts/redux/reducer.ts b/packages/website/ts/redux/reducer.ts
index cc467eadd..06ac8b670 100644
--- a/packages/website/ts/redux/reducer.ts
+++ b/packages/website/ts/redux/reducer.ts
@@ -2,18 +2,18 @@ import { ZeroEx } from '0x.js';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import {
- Action,
- ActionTypes,
- BlockchainErrs,
- Order,
- ProviderType,
- ScreenWidths,
- Side,
- SideToAssetToken,
- SignatureData,
- TokenByAddress,
- TokenState,
- TokenStateByAddress,
+ Action,
+ ActionTypes,
+ BlockchainErrs,
+ Order,
+ ProviderType,
+ ScreenWidths,
+ Side,
+ SideToAssetToken,
+ SignatureData,
+ TokenByAddress,
+ TokenState,
+ TokenStateByAddress,
} from 'ts/types';
import { utils } from 'ts/utils/utils';
@@ -23,367 +23,367 @@ import { utils } from 'ts/utils/utils';
const DEFAULT_DOCS_VERSION = '0.0.0';
export interface State {
- // Portal
- blockchainErr: BlockchainErrs;
- blockchainIsLoaded: boolean;
- networkId: number;
- orderExpiryTimestamp: BigNumber;
- orderFillAmount: BigNumber;
- orderTakerAddress: string;
- orderSignatureData: SignatureData;
- orderSalt: BigNumber;
- nodeVersion: string;
- screenWidth: ScreenWidths;
- shouldBlockchainErrDialogBeOpen: boolean;
- sideToAssetToken: SideToAssetToken;
- tokenByAddress: TokenByAddress;
- tokenStateByAddress: TokenStateByAddress;
- userAddress: string;
- userEtherBalance: BigNumber;
- // Note: cache of supplied orderJSON in fill order step. Do not use for anything else.
- userSuppliedOrderCache: Order;
-
- // Docs
- docsVersion: string;
- availableDocVersions: string[];
-
- // Shared
- flashMessage: string | React.ReactNode;
- providerType: ProviderType;
- injectedProviderName: string;
+ // Portal
+ blockchainErr: BlockchainErrs;
+ blockchainIsLoaded: boolean;
+ networkId: number;
+ orderExpiryTimestamp: BigNumber;
+ orderFillAmount: BigNumber;
+ orderTakerAddress: string;
+ orderSignatureData: SignatureData;
+ orderSalt: BigNumber;
+ nodeVersion: string;
+ screenWidth: ScreenWidths;
+ shouldBlockchainErrDialogBeOpen: boolean;
+ sideToAssetToken: SideToAssetToken;
+ tokenByAddress: TokenByAddress;
+ tokenStateByAddress: TokenStateByAddress;
+ userAddress: string;
+ userEtherBalance: BigNumber;
+ // Note: cache of supplied orderJSON in fill order step. Do not use for anything else.
+ userSuppliedOrderCache: Order;
+
+ // Docs
+ docsVersion: string;
+ availableDocVersions: string[];
+
+ // Shared
+ flashMessage: string | React.ReactNode;
+ providerType: ProviderType;
+ injectedProviderName: string;
}
const INITIAL_STATE: State = {
- // Portal
- blockchainErr: BlockchainErrs.NoError,
- blockchainIsLoaded: false,
- networkId: undefined,
- orderExpiryTimestamp: utils.initialOrderExpiryUnixTimestampSec(),
- orderFillAmount: undefined,
- orderSignatureData: {
- hash: '',
- r: '',
- s: '',
- v: 27,
- },
- orderTakerAddress: '',
- orderSalt: ZeroEx.generatePseudoRandomSalt(),
- nodeVersion: undefined,
- screenWidth: utils.getScreenWidth(),
- shouldBlockchainErrDialogBeOpen: false,
- sideToAssetToken: {
- [Side.Deposit]: {},
- [Side.Receive]: {},
- },
- tokenByAddress: {},
- tokenStateByAddress: {},
- userAddress: '',
- userEtherBalance: new BigNumber(0),
- userSuppliedOrderCache: undefined,
-
- // Docs
- docsVersion: DEFAULT_DOCS_VERSION,
- availableDocVersions: [DEFAULT_DOCS_VERSION],
-
- // Shared
- flashMessage: undefined,
- providerType: ProviderType.Injected,
- injectedProviderName: '',
+ // Portal
+ blockchainErr: BlockchainErrs.NoError,
+ blockchainIsLoaded: false,
+ networkId: undefined,
+ orderExpiryTimestamp: utils.initialOrderExpiryUnixTimestampSec(),
+ orderFillAmount: undefined,
+ orderSignatureData: {
+ hash: '',
+ r: '',
+ s: '',
+ v: 27,
+ },
+ orderTakerAddress: '',
+ orderSalt: ZeroEx.generatePseudoRandomSalt(),
+ nodeVersion: undefined,
+ screenWidth: utils.getScreenWidth(),
+ shouldBlockchainErrDialogBeOpen: false,
+ sideToAssetToken: {
+ [Side.Deposit]: {},
+ [Side.Receive]: {},
+ },
+ tokenByAddress: {},
+ tokenStateByAddress: {},
+ userAddress: '',
+ userEtherBalance: new BigNumber(0),
+ userSuppliedOrderCache: undefined,
+
+ // Docs
+ docsVersion: DEFAULT_DOCS_VERSION,
+ availableDocVersions: [DEFAULT_DOCS_VERSION],
+
+ // Shared
+ flashMessage: undefined,
+ providerType: ProviderType.Injected,
+ injectedProviderName: '',
};
export function reducer(state: State = INITIAL_STATE, action: Action) {
- switch (action.type) {
- // Portal
- case ActionTypes.ResetState:
- return INITIAL_STATE;
-
- case ActionTypes.UpdateOrderSalt: {
- return {
- ...state,
- orderSalt: action.data,
- };
- }
-
- case ActionTypes.UpdateNodeVersion: {
- return {
- ...state,
- nodeVersion: action.data,
- };
- }
-
- case ActionTypes.UpdateOrderFillAmount: {
- return {
- ...state,
- orderFillAmount: action.data,
- };
- }
-
- case ActionTypes.UpdateShouldBlockchainErrDialogBeOpen: {
- return {
- ...state,
- shouldBlockchainErrDialogBeOpen: action.data,
- };
- }
-
- case ActionTypes.UpdateUserEtherBalance: {
- return {
- ...state,
- userEtherBalance: action.data,
- };
- }
-
- case ActionTypes.UpdateUserSuppliedOrderCache: {
- return {
- ...state,
- userSuppliedOrderCache: action.data,
- };
- }
-
- case ActionTypes.ClearTokenByAddress: {
- return {
- ...state,
- tokenByAddress: {},
- };
- }
-
- case ActionTypes.AddTokenToTokenByAddress: {
- const newTokenByAddress = state.tokenByAddress;
- newTokenByAddress[action.data.address] = action.data;
- return {
- ...state,
- tokenByAddress: newTokenByAddress,
- };
- }
-
- case ActionTypes.RemoveTokenFromTokenByAddress: {
- const newTokenByAddress = state.tokenByAddress;
- delete newTokenByAddress[action.data.address];
- return {
- ...state,
- tokenByAddress: newTokenByAddress,
- };
- }
-
- case ActionTypes.UpdateTokenByAddress: {
- const tokenByAddress = state.tokenByAddress;
- const tokens = action.data;
- _.each(tokens, token => {
- const updatedToken = {
- ...tokenByAddress[token.address],
- ...token,
- };
- tokenByAddress[token.address] = updatedToken;
- });
- return {
- ...state,
- tokenByAddress,
- };
- }
-
- case ActionTypes.UpdateTokenStateByAddress: {
- const tokenStateByAddress = state.tokenStateByAddress;
- const updatedTokenStateByAddress = action.data;
- _.each(updatedTokenStateByAddress, (tokenState: TokenState, address: string) => {
- const updatedTokenState = {
- ...tokenStateByAddress[address],
- ...tokenState,
- };
- tokenStateByAddress[address] = updatedTokenState;
- });
- return {
- ...state,
- tokenStateByAddress,
- };
- }
-
- case ActionTypes.RemoveFromTokenStateByAddress: {
- const tokenStateByAddress = state.tokenStateByAddress;
- const tokenAddress = action.data;
- delete tokenStateByAddress[tokenAddress];
- return {
- ...state,
- tokenStateByAddress,
- };
- }
-
- case ActionTypes.ReplaceTokenAllowanceByAddress: {
- const tokenStateByAddress = state.tokenStateByAddress;
- const allowance = action.data.allowance;
- const tokenAddress = action.data.address;
- tokenStateByAddress[tokenAddress] = {
- ...tokenStateByAddress[tokenAddress],
- allowance,
- };
- return {
- ...state,
- tokenStateByAddress,
- };
- }
-
- case ActionTypes.ReplaceTokenBalanceByAddress: {
- const tokenStateByAddress = state.tokenStateByAddress;
- const balance = action.data.balance;
- const tokenAddress = action.data.address;
- tokenStateByAddress[tokenAddress] = {
- ...tokenStateByAddress[tokenAddress],
- balance,
- };
- return {
- ...state,
- tokenStateByAddress,
- };
- }
-
- case ActionTypes.UpdateTokenBalanceByAddress: {
- const tokenStateByAddress = state.tokenStateByAddress;
- const balanceDelta = action.data.balanceDelta;
- const tokenAddress = action.data.address;
- const currBalance = tokenStateByAddress[tokenAddress].balance;
- tokenStateByAddress[tokenAddress] = {
- ...tokenStateByAddress[tokenAddress],
- balance: currBalance.plus(balanceDelta),
- };
- return {
- ...state,
- tokenStateByAddress,
- };
- }
-
- case ActionTypes.UpdateOrderSignatureData: {
- return {
- ...state,
- orderSignatureData: action.data,
- };
- }
-
- case ActionTypes.UpdateScreenWidth: {
- return {
- ...state,
- screenWidth: action.data,
- };
- }
-
- case ActionTypes.UpdateBlockchainIsLoaded: {
- return {
- ...state,
- blockchainIsLoaded: action.data,
- };
- }
-
- case ActionTypes.BlockchainErrEncountered: {
- return {
- ...state,
- blockchainErr: action.data,
- };
- }
-
- case ActionTypes.UpdateNetworkId: {
- return {
- ...state,
- networkId: action.data,
- };
- }
-
- case ActionTypes.UpdateChosenAssetToken: {
- const newSideToAssetToken = {
- ...state.sideToAssetToken,
- [action.data.side]: action.data.token,
- };
- return {
- ...state,
- sideToAssetToken: newSideToAssetToken,
- };
- }
-
- case ActionTypes.UpdateChosenAssetTokenAddress: {
- const newAssetToken = state.sideToAssetToken[action.data.side];
- newAssetToken.address = action.data.address;
- const newSideToAssetToken = {
- ...state.sideToAssetToken,
- [action.data.side]: newAssetToken,
- };
- return {
- ...state,
- sideToAssetToken: newSideToAssetToken,
- };
- }
-
- case ActionTypes.SwapAssetTokens: {
- const newSideToAssetToken = {
- [Side.Deposit]: state.sideToAssetToken[Side.Receive],
- [Side.Receive]: state.sideToAssetToken[Side.Deposit],
- };
- return {
- ...state,
- sideToAssetToken: newSideToAssetToken,
- };
- }
-
- case ActionTypes.UpdateOrderExpiry: {
- return {
- ...state,
- orderExpiryTimestamp: action.data,
- };
- }
-
- case ActionTypes.UpdateOrderTakerAddress: {
- return {
- ...state,
- orderTakerAddress: action.data,
- };
- }
-
- case ActionTypes.UpdateUserAddress: {
- return {
- ...state,
- userAddress: action.data,
- };
- }
-
- // Docs
- case ActionTypes.UpdateLibraryVersion: {
- return {
- ...state,
- docsVersion: action.data,
- };
- }
- case ActionTypes.UpdateAvailableLibraryVersions: {
- return {
- ...state,
- availableDocVersions: action.data,
- };
- }
-
- // Shared
- case ActionTypes.ShowFlashMessage: {
- return {
- ...state,
- flashMessage: action.data,
- };
- }
-
- case ActionTypes.HideFlashMessage: {
- return {
- ...state,
- flashMessage: undefined,
- };
- }
-
- case ActionTypes.UpdateProviderType: {
- return {
- ...state,
- providerType: action.data,
- };
- }
-
- case ActionTypes.UpdateInjectedProviderName: {
- return {
- ...state,
- injectedProviderName: action.data,
- };
- }
-
- default:
- return state;
- }
+ switch (action.type) {
+ // Portal
+ case ActionTypes.ResetState:
+ return INITIAL_STATE;
+
+ case ActionTypes.UpdateOrderSalt: {
+ return {
+ ...state,
+ orderSalt: action.data,
+ };
+ }
+
+ case ActionTypes.UpdateNodeVersion: {
+ return {
+ ...state,
+ nodeVersion: action.data,
+ };
+ }
+
+ case ActionTypes.UpdateOrderFillAmount: {
+ return {
+ ...state,
+ orderFillAmount: action.data,
+ };
+ }
+
+ case ActionTypes.UpdateShouldBlockchainErrDialogBeOpen: {
+ return {
+ ...state,
+ shouldBlockchainErrDialogBeOpen: action.data,
+ };
+ }
+
+ case ActionTypes.UpdateUserEtherBalance: {
+ return {
+ ...state,
+ userEtherBalance: action.data,
+ };
+ }
+
+ case ActionTypes.UpdateUserSuppliedOrderCache: {
+ return {
+ ...state,
+ userSuppliedOrderCache: action.data,
+ };
+ }
+
+ case ActionTypes.ClearTokenByAddress: {
+ return {
+ ...state,
+ tokenByAddress: {},
+ };
+ }
+
+ case ActionTypes.AddTokenToTokenByAddress: {
+ const newTokenByAddress = state.tokenByAddress;
+ newTokenByAddress[action.data.address] = action.data;
+ return {
+ ...state,
+ tokenByAddress: newTokenByAddress,
+ };
+ }
+
+ case ActionTypes.RemoveTokenFromTokenByAddress: {
+ const newTokenByAddress = state.tokenByAddress;
+ delete newTokenByAddress[action.data.address];
+ return {
+ ...state,
+ tokenByAddress: newTokenByAddress,
+ };
+ }
+
+ case ActionTypes.UpdateTokenByAddress: {
+ const tokenByAddress = state.tokenByAddress;
+ const tokens = action.data;
+ _.each(tokens, token => {
+ const updatedToken = {
+ ...tokenByAddress[token.address],
+ ...token,
+ };
+ tokenByAddress[token.address] = updatedToken;
+ });
+ return {
+ ...state,
+ tokenByAddress,
+ };
+ }
+
+ case ActionTypes.UpdateTokenStateByAddress: {
+ const tokenStateByAddress = state.tokenStateByAddress;
+ const updatedTokenStateByAddress = action.data;
+ _.each(updatedTokenStateByAddress, (tokenState: TokenState, address: string) => {
+ const updatedTokenState = {
+ ...tokenStateByAddress[address],
+ ...tokenState,
+ };
+ tokenStateByAddress[address] = updatedTokenState;
+ });
+ return {
+ ...state,
+ tokenStateByAddress,
+ };
+ }
+
+ case ActionTypes.RemoveFromTokenStateByAddress: {
+ const tokenStateByAddress = state.tokenStateByAddress;
+ const tokenAddress = action.data;
+ delete tokenStateByAddress[tokenAddress];
+ return {
+ ...state,
+ tokenStateByAddress,
+ };
+ }
+
+ case ActionTypes.ReplaceTokenAllowanceByAddress: {
+ const tokenStateByAddress = state.tokenStateByAddress;
+ const allowance = action.data.allowance;
+ const tokenAddress = action.data.address;
+ tokenStateByAddress[tokenAddress] = {
+ ...tokenStateByAddress[tokenAddress],
+ allowance,
+ };
+ return {
+ ...state,
+ tokenStateByAddress,
+ };
+ }
+
+ case ActionTypes.ReplaceTokenBalanceByAddress: {
+ const tokenStateByAddress = state.tokenStateByAddress;
+ const balance = action.data.balance;
+ const tokenAddress = action.data.address;
+ tokenStateByAddress[tokenAddress] = {
+ ...tokenStateByAddress[tokenAddress],
+ balance,
+ };
+ return {
+ ...state,
+ tokenStateByAddress,
+ };
+ }
+
+ case ActionTypes.UpdateTokenBalanceByAddress: {
+ const tokenStateByAddress = state.tokenStateByAddress;
+ const balanceDelta = action.data.balanceDelta;
+ const tokenAddress = action.data.address;
+ const currBalance = tokenStateByAddress[tokenAddress].balance;
+ tokenStateByAddress[tokenAddress] = {
+ ...tokenStateByAddress[tokenAddress],
+ balance: currBalance.plus(balanceDelta),
+ };
+ return {
+ ...state,
+ tokenStateByAddress,
+ };
+ }
+
+ case ActionTypes.UpdateOrderSignatureData: {
+ return {
+ ...state,
+ orderSignatureData: action.data,
+ };
+ }
+
+ case ActionTypes.UpdateScreenWidth: {
+ return {
+ ...state,
+ screenWidth: action.data,
+ };
+ }
+
+ case ActionTypes.UpdateBlockchainIsLoaded: {
+ return {
+ ...state,
+ blockchainIsLoaded: action.data,
+ };
+ }
+
+ case ActionTypes.BlockchainErrEncountered: {
+ return {
+ ...state,
+ blockchainErr: action.data,
+ };
+ }
+
+ case ActionTypes.UpdateNetworkId: {
+ return {
+ ...state,
+ networkId: action.data,
+ };
+ }
+
+ case ActionTypes.UpdateChosenAssetToken: {
+ const newSideToAssetToken = {
+ ...state.sideToAssetToken,
+ [action.data.side]: action.data.token,
+ };
+ return {
+ ...state,
+ sideToAssetToken: newSideToAssetToken,
+ };
+ }
+
+ case ActionTypes.UpdateChosenAssetTokenAddress: {
+ const newAssetToken = state.sideToAssetToken[action.data.side];
+ newAssetToken.address = action.data.address;
+ const newSideToAssetToken = {
+ ...state.sideToAssetToken,
+ [action.data.side]: newAssetToken,
+ };
+ return {
+ ...state,
+ sideToAssetToken: newSideToAssetToken,
+ };
+ }
+
+ case ActionTypes.SwapAssetTokens: {
+ const newSideToAssetToken = {
+ [Side.Deposit]: state.sideToAssetToken[Side.Receive],
+ [Side.Receive]: state.sideToAssetToken[Side.Deposit],
+ };
+ return {
+ ...state,
+ sideToAssetToken: newSideToAssetToken,
+ };
+ }
+
+ case ActionTypes.UpdateOrderExpiry: {
+ return {
+ ...state,
+ orderExpiryTimestamp: action.data,
+ };
+ }
+
+ case ActionTypes.UpdateOrderTakerAddress: {
+ return {
+ ...state,
+ orderTakerAddress: action.data,
+ };
+ }
+
+ case ActionTypes.UpdateUserAddress: {
+ return {
+ ...state,
+ userAddress: action.data,
+ };
+ }
+
+ // Docs
+ case ActionTypes.UpdateLibraryVersion: {
+ return {
+ ...state,
+ docsVersion: action.data,
+ };
+ }
+ case ActionTypes.UpdateAvailableLibraryVersions: {
+ return {
+ ...state,
+ availableDocVersions: action.data,
+ };
+ }
+
+ // Shared
+ case ActionTypes.ShowFlashMessage: {
+ return {
+ ...state,
+ flashMessage: action.data,
+ };
+ }
+
+ case ActionTypes.HideFlashMessage: {
+ return {
+ ...state,
+ flashMessage: undefined,
+ };
+ }
+
+ case ActionTypes.UpdateProviderType: {
+ return {
+ ...state,
+ providerType: action.data,
+ };
+ }
+
+ case ActionTypes.UpdateInjectedProviderName: {
+ return {
+ ...state,
+ injectedProviderName: action.data,
+ };
+ }
+
+ default:
+ return state;
+ }
}