From 00a6afaa8e1658608d441d7cfcd31bc73c70253a Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 13 Nov 2017 16:27:43 -0500 Subject: [PATCH 01/10] Re-add changelog for 0x.js --- packages/0x.js/CHANGELOG.md | 211 ++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 packages/0x.js/CHANGELOG.md diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md new file mode 100644 index 0000000000..029144b5ae --- /dev/null +++ b/packages/0x.js/CHANGELOG.md @@ -0,0 +1,211 @@ +# CHANGELOG + +v0.22.6 - _November 10, 2017_ +------------------------ + * Add a timeout parameter to transaction awaiting (#206) + +v0.22.5 - _November 7, 2017_ +------------------------ + * Re-publish v0.22.4 to fix publishing issue + +v0.22.4 - _October 25, 2017_ +------------------------ + * Upgraded bignumber.js to a new version that ships with native typings + +v0.22.3 - _October 25, 2017_ +------------------------ + * Fixed an issue with new version of testrpc and unlimited proxy allowance (#199) + +v0.22.2 - _October 24, 2017_ +------------------------ + * Fixed rounding of maker fill amount and incorrect validation of partial fees (#197) + +v0.22.0 - _October 16, 2017_ +------------------------ + * Started using `OrderFillRequest` interface instead of `OrderFillOrKillRequest` interface for `zeroEx.exchange.batchFillOrKill` (#187) + * Removed `OrderFillOrKillRequest` (#187) + +v0.21.4 - _October 13, 2017_ +------------------------ + * Made 0x.js more type-safe by making `getLogsAsync` and `subscribe/subscribeAsync` generics parametrized with arg type (#194) + +v0.21.3 - _October 12, 2017_ +------------------------ + * Fixed a bug causing order fills to throw `INSUFFICIENT_TAKER_ALLOWANCE` (#193) + +v0.21.2 - _October 11, 2017_ +------------------------ + * Exported `ContractEventArg` as a public type (#190) + +v0.21.1 - _October 11, 2017_ +------------------------ + * Fixed a bug in subscriptions (#189) + +v0.21.0 - _October 10, 2017_ +------------------------ + * Complete rewrite of subscription logic (#182) + * Subscriptions no longer return historical logs. If you want them - use `getLogsAsync` + * Subscriptions now use [ethereumjs-blockstream](https://github.com/ethereumjs/ethereumjs-blockstream) under the hood + * Subscriptions correctly handle block re-orgs (forks) + * Subscriptions correctly backfill logs (connection problems) + * They no longer setup filters on the underlying nodes, so you can use them with infura without a filter Subprovider + * Removed `ContractEventEmitter` and added `LogEvent` + * Renamed `zeroEx.token.subscribeAsync` to `zeroEx.token.subscribe` + * Added `zeroEx.token.unsubscribe` and `zeroEx.exchange.unsubscribe` + * Renamed `zeroEx.exchange.stopWatchingAllEventsAsync` to `zeroEx.exhange.unsubscribeAll` + * Renamed `zeroEx.token.stopWatchingAllEventsAsync` to `zeroEx.token.unsubscribeAll` + * Fixed the batch fills validation by emulating all balance & proxy allowance changes (#185) + +v0.20.0 - _October 5, 2017_ +------------------------ + * Add `zeroEx.token.getLogsAsync` (#178) + * Add `zeroEx.exchange.getLogsAsync` (#178) + * Fixed fees validation when one of the tokens transferred is ZRX (#181) + +v0.19.0 - _September 29, 2017_ +------------------------ + * Made order validation optional (#172) + * Added Ropsten testnet support (#173) + * Fixed a bug causing awaitTransactionMinedAsync to DDos backend nodes (#175) + +v0.18.0 - _September 26, 2017_ +------------------------ + * Added `zeroEx.exchange.validateOrderFillableOrThrowAsync` to simplify orderbook pruning (#170) + +v0.17.0 - _September 26, 2017_ +------------------------ + * Made `zeroEx.exchange.getZRXTokenAddressAsync` public (#171) + +v0.16.0 - _September 20, 2017_ +------------------------ + * Added the ability to specify custom contract addresses to be used with 0x.js (#165) + * ZeroExConfig.exchangeContractAddress + * ZeroExConfig.tokenRegistryContractAddress + * ZeroExConfig.etherTokenContractAddress + * Added `zeroEx.tokenRegistry.getContractAddressAsync` (#165) + +v0.15.0 - _September 8, 2017_ +------------------------ + * Added the ability to specify a historical `blockNumber` at which to query the blockchain's state when calling a token or exchange method (#161) + +v0.14.2 - _September 7, 2017_ +------------------------ + * Fixed an issue with bignumber.js types not found (#160) + +v0.14.1 - _September 7, 2017_ +------------------------ + * Fixed an issue with Artifact type not found (#159) + +v0.14.0 - _September 6, 2017_ +------------------------ + * Added `zeroEx.exchange.throwLogErrorsAsErrors` method to public interface (#157) + * Fixed an issue with overlapping async intervals in `zeroEx.awaitTransactionMinedAsync` (#157) + * Fixed an issue with log decoder returning `BigNumber`s as `strings` (#157) + +v0.13.0 - _September 6, 2017_ +------------------------ + * Made all the functions submitting transactions to the network to immediately return transaction hash (#151) + * Added `zeroEx.awaitTransactionMinedAsync` (#151) + * Added `TransactionReceiptWithDecodedLogs`, `LogWithDecodedArgs`, `DecodedLogArgs` to public types (#151) + * Added signature validation to `validateFillOrderThrowIfInvalidAsync` (#152) + +v0.12.1 - _September 2, 2017_ +------------------------ + * Added the support for web3@1.x.x provider (#142) + * Added the optional `zeroExConfig` parameter to the constructor of `ZeroEx` (#139) + * Added the ability to specify `gasPrice` when instantiating `ZeroEx` (#139) + +v0.11.0 - _August 24, 2017_ +------------------------ + * Added `zeroEx.token.setUnlimitedProxyAllowanceAsync` (#137) + * Added `zeroEx.token.setUnlimitedAllowanceAsync` (#137) + * Added `zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS` (#137) + +v0.10.4 - _Aug 24, 2017_ +------------------------ + * Fixed a bug where checksummed addresses were being pulled from artifacts and not lower-cased. (#135) + +v0.10.1 - _Aug 24, 2017_ +------------------------ + * Added `zeroEx.exchange.validateFillOrderThrowIfInvalidAsync` (#128) + * Added `zeroEx.exchange.validateFillOrKillOrderThrowIfInvalidAsync` (#128) + * Added `zeroEx.exchange.validateCancelOrderThrowIfInvalidAsync` (#128) + * Added `zeroEx.exchange.isRoundingErrorAsync` (#128) + * Added `zeroEx.proxy.getContractAddressAsync` (#130) + * Added `zeroEx.tokenRegistry.getTokenAddressesAsync` (#132) + * Added `zeroEx.tokenRegistry.getTokenAddressBySymbolIfExistsAsync` (#132) + * Added `zeroEx.tokenRegistry.getTokenAddressByNameIfExistsAsync` (#132) + * Added `zeroEx.tokenRegistry.getTokenBySymbolIfExistsAsync` (#132) + * Added `zeroEx.tokenRegistry.getTokenByNameIfExistsAsync` (#132) + * Added clear error message when checksummed address is passed to a public method (#124) + * Fixes the description of `shouldThrowOnInsufficientBalanceOrAllowance` in docs (#127) + +v0.9.3 - _Aug 22, 2017_ +------------------------ + * Update contract artifacts to include latest Kovan and Mainnet deploys (#118) + +v0.9.2 - _Aug 21, 2017_ +------------------------ + * *This version was unpublished because of a publishing issue.* + * Update contract artifacts to include latest Kovan and Mainnet deploys (#118) + +v0.9.1 - _Aug. 16, 2017_ +------------------------ + * Fixed the bug causing `zeroEx.token.getBalanceAsync()` to fail if no addresses available (#120) + +v0.9.0 - _Jul. 26, 2017_ +------------------------ + * Migrated to the new version of smart contracts (#101) + * Removed the ability to call methods on multiple authorized Exchange smart contracts (#106) + * Made `zeroEx.getOrderHashHex` a static method (#107) + * Cached `net_version` requests and invalidate the cache on calls to `setProvider` (#95) + * Renamed `zeroEx.exchange.batchCancelOrderAsync` to `zeroEx.exchange.batchCancelOrdersAsync` + * Renamed `zeroEx.exchange.batchFillOrderAsync` to `zeroEx.exchange.batchFillOrdersAsync` + * Updated to typescript v2.4 (#104) + * Fixed an issue with incorrect balance/allowance validation when ZRX is one of the tokens traded (#109) + +v0.8.0 - _Jul. 4, 2017_ +------------------------ + * Added the ability to call methods on different authorized versions of the Exchange smart contract (#82) + * Updated contract artifacts to reflect latest changes to the smart contracts (0xproject/contracts#59) + * Added `zeroEx.proxy.isAuthorizedAsync` and `zeroEx.proxy.getAuthorizedAddressesAsync` (#89) + * Added `zeroEx.token.subscribeAsync` (#90) + * Made contract invalidation functions private (#90) + * `zeroEx.token.invalidateContractInstancesAsync` + * `zeroEx.exchange.invalidateContractInstancesAsync` + * `zeroEx.proxy.invalidateContractInstance` + * `zeroEx.tokenRegistry.invalidateContractInstance` + * Fixed the bug where `zeroEx.setProviderAsync` didn't invalidate etherToken contract's instance + +v0.7.1 - _Jun. 26, 2017_ +------------------------ + * Added the ability to convert Ether to wrapped Ether tokens and back via `zeroEx.etherToken.depostAsync` and `zeroEx.etherToken.withdrawAsync` (#81) + +v0.7.0 - _Jun. 22, 2017_ +------------------------ + * Added Kovan smart contract artifacts (#78) + * Started returning fillAmount from `fillOrderAsync` and `fillUpToAsync` (#72) + * Started returning cancelledAmount from `cancelOrderAsync` (#72) + * Renamed type `LogCancelArgs` to `LogCancelContractEventArgs` and `LogFillArgs` to `LogFillContractEventArgs` + +v0.6.2 - _Jun. 21, 2017_ +------------------------ + * Reduced bundle size + * Improved documentation + +v0.6.1 - _Jun. 19, 2017_ +------------------------ + * Improved documentation + +v0.6.0 - _Jun. 19, 2017_ +------------------------ + * Made `ZeroEx` class accept `Web3Provider` instance instead of `Web3` instance + * Added types for contract event arguments + +v0.5.2 - _Jun. 15, 2017_ +------------------------ + * Fixed the bug in `postpublish` script that caused that only unminified UMD bundle was uploaded to release page + +v0.5.1 - _Jun. 15, 2017_ +------------------------ + * Added `postpublish` script to publish to Github Releases with assets. From 20862d47abded45567e7818813c49e95ef871fc8 Mon Sep 17 00:00:00 2001 From: Daniel Pyrathon Date: Fri, 3 May 2019 17:27:26 -0700 Subject: [PATCH 02/10] Added performedCallback attribute for Redux state, and added a hook for callback whenever the transaction was successful --- packages/instant/public/index.html | 3 +++ .../src/components/zero_ex_instant_provider.tsx | 15 ++++++++++++++- .../selected_asset_buy_order_state_buttons.ts | 2 +- packages/instant/src/redux/actions.ts | 2 +- packages/instant/src/redux/reducer.ts | 5 ++++- packages/instant/src/types.ts | 2 ++ 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/instant/public/index.html b/packages/instant/public/index.html index 2c4314fc27..f91809471f 100644 --- a/packages/instant/public/index.html +++ b/packages/instant/public/index.html @@ -203,6 +203,9 @@ onClose: () => { console.log('0x Instant Closed'); }, + onSuccess: (txHash) => { + console.log(`Success! Transaction hash is: ${txHash}`) + } }; const renderOptions = Object.assign({}, renderOptionsDefaults, removeUndefined(renderOptionsOverrides)); zeroExInstant.render(renderOptions); diff --git a/packages/instant/src/components/zero_ex_instant_provider.tsx b/packages/instant/src/components/zero_ex_instant_provider.tsx index aadd7c3a2e..0d9cfdcb08 100644 --- a/packages/instant/src/components/zero_ex_instant_provider.tsx +++ b/packages/instant/src/components/zero_ex_instant_provider.tsx @@ -10,7 +10,7 @@ import { asyncData } from '../redux/async_data'; import { DEFAULT_STATE, DefaultState, State } from '../redux/reducer'; import { store, Store } from '../redux/store'; import { fonts } from '../style/fonts'; -import { AccountState, Network, QuoteFetchOrigin, ZeroExInstantBaseConfig } from '../types'; +import { AccountState, Network, QuoteFetchOrigin, ZeroExInstantBaseConfig, OrderProcessState } from '../types'; import { analytics, disableAnalytics } from '../util/analytics'; import { assetUtils } from '../util/asset'; import { errorFlasher } from '../util/error_flasher'; @@ -19,6 +19,7 @@ import { gasPriceEstimator } from '../util/gas_price_estimator'; import { Heartbeater } from '../util/heartbeater'; import { generateAccountHeartbeater, generateBuyQuoteHeartbeater } from '../util/heartbeater_factory'; import { providerStateFactory } from '../util/provider_state_factory'; +import { ActionTypes, actions } from '../redux/actions'; export type ZeroExInstantProviderProps = ZeroExInstantBaseConfig; @@ -97,6 +98,18 @@ export class ZeroExInstantProvider extends React.PureComponent { + const currentState = this._store.getState(); + if ( + (currentState.buyOrderState.processState === OrderProcessState.Success) && + (currentState.buyOrderState.performedCallback === false) && + (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); diff --git a/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts b/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts index 4da99cf047..deb482bd14 100644 --- a/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts +++ b/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts @@ -83,7 +83,7 @@ const mapDispatchToProps = ( onBuyProcessing: (buyQuote: BuyQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => { dispatch(actions.setBuyOrderStateProcessing(txHash, startTimeUnix, expectedEndTimeUnix)); }, - onBuySuccess: (buyQuote: BuyQuote, txHash: string) => dispatch(actions.setBuyOrderStateSuccess(txHash)), + onBuySuccess: (buyQuote: BuyQuote, txHash: string) => dispatch(actions.setBuyOrderStateSuccess(txHash, false)), onBuyFailure: (buyQuote: BuyQuote, txHash: string) => dispatch(actions.setBuyOrderStateFailure(txHash)), onSignatureDenied: () => { dispatch(actions.resetAmount()); diff --git a/packages/instant/src/redux/actions.ts b/packages/instant/src/redux/actions.ts index 013527f752..86aacd3628 100644 --- a/packages/instant/src/redux/actions.ts +++ b/packages/instant/src/redux/actions.ts @@ -58,7 +58,7 @@ export const actions = { setBuyOrderStateProcessing: (txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => createAction(ActionTypes.SetBuyOrderStateProcessing, { txHash, startTimeUnix, expectedEndTimeUnix }), setBuyOrderStateFailure: (txHash: string) => createAction(ActionTypes.SetBuyOrderStateFailure, txHash), - setBuyOrderStateSuccess: (txHash: string) => createAction(ActionTypes.SetBuyOrderStateSuccess, txHash), + setBuyOrderStateSuccess: (txHash: string, performedCallback: boolean) => createAction(ActionTypes.SetBuyOrderStateSuccess, {txHash, performedCallback}), updateLatestBuyQuote: (buyQuote?: BuyQuote) => createAction(ActionTypes.UpdateLatestBuyQuote, buyQuote), updateSelectedAsset: (asset: Asset) => createAction(ActionTypes.UpdateSelectedAsset, asset), setAvailableAssets: (availableAssets: Asset[]) => createAction(ActionTypes.SetAvailableAssets, availableAssets), diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts index 86963c7917..19890d2158 100644 --- a/packages/instant/src/redux/reducer.ts +++ b/packages/instant/src/redux/reducer.ts @@ -157,6 +157,7 @@ export const createReducer = (initialState: State) => { buyOrderState: { processState: OrderProcessState.Processing, txHash: processingData.txHash, + performedCallback: false, progress: { startTimeUnix, expectedEndTimeUnix, @@ -171,6 +172,7 @@ export const createReducer = (initialState: State) => { return { ...state, buyOrderState: { + performedCallback: false, processState: OrderProcessState.Failure, txHash, progress, @@ -180,13 +182,14 @@ export const createReducer = (initialState: State) => { } return state; case ActionTypes.SetBuyOrderStateSuccess: - const successTxHash = action.data; + const successTxHash = action.data.txHash; if ('txHash' in state.buyOrderState) { if (state.buyOrderState.txHash === successTxHash) { const { txHash, progress } = state.buyOrderState; return { ...state, buyOrderState: { + performedCallback: action.data.performedCallback, processState: OrderProcessState.Success, txHash, progress, diff --git a/packages/instant/src/types.ts b/packages/instant/src/types.ts index 109ee44a5b..e058e22a06 100644 --- a/packages/instant/src/types.ts +++ b/packages/instant/src/types.ts @@ -43,6 +43,7 @@ interface OrderStatePostTx { processState: OrderProcessState.Processing | OrderProcessState.Success | OrderProcessState.Failure; txHash: string; progress: SimulatedProgress; + performedCallback: boolean } export type OrderState = OrderStatePreTx | OrderStatePostTx; @@ -201,6 +202,7 @@ export interface ZeroExInstantOptionalBaseConfig { networkId: Network; affiliateInfo: AffiliateInfo; shouldDisableAnalyticsTracking: boolean; + onSuccess?: (txHash: string) => void; } export type ZeroExInstantBaseConfig = ZeroExInstantRequiredBaseConfig & Partial; From f00a2dbc595808c184bdc1b579ff62511223c05a Mon Sep 17 00:00:00 2001 From: Daniel Pyrathon Date: Fri, 3 May 2019 18:05:40 -0700 Subject: [PATCH 03/10] added an unsubscribe handler --- .../instant/src/components/zero_ex_instant_provider.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/instant/src/components/zero_ex_instant_provider.tsx b/packages/instant/src/components/zero_ex_instant_provider.tsx index 0d9cfdcb08..2e3c383fca 100644 --- a/packages/instant/src/components/zero_ex_instant_provider.tsx +++ b/packages/instant/src/components/zero_ex_instant_provider.tsx @@ -20,6 +20,7 @@ import { Heartbeater } from '../util/heartbeater'; import { generateAccountHeartbeater, generateBuyQuoteHeartbeater } from '../util/heartbeater_factory'; import { providerStateFactory } from '../util/provider_state_factory'; import { ActionTypes, actions } from '../redux/actions'; +import { Unsubscribe } from 'redux'; export type ZeroExInstantProviderProps = ZeroExInstantBaseConfig; @@ -27,6 +28,7 @@ export class ZeroExInstantProvider extends React.PureComponent { + this._unsubscribeHandler = this._store.subscribe(() => { const currentState = this._store.getState(); if ( (currentState.buyOrderState.processState === OrderProcessState.Success) && @@ -165,6 +169,9 @@ export class ZeroExInstantProvider extends React.PureComponent Date: Fri, 3 May 2019 18:23:07 -0700 Subject: [PATCH 04/10] applied linting --- .../components/zero_ex_instant_provider.tsx | 18 +++++++++--------- packages/instant/src/types.ts | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/instant/src/components/zero_ex_instant_provider.tsx b/packages/instant/src/components/zero_ex_instant_provider.tsx index 2e3c383fca..a89b8cd3fb 100644 --- a/packages/instant/src/components/zero_ex_instant_provider.tsx +++ b/packages/instant/src/components/zero_ex_instant_provider.tsx @@ -3,14 +3,16 @@ import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; import * as React from 'react'; import { Provider as ReduxProvider } from 'react-redux'; +import { Unsubscribe } from 'redux'; import { ACCOUNT_UPDATE_INTERVAL_TIME_MS, BUY_QUOTE_UPDATE_INTERVAL_TIME_MS } from '../constants'; import { SelectedAssetThemeProvider } from '../containers/selected_asset_theme_provider'; +import { actions } from '../redux/actions'; import { asyncData } from '../redux/async_data'; import { DEFAULT_STATE, DefaultState, State } from '../redux/reducer'; import { store, Store } from '../redux/store'; import { fonts } from '../style/fonts'; -import { AccountState, Network, QuoteFetchOrigin, ZeroExInstantBaseConfig, OrderProcessState } from '../types'; +import { AccountState, Network, OrderProcessState, QuoteFetchOrigin, ZeroExInstantBaseConfig } from '../types'; import { analytics, disableAnalytics } from '../util/analytics'; import { assetUtils } from '../util/asset'; import { errorFlasher } from '../util/error_flasher'; @@ -19,8 +21,6 @@ import { gasPriceEstimator } from '../util/gas_price_estimator'; import { Heartbeater } from '../util/heartbeater'; import { generateAccountHeartbeater, generateBuyQuoteHeartbeater } from '../util/heartbeater_factory'; import { providerStateFactory } from '../util/provider_state_factory'; -import { ActionTypes, actions } from '../redux/actions'; -import { Unsubscribe } from 'redux'; export type ZeroExInstantProviderProps = ZeroExInstantBaseConfig; @@ -106,14 +106,14 @@ export class ZeroExInstantProvider extends React.PureComponent Date: Mon, 6 May 2019 12:57:20 -0700 Subject: [PATCH 05/10] added prettifying operations on CI --- .../instant/src/components/zero_ex_instant_provider.tsx | 8 +++----- packages/instant/src/redux/actions.ts | 3 ++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/instant/src/components/zero_ex_instant_provider.tsx b/packages/instant/src/components/zero_ex_instant_provider.tsx index a89b8cd3fb..7b949eb78a 100644 --- a/packages/instant/src/components/zero_ex_instant_provider.tsx +++ b/packages/instant/src/components/zero_ex_instant_provider.tsx @@ -97,17 +97,15 @@ export class ZeroExInstantProvider extends React.PureComponent { const currentState = this._store.getState(); if ( - (currentState.buyOrderState.processState === OrderProcessState.Success) && - (!currentState.buyOrderState.performedCallback) && - (this.props.onSuccess !== undefined) + currentState.buyOrderState.processState === OrderProcessState.Success && + !currentState.buyOrderState.performedCallback && + this.props.onSuccess !== undefined ) { const txHash = currentState.buyOrderState.txHash; this.props.onSuccess(txHash); diff --git a/packages/instant/src/redux/actions.ts b/packages/instant/src/redux/actions.ts index 86aacd3628..b003cc32c5 100644 --- a/packages/instant/src/redux/actions.ts +++ b/packages/instant/src/redux/actions.ts @@ -58,7 +58,8 @@ export const actions = { setBuyOrderStateProcessing: (txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => createAction(ActionTypes.SetBuyOrderStateProcessing, { txHash, startTimeUnix, expectedEndTimeUnix }), setBuyOrderStateFailure: (txHash: string) => createAction(ActionTypes.SetBuyOrderStateFailure, txHash), - setBuyOrderStateSuccess: (txHash: string, performedCallback: boolean) => createAction(ActionTypes.SetBuyOrderStateSuccess, {txHash, performedCallback}), + setBuyOrderStateSuccess: (txHash: string, performedCallback: boolean) => + createAction(ActionTypes.SetBuyOrderStateSuccess, { txHash, performedCallback }), updateLatestBuyQuote: (buyQuote?: BuyQuote) => createAction(ActionTypes.UpdateLatestBuyQuote, buyQuote), updateSelectedAsset: (asset: Asset) => createAction(ActionTypes.UpdateSelectedAsset, asset), setAvailableAssets: (availableAssets: Asset[]) => createAction(ActionTypes.SetAvailableAssets, availableAssets), From af755816590582ad136929c8d86441025e3dffea Mon Sep 17 00:00:00 2001 From: Daniel Pyrathon Date: Mon, 27 May 2019 18:30:29 -0700 Subject: [PATCH 06/10] removed legacy performedCallback system, and implemented new react-redux system --- .../components/zero_ex_instant_provider.tsx | 17 +------------ .../selected_asset_buy_order_state_buttons.ts | 25 ++++++++++++++++++- packages/instant/src/redux/reducer.ts | 2 +- packages/instant/src/types.ts | 1 - 4 files changed, 26 insertions(+), 19 deletions(-) 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; From dd97669cdd33147883802cbd5f7b8d08dafe58ff Mon Sep 17 00:00:00 2001 From: Daniel Pyrathon Date: Mon, 27 May 2019 18:34:23 -0700 Subject: [PATCH 07/10] removed other legacy code --- .../src/containers/selected_asset_buy_order_state_buttons.ts | 2 +- packages/instant/src/redux/actions.ts | 3 +-- packages/instant/src/redux/reducer.ts | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts b/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts index 0a85e358ee..9cdbfc6355 100644 --- a/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts +++ b/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts @@ -85,7 +85,7 @@ const mapDispatchToProps = ( onBuyProcessing: (buyQuote: BuyQuote, txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => { dispatch(actions.setBuyOrderStateProcessing(txHash, startTimeUnix, expectedEndTimeUnix)); }, - onBuySuccess: (buyQuote: BuyQuote, txHash: string) => dispatch(actions.setBuyOrderStateSuccess(txHash, false)), + onBuySuccess: (buyQuote: BuyQuote, txHash: string) => dispatch(actions.setBuyOrderStateSuccess(txHash)), onBuyFailure: (buyQuote: BuyQuote, txHash: string) => dispatch(actions.setBuyOrderStateFailure(txHash)), onSignatureDenied: () => { dispatch(actions.resetAmount()); diff --git a/packages/instant/src/redux/actions.ts b/packages/instant/src/redux/actions.ts index b003cc32c5..013527f752 100644 --- a/packages/instant/src/redux/actions.ts +++ b/packages/instant/src/redux/actions.ts @@ -58,8 +58,7 @@ export const actions = { setBuyOrderStateProcessing: (txHash: string, startTimeUnix: number, expectedEndTimeUnix: number) => createAction(ActionTypes.SetBuyOrderStateProcessing, { txHash, startTimeUnix, expectedEndTimeUnix }), setBuyOrderStateFailure: (txHash: string) => createAction(ActionTypes.SetBuyOrderStateFailure, txHash), - setBuyOrderStateSuccess: (txHash: string, performedCallback: boolean) => - createAction(ActionTypes.SetBuyOrderStateSuccess, { txHash, performedCallback }), + setBuyOrderStateSuccess: (txHash: string) => createAction(ActionTypes.SetBuyOrderStateSuccess, txHash), updateLatestBuyQuote: (buyQuote?: BuyQuote) => createAction(ActionTypes.UpdateLatestBuyQuote, buyQuote), updateSelectedAsset: (asset: Asset) => createAction(ActionTypes.UpdateSelectedAsset, asset), setAvailableAssets: (availableAssets: Asset[]) => createAction(ActionTypes.SetAvailableAssets, availableAssets), diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts index e7f161bfa7..7da743e4b5 100644 --- a/packages/instant/src/redux/reducer.ts +++ b/packages/instant/src/redux/reducer.ts @@ -182,14 +182,13 @@ export const createReducer = (initialState: State) => { } return state; case ActionTypes.SetBuyOrderStateSuccess: - const successTxHash = action.data.txHash; + const successTxHash = action.data; if ('txHash' in state.buyOrderState) { if (state.buyOrderState.txHash === successTxHash) { const { txHash, progress } = state.buyOrderState; return { ...state, buyOrderState: { - performedCallback: action.data.performedCallback, processState: OrderProcessState.Success, txHash, progress, From 5e41168305655684be5a924156e6a56605062ddd Mon Sep 17 00:00:00 2001 From: Daniel Pyrathon Date: Mon, 27 May 2019 18:35:47 -0700 Subject: [PATCH 08/10] removed final bit of performedCallback --- packages/instant/src/redux/reducer.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/instant/src/redux/reducer.ts b/packages/instant/src/redux/reducer.ts index 7da743e4b5..fd57ba322c 100644 --- a/packages/instant/src/redux/reducer.ts +++ b/packages/instant/src/redux/reducer.ts @@ -172,7 +172,6 @@ export const createReducer = (initialState: State) => { return { ...state, buyOrderState: { - performedCallback: false, processState: OrderProcessState.Failure, txHash, progress, From 344d28ab78b16f91588526478f68c33f611c9b4d Mon Sep 17 00:00:00 2001 From: Daniel Pyrathon Date: Mon, 27 May 2019 18:45:08 -0700 Subject: [PATCH 09/10] added prettier --- packages/instant/src/components/zero_ex_instant_provider.tsx | 4 +--- .../src/containers/selected_asset_buy_order_state_buttons.ts | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/instant/src/components/zero_ex_instant_provider.tsx b/packages/instant/src/components/zero_ex_instant_provider.tsx index 8babae306b..c95cddbafc 100644 --- a/packages/instant/src/components/zero_ex_instant_provider.tsx +++ b/packages/instant/src/components/zero_ex_instant_provider.tsx @@ -3,16 +3,14 @@ import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; import * as React from 'react'; import { Provider as ReduxProvider } from 'react-redux'; -import { Unsubscribe } from 'redux'; import { ACCOUNT_UPDATE_INTERVAL_TIME_MS, BUY_QUOTE_UPDATE_INTERVAL_TIME_MS } from '../constants'; import { SelectedAssetThemeProvider } from '../containers/selected_asset_theme_provider'; -import { actions } from '../redux/actions'; import { asyncData } from '../redux/async_data'; import { DEFAULT_STATE, DefaultState, State } from '../redux/reducer'; import { store, Store } from '../redux/store'; import { fonts } from '../style/fonts'; -import { AccountState, Network, OrderProcessState, QuoteFetchOrigin, ZeroExInstantBaseConfig } from '../types'; +import { AccountState, Network, QuoteFetchOrigin, ZeroExInstantBaseConfig } from '../types'; import { analytics, disableAnalytics } from '../util/analytics'; import { assetUtils } from '../util/asset'; import { errorFlasher } from '../util/error_flasher'; diff --git a/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts b/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts index 9cdbfc6355..69c9bc0287 100644 --- a/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts +++ b/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts @@ -2,7 +2,6 @@ import { AssetBuyer, AssetBuyerError, BuyQuote } from '@0x/asset-buyer'; import { BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; import * as _ from 'lodash'; -import * as React from 'react'; import { connect } from 'react-redux'; import { Dispatch } from 'redux'; @@ -109,7 +108,6 @@ const mapDispatchToProps = ( }, }); - const mergeProps = ( connectedState: ConnectedState, connectedDispatch: ConnectedDispatch, @@ -125,7 +123,7 @@ const mergeProps = ( connectedState.onSuccess(txHash); } }, - } + }; }; From 1bcb2697e78facd5a0b1e5c2ca0c6606121b922f Mon Sep 17 00:00:00 2001 From: Daniel Pyrathon Date: Mon, 27 May 2019 19:16:11 -0700 Subject: [PATCH 10/10] added prettifier --- .../selected_asset_buy_order_state_buttons.ts | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts b/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts index 69c9bc0287..433f6cc30c 100644 --- a/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts +++ b/packages/instant/src/containers/selected_asset_buy_order_state_buttons.ts @@ -109,22 +109,21 @@ const mapDispatchToProps = ( }); const mergeProps = ( - connectedState: ConnectedState, - connectedDispatch: ConnectedDispatch, - ownProps: SelectedAssetBuyOrderStateButtons, + 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); - } - }, + return { + ...ownProps, + ...connectedState, + ...connectedDispatch, + onBuySuccess: (buyQuote: BuyQuote, txHash: string) => { + connectedDispatch.onBuySuccess(buyQuote, txHash); + if (connectedState.onSuccess) { + connectedState.onSuccess(txHash); + } + }, }; - }; export const SelectedAssetBuyOrderStateButtons = connect(