Enable min_tip setting

This commit is contained in:
infinite-persistence 2021-07-16 16:11:02 +08:00
parent bf710cb325
commit 05f7e55aed
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 DEBOUNCE_REFRESH_MS = 1000;
const FEATURE_IS_READY = false; const BTC_SATOSHIS = 100000000;
const LBC_MAX = 21000000;
const LBC_MIN = 1;
type Props = { type Props = {
activeChannelClaim: ChannelClaim, activeChannelClaim: ChannelClaim,
@ -297,7 +299,6 @@ export default function SettingsCreatorPage(props: Props) {
</div> </div>
} }
/> />
{FEATURE_IS_READY && (
<Card <Card
title={__('Tip')} title={__('Tip')}
actions={ actions={
@ -311,10 +312,11 @@ export default function SettingsCreatorPage(props: Props) {
'Enabling a minimum amount to comment will force all comments, including livestreams, to have tips associated with them. This can help prevent spam.' '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" className="form-field--price-amount"
min={0} max={LBC_MAX}
step="any" min={LBC_MIN}
step={1 / BTC_SATOSHIS}
type="number" type="number"
placeholder="1" placeholder="3.14"
value={minTipAmountComment} value={minTipAmountComment}
onChange={(e) => setSettings({ min_tip_amount_comment: parseFloat(e.target.value) })} onChange={(e) => setSettings({ min_tip_amount_comment: parseFloat(e.target.value) })}
/> />
@ -337,7 +339,6 @@ export default function SettingsCreatorPage(props: Props) {
</> </>
} }
/> />
)}
<Card <Card
title={__('Delegation')} title={__('Delegation')}
className="card--enable-overflow" className="card--enable-overflow"

View file

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

View file

@ -991,9 +991,22 @@ export default handleActions(
// because the GUI only shows 1 channel's setting at a time, and *always* // 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 // re-fetches to get latest data before displaying. Either rename this to
// 'activeChannelCreatorSettings', or append the new data properly. // '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 { return {
...state, ...state,
settingsByChannelId: action.data, settingsByChannelId,
fetchingSettings: false, fetchingSettings: false,
}; };
}, },