diff --git a/api/views.py b/api/views.py index c991b3b6..70cd26fc 100644 --- a/api/views.py +++ b/api/views.py @@ -748,6 +748,8 @@ class UserView(APIView): login(request, user) context["public_key"] = user.profile.public_key context["encrypted_private_key"] = user.profile.encrypted_private_key + context["earned_rewards"] = user.profile.earned_rewards + context["referral_code"] = str(user.profile.referral_code) # return active order or last made order if any has_no_active_order, _, order = Logics.validate_already_maker_or_taker(request.user) diff --git a/frontend/src/components/BottomBar.js b/frontend/src/components/BottomBar.js index 2cf5a0d5..64108fc7 100644 --- a/frontend/src/components/BottomBar.js +++ b/frontend/src/components/BottomBar.js @@ -46,8 +46,6 @@ class BottomBar extends Component { alternative_site: 'robosats...', node_id: '00000000', showRewards: false, - referral_code: '', - earned_rewards: 0, rewardInvoice: null, badInvoice: false, showRewardsSpinner: false, @@ -67,7 +65,9 @@ class BottomBar extends Component { & this.props.setAppState({nickname:data.nickname, loading:false, activeOrderId: data.active_order_id ? data.active_order_id : null, - lastOrderId: data.last_order_id ? data.last_order_id : null})); + lastOrderId: data.last_order_id ? data.last_order_id : null, + referralCode: data.referral_code, + earnedRewards: data.earned_rewards,})); } handleClickOpenStatsForNerds = () => { @@ -111,10 +111,13 @@ class BottomBar extends Component { .then((data) => this.setState({ badInvoice:data.bad_invoice, openClaimRewards: data.successful_withdrawal ? false : true, - earned_rewards: data.successful_withdrawal ? 0 : this.state.earned_rewards, withdrawn: data.successful_withdrawal ? true : false, showRewardsSpinner: false, - })); + }) + & this.props.setAppState({ + earnedRewards: data.successful_withdrawal ? 0 : this.props.earnedRewards, + }) + ); e.preventDefault(); } @@ -129,7 +132,7 @@ class BottomBar extends Component { bottomBarDesktop =()=>{ const { t } = this.props; - var hasRewards = this.state.earned_rewards > 0 ? true: false; + var hasRewards = this.props.earnedRewards > 0 ? true: false; var hasOrder = this.props.activeOrderId > 0 & !this.state.profileShown & this.props.avatarLoaded ? true : false; return( @@ -316,7 +319,10 @@ bottomBarDesktop =()=>{ } handleClickOpenExchangeSummary = () => { - this.getInfo(); + // avoid calling getInfo while sessionid not yet set. Temporary fix. + if(getCookie('sessionid')){ + this.getInfo(); + } this.setState({openExchangeSummary: true}); }; handleClickCloseExchangeSummary = () => { @@ -325,7 +331,7 @@ bottomBarDesktop =()=>{ bottomBarPhone =()=>{ const { t } = this.props; - var hasRewards = this.state.earned_rewards > 0 ? true: false; + var hasRewards = this.props.earnedRewards > 0 ? true: false; var hasOrder = this.state.active_order_id > 0 & !this.state.profileShown & this.props.avatarLoaded ? true : false; return( @@ -464,13 +470,13 @@ bottomBarPhone =()=>{ nickname={this.props.nickname} activeOrderId={this.props.activeOrderId} lastOrderId={this.props.lastOrderId} - referralCode={this.state.referral_code} + referralCode={this.props.referralCode} handleSubmitInvoiceClicked={this.handleSubmitInvoiceClicked} host={this.getHost()} showRewardsSpinner={this.state.showRewardsSpinner} withdrawn={this.state.withdrawn} badInvoice={this.state.badInvoice} - earnedRewards={this.state.earned_rewards} + earnedRewards={this.props.earnedRewards} setAppState={this.props.setAppState} /> diff --git a/frontend/src/components/HomePage.js b/frontend/src/components/HomePage.js index 834537b6..55205e1b 100644 --- a/frontend/src/components/HomePage.js +++ b/frontend/src/components/HomePage.js @@ -24,6 +24,8 @@ export default class HomePage extends Component { bookLoading: true, activeOrderId: null, lastOrderId: null, + earnedRewards: 0, + referralCode:'', } } diff --git a/frontend/src/components/UserGenPage.js b/frontend/src/components/UserGenPage.js index 39c736f7..4400ffe0 100644 --- a/frontend/src/components/UserGenPage.js +++ b/frontend/src/components/UserGenPage.js @@ -93,6 +93,8 @@ class UserGenPage extends Component { nickname: data.nickname, avatarLoaded: false, activeOrderId: data.active_order_id ? data.active_order_id : null, + referralCode: data.referral_code, + earnedRewards: data.earned_rewards, lastOrderId: data.last_order_id ? data.last_order_id : null, }) : @@ -102,6 +104,8 @@ class UserGenPage extends Component { avatarLoaded: false, activeOrderId: data.active_order_id ? data.active_order_id : null, lastOrderId: data.last_order_id ? data.last_order_id : null, + referralCode: data.referral_code, + earnedRewards: data.earned_rewards, })) & writeCookie("robot_token",token) & writeCookie("pub_key",data.public_key.split('\n').join('\\')) & writeCookie("enc_priv_key",data.encrypted_private_key.split('\n').join('\\')))