Skip to content

Commit

Permalink
Referrers, referrals
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Nov 19, 2023
1 parent bb62cf3 commit db95e80
Show file tree
Hide file tree
Showing 10 changed files with 279 additions and 29 deletions.
4 changes: 2 additions & 2 deletions app/ResolveRoute.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const routeRegex = {
PostsIndex: /^\/(@[\w\.\d-]+)\/feed\/?$/,
UserProfile1: /^\/(@[\w\.\d-]+)\/?$/,
UserProfile2: /^\/(@[\w\.\d-]+)\/(blog|posts|comments|reputation|mentions|created|recent-replies|discussions|feed|followed|followers|sponsors|settings)\/??(?:&?[^=&]*=[^=&]*)*$/,
UserProfile2: /^\/(@[\w\.\d-]+)\/(blog|posts|comments|reputation|mentions|created|recent-replies|discussions|feed|followed|followers|sponsors|referrals|settings)\/??(?:&?[^=&]*=[^=&]*)*$/,
UserProfile3: /^\/(@[\w\.\d-]+)\/[\w\.\d-]+/,
UserEndPoints: /^(blog|posts|comments|reputation|mentions|created|recent-replies|discussions|feed|followed|followers|sponsors|settings)$/,
UserEndPoints: /^(blog|posts|comments|reputation|mentions|created|recent-replies|discussions|feed|followed|followers|sponsors|referrals|settings)$/,
CategoryFilters: /^\/(hot|responses|donates|forums|trending|promoted|allposts|allcomments|created|active)\/?$/ig,
PostNoCategory: /^\/(@[\w\.\d-]+)\/([\w\d-]+)/,
Post: /^\/([\w\d\-\/]+)\/(\@[\w\d\.-]+)\/([\w\d-]+)\/?($|\?)/,
Expand Down
6 changes: 6 additions & 0 deletions app/components/modules/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ class Header extends React.Component {
if(route.params[1] === "followed"){
page_title = tt('header_jsx.people_followed_by') + " " + user_title;
}
if (route.params[1] === "sponsors"){
page_title = tt('sponsors_jsx.your_sponsors') + " " + user_title
}
if (route.params[1] === "referrals"){
page_title = tt('referrals_jsx.title') + " " + user_title
}
if(route.params[1] === "curation-rewards"){
page_title = tt('header_jsx.curation_rewards_by') + " " + user_title;
}
Expand Down
132 changes: 132 additions & 0 deletions app/components/modules/Referrals.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import React from 'react'
import { Link } from 'react-router'
import { connect } from 'react-redux'
import tt from 'counterpart'
import { Asset } from 'golos-lib-js/lib/utils'
import CopyToClipboard from 'react-copy-to-clipboard'

import DateJoinWrapper from 'app/components/elements/DateJoinWrapper'
import Icon from 'app/components/elements/Icon'
import LoadingIndicator from 'app/components/elements/LoadingIndicator'
import TimeAgoWrapper from 'app/components/elements/TimeAgoWrapper'
import LinkEx from 'app/utils/LinkEx'
import { getLastSeen } from 'app/utils/NormalizeProfile'
import { vestsToSteem } from 'app/utils/StateFunctions'

class Referrals extends React.Component {
constructor(props) {
super(props)
}

state = {
}

render() {
const { referrals, account } = this.props

const props = this.props.props.toJS()

if (!referrals || !referrals.get('loaded')){
return <div style={{ paddingBottom: '1rem' }}>
<h3>{tt('referrals_jsx.title')}</h3>
<LoadingIndicator type='circle' />
</div>
}

const refs = referrals.get('data').toJS()

let count = 0

let items = refs.map(ref => {
++count

const { accounts } = this.props
const acc = accounts.toJS()[ref.account]
let lastSeen
if (acc) {
lastSeen = getLastSeen(acc)
}

const golosRewards = Asset(ref.referrer_rewards).plus(Asset(ref.referrer_donate_rewards))

return <tr key={ref.account} className={count % 2 == 0 ? '' : 'zebra'}>
<td>
<LinkEx to={'/@' + ref.account}><b>
{ref.account}
</b></LinkEx>
</td>
{acc && <td title={tt('referrals_jsx.vs')}>
{vestsToSteem(acc.vesting_shares, props) + ' GOLOS'}
</td>}
{acc && <td title={tt('referrals_jsx.posts')}>
{tt('user_profile.post_count', {count: acc.post_count || 0})}
</td>}
<td>
<span title={tt('referrals_jsx.rewards')}>
{' +'}
{golosRewards.floatString}
</span>
{ref.referrer_donate_rewards_uia ? <span title={tt('referrals_jsx.donates_uia')}>
{' + ' + ref.referrer_donate_rewards_uia + ' UIA'}</span> : null}
</td>
<td title={tt('referrals_jsx.joined')}>
<DateJoinWrapper date={ref.joined} />
</td>
<td title={tt('referrals_jsx.last')}>
{lastSeen && <TimeAgoWrapper date={`${lastSeen}`} />}
</td>
</tr>
})

let refUrl
if (account) {
refUrl = 'https://' + $STM_Config.site_domain + '/welcome?invite=' + account.name
}

return <div style={{ paddingBottom: '1rem' }}>
<h3 style={{ display: 'inline-block' }}>{tt('referrals_jsx.title')}</h3>
{refUrl && <span style={{float: 'right', fontSize: '85%'}} title={tt('g.referral_link_title')}>
<Icon name="hf/hf5" size="2x" />
{' '}{tt('g.referral_link')}{' - '}
<span style={{border: '1px solid lightgray', padding: '5px', borderRadius: '3px'}}>
<a target="_blank" href={refUrl}>{refUrl}</a>
</span>
<CopyToClipboard text={refUrl}>
<span style={{cursor: 'pointer'}}>
<Icon name="copy" size="2x" />
</span>
</CopyToClipboard>
</span>}
<div>{tt('referrals_jsx.desc')}</div>
<table style={{marginTop: '1rem'}}>
<thead>
<th>{tt('referrals_jsx.name')}</th>
<th>{tt('referrals_jsx.vs')}</th>
<th>{tt('referrals_jsx.posts')}</th>
<th>{tt('referrals_jsx.rewards')}</th>
<th>{tt('referrals_jsx.joined')}</th>
<th>{tt('referrals_jsx.last')}</th>
</thead>
<tbody>
{items}
</tbody></table>
</div>
}
}


export default connect(
state => {
const referrals = state.global.get('referrals')
const accounts = state.global.get('accounts')
const props = state.global.get('props')

return {
referrals,
accounts,
props
}
},
dispatch => ({
})
)(Referrals)
9 changes: 9 additions & 0 deletions app/components/pages/UserProfile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import UserKeys from 'app/components/elements/UserKeys';
import Settings from 'app/components/modules/Settings';
import ReputationHistory from 'app/components/modules/ReputationHistory'
import Mentions from 'app/components/modules/Mentions'
import Referrals from 'app/components/modules/Referrals'
import Sponsors from 'app/components/modules/Sponsors'
import UserList from 'app/components/elements/UserList';
import Follow from 'app/components/elements/Follow';
Expand Down Expand Up @@ -398,6 +399,11 @@ export default class UserProfile extends React.Component {
<Sponsors account={account} current_user={current_user} />
<MarkNotificationRead fields='new_sponsor,sponsor_inactive' account={account.name} />
</div>
} else if (section === 'referrals') {
tab_content = <div>
<Referrals account={account} current_user={current_user} />
<MarkNotificationRead fields='referral' account={account.name} />
</div>
}

tab_content = <div className='row'>
Expand Down Expand Up @@ -514,6 +520,9 @@ export default class UserProfile extends React.Component {
<span className='sponsors_notify'><Link to={`/@${accountname}/sponsors`}>{tt('user_profile.sponsor_count', {count: account.sponsor_count || 0})}
{isMyAccount && <NotifiCounter fields='new_sponsor,sponsor_inactive' />}
</Link></span>
<span className='sponsors_notify'><Link to={`/@${accountname}/referrals`}>{tt('user_profile.referral_count', {count: account.referral_count || 0})}
{isMyAccount && <NotifiCounter fields='referral' />}
</Link></span>
</div>
<p className='UserProfile__info'>
{location && <span><Icon name='location' /> {location}</span>}
Expand Down
16 changes: 16 additions & 0 deletions app/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,17 @@
"responses": "responses",
"popular": "popular"
},
"referrals_jsx": {
"title": "Referrals",
"joined": "Registration",
"last": "Last activity",
"vs": "Golos Power",
"posts": "Post count",
"rewards": "Rewards and donates for referrer",
"donates_uia": "Donates in UIA",
"desc": "During the year, 10%% of rewards of users (registered by your referral link or invite codes) will be arrive to your TIP-balance (donates) and Golos Power (author rewards).",
"name": "Name"
},
"sponsorslist_jsx": {
"payment": "Payment",
"payment_hint": "Next payment, will be claimed automatically",
Expand Down Expand Up @@ -524,6 +535,11 @@
"one": "1 sponsor",
"other": "%(count)s sponsors"
},
"referral_count": {
"zero": "No referrals",
"one": "1 referral",
"other": "%(count)s referrals"
},
"account_frozen": "Account is temporarily deactivated."
},
"plurals": {
Expand Down
16 changes: 16 additions & 0 deletions app/locales/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,17 @@
"sponsored_authors": "Спонсируемые авторы",
"created": "Создано"
},
"referrals_jsx": {
"title": "Рефералы",
"joined": "Регистрация",
"last": "Последняя активность",
"vs": "Сила Голоса",
"posts": "Кол-во постов",
"rewards": "Выплаты и донаты рефереру",
"donates_uia": "Донаты рефереру в UIA",
"desc": "В течение года 10%% от вознаграждений пользователей (зарегистрированных по вашей реферальной ссылке или инвайт-чеку) будут поступать на ваш TIP-баланс (донаты) и Силу Голоса (авторские награды).",
"name": "Имя"
},
"sponsorslist_jsx": {
"payment": "Платеж",
"payment_hint": "Следующий платеж, спишется автоматически",
Expand Down Expand Up @@ -898,6 +909,11 @@
"one": "1 спонсор",
"other": "%(count)s спонсоров"
},
"referral_count": {
"zero": "0 рефералов",
"one": "1 реферал",
"other": "%(count)s рефералов"
},
"account_frozen": "Аккаунт временно деактивирован."
},
"invites_jsx": {
Expand Down
18 changes: 18 additions & 0 deletions app/redux/FetchDataSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export function* fetchState(location_change_action) {
state.tokens = []
state.sponsors = { data: [] }
state.sponsoreds = { data: [] }
state.referrals = { data: [] }
state.minused_accounts = {}
state.accounts = {}
state.confetti_nft_active = false
Expand Down Expand Up @@ -283,6 +284,23 @@ export function* fetchState(location_change_action) {
}
break

case 'referrals':
state.referrals = {
data: yield call([api, api.getReferralsAsync], {
referrer: uname,
start_name: '',
limit: 100
}),
loaded: true
}

state.props = yield call([api, api.getDynamicGlobalProperties])

for (const referral of state.referrals.data) {
accounts.add(referral.account)
}
break

case 'blog':
default:
const blogEntries = yield call([api, api.getBlogEntriesAsync], uname, 0, 20, ['fm-'], {})
Expand Down
1 change: 1 addition & 0 deletions app/redux/GlobalReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default createModule({
res = res.delete('pso')
}
res = res.setIn(['sponsoreds', 'data'], List())
res = res.setIn(['referrals', 'data'], List())
if (res.has('nft_tokens'))
res = res.delete('nft_tokens')
res = res.mergeDeep(payload);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"foundation-sites": "^6.4.3",
"fs-extra": "^10.0.1",
"git-rev-sync": "^3.0.2",
"golos-lib-js": "^0.9.56",
"golos-lib-js": "^0.9.61",
"history": "^2.0.0-rc2",
"immutable": "^3.8.2",
"intl": "^1.2.5",
Expand Down Expand Up @@ -89,6 +89,7 @@
"react": "^18.2.0",
"react-addons-pure-render-mixin": "^15.6.3",
"react-cookie": "1.0.4",
"react-copy-to-clipboard": "^5.1.0",
"react-dom": "^18.2.0",
"react-dom-confetti": "^0.1.3",
"react-dropzone": "^4.2.12",
Expand Down
Loading

0 comments on commit db95e80

Please sign in to comment.