aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-10-16 09:07:19 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-10-16 09:07:19 +0800
commitf2e5fd88469c9e3396197b42298d0b2de8a4d47c (patch)
tree7f597250870b2157f6e54418fc6c339f63ea8e02 /packages/instant
parent18667d739c112955478ab07cb245dc435b31a974 (diff)
downloaddexon-sol-tools-f2e5fd88469c9e3396197b42298d0b2de8a4d47c.tar
dexon-sol-tools-f2e5fd88469c9e3396197b42298d0b2de8a4d47c.tar.gz
dexon-sol-tools-f2e5fd88469c9e3396197b42298d0b2de8a4d47c.tar.bz2
dexon-sol-tools-f2e5fd88469c9e3396197b42298d0b2de8a4d47c.tar.lz
dexon-sol-tools-f2e5fd88469c9e3396197b42298d0b2de8a4d47c.tar.xz
dexon-sol-tools-f2e5fd88469c9e3396197b42298d0b2de8a4d47c.tar.zst
dexon-sol-tools-f2e5fd88469c9e3396197b42298d0b2de8a4d47c.zip
Add ts-optchain and use it instead of lodash get
Diffstat (limited to 'packages/instant')
-rw-r--r--packages/instant/package.json3
-rw-r--r--packages/instant/src/components/order_details.tsx8
-rw-r--r--packages/instant/src/containers/latest_buy_quote_order_details.ts3
-rw-r--r--packages/instant/src/containers/selected_asset_instant_heading.ts3
4 files changed, 11 insertions, 6 deletions
diff --git a/packages/instant/package.json b/packages/instant/package.json
index 35cc39d27..7203e3c96 100644
--- a/packages/instant/package.json
+++ b/packages/instant/package.json
@@ -56,7 +56,8 @@
"react-dom": "^16.5.2",
"react-redux": "^5.0.7",
"redux": "^4.0.0",
- "styled-components": "^3.4.9"
+ "styled-components": "^3.4.9",
+ "ts-optchain": "^0.1.1"
},
"devDependencies": {
"@0xproject/tslint-config": "^1.0.8",
diff --git a/packages/instant/src/components/order_details.tsx b/packages/instant/src/components/order_details.tsx
index bd31bfba8..a15ff411b 100644
--- a/packages/instant/src/components/order_details.tsx
+++ b/packages/instant/src/components/order_details.tsx
@@ -2,6 +2,7 @@ import { BuyQuoteInfo } from '@0xproject/asset-buyer';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import * as React from 'react';
+import { oc } from 'ts-optchain';
import { ColorOption } from '../style/theme';
import { format } from '../util/format';
@@ -16,9 +17,10 @@ export interface OrderDetailsProps {
export class OrderDetails extends React.Component<OrderDetailsProps> {
public render(): React.ReactNode {
const { buyQuoteInfo, ethUsdPrice } = this.props;
- const ethAssetPrice = _.get(buyQuoteInfo, 'ethPerAssetPrice');
- const ethTokenFee = _.get(buyQuoteInfo, 'feeEthAmount');
- const totalEthAmount = _.get(buyQuoteInfo, 'totalEthAmount');
+ const buyQuoteAccessor = oc(buyQuoteInfo);
+ const ethAssetPrice = buyQuoteAccessor.ethPerAssetPrice();
+ const ethTokenFee = buyQuoteAccessor.feeEthAmount();
+ const totalEthAmount = buyQuoteAccessor.totalEthAmount();
return (
<Container padding="20px" width="100%">
<Container marginBottom="10px">
diff --git a/packages/instant/src/containers/latest_buy_quote_order_details.ts b/packages/instant/src/containers/latest_buy_quote_order_details.ts
index 77d84289b..b354c78fa 100644
--- a/packages/instant/src/containers/latest_buy_quote_order_details.ts
+++ b/packages/instant/src/containers/latest_buy_quote_order_details.ts
@@ -3,6 +3,7 @@ import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import * as React from 'react';
import { connect } from 'react-redux';
+import { oc } from 'ts-optchain';
import { State } from '../redux/reducer';
@@ -17,7 +18,7 @@ interface ConnectedState {
const mapStateToProps = (state: State, _ownProps: LatestBuyQuoteOrderDetailsProps): ConnectedState => ({
// use the worst case quote info
- buyQuoteInfo: _.get(state, 'latestBuyQuote.worstCaseQuoteInfo'),
+ buyQuoteInfo: oc(state).latestBuyQuote.worstCaseQuoteInfo(),
ethUsdPrice: state.ethUsdPrice,
});
diff --git a/packages/instant/src/containers/selected_asset_instant_heading.ts b/packages/instant/src/containers/selected_asset_instant_heading.ts
index a9e853fe1..c97cfe11a 100644
--- a/packages/instant/src/containers/selected_asset_instant_heading.ts
+++ b/packages/instant/src/containers/selected_asset_instant_heading.ts
@@ -2,6 +2,7 @@ import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import * as React from 'react';
import { connect } from 'react-redux';
+import { oc } from 'ts-optchain';
import { State } from '../redux/reducer';
@@ -17,7 +18,7 @@ interface ConnectedState {
const mapStateToProps = (state: State, _ownProps: InstantHeadingProps): ConnectedState => ({
selectedAssetAmount: state.selectedAssetAmount,
- totalEthBaseAmount: _.get(state, 'latestBuyQuote.worstCaseQuoteInfo.totalEthAmount'),
+ totalEthBaseAmount: oc(state).latestBuyQuote.worstCaseQuoteInfo.totalEthAmount(),
ethUsdPrice: state.ethUsdPrice,
});