import { IHttpClient } from '@/common/http'; import { IAdBreakParams } from '@/common/ads'; import { unlockOptionsHandler } from './utils/common'; import { createCommonGemRewardHandler } from './utils/coins/joligem/gem-handler'; import { createShowUnlockWithCurrencyModal, createInitiateAndAwaitPayment, createShowUnloginModal } from './utils/coins/commands'; export type GemRewardsHandler = (params: IAdBreakParams) => Promise; export const createGemRewardHandler = ( httpClient: IHttpClient, { onUnlockSuccess, onUnlockFailed, hasSubscription }: { onUnlockSuccess?: (data: { quantity: number; balance: number }) => void; onUnlockFailed?: () => void; hasSubscription: () => boolean; } ): GemRewardsHandler => { const handleUnlockFailed = () => { onUnlockFailed?.(); }; const showUnlockWithGemModal = createShowUnlockWithCurrencyModal('ADS-JOLI_GEM', { confirmButtonText: 'joligem.useJolicoin', // TODO: change key cancelButtonText: 'jolicoin.noWatchAds' }); const initiateAndAwaitPayment = createInitiateAndAwaitPayment('ADS-JOLI_GEM', { confirmButtonText: 'jolicoin.payAndUnlock', // 复用文案 cancelButtonText: 'jolicoin.noWatchAds' }); const showUnloginModal = createShowUnloginModal('ADS-JOLI_GEM', { confirmButtonText: 'loginGuide.login', cancelButtonText: 'loginGuide.noWatchAds' }); const gemRewardHandler = createCommonGemRewardHandler('ADS-JOLI_GEM', httpClient, { handlers: { handleUnlockSuccess: onUnlockSuccess, handleUnlockFailed, unlockOptionsHandler, initiateAndAwaitPayment, showUnlockWithCurrencyModal: showUnlockWithGemModal, showUnloginModal, hasSubscription } }); return gemRewardHandler; };