11import type { OfferwallModal } from '@c/offerwall'
2- import type { Controller } from '@c/offerwall/controller'
2+ import type { Actions } from '@c/offerwall/controller'
33import { applyFontFamily } from '@c/utils'
44import {
55 BORDER_RADIUS ,
@@ -95,7 +95,9 @@ export class WebMonetizationCustomOfferwallChoice implements OfferwallCustomChoi
9595
9696 const abortController = new AbortController ( )
9797 const onDoneResolver = withResolvers < boolean > ( )
98- const controller : Controller = {
98+
99+ const owElem = document . createElement ( elementName ) as OfferwallModal
100+ const actions = owElem . setController ( {
99101 onExtensionLinkClick ( ) {
100102 // can start tracking
101103 } ,
@@ -106,10 +108,7 @@ export class WebMonetizationCustomOfferwallChoice implements OfferwallCustomChoi
106108 onDone ( ) {
107109 onDoneResolver . resolve ( true )
108110 } ,
109- }
110-
111- const owElem = document . createElement ( elementName ) as OfferwallModal
112- owElem . setController ( controller )
111+ } )
113112
114113 // in case initialize() wasn't called
115114 this . #configPromise ??= fetchConfig ( params )
@@ -119,7 +118,7 @@ export class WebMonetizationCustomOfferwallChoice implements OfferwallCustomChoi
119118 document . body . appendChild ( owElem )
120119
121120 try {
122- await this . #runBusinessLogic( owElem , abortController . signal )
121+ await this . #runBusinessLogic( actions , abortController . signal )
123122 onDoneResolver . resolve ( true )
124123 } catch ( error ) {
125124 console . error ( error )
@@ -157,7 +156,7 @@ export class WebMonetizationCustomOfferwallChoice implements OfferwallCustomChoi
157156 * to give access.
158157 * - If either of above was within allowed time, give access.
159158 */
160- #runBusinessLogic = async ( elem : OfferwallModal , signal : AbortSignal ) => {
159+ #runBusinessLogic = async ( actions : Actions , signal : AbortSignal ) => {
161160 const { linkElem } = this . #deps
162161 const wasExtensionInstalledAtStart = isExtensionInstalled ( )
163162
@@ -167,11 +166,11 @@ export class WebMonetizationCustomOfferwallChoice implements OfferwallCustomChoi
167166 this . #isWithinAllowedTime( lastEvent . timestamp ) &&
168167 isExtensionInstalled ( )
169168 ) {
170- return elem . setScreen ( 'all-set' )
169+ return actions . setScreen ( 'all-set' )
171170 }
172171
173172 if ( wasExtensionInstalledAtStart ) {
174- elem . setScreen ( 'contribution-required' )
173+ actions . setScreen ( 'contribution-required' )
175174 while ( true ) {
176175 if ( ! this . #monetizationEventResolver) {
177176 // if not initialized
@@ -189,7 +188,7 @@ export class WebMonetizationCustomOfferwallChoice implements OfferwallCustomChoi
189188 this . #isForSameWalletAddress( event . paymentPointer ) &&
190189 ( await isValidPayment ( event . incomingPayment ) )
191190 ) {
192- elem . setScreen ( 'all-set' )
191+ actions . setScreen ( 'all-set' )
193192 this . #setLastEvent( {
194193 type : 'monetization' ,
195194 timestamp : Date . now ( ) ,
@@ -211,7 +210,7 @@ export class WebMonetizationCustomOfferwallChoice implements OfferwallCustomChoi
211210 }
212211 } else {
213212 await this . #waitForExtensionInstall( signal )
214- elem . setScreen ( 'all-set' )
213+ actions . setScreen ( 'all-set' )
215214 this . #setLastEvent( { type : 'install' , timestamp : Date . now ( ) } )
216215 }
217216 }
0 commit comments