aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/redux
diff options
context:
space:
mode:
Diffstat (limited to 'packages/website/ts/redux')
-rw-r--r--packages/website/ts/redux/analyticsMiddleware.ts36
-rw-r--r--packages/website/ts/redux/dispatcher.ts227
-rw-r--r--packages/website/ts/redux/reducer.ts361
-rw-r--r--packages/website/ts/redux/store.ts24
4 files changed, 0 insertions, 648 deletions
diff --git a/packages/website/ts/redux/analyticsMiddleware.ts b/packages/website/ts/redux/analyticsMiddleware.ts
deleted file mode 100644
index 51d39a5d7..000000000
--- a/packages/website/ts/redux/analyticsMiddleware.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-import { Middleware } from 'redux';
-import { State } from 'ts/redux/reducer';
-import { ActionTypes } from 'ts/types';
-import { analytics } from 'ts/utils/analytics';
-
-export const analyticsMiddleware: Middleware = store => next => action => {
- const nextAction = next(action);
- const nextState = (store.getState() as any) as State;
- switch (action.type) {
- case ActionTypes.UpdateInjectedProviderName:
- analytics.addEventProperties({
- injectedProviderName: nextState.injectedProviderName,
- });
- break;
- case ActionTypes.UpdateNetworkId:
- analytics.addEventProperties({
- networkId: nextState.networkId,
- });
- break;
- case ActionTypes.UpdateUserAddress:
- analytics.addUserProperties({
- ethAddress: nextState.userAddress,
- });
- break;
- case ActionTypes.UpdateUserEtherBalance:
- if (nextState.userEtherBalanceInWei) {
- analytics.addUserProperties({
- ethBalance: nextState.userEtherBalanceInWei.toString(),
- });
- }
- break;
- default:
- break;
- }
- return nextAction;
-};
diff --git a/packages/website/ts/redux/dispatcher.ts b/packages/website/ts/redux/dispatcher.ts
deleted file mode 100644
index e85afd3b1..000000000
--- a/packages/website/ts/redux/dispatcher.ts
+++ /dev/null
@@ -1,227 +0,0 @@
-import { BigNumber } from '@0x/utils';
-import { Dispatch } from 'redux';
-import { State } from 'ts/redux/reducer';
-import {
- ActionTypes,
- AssetToken,
- BlockchainErrs,
- Language,
- PortalOrder,
- ProviderType,
- ScreenWidths,
- Side,
- SideToAssetToken,
- Token,
- TokenByAddress,
-} from 'ts/types';
-
-export class Dispatcher {
- private readonly _dispatch: Dispatch<State>;
- constructor(dispatch: Dispatch<State>) {
- this._dispatch = dispatch;
- }
- // Portal
- public resetState(): void {
- this._dispatch({
- type: ActionTypes.ResetState,
- });
- }
- public updateNodeVersion(nodeVersion: string): void {
- this._dispatch({
- data: nodeVersion,
- type: ActionTypes.UpdateNodeVersion,
- });
- }
- public updateScreenWidth(screenWidth: ScreenWidths): void {
- this._dispatch({
- data: screenWidth,
- type: ActionTypes.UpdateScreenWidth,
- });
- }
- public swapAssetTokenSymbols(): void {
- this._dispatch({
- type: ActionTypes.SwapAssetTokens,
- });
- }
- public updateOrderSalt(salt: BigNumber): void {
- this._dispatch({
- data: salt,
- type: ActionTypes.UpdateOrderSalt,
- });
- }
- public updateUserSuppliedOrderCache(order: PortalOrder): void {
- this._dispatch({
- data: order,
- type: ActionTypes.UpdateUserSuppliedOrderCache,
- });
- }
- public updateShouldBlockchainErrDialogBeOpen(shouldBeOpen: boolean): void {
- this._dispatch({
- data: shouldBeOpen,
- type: ActionTypes.UpdateShouldBlockchainErrDialogBeOpen,
- });
- }
- public updateChosenAssetToken(side: Side, token: AssetToken): void {
- this._dispatch({
- data: {
- side,
- token,
- },
- type: ActionTypes.UpdateChosenAssetToken,
- });
- }
- public updateChosenAssetTokenAddress(side: Side, address: string): void {
- this._dispatch({
- data: {
- address,
- side,
- },
- type: ActionTypes.UpdateChosenAssetTokenAddress,
- });
- }
- public updateOrderTakerAddress(address: string): void {
- this._dispatch({
- data: address,
- type: ActionTypes.UpdateOrderTakerAddress,
- });
- }
- public updateUserAddress(address?: string): void {
- this._dispatch({
- data: address,
- type: ActionTypes.UpdateUserAddress,
- });
- }
- public updateOrderExpiry(unixTimestampSec: BigNumber): void {
- this._dispatch({
- data: unixTimestampSec,
- type: ActionTypes.UpdateOrderExpiry,
- });
- }
- public encounteredBlockchainError(err: BlockchainErrs): void {
- this._dispatch({
- data: err,
- type: ActionTypes.BlockchainErrEncountered,
- });
- }
- public updateBlockchainIsLoaded(isLoaded: boolean): void {
- this._dispatch({
- data: isLoaded,
- type: ActionTypes.UpdateBlockchainIsLoaded,
- });
- }
- public addTokenToTokenByAddress(token: Token): void {
- this._dispatch({
- data: token,
- type: ActionTypes.AddTokenToTokenByAddress,
- });
- }
- public removeTokenToTokenByAddress(token: Token): void {
- this._dispatch({
- data: token,
- type: ActionTypes.RemoveTokenFromTokenByAddress,
- });
- }
- public batchDispatch(
- tokenByAddress: TokenByAddress,
- networkId: number,
- userAddressIfExists: string | undefined,
- sideToAssetToken: SideToAssetToken,
- ): void {
- this._dispatch({
- data: {
- tokenByAddress,
- networkId,
- userAddressIfExists,
- sideToAssetToken,
- },
- type: ActionTypes.BatchDispatch,
- });
- }
- public updateTokenByAddress(tokens: Token[]): void {
- this._dispatch({
- data: tokens,
- type: ActionTypes.UpdateTokenByAddress,
- });
- }
- public forceTokenStateRefetch(): void {
- this._dispatch({
- type: ActionTypes.ForceTokenStateRefetch,
- });
- }
- public updateSignature(signature: string): void {
- this._dispatch({
- data: signature,
- type: ActionTypes.UpdateOrderSignature,
- });
- }
- public updateUserWeiBalance(balance?: BigNumber): void {
- this._dispatch({
- data: balance,
- type: ActionTypes.UpdateUserEtherBalance,
- });
- }
- public updateNetworkId(networkId: number): void {
- this._dispatch({
- data: networkId,
- type: ActionTypes.UpdateNetworkId,
- });
- }
- public updateOrderFillAmount(amount: BigNumber): void {
- this._dispatch({
- data: amount,
- type: ActionTypes.UpdateOrderFillAmount,
- });
- }
-
- public updatePortalOnboardingShowing(isShowing: boolean): void {
- this._dispatch({
- data: isShowing,
- type: ActionTypes.UpdatePortalOnboardingShowing,
- });
- }
-
- // Docs
- public updateCurrentDocsVersion(version: string): void {
- this._dispatch({
- data: version,
- type: ActionTypes.UpdateLibraryVersion,
- });
- }
- public updateAvailableDocVersions(versions: string[]): void {
- this._dispatch({
- data: versions,
- type: ActionTypes.UpdateAvailableLibraryVersions,
- });
- }
-
- // Shared
- public showFlashMessage(msg: string | React.ReactNode): void {
- this._dispatch({
- data: msg,
- type: ActionTypes.ShowFlashMessage,
- });
- }
- public hideFlashMessage(): void {
- this._dispatch({
- type: ActionTypes.HideFlashMessage,
- });
- }
- public updateProviderType(providerType: ProviderType): void {
- this._dispatch({
- type: ActionTypes.UpdateProviderType,
- data: providerType,
- });
- }
- public updateInjectedProviderName(injectedProviderName: string): void {
- this._dispatch({
- type: ActionTypes.UpdateInjectedProviderName,
- data: injectedProviderName,
- });
- }
- public updateSelectedLanguage(language: Language): void {
- this._dispatch({
- type: ActionTypes.UpdateSelectedLanguage,
- data: language,
- });
- }
-}
diff --git a/packages/website/ts/redux/reducer.ts b/packages/website/ts/redux/reducer.ts
deleted file mode 100644
index 51c77ba47..000000000
--- a/packages/website/ts/redux/reducer.ts
+++ /dev/null
@@ -1,361 +0,0 @@
-import { generatePseudoRandomSalt } from '@0x/order-utils';
-import { BigNumber } from '@0x/utils';
-import * as _ from 'lodash';
-import * as moment from 'moment';
-import {
- Action,
- ActionTypes,
- BlockchainErrs,
- PortalOrder,
- ProviderType,
- ScreenWidths,
- Side,
- SideToAssetToken,
- TokenByAddress,
-} from 'ts/types';
-import { constants } from 'ts/utils/constants';
-import { Translate } from 'ts/utils/translate';
-import { utils } from 'ts/utils/utils';
-
-// Instead of defaulting the docs version to an empty string, we pre-populate it with
-// a valid version value. This does not need to be updated however, since onLoad, it
-// is always replaced with a value retrieved from our S3 bucket.
-const DEFAULT_DOCS_VERSION = '0.0.0';
-
-export interface State {
- // Portal
- blockchainErr: BlockchainErrs;
- blockchainIsLoaded: boolean;
- networkId: number;
- orderExpiryTimestamp: BigNumber;
- orderFillAmount: BigNumber;
- orderTakerAddress: string;
- orderSignature: string;
- orderSalt: BigNumber;
- nodeVersion: string;
- screenWidth: ScreenWidths;
- shouldBlockchainErrDialogBeOpen: boolean;
- sideToAssetToken: SideToAssetToken;
- tokenByAddress: TokenByAddress;
- lastForceTokenStateRefetch: number;
- userAddress: string;
- userEtherBalanceInWei?: BigNumber;
- portalOnboardingStep: number;
- isPortalOnboardingShowing: boolean;
- hasPortalOnboardingBeenClosed: boolean;
- // Note: cache of supplied orderJSON in fill order step. Do not use for anything else.
- userSuppliedOrderCache: PortalOrder;
-
- // Docs
- docsVersion: string;
- availableDocVersions: string[];
-
- // Shared
- flashMessage: string | React.ReactNode;
- providerType: ProviderType;
- injectedProviderName: string;
- translate: Translate;
-}
-
-export const INITIAL_STATE: State = {
- // Portal
- blockchainErr: BlockchainErrs.NoError,
- blockchainIsLoaded: false,
- networkId: undefined,
- orderExpiryTimestamp: utils.initialOrderExpiryUnixTimestampSec(),
- orderFillAmount: undefined,
- orderSignature: '',
- orderTakerAddress: constants.NULL_ADDRESS,
- orderSalt: generatePseudoRandomSalt(),
- nodeVersion: undefined,
- screenWidth: utils.getScreenWidth(),
- shouldBlockchainErrDialogBeOpen: false,
- sideToAssetToken: {
- [Side.Deposit]: {},
- [Side.Receive]: {},
- },
- tokenByAddress: {},
- lastForceTokenStateRefetch: moment().unix(),
- userAddress: '',
- userEtherBalanceInWei: undefined,
- userSuppliedOrderCache: undefined,
- portalOnboardingStep: 0,
- isPortalOnboardingShowing: false,
- hasPortalOnboardingBeenClosed: false,
- // Docs
- docsVersion: DEFAULT_DOCS_VERSION,
- availableDocVersions: [DEFAULT_DOCS_VERSION],
- // Shared
- flashMessage: undefined,
- providerType: ProviderType.Injected,
- injectedProviderName: '',
- translate: new Translate(),
-};
-
-export function reducer(state: State = INITIAL_STATE, action: Action): State {
- switch (action.type) {
- // Portal
- case ActionTypes.ResetState:
- return {
- ...INITIAL_STATE,
- translate: state.translate,
- };
-
- case ActionTypes.UpdateOrderSalt: {
- return {
- ...state,
- orderSalt: action.data,
- };
- }
-
- case ActionTypes.UpdateSelectedLanguage: {
- return {
- ...state,
- translate: new Translate(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,
- userEtherBalanceInWei: action.data,
- };
- }
-
- case ActionTypes.UpdateUserSuppliedOrderCache: {
- return {
- ...state,
- userSuppliedOrderCache: action.data,
- };
- }
-
- 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.BatchDispatch: {
- const userAddress = _.isUndefined(action.data.userAddressIfExists) ? '' : action.data.userAddressIfExists;
- return {
- ...state,
- networkId: action.data.networkId,
- userAddress,
- sideToAssetToken: action.data.sideToAssetToken,
- tokenByAddress: action.data.tokenByAddress,
- };
- }
-
- case ActionTypes.ForceTokenStateRefetch:
- return {
- ...state,
- lastForceTokenStateRefetch: moment().unix(),
- };
-
- case ActionTypes.UpdateOrderSignature: {
- return {
- ...state,
- orderSignature: 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: {
- const userAddress = _.isUndefined(action.data) ? '' : action.data;
- return {
- ...state,
- userAddress,
- };
- }
-
- case ActionTypes.UpdatePortalOnboardingStep: {
- const portalOnboardingStep = action.data;
- return {
- ...state,
- portalOnboardingStep,
- };
- }
-
- case ActionTypes.UpdatePortalOnboardingShowing: {
- const isPortalOnboardingShowing = action.data;
- return {
- ...state,
- isPortalOnboardingShowing,
- hasPortalOnboardingBeenClosed: !isPortalOnboardingShowing ? true : state.hasPortalOnboardingBeenClosed,
- // always start onboarding from the beginning
- portalOnboardingStep: 0,
- };
- }
-
- // 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;
- }
-}
diff --git a/packages/website/ts/redux/store.ts b/packages/website/ts/redux/store.ts
deleted file mode 100644
index 006241371..000000000
--- a/packages/website/ts/redux/store.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import * as _ from 'lodash';
-import { applyMiddleware, createStore, Store as ReduxStore } from 'redux';
-import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly';
-import { stateStorage } from 'ts/local_storage/state_storage';
-import { analyticsMiddleware } from 'ts/redux/analyticsMiddleware';
-import { reducer, State } from 'ts/redux/reducer';
-
-const ONE_SECOND = 1000;
-
-export const store: ReduxStore<State> = createStore(
- reducer,
- stateStorage.getPersistedDefaultState(),
- composeWithDevTools(applyMiddleware(analyticsMiddleware)),
-);
-store.subscribe(
- _.throttle(() => {
- const state = store.getState();
- // Persisted state
- stateStorage.saveState({
- hasPortalOnboardingBeenClosed: state.hasPortalOnboardingBeenClosed,
- isPortalOnboardingShowing: state.isPortalOnboardingShowing,
- });
- }, ONE_SECOND),
-);