Compare commits

...

54 commits

Author SHA1 Message Date
Anthony
041647d1f6
fix lot of linting errors and make command more userful 2021-08-12 13:53:28 +02:00
Anthony
ab2e9094e3
add subscriptions section 2021-08-11 15:04:15 +02:00
Anthony
ad456cd091
small optimization 2021-08-11 15:04:15 +02:00
Anthony
b7482fb800
add view transactions buttons 2021-08-11 15:04:15 +02:00
Anthony
d5c38759ad
remove transaction listings from settings 2021-08-11 15:04:15 +02:00
Anthony
81fa79301d
couple touchups 2021-08-11 15:04:15 +02:00
Anthony
5b20e99fd8
calculate the total amount of unique creators tipped 2021-08-11 15:04:15 +02:00
Anthony
a3f275409a
adding last features 2021-08-11 15:04:15 +02:00
Anthony
70e423a026
More touchups 2021-08-11 15:04:15 +02:00
Anthony
5e02f5cb54
cleanup 2021-08-11 15:04:15 +02:00
Anthony
661ed562fa
about to add last couple features 2021-08-11 15:04:15 +02:00
Anthony
fa910bde8d
showing total tipped amount 2021-08-11 15:04:15 +02:00
Anthony
2e25fbc3f3
approaching something thats working 2021-08-11 15:04:15 +02:00
Anthony
41486f662d
working but in the wrong component 2021-08-11 15:04:15 +02:00
Anthony
a9c45eac26
display if no transactions or subs 2021-08-11 15:04:15 +02:00
Anthony
852c13d3fe
show filler for subscriptions 2021-08-11 15:04:15 +02:00
Anthony
4c0bc66498
show payments successfully 2021-08-11 15:04:15 +02:00
Anthony
2d9005a8c2
some renaming 2021-08-11 15:04:15 +02:00
Anthony
1decc5ffef
add card last 4 to transaction history 2021-08-11 15:04:15 +02:00
Anthony
3898b8ae9b
add third tab 2021-08-11 15:04:15 +02:00
Anthony
1f70ca7b8d
about to add a third tab 2021-08-11 15:04:15 +02:00
Anthony
a2113973cf
add no transactions thing 2021-08-11 15:04:15 +02:00
Anthony
feeefc7520
transaction listing working 2021-08-11 15:04:15 +02:00
Anthony
9604d9a079
should be fine but keeps crashing 2021-08-11 15:04:15 +02:00
Anthony
360cfe29c8
using es6 to populate data 2021-08-11 15:04:15 +02:00
Anthony
bf8632a506
add fiat transactions 2021-08-11 15:04:15 +02:00
Anthony
a79cc9f699
fixing naming 2021-08-11 15:04:15 +02:00
Anthony
9d49434f58
add wallet fiat balance 2021-08-11 15:04:15 +02:00
Anthony
8eb0fc9847
support setting currency as the default tab via query param 2021-08-11 15:04:15 +02:00
Anthony
9e76f85aff
fiat and lbc tabs coming along 2021-08-11 15:04:15 +02:00
Anthony
3bc2b6ef5d
fix last flow error and touchups 2021-08-11 14:44:40 +02:00
Anthony
891512881c
fixing flow errors 2021-08-10 22:57:01 +02:00
Anthony
b41eeec78e
requested changes 2021-08-10 22:06:13 +02:00
Anthony
5e37b3ebba
bugfix and cleanup 2021-08-10 21:55:38 +02:00
Anthony
8f419fea67
get stuff ready for merge 2021-08-10 21:08:15 +02:00
Anthony
13f49cd169
remove unused conditional 2021-08-10 20:27:58 +02:00
Anthony
9d6bc66eae
eslint fixes 2021-08-10 20:01:46 +02:00
Anthony
8b75ff0e09 fixing bug caused by floating point precision 2021-08-10 13:23:32 -04:00
Anthony
db23d2239d reverse so newest transactions come first 2021-08-10 13:23:32 -04:00
Anthony
f1f8bccd8c one bug left but almost working perfectly 2021-08-10 13:23:32 -04:00
Anthony
32678326d8 increase size of input value 2021-08-10 13:23:32 -04:00
Anthony
177f4aaf42 show decimals value better 2021-08-10 13:23:32 -04:00
Anthony
6e19f790b2 close to working perfectly 2021-08-10 13:23:32 -04:00
Anthony
e831f0e790 automatically truncate to two decimals 2021-08-10 13:23:32 -04:00
Anthony
6648e7d47d show error on account connection page 2021-08-10 13:23:32 -04:00
Anthony
054dd045aa add error toast for card page 2021-08-10 13:23:32 -04:00
Anthony
b7747d085f add toast when someone does a tip for a comment 2021-08-10 13:23:32 -04:00
Anthony
2899c9b3a9 bugfix cant tip fiat if no lbc balance 2021-08-10 13:23:32 -04:00
Anthony
f5828154e0 refactor code a bit remove why isnt this working bit 2021-08-10 13:23:32 -04:00
Anthony
43f40fcabb sum up lbc amounts 2021-08-10 13:23:32 -04:00
Anthony
f2c1474d42 calculate fiat tips properly 2021-08-10 13:23:32 -04:00
Anthony
9debf3ed08 scroll properly when switching tabs 2021-08-10 13:23:32 -04:00
Anthony
ee669c7d3f show superchats in order properly 2021-08-10 13:23:32 -04:00
Anthony
5340d40e05 fix frontend bug 2021-08-10 13:23:32 -04:00
17 changed files with 1334 additions and 438 deletions

View file

@ -38,7 +38,7 @@
"build:dir": "yarn build -- --dir -c.compression=store -c.mac.identity=null",
"crossenv": "./node_modules/cross-env/dist/bin/cross-env",
"lint": "eslint 'ui/**/*.{js,jsx}' && eslint 'web/**/*.{js,jsx}' && eslint 'electron/**/*.js' && flow",
"lint-fix": "eslint --fix 'ui/**/*.{js,jsx}' && eslint --fix 'web/**/*.{js,jsx}' && eslint --fix 'electron/**/*.js' && flow",
"lint-fix": "eslint --fix --quiet 'ui/**/*.{js,jsx}' && eslint --fix --quiet 'web/**/*.{js,jsx}' && eslint --fix --quiet 'electron/**/*.js'",
"format": "prettier 'src/**/*.{js,jsx,scss,json}' --write",
"flow-defs": "flow-typed install",
"precommit": "lint-staged",

View file

@ -131,6 +131,7 @@ export function CommentCreate(props: Props) {
return;
}
// if comment post didn't work, but tip was already made, try again to create comment
if (commentFailure && tipAmount === successTip.tipAmount) {
handleCreateComment(successTip.txid);
return;
@ -147,27 +148,6 @@ export function CommentCreate(props: Props) {
const activeChannelName = activeChannelClaim && activeChannelClaim.name;
const activeChannelId = activeChannelClaim && activeChannelClaim.claim_id;
setIsSubmitting(true);
if (activeTab === TAB_LBC) {
// call sendTip and then run the callback from the response
// second parameter is callback
sendTip(
params,
(response) => {
const { txid } = response;
// todo: why the setTimeout?
setTimeout(() => {
handleCreateComment(txid);
}, 1500);
setSuccessTip({ txid, tipAmount });
},
() => {
// reset the frontend so people can send a new comment
setIsSubmitting(false);
}
);
} else {
// setup variables for tip API
let channelClaimId, tipChannelName;
// if there is a signing channel it's on a file
@ -181,14 +161,43 @@ export function CommentCreate(props: Props) {
tipChannelName = claim.name;
}
setIsSubmitting(true);
if (activeTab === TAB_LBC) {
// call sendTip and then run the callback from the response
// second parameter is callback
sendTip(
params,
(response) => {
const { txid } = response;
// todo: why the setTimeout?
setTimeout(() => {
handleCreateComment(txid);
}, 1500);
doToast({
message: __("You sent %tipAmount% LBRY Credits as a tip to %tipChannelName%, I'm sure they appreciate it!", {
tipAmount: tipAmount, // force show decimal places
tipChannelName,
}),
});
setSuccessTip({ txid, tipAmount });
},
() => {
// reset the frontend so people can send a new comment
setIsSubmitting(false);
}
);
} else {
const sourceClaimId = claim.claim_id;
const roundedAmount = Math.round(tipAmount * 100) / 100;
Lbryio.call(
'customer',
'tip',
{
amount: 100 * roundedAmount, // convert from dollars to cents
{ // round to deal with floating point precision
amount: Math.round(100 * roundedAmount), // convert from dollars to cents
creator_channel_name: tipChannelName, // creator_channel_name
creator_channel_claim_id: channelClaimId,
tipper_channel_name: activeChannelName,

View file

@ -22,7 +22,6 @@ type Props = {
fetchingComments: boolean,
doSuperChatList: (string) => void,
superChats: Array<Comment>,
superChatsTotalAmount: number,
myChannels: ?Array<ChannelClaim>,
};
@ -38,38 +37,27 @@ export default function LivestreamComments(props: Props) {
embed,
doCommentSocketConnect,
doCommentSocketDisconnect,
comments,
comments: commentsByChronologicalOrder,
doCommentList,
fetchingComments,
doSuperChatList,
superChats,
superChatsTotalAmount,
myChannels,
superChats: superChatsByTipAmount,
} = props;
let superChatsFiatAmount, superChatsTotalAmount;
const commentsRef = React.createRef();
const [scrollBottom, setScrollBottom] = React.useState(true);
const [viewMode, setViewMode] = React.useState(VIEW_MODE_CHAT);
const [performedInitialScroll, setPerformedInitialScroll] = React.useState(false);
const claimId = claim && claim.claim_id;
const commentsLength = comments && comments.length;
const commentsToDisplay = viewMode === VIEW_MODE_CHAT ? comments : superChats;
const commentsLength = commentsByChronologicalOrder && commentsByChronologicalOrder.length;
const commentsToDisplay = viewMode === VIEW_MODE_CHAT ? commentsByChronologicalOrder : superChatsByTipAmount;
const discussionElement = document.querySelector('.livestream__comments');
const commentElement = document.querySelector('.livestream-comment');
// todo: implement comment_list --mine in SDK so redux can grab with selectCommentIsMine
function isMyComment(channelId: string) {
if (myChannels != null && channelId != null) {
for (let i = 0; i < myChannels.length; i++) {
if (myChannels[i].claim_id === channelId) {
return true;
}
}
}
return false;
}
React.useEffect(() => {
if (claimId) {
doCommentList(uri, '', 1, 75);
@ -115,6 +103,51 @@ export default function LivestreamComments(props: Props) {
}
}, [commentsLength, discussionElement, handleScroll, performedInitialScroll, setPerformedInitialScroll]);
// sum total amounts for fiat tips and lbc tips
if (superChatsByTipAmount) {
let fiatAmount = 0;
let LBCAmount = 0;
for (const superChat of superChatsByTipAmount) {
if (superChat.is_fiat) {
fiatAmount = fiatAmount + superChat.support_amount;
} else {
LBCAmount = LBCAmount + superChat.support_amount;
}
}
superChatsFiatAmount = fiatAmount;
superChatsTotalAmount = LBCAmount;
}
let superChatsReversed;
// array of superchats organized by fiat or not first, then support amount
if (superChatsByTipAmount) {
const clonedSuperchats = JSON.parse(JSON.stringify(superChatsByTipAmount));
// sort by fiat first then by support amount
superChatsReversed = clonedSuperchats.sort(function(a, b) {
// if both are fiat, organize by support
if (a.is_fiat === b.is_fiat) {
return b.support_amount - a.support_amount;
// otherwise, if they are not both fiat, put the fiat transaction first
} else {
return (a.is_fiat === b.is_fiat) ? 0 : a.is_fiat ? -1 : 1;
}
}).reverse();
}
// todo: implement comment_list --mine in SDK so redux can grab with selectCommentIsMine
function isMyComment(channelId: string) {
if (myChannels != null && channelId != null) {
for (let i = 0; i < myChannels.length; i++) {
if (myChannels[i].claim_id === channelId) {
return true;
}
}
}
return false;
}
if (!claim) {
return null;
}
@ -130,41 +163,55 @@ export default function LivestreamComments(props: Props) {
<div className="card livestream__discussion">
<div className="card__header--between livestream-discussion__header">
<div className="livestream-discussion__title">{__('Live discussion')}</div>
{superChatsTotalAmount > 0 && (
{(superChatsTotalAmount || 0) > 0 && (
<div className="recommended-content__toggles">
{/* the superchats in chronological order button */}
<Button
className={classnames('button-toggle', {
'button-toggle--active': viewMode === VIEW_MODE_CHAT,
})}
label={__('Chat')}
onClick={() => setViewMode(VIEW_MODE_CHAT)}
onClick={function() {
setViewMode(VIEW_MODE_CHAT);
const livestreamCommentsDiv = document.getElementsByClassName('livestream__comments')[0];
const divHeight = livestreamCommentsDiv.scrollHeight;
livestreamCommentsDiv.scrollTop = divHeight;
}}
/>
{/* the button to show superchats listed by most to least support amount */}
<Button
className={classnames('button-toggle', {
'button-toggle--active': viewMode === VIEW_MODE_SUPER_CHAT,
})}
label={
<>
<CreditAmount amount={superChatsTotalAmount} size={8} /> {__('Tipped')}
<CreditAmount amount={superChatsTotalAmount || 0} size={8} /> /
<CreditAmount amount={superChatsFiatAmount || 0} size={8} isFiat /> {' '}{__('Tipped')}
</>
}
onClick={() => setViewMode(VIEW_MODE_SUPER_CHAT)}
onClick={function() {
setViewMode(VIEW_MODE_SUPER_CHAT);
const livestreamCommentsDiv = document.getElementsByClassName('livestream__comments')[0];
const divHeight = livestreamCommentsDiv.scrollHeight;
livestreamCommentsDiv.scrollTop = divHeight * -1;
}}
/>
</div>
)}
</div>
<>
{fetchingComments && !comments && (
{fetchingComments && !commentsByChronologicalOrder && (
<div className="main--empty">
<Spinner />
</div>
)}
<div ref={commentsRef} className="livestream__comments-wrapper">
{viewMode === VIEW_MODE_CHAT && superChatsTotalAmount > 0 && superChats && (
{viewMode === VIEW_MODE_CHAT && superChatsByTipAmount && (superChatsTotalAmount || 0) > 0 && (
<div className="livestream-superchats__wrapper">
<div className="livestream-superchats__inner">
{superChats.map((superChat: Comment) => (
{superChatsByTipAmount.map((superChat: Comment) => (
<Tooltip key={superChat.comment_id} label={superChat.comment}>
<div className="livestream-superchat">
<div className="livestream-superchat__thumbnail">
@ -187,9 +234,23 @@ export default function LivestreamComments(props: Props) {
</div>
)}
{!fetchingComments && comments.length > 0 ? (
{/* top to bottom comment display */}
{!fetchingComments && commentsByChronologicalOrder.length > 0 ? (
<div className="livestream__comments">
{commentsToDisplay.map((comment) => (
{viewMode === VIEW_MODE_CHAT && commentsToDisplay.map((comment) => (
<LivestreamComment
key={comment.comment_id}
uri={uri}
authorUri={comment.channel_url}
commentId={comment.comment_id}
message={comment.comment}
supportAmount={comment.support_amount}
isFiat={comment.is_fiat}
commentIsMine={comment.channel_id && isMyComment(comment.channel_id)}
/>
))}
{viewMode === VIEW_MODE_SUPER_CHAT && superChatsReversed && superChatsReversed.map((comment) => (
<LivestreamComment
key={comment.comment_id}
uri={uri}

View file

@ -0,0 +1,40 @@
import { connect } from 'react-redux';
import {
selectBalance,
selectClaimsBalance,
selectSupportsBalance,
selectTipsBalance,
selectIsFetchingUtxoCounts,
selectUtxoCounts,
doFetchUtxoCounts,
doUtxoConsolidate,
selectIsConsolidatingUtxos,
selectIsMassClaimingTips,
selectPendingConsolidateTxid,
selectPendingMassClaimTxid,
} from 'lbry-redux';
import { doOpenModal } from 'redux/actions/app';
import { selectSyncHash } from 'redux/selectors/sync';
import { selectClaimedRewards } from 'redux/selectors/rewards';
import WalletBalance from './view';
const select = state => ({
balance: selectBalance(state),
claimsBalance: selectClaimsBalance(state) || 0,
supportsBalance: selectSupportsBalance(state) || 0,
tipsBalance: selectTipsBalance(state) || 0,
rewards: selectClaimedRewards(state),
hasSynced: Boolean(selectSyncHash(state)),
fetchingUtxoCounts: selectIsFetchingUtxoCounts(state),
consolidatingUtxos: selectIsConsolidatingUtxos(state),
massClaimingTips: selectIsMassClaimingTips(state),
utxoCounts: selectUtxoCounts(state),
consolidateIsPending: selectPendingConsolidateTxid(state),
massClaimIsPending: selectPendingMassClaimTxid(state),
});
export default connect(select, {
doOpenModal,
doFetchUtxoCounts,
doUtxoConsolidate,
})(WalletBalance);

View file

@ -0,0 +1,166 @@
// @flow
import React from 'react';
import Button from 'component/button';
import Card from 'component/common/card';
import { Lbryio } from 'lbryinc';
import moment from 'moment';
type Props = {
accountDetails: any,
transactions: any,
};
const WalletBalance = (props: Props) => {
// receive transactions from parent component
let accountTransactions = props.transactions;
// reverse so most recent payments come first
if (accountTransactions) {
accountTransactions = accountTransactions.reverse();
}
if (accountTransactions && accountTransactions.length > 10) {
accountTransactions.length = 10;
}
// const [detailsExpanded, setDetailsExpanded] = React.useState(false);
const [accountStatusResponse, setAccountStatusResponse] = React.useState();
const [subscriptions, setSubscriptions] = React.useState([]);
var environment = 'test';
function getAccountStatus() {
return Lbryio.call(
'account',
'status',
{
environment,
},
'post'
);
}
React.useEffect(() => {
(async function() {
const response = await getAccountStatus();
setAccountStatusResponse(response);
console.log(response);
})();
}, []);
return (
<><Card
title={'Tip History'}
body={(
<>
<div className="table__wrapper">
<table className="table table--transactions">
<thead>
<tr>
<th className="date-header">{__('Date')}</th>
<th>{<>{__('Receiving Channel Name')}</>}</th>
<th>{__('Tip Location')}</th>
<th>{__('Amount (USD)')} </th>
<th>{__('Processing Fee')}</th>
<th>{__('Odysee Fee')}</th>
<th>{__('Received Amount')}</th>
</tr>
</thead>
<tbody>
{accountTransactions &&
accountTransactions.map((transaction) => (
<tr key={transaction.name + transaction.created_at}>
<td>{moment(transaction.created_at).format('LLL')}</td>
<td>
<Button
className="stripe__card-link-text"
navigate={'/' + transaction.channel_name + ':' + transaction.channel_claim_id}
label={transaction.channel_name}
button="link"
/>
</td>
<td>
<Button
className="stripe__card-link-text"
navigate={'/' + transaction.channel_name + ':' + transaction.source_claim_id}
label={
transaction.channel_claim_id === transaction.source_claim_id
? 'Channel Page'
: 'File Page'
}
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>
</tr>
))}
</tbody>
</table>
{!accountTransactions && <p style={{textAlign: 'center', marginTop: '20px', fontSize: '13px', color: 'rgb(171, 171, 171)'}}>No Transactions</p>}
</div>
</>
)}
/>
<Card
title={__('Subscriptions')}
body={
<>
<div className="table__wrapper">
<table className="table table--transactions">
<thead>
<tr>
<th className="date-header">{__('Date')}</th>
<th>{<>{__('Receiving Channel Name')}</>}</th>
<th>{__('Tip Location')}</th>
<th>{__('Amount (USD)')} </th>
<th>{__('Card Last 4')}</th>
<th>{__('Anonymous')}</th>
</tr>
</thead>
<tbody>
{subscriptions &&
subscriptions.reverse().map((transaction) => (
<tr key={transaction.name + transaction.created_at}>
<td>{moment(transaction.created_at).format('LLL')}</td>
<td>
<Button
className="stripe__card-link-text"
navigate={'/' + transaction.channel_name + ':' + transaction.channel_claim_id}
label={transaction.channel_name}
button="link"
/>
</td>
<td>
<Button
className="stripe__card-link-text"
navigate={'/' + transaction.channel_name + ':' + transaction.source_claim_id}
label={
transaction.channel_claim_id === transaction.source_claim_id
? 'Channel Page'
: 'File Page'
}
button="link"
/>
</td>
<td>${transaction.tipped_amount / 100}</td>
<td>{lastFour}</td>
<td>{transaction.private_tip ? 'Yes' : 'No'}</td>
</tr>
))}
</tbody>
</table>
{(!subscriptions || subscriptions.length === 0) && <p style={{textAlign: 'center', marginTop: '22px', fontSize: '13px', color: 'rgb(171, 171, 171)'}}>No Subscriptions</p>}
</div>
</>
}
/></>
);
};
export default WalletBalance;

View file

@ -0,0 +1,40 @@
import { connect } from 'react-redux';
import {
selectBalance,
selectClaimsBalance,
selectSupportsBalance,
selectTipsBalance,
selectIsFetchingUtxoCounts,
selectUtxoCounts,
doFetchUtxoCounts,
doUtxoConsolidate,
selectIsConsolidatingUtxos,
selectIsMassClaimingTips,
selectPendingConsolidateTxid,
selectPendingMassClaimTxid,
} from 'lbry-redux';
import { doOpenModal } from 'redux/actions/app';
import { selectSyncHash } from 'redux/selectors/sync';
import { selectClaimedRewards } from 'redux/selectors/rewards';
import WalletBalance from './view';
const select = state => ({
balance: selectBalance(state),
claimsBalance: selectClaimsBalance(state) || 0,
supportsBalance: selectSupportsBalance(state) || 0,
tipsBalance: selectTipsBalance(state) || 0,
rewards: selectClaimedRewards(state),
hasSynced: Boolean(selectSyncHash(state)),
fetchingUtxoCounts: selectIsFetchingUtxoCounts(state),
consolidatingUtxos: selectIsConsolidatingUtxos(state),
massClaimingTips: selectIsMassClaimingTips(state),
utxoCounts: selectUtxoCounts(state),
consolidateIsPending: selectPendingConsolidateTxid(state),
massClaimIsPending: selectPendingMassClaimTxid(state),
});
export default connect(select, {
doOpenModal,
doFetchUtxoCounts,
doUtxoConsolidate,
})(WalletBalance);

View file

@ -0,0 +1,99 @@
// @flow
import * as ICONS from 'constants/icons';
import * as PAGES from 'constants/pages';
import React from 'react';
import CreditAmount from 'component/common/credit-amount';
import Button from 'component/button';
import Card from 'component/common/card';
import Icon from 'component/common/icon';
import I18nMessage from 'component/i18nMessage';
type Props = {
accountDetails: any,
};
const WalletBalance = (props: Props) => {
const {
accountDetails,
} = props;
console.log('account details');
console.log(accountDetails);
const [detailsExpanded, setDetailsExpanded] = React.useState(false);
return (
<>{<Card
title={<><Icon size="18" icon={ICONS.FINANCE} />{(accountDetails && (accountDetails.total_received_unpaid / 100)) || 0} USD</>}
subtitle={
<I18nMessage>
This is your remaining balance that can still be withdrawn to your bank account
</I18nMessage>
}
actions={
<>
<h2 className="section__title--small">
${(accountDetails && (accountDetails.total_tipped / 100)) || 0} Total Received Tips
</h2>
<h2 className="section__title--small">
${(accountDetails && (accountDetails.total_paid_out / 100)) || 0} Withdrawn
<Button
button="link"
label={detailsExpanded ? __('View less') : __('View more')}
iconRight={detailsExpanded ? ICONS.UP : ICONS.DOWN}
onClick={() => setDetailsExpanded(!detailsExpanded)}
/>
</h2>
{/* view more section */}
{detailsExpanded && (
<div className="section__subtitle">
<dl>
<dt>
<span className="dt__text">{__('Earned from uploads')}</span>
{/* <span className="help--dt">({__('Earned from channel page')})</span> */}
</dt>
<dd>
<span className="dd__text">
{Boolean(1) && (
<Button
button="link"
className="dd__button"
icon={ICONS.UNLOCK}
/>
)}
<CreditAmount amount={1} precision={4} />
</span>
</dd>
<dt>
<span className="dt__text">{__('Earned from channel page')}</span>
{/* <span className="help--dt">({__('Delete or edit past content to spend')})</span> */}
</dt>
<dd>
<CreditAmount amount={1} precision={4} />
</dd>
{/* <dt> */}
{/* <span className="dt__text">{__('...supporting content')}</span> */}
{/* <span className="help--dt">({__('Delete supports to spend')})</span> */}
{/* </dt> */}
{/* <dd> */}
{/* <CreditAmount amount={1} precision={4} /> */}
{/* </dd> */}
</dl>
</div>
)}
<div className="section__actions">
<Button button="primary" label={__('Receive Payout')} icon={ICONS.SEND} />
<Button button="secondary" label={__('Account Configuration')} icon={ICONS.SETTINGS} navigate={`/$/${PAGES.SETTINGS_STRIPE_ACCOUNT}`} />
</div>
</>
}
/>}</>
);
};
export default WalletBalance;

View file

@ -0,0 +1,40 @@
import { connect } from 'react-redux';
import {
selectBalance,
selectClaimsBalance,
selectSupportsBalance,
selectTipsBalance,
selectIsFetchingUtxoCounts,
selectUtxoCounts,
doFetchUtxoCounts,
doUtxoConsolidate,
selectIsConsolidatingUtxos,
selectIsMassClaimingTips,
selectPendingConsolidateTxid,
selectPendingMassClaimTxid,
} from 'lbry-redux';
import { doOpenModal } from 'redux/actions/app';
import { selectSyncHash } from 'redux/selectors/sync';
import { selectClaimedRewards } from 'redux/selectors/rewards';
import WalletBalance from './view';
const select = state => ({
balance: selectBalance(state),
claimsBalance: selectClaimsBalance(state) || 0,
supportsBalance: selectSupportsBalance(state) || 0,
tipsBalance: selectTipsBalance(state) || 0,
rewards: selectClaimedRewards(state),
hasSynced: Boolean(selectSyncHash(state)),
fetchingUtxoCounts: selectIsFetchingUtxoCounts(state),
consolidatingUtxos: selectIsConsolidatingUtxos(state),
massClaimingTips: selectIsMassClaimingTips(state),
utxoCounts: selectUtxoCounts(state),
consolidateIsPending: selectPendingConsolidateTxid(state),
massClaimIsPending: selectPendingMassClaimTxid(state),
});
export default connect(select, {
doOpenModal,
doFetchUtxoCounts,
doUtxoConsolidate,
})(WalletBalance);

View file

@ -0,0 +1,68 @@
// @flow
import * as ICONS from 'constants/icons';
import * as PAGES from 'constants/pages';
import React from 'react';
import Button from 'component/button';
import Card from 'component/common/card';
import Icon from 'component/common/icon';
import I18nMessage from 'component/i18nMessage';
type Props = {
totalTippedAmount: number,
accountDetails: any,
transactions: any,
};
const WalletBalance = (props: Props) => {
const {
// accountDetails,
totalTippedAmount,
transactions,
} = props;
// const [detailsExpanded, setDetailsExpanded] = React.useState(false);
const [totalCreatorsSupported, setTotalCreatorsSupported] = React.useState(false);
// calculate how many unique users tipped
React.useEffect(() => {
if (transactions) {
let channelNames = [];
for (const transaction of transactions) {
channelNames.push(transaction.channel_name);
console.log(transaction.channel_name);
}
let unique = [...new Set(channelNames)];
setTotalCreatorsSupported(unique.length);
}
}, [transactions]);
return (
<>{<Card
title={<><Icon size="18" icon={ICONS.FINANCE} />{totalTippedAmount} USD</>}
subtitle={
<I18nMessage>
The total amount you have tipped to different creators
</I18nMessage>
}
actions={
<>
<h2 className="section__title--small">
{transactions && transactions.length} Total Tips
</h2>
<h2 className="section__title--small">
{totalCreatorsSupported || 0} Creators Supported
</h2>
<div className="section__actions">
<Button button="secondary" label={__('Manage Cards')} icon={ICONS.SETTINGS} navigate={`/$/${PAGES.SETTINGS_STRIPE_CARD}`} />
</div>
</>
}
/>}</>
);
};
export default WalletBalance;

View file

@ -0,0 +1,40 @@
import { connect } from 'react-redux';
import {
selectBalance,
selectClaimsBalance,
selectSupportsBalance,
selectTipsBalance,
selectIsFetchingUtxoCounts,
selectUtxoCounts,
doFetchUtxoCounts,
doUtxoConsolidate,
selectIsConsolidatingUtxos,
selectIsMassClaimingTips,
selectPendingConsolidateTxid,
selectPendingMassClaimTxid,
} from 'lbry-redux';
import { doOpenModal } from 'redux/actions/app';
import { selectSyncHash } from 'redux/selectors/sync';
import { selectClaimedRewards } from 'redux/selectors/rewards';
import WalletBalance from './view';
const select = state => ({
balance: selectBalance(state),
claimsBalance: selectClaimsBalance(state) || 0,
supportsBalance: selectSupportsBalance(state) || 0,
tipsBalance: selectTipsBalance(state) || 0,
rewards: selectClaimedRewards(state),
hasSynced: Boolean(selectSyncHash(state)),
fetchingUtxoCounts: selectIsFetchingUtxoCounts(state),
consolidatingUtxos: selectIsConsolidatingUtxos(state),
massClaimingTips: selectIsMassClaimingTips(state),
utxoCounts: selectUtxoCounts(state),
consolidateIsPending: selectPendingConsolidateTxid(state),
massClaimIsPending: selectPendingMassClaimTxid(state),
});
export default connect(select, {
doOpenModal,
doFetchUtxoCounts,
doUtxoConsolidate,
})(WalletBalance);

View file

@ -0,0 +1,203 @@
// @flow
import React from 'react';
import Button from 'component/button';
import Card from 'component/common/card';
import { Lbryio } from 'lbryinc';
import moment from 'moment';
type Props = {
accountDetails: any,
transactions: any,
totalTippedAmount: number,
};
const WalletBalance = (props: Props) => {
// receive transactions from parent component
let accountTransactions = props.transactions;
console.log('heres transactions');
console.log(accountTransactions);
// let totalTippedAmount = props.totalTippedAmount;
// totalTippedAmount = 0;
// reverse so most recent payments come first
if (accountTransactions) {
accountTransactions = accountTransactions.reverse();
}
// const [detailsExpanded, setDetailsExpanded] = React.useState(false);
// const [accountStatusResponse, setAccountStatusResponse] = React.useState();
// const [totalTippedAmount, setTotalTippedAmount] = React.useState(0);
const [paymentHistoryTransactions, setPaymentHistoryTransactions] = React.useState();
const [subscriptions, setSubscriptions] = React.useState();
const [lastFour, setLastFour] = React.useState();
var environment = 'test';
// function getPaymentHistory() {
// return Lbryio.call(
// 'customer',
// 'list',
// {
// environment,
// },
// 'post'
// ); };
function getCustomerStatus() {
return Lbryio.call(
'customer',
'status',
{
environment,
},
'post'
);
}
React.useEffect(() => {
(async function() {
let response = accountTransactions;
console.log('payment transactions');
console.log(response);
const customerStatusResponse = await getCustomerStatus();
setLastFour(customerStatusResponse.PaymentMethods[0].card.last4);
if (response && response.length > 10) response.length = 10;
setPaymentHistoryTransactions(response);
const subscriptions = [...response];
if (subscriptions && subscriptions.length > 2) {
subscriptions.length = 2;
setSubscriptions([]);
} else {
setSubscriptions([]);
}
console.log(response);
})();
}, [accountTransactions]);
return (
<>
<Card
title={__('Payment History')}
body={
<>
<div className="table__wrapper">
<table className="table table--transactions">
<thead>
<tr>
<th className="date-header">{__('Date')}</th>
<th>{<>{__('Receiving Channel Name')}</>}</th>
<th>{__('Tip Location')}</th>
<th>{__('Amount (USD)')} </th>
<th>{__('Card Last 4')}</th>
<th>{__('Anonymous')}</th>
</tr>
</thead>
<tbody>
{accountTransactions &&
accountTransactions.map((transaction) => (
<tr key={transaction.name + transaction.created_at}>
<td>{moment(transaction.created_at).format('LLL')}</td>
<td>
<Button
className="stripe__card-link-text"
navigate={'/' + transaction.channel_name + ':' + transaction.channel_claim_id}
label={transaction.channel_name}
button="link"
/>
</td>
<td>
<Button
className="stripe__card-link-text"
navigate={'/' + transaction.channel_name + ':' + transaction.source_claim_id}
label={
transaction.channel_claim_id === transaction.source_claim_id
? 'Channel Page'
: 'File Page'
}
button="link"
/>
</td>
<td>${transaction.tipped_amount / 100}</td>
<td>{lastFour}</td>
<td>{transaction.private_tip ? 'Yes' : 'No'}</td>
</tr>
))}
</tbody>
</table>
{(!accountTransactions || accountTransactions.length === 0) && <p style={{textAlign: 'center', marginTop: '20px', fontSize: '13px', color: 'rgb(171, 171, 171)'}}>No Transactions</p>}
</div>
</>
}
/>
<Card
title={__('Subscriptions')}
body={
<>
<div className="table__wrapper">
<table className="table table--transactions">
<thead>
<tr>
<th className="date-header">{__('Date')}</th>
<th>{<>{__('Receiving Channel Name')}</>}</th>
<th>{__('Tip Location')}</th>
<th>{__('Amount (USD)')} </th>
<th>{__('Card Last 4')}</th>
<th>{__('Anonymous')}</th>
</tr>
</thead>
<tbody>
{subscriptions &&
subscriptions.reverse().map((transaction) => (
<tr key={transaction.name + transaction.created_at}>
<td>{moment(transaction.created_at).format('LLL')}</td>
<td>
<Button
className="stripe__card-link-text"
navigate={'/' + transaction.channel_name + ':' + transaction.channel_claim_id}
label={transaction.channel_name}
button="link"
/>
</td>
<td>
<Button
className="stripe__card-link-text"
navigate={'/' + transaction.channel_name + ':' + transaction.source_claim_id}
label={
transaction.channel_claim_id === transaction.source_claim_id
? 'Channel Page'
: 'File Page'
}
button="link"
/>
</td>
<td>${transaction.tipped_amount / 100}</td>
<td>{lastFour}</td>
<td>{transaction.private_tip ? 'Yes' : 'No'}</td>
</tr>
))}
</tbody>
</table>
{(!subscriptions || subscriptions.length === 0) && <p style={{textAlign: 'center', marginTop: '22px', fontSize: '13px', color: 'rgb(171, 171, 171)'}}>No Subscriptions</p>}
</div>
</>
}
/>
</>
);
};
export default WalletBalance;

View file

@ -122,7 +122,7 @@ function WalletSendTip(props: Props) {
// check if creator has an account saved
React.useEffect(() => {
var tipInputElement = document.getElementById('tip-input');
const tipInputElement = document.getElementById('tip-input');
if (tipInputElement) { tipInputElement.focus() }
}, []);
@ -141,6 +141,8 @@ function WalletSendTip(props: Props) {
.then((accountCheckResponse) => {
if (accountCheckResponse === true && canReceiveFiatTip !== true) {
setCanReceiveFiatTip(true);
} else {
setCanReceiveFiatTip(false);
}
})
.catch(function (error) {
@ -169,7 +171,8 @@ function WalletSendTip(props: Props) {
}
const claimTypeText = setClaimTypeText();
let iconToUse, explainerText;
let iconToUse;
let explainerText = '';
if (activeTab === TAB_BOOST) {
iconToUse = ICONS.LBC;
explainerText = __('This refundable boost will improve the discoverability of this %claimTypeText% while active.', {claimTypeText});
@ -273,8 +276,8 @@ function WalletSendTip(props: Props) {
Lbryio.call(
'customer',
'tip',
{
amount: 100 * tipAmount, // convert from dollars to cents
{ // round to fix issues with floating point numbers
amount: Math.round(100 * tipAmount), // convert from dollars to cents
creator_channel_name: tipChannelName, // creator_channel_name
creator_channel_claim_id: channelClaimId,
tipper_channel_name: sendAnonymously ? '' : activeChannelName,
@ -295,7 +298,7 @@ function WalletSendTip(props: Props) {
});
})
.catch(function(error) {
var displayError = 'Sorry, there was an error in processing your payment!';
let displayError = 'Sorry, there was an error in processing your payment!';
if (error.message !== 'payment intent failed to confirm') {
displayError = error.message;
@ -313,10 +316,53 @@ function WalletSendTip(props: Props) {
}
}
function handleCustomPriceChange(event: SyntheticInputEvent<*>) {
const tipAmount = parseFloat(event.target.value);
const countDecimals = function(value) {
const text = value.toString();
const index = text.indexOf('.');
return (text.length - index - 1);
};
function handleCustomPriceChange(event: SyntheticInputEvent<*>) {
let tipAmountAsString = event.target.value;
let tipAmount = parseFloat(tipAmountAsString);
const howManyDecimals = countDecimals(tipAmountAsString);
// fiat tip input
if (activeTab === TAB_FIAT) {
if (Number.isNaN(tipAmount)) {
setCustomTipAmount('');
}
// allow maximum of two decimal places
if (howManyDecimals > 2) {
tipAmount = Math.floor(tipAmount * 100) / 100;
}
// remove decimals, and then get number of digits
const howManyDigits = Math.trunc(tipAmount).toString().length;
if (howManyDigits > 4 && tipAmount !== 1000) {
setTipError('Amount cannot be over 1000 dollars');
setCustomTipAmount(tipAmount);
} else if (tipAmount > 1000) {
setTipError('Amount cannot be over 1000 dollars');
setCustomTipAmount(tipAmount);
} else {
setCustomTipAmount(tipAmount);
}
// LBC tip input
} else {
// TODO: this is a bit buggy, needs a touchup
// if (howManyDecimals > 9) {
// // only allows up to 8 decimal places
// tipAmount = Number(tipAmount.toString().match(/^-?\d+(?:\.\d{0,8})?/)[0]);
//
// setTipError('Please only use up to 8 decimals');
// }
setCustomTipAmount(tipAmount);
}
}
function buildButtonText() {
@ -331,8 +377,14 @@ function WalletSendTip(props: Props) {
return false;
}
function convertToTwoDecimals(number) {
return (Math.round(number * 100) / 100).toFixed(2);
}
const amountToShow = activeTab === TAB_FIAT ? convertToTwoDecimals(tipAmount) : tipAmount;
// if it's a valid number display it, otherwise do an empty string
const displayAmount = !isNan(tipAmount) ? tipAmount : '';
const displayAmount = !isNan(tipAmount) ? amountToShow : '';
if (activeTab === TAB_BOOST) {
return (claimIsMine ? __('Boost Your %claimTypeText%', {claimTypeText}) : __('Boost This %claimTypeText%', {claimTypeText}));
@ -362,30 +414,7 @@ function WalletSendTip(props: Props) {
return (
<Form onSubmit={handleSubmit}>
{/* if there is no LBC balance, show user frontend to get credits */}
{noBalance ? (
<Card
title={<I18nMessage tokens={{ lbc: <LbcSymbol size={22} /> }}>Supporting content requires %lbc%</I18nMessage>}
subtitle={
<I18nMessage tokens={{ lbc: <LbcSymbol /> }}>
With %lbc%, you can send tips to your favorite creators, or help boost their content for more people to
see.
</I18nMessage>
}
actions={
<div className="section__actions">
<Button
icon={ICONS.REWARDS}
button="primary"
label={__('Earn Rewards')}
navigate={`/$/${PAGES.REWARDS}`}
/>
<Button icon={ICONS.BUY} button="secondary" label={__('Buy/Swap Credits')} navigate={`/$/${PAGES.BUY}`} />
<Button button="link" label={__('Nevermind')} onClick={closeModal} />
</div>
}
/>
) : (
// if there is lbc, the main tip/boost gui with the 3 tabs at the top
{/* if there is lbc, the main tip/boost gui with the 3 tabs at the top */}
<Card
title={<LbcSymbol postfix={claimIsMine ? __('Boost Your %claimTypeText%', {claimTypeText}) : __('Support This %claimTypeText%', {claimTypeText})} size={22} />}
subtitle={
@ -399,7 +428,7 @@ function WalletSendTip(props: Props) {
label={__('Tip')}
button="alt"
onClick={() => {
var tipInputElement = document.getElementById('tip-input');
const tipInputElement = document.getElementById('tip-input');
if (tipInputElement) { tipInputElement.focus() }
if (!isConfirming) {
setActiveTab(TAB_LBC);
@ -415,7 +444,7 @@ function WalletSendTip(props: Props) {
label={__('Tip')}
button="alt"
onClick={() => {
var tipInputElement = document.getElementById('tip-input');
const tipInputElement = document.getElementById('tip-input');
if (tipInputElement) { tipInputElement.focus() }
if (!isConfirming) {
setActiveTab(TAB_FIAT);
@ -431,7 +460,7 @@ function WalletSendTip(props: Props) {
label={__('Boost')}
button="alt"
onClick={() => {
var tipInputElement = document.getElementById('tip-input');
const tipInputElement = document.getElementById('tip-input');
if (tipInputElement) { tipInputElement.focus() }
if (!isConfirming) {
setActiveTab(TAB_BOOST);
@ -444,7 +473,7 @@ function WalletSendTip(props: Props) {
{/* short explainer under the button */}
<div className="section__subtitle">
{explainerText}
{explainerText + ' '}
{/* {activeTab === TAB_FIAT && !hasCardSaved && <Button navigate={`/$/${PAGES.SETTINGS_STRIPE_CARD}`} label={__('Add A Card')} button="link" />} */}
{<Button label={__('Learn more')} button="link" href="https://lbry.com/faq/tipping" />}
</div>
@ -464,7 +493,7 @@ function WalletSendTip(props: Props) {
</div>
<div className="confirm__label">{setConfirmLabel()}</div>
<div className="confirm__value">
{activeTab === TAB_FIAT ? <p>$ {tipAmount}</p> : <LbcSymbol postfix={tipAmount} size={22} />}
{activeTab === TAB_FIAT ? <p>$ {(Math.round(tipAmount * 100) / 100).toFixed(2)}</p> : <LbcSymbol postfix={tipAmount} size={22} />}
</div>
</div>
</div>
@ -479,8 +508,10 @@ function WalletSendTip(props: Props) {
<Button button="link" label={__('Cancel')} onClick={() => setIsConfirming(false)} />
</div>
</>
) : (
<>
// only show the prompt to earn more if its lbc or boost tab and no balance
// otherwise you can show the full prompt
) : (!((activeTab === TAB_LBC || activeTab === TAB_BOOST) && noBalance)
? <>
<div className="section">
<ChannelSelector />
</div>
@ -554,11 +585,13 @@ function WalletSendTip(props: Props) {
)}
</React.Fragment>
}
className="form-field--price-amount"
error={tipError}
min="0"
step="any"
type="number"
style={{
width: activeTab === TAB_FIAT ? '99px' : '160px',
}}
placeholder="1.23"
value={customTipAmount}
onChange={(event) => handleCustomPriceChange(event)}
@ -592,10 +625,31 @@ function WalletSendTip(props: Props) {
<div className="help">{__('The payment will be made from your saved card')}</div>
)}
</>
// if it's LBC and there is no balance, you can prompt to purchase LBC
: <Card
title={<I18nMessage tokens={{ lbc: <LbcSymbol size={22} /> }}>Supporting content requires %lbc%</I18nMessage>}
subtitle={
<I18nMessage tokens={{ lbc: <LbcSymbol /> }}>
With %lbc%, you can send tips to your favorite creators, or help boost their content for more people to
see.
</I18nMessage>
}
actions={
<div className="section__actions">
<Button
icon={ICONS.REWARDS}
button="primary"
label={__('Earn Rewards')}
navigate={`/$/${PAGES.REWARDS}`}
/>
<Button icon={ICONS.BUY} button="secondary" label={__('Buy/Swap Credits')} navigate={`/$/${PAGES.BUY}`} />
<Button button="link" label={__('Nevermind')} onClick={closeModal} />
</div>
}
/>
)
}
/>
)}
</Form>
);
}

View file

@ -263,7 +263,6 @@ function WalletTipAmountSelector(props: Props) {
// </div>
// </>
}
className="form-field--price-amount"
error={tipError}
min="0"
step="any"

View file

@ -2,12 +2,14 @@ import { connect } from 'react-redux';
import { withRouter } from 'react-router';
import StripeAccountConnection from './view';
import { selectUser } from 'redux/selectors/user';
import { doToast } from 'redux/actions/notifications';
// function that receives state parameter and returns object of functions that accept state
const select = (state) => ({
user: selectUser(state),
});
// const perform = (dispatch) => ({});
const perform = (dispatch) => ({
doToast: (options) => dispatch(doToast(options)),
});
export default withRouter(connect(select)(StripeAccountConnection));
export default withRouter(connect(select, perform)(StripeAccountConnection));

View file

@ -1,12 +1,13 @@
// @flow
import * as ICONS from 'constants/icons';
import * as PAGES from 'constants/pages';
import React from 'react';
import Button from 'component/button';
import Card from 'component/common/card';
import Page from 'component/page';
import { Lbryio } from 'lbryinc';
import { URL, WEBPACK_WEB_PORT, STRIPE_PUBLIC_KEY } from 'config';
import moment from 'moment';
const isDev = process.env.NODE_ENV !== 'production';
@ -31,6 +32,8 @@ if (isDev) {
type Props = {
source: string,
user: User,
doOpenModal: (string, {}) => void,
doToast: ({ message: string }) => void,
};
type State = {
@ -68,6 +71,8 @@ class StripeAccountConnection extends React.Component<Props, State> {
componentDidMount() {
const { user } = this.props;
let doToast = this.props.doToast;
// $FlowFixMe
this.experimentalUiEnabled = user && user.experimental_ui;
@ -127,10 +132,8 @@ class StripeAccountConnection extends React.Component<Props, State> {
).then((accountListResponse: any) => {
// TODO type this
that.setState({
accountTransactions: accountListResponse,
accountTransactions: accountListResponse.reverse(),
});
console.log(accountListResponse);
});
}
@ -165,6 +168,9 @@ class StripeAccountConnection extends React.Component<Props, State> {
// get stripe link and set it on the frontend
getAndSetAccountLink(true);
} else {
// probably an error from stripe
const displayString = 'There was an error getting your account setup, please let support know';
doToast({ message: displayString, isError: true });
// not an error from Beamer, throw it
throw new Error(error);
}
@ -179,7 +185,7 @@ class StripeAccountConnection extends React.Component<Props, State> {
unpaidBalance,
accountNotConfirmedButReceivedTips,
pageTitle,
accountTransactions,
// accountTransactions,
} = this.state;
const { user } = this.props;
@ -223,25 +229,11 @@ class StripeAccountConnection extends React.Component<Props, State> {
<div>
<div>
<h3>{__('Congratulations! Your account has been connected with Odysee.')}</h3>
{unpaidBalance > 0 ? (
<div>
<br />
<h3>
{__('Your pending account balance is $%balance% USD.', { balance: unpaidBalance / 100 })}
</h3>
</div>
) : (
<div>
<br />
<h3>
{__('Your account balance is $0 USD. When you receive a tip you will see it here.')}
</h3>
</div>
)}
</div>
</div>
</div>
)}
{/* TODO: hopefully we won't be using this anymore and can remove it */}
{accountNotConfirmedButReceivedTips && (
<div className="card__body-actions">
<div>
@ -272,66 +264,16 @@ class StripeAccountConnection extends React.Component<Props, State> {
)}
</div>
}
actions={
<Button
button="primary"
label={__('View Transactions')}
icon={ICONS.SETTINGS}
navigate={`/$/${PAGES.WALLET}?tab=account-history`}
/>
}
/>
<br />
{/* customer already has transactions */}
{accountTransactions && accountTransactions.length > 0 && (
<Card
title={__('Tip History')}
body={
<>
<div className="table__wrapper">
<table className="table table--transactions">
<thead>
<tr>
<th className="date-header">{__('Date')}</th>
<th>{<>{__('Receiving Channel Name')}</>}</th>
<th>{__('Tip Location')}</th>
<th>{__('Amount (USD)')} </th>
<th>{__('Processing Fee')}</th>
<th>{__('Odysee Fee')}</th>
<th>{__('Received Amount')}</th>
</tr>
</thead>
<tbody>
{accountTransactions &&
accountTransactions.reverse().map((transaction) => (
<tr key={transaction.name + transaction.created_at}>
<td>{moment(transaction.created_at).format('LLL')}</td>
<td>
<Button
className="stripe__card-link-text"
navigate={'/' + transaction.channel_name + ':' + transaction.channel_claim_id}
label={transaction.channel_name}
button="link"
/>
</td>
<td>
<Button
className="stripe__card-link-text"
navigate={'/' + transaction.channel_name + ':' + transaction.source_claim_id}
label={
transaction.channel_claim_id === transaction.source_claim_id
? 'Channel Page'
: 'File Page'
}
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>
</tr>
))}
</tbody>
</table>
</div>
</>
}
/>
)}
</Page>
);
} else {

View file

@ -6,11 +6,11 @@ import Page from 'component/page';
import Card from 'component/common/card';
import { Lbryio } from 'lbryinc';
import { STRIPE_PUBLIC_KEY } from 'config';
import moment from 'moment';
import Plastic from 'react-plastic';
import Button from 'component/button';
import * as ICONS from 'constants/icons';
import * as MODALS from 'constants/modal_types';
import * as PAGES from 'constants/pages';
let stripeEnvironment = 'test';
// if the key contains pk_live it's a live key
@ -19,6 +19,9 @@ if (STRIPE_PUBLIC_KEY.indexOf('pk_live') > -1) {
stripeEnvironment = 'live';
}
const APIS_DOWN_ERROR_RESPONSE = 'There was an error from the server, please let support know';
const CARD_SETUP_ERROR_RESPONSE = 'There was an error getting your card setup, please let support know';
// eslint-disable-next-line flowtype/no-types-missing-file-annotation
type Props = {
disabled: boolean,
@ -181,18 +184,17 @@ class SettingsStripeCard extends React.Component<Props, State> {
},
'post'
).then((customerSetupResponse) => {
console.log(customerSetupResponse);
clientSecret = customerSetupResponse.client_secret;
// instantiate stripe elements
setupStripe();
});
// 500 error from the backend being down
} else if (error === 'internal_apis_down') {
var displayString = 'There was an error from the server, please let support know';
doToast({ message: displayString, isError: true });
doToast({ message: APIS_DOWN_ERROR_RESPONSE, isError: true });
} else {
console.log('Unseen before error');
// probably an error from stripe
doToast({ message: CARD_SETUP_ERROR_RESPONSE, isError: true });
}
});
}, 250);
@ -366,7 +368,7 @@ class SettingsStripeCard extends React.Component<Props, State> {
const { scriptFailedToLoad, openModal } = this.props;
const { currentFlowStage, customerTransactions, pageTitle, userCardDetails, paymentMethodId } = this.state;
const { currentFlowStage, pageTitle, userCardDetails, paymentMethodId } = this.state;
return (
<Page backout={{ title: pageTitle, backLabel: __('Done') }} noFooter noSideNavigation>
@ -430,72 +432,18 @@ class SettingsStripeCard extends React.Component<Props, State> {
/>
</>
}
actions={
<Button
button="primary"
label={__('View Transactions')}
icon={ICONS.SETTINGS}
navigate={`/$/${PAGES.WALLET}?tab=payment-history`}
/>
}
/>
<br />
{/* if a user has no transactions yet */}
{(!customerTransactions || customerTransactions.length === 0) && (
<Card
title={__('Tip History')}
subtitle={__('You have not sent any tips yet. When you do they will appear here. ')}
/>
)}
</div>
)}
{/* customer already has transactions */}
{customerTransactions && customerTransactions.length > 0 && (
<Card
title={__('Tip History')}
body={
<>
<div className="table__wrapper">
<table className="table table--transactions">
<thead>
<tr>
<th className="date-header">{__('Date')}</th>
<th>{<>{__('Receiving Channel Name')}</>}</th>
<th>{__('Tip Location')}</th>
<th>{__('Amount (USD)')} </th>
<th>{__('Anonymous')}</th>
</tr>
</thead>
<tbody>
{customerTransactions &&
customerTransactions.reverse().map((transaction) => (
<tr key={transaction.name + transaction.created_at}>
<td>{moment(transaction.created_at).format('LLL')}</td>
<td>
<Button
className="stripe__card-link-text"
navigate={'/' + transaction.channel_name + ':' + transaction.channel_claim_id}
label={transaction.channel_name}
button="link"
/>
</td>
<td>
<Button
className="stripe__card-link-text"
navigate={'/' + transaction.channel_name + ':' + transaction.source_claim_id}
label={
transaction.channel_claim_id === transaction.source_claim_id
? 'Channel Page'
: 'File Page'
}
button="link"
/>
</td>
<td>${transaction.tipped_amount / 100}</td>
<td>{transaction.private_tip ? 'Yes' : 'No'}</td>
</tr>
))}
</tbody>
</table>
</div>
</>
}
/>
)}
</Page>
);
}

View file

@ -2,10 +2,15 @@
import React from 'react';
import { withRouter } from 'react-router';
import WalletBalance from 'component/walletBalance';
import WalletFiatBalance from 'component/walletFiatBalance';
import WalletFiatPaymentBalance from 'component/walletFiatPaymentBalance';
import WalletFiatAccountHistory from 'component/walletFiatAccountHistory';
import WalletFiatPaymentHistory from 'component/walletFiatPaymentHistory';
import TxoList from 'component/txoList';
import Page from 'component/page';
import Spinner from 'component/spinner';
import YrblWalletEmpty from 'component/yrblWalletEmpty';
import { Lbryio } from 'lbryinc';
type Props = {
history: { action: string, push: (string) => void, replace: (string) => void },
@ -14,6 +19,143 @@ type Props = {
};
const WalletPage = (props: Props) => {
console.log(props);
const stripeEnvironment = 'test';
const tab = new URLSearchParams(props.location.search).get('tab');
const [accountStatusResponse, setAccountStatusResponse] = React.useState();
const [accountTransactionResponse, setAccountTransactionResponse] = React.useState();
const [customerTransactions, setCustomerTransactions] = React.useState();
const [totalTippedAmount, setTotalTippedAmount] = React.useState(0);
function getPaymentHistory() {
return Lbryio.call(
'customer',
'list',
{
environment: stripeEnvironment,
},
'post'
); };
// function getCustomerStatus() {
// return Lbryio.call(
// 'customer',
// 'status',
// {
// environment: stripeEnvironment,
// },
// 'post'
// );
// }
function getAccountStatus() {
return Lbryio.call(
'account',
'status',
{
environment: stripeEnvironment,
},
'post'
);
}
function getAccountTransactionsa() {
return Lbryio.call(
'account',
'list',
{
environment: stripeEnvironment,
},
'post'
);
}
// calculate account transactions section
React.useEffect(() => {
(async function() {
try {
const response = await getAccountStatus();
setAccountStatusResponse(response);
// TODO: some weird naming clash hence getAccountTransactionsa
const getAccountTransactions = await getAccountTransactionsa();
setAccountTransactionResponse(getAccountTransactions);
} catch (err) {
console.log(err);
}
})();
}, []);
// populate customer payment data
React.useEffect(() => {
(async function() {
try {
// get card payments customer has made
const customerTransactionResponse = await getPaymentHistory();
let totalTippedAmount = 0;
for (const transaction of customerTransactionResponse) {
totalTippedAmount = totalTippedAmount + transaction.tipped_amount;
}
setTotalTippedAmount(totalTippedAmount / 100);
setCustomerTransactions(customerTransactionResponse);
} catch (err) {
console.log(err);
}
})();
}, []);
function focusLBCTab() {
document.getElementsByClassName('lbc-transactions')[0].style.display = 'inline';
document.getElementsByClassName('fiat-transactions')[0].style.display = 'none';
document.getElementsByClassName('payment-history-tab')[0].style.display = 'none';
document.getElementsByClassName('lbc-tab-switcher')[0].style.textDecoration = 'underline';
document.getElementsByClassName('fiat-tab-switcher')[0].style.textDecoration = 'none';
document.getElementsByClassName('fiat-payment-history-switcher')[0].style.textDecoration = 'none';
}
function focusAccountHistoryTab() {
document.getElementsByClassName('lbc-transactions')[0].style.display = 'none';
document.getElementsByClassName('payment-history-tab')[0].style.display = 'none';
document.getElementsByClassName('fiat-transactions')[0].style.display = 'inline';
document.getElementsByClassName('lbc-tab-switcher')[0].style.textDecoration = 'none';
document.getElementsByClassName('fiat-tab-switcher')[0].style.textDecoration = 'underline';
document.getElementsByClassName('fiat-payment-history-switcher')[0].style.textDecoration = 'none';
}
function focusPaymentHistoryTab() {
document.getElementsByClassName('lbc-transactions')[0].style.display = 'none';
document.getElementsByClassName('fiat-transactions')[0].style.display = 'none';
document.getElementsByClassName('payment-history-tab')[0].style.display = 'inline';
document.getElementsByClassName('lbc-tab-switcher')[0].style.textDecoration = 'none';
document.getElementsByClassName('fiat-tab-switcher')[0].style.textDecoration = 'none';
document.getElementsByClassName('fiat-payment-history-switcher')[0].style.textDecoration = 'underline';
}
// select the first tab
React.useEffect(() => {
if (tab === 'account-history') {
// if (1 === 2) {
focusAccountHistoryTab();
} else if (tab === 'payment-history') {
// } else if (1 === 2){
focusPaymentHistoryTab();
} else {
focusLBCTab();
}
}, []);
const { location, totalBalance } = props;
const { search } = location;
const showIntro = totalBalance === 0;
@ -21,12 +163,39 @@ const WalletPage = (props: Props) => {
return (
<Page>
{loading && (
{/* tabs to switch between fiat and lbc */}
{/* lbc button */}
<h2 className="lbc-tab-switcher"
style={{display: 'inline-block', paddingBottom: '16px', marginRight: '14px', textUnderlineOffset: '4px', fontSize: '18px', marginLeft: '3px'}}
onClick={() => {
focusLBCTab();
}}
>LBC Wallet</h2>
{/* account history button */}
<h2 className="fiat-tab-switcher"
style={{display: 'inline-block', textUnderlineOffset: '4px', fontSize: '18px', marginRight: '14px'}}
onClick={() => {
focusAccountHistoryTab();
}}
>Account History</h2>
{/* payment history button */}
<h2 className="fiat-payment-history-switcher"
style={{display: 'inline-block', textUnderlineOffset: '4px', fontSize: '18px'}}
onClick={() => {
focusPaymentHistoryTab();
}}
>Payment History</h2>
{/* lbc wallet section */}
<div className="lbc-transactions">
{/* if the transactions are loading */}
{ loading && (
<div className="main--empty">
<Spinner delayed />
</div>
)}
{!loading && (
{/* when the transactions are finished loading */}
{ !loading && (
<>
{showIntro ? (
<YrblWalletEmpty includeWalletLink />
@ -38,6 +207,22 @@ const WalletPage = (props: Props) => {
)}
</>
)}
</div>
{/* account received transactions section */}
<div className="fiat-transactions" style={{display: 'none'}}>
<WalletFiatBalance accountDetails={accountStatusResponse} />
<div style={{paddingTop: '25px'}} />
<WalletFiatAccountHistory transactions={accountTransactionResponse} />
</div>
{/* fiat payment history for tips made by user */}
<div className="payment-history-tab" style={{display: 'none'}}>
<WalletFiatPaymentBalance transactions={customerTransactions} totalTippedAmount={totalTippedAmount} accountDetails={accountStatusResponse} />
<div style={{paddingTop: '25px'}} />
<WalletFiatPaymentHistory transactions={customerTransactions} />
</div>
</Page>
);
};