Skip to content

Commit

Permalink
Merge pull request #536 from cnguyen812/feat/pass-appsflyerid-to-bitpay
Browse files Browse the repository at this point in the history
Feat/pass appsflyerid to bitpay
  • Loading branch information
JohnathanWhite authored Nov 9, 2022
2 parents f928b6a + cac5f06 commit d7daa6d
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 15 deletions.
62 changes: 58 additions & 4 deletions src/api/card/card.mutations.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {IS_ANDROID, IS_IOS} from '../../constants';
import {
AppleWalletProvisioningRequestParams,
StartActivateCardParams,
Expand All @@ -19,6 +20,22 @@ type ActivateCardInputType = {
lastFourDigits: string | undefined;
};

type AnalyticsContextInputType =
| {
device?: {
type?: 'ios' | 'android';
};
}
| undefined;

type AnalyticsIntegrationsInputType =
| {
AppsFlyer?: {
appsFlyerId?: string;
};
}
| undefined;

type GoogleProvisioningInputType = {
walletProvider: 'google';
};
Expand Down Expand Up @@ -76,14 +93,49 @@ export const LOCK_CARD = (
export const ACTIVATE_CARD = (
token: string,
id: string,
{cvv, expirationDate, cardNumber, lastFourDigits}: StartActivateCardParams,
): GqlQueryParams<ActivateCardInputType> => {
{
cvv,
expirationDate,
cardNumber,
lastFourDigits,
appsFlyerId,
}: StartActivateCardParams,
): GqlQueryParams<
| ActivateCardInputType
| AnalyticsContextInputType
| AnalyticsIntegrationsInputType
> => {
let context: AnalyticsContextInputType;
let integrations: AnalyticsIntegrationsInputType;

if (IS_ANDROID) {
context = {
device: {
type: 'android',
},
};
} else if (IS_IOS) {
context = {
device: {
type: 'ios',
},
};
}

if (appsFlyerId) {
integrations = {
AppsFlyer: {
appsFlyerId,
},
};
}

return {
query: `
mutation ACTIVATE_CARD($token:String!, $csrf:String, $cardId:String!, $input:ActivateCardInputType!) {
mutation ACTIVATE_CARD($token:String!, $csrf:String, $cardId:String!, $input:ActivateCardInputType!, $context:AnalyticsContextInputType, $integrations:AnalyticsIntegrationsInputType) {
user:bitpayUser(token:$token, csrf:$csrf) {
card:debitCard(cardId:$cardId) {
activationDate:activateCard(input:$input)
activationDate:activateCard(input:$input, context:$context, integrations:$integrations)
}
}
}
Expand All @@ -97,6 +149,8 @@ export const ACTIVATE_CARD = (
expirationDate,
lastFourDigits,
},
context,
integrations,
},
};
};
Expand Down
12 changes: 6 additions & 6 deletions src/api/card/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import {
AppleWalletProvisioningRequestParams,
StartActivateCardParams,
} from '../../store/card/card.effects';
import GraphQlApi from '../graphql';
import CardMutations from './card.mutations';
import CardQueries from './card.queries';
import {
ActivateCardResponse,
FetchAllCardsResponse,
Expand All @@ -12,12 +18,6 @@ import {
UpdateCardLockResponse,
UpdateCardNameResponse,
} from './card.types';
import CardQueries from './card.queries';
import CardMutations from './card.mutations';
import {
AppleWalletProvisioningRequestParams,
StartActivateCardParams,
} from '../../store/card/card.effects';

const fetchAll = async (token: string) => {
const query = CardQueries.FETCH_CARDS(token);
Expand Down
13 changes: 8 additions & 5 deletions src/navigation/card/components/CardIntro.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {useScrollToTop} from '@react-navigation/native';
import {StackNavigationProp} from '@react-navigation/stack';
import React, {useLayoutEffect, useRef} from 'react';
import {useTranslation} from 'react-i18next';
Expand All @@ -24,11 +25,11 @@ import {Network, URL} from '../../../constants';
import {BASE_BITPAY_URLS} from '../../../constants/config';
import {RootState} from '../../../store';
import {AppEffects} from '../../../store/app';
import {getAppsFlyerId} from '../../../utils/appsFlyer';
import {CardStackParamList} from '../CardStack';
import CardFeatureTabs from './CardIntroFeatureTabs';
import CardIntroHeroImg from './CardIntroHeroImage';
import CardHighlights from './CardIntroHighlights';
import {useScrollToTop} from '@react-navigation/native';

interface CardIntroProps {
navigation: StackNavigationProp<CardStackParamList, 'CardHome'>;
Expand Down Expand Up @@ -77,13 +78,15 @@ const CardIntro: React.FC<CardIntroProps> = props => {
const network = useSelector<RootState, Network>(({APP}) => APP.network);
const insets = useSafeAreaInsets();

const onGetCardPress = async (context?: 'login' | 'createAccount') => {
const onGetCardPress = async (context: 'login' | 'createAccount') => {
const baseUrl = BASE_BITPAY_URLS[network];
const path = 'wallet-card';
let url = `${baseUrl}/${path}`;
const afid = await getAppsFlyerId();

let url = `${baseUrl}/${path}?context=${context}`;

if (context) {
url += `?context=${context}`;
if (afid) {
url += `&afid=${afid}`;
}

dispatch(AppEffects.openUrlWithInAppBrowser(url));
Expand Down
8 changes: 8 additions & 0 deletions src/store/card/card.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {BASE_BITPAY_URLS} from '../../constants/config';
import ApplePushProvisioningModule from '../../lib/apple-push-provisioning/ApplePushProvisioning';
import {GeneralError} from '../../navigation/wallet/components/ErrorMessages';
import GooglePushProvisioningModule from '../../lib/google-push-provisioning/GooglePushProvisioning';
import {getAppsFlyerId} from '../../utils/appsFlyer';

const DoshWhitelist: string[] = [];

Expand All @@ -40,6 +41,7 @@ export interface StartActivateCardParams {
expirationDate: string;
lastFourDigits?: string;
cardNumber?: string;
appsFlyerId?: string;
}

export interface AppleWalletProvisioningRequestParams {
Expand Down Expand Up @@ -359,6 +361,12 @@ export const startActivateCard =
const {APP, BITPAY_ID} = getState();
const {network} = APP;
const token = BITPAY_ID.apiToken[network];
const appsFlyerId = await getAppsFlyerId();

payload = {
...payload,
appsFlyerId,
};

const {data, errors} = await CardApi.activateCard(token, id, payload);

Expand Down
14 changes: 14 additions & 0 deletions src/utils/appsFlyer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import AppsFlyer from 'react-native-appsflyer';

/**
* Promisifies the AppsFlyer SDK getAppsFlyerUID method.
*
* @returns AppsFlyer ID
*/
export const getAppsFlyerId = () => {
return new Promise<string | undefined>(resolve =>
AppsFlyer.getAppsFlyerUID((err, id) => {
resolve(err ? undefined : id);
}),
);
};

0 comments on commit d7daa6d

Please sign in to comment.