allow user to save currency on client
This commit is contained in:
parent
fed8fafe6c
commit
5a2684643e
4 changed files with 24 additions and 6 deletions
|
@ -4,7 +4,9 @@ import OdyseeMembership from './view';
|
||||||
import { selectActiveChannelClaim, selectIncognito } from 'redux/selectors/app';
|
import { selectActiveChannelClaim, selectIncognito } from 'redux/selectors/app';
|
||||||
import { selectMyChannelClaims, selectClaimsByUri } from 'redux/selectors/claims';
|
import { selectMyChannelClaims, selectClaimsByUri } from 'redux/selectors/claims';
|
||||||
import { doFetchUserMemberships, doCheckUserOdyseeMemberships } from 'redux/actions/user';
|
import { doFetchUserMemberships, doCheckUserOdyseeMemberships } from 'redux/actions/user';
|
||||||
|
import { selectClientSetting } from 'redux/selectors/settings';
|
||||||
import { selectUser, selectUserLocale } from 'redux/selectors/user';
|
import { selectUser, selectUserLocale } from 'redux/selectors/user';
|
||||||
|
import * as SETTINGS from 'constants/settings';
|
||||||
|
|
||||||
const select = (state) => {
|
const select = (state) => {
|
||||||
const activeChannelClaim = selectActiveChannelClaim(state);
|
const activeChannelClaim = selectActiveChannelClaim(state);
|
||||||
|
@ -16,6 +18,7 @@ const select = (state) => {
|
||||||
incognito: selectIncognito(state),
|
incognito: selectIncognito(state),
|
||||||
user: selectUser(state),
|
user: selectUser(state),
|
||||||
locale: selectUserLocale(state),
|
locale: selectUserLocale(state),
|
||||||
|
preferredCurrency: selectClientSetting(state, SETTINGS.PREFERRED_CURRENCY),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ type Props = {
|
||||||
updateUserOdyseeMembershipStatus: () => void,
|
updateUserOdyseeMembershipStatus: () => void,
|
||||||
user: ?User,
|
user: ?User,
|
||||||
locale: ?LocaleInfo,
|
locale: ?LocaleInfo,
|
||||||
|
preferredCurrency: ?string,
|
||||||
};
|
};
|
||||||
|
|
||||||
const OdyseeMembershipPage = (props: Props) => {
|
const OdyseeMembershipPage = (props: Props) => {
|
||||||
|
@ -55,6 +56,7 @@ const OdyseeMembershipPage = (props: Props) => {
|
||||||
incognito,
|
incognito,
|
||||||
user,
|
user,
|
||||||
locale,
|
locale,
|
||||||
|
preferredCurrency,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const userChannelName = activeChannelClaim ? activeChannelClaim.name : '';
|
const userChannelName = activeChannelClaim ? activeChannelClaim.name : '';
|
||||||
|
@ -196,8 +198,13 @@ const OdyseeMembershipPage = (props: Props) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (locale?.continent === 'EU') {
|
// use currency if set on client, otherwise use USD by default or EUR if in Europe
|
||||||
setCurrencyToUse('eur');
|
if (preferredCurrency) {
|
||||||
|
setCurrencyToUse(preferredCurrency.toLowerCase());
|
||||||
|
} else {
|
||||||
|
if (locale?.continent === 'EU') {
|
||||||
|
setCurrencyToUse('eur');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
populateMembershipData();
|
populateMembershipData();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { doSetClientSetting } from 'redux/actions/settings';
|
import { doSetClientSetting } from 'redux/actions/settings';
|
||||||
import { selectClientSetting } from 'redux/selectors/settings';
|
import { selectClientSetting } from 'redux/selectors/settings';
|
||||||
import { selectUserVerifiedEmail, selectUserEmail } from 'redux/selectors/user';
|
import { selectUserVerifiedEmail, selectUserEmail, selectUserLocale } from 'redux/selectors/user';
|
||||||
import { doOpenModal } from 'redux/actions/app';
|
import { doOpenModal } from 'redux/actions/app';
|
||||||
import { doToast } from 'redux/actions/notifications';
|
import { doToast } from 'redux/actions/notifications';
|
||||||
import * as SETTINGS from 'constants/settings';
|
import * as SETTINGS from 'constants/settings';
|
||||||
|
@ -12,6 +12,7 @@ const select = (state) => ({
|
||||||
isAuthenticated: Boolean(selectUserVerifiedEmail(state)),
|
isAuthenticated: Boolean(selectUserVerifiedEmail(state)),
|
||||||
email: selectUserEmail(state),
|
email: selectUserEmail(state),
|
||||||
preferredCurrency: selectClientSetting(state, SETTINGS.PREFERRED_CURRENCY),
|
preferredCurrency: selectClientSetting(state, SETTINGS.PREFERRED_CURRENCY),
|
||||||
|
locale: selectUserLocale(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = (dispatch) => ({
|
const perform = (dispatch) => ({
|
||||||
|
|
|
@ -29,6 +29,7 @@ type Props = {
|
||||||
doOpenModal: (string, {}) => void,
|
doOpenModal: (string, {}) => void,
|
||||||
openModal: (string, {}) => void,
|
openModal: (string, {}) => void,
|
||||||
setAsConfirmingCard: () => void,
|
setAsConfirmingCard: () => void,
|
||||||
|
locale: ?any,
|
||||||
};
|
};
|
||||||
|
|
||||||
// type State = {
|
// type State = {
|
||||||
|
@ -59,12 +60,19 @@ class SettingsStripeCard extends React.Component<Props, State> {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
let that = this;
|
let that = this;
|
||||||
|
|
||||||
const { preferredCurrency } = this.props;
|
const { preferredCurrency, locale } = this.props;
|
||||||
|
|
||||||
|
// use preferredCurrency if it's set on client, otherwise use USD, unless in Europe then use EUR
|
||||||
if (preferredCurrency) {
|
if (preferredCurrency) {
|
||||||
that.setState({
|
that.setState({
|
||||||
preferredCurrency: preferredCurrency,
|
preferredCurrency: preferredCurrency,
|
||||||
});
|
});
|
||||||
|
} else if (locale) {
|
||||||
|
if (locale.continent === 'EU') {
|
||||||
|
that.setState({
|
||||||
|
preferredCurrency: 'EUR',
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let doToast = this.props.doToast;
|
let doToast = this.props.doToast;
|
||||||
|
@ -355,7 +363,6 @@ class SettingsStripeCard extends React.Component<Props, State> {
|
||||||
};
|
};
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -370,7 +377,7 @@ class SettingsStripeCard extends React.Component<Props, State> {
|
||||||
const { setPreferredCurrency } = this.props;
|
const { setPreferredCurrency } = this.props;
|
||||||
|
|
||||||
// when user changes currency in selector
|
// when user changes currency in selector
|
||||||
function onCurrencyChange(event: SyntheticInputEvent<*>) {
|
function onCurrencyChange(event) {
|
||||||
const { value } = event.target;
|
const { value } = event.target;
|
||||||
|
|
||||||
// update preferred currency in frontend
|
// update preferred currency in frontend
|
||||||
|
|
Loading…
Reference in a new issue