diff --git a/packages/instant/src/components/zero_ex_instant_provider.tsx b/packages/instant/src/components/zero_ex_instant_provider.tsx index 7b949eb78a..8babae306b 100644 --- a/packages/instant/src/components/zero_ex_instant_provider.tsx +++ b/packages/instant/src/components/zero_ex_instant_provider.tsx @@ -28,7 +28,6 @@ export class ZeroExInstantProvider extends React.PureComponent { - const currentState = this._store.getState(); - if ( - currentState.buyOrderState.processState === OrderProcessState.Success && - !currentState.buyOrderState.performedCallback && - this.props.onSuccess !== undefined - ) { - const txHash = currentState.buyOrderState.txHash; - this.props.onSuccess(txHash); - this._store.dispatch(actions.setBuyOrderStateSuccess(txHash, true)); - } - }); const dispatch = this._store.dispatch; // tslint:disable-next-line:no-floating-promises asyncData.fetchEthPriceAndDispatchToStore(dispatch); @@ -167,9 +155,6 @@ export class ZeroExInstantProvider extends React.PureComponent void; + onSuccess?: (txHash: string) => void; } interface ConnectedDispatch { @@ -52,6 +53,7 @@ const mapStateToProps = (state: State, _ownProps: SelectedAssetBuyOrderStateButt buyQuote: state.latestBuyQuote, affiliateInfo: state.affiliateInfo, selectedAsset, + onSuccess: state.onSuccess, onViewTransaction: () => { if ( state.buyOrderState.processState === OrderProcessState.Processing || @@ -107,7 +109,28 @@ const mapDispatchToProps = ( }, }); -export const SelectedAssetBuyOrderStateButtons: React.ComponentClass = connect( + +const mergeProps = ( + connectedState: ConnectedState, + connectedDispatch: ConnectedDispatch, + ownProps: SelectedAssetBuyOrderStateButtons, +) => { + return { + ...ownProps, + ...connectedState, + ...connectedDispatch, + onBuySuccess: (buyQuote: BuyQuote, txHash: string) => { + connectedDispatch.onBuySuccess(buyQuote, txHash); + if (connectedState.onSuccess) { + connectedState.onSuccess(txHash); + } + }, + } + +}; + +export const SelectedAssetBuyOrderStateButtons = connect( mapStateToProps, mapDispatchToProps, + mergeProps, )(BuyOrderStateButtons); diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts index 19890d2158..e7f161bfa7 100644 --- a/packages/instant/src/redux/reducer.ts +++ b/packages/instant/src/redux/reducer.ts @@ -52,6 +52,7 @@ interface OptionalState { latestErrorMessage: string; affiliateInfo: AffiliateInfo; walletDisplayName: string; + onSuccess: (txHash: string) => void; } export type State = DefaultState & PropsDerivedState & Partial; @@ -157,7 +158,6 @@ export const createReducer = (initialState: State) => { buyOrderState: { processState: OrderProcessState.Processing, txHash: processingData.txHash, - performedCallback: false, progress: { startTimeUnix, expectedEndTimeUnix, diff --git a/packages/instant/src/types.ts b/packages/instant/src/types.ts index a5674dcce2..ee94b885f4 100644 --- a/packages/instant/src/types.ts +++ b/packages/instant/src/types.ts @@ -43,7 +43,6 @@ interface OrderStatePostTx { processState: OrderProcessState.Processing | OrderProcessState.Success | OrderProcessState.Failure; txHash: string; progress: SimulatedProgress; - performedCallback: boolean; } export type OrderState = OrderStatePreTx | OrderStatePostTx;