Skip to content

Commit

Permalink
NC-4886 Update NamiCampaignManager.refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sumi-k committed Jun 21, 2024
1 parent 4637061 commit 1527811
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,14 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
}

@ReactMethod
fun refresh() {
NamiCampaignManager.refresh() { }
fun refresh(promise: Promise) {
NamiCampaignManager.refresh { campaigns
val array = WritableNativeArray()
campaigns.forEach { campaign ->
array.pushMap(campaignToReadableMap(campaign))
}
promise.resolve(array)
}
}

@ReactMethod
Expand Down
5 changes: 4 additions & 1 deletion examples/Basic/containers/CampaignScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ const CampaignScreen: FC<CampaignScreenProps> = ({ navigation }) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const triggerLaunch = (label?: any, url?: any) => {
const triggerLaunch = async (label?: any, url?: any) => {
checkIfPaywallOpen();

const camps = await NamiCampaignManager.refresh()
console.log('NamiSDK: refresh campaigns', camps);

return NamiCampaignManager.launch(
label,
url,
Expand Down
2 changes: 1 addition & 1 deletion src/NamiCampaignManager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface ICampaignManager {
allCampaigns: () => Promise<Array<NamiCampaign>>;
isCampaignAvailable(campaignSource: string | null): Promise<boolean>;
launch: (label?: string, 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) => void;
refresh: () => void;
refresh: () => Promise<Array<NamiCampaign>>;
registerAvailableCampaignsHandler: (callback: (availableCampaigns: NamiCampaign[]) => void) => EmitterSubscription['remove'];
}
export declare const NamiCampaignManager: ICampaignManager;
Expand Down
10 changes: 7 additions & 3 deletions src/NamiCampaignManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interface ICampaignManager {
purchases?: NamiPurchase[],
) => void,
) => void;
refresh: () => void;
refresh: () => Promise<Array<NamiCampaign>>;
registerAvailableCampaignsHandler: (
callback: (availableCampaigns: NamiCampaign[]) => void,
) => EmitterSubscription['remove'];
Expand Down Expand Up @@ -115,8 +115,8 @@ export const NamiCampaignManager: ICampaignManager = {
label ?? null,
withUrl ?? null,
context ?? null,
resultCallback ?? (() => {}),
actionCallback ?? (() => {}),
resultCallback ?? (() => { }),
actionCallback ?? (() => { }),
);
},

Expand All @@ -140,4 +140,8 @@ export const NamiCampaignManager: ICampaignManager = {
}
};
},

refresh: async () => {
return await RNNamiCampaignManager.refresh();
}
};

0 comments on commit 1527811

Please sign in to comment.