Skip to content

Commit

Permalink
Decrypt fee
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Dec 10, 2023
1 parent 93b3d1f commit 1e7e604
Show file tree
Hide file tree
Showing 13 changed files with 374 additions and 70 deletions.
3 changes: 2 additions & 1 deletion app/components/cards/PostFull.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class PostFull extends React.Component {

const p = extractContent(immutableAccessor, postContent);
const content = postContent.toJS();
const { author, permlink, parent_author, parent_permlink, root_author, encrypted } = content;
const { author, permlink, parent_author, parent_permlink, root_author, encrypted, decrypt_fee } = content;
const jsonMetadata = showReply ? null : p.json_metadata;
let link = `/@${content.author}/${content.permlink}`;

Expand All @@ -237,6 +237,7 @@ class PostFull extends React.Component {
title,
body,
encrypted,
decrypt_fee: decrypt_fee ? Asset(decrypt_fee) : null,
};

const APP_DOMAIN = $STM_Config.site_domain;
Expand Down
67 changes: 57 additions & 10 deletions app/components/elements/EncryptedStub.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,42 +73,80 @@ class EncryptedStub extends React.Component {
</div>
}

onDonateClick = (e) => {
e.preventDefault()
}

_renderDonate = (decrypt_fee, isMy) => {
if (isMy || !decrypt_fee) return null
decrypt_fee = Asset(decrypt_fee)
if (decrypt_fee.eq(0)) return
return <div>
{tt('poststub.you_can_decrypt_just_this_post')}
<b>{decrypt_fee.floatString}</b>.<br/>
<button className='button hollow small' style={{ marginTop: '0.5rem' }} onClick={this.onDonateClick}>
{tt('poststub.donate')}
</button>
</div>
}

onDeleteClick = (e) => {
e.preventDefault()

const { dis, } = this.props

const author = dis.get('author')
const permlink = dis.get('permlink')

this.props.deletePost(author, permlink)
}

render() {
const { dis, encrypted, username } = this.props

const author = dis.get('author')

if (encrypted === EncryptedStates.no_sponsor) {
const sub = dis.get('encrypted_sub')
const isMy = author === username

if (!username) {
return (<div>
const btn = isMy && <div><button onClick={this.onDeleteClick} className='button alert slim hollow'>{tt('g.remove')}</button></div>

if ((encrypted === EncryptedStates.no_sponsor && !username) || encrypted === EncryptedStates.no_auth) {
return (<div>
{this._renderAuthor(tt('poststub.for_sponsors'), author)}
{tt('poststub.login_to_become_sponsor')}
</div>)
}
</div>)
} else if (encrypted === EncryptedStates.no_sponsor) {
const sub = dis.get('encrypted_sub')
const encrypted_decrypt_fee = dis.get('encrypted_decrypt_fee')

return (<div>
{this._renderAuthor(tt('poststub.for_sponsors'), author)}
{this._renderSub(sub)}
{this._renderButton(sub, tt('poststub.become_sponsor'))}
{this._renderDonate(encrypted_decrypt_fee, isMy)}
</div>)
} else if (encrypted === EncryptedStates.inactive) {
const sub = dis.get('encrypted_sub')
const encrypted_decrypt_fee = dis.get('encrypted_decrypt_fee')

return (<div>
{this._renderAuthor(tt('poststub.sponsorship_expired'), author)}
{this._renderSub(sub)}
{this._renderButton(sub, tt('poststub.prolong_sponsorship'))}
{this._renderDonate(encrypted_decrypt_fee, isMy)}
</div>)
} else if (encrypted === EncryptedStates.no_key) {
return <div>{tt('postsummary_jsx.no_decrypt_key')}</div>
return <div>{tt('postsummary_jsx.no_decrypt_key')}{btn}</div>
} else if (encrypted === EncryptedStates.no_sub) {
return <div>{tt('postsummary_jsx.no_sub')}</div>
const encrypted_decrypt_fee = dis.get('encrypted_decrypt_fee')

return <div>{tt('postsummary_jsx.no_sub')}
{this._renderDonate(encrypted_decrypt_fee, isMy)}
</div>
} else if (encrypted === EncryptedStates.wrong_format) {
return <div>{tt('postsummary_jsx.wrong_format')}</div>
return <div>{tt('postsummary_jsx.wrong_format')}{btn}</div>
}
return <div>{tt('postsummary_jsx.no_decrypt_key')}</div>
return <div>{tt('postsummary_jsx.no_decrypt_key')}{btn}</div>
}
}

Expand Down Expand Up @@ -142,6 +180,15 @@ export default connect(
}
}))
},
deletePost(author, permlink) {
dispatch(
transaction.actions.broadcastOperation({
type: 'delete_comment',
operation: { author, permlink },
confirm: tt('g.are_you_sure'),
})
);
},
fetchState: () => {
const pathname = window.location.pathname
dispatch({type: 'FETCH_STATE', payload: {pathname}})
Expand Down
4 changes: 2 additions & 2 deletions app/components/elements/VerticalMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export default class VerticalMenu extends React.Component {
if(i.value === hideValue) return null
const iconSize = i.iconSize || '1x'
const target = i.target
return <li data-link={i.link} data-value={i.value} key={i.key ? i.key : i.value} onClick={i.link ? this.closeMenu : null}>
{i.link ? <LinkEx to={i.link} target={target} onClick={i.onClick}>
return <li data-disabled={!!i.disabled} data-link={i.link} data-value={i.value} key={i.key ? i.key : i.value} onClick={(i.link && !i.disabled) ? this.closeMenu : null}>
{i.link ? <LinkEx to={!i.disabled && i.link} target={target} onClick={!i.disabled && i.onClick}>
{i.icon && <Icon name={i.icon} size={iconSize} />}{i.label ? i.label : i.value}
{i.data && <span>{i.data}</span>}
&nbsp; {i.addon}
Expand Down
4 changes: 4 additions & 0 deletions app/components/elements/VerticalMenu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
background-color: #f0f0f0;
}

> li[data-disabled=true] {
opacity: .5;
}

> li.title {
padding: 0.56rem;
@include themify($themes) {
Expand Down
15 changes: 11 additions & 4 deletions app/components/elements/postEditor/PostFooter/PostFooter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class PostFooter extends PureComponent {
disabledHint: PropTypes.string,
onPayoutTypeChange: PropTypes.func.isRequired,
onCurationPercentChange: PropTypes.func.isRequired,
onDecryptFeeChange: PropTypes.func.isRequired,
onTagsChange: PropTypes.func.isRequired,
onPost: PropTypes.func.isRequired,
onResetClick: PropTypes.func.isRequired,
Expand Down Expand Up @@ -71,7 +72,8 @@ export default class PostFooter extends PureComponent {

const { editMode, postEncrypted } = this.props
if (editMode) {
this.props.onPost(postEncrypted ? VISIBLE_TYPES.ONLY_SPONSORS : VISIBLE_TYPES.ALL)
this.props.onPost(postEncrypted ? VISIBLE_TYPES.ONLY_SPONSORS : VISIBLE_TYPES.ALL,
this.props.decryptFee)
return
}

Expand Down Expand Up @@ -105,15 +107,18 @@ export default class PostFooter extends PureComponent {
}

_renderVisibleOptions = (postDisabled) => {
const { decryptFee } = this.props

const onClick = (e) => {
e.preventDefault()
if (!postDisabled)
this.props.onPost(parseInt(e.target.parentNode.dataset.value))
this.props.onPost(parseInt(e.target.parentNode.dataset.value),
decryptFee)
}

const visibleItems = [
{link: '#', label: tt('post_editor.visible_option_all'), value: VISIBLE_TYPES.ALL, onClick },
{link: '#', label: tt('post_editor.visible_option_onlyblog'), value: VISIBLE_TYPES.ONLY_BLOG, onClick },
{disabled: decryptFee && decryptFee.amount > 0, link: '#', label: tt('post_editor.visible_option_all'), value: VISIBLE_TYPES.ALL, onClick },
{disabled: decryptFee && decryptFee.amount > 0, link: '#', label: tt('post_editor.visible_option_onlyblog'), value: VISIBLE_TYPES.ONLY_BLOG, onClick },
{link: '#', label: tt('post_editor.visible_option_onlysponsors'), value: VISIBLE_TYPES.ONLY_SPONSORS, onClick },
]

Expand Down Expand Up @@ -175,6 +180,8 @@ export default class PostFooter extends PureComponent {
editMode={editMode}
onPayoutChange={this.props.onPayoutTypeChange}
onCurationPercentChange={this.props.onCurationPercentChange}
decryptFee={this.props.decryptFee}
onDecryptFeeChange={this.props.onDecryptFeeChange}
/>)

const buttons = (<div className="PostFooter__buttons" style={{ 'marginTop': isMobile ? '15px' : '0px' }}>
Expand Down
112 changes: 111 additions & 1 deletion app/components/elements/postEditor/PostOptions/PostOptions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import cn from 'classnames';
import tt from 'counterpart';
import { isNil } from 'ramda';
import { api } from 'golos-lib-js';
import { Asset, AssetEditor } from 'golos-lib-js/lib/utils'
import {connect} from 'react-redux';
import styled from 'styled-components';

import Slider from 'golos-ui/Slider';
import Icon from 'app/components/elements/Icon';
import Hint from 'app/components/elements/common/Hint';
Expand All @@ -31,16 +33,20 @@ const CuratorValue = styled.b`
font-weight: 500;
`;

const DEFAULT_DECRYPT_FEE = '100.000 GOLOS'

class PostOptions extends React.PureComponent {
static propTypes = {
nsfw: PropTypes.bool.isRequired,
payoutType: PropTypes.number.isRequired,
curationPercent: PropTypes.number.isRequired,
decryptFee: PropTypes.object,

editMode: PropTypes.bool,
onNsfwClick: PropTypes.func.isRequired,
onPayoutChange: PropTypes.func.isRequired,
onCurationPercentChange: PropTypes.func.isRequired,
onDecryptFeeChange: PropTypes.func.isRequired,
};

constructor(props) {
Expand All @@ -50,9 +56,12 @@ class PostOptions extends React.PureComponent {

this.state = {
showCoinMenu: false,
showLockMenu: false,

minCurationPercent: 0,
maxCurationPercent: 0,

decryptFeeEdit: AssetEditor(DEFAULT_DECRYPT_FEE),
};
}

Expand All @@ -65,7 +74,10 @@ class PostOptions extends React.PureComponent {
}

render() {
const { showCoinMenu, curatorPercent, minCurationPercent, maxCurationPercent } = this.state;
const { editMode, decryptFee } = this.props
const { showCoinMenu, showLockMenu, curatorPercent, minCurationPercent, maxCurationPercent, decryptFeeToSave } = this.state;
const hasDecryptFee = (decryptFee && decryptFee.amount > 0)

return (
<div className="PostOptions">
<span
Expand Down Expand Up @@ -95,6 +107,22 @@ class PostOptions extends React.PureComponent {
</span>
{showCoinMenu ? this._renderCoinMenu() : null}
</span>
{(!editMode || hasDecryptFee) ? <span className="PostOptions__item-wrapper">
<span
className={cn('PostOptions__item', {
PostOptions__item_active: showLockMenu,
})}
onClick={this._onLockClick}
>
<Icon
name={hasDecryptFee ? 'ionicons/lock-closed-outline' : 'ionicons/lock-open-outline'}
size="1_5x"
data-tooltip={showLockMenu ? null :
hasDecryptFee ? (tt('post_editor.lock_hint2') + decryptFee.floatString) : tt('post_editor.lock_hint')}
/>
</span>
{showLockMenu ? this._renderLockMenu() : null}
</span> : null}
</div>
);
}
Expand All @@ -121,6 +149,45 @@ class PostOptions extends React.PureComponent {
);
}

onDecryptFeeChange = (e) => {
const decryptFeeEdit = this.state.decryptFeeEdit.withChange(e.target.value)
if (decryptFeeEdit.asset.amount < 0) return
if (this.props.editMode && decryptFeeEdit.asset.amount == 0) return

this.setState({
decryptFeeEdit
})
}

_lockOkClick = (e) => {
e.preventDefault()
const { decryptFeeEdit } = this.state
this.setState({
decryptFeeToSave: true,
showLockMenu: false
}, () => {
this.props.onDecryptFeeChange(decryptFeeEdit.asset.clone())
})
}

_renderLockMenu() {
let { decryptFeeEdit } = this.state
return (
<Hint align="center" innerRef={this._popupLockRef}>
<div className="PostOptions__bubble-text">
{tt('post_editor.lock_hint')}:
</div>
<div class="input-group" style={{ marginBottom: '5px', fontSize: '90%' }}>
<input type="text" name="cost" value={decryptFeeEdit.amountStr} onChange={this.onDecryptFeeChange} />
<span class="input-group-label" style={{ paddingLeft: '7px', paddingRight: '7px' }}>
GOLOS
</span>
</div>
<button onClick={this._lockOkClick} className='button primary slim' style={{ paddingLeft: '15px', paddingRight: '15px', marginRight: '7px !important' }}>OK</button>
</Hint>
);
}

_onCoinClick = () => {
this.setState(
{
Expand All @@ -137,6 +204,36 @@ class PostOptions extends React.PureComponent {
);
};

_onLockClick = () => {
const { decryptFee, editMode } = this.props
if (!editMode && decryptFee && decryptFee.amount > 0) {
this.setState({
decryptFee: Asset('0.000 GOLOS'),
decryptFeeEdit: AssetEditor(DEFAULT_DECRYPT_FEE)
}, () => {
this.props.onDecryptFeeChange(this.state.decryptFee.clone())
})
return
}
const { showLockMenu, } = this.state
if (!showLockMenu && decryptFee && decryptFee.amount > 0) {
this.setState({
decryptFeeEdit: AssetEditor(decryptFee.clone())
})
}
this.setState(
{
showLockMenu: !showLockMenu,
},
() => {
if (this.state.showLockMenu && !this._onAwayClickListen) {
window.addEventListener('mousedown', this._onAwayClick);
this._onAwayClickListen = true;
}
}
);
};

_onCoinModeChange = coinMode => {
this.props.onPayoutChange(coinMode);
};
Expand All @@ -155,12 +252,25 @@ class PostOptions extends React.PureComponent {
}
}, 50);
}
if (!this._popupLock || !this._popupLock.contains(e.target)) {
setTimeout(() => {
if (!this._unmount) {
this.setState({
showLockMenu: false,
});
}
}, 50);
}
};

_popupPayoutRef = el => {
this._popupPayout = el
}

_popupLockRef = el => {
this._popupLock = el
}

componentDidMount() {
// FIXME Dirty hack
// retry api call
Expand Down
Loading

0 comments on commit 1e7e604

Please sign in to comment.