allow tips in euros

This commit is contained in:
Anthony 2022-03-28 23:40:56 +02:00 committed by Thomas Zarebczan
parent 631d3cc1f3
commit fe9b33e42b
4 changed files with 31 additions and 10 deletions

View file

@ -308,7 +308,7 @@ export function CommentCreate(props: Props) {
const tipParams: TipParams = { tipAmount: Math.round(tipAmount * 100) / 100, tipChannelName, channelClaimId };
const userParams: UserParams = { activeChannelName, activeChannelId: activeChannelClaimId };
doSendCashTip(tipParams, false, userParams, claimId, stripeEnvironment, (customerTipResponse) => {
doSendCashTip(tipParams, false, userParams, claimId, stripeEnvironment, preferredCurrency, (customerTipResponse) => {
const { payment_intent_id } = customerTipResponse;
handleCreateComment(null, payment_intent_id, stripeEnvironment);

View file

@ -43,6 +43,7 @@ const select = (state, props) => {
instantTipMax: selectClientSetting(state, SETTINGS.INSTANT_PURCHASE_MAX),
isPending: selectIsSendingSupport(state),
title: selectTitleForUri(state, uri),
preferredCurrency: selectClientSetting(state, SETTINGS.PREFERRED_CURRENCY),
};
};

View file

@ -49,6 +49,7 @@ type Props = {
doSendCashTip: (TipParams, boolean, UserParams, string, ?string) => string,
doSendTip: (SupportParams, boolean) => void, // function that comes from lbry-redux
setAmount?: (number) => void,
preferredCurrency?: boolean,
};
export default function WalletSendTip(props: Props) {
@ -75,6 +76,7 @@ export default function WalletSendTip(props: Props) {
doSendCashTip,
doSendTip,
setAmount,
preferredCurrency,
} = props;
/** WHAT TAB TO SHOW **/
@ -118,8 +120,9 @@ export default function WalletSendTip(props: Props) {
confirmLabel = __('Boosting');
break;
case TAB_FIAT:
explainerText = __('Show this channel your appreciation by sending a donation in USD. ');
confirmLabel = __('Tipping Fiat (USD)');
explainerText = __('Show this channel your appreciation by sending a donation in %currencyToUse%. ',
{ currencyToUse: preferredCurrency});
confirmLabel = __('Tipping %currencyToUse%', { currencyToUse: preferredCurrency });
break;
case TAB_LBC:
explainerText = __('Show this channel your appreciation by sending a donation of Credits. ');
@ -192,7 +195,7 @@ export default function WalletSendTip(props: Props) {
const userParams: UserParams = { activeChannelName, activeChannelId };
// hit backend to send tip
doSendCashTip(tipParams, !activeChannelId || incognito, userParams, claimId, stripeEnvironment);
doSendCashTip(tipParams, !activeChannelId || incognito, userParams, claimId, stripeEnvironment, preferredCurrency);
doHideModal();
}
// if it's a boost (?)
@ -224,7 +227,7 @@ export default function WalletSendTip(props: Props) {
case TAB_BOOST:
return titleText;
case TAB_FIAT:
return __('Send a $%displayAmount% Tip', { displayAmount });
return __('Send a %fiatSymbolToUse%%displayAmount% Tip', { displayAmount, fiatSymbolToUse });
case TAB_LBC:
return __('Send a %displayAmount% Credit Tip', { displayAmount });
}
@ -247,6 +250,13 @@ export default function WalletSendTip(props: Props) {
const tabButtonProps = { isOnConfirmationPage, activeTab, setActiveTab };
let fiatIconToUse = ICONS.FINANCE;
let fiatSymbolToUse = '$';
if (preferredCurrency === 'EUR') {
fiatIconToUse = ICONS.EURO;
fiatSymbolToUse = '€';
}
return (
<Form onSubmit={handleSubmit}>
{/* if there is no LBC balance, show user frontend to get credits */}
@ -260,7 +270,7 @@ export default function WalletSendTip(props: Props) {
<div className="section">
{/* tip fiat tab button */}
{stripeEnvironment && (
<TabSwitchButton icon={ICONS.FINANCE} label={__('Tip')} name={TAB_FIAT} {...tabButtonProps} />
<TabSwitchButton icon={fiatIconToUse} label={__('Tip')} name={TAB_FIAT} {...tabButtonProps} />
)}
{/* tip LBC tab button */}
@ -298,7 +308,7 @@ export default function WalletSendTip(props: Props) {
<div className="confirm__label">{confirmLabel}</div>
<div className="confirm__value">
{activeTab === TAB_FIAT ? (
<p>{`$ ${(Math.round(tipAmount * 100) / 100).toFixed(2)}`}</p>
<p>{`${fiatSymbolToUse} ${(Math.round(tipAmount * 100) / 100).toFixed(2)}`}</p>
) : (
<LbcSymbol postfix={tipAmount} size={22} />
)}

View file

@ -715,7 +715,14 @@ export const doCheckPendingTxs = () => (dispatch, getState) => {
}, 30000);
};
export const doSendCashTip = (tipParams, anonymous, userParams, claimId, stripeEnvironment, successCallback) => (
export const doSendCashTip = (
tipParams,
anonymous,
userParams,
claimId,
stripeEnvironment,
preferredCurrency,
successCallback) => (
dispatch
) => {
Lbryio.call(
@ -728,7 +735,7 @@ export const doSendCashTip = (tipParams, anonymous, userParams, claimId, stripeE
creator_channel_claim_id: tipParams.channelClaimId,
tipper_channel_name: anonymous ? '' : userParams.activeChannelName,
tipper_channel_claim_id: anonymous ? '' : userParams.activeChannelId,
currency: 'EUR',
currency: preferredCurrency || 'USD',
anonymous: anonymous,
source_claim_id: claimId,
environment: stripeEnvironment,
@ -736,11 +743,14 @@ export const doSendCashTip = (tipParams, anonymous, userParams, claimId, stripeE
'post'
)
.then((customerTipResponse) => {
const fiatIconToUse = preferredCurrency === 'USD' ? '$' : '€';
dispatch(
doToast({
message: __('You sent $%tipAmount% as a tip to %tipChannelName%, I\'m sure they appreciate it!', {
message: __('You sent %fiatIconToUse%%tipAmount% as a tip to %tipChannelName%, I\'m sure they appreciate it!', {
tipAmount: tipParams.tipAmount,
tipChannelName: tipParams.tipChannelName,
fiatIconToUse,
}),
})
);