Add utilities for getting tokens from tokensByAddress
This commit is contained in:
@@ -2,12 +2,14 @@ import * as _ from 'lodash';
|
||||
import * as React from 'react';
|
||||
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import { Blockchain } from 'ts/blockchain';
|
||||
import { OnboardingFlow, Step } from 'ts/components/onboarding/onboarding_flow';
|
||||
import { ProviderType, TokenByAddress, TokenStateByAddress } from 'ts/types';
|
||||
import { utils } from 'ts/utils/utils';
|
||||
import { AllowanceToggle } from 'ts/containers/inputs/allowance_toggle';
|
||||
|
||||
export interface PortalOnboardingFlowProps {
|
||||
blockchain: Blockchain;
|
||||
stepIndex: number;
|
||||
isRunning: boolean;
|
||||
userAddress: string;
|
||||
@@ -20,6 +22,7 @@ export interface PortalOnboardingFlowProps {
|
||||
trackedTokenStateByAddress: TokenStateByAddress;
|
||||
updateIsRunning: (isRunning: boolean) => void;
|
||||
updateOnboardingStep: (stepIndex: number) => void;
|
||||
refetchTokenStateAsync: (tokenAddress: string) => Promise<void>;
|
||||
}
|
||||
|
||||
export class PortalOnboardingFlow extends React.Component<PortalOnboardingFlowProps> {
|
||||
|
||||
@@ -235,7 +235,11 @@ export class Portal extends React.Component<PortalProps, PortalState> {
|
||||
: TokenVisibility.TRACKED;
|
||||
return (
|
||||
<div style={styles.root}>
|
||||
<PortalOnboardingFlow trackedTokenStateByAddress={this.state.trackedTokenStateByAddress} />
|
||||
<PortalOnboardingFlow
|
||||
blockchain={this._blockchain}
|
||||
trackedTokenStateByAddress={this.state.trackedTokenStateByAddress}
|
||||
refetchTokenStateAsync={this._refetchTokenStateAsync.bind(this)}
|
||||
/>
|
||||
<DocumentTitle title="0x Portal DApp" />
|
||||
<TopBar
|
||||
userAddress={this.props.userAddress}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { BigNumber } from '@0xproject/utils';
|
||||
import * as React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { Dispatch } from 'redux';
|
||||
import { Blockchain } from 'ts/blockchain';
|
||||
import { ActionTypes, ProviderType, TokenByAddress, TokenStateByAddress } from 'ts/types';
|
||||
|
||||
import { PortalOnboardingFlow as PortalOnboardingFlowComponent } from 'ts/components/onboarding/portal_onboarding_flow';
|
||||
@@ -9,6 +10,8 @@ import { State } from 'ts/redux/reducer';
|
||||
|
||||
interface PortalOnboardingFlowProps {
|
||||
trackedTokenStateByAddress: TokenStateByAddress;
|
||||
blockchain: Blockchain;
|
||||
refetchTokenStateAsync: (tokenAddress: string) => Promise<void>;
|
||||
}
|
||||
|
||||
interface ConnectedState {
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
import { configs } from 'ts/utils/configs';
|
||||
import { constants } from 'ts/utils/constants';
|
||||
import * as u2f from 'ts/vendor/u2f_api';
|
||||
import { Container } from '../components/ui/container';
|
||||
|
||||
const LG_MIN_EM = 64;
|
||||
const MD_MIN_EM = 52;
|
||||
@@ -322,8 +323,14 @@ export const utils = {
|
||||
return this.isDevelopment() || this.isStaging() || this.isDogfood();
|
||||
},
|
||||
getEthToken(tokenByAddress: TokenByAddress): Token {
|
||||
return utils.getTokenBySymbol(constants.ETHER_TOKEN_SYMBOL, tokenByAddress);
|
||||
},
|
||||
getZrxToken(tokenByAddress: TokenByAddress): Token {
|
||||
return utils.getTokenBySymbol(constants.ZRX_TOKEN_SYMBOL, tokenByAddress);
|
||||
},
|
||||
getTokenBySymbol(symbol: string, tokenByAddress: TokenByAddress): Token {
|
||||
const tokens = _.values(tokenByAddress);
|
||||
const etherToken = _.find(tokens, { symbol: constants.ETHER_TOKEN_SYMBOL });
|
||||
return etherToken;
|
||||
const token = _.find(tokens, { symbol });
|
||||
return token;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user