Skip to content

Commit

Permalink
Support EUR tipping lbryio#1222
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeaux authored and infinite-persistence committed Mar 30, 2022
2 parents cc8812d + beaf425 commit 911ccaa
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 42 deletions.
3 changes: 3 additions & 0 deletions ui/component/claimSupportButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { connect } from 'react-redux';
import { doOpenModal } from 'redux/actions/app';
import { makeSelectTagInClaimOrChannelForUri, selectClaimForUri } from 'redux/selectors/claims';
import ClaimSupportButton from './view';
import { selectClientSetting } from 'redux/selectors/settings';
import * as SETTINGS from 'constants/settings';

const DISABLE_SUPPORT_TAG = 'disable-support';

Expand All @@ -14,6 +16,7 @@ const select = (state, props) => {
return {
disableSupport: makeSelectTagInClaimOrChannelForUri(uri, DISABLE_SUPPORT_TAG)(state),
isRepost,
preferredCurrency: selectClientSetting(state, SETTINGS.PREFERRED_CURRENCY),
};
};

Expand Down
20 changes: 17 additions & 3 deletions ui/component/claimSupportButton/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,32 @@ type Props = {
disableSupport: boolean,
isRepost?: boolean,
doOpenModal: (id: string, {}) => void,
preferredCurrency: string,
};

export default function ClaimSupportButton(props: Props) {
const { uri, fileAction, isRepost, disableSupport, doOpenModal } = props;
const { uri, fileAction, isRepost, disableSupport, doOpenModal, preferredCurrency } = props;

const currencyToUse = preferredCurrency;

const iconToUse = {
EUR: {
icon: ICONS.EURO,
iconSize: 16,
},
USD: {
icon: ICONS.FINANCE,
iconSize: fileAction ? 22 : undefined,
},
};

return disableSupport ? null : (
<Tooltip title={__('Support this claim')} arrow={false}>
<Button
button={!fileAction ? 'alt' : undefined}
className={classnames('support-claim-button', { 'button--file-action': fileAction })}
icon={ICONS.FINANCE}
iconSize={fileAction ? 22 : undefined}
icon={iconToUse[currencyToUse].icon}
iconSize={iconToUse[currencyToUse].iconSize}
label={isRepost ? __('Support Repost') : __('Support --[button to support a claim]--')}
requiresAuth
onClick={() => doOpenModal(MODALS.SEND_TIP, { uri, isSupport: true })}
Expand Down
3 changes: 3 additions & 0 deletions ui/component/commentCreate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { selectActiveChannelClaim } from 'redux/selectors/app';
import { selectSettingsByChannelId } from 'redux/selectors/comments';
import { getChannelIdFromClaim } from 'util/claim';
import { doOpenModal } from 'redux/actions/app';
import { selectClientSetting } from 'redux/selectors/settings';
import * as SETTINGS from 'constants/settings';

const select = (state, props) => {
const { uri } = props;
Expand Down Expand Up @@ -42,6 +44,7 @@ const select = (state, props) => {
isFetchingChannels: selectFetchingMyChannels(state),
settingsByChannelId: selectSettingsByChannelId(state),
supportDisabled: makeSelectTagInClaimOrChannelForUri(uri, DISABLE_SUPPORT_TAG)(state),
preferredCurrency: selectClientSetting(state, SETTINGS.PREFERRED_CURRENCY),
};
};

Expand Down
45 changes: 33 additions & 12 deletions ui/component/commentCreate/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,18 @@ type Props = {
doFetchCreatorSettings: (channelId: string) => Promise<any>,
doToast: ({ message: string }) => void,
doCommentById: (commentId: string, toastIfNotFound: boolean) => Promise<any>,
doSendCashTip: (TipParams, anonymous: boolean, UserParams, claimId: string, stripe: ?string, (any) => void) => string,
doSendCashTip: (
TipParams,
anonymous: boolean,
UserParams,
claimId: string,
stripe: ?string,
preferredCurrency: string,
(any) => void
) => string,
doSendTip: (params: {}, isSupport: boolean, successCb: (any) => void, errorCb: (any) => void, boolean) => void,
doOpenModal: (id: string, any) => void,
preferredCurrency: string,
};

export function CommentCreate(props: Props) {
Expand Down Expand Up @@ -101,6 +110,7 @@ export function CommentCreate(props: Props) {
doSendTip,
setQuickReply,
doOpenModal,
preferredCurrency,
} = props;

const isMobile = useIsMobile();
Expand Down Expand Up @@ -306,17 +316,25 @@ 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) => {
const { payment_intent_id } = customerTipResponse;
doSendCashTip(
tipParams,
false,
userParams,
claimId,
stripeEnvironment,
preferredCurrency,
(customerTipResponse) => {
const { payment_intent_id } = customerTipResponse;

handleCreateComment(null, payment_intent_id, stripeEnvironment);
handleCreateComment(null, payment_intent_id, stripeEnvironment);

setCommentValue('');
setReviewingSupportComment(false);
setTipSelector(false);
setCommentFailure(false);
setSubmitting(false);
});
setCommentValue('');
setReviewingSupportComment(false);
setTipSelector(false);
setCommentFailure(false);
setSubmitting(false);
}
);
}
}

Expand Down Expand Up @@ -382,6 +400,9 @@ export function CommentCreate(props: Props) {
setTipSelector(false);
}

let fiatIconToUse = ICONS.FINANCE;
if (preferredCurrency === 'EUR') fiatIconToUse = ICONS.EURO;

// **************************************************************************
// Effects
// **************************************************************************
Expand Down Expand Up @@ -640,7 +661,7 @@ export function CommentCreate(props: Props) {
<Button
{...submitButtonProps}
disabled={disabled || tipSelectorError || !minAmountMet}
icon={activeTab === TAB_LBC ? ICONS.LBC : ICONS.FINANCE}
icon={activeTab === TAB_LBC ? ICONS.LBC : fiatIconToUse}
label={__('Review')}
onClick={() => {
setReviewingSupportComment(true);
Expand Down Expand Up @@ -682,7 +703,7 @@ export function CommentCreate(props: Props) {
<TipActionButton {...tipButtonProps} name={__('Credits')} icon={ICONS.LBC} tab={TAB_LBC} />

{stripeEnvironment && (
<TipActionButton {...tipButtonProps} name={__('Cash')} icon={ICONS.FINANCE} tab={TAB_FIAT} />
<TipActionButton {...tipButtonProps} name={__('Cash')} icon={fiatIconToUse} tab={TAB_FIAT} />
)}
</>
)}
Expand Down
20 changes: 20 additions & 0 deletions ui/component/common/icon-custom.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,26 @@ export const icons = {
<path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6" />
</g>
),
[ICONS.EURO]: (props: CustomProps) => (
<svg
{...props}
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 48 48"
width={props.size || '16'}
height={props.size || '18'}
fill="none"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="1.5"
stroke="currentColor"
>
<g transform="matrix(2,0,0,2,0,0)">
<path d="M19.5,23.25a11.25,11.25,0,0,1,0-22.5" />
<path d="M4.5 9.75L16.5 9.75" />
<path d="M4.5 14.25L13.5 14.25" />
</g>
</svg>
),
[ICONS.RABBIT_HOLE]: (props: CustomProps) => (
<svg
{...props}
Expand Down
2 changes: 1 addition & 1 deletion ui/component/txoList/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ function TxoList(props: Props) {
className={classnames(`button-toggle`, {
'button-toggle--active': currency === 'fiat',
})}
label={__('USD --[transactions tab]--')}
label={__('Currency --[transactions tab]--')}
/>
</div>
</fieldset-section>
Expand Down
38 changes: 33 additions & 5 deletions ui/component/walletFiatAccountHistory/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ const WalletBalance = (props: Props) => {
// accountTransactions.length = 10;
// }

function getSymbol(transaction) {
if (transaction.currency === 'eur') {
return '€';
} else {
return '$';
}
}

function getCurrencyIso(transaction) {
if (transaction.currency === 'eur') {
return 'EUR';
} else {
return 'USD';
}
}

return (
<div className="table__wrapper">
<table className="table table--transactions">
Expand All @@ -32,7 +48,7 @@ const WalletBalance = (props: Props) => {
<th className="date-header">{__('Date')}</th>
<th className="channelName-header">{<>{__('Receiving Channel Name')}</>}</th>
<th className="location-header">{__('Tip Location')}</th>
<th className="amount-header">{__('Amount (USD)')} </th>
<th className="amount-header">{__('Amount')} </th>
<th className="processingFee-header">{__('Processing Fee')}</th>
<th className="odyseeFee-header">{__('Odysee Fee')}</th>
<th className="receivedAmount-header">{__('Received Amount')}</th>
Expand Down Expand Up @@ -63,10 +79,22 @@ const WalletBalance = (props: Props) => {
button="link"
/>
</td>
<td>${transaction.tipped_amount / 100}</td>
<td>${transaction.transaction_fee / 100}</td>
<td>${transaction.application_fee / 100}</td>
<td>${transaction.received_amount / 100}</td>
<td>
{getSymbol(transaction)}
{transaction.tipped_amount / 100} {getCurrencyIso(transaction)}
</td>
<td>
{getSymbol(transaction)}
{transaction.transaction_fee / 100}
</td>
<td>
{getSymbol(transaction)}
{transaction.application_fee / 100}
</td>
<td>
{getSymbol(transaction)}
{transaction.received_amount / 100}
</td>
</tr>
))}
</tbody>
Expand Down
1 change: 1 addition & 0 deletions ui/component/walletSendTip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
};

Expand Down
40 changes: 33 additions & 7 deletions ui/component/walletSendTip/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,18 @@ type Props = {
hasSelectedTab?: string,
customText?: string,
doHideModal: () => void,
doSendCashTip: (TipParams, boolean, UserParams, string, ?string) => string,
doSendCashTip: (
TipParams,
anonymous: boolean,
UserParams,
claimId: string,
stripe: ?string,
preferredCurrency: string,
?(any) => void
) => string,
doSendTip: (SupportParams, boolean) => void, // function that comes from lbry-redux
setAmount?: (number) => void,
preferredCurrency: string,
};

export default function WalletSendTip(props: Props) {
Expand All @@ -75,6 +84,7 @@ export default function WalletSendTip(props: Props) {
doSendCashTip,
doSendTip,
setAmount,
preferredCurrency,
} = props;

/** WHAT TAB TO SHOW **/
Expand Down Expand Up @@ -118,8 +128,10 @@ 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. ');
Expand Down Expand Up @@ -192,7 +204,14 @@ 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 (?)
Expand Down Expand Up @@ -224,7 +243,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 });
}
Expand All @@ -247,6 +266,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 */}
Expand All @@ -260,7 +286,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 */}
Expand Down Expand Up @@ -298,7 +324,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} />
)}
Expand Down
3 changes: 3 additions & 0 deletions ui/component/walletTipAmountSelector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import { connect } from 'react-redux';
import { selectBalance } from 'redux/selectors/wallet';
import { selectClaimForUri } from 'redux/selectors/claims';
import WalletTipAmountSelector from './view';
import { selectClientSetting } from 'redux/selectors/settings';
import * as SETTINGS from 'constants/settings';

const select = (state, props) => ({
balance: selectBalance(state),
claim: selectClaimForUri(state, props.uri),
preferredCurrency: selectClientSetting(state, SETTINGS.PREFERRED_CURRENCY),
});

export default connect(select)(WalletTipAmountSelector);

0 comments on commit 911ccaa

Please sign in to comment.