diff options
author | Brandon Millman <brandon@0xproject.com> | 2018-06-23 02:43:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-23 02:43:02 +0800 |
commit | b097193486a07ae52bcac591438a007499d96275 (patch) | |
tree | 482a321f97ab93082bf63adfe2bed1e7b78809bf /packages | |
parent | 05c008844532a9386341f60e51270756341d00db (diff) | |
parent | 543f2c91fe3d00be33b2193eb88529a53622506a (diff) | |
download | dexon-sol-tools-b097193486a07ae52bcac591438a007499d96275.tar.gz dexon-sol-tools-b097193486a07ae52bcac591438a007499d96275.tar.zst dexon-sol-tools-b097193486a07ae52bcac591438a007499d96275.zip |
Merge pull request #750 from 0xProject/bug/website/fix-add-token
Various add token flow bugs
Diffstat (limited to 'packages')
-rw-r--r-- | packages/website/ts/components/generate_order/asset_picker.tsx | 22 | ||||
-rw-r--r-- | packages/website/ts/redux/reducer.ts | 8 |
2 files changed, 16 insertions, 14 deletions
diff --git a/packages/website/ts/components/generate_order/asset_picker.tsx b/packages/website/ts/components/generate_order/asset_picker.tsx index b43ac1f2e..87618f1e0 100644 --- a/packages/website/ts/components/generate_order/asset_picker.tsx +++ b/packages/website/ts/components/generate_order/asset_picker.tsx @@ -232,12 +232,14 @@ export class AssetPicker extends React.Component<AssetPickerProps, AssetPickerSt this.props.onTokenChosen(newToken.address); } private async _onTrackConfirmationRespondedAsync(didUserAcceptTracking: boolean): Promise<void> { + const resetState: AssetPickerState = { + ...this.state, + isAddingTokenToTracked: false, + assetView: AssetViews.ASSET_PICKER, + chosenTrackTokenAddress: undefined, + }; if (!didUserAcceptTracking) { - this.setState({ - isAddingTokenToTracked: false, - assetView: AssetViews.ASSET_PICKER, - chosenTrackTokenAddress: undefined, - }); + this.setState(resetState); this._onCloseDialog(); return; } @@ -246,6 +248,10 @@ export class AssetPicker extends React.Component<AssetPickerProps, AssetPickerSt }); const tokenAddress = this.state.chosenTrackTokenAddress; const token = this.props.tokenByAddress[tokenAddress]; + if (_.isUndefined(tokenAddress)) { + this.setState(resetState); + return; + } const newTokenEntry = { ...token, }; @@ -254,11 +260,7 @@ export class AssetPicker extends React.Component<AssetPickerProps, AssetPickerSt trackedTokenStorage.addTrackedTokenToUser(this.props.userAddress, this.props.networkId, newTokenEntry); this.props.dispatcher.updateTokenByAddress([newTokenEntry]); - this.setState({ - isAddingTokenToTracked: false, - assetView: AssetViews.ASSET_PICKER, - chosenTrackTokenAddress: undefined, - }); + this.setState(resetState); this.props.onTokenChosen(tokenAddress); } } diff --git a/packages/website/ts/redux/reducer.ts b/packages/website/ts/redux/reducer.ts index 9d3d8f7d9..ed6a4868e 100644 --- a/packages/website/ts/redux/reducer.ts +++ b/packages/website/ts/redux/reducer.ts @@ -156,7 +156,7 @@ export function reducer(state: State = INITIAL_STATE, action: Action): State { } case ActionTypes.AddTokenToTokenByAddress: { - const newTokenByAddress = state.tokenByAddress; + const newTokenByAddress = { ...state.tokenByAddress }; newTokenByAddress[action.data.address] = action.data; return { ...state, @@ -165,7 +165,7 @@ export function reducer(state: State = INITIAL_STATE, action: Action): State { } case ActionTypes.RemoveTokenFromTokenByAddress: { - const newTokenByAddress = state.tokenByAddress; + const newTokenByAddress = { ...state.tokenByAddress }; delete newTokenByAddress[action.data.address]; return { ...state, @@ -174,7 +174,7 @@ export function reducer(state: State = INITIAL_STATE, action: Action): State { } case ActionTypes.UpdateTokenByAddress: { - const tokenByAddress = state.tokenByAddress; + const tokenByAddress = { ...state.tokenByAddress }; const tokens = action.data; _.each(tokens, token => { const updatedToken = { @@ -253,7 +253,7 @@ export function reducer(state: State = INITIAL_STATE, action: Action): State { } case ActionTypes.UpdateChosenAssetTokenAddress: { - const newAssetToken = state.sideToAssetToken[action.data.side]; + const newAssetToken = { ...state.sideToAssetToken[action.data.side] }; newAssetToken.address = action.data.address; const newSideToAssetToken = { ...state.sideToAssetToken, |