add referral link

This commit is contained in:
Sean Yesmunt 2019-02-20 11:14:42 -05:00
parent c95a1a922e
commit 2334ad53e8
6 changed files with 263 additions and 483 deletions

723
dist/bundle.js vendored

File diff suppressed because it is too large Load diff

View file

@ -131,4 +131,5 @@ export {
selectUserInviteStatusFailed,
selectUserInviteNewIsPending,
selectUserInviteNewErrorMessage,
selectUserInviteReferralLink,
} from 'redux/selectors/user';

View file

@ -5,12 +5,12 @@ import querystring from 'querystring';
const Lbryio = {
enabled: true,
authenticationPromise: null,
CONNECTION_STRING: 'https://api.lbry.io/',
};
// We can't use env's because they aren't passed into node_modules
let CONNECTION_STRING = 'https://api.lbry.io/';
Lbryio.setLocalApi = endpoint => {
CONNECTION_STRING = endpoint.replace(/\/*$/, '/'); // exactly one slash at the end;
Lbryio.CONNECTION_STRING = endpoint.replace(/\/*$/, '/'); // exactly one slash at the end;
};
Lbryio.call = (resource, action, params = {}, method = 'get') => {
@ -45,7 +45,7 @@ Lbryio.call = (resource, action, params = {}, method = 'get') => {
return Lbryio.getAuthToken().then(token => {
const fullParams = { auth_token: token, ...params };
const qs = querystring.stringify(fullParams);
let url = `${CONNECTION_STRING}${resource}/${action}?${qs}`;
let url = `${Lbryio.CONNECTION_STRING}${resource}/${action}?${qs}`;
let options = {
method: 'GET',
@ -59,7 +59,7 @@ Lbryio.call = (resource, action, params = {}, method = 'get') => {
},
body: qs,
};
url = `${CONNECTION_STRING}${resource}/${action}`;
url = `${Lbryio.CONNECTION_STRING}${resource}/${action}`;
}
return makeRequest(url, options).then(response => response.data);
@ -174,7 +174,7 @@ Lbryio.authenticate = () => {
};
Lbryio.getStripeToken = () =>
CONNECTION_STRING.startsWith('http://localhost:')
Lbryio.CONNECTION_STRING.startsWith('http://localhost:')
? 'pk_test_NoL1JWL7i1ipfhVId5KfDZgo'
: 'pk_live_e8M4dRNnCCbmpZzduEUZBgJO';

View file

@ -7,6 +7,7 @@ import {
} from 'redux/selectors/user';
import rewards from 'rewards';
import Lbryio from 'lbryio';
import Promise from 'bluebird';
export function doFetchInviteStatus() {
return dispatch => {
@ -14,8 +15,8 @@ export function doFetchInviteStatus() {
type: ACTIONS.USER_INVITE_STATUS_FETCH_STARTED,
});
Lbryio.call('user', 'invite_status')
.then(status => {
Promise.all([Lbryio.call('user', 'invite_status'), Lbryio.call('user_referral_code', 'list')])
.then(([status, code]) => {
dispatch(doRewardList());
dispatch({
@ -23,6 +24,7 @@ export function doFetchInviteStatus() {
data: {
invitesRemaining: status.invites_remaining ? status.invites_remaining : 0,
invitees: status.invitees,
referralLink: `${Lbryio.CONNECTION_STRING}user/refer?r=${code}`,
},
});
})

View file

@ -193,6 +193,7 @@ reducers[ACTIONS.USER_INVITE_STATUS_FETCH_SUCCESS] = (state, action) =>
inviteStatusIsPending: false,
invitesRemaining: action.data.invitesRemaining,
invitees: action.data.invitees,
referralLink: action.data.referralLink,
});
reducers[ACTIONS.USER_INVITE_NEW_STARTED] = state =>

View file

@ -126,3 +126,8 @@ export const selectUserInviteNewErrorMessage = createSelector(
selectState,
state => state.inviteNewErrorMessage
);
export const selectUserInviteReferralLink = createSelector(
selectState,
state => state.referralLink
);