cleanup with last four fix

This commit is contained in:
Anthony 2021-08-13 16:46:45 +02:00
parent e5ef460e7e
commit 9810c8a135
No known key found for this signature in database
GPG key ID: C386D3C93D50E356
8 changed files with 44 additions and 184 deletions

View file

@ -1,40 +1,3 @@
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';
import FiatAccountHistory 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);
export default FiatAccountHistory;

View file

@ -4,7 +4,7 @@ import Button from 'component/button';
import Card from 'component/common/card';
import { Lbryio } from 'lbryinc';
import moment from 'moment';
import { STRIPE_PUBLIC_KEY } from '../../../config';
import { STRIPE_PUBLIC_KEY } from 'config';
let stripeEnvironment = 'test';
// if the key contains pk_live it's a live key
@ -20,13 +20,16 @@ type Props = {
const WalletBalance = (props: Props) => {
// receive transactions from parent component
let accountTransactions = props.transactions;
const { transactions } = props;
let accountTransactions;
// reverse so most recent payments come first
if (accountTransactions) {
accountTransactions = accountTransactions.reverse();
if (transactions && transactions.length) {
accountTransactions = transactions.reverse();
}
// if there are more than 10 transactions, limit it to 10 for the frontend
if (accountTransactions && accountTransactions.length > 10) {
accountTransactions.length = 10;
}
@ -51,8 +54,6 @@ const WalletBalance = (props: Props) => {
const response = await getAccountStatus();
setAccountStatusResponse(response);
console.log(response);
})();
}, []);

View file

@ -1,3 +1,3 @@
import WalletBalance from './view';
import WalletFiatBalance from './view';
export default WalletBalance;
export default WalletFiatBalance;

View file

@ -1,40 +1,3 @@
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';
import WalletFiatPaymentBalance 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);
export default WalletFiatPaymentBalance;

View file

@ -50,14 +50,15 @@ const WalletBalance = (props: Props) => {
return (
<>{<Card
subtitle={1 === 2 && <h2>Hello</h2>
// <Plastic
// type={userCardDetails.brand}
// name={userCardDetails.topOfDisplay + ' ' + userCardDetails.bottomOfDisplay}
// expiry={userCardDetails.expiryMonth + '/' + userCardDetails.expiryYear}
// number={'____________' + userCardDetails.lastFour}
// />
}
// TODO: implement hasActiveCard and show the current card the user would charge to
// subtitle={hasActiveCard && <h2>Hello</h2>
// // <Plastic
// // type={userCardDetails.brand}
// // name={userCardDetails.topOfDisplay + ' ' + userCardDetails.bottomOfDisplay}
// // expiry={userCardDetails.expiryMonth + '/' + userCardDetails.expiryYear}
// // number={'____________' + userCardDetails.lastFour}
// // />
// }
actions={
<>
<h2 className="section__title--small">

View file

@ -1,40 +1,3 @@
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';
import WalletFiatPaymentHistory 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);
export default WalletFiatPaymentHistory;

View file

@ -4,88 +4,57 @@ import Button from 'component/button';
import Card from 'component/common/card';
import { Lbryio } from 'lbryinc';
import moment from 'moment';
import { STRIPE_PUBLIC_KEY } from 'config';
let stripeEnvironment = 'test';
// if the key contains pk_live it's a live key
// update the environment for the calls to the backend to indicate which environment to hit
if (STRIPE_PUBLIC_KEY.indexOf('pk_live') > -1) {
stripeEnvironment = 'live';
}
type Props = {
accountDetails: any,
transactions: any,
totalTippedAmount: number,
};
const WalletBalance = (props: Props) => {
// receive transactions from parent component
let accountTransactions = props.transactions;
const { transactions } = props;
console.log('heres transactions');
console.log(accountTransactions);
// let totalTippedAmount = props.totalTippedAmount;
// totalTippedAmount = 0;
let accountTransactions;
// reverse so most recent payments come first
if (accountTransactions) {
accountTransactions = accountTransactions.reverse();
if (transactions && transactions.length) {
accountTransactions = transactions.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 [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,
environment: stripeEnvironment,
},
'post'
);
}
// TODO: this is actually incorrect, last4 should be populated based on the transaction not the current customer details
React.useEffect(() => {
(async function() {
let response = accountTransactions;
console.log('payment transactions');
console.log(response);
const customerStatusResponse = await getCustomerStatus();
setLastFour(customerStatusResponse.PaymentMethods[0].card.last4);
const lastFour = customerStatusResponse.PaymentMethods && customerStatusResponse.PaymentMethods.length && 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);
setLastFour(lastFour);
})();
}, [accountTransactions]);
}, []);
return (
<>

View file

@ -30,8 +30,8 @@ const WalletPage = (props: Props) => {
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 [accountTransactionResponse, setAccountTransactionResponse] = React.useState([]);
const [customerTransactions, setCustomerTransactions] = React.useState([]);
const [totalTippedAmount, setTotalTippedAmount] = React.useState(0);
function getPaymentHistory() {