From 3278318fa62241990c75825a91919c5cf314a9a3 Mon Sep 17 00:00:00 2001 From: Daniel Ternyak Date: Wed, 7 Mar 2018 10:54:14 -0600 Subject: [PATCH] Fix Coinbase Widget (#1286) * Connect Promos; pass current wallet address to Coinbase * Use ShapeShift as promo if no wallet instance when showing Coinbase * use appstate for typing --- .../PromoComponents/Coinbase.tsx | 8 +++- common/components/BalanceSidebar/Promos.tsx | 38 +++++++++++++++++-- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/common/components/BalanceSidebar/PromoComponents/Coinbase.tsx b/common/components/BalanceSidebar/PromoComponents/Coinbase.tsx index c3714652..6be6dd5e 100644 --- a/common/components/BalanceSidebar/PromoComponents/Coinbase.tsx +++ b/common/components/BalanceSidebar/PromoComponents/Coinbase.tsx @@ -2,10 +2,14 @@ import React from 'react'; import CoinbaseLogo from 'assets/images/logo-coinbase.svg'; import { NewTabLink } from 'components/ui'; -export const Coinbase: React.SFC = () => ( +interface Props { + address: string; +} + +export const Coinbase: React.SFC = ({ address }) => (
diff --git a/common/components/BalanceSidebar/Promos.tsx b/common/components/BalanceSidebar/Promos.tsx index 32f1fbfe..fdc5fa94 100644 --- a/common/components/BalanceSidebar/Promos.tsx +++ b/common/components/BalanceSidebar/Promos.tsx @@ -2,8 +2,8 @@ import React from 'react'; import { TransitionGroup, CSSTransition } from 'react-transition-group'; import { HardwareWallets, Coinbase, Shapeshift } from './PromoComponents'; import './Promos.scss'; - -const promos = [HardwareWallets, Coinbase, Shapeshift]; +import { connect } from 'react-redux'; +import { AppState } from '../../reducers'; const CarouselAnimation = ({ children, ...props }) => ( @@ -11,12 +11,20 @@ const CarouselAnimation = ({ children, ...props }) => ( ); +// Don't change Coinbase index +const promos = [HardwareWallets, Coinbase, Shapeshift]; + interface State { activePromo: number; } -export default class Promos extends React.PureComponent<{}, State> { +interface StateProps { + wallet: AppState['wallet']['inst']; +} + +class PromosClass extends React.PureComponent { public timer: any = null; + public promos = [HardwareWallets, Coinbase, Shapeshift]; public state = { activePromo: parseInt(String(Math.random() * promos.length), 10) @@ -30,13 +38,27 @@ export default class Promos extends React.PureComponent<{}, State> { clearInterval(this.timer); } + public getPromo() { + const { activePromo } = this.state; + const { wallet } = this.props; + if (activePromo === 1) { + if (wallet) { + return ; + } else { + return ; + } + } else { + return promos[activePromo]; + } + } + public render() { const { activePromo } = this.state; return (
- {promos[activePromo]} + {this.getPromo()}
{promos.map((_, index) => { @@ -64,3 +86,11 @@ export default class Promos extends React.PureComponent<{}, State> { this.setState({ activePromo }); }; } + +function mapStateToProps(state: AppState): StateProps { + return { + wallet: state.wallet.inst + }; +} + +export default connect(mapStateToProps, {})(PromosClass);