diff options
author | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-11-17 07:25:29 +0800 |
---|---|---|
committer | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-11-17 07:25:29 +0800 |
commit | 4d7bd15334f909765749fea1c67ad26b161d6025 (patch) | |
tree | f1e73bbaf3bb6a09347322b3a80621596dd513ab /packages/instant | |
parent | 31ffa65f59fc6d2c6c7f79c1ac0e2abe0c5ed4ab (diff) | |
download | dexon-sol-tools-4d7bd15334f909765749fea1c67ad26b161d6025.tar dexon-sol-tools-4d7bd15334f909765749fea1c67ad26b161d6025.tar.gz dexon-sol-tools-4d7bd15334f909765749fea1c67ad26b161d6025.tar.bz2 dexon-sol-tools-4d7bd15334f909765749fea1c67ad26b161d6025.tar.lz dexon-sol-tools-4d7bd15334f909765749fea1c67ad26b161d6025.tar.xz dexon-sol-tools-4d7bd15334f909765749fea1c67ad26b161d6025.tar.zst dexon-sol-tools-4d7bd15334f909765749fea1c67ad26b161d6025.zip |
Trigger Wallet Ready when address changed
Diffstat (limited to 'packages/instant')
-rw-r--r-- | packages/instant/src/redux/analytics_middleware.ts | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/packages/instant/src/redux/analytics_middleware.ts b/packages/instant/src/redux/analytics_middleware.ts index 7fbb12cb9..a86cf1b83 100644 --- a/packages/instant/src/redux/analytics_middleware.ts +++ b/packages/instant/src/redux/analytics_middleware.ts @@ -3,13 +3,27 @@ import * as _ from 'lodash'; import { Middleware } from 'redux'; import { ETH_DECIMALS } from '../constants'; -import { AccountState } from '../types'; +import { Account, AccountState } from '../types'; import { analytics } from '../util/analytics'; import { Action, ActionTypes } from './actions'; import { State } from './reducer'; +const shouldTriggerWalletReady = (prevAccount: Account, curAccount: Account): boolean => { + const justTurnedReady = curAccount.state === AccountState.Ready && prevAccount.state !== AccountState.Ready; + if (justTurnedReady) { + return true; + } + + if (curAccount.state === AccountState.Ready && prevAccount.state === AccountState.Ready) { + // Account was ready, and is now ready again, but address has changed + return curAccount.address !== prevAccount.address; + } + + return false; +}; + export const analyticsMiddleware: Middleware = store => next => middlewareAction => { const prevState = store.getState() as State; const prevAccount = prevState.providerState.account; @@ -21,7 +35,7 @@ export const analyticsMiddleware: Middleware = store => next => middlewareAction switch (nextAction.type) { case ActionTypes.SET_ACCOUNT_STATE_READY: - if (curAccount.state === AccountState.Ready && prevAccount.state !== AccountState.Ready) { + if (curAccount.state === AccountState.Ready && shouldTriggerWalletReady(prevAccount, curAccount)) { const ethAddress = curAccount.address; analytics.addUserProperties({ ethAddress }); analytics.trackWalletReady(); |