From 0e622e969981c095eef2c90cc4472bc93f236d86 Mon Sep 17 00:00:00 2001 From: lissavxo Date: Thu, 17 Apr 2025 11:46:42 -0300 Subject: [PATCH 1/2] feat: disableSound prop --- paybutton/src/index.tsx | 3 ++- react/lib/components/PayButton/PayButton.tsx | 6 ++++-- react/lib/components/PaymentDialog/PaymentDialog.tsx | 7 +++++-- react/lib/components/Widget/WidgetContainer.tsx | 9 ++++++--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/paybutton/src/index.tsx b/paybutton/src/index.tsx index e7c9e205..60c04d56 100644 --- a/paybutton/src/index.tsx +++ b/paybutton/src/index.tsx @@ -101,7 +101,8 @@ const allowedProps = [ 'apiBaseUrl', 'disableAltpayment', 'contributionOffset', - 'autoClose' + 'autoClose', + 'disableSound', ]; const requiredProps = [ diff --git a/react/lib/components/PayButton/PayButton.tsx b/react/lib/components/PayButton/PayButton.tsx index 9206cf34..6e49ebfe 100644 --- a/react/lib/components/PayButton/PayButton.tsx +++ b/react/lib/components/PayButton/PayButton.tsx @@ -46,6 +46,7 @@ export interface PayButtonProps extends ButtonProps { disableAltpayment?: boolean contributionOffset?: number autoClose?: boolean + disableSound?: boolean } export const PayButton = (props: PayButtonProps): React.ReactElement => { @@ -60,7 +61,6 @@ export const PayButton = (props: PayButtonProps): React.ReactElement => { const priceRef = useRef(price); const cryptoAmountRef = useRef(cryptoAmount); - const { to, opReturn, @@ -83,7 +83,8 @@ export const PayButton = (props: PayButtonProps): React.ReactElement => { apiBaseUrl, disableAltpayment, contributionOffset, - autoClose + autoClose, + disableSound, } = Object.assign({}, PayButton.defaultProps, props); const [paymentId] = useState(!disablePaymentId ? generatePaymentId(8) : undefined); @@ -240,6 +241,7 @@ export const PayButton = (props: PayButtonProps): React.ReactElement => { disableAltpayment={disableAltpayment} contributionOffset={contributionOffset} autoClose={autoClose} + disableSound={disableSound} /> {errorMsg && (

{ @@ -154,6 +156,7 @@ export const PaymentDialog = ( hoverText={hoverText} disableAltpayment={disableAltpayment} contributionOffset={contributionOffset} + disableSound={disableSound} foot={success && ( = hoverText, disableAltpayment, contributionOffset, + disableSound, ...widgetProps } = props; @@ -148,7 +151,7 @@ export const WidgetContainer: React.FunctionComponent = if (altpaymentShift) { const shiftStatus = await paymentClient.getPaymentStatus(altpaymentShift.id) if (shiftStatus.status === 'settled') { - if (sound) txSound.play().catch(() => {}); + if (sound && disableSound !== true) txSound.play().catch(() => {}); onSuccess?.(transaction); setShiftCompleted(true) } @@ -170,7 +173,7 @@ export const WidgetContainer: React.FunctionComponent = randomSatoshis, ), )) { - if (sound) { + if (sound && !isPropsTrue(disableSound)) { txSound.play().catch(() => {}); } From 6de0dea1174cfd882664e1713885c80b566e4e9c Mon Sep 17 00:00:00 2001 From: lissavxo Date: Thu, 17 Apr 2025 11:50:06 -0300 Subject: [PATCH 2/2] docs: disableSound prop --- docs/README.md | 27 ++++++++++++++++++ docs/zh-cn/README.md | 28 +++++++++++++++++++ docs/zh-tw/README.md | 28 +++++++++++++++++++ .../lib/components/Widget/WidgetContainer.tsx | 2 +- 4 files changed, 84 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 6706cb41..05a5a23c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1011,6 +1011,33 @@ autoClose = false ``` +## disable-sound + +> **The ‘disableSound’ parameter mutes the sound played when a transaction is successful.** + +?> This parameter is optional. Default value is false. Possible values are true or false. +**Example:** + + +#### ** HTML ** + +```html +disable-sound="false" +``` + +#### ** JavaScript ** + +```javascript +disableSound: false +``` + +#### ** React ** + +```react +disableSound = false +``` + + # Contribute PayButton is a community-driven open-source initiative. Contributions from the community are _crucial_ to the success of the project. diff --git a/docs/zh-cn/README.md b/docs/zh-cn/README.md index d31435db..8067368a 100644 --- a/docs/zh-cn/README.md +++ b/docs/zh-cn/README.md @@ -1007,6 +1007,34 @@ autoClose = false ``` +## disable-sound + +> **“disableSound”参数会在交易成功时静音原本播放的声音。** + +?>此参数为可选。默认值为 false。可接受的值为 true 或 false。 + +**Example:** + + +#### ** HTML ** + +```html +disable-sound="false" +``` + +#### ** JavaScript ** + +```javascript +disableSound: false +``` + +#### ** React ** + +```react +disableSound = false +``` + + # 贡献 PayButton是一个社群主导的开放源代码促进会。此项目的成功关键在于对社群的贡献。 diff --git a/docs/zh-tw/README.md b/docs/zh-tw/README.md index 8a9a72e8..a34832a7 100644 --- a/docs/zh-tw/README.md +++ b/docs/zh-tw/README.md @@ -1006,6 +1006,34 @@ autoClose = false ``` +## disable-sound + +> **「disableSound」參數會在交易成功時靜音原本播放的聲音。** + +?>此參數為選填。預設值為 false。可接受的值為 true 或 false。 + +**Example:** + + +#### ** HTML ** + +```html +disable-sound="false" +``` + +#### ** JavaScript ** + +```javascript +disableSound: false +``` + +#### ** React ** + +```react +disableSound = false +``` + + # 貢獻 PayButton是一個社區主導的開放源代碼促進會。此項目的成功關鍵在於對社區的貢獻。 diff --git a/react/lib/components/Widget/WidgetContainer.tsx b/react/lib/components/Widget/WidgetContainer.tsx index 1b4139d3..96790787 100644 --- a/react/lib/components/Widget/WidgetContainer.tsx +++ b/react/lib/components/Widget/WidgetContainer.tsx @@ -151,7 +151,7 @@ export const WidgetContainer: React.FunctionComponent = if (altpaymentShift) { const shiftStatus = await paymentClient.getPaymentStatus(altpaymentShift.id) if (shiftStatus.status === 'settled') { - if (sound && disableSound !== true) txSound.play().catch(() => {}); + if (sound && !isPropsTrue(disableSound)) txSound.play().catch(() => {}); onSuccess?.(transaction); setShiftCompleted(true) }