Remove isTracked field on token in favor of trackedTimestamp
This commit is contained in:
@@ -30,6 +30,7 @@ import {
|
||||
import { BigNumber, intervalUtils, logUtils, promisify } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
import * as moment from 'moment';
|
||||
import * as React from 'react';
|
||||
import contract = require('truffle-contract');
|
||||
import { BlockchainWatcher } from 'ts/blockchain_watcher';
|
||||
@@ -559,6 +560,7 @@ export class Blockchain {
|
||||
tokenRegistryTokenSymbols,
|
||||
configs.DEFAULT_TRACKED_TOKEN_SYMBOLS,
|
||||
);
|
||||
const currentTimestamp = moment().unix();
|
||||
if (defaultTrackedTokensInRegistry.length !== configs.DEFAULT_TRACKED_TOKEN_SYMBOLS.length) {
|
||||
this._dispatcher.updateShouldBlockchainErrDialogBeOpen(true);
|
||||
this._dispatcher.encounteredBlockchainError(BlockchainErrs.DefaultTokensNotInTokenRegistry);
|
||||
@@ -573,7 +575,7 @@ export class Blockchain {
|
||||
if (_.isEmpty(trackedTokensByAddress)) {
|
||||
_.each(configs.DEFAULT_TRACKED_TOKEN_SYMBOLS, symbol => {
|
||||
const token = _.find(tokenRegistryTokens, t => t.symbol === symbol);
|
||||
token.isTracked = true;
|
||||
token.trackedTimestamp = currentTimestamp;
|
||||
trackedTokensByAddress[token.address] = token;
|
||||
});
|
||||
if (!_.isUndefined(this._userAddressIfExists)) {
|
||||
@@ -582,10 +584,10 @@ export class Blockchain {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Properly set all tokenRegistry tokens `isTracked` to true if they are in the existing trackedTokens array
|
||||
_.each(trackedTokensByAddress, (_trackedToken: Token, address: string) => {
|
||||
// Properly set all tokenRegistry tokens `trackedTimestamp` if they are in the existing trackedTokens array
|
||||
_.each(trackedTokensByAddress, (trackedToken: Token, address: string) => {
|
||||
if (!_.isUndefined(tokenRegistryTokensByAddress[address])) {
|
||||
tokenRegistryTokensByAddress[address].isTracked = true;
|
||||
tokenRegistryTokensByAddress[address].trackedTimestamp = trackedToken.trackedTimestamp;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -765,7 +767,7 @@ export class Blockchain {
|
||||
name: t.name,
|
||||
symbol: t.symbol,
|
||||
decimals: t.decimals,
|
||||
isTracked: false,
|
||||
trackedTimestamp: undefined,
|
||||
isRegistered: true,
|
||||
};
|
||||
tokenByAddress[token.address] = token;
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import Dialog from 'material-ui/Dialog';
|
||||
import FlatButton from 'material-ui/FlatButton';
|
||||
import * as moment from 'moment';
|
||||
import * as React from 'react';
|
||||
import { Blockchain } from 'ts/blockchain';
|
||||
import { TrackTokenConfirmation } from 'ts/components/track_token_confirmation';
|
||||
@@ -73,12 +74,13 @@ export class TrackTokenConfirmationDialog extends React.Component<
|
||||
this.setState({
|
||||
isAddingTokenToTracked: true,
|
||||
});
|
||||
const currentTimestamp = moment().unix();
|
||||
for (const token of this.props.tokens) {
|
||||
const newTokenEntry = {
|
||||
...token,
|
||||
trackedTimestamp: currentTimestamp,
|
||||
};
|
||||
|
||||
newTokenEntry.isTracked = true;
|
||||
trackedTokenStorage.addTrackedTokenToUser(this.props.userAddress, this.props.networkId, newTokenEntry);
|
||||
this.props.dispatcher.updateTokenByAddress([newTokenEntry]);
|
||||
}
|
||||
|
@@ -373,26 +373,26 @@ export class FillOrder extends React.Component<FillOrderProps, FillOrderState> {
|
||||
|
||||
const tokensToTrack: Token[] = [];
|
||||
const isUnseenMakerToken = _.isUndefined(makerTokenIfExists);
|
||||
const isMakerTokenTracked = !_.isUndefined(makerTokenIfExists) && makerTokenIfExists.isTracked;
|
||||
const isMakerTokenTracked = !_.isUndefined(makerTokenIfExists) && utils.isTokenTracked(makerTokenIfExists);
|
||||
if (isUnseenMakerToken) {
|
||||
tokensToTrack.push({
|
||||
...this.state.parsedOrder.metadata.makerToken,
|
||||
address: this.state.parsedOrder.signedOrder.makerTokenAddress,
|
||||
iconUrl: undefined,
|
||||
isTracked: false,
|
||||
trackedTimestamp: undefined,
|
||||
isRegistered: false,
|
||||
});
|
||||
} else if (!isMakerTokenTracked) {
|
||||
tokensToTrack.push(makerTokenIfExists);
|
||||
}
|
||||
const isUnseenTakerToken = _.isUndefined(takerTokenIfExists);
|
||||
const isTakerTokenTracked = !_.isUndefined(takerTokenIfExists) && takerTokenIfExists.isTracked;
|
||||
const isTakerTokenTracked = !_.isUndefined(takerTokenIfExists) && utils.isTokenTracked(takerTokenIfExists);
|
||||
if (isUnseenTakerToken) {
|
||||
tokensToTrack.push({
|
||||
...this.state.parsedOrder.metadata.takerToken,
|
||||
address: this.state.parsedOrder.signedOrder.takerTokenAddress,
|
||||
iconUrl: undefined,
|
||||
isTracked: false,
|
||||
trackedTimestamp: undefined,
|
||||
isRegistered: false,
|
||||
});
|
||||
} else if (!isTakerTokenTracked) {
|
||||
|
@@ -11,6 +11,7 @@ import { trackedTokenStorage } from 'ts/local_storage/tracked_token_storage';
|
||||
import { Dispatcher } from 'ts/redux/dispatcher';
|
||||
import { DialogConfigs, Token, TokenByAddress, TokenVisibility } from 'ts/types';
|
||||
import { constants } from 'ts/utils/constants';
|
||||
import { utils } from 'ts/utils/utils';
|
||||
|
||||
const TOKEN_ICON_DIMENSION = 100;
|
||||
const TILE_DIMENSION = 146;
|
||||
@@ -135,8 +136,8 @@ export class AssetPicker extends React.Component<AssetPickerProps, AssetPickerSt
|
||||
let tileStyles;
|
||||
const gridTiles = _.map(this.props.tokenByAddress, (token: Token, address: string) => {
|
||||
if (
|
||||
(this.props.tokenVisibility === TokenVisibility.TRACKED && !token.isTracked) ||
|
||||
(this.props.tokenVisibility === TokenVisibility.UNTRACKED && token.isTracked) ||
|
||||
(this.props.tokenVisibility === TokenVisibility.TRACKED && !utils.isTokenTracked(token)) ||
|
||||
(this.props.tokenVisibility === TokenVisibility.UNTRACKED && utils.isTokenTracked(token)) ||
|
||||
token.symbol === constants.ZRX_TOKEN_SYMBOL ||
|
||||
token.symbol === constants.ETHER_TOKEN_SYMBOL
|
||||
) {
|
||||
@@ -213,7 +214,7 @@ export class AssetPicker extends React.Component<AssetPickerProps, AssetPickerSt
|
||||
}
|
||||
private _onChooseToken(tokenAddress: string): void {
|
||||
const token = this.props.tokenByAddress[tokenAddress];
|
||||
if (token.isTracked) {
|
||||
if (utils.isTokenTracked(token)) {
|
||||
this.props.onTokenChosen(tokenAddress);
|
||||
} else {
|
||||
this.setState({
|
||||
@@ -258,10 +259,8 @@ export class AssetPicker extends React.Component<AssetPickerProps, AssetPickerSt
|
||||
}
|
||||
const newTokenEntry = {
|
||||
...token,
|
||||
trackedTimestamp: moment().unix(),
|
||||
};
|
||||
|
||||
newTokenEntry.isTracked = true;
|
||||
newTokenEntry.trackedTimestamp = moment().unix();
|
||||
trackedTokenStorage.addTrackedTokenToUser(this.props.userAddress, this.props.networkId, newTokenEntry);
|
||||
|
||||
this.props.dispatcher.updateTokenByAddress([newTokenEntry]);
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import { colors } from '@0xproject/react-shared';
|
||||
import * as _ from 'lodash';
|
||||
import TextField from 'material-ui/TextField';
|
||||
import * as moment from 'moment';
|
||||
import * as React from 'react';
|
||||
import { Blockchain } from 'ts/blockchain';
|
||||
import { AddressInput } from 'ts/components/inputs/address_input';
|
||||
@@ -147,7 +148,7 @@ export class NewTokenForm extends React.Component<NewTokenFormProps, NewTokenFor
|
||||
iconUrl: undefined,
|
||||
name: this.state.name,
|
||||
symbol: this.state.symbol.toUpperCase(),
|
||||
isTracked: true,
|
||||
trackedTimestamp: moment().unix(),
|
||||
isRegistered: false,
|
||||
};
|
||||
this.props.onNewTokenSubmitted(newToken);
|
||||
|
@@ -292,8 +292,7 @@ export class LegacyPortal extends React.Component<LegacyPortalProps, LegacyPorta
|
||||
);
|
||||
}
|
||||
private _renderTokenBalances(): React.ReactNode {
|
||||
const allTokens = _.values(this.props.tokenByAddress);
|
||||
const trackedTokens = _.filter(allTokens, t => t.isTracked);
|
||||
const trackedTokens = utils.getTrackedTokens(this.props.tokenByAddress);
|
||||
return (
|
||||
<TokenBalances
|
||||
blockchain={this._blockchain}
|
||||
|
@@ -563,9 +563,9 @@ export class Portal extends React.Component<PortalProps, PortalState> {
|
||||
if (this.state.tokenManagementState === TokenManagementState.Remove && !isDefaultTrackedToken) {
|
||||
if (token.isRegistered) {
|
||||
// Remove the token from tracked tokens
|
||||
const newToken = {
|
||||
const newToken: Token = {
|
||||
...token,
|
||||
isTracked: false,
|
||||
trackedTimestamp: undefined,
|
||||
};
|
||||
this.props.dispatcher.updateTokenByAddress([newToken]);
|
||||
} else {
|
||||
|
@@ -424,9 +424,9 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala
|
||||
if (!this.state.isAddingToken && !isDefaultTrackedToken) {
|
||||
if (token.isRegistered) {
|
||||
// Remove the token from tracked tokens
|
||||
const newToken = {
|
||||
const newToken: Token = {
|
||||
...token,
|
||||
isTracked: false,
|
||||
trackedTimestamp: undefined,
|
||||
};
|
||||
this.props.dispatcher.updateTokenByAddress([newToken]);
|
||||
} else {
|
||||
|
@@ -13,7 +13,6 @@ export interface Token {
|
||||
address: string;
|
||||
symbol: string;
|
||||
decimals: number;
|
||||
isTracked: boolean;
|
||||
isRegistered: boolean;
|
||||
trackedTimestamp?: number;
|
||||
}
|
||||
|
@@ -66,7 +66,7 @@ export const configs = {
|
||||
IS_MAINNET_ENABLED: true,
|
||||
GOOGLE_ANALYTICS_ID: 'UA-98720122-1',
|
||||
LAST_LOCAL_STORAGE_FILL_CLEARANCE_DATE: '2017-11-22',
|
||||
LAST_LOCAL_STORAGE_TRACKED_TOKEN_CLEARANCE_DATE: '2017-12-19',
|
||||
LAST_LOCAL_STORAGE_TRACKED_TOKEN_CLEARANCE_DATE: '2018-6-25',
|
||||
OUTDATED_WRAPPED_ETHERS: [
|
||||
{
|
||||
42: {
|
||||
|
@@ -357,7 +357,7 @@ export const utils = {
|
||||
},
|
||||
getTrackedTokens(tokenByAddress: TokenByAddress): Token[] {
|
||||
const allTokens = _.values(tokenByAddress);
|
||||
const trackedTokens = _.filter(allTokens, t => t.isTracked);
|
||||
const trackedTokens = _.filter(allTokens, t => this.isTokenTracked(t));
|
||||
return trackedTokens;
|
||||
},
|
||||
getFormattedAmountFromToken(token: Token, tokenState: TokenState): string {
|
||||
@@ -386,4 +386,7 @@ export const utils = {
|
||||
return BrowserType.Other;
|
||||
}
|
||||
},
|
||||
isTokenTracked(token: Token): boolean {
|
||||
return !_.isUndefined(token.trackedTimestamp);
|
||||
},
|
||||
};
|
||||
|
Reference in New Issue
Block a user