diff --git a/cdn/src/paywall.ts b/cdn/src/paywall.ts index fd2bed03..30e50e89 100644 --- a/cdn/src/paywall.ts +++ b/cdn/src/paywall.ts @@ -4,7 +4,6 @@ import { sleep } from '@shared/utils' import { Paywall } from '@tools/components' import { fetchProfile, - fetchQuote, getScriptParams, getWallet, initiatePayment, @@ -35,10 +34,6 @@ function drawPaywall() { // TODO: create and call API }, getWallet: (walletAddressUrl) => getWallet(API_URL, walletAddressUrl), - fetchQuote({ sender, receiver, amount }) { - const receiveAmount = Number(amount) - return fetchQuote(API_URL, { sender, receiver, receiveAmount }) - }, async initiatePayment({ sender, receiver, amount, note }) { const receiveAmount = Number(amount) const redirectUrl = window.location.href diff --git a/components/src/paywall/components/common.css b/components/src/paywall/components/common.css new file mode 100644 index 00000000..0c917b11 --- /dev/null +++ b/components/src/paywall/components/common.css @@ -0,0 +1,35 @@ +.title { + font-size: 1.75em; +} + +.description { + font-size: 1em; +} + +button { + border: none; + display: flex; + justify-content: center; + align-items: center; + padding: 1em; + font-size: 1.25em; + border-radius: var(--border-radius); + background-color: var(--theme); + /* contrast-color() is unreliable in Chrome shadow DOM; approximate with OKLCH: + https://css-tricks.com/approximating-contrast-color-with-other-css-features/ */ + color: white; + color: oklch(from var(--theme) round(1.21 - L) 0 0); + font-weight: 600; + cursor: pointer; +} + +button:disabled { + opacity: 0.75; + cursor: not-allowed; +} + +.footer { + font-size: 0.6em; + margin-top: -1.25em; + text-align: center; +} diff --git a/components/src/paywall/components/form.css b/components/src/paywall/components/form.css new file mode 100644 index 00000000..5ff09a1a --- /dev/null +++ b/components/src/paywall/components/form.css @@ -0,0 +1,47 @@ +:host { + display: flex; + flex-direction: column; + gap: 1em; + width: 100%; + height: 100%; +} + +form { + display: flex; + flex-direction: column; + gap: 1em; + margin-top: auto; +} + +form label { + display: block; + margin-bottom: 0.2em; + font-size: 1em; + font-weight: 600; +} + +form input { + font-family: inherit; + border: 2px solid rgba(0, 0, 0, 0.1); + display: flex; + width: 100%; + justify-content: center; + align-items: center; + padding: 1em; + font-size: 1.25em; + border-radius: var(--border-radius); + background-color: #fff; +} + +form wm-dots-loader { + --primary-color: var(--theme); +} + +form input[aria-invalid='true'] { + border-color: var(--color-error); +} +form div p.error { + margin-top: 0.2em; + font-size: 0.9em; + color: var(--color-error); +} diff --git a/components/src/paywall/components/form.ts b/components/src/paywall/components/form.ts new file mode 100644 index 00000000..9e03ec69 --- /dev/null +++ b/components/src/paywall/components/form.ts @@ -0,0 +1,90 @@ +import { html, LitElement, unsafeCSS } from 'lit' +import { property, state } from 'lit/decorators.js' +import { DotsLoader } from '@c/shared/dots-loader' +import { registerComponents } from '@c/utils' +import stylesCommon from './common.css?raw' +import styles from './form.css?raw' +import { DEFAULTS } from '../utils' +import styleTokens from '../vars.css?raw' + +export type FormSubmitEventDetail = { + walletAddress: string + onComplete(error?: string): void +} + +export class PaywallWalletAddressForm extends LitElement { + static styles = [ + unsafeCSS(styleTokens), + unsafeCSS(stylesCommon), + unsafeCSS(styles), + ] + + @property({ type: String }) title = DEFAULTS.title.text + @property({ type: String }) description = DEFAULTS.description.text + @property({ type: String }) ctaText = DEFAULTS.ctaButton.text + + @state() private _error = '' + @state() private _loading = false + + connectedCallback() { + super.connectedCallback() + registerComponents({ + 'wm-dots-loader': DotsLoader, + }) + } + + render() { + return html` +
${this.description}
+ + + ` + } + + private async handleSubmit(ev: SubmitEvent) { + ev.preventDefault() + this._error = '' + const formData = new FormData(ev.target as HTMLFormElement) + const walletAddress = formData.get('walletAddress') as string + + if (!walletAddress) { + this._error = 'Please enter a valid wallet address' + return + } + + this._loading = true + const detail: FormSubmitEventDetail = { + walletAddress, + onComplete: (error) => { + this._error = error || '' + this._loading = false + }, + } + this.dispatchEvent(new CustomEvent('submit', { detail })) + } +} diff --git a/components/src/paywall/components/home.css b/components/src/paywall/components/home.css index 5b09b676..e30842e6 100644 --- a/components/src/paywall/components/home.css +++ b/components/src/paywall/components/home.css @@ -6,14 +6,6 @@ height: 100%; } -.title { - font-size: 1.75em; -} - -.description { - font-size: 1em; -} - .price { background-color: rgba(0, 0, 0, 0.05); border: rgba(0, 0, 0, 0.1); @@ -33,26 +25,3 @@ font-weight: 600; } } - -button { - border: none; - display: flex; - justify-content: center; - align-items: center; - padding: 1em; - font-size: 1.25em; - border-radius: var(--border-radius); - background-color: var(--theme); - /* contrast-color() is unreliable in Chrome shadow DOM; approximate with OKLCH: - https://css-tricks.com/approximating-contrast-color-with-other-css-features/ */ - color: white; - color: oklch(from var(--theme) round(1.21 - L) 0 0); - font-weight: 600; - cursor: pointer; -} - -.footer { - font-size: 0.6em; - margin-top: -1.25em; - text-align: center; -} diff --git a/components/src/paywall/components/home.ts b/components/src/paywall/components/home.ts index 808094f9..312c9777 100644 --- a/components/src/paywall/components/home.ts +++ b/components/src/paywall/components/home.ts @@ -1,14 +1,17 @@ import { html, LitElement, unsafeCSS } from 'lit' import { property } from 'lit/decorators.js' -import { createDefaultPaywallProfile } from '@shared/default-data' import { formatCurrency } from '@shared/utils' +import stylesCommon from './common.css?raw' import styles from './home.css?raw' +import { DEFAULTS } from '../utils' import styleTokens from '../vars.css?raw' -const DEFAULTS = createDefaultPaywallProfile('') - export class PaywallHome extends LitElement { - static styles = [unsafeCSS(styleTokens), unsafeCSS(styles)] + static styles = [ + unsafeCSS(styleTokens), + unsafeCSS(stylesCommon), + unsafeCSS(styles), + ] @property({ type: Object, attribute: false }) price: PaymentCurrencyAmount = DEFAULTS.price @@ -25,8 +28,12 @@ export class PaywallHome extends LitElement {