Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NC-4885: Update NamiCampaignManager.launch #315

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 4 additions & 36 deletions examples/Basic/containers/CampaignScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
NamiPaywallManager,
NamiPaywallAction,
NamiCampaignRuleType,
NamiPaywallEvent,
} from 'react-native-nami-sdk';
import {
FlatList,
Expand Down Expand Up @@ -165,43 +166,10 @@
console.log('error', error);

checkIfPaywallOpen();

},
(
action,
campaignId,
paywallId,
campaignName,
campaignType,
campaignLabel,
campaignUrl,
paywallName,
segmentId,
externalSegmentId,
deeplinkUrl,
skuId,
componentChangeId,
componentChangeName,
purchaseError,
purchases,
) => {
console.log('action', action);
setAction(action);
console.log('campaignId', campaignId);
console.log('paywallId', paywallId);
console.log('campaignName', campaignName);
console.log('campaignType', campaignType);
console.log('campaignLabel', campaignLabel);
console.log('campaignUrl', campaignUrl);
console.log('paywallName', paywallName);
console.log('segmentId', segmentId);
console.log('externalSegmentId', externalSegmentId);
console.log('deeplinkUrl', deeplinkUrl);
console.log('skuId', skuId);
console.log('componentChangeId', componentChangeId);
console.log('componentChangeName', componentChangeName);
console.log('purchaseError', purchaseError);
console.log('purchases', purchases);
(event: NamiPaywallEvent) => {
console.log('event', event);
setAction(event.action);
},
);
};
Expand All @@ -222,9 +190,9 @@
? triggerLaunch(item.value, null)
: triggerLaunch(null, item.value);
}
}, []);

Check warning on line 193 in examples/Basic/containers/CampaignScreen.tsx

View workflow job for this annotation

GitHub Actions / ESLint

React Hook useCallback has a missing dependency: 'triggerLaunch'. Either include it or remove the dependency array

const onItemPressDefault = useCallback(() => triggerLaunch(null, null), []);

Check warning on line 195 in examples/Basic/containers/CampaignScreen.tsx

View workflow job for this annotation

GitHub Actions / ESLint

React Hook useCallback has a missing dependency: 'triggerLaunch'. Either include it or remove the dependency array

const onRefreshPress = useCallback(() => {
getAllCampaigns();
Expand Down
34 changes: 3 additions & 31 deletions examples/Basic/services/deeplinking.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NamiCampaignManager } from 'react-native-nami-sdk';
import { NamiCampaignManager, NamiPaywallEvent } from 'react-native-nami-sdk';

interface HandleDeepLinkParams {
url: string;
Expand All @@ -22,36 +22,8 @@ export async function handleDeepLink(params: HandleDeepLinkParams) {
(success, error) => {
console.log(success, error);
},
(
action,
campaignId,
paywallId,
campaignLabel,
campaignName,
campaignType,
campaignUrl,
segmentId,
externalSegmentId,
paywallName,
deeplinkUrl,
skuId,
purchaseError,
purchases,
) => {
console.log('action', action);
console.log('campaignId', campaignId);
console.log('paywallId', paywallId);
console.log('campaignLabel', campaignLabel);
console.log('campaignName', campaignName);
console.log('campaignType', campaignType);
console.log('campaignUrl', campaignUrl);
console.log('paywallName', paywallName);
console.log('segmentId', segmentId);
console.log('externalSegmentId', externalSegmentId);
console.log('deeplinkUrl', deeplinkUrl);
console.log('skuId', skuId);
console.log('purchaseError', purchaseError);
console.log('purchases', purchases);
(event: NamiPaywallEvent) => {
console.log('event', event);
},
);
}
Expand Down
34 changes: 3 additions & 31 deletions examples/TestNamiTV/containers/CampaignScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Text,
TouchableOpacity,
} from 'react-native';
import { NamiCampaignManager, NamiCampaign, NamiCampaignRuleType } from 'react-native-nami-sdk';
import { NamiCampaignManager, NamiCampaign, NamiCampaignRuleType, NamiPaywallEvent } from 'react-native-nami-sdk';
import { ViewerTabProps } from '../App';
import theme from '../theme';
import { SafeAreaView } from 'react-native-safe-area-context';
Expand Down Expand Up @@ -65,36 +65,8 @@ const CampaignScreen: FC<CampaignScreenProps> = ({ navigation }) => {
console.log('successAction', successAction);
console.log('error', error);
},
(
action,
campaignId,
paywallId,
campaignName,
campaignType,
campaignLabel,
campaignUrl,
paywallName,
segmentId,
externalSegmentId,
deeplinkUrl,
skuId,
purchaseError,
purchases,
) => {
console.log('action', action);
console.log('campaignId', campaignId);
console.log('paywallId', paywallId);
console.log('campaignLabel', campaignLabel);
console.log('campaignName', campaignName);
console.log('campaignType', campaignType);
console.log('campaignUrl', campaignUrl);
console.log('paywallName', paywallName);
console.log('segmentId', segmentId);
console.log('externalSegmentId', externalSegmentId);
console.log('deeplinkUrl', deeplinkUrl);
console.log('skuId', skuId);
console.log('purchaseError', purchaseError);
console.log('purchases', purchases);
(event: NamiPaywallEvent) => {
console.log('event', event);
},
);
};
Expand Down
34 changes: 3 additions & 31 deletions examples/TestNamiTV/services/deeplinking.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NamiCampaignManager } from 'react-native-nami-sdk';
import { NamiCampaignManager, NamiPaywallEvent } from 'react-native-nami-sdk';

interface HandleDeepLinkParams {
url: string;
Expand All @@ -22,36 +22,8 @@ export async function handleDeepLink(params: HandleDeepLinkParams) {
(success, error) => {
console.log(success, error);
},
(
action,
campaignId,
paywallId,
campaignLabel,
campaignName,
campaignType,
campaignUrl,
segmentId,
externalSegmentId,
paywallName,
deeplinkUrl,
skuId,
purchaseError,
purchases,
) => {
console.log('action', action);
console.log('campaignId', campaignId);
console.log('paywallId', paywallId);
console.log('campaignLabel', campaignLabel);
console.log('campaignName', campaignName);
console.log('campaignType', campaignType);
console.log('campaignUrl', campaignUrl);
console.log('paywallName', paywallName);
console.log('segmentId', segmentId);
console.log('externalSegmentId', externalSegmentId);
console.log('deeplinkUrl', deeplinkUrl);
console.log('skuId', skuId);
console.log('purchaseError', purchaseError);
console.log('purchases', purchases);
(event: NamiPaywallEvent) => {
console.log('event', event);
},
);
}
Expand Down
81 changes: 23 additions & 58 deletions src/NamiCampaignManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
import {
LaunchCampaignError,
NamiCampaign,
NamiPaywallAction,
NamiPurchase,
NamiPaywallActionHandler,
NamiPaywallEvent,
PaywallLaunchContext,
} from './types';

Expand All @@ -30,24 +30,7 @@ interface ICampaignManager {
withUrl?: string,
context?: PaywallLaunchContext,
resultCallback?: (success: boolean, error?: LaunchCampaignError) => void,
actionCallback?: (
action: NamiPaywallAction,
campaignId: string,
paywallId: string,
campaignName?: string,
campaignType?: string,
campaignLabel?: string,
campaignUrl?: string,
paywallName?: string,
segmentId?: string,
externalSegmentId?: string,
deeplinkUrl?: string,
skuId?: string,
componentChangeId?: string,
componentChangeName?: string,
purchaseError?: string,
purchases?: NamiPurchase[],
) => void,
actionCallback?: NamiPaywallActionHandler,
) => void;
refresh: () => void;
registerAvailableCampaignsHandler: (
Expand All @@ -71,52 +54,34 @@ export const NamiCampaignManager: ICampaignManager = {
? body.action.substring(5, body.action.length)
: body.action;

const {
action,
campaignId,
paywallId,
campaignName,
campaignType,
campaignLabel,
campaignUrl,
paywallName,
segmentId,
externalSegmentId,
deeplinkUrl,
skuId,
componentChangeId,
componentChangeName,
purchaseError,
purchases,
} = body;
if (actionCallback) {
actionCallback(
action,
campaignId,
paywallId,
campaignName,
campaignType,
campaignLabel,
campaignUrl,
paywallName,
segmentId,
externalSegmentId,
deeplinkUrl,
skuId,
componentChangeId,
componentChangeName,
purchaseError,
purchases,
);
const paywallEvent: NamiPaywallEvent = {
action: body.action,
campaignId: body.campaignId,
campaignName: body.campaignName,
campaignType: body.campaignType,
campaignLabel: body.campaignLabel,
campaignUrl: body.campaignUrl,
paywallId: body.paywallId,
paywallName: body.paywallName,
componentChange: body.componentChange,
segmentId: body.segmentId,
externalSegmentId: body.externalSegmentId,
deeplinkUrl: body.deeplinkUrl,
sku: body.sku,
purchaseError: body.purchaseError,
purchases: body.purchases,
}
actionCallback(paywallEvent)
}
},
);
RNNamiCampaignManager.launch(
label ?? null,
withUrl ?? null,
context ?? null,
resultCallback ?? (() => {}),
actionCallback ?? (() => {}),
resultCallback ?? (() => { }),
actionCallback ?? (() => { }),
);
},

Expand Down
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ export type NamiPaywallEvent = {
sku?: NamiSKU;
purchaseError?: string;
purchases?: NamiPurchase[];
};
}

export type NamiPaywallActionHandler = (event: NamiPaywallEvent) => void;

export type NamiPaywallComponentChange = {
id?: string;
Expand Down
Loading