diff --git a/docs/README.md b/docs/README.md index 05a5a23c..05c589e7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -558,6 +558,35 @@ successText = "Thanks!" +## transaction-text + +> **The ‘transaction-text’ parameter specifies the text displayed when a new transaction occurs but the amount or OP_RETURN code are incorrect.** + +?> This parameter is optional. Default value is empty. Possible values are any string. + +**Example:** + + +#### ** HTML ** + +```html +transaction-text="New transaction!" +``` + +#### ** JavaScript ** + +```javascript +transactionText: 'New transaction!' +``` + +#### ** React ** + +```react +transactionText = "New transaction!" +``` + + + ## on-success > **The ‘on-success’ parameter specifies the callback function that runs upon successful payment.** @@ -928,6 +957,8 @@ apiBaseUrl: 'https://paybutton.org' apiBaseUrl = "https://paybutton.org" ``` + + ## disable-altpayment > **The ‘disableAltpayment’ parameter disables altpayment logic.** diff --git a/docs/_sidebar.md b/docs/_sidebar.md index 997f5571..aa35e4b4 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -15,6 +15,7 @@ - [theme](/?id=theme) - [animation](/?id=animation) - [success-text](/?id=success-text) + - [transaction-text](/?id=transaction-text) - [on-success](/?id=on-success) - [on-transaction](/?id=on-transaction) - [on-open](/?id=on-open) diff --git a/docs/zh-cn/README.md b/docs/zh-cn/README.md index 27675750..100479a4 100644 --- a/docs/zh-cn/README.md +++ b/docs/zh-cn/README.md @@ -553,6 +553,37 @@ successText = "Thanks!" +## transaction-text + +> **“transaction-text” 参数指定当发生新交易但金额或 OP_RETURN 代码不正确时显示的文本。** + +?> 此参数为选填,默认值为空。可用值为任何字符串。 + +**Example:** + + +#### ** HTML ** + +```html +transaction-text="New transaction!" +``` + +#### ** JavaScript ** + +```javascript +transactionText: 'New transaction!' +``` + +#### ** React ** + +```react +transactionText = "New transaction!" +``` + + + + + ## on-success > **参数'on-success'用来定义指定地址收款后运行的回调函数。** diff --git a/docs/zh-cn/_sidebar.md b/docs/zh-cn/_sidebar.md index 1d7e1bdc..c106ca05 100644 --- a/docs/zh-cn/_sidebar.md +++ b/docs/zh-cn/_sidebar.md @@ -14,6 +14,7 @@ - [theme](/zh-cn/?id=theme) - [animation](/zh-cn/?id=animation) - [success-text](/zh-cn/?id=success-text) + - [transaction-text](/zh-cn/?id=transaction-text) - [on-success](/zh-cn/?id=on-success) - [on-transaction](/zh-cn/?id=on-transaction) - [on-open](/zh-cn/?id=on-open) diff --git a/docs/zh-tw/README.md b/docs/zh-tw/README.md index fec99253..5b25687c 100644 --- a/docs/zh-tw/README.md +++ b/docs/zh-tw/README.md @@ -553,6 +553,36 @@ successText = "Thanks!" +## transaction-text + +> **"transaction-text" 參數指定當發生新交易但金額或 OP_RETURN 代碼不正確時顯示的文字。** + +?> 此參數為選填,預設值為空。可用值為任何字串。 + +**Example:** + + +#### ** HTML ** + +```html +transaction-text="New transaction!" +``` + +#### ** JavaScript ** + +```javascript +transactionText: 'New transaction!' +``` + +#### ** React ** + +```react +transactionText = "New transaction!" +``` + + + + ## on-success > **參數"on-success"用來定義指定地址收款後運行的回呼函式。** diff --git a/docs/zh-tw/_sidebar.md b/docs/zh-tw/_sidebar.md index a87ee3cb..e027369d 100644 --- a/docs/zh-tw/_sidebar.md +++ b/docs/zh-tw/_sidebar.md @@ -14,6 +14,7 @@ - [theme](/zh-tw/?id=theme) - [animation](/zh-tw/?id=animation) - [success-text](/zh-tw/?id=success-text) + - [ transaction-text](/zh-tw/?id=transaction-text) - [on-success](/zh-tw/?id=on-success) - [on-transaction](/zh-tw/?id=on-transaction) - [on-open](/zh-tw/?id=on-open) diff --git a/paybutton/dev/demo/paybutton-generator.html b/paybutton/dev/demo/paybutton-generator.html index ef1c8012..897af42a 100644 --- a/paybutton/dev/demo/paybutton-generator.html +++ b/paybutton/dev/demo/paybutton-generator.html @@ -119,9 +119,15 @@ -
- - +
+
+ + +
+
+ + +
@@ -206,6 +212,7 @@ :on-success="mySuccessFuction" :on-transaction="myTransactionFuction" :disable-altpayment="paybuttonProps.disableAltpayment" + :transaction-text="paybuttonProps.transactionText" :op-return="paybuttonProps.opReturn">
@@ -238,6 +245,7 @@ disableAltpayment: false, contributionOffset: undefined, opReturn:undefined, + transactiontext: '', onSuccess: mySuccessFuction, onTransaction: myTransactionFuction }); diff --git a/paybutton/src/index.tsx b/paybutton/src/index.tsx index 60c04d56..f5b4be16 100644 --- a/paybutton/src/index.tsx +++ b/paybutton/src/index.tsx @@ -103,6 +103,7 @@ const allowedProps = [ 'contributionOffset', 'autoClose', 'disableSound', + 'transactionText', ]; const requiredProps = [ diff --git a/react/lib/components/PayButton/PayButton.tsx b/react/lib/components/PayButton/PayButton.tsx index 6e49ebfe..bc6cef93 100644 --- a/react/lib/components/PayButton/PayButton.tsx +++ b/react/lib/components/PayButton/PayButton.tsx @@ -43,10 +43,11 @@ export interface PayButtonProps extends ButtonProps { onClose?: (success?: boolean, paymentId?:string) => void; wsBaseUrl?: string; apiBaseUrl?: string; - disableAltpayment?: boolean - contributionOffset?: number - autoClose?: boolean disableSound?: boolean + autoClose?: boolean; + disableAltpayment?:boolean; + contributionOffset?:number; + transactionText?: string; } export const PayButton = (props: PayButtonProps): React.ReactElement => { @@ -85,6 +86,7 @@ export const PayButton = (props: PayButtonProps): React.ReactElement => { contributionOffset, autoClose, disableSound, + transactionText, } = Object.assign({}, PayButton.defaultProps, props); const [paymentId] = useState(!disablePaymentId ? generatePaymentId(8) : undefined); @@ -242,6 +244,7 @@ export const PayButton = (props: PayButtonProps): React.ReactElement => { contributionOffset={contributionOffset} autoClose={autoClose} disableSound={disableSound} + transactionText={transactionText} /> {errorMsg && (

{ @@ -157,6 +159,7 @@ export const PaymentDialog = ( disableAltpayment={disableAltpayment} contributionOffset={contributionOffset} disableSound={disableSound} + transactionText={transactionText} foot={success && ( = disableAltpayment, contributionOffset, disableSound, + transactionText, ...widgetProps } = props; @@ -158,6 +168,7 @@ export const WidgetContainer: React.FunctionComponent = } else { const expectedAmount = amount ? resolveNumber(amount) : undefined; const receivedAmount = resolveNumber(transaction.amount); + const currencyTicker = getCurrencyTypeFromAddress(to); if (await shouldTriggerOnSuccess( transaction, @@ -177,13 +188,12 @@ export const WidgetContainer: React.FunctionComponent = txSound.play().catch(() => {}); } - const currencyTicker = getCurrencyTypeFromAddress(to); if (!hideToasts) enqueueSnackbar( `${ successText ? successText + ' | ' : '' }Received ${receivedAmount} ${currencyTicker}`, - snackbarOptions, + snackbarOptionsSuccess, ); setSuccess(true); onSuccess?.(transaction); @@ -192,6 +202,15 @@ export const WidgetContainer: React.FunctionComponent = }, 3000); } else { onTransaction?.(transaction); + if (transactionText){ + enqueueSnackbar( + `${ + transactionText ? transactionText : 'New transaction' + } | Received ${receivedAmount} ${currencyTicker}`, + snackbarOptionsInfo, + ); + } + } } setNewTxs([]); @@ -286,6 +305,7 @@ export const WidgetContainer: React.FunctionComponent = setShiftCompleted={setShiftCompleted} disableAltpayment={disableAltpayment} contributionOffset={contributionOffset} + transactionText={transactionText} /> );