diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 696ae85ea36..a65fccba968 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -87,8 +87,6 @@ import { sleep } from '../utils'; (window as any).handleOpenURL_LastURL = url; }; -declare var AppboyPlugin: any; - @Component({ templateUrl: 'app.html', providers: [TouchIdProvider] @@ -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); } } diff --git a/src/providers/bitpay-id/bitpay-id.ts b/src/providers/bitpay-id/bitpay-id.ts index bd063a41249..1227a6fc2f9 100644 --- a/src/providers/bitpay-id/bitpay-id.ts +++ b/src/providers/bitpay-id/bitpay-id.ts @@ -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'); @@ -154,6 +150,7 @@ export class BitPayIdProvider { network, token.data ), + this.setBrazeUser(user), this.persistenceProvider.setBitPayIdUserInfo(network, data), this.persistenceProvider.setBitpayAccount(network, { email, @@ -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 { const isPaired = !!(await this.persistenceProvider.getBitPayIdPairingToken( Network[this.NETWORK] diff --git a/src/providers/persistence/persistence.ts b/src/providers/persistence/persistence.ts index a39b588bd0f..80ca019d0d6 100644 --- a/src/providers/persistence/persistence.ts +++ b/src/providers/persistence/persistence.ts @@ -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 { @@ -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) {