Skip to content

Commit b17bc65

Browse files
committed
single interaction view for rendering different widget payment states
1 parent fe20451 commit b17bc65

File tree

1 file changed

+93
-85
lines changed

1 file changed

+93
-85
lines changed

components/src/widget/views/interaction/interaction.ts

Lines changed: 93 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LitElement, html, unsafeCSS } from 'lit'
1+
import { LitElement, html, nothing, unsafeCSS } from 'lit'
22
import { property, state } from 'lit/decorators.js'
33
import type {
44
PaymentStatusSuccess,
@@ -12,6 +12,23 @@ import successIcon from '@c/assets/interaction/authorization_success.svg'
1212
import interactionStyles from './interaction.css?raw'
1313
import type { WidgetController } from '../../controller'
1414

15+
type ButtonAction = {
16+
label: string
17+
buttonClass: 'primary-button' | 'empty-button'
18+
handler: () => void
19+
}
20+
21+
type InteractionView = {
22+
titleClass: 'authorizing' | 'complete' | 'failed'
23+
title: string
24+
image: {
25+
src: string
26+
alt: string
27+
}
28+
button?: ButtonAction
29+
description?: string
30+
}
31+
1532
function isInteractionSuccess(
1633
params: PaymentStatus,
1734
): params is PaymentStatusSuccess {
@@ -243,108 +260,99 @@ export class PaymentInteraction extends LitElement {
243260
}, 3000)
244261
}
245262

246-
private renderAuthorizingView() {
247-
return html`
248-
<div class="interaction-container">
249-
<div class="empty-header"></div>
250-
251-
<div class="interaction-body">
252-
<div class="title authorizing">Authorizing payment</div>
253-
<div class="description">
254-
Please complete the authorization in the opened tab
255-
</div>
256-
<img
257-
src=${loadingIcon}
258-
width="122"
259-
height="200"
260-
alt="Payment authorization in progress"
261-
/>
262-
</div>
263-
264-
<button class="button-container empty-button" @click=${this.cancel}>
265-
Cancel payment
266-
</button>
267-
</div>
268-
`
269-
}
270-
271-
private renderProcessingView() {
272-
return html`
273-
<div class="interaction-container">
274-
<div class="empty-header"></div>
275-
276-
<div class="interaction-body">
277-
<div class="title authorizing">Verifying payment</div>
278-
<div class="description">Checking payment status</div>
279-
<img
280-
src=${loadingIcon}
281-
width="122"
282-
height="200"
283-
alt="Payment verification in progress"
284-
/>
285-
</div>
286-
</div>
287-
`
288-
}
289-
290-
private renderSuccessView() {
291-
return html`
292-
<div class="interaction-container">
293-
<div class="empty-header"></div>
294-
295-
<div class="interaction-body">
296-
<div class="title complete">Payment complete!</div>
297-
<div class="description">
298-
Your payment has been processed successfully
299-
</div>
300-
<img
301-
src=${successIcon}
302-
width="122"
303-
height="200"
304-
alt="Payment successful"
305-
/>
306-
</div>
263+
private resolveInteractionView(): InteractionView {
264+
switch (this.currentView) {
265+
case 'processing':
266+
return {
267+
titleClass: 'authorizing',
268+
title: 'Verifying payment',
269+
description: 'Checking payment status',
270+
image: {
271+
src: loadingIcon,
272+
alt: 'Payment verification in progress',
273+
},
274+
}
307275

308-
<button class="button-container primary-button" @click=${this.goBack}>
309-
Done
310-
</button>
311-
</div>
312-
`
276+
case 'success':
277+
return {
278+
titleClass: 'complete',
279+
title: 'Payment complete!',
280+
description: 'Your payment has been processed successfully',
281+
image: {
282+
src: successIcon,
283+
alt: 'Payment successful',
284+
},
285+
button: {
286+
label: 'Done',
287+
buttonClass: 'primary-button',
288+
handler: this.goBack,
289+
},
290+
}
291+
case 'failed':
292+
return {
293+
titleClass: 'failed',
294+
title: this.errorMessage,
295+
image: {
296+
src: failedIcon,
297+
alt: 'Payment failed',
298+
},
299+
button: {
300+
label: 'Cancel payment',
301+
buttonClass: 'empty-button',
302+
handler: this.cancel,
303+
},
304+
}
305+
case 'authorizing':
306+
return {
307+
titleClass: 'authorizing',
308+
title: 'Authorizing payment',
309+
description: 'Please complete the authorization in the opened tab',
310+
image: {
311+
src: loadingIcon,
312+
alt: 'Payment authorization in progress',
313+
},
314+
button: {
315+
label: 'Cancel payment',
316+
buttonClass: 'empty-button',
317+
handler: this.cancel,
318+
},
319+
}
320+
}
313321
}
314322

315-
private renderFailedView() {
323+
private renderInteractionView(view: InteractionView) {
316324
return html`
317325
<div class="interaction-container">
318326
<div class="empty-header"></div>
319327
320328
<div class="interaction-body">
321-
<div class="title failed">${this.errorMessage}</div>
329+
<div class="title ${view.titleClass}">${view.title}</div>
330+
${view.description
331+
? html`<div class="description">${view.description}</div>`
332+
: nothing}
322333
<img
323-
src=${failedIcon}
334+
src=${view.image.src}
324335
width="122"
325336
height="200"
326-
alt="Payment failed"
337+
alt=${view.image.alt}
327338
/>
328339
</div>
329340
330-
<button class="button-container empty-button" @click=${this.cancel}>
331-
Cancel payment
332-
</button>
341+
${view.button
342+
? html`
343+
<button
344+
class="button-container ${view.button.buttonClass}"
345+
@click=${view.button.handler}
346+
>
347+
${view.button.label}
348+
</button>
349+
`
350+
: nothing}
333351
</div>
334352
`
335353
}
336354

337355
render() {
338-
switch (this.currentView) {
339-
case 'processing':
340-
return this.renderProcessingView()
341-
case 'success':
342-
return this.renderSuccessView()
343-
case 'failed':
344-
return this.renderFailedView()
345-
case 'authorizing':
346-
default:
347-
return this.renderAuthorizingView()
348-
}
356+
return this.renderInteractionView(this.resolveInteractionView())
349357
}
350358
}

0 commit comments

Comments
 (0)