aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/redux
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-01-31 04:27:21 +0800
committerGitHub <noreply@github.com>2018-01-31 04:27:21 +0800
commit1feac1a30886944ccadc00b2ff4f493e0d495301 (patch)
treebe68e9a62e3de3caf6e5e841899df16d8decc7e5 /packages/website/ts/redux
parent2bcb7d56394c43acd68d1823092de2ad047abc6d (diff)
parentd3e42e4b3e2f893b616246d35f46dba92f251e83 (diff)
downloaddexon-sol-tools-1feac1a30886944ccadc00b2ff4f493e0d495301.tar
dexon-sol-tools-1feac1a30886944ccadc00b2ff4f493e0d495301.tar.gz
dexon-sol-tools-1feac1a30886944ccadc00b2ff4f493e0d495301.tar.bz2
dexon-sol-tools-1feac1a30886944ccadc00b2ff4f493e0d495301.tar.lz
dexon-sol-tools-1feac1a30886944ccadc00b2ff4f493e0d495301.tar.xz
dexon-sol-tools-1feac1a30886944ccadc00b2ff4f493e0d495301.tar.zst
dexon-sol-tools-1feac1a30886944ccadc00b2ff4f493e0d495301.zip
Merge pull request #351 from 0xProject/feature/portal-ledger-support
Portal Ledger Support, Lazy-loading token balances/allowances
Diffstat (limited to 'packages/website/ts/redux')
-rw-r--r--packages/website/ts/redux/dispatcher.ts56
-rw-r--r--packages/website/ts/redux/reducer.ts81
2 files changed, 27 insertions, 110 deletions
diff --git a/packages/website/ts/redux/dispatcher.ts b/packages/website/ts/redux/dispatcher.ts
index 42989e5e1..87415b285 100644
--- a/packages/website/ts/redux/dispatcher.ts
+++ b/packages/website/ts/redux/dispatcher.ts
@@ -9,9 +9,10 @@ import {
ProviderType,
ScreenWidths,
Side,
+ SideToAssetToken,
SignatureData,
Token,
- TokenStateByAddress,
+ TokenByAddress,
} from 'ts/types';
export class Dispatcher {
@@ -120,9 +121,20 @@ export class Dispatcher {
type: ActionTypes.RemoveTokenFromTokenByAddress,
});
}
- public clearTokenByAddress() {
+ public batchDispatch(
+ tokenByAddress: TokenByAddress,
+ networkId: number,
+ userAddress: string,
+ sideToAssetToken: SideToAssetToken,
+ ) {
this._dispatch({
- type: ActionTypes.ClearTokenByAddress,
+ data: {
+ tokenByAddress,
+ networkId,
+ userAddress,
+ sideToAssetToken,
+ },
+ type: ActionTypes.BatchDispatch,
});
}
public updateTokenByAddress(tokens: Token[]) {
@@ -131,43 +143,9 @@ export class Dispatcher {
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) {
+ public forceTokenStateRefetch() {
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,
+ type: ActionTypes.ForceTokenStateRefetch,
});
}
public updateSignatureData(signatureData: SignatureData) {
diff --git a/packages/website/ts/redux/reducer.ts b/packages/website/ts/redux/reducer.ts
index 06ac8b670..7b0b03dae 100644
--- a/packages/website/ts/redux/reducer.ts
+++ b/packages/website/ts/redux/reducer.ts
@@ -1,6 +1,7 @@
import { ZeroEx } from '0x.js';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
+import * as moment from 'moment';
import {
Action,
ActionTypes,
@@ -12,8 +13,6 @@ import {
SideToAssetToken,
SignatureData,
TokenByAddress,
- TokenState,
- TokenStateByAddress,
} from 'ts/types';
import { utils } from 'ts/utils/utils';
@@ -37,7 +36,7 @@ export interface State {
shouldBlockchainErrDialogBeOpen: boolean;
sideToAssetToken: SideToAssetToken;
tokenByAddress: TokenByAddress;
- tokenStateByAddress: TokenStateByAddress;
+ lastForceTokenStateRefetch: number;
userAddress: string;
userEtherBalance: BigNumber;
// Note: cache of supplied orderJSON in fill order step. Do not use for anything else.
@@ -76,7 +75,7 @@ const INITIAL_STATE: State = {
[Side.Receive]: {},
},
tokenByAddress: {},
- tokenStateByAddress: {},
+ lastForceTokenStateRefetch: moment().unix(),
userAddress: '',
userEtherBalance: new BigNumber(0),
userSuppliedOrderCache: undefined,
@@ -139,13 +138,6 @@ export function reducer(state: State = INITIAL_STATE, action: Action) {
};
}
- case ActionTypes.ClearTokenByAddress: {
- return {
- ...state,
- tokenByAddress: {},
- };
- }
-
case ActionTypes.AddTokenToTokenByAddress: {
const newTokenByAddress = state.tokenByAddress;
newTokenByAddress[action.data.address] = action.data;
@@ -180,74 +172,21 @@ export function reducer(state: State = INITIAL_STATE, action: Action) {
};
}
- 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,
- };
+ case ActionTypes.BatchDispatch: {
return {
...state,
- tokenStateByAddress,
+ networkId: action.data.networkId,
+ userAddress: action.data.userAddress,
+ sideToAssetToken: action.data.sideToAssetToken,
+ tokenByAddress: action.data.tokenByAddress,
};
}
- case ActionTypes.ReplaceTokenBalanceByAddress: {
- const tokenStateByAddress = state.tokenStateByAddress;
- const balance = action.data.balance;
- const tokenAddress = action.data.address;
- tokenStateByAddress[tokenAddress] = {
- ...tokenStateByAddress[tokenAddress],
- balance,
- };
+ case ActionTypes.ForceTokenStateRefetch:
return {
...state,
- tokenStateByAddress,
+ lastForceTokenStateRefetch: moment().unix(),
};
- }
-
- 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 {