Skip to content

Commit

Permalink
refactored setting braze user
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnathanWhite committed Oct 25, 2021
1 parent 1cab638 commit 9f7ecd6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ import { sleep } from '../utils';
(window as any).handleOpenURL_LastURL = url;
};

declare var AppboyPlugin: any;

@Component({
templateUrl: 'app.html',
providers: [TouchIdProvider]
Expand Down Expand Up @@ -470,8 +468,11 @@ export class CopayApp {
const user = await this.persistenceProvider.getBitPayIdUserInfo(
Network[this.NETWORK]
);
if (user && user.email) {
AppboyPlugin.setEmail(user.email);
const brazeUserSet = await this.persistenceProvider.getBrazeUserSet(
Network[this.NETWORK]
);
if (user && !brazeUserSet) {
this.bitpayIdProvider.setBrazeUser(user);
}
}

Expand Down
19 changes: 15 additions & 4 deletions src/providers/bitpay-id/bitpay-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@ export class BitPayIdProvider {
incentiveLevelId
} = data;

if (email) {
AppboyPlugin.setEmail(email);
}

if (experiments && experiments.includes('NADebitCard')) {
this.persistenceProvider.setCardExperimentFlag('enabled');
this.events.publish('experimentUpdateStart');
Expand All @@ -154,6 +150,7 @@ export class BitPayIdProvider {
network,
token.data
),
this.setBrazeUser(user),
this.persistenceProvider.setBitPayIdUserInfo(network, data),
this.persistenceProvider.setBitpayAccount(network, {
email,
Expand Down Expand Up @@ -220,6 +217,20 @@ export class BitPayIdProvider {
await this.persistenceProvider.setBitPayIdUserInfo(network, userInfo);
}

public async setBrazeUser(user: User) {
const {
data: { email, eid }
} = user;

AppboyPlugin.changeUser(eid);
AppboyPlugin.setEmail(email);

await this.persistenceProvider.setBrazeUser(
Network[this.getEnvironment().network]
);
this.logger.debug('Braze: user set');
}

public async unlockInvoice(invoiceId: string): Promise<string> {
const isPaired = !!(await this.persistenceProvider.getBitPayIdPairingToken(
Network[this.NETWORK]
Expand Down
11 changes: 10 additions & 1 deletion src/providers/persistence/persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ const Keys = {
BITPAY_CARD_ORDER_STARTED: `bitPayCardOrderStarted`,
BITPAY_SURVEY_CARD_DISMISSED: `bitPaySurveyCardDismissed`,
ACCEPTED_SWAP_CRYPTO_DISCLAIMER: 'acceptedSwapCryptoDisclaimer',
CUSTOM_VIRTUAL_CARD_DESIGN: `customVirtualCardDesign`
CUSTOM_VIRTUAL_CARD_DESIGN: `customVirtualCardDesign`,
BRAZE_USER_SET: network => `brazeUserSet-${network}`
};

interface Storage {
Expand Down Expand Up @@ -1133,6 +1134,14 @@ export class PersistenceProvider {
setCustomVirtualCardDesign(currency) {
return this.storage.set(Keys.CUSTOM_VIRTUAL_CARD_DESIGN, currency);
}

getBrazeUserSet(network: Network) {
return this.storage.get(Keys.BRAZE_USER_SET(network));
}

setBrazeUser(network: Network) {
return this.storage.set(Keys.BRAZE_USER_SET(network), true);
}
}

function getLegacyGiftCardKey(cardName: string, network: Network) {
Expand Down

0 comments on commit 9f7ecd6

Please sign in to comment.