Invite link with no channels #121

Merged
akinwale merged 2 commits from invite-no-channels into master 2020-02-17 06:15:09 +01:00
2 changed files with 30 additions and 1 deletions

View file

@ -21,6 +21,7 @@ import RewardCard from 'component/rewardCard';
import RewardEnrolment from 'component/rewardEnrolment';
import UriBar from 'component/uriBar';
import invitesStyle from 'styles/invites';
import { fetchReferralCode, logPublish } from 'utils/helper';
class InvitesPage extends React.PureComponent {
state = {
@ -47,7 +48,19 @@ class InvitesPage extends React.PureComponent {
pushDrawerStack();
setPlayerVisible();
NativeModules.Firebase.setCurrentScreen('Invites').then(result => {
fetchChannelListMine();
fetchReferralCode(
response => {
if (response && response.length > 0) {
// only need to use the first referral code.
// inviteLink will be updated after channels are loaded (if the user has created at least one channel)
this.setState({ inviteLink: `https://lbry.tv/$/invite/${response[0]}` });
}
fetchChannelListMine();
},
error => {
fetchChannelListMine();
},
);
fetchInviteStatus();
});
};
@ -62,6 +75,7 @@ class InvitesPage extends React.PureComponent {
const filtered = channels.filter(c => c.name === channelName);
if (filtered.length > 0) {
const channel = filtered[0];
logPublish(channel);
this.setState({ channelName, inviteLink: this.getLinkForChannel(channel) });
}
}
@ -96,6 +110,7 @@ class InvitesPage extends React.PureComponent {
if (!this.state.channelName && channels && channels.length > 0) {
const firstChannel = channels[0];
logPublish(firstChannel);
this.setState({ channelName: firstChannel.name, inviteLink: this.getLinkForChannel(firstChannel) });
}

View file

@ -400,3 +400,17 @@ export function formatTitle(title) {
return title.length > 80 ? title.substring(0, 77).trim() + '...' : title;
}
export function fetchReferralCode(successCallback, errorCallback) {
Lbryio.call('user_referral_code', 'list')
.then(response => {
if (successCallback) {
successCallback(response);
}
})
.catch(err => {
if (errorCallback) {
errorCallback(err);
}
});
}