Enable min_tip setting

This commit is contained in:
infinite-persistence 2021-07-16 16:11:02 +08:00
parent ff9ca662f2
commit 658e9bd1db
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
3 changed files with 69 additions and 60 deletions

View file

@ -15,7 +15,9 @@ import { getUriForSearchTerm } from 'util/search';
const DEBOUNCE_REFRESH_MS = 1000;
const FEATURE_IS_READY = false;
const LBC_MAX = 21000000;
const LBC_MIN = 0;
const LBC_STEP = 1.0;
type Props = {
activeChannelClaim: ChannelClaim,
@ -297,47 +299,46 @@ export default function SettingsCreatorPage(props: Props) {
</div>
}
/>
{FEATURE_IS_READY && (
<Card
title={__('Tip')}
actions={
<>
<FormField
name="min_tip_amount_comment"
label={
<I18nMessage tokens={{ lbc: <LbcSymbol /> }}>Minimum %lbc% tip amount for comments</I18nMessage>
}
helper={__(
'Enabling a minimum amount to comment will force all comments, including livestreams, to have tips associated with them. This can help prevent spam.'
)}
className="form-field--price-amount"
min={0}
step="any"
type="number"
placeholder="1"
value={minTipAmountComment}
onChange={(e) => setSettings({ min_tip_amount_comment: parseFloat(e.target.value) })}
/>
<FormField
name="min_tip_amount_super_chat"
label={
<I18nMessage tokens={{ lbc: <LbcSymbol /> }}>Minimum %lbc% tip amount for hyperchats</I18nMessage>
}
helper={__(
'Enabling a minimum amount to hyperchat will force all TIPPED comments to have this value in order to be shown. This still allows regular comments to be posted.'
)}
className="form-field--price-amount"
min={0}
step="any"
type="number"
placeholder="1"
value={minTipAmountSuperChat}
onChange={(e) => setSettings({ min_tip_amount_super_chat: parseFloat(e.target.value) })}
/>
</>
}
/>
)}
<Card
title={__('Tip')}
actions={
<>
<FormField
name="min_tip_amount_comment"
label={
<I18nMessage tokens={{ lbc: <LbcSymbol /> }}>Minimum %lbc% tip amount for comments</I18nMessage>
}
helper={__(
'Enabling a minimum amount to comment will force all comments, including livestreams, to have tips associated with them. This can help prevent spam.'
)}
className="form-field--price-amount"
max={LBC_MAX}
min={LBC_MIN}
step={LBC_STEP}
type="number"
placeholder="3.14"
value={minTipAmountComment}
onChange={(e) => setSettings({ min_tip_amount_comment: parseFloat(e.target.value) })}
/>
<FormField
name="min_tip_amount_super_chat"
label={
<I18nMessage tokens={{ lbc: <LbcSymbol /> }}>Minimum %lbc% tip amount for hyperchats</I18nMessage>
}
helper={__(
'Enabling a minimum amount to hyperchat will force all TIPPED comments to have this value in order to be shown. This still allows regular comments to be posted.'
)}
className="form-field--price-amount"
min={0}
step="any"
type="number"
placeholder="1"
value={minTipAmountSuperChat}
onChange={(e) => setSettings({ min_tip_amount_super_chat: parseFloat(e.target.value) })}
/>
</>
}
/>
<Card
title={__('Delegation')}
className="card--enable-overflow"

View file

@ -1458,21 +1458,21 @@ export const doFetchCreatorSettings = (channelClaimIds: Array<string> = []) => {
*/
export const doUpdateCreatorSettings = (channelClaim: ChannelClaim, settings: PerChannelSettings) => {
return async (dispatch: Dispatch, getState: GetState) => {
let channelSignature: ?{
signature: string,
signing_ts: string,
};
try {
channelSignature = await Lbry.channel_sign({
channel_id: channelClaim.claim_id,
hexdata: toHex(channelClaim.name),
});
} catch (e) {}
const channelSignature = await channelSignName(channelClaim.claim_id, channelClaim.name);
if (!channelSignature) {
devToast(dispatch, 'doUpdateCreatorSettings: failed to sign channel name');
return;
}
const BTC_SATOSHIS = 100000000;
if (settings.min_tip_amount_comment !== undefined) {
settings.min_tip_amount_comment *= BTC_SATOSHIS;
}
if (settings.min_tip_amount_super_chat !== undefined) {
settings.min_tip_amount_super_chat *= BTC_SATOSHIS;
}
return Comments.setting_update({
channel_name: channelClaim.name,
channel_id: channelClaim.claim_id,
@ -1480,12 +1480,7 @@ export const doUpdateCreatorSettings = (channelClaim: ChannelClaim, settings: Pe
signing_ts: channelSignature.signing_ts,
...settings,
}).catch((err) => {
dispatch(
doToast({
message: err.message,
isError: true,
})
);
dispatch(doToast({ message: err.message, isError: true }));
});
};
};

View file

@ -1023,9 +1023,22 @@ export default handleActions(
// because the GUI only shows 1 channel's setting at a time, and *always*
// re-fetches to get latest data before displaying. Either rename this to
// 'activeChannelCreatorSettings', or append the new data properly.
const settingsByChannelId = Object.assign({}, action.data);
const BTC_SATOSHIS = 100000000;
const channelIds = Object.keys(settingsByChannelId);
channelIds.forEach((ci) => {
if (settingsByChannelId[ci].min_tip_amount_comment) {
settingsByChannelId[ci].min_tip_amount_comment /= BTC_SATOSHIS;
}
if (settingsByChannelId[ci].min_tip_amount_super_chat) {
settingsByChannelId[ci].min_tip_amount_super_chat /= BTC_SATOSHIS;
}
});
return {
...state,
settingsByChannelId: action.data,
settingsByChannelId,
fetchingSettings: false,
};
},