aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/containers/selected_asset_view_transaction_button.tsx
blob: 44de16c4a50588406cec3666718c977e25c89535 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { EtherscanLinkSuffixes, utils } from '@0x/react-shared';
import * as _ from 'lodash';
import * as React from 'react';
import { connect } from 'react-redux';

import { State } from '../redux/reducer';

import { ViewTransactionButton } from '../components/view_transaction_button';
import { AsyncProcessState } from '../types';

export interface SelectedAssetViewTransactionButtonProps {}

interface ConnectedState {
    onClick: () => void;
}

const mapStateToProps = (state: State, _ownProps: {}): ConnectedState => ({
    onClick: () => {
        if (state.assetBuyer && state.buyOrderState.processState === AsyncProcessState.SUCCESS) {
            const etherscanUrl = utils.getEtherScanLinkIfExists(
                state.buyOrderState.txnHash,
                state.assetBuyer.networkId,
                EtherscanLinkSuffixes.Tx,
            );
            if (etherscanUrl) {
                window.open(etherscanUrl, '_blank');
                return;
            }
        }
    },
});

export const SelectedAssetViewTransactionButton: React.ComponentClass<
    SelectedAssetViewTransactionButtonProps
> = connect(mapStateToProps)(ViewTransactionButton);