import { connect } from 'react-redux' ; import * as React from 'react' ; import runActionCreators from '../../../state/run/runActionCreators' ; import State from '../../../state/State' ; import { Dispatch , Action } from 'redux' ; import StakeTypes from '../../../model/enums/StakeTypes' ; interface SendStakeButtonProps { isConnected : boolean ; allowedStakeTypes : Record < StakeTypes , boolean > ; stake : number ; sendStake : ( ) => void ; } const mapStateToProps = ( state ) => ( { isConnected : state . common . isConnected , allowedStakeTypes : state . run . stakes . allowedStakeTypes , stake : state . run . stakes . stake } ) ; const mapDispatchToProps = ( dispatch ) => ( { sendStake : ( ) => { dispatch ( ( runActionCreators . sendStake ( ) as object ) as Action ) ; } } ) ; export function SendStakeButton ( props ) { const canSendStake = props . allowedStakeTypes [ StakeTypes . Sum ] ; return < button onClick = { ( ) => props . sendStake ( ) } disabled = { ! props . isConnected || ! canSendStake } > { canSendStake ? props . stake : '' } < /button>; } export default connect ( mapStateToProps , mapDispatchToProps ) ( SendStakeButton ) ;