aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-17 07:25:29 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-17 07:25:29 +0800
commit4d7bd15334f909765749fea1c67ad26b161d6025 (patch)
treef1e73bbaf3bb6a09347322b3a80621596dd513ab
parent31ffa65f59fc6d2c6c7f79c1ac0e2abe0c5ed4ab (diff)
downloaddexon-sol-tools-4d7bd15334f909765749fea1c67ad26b161d6025.tar.gz
dexon-sol-tools-4d7bd15334f909765749fea1c67ad26b161d6025.tar.zst
dexon-sol-tools-4d7bd15334f909765749fea1c67ad26b161d6025.zip
Trigger Wallet Ready when address changed
-rw-r--r--packages/instant/src/redux/analytics_middleware.ts18
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();