diff --git a/docs/README.md b/docs/README.md index bfb9f88d..f13a1d57 100644 --- a/docs/README.md +++ b/docs/README.md @@ -918,6 +918,34 @@ enableAltpayment = "true" +## contribution-offset + +> **The ‘contributionOffset’ parameter sets an initial amount to add to the total contributions displayed, simulating prior contributions.** + +?> This parameter is optional. Default value is 0. Possible values are positive integers between 0 and the goal-amount. + +**Example:** + + +#### ** HTML ** + +```html +contribution-offset="10" +``` + +#### ** JavaScript ** + +```javascript +contribution-offset: 10 +``` + +#### ** React ** + +```react +contributionOffset = 10 +``` + + # 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/_sidebar.md b/docs/_sidebar.md index 33a947ac..c2971741 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -28,6 +28,7 @@ - [ws-base-url](/?id=ws-base-url) - [api-base-url](/?id=api-base-url) - [enable-altpayment](/?id=enable-altpayment) + - [contribution-offset](/?id=contribution-offset) - [Contribute](/?id=contribute) - [Developer Quick Start](/?id=developer-quick-start) - [Getting Started](/?id=getting-started) diff --git a/docs/zh-cn/README.md b/docs/zh-cn/README.md index 030f5c54..671ebca9 100644 --- a/docs/zh-cn/README.md +++ b/docs/zh-cn/README.md @@ -887,7 +887,7 @@ apiBaseUrl: 'https://paybutton.org' ```react apiBaseUrl = "https://paybutton.org" ``` - + ## enable-altpayment > **“enableAltpayment” 参数控制是否启用备用支付逻辑。** @@ -916,6 +916,33 @@ enableAltpayment = "true" ``` +## contribution-offset + +> **"contributionOffset" 参数用于设置一个初始金额,将其加到显示的总贡献额中,以模拟先前的贡献。** + +?> 此参数是可选的,默认值为 0。可能的值是介于 0 和目标金额之间的正整数。 + +**Example:** + + +#### ** HTML ** + +```html +contribution-offset="10" +``` + +#### ** JavaScript ** + +```javascript +contribution-offset: 10 +``` + +#### ** React ** + +```react +contributionOffset = 10 +``` + # 贡献 PayButton是一个社群主导的开放源代码促进会。此项目的成功关键在于对社群的贡献。 diff --git a/docs/zh-cn/_sidebar.md b/docs/zh-cn/_sidebar.md index 430f07d8..4bbf0b10 100644 --- a/docs/zh-cn/_sidebar.md +++ b/docs/zh-cn/_sidebar.md @@ -27,6 +27,7 @@ - [ws-base-url](/zh-cn/?id=ws-base-url) - [api-base-url](/zh-cn/?id=api-base-url) - [enable-altpayment](/zh-cn/?id=enable-altpayment) + - [contribution-offset](/zh-cn/?id=contribution-offset) - [贡献](/zh-cn/?id=贡献) - [开发人员快速入门](/zh-cn/?id=开发人员快速入门) - [入门](/zh-cn/?id=入门) diff --git a/docs/zh-tw/README.md b/docs/zh-tw/README.md index 1336f4d1..abdb8835 100644 --- a/docs/zh-tw/README.md +++ b/docs/zh-tw/README.md @@ -912,9 +912,36 @@ enableAltpayment: 'true' ```react enableAltpayment = "true" -`` +``` +## contribution-offset + +> **"contributionOffset" 參數用於設定一個初始數額,將其加至顯示的總貢獻額,以模擬先前的貢獻。** + +?> 此參數是可選的,預設值為 0。可能的值是介於 0 和目標金額之間的正整數。 + +**Example:** + + +#### ** HTML ** + +```html +contribution-offset="10" +``` + +#### ** JavaScript ** + +```javascript +contribution-offset: 10 +``` + +#### ** React ** + +```react +contributionOffset = 10 +``` + # 貢獻 PayButton是一個社區主導的開放源代碼促進會。此項目的成功關鍵在於對社區的貢獻。 diff --git a/docs/zh-tw/_sidebar.md b/docs/zh-tw/_sidebar.md index 75937627..734e9268 100644 --- a/docs/zh-tw/_sidebar.md +++ b/docs/zh-tw/_sidebar.md @@ -27,6 +27,7 @@ - [ws-base-url](/zh-tw/?id=ws-base-url) - [api-base-url](/zh-tw/?id=api-base-url) - [enable-altpayment](/zh-tw/?id=enable-altpayment) + - [contribution-offset](/zh-tw/?id=contribution-offset) - [貢獻](/zh-tw/?id=貢獻) - [開發人員快速入門](/zh-tw/?id=開發人員快速入門) - [入門](/zh-tw/?id=入門) diff --git a/paybutton/dev/demo/paybutton-generator.html b/paybutton/dev/demo/paybutton-generator.html index 09358f9f..4cb19bc8 100644 --- a/paybutton/dev/demo/paybutton-generator.html +++ b/paybutton/dev/demo/paybutton-generator.html @@ -86,13 +86,19 @@ +
+ + +
+ +
- - + +
@@ -216,6 +222,7 @@ hideToasts: false, disableEnforceFocus: false, enableAltpayment: false, + contributionOffset: undefined, onSuccess: mySuccessFuction, onTransaction: myTransactionFuction }); diff --git a/paybutton/src/index.tsx b/paybutton/src/index.tsx index 126e3855..d6f3fea3 100644 --- a/paybutton/src/index.tsx +++ b/paybutton/src/index.tsx @@ -99,7 +99,8 @@ const allowedProps = [ 'editable', 'wsBaseUrl', 'apiBaseUrl', - 'enableAltpayment' + 'enableAltpayment', + 'contributionOffset' ]; const requiredProps = [ diff --git a/react/lib/components/PayButton/PayButton.tsx b/react/lib/components/PayButton/PayButton.tsx index 6cd35df0..93e4262a 100644 --- a/react/lib/components/PayButton/PayButton.tsx +++ b/react/lib/components/PayButton/PayButton.tsx @@ -44,6 +44,7 @@ export interface PayButtonProps extends ButtonProps { wsBaseUrl?: string; apiBaseUrl?: string; enableAltpayment?:boolean + contributionOffset?:number } export const PayButton = (props: PayButtonProps): React.ReactElement => { @@ -79,7 +80,8 @@ export const PayButton = (props: PayButtonProps): React.ReactElement => { editable, wsBaseUrl, apiBaseUrl, - enableAltpayment + enableAltpayment, + contributionOffset } = Object.assign({}, PayButton.defaultProps, props); const [paymentId] = useState(!disablePaymentId ? generatePaymentId(8) : undefined); @@ -234,6 +236,7 @@ export const PayButton = (props: PayButtonProps): React.ReactElement => { apiBaseUrl={apiBaseUrl} hoverText={hoverText} enableAltpayment={enableAltpayment} + contributionOffset={contributionOffset} /> {errorMsg && (

void; wsBaseUrl?: string; apiBaseUrl?: string; - enableAltpayment?: boolean + enableAltpayment?: boolean; + contributionOffset?:number; } export const PaymentDialog = ( @@ -71,7 +72,8 @@ export const PaymentDialog = ( wsBaseUrl, apiBaseUrl, hoverText, - enableAltpayment + enableAltpayment, + contributionOffset } = Object.assign({}, PaymentDialog.defaultProps, props); const handleWidgetClose = (): void => { @@ -142,6 +144,7 @@ export const PaymentDialog = ( apiBaseUrl={apiBaseUrl} hoverText={hoverText} enableAltpayment={enableAltpayment} + contributionOffset={contributionOffset} foot={success && ( = props => { shiftCompleted, setShiftCompleted, enableAltpayment, + contributionOffset } = Object.assign({}, Widget.defaultProps, props); const [loading, setLoading] = useState(true); @@ -446,12 +448,16 @@ export const Widget: React.FunctionComponent = props => { const goal = getCurrencyObject(cleanGoalAmount, currency, false); if (!isFiat(currency)) { if (goal !== undefined) { - setGoalPercent((100 * progress.float) / goal.float); - setGoalText(`${progress.float} / ${cleanGoalAmount}`); + let progressFloat = progress.float; + if(contributionOffset !== undefined){ + progressFloat = Number(progressFloat) + Number(contributionOffset) + }; + setGoalPercent((100 * progressFloat) / goal.float); + setGoalText(`${progressFloat} / ${cleanGoalAmount}`); setLoading(false); } } else { - if (hasPrice) { + if (hasPrice) { const receivedVal: number = totalReceived * price; const receivedText: string = formatPrice( receivedVal, @@ -476,7 +482,7 @@ export const Widget: React.FunctionComponent = props => { setErrorMsg('Goal Value must be a number'); } } - }, [totalReceived, currency, goalAmount, price, hasPrice]); + }, [totalReceived, currency, goalAmount, price, hasPrice, contributionOffset]); const handleButtonClick = () => { if (addressType === 'XEC') { diff --git a/react/lib/components/Widget/WidgetContainer.tsx b/react/lib/components/Widget/WidgetContainer.tsx index 32fe7ff8..084dcd4e 100644 --- a/react/lib/components/Widget/WidgetContainer.tsx +++ b/react/lib/components/Widget/WidgetContainer.tsx @@ -45,6 +45,7 @@ export interface WidgetContainerProps apiBaseUrl?: string; successText?: string; enableAltpayment?: boolean + contributionOffset?: number } const snackbarOptions: OptionsObject = { @@ -104,6 +105,7 @@ export const WidgetContainer: React.FunctionComponent = successText, hoverText, enableAltpayment, + contributionOffset, ...widgetProps } = props; @@ -278,6 +280,7 @@ export const WidgetContainer: React.FunctionComponent = shiftCompleted={shiftCompleted} setShiftCompleted={setShiftCompleted} enableAltpayment={enableAltpayment} + contributionOffset={contributionOffset} /> );