make flow shut up

This commit is contained in:
zeppi 2021-07-05 00:04:05 -04:00 committed by jessopb
parent 50556bba97
commit d34ef851d0
3 changed files with 365 additions and 276 deletions

1
flow-typed/user.js vendored
View file

@ -28,6 +28,7 @@ declare type User = {
device_types: Array<DeviceType>, device_types: Array<DeviceType>,
lbry_first_approved: boolean, lbry_first_approved: boolean,
experimental_ui: boolean, experimental_ui: boolean,
fiat_enabled: boolean,
odysee_live_enabled: boolean, odysee_live_enabled: boolean,
odysee_live_disabled: boolean, odysee_live_disabled: boolean,
global_mod: boolean, global_mod: boolean,

View file

@ -36,10 +36,11 @@ type State = {
loading: boolean, loading: boolean,
content: ?string, content: ?string,
stripeConnectionUrl: string, stripeConnectionUrl: string,
alreadyUpdated: boolean, // alreadyUpdated: boolean,
accountConfirmed: boolean, accountConfirmed: boolean,
accountPendingConfirmation: boolean,
accountNotConfirmedButReceivedTips: boolean, accountNotConfirmedButReceivedTips: boolean,
unpaidBalance: string unpaidBalance: number,
}; };
class StripeAccountConnection extends React.Component<Props, State> { class StripeAccountConnection extends React.Component<Props, State> {
@ -53,22 +54,30 @@ class StripeAccountConnection extends React.Component<Props, State> {
accountPendingConfirmation: false, accountPendingConfirmation: false,
accountNotConfirmedButReceivedTips: false, accountNotConfirmedButReceivedTips: false,
unpaidBalance: 0, unpaidBalance: 0,
stripeConnectionUrl: '',
// alreadyUpdated: false,
}; };
} }
componentDidMount() { componentDidMount() {
const { user } = this.props; const { user } = this.props;
// $FlowFixMe
this.experimentalUiEnabled = user && user.experimental_ui; this.experimentalUiEnabled = user && user.experimental_ui;
var that = this; var that = this;
function getAndSetAccountLink(stillNeedToConfirmAccount) { function getAndSetAccountLink(stillNeedToConfirmAccount) {
Lbryio.call('account', 'link', { Lbryio.call(
'account',
'link',
{
return_url: successStripeRedirectUrl, return_url: successStripeRedirectUrl,
refresh_url: failureStripeRedirectUrl, refresh_url: failureStripeRedirectUrl,
environment: stripeEnvironment, environment: stripeEnvironment,
}, 'post').then(accountLinkResponse => { },
'post'
).then((accountLinkResponse) => {
// stripe link for user to navigate to and confirm account // stripe link for user to navigate to and confirm account
const stripeConnectionUrl = accountLinkResponse.url; const stripeConnectionUrl = accountLinkResponse.url;
@ -87,9 +96,15 @@ class StripeAccountConnection extends React.Component<Props, State> {
} }
// call the account status endpoint // call the account status endpoint
Lbryio.call('account', 'status', { Lbryio.call(
'account',
'status',
{
environment: stripeEnvironment, environment: stripeEnvironment,
}, 'post').then(accountStatusResponse => { },
'post'
)
.then((accountStatusResponse) => {
const yetToBeCashedOutBalance = accountStatusResponse.total_received_unpaid; const yetToBeCashedOutBalance = accountStatusResponse.total_received_unpaid;
if (yetToBeCashedOutBalance) { if (yetToBeCashedOutBalance) {
that.setState({ that.setState({
@ -118,7 +133,8 @@ class StripeAccountConnection extends React.Component<Props, State> {
// pass true so it updates the frontend // pass true so it updates the frontend
getAndSetAccountLink(true); getAndSetAccountLink(true);
} }
}).catch(function(error) { })
.catch(function (error) {
// errorString passed from the API (with a 403 error) // errorString passed from the API (with a 403 error)
const errorString = 'account not linked to user, please link first'; const errorString = 'account not linked to user, please link first';
@ -134,7 +150,13 @@ class StripeAccountConnection extends React.Component<Props, State> {
} }
render() { render() {
const { stripeConnectionUrl, accountConfirmed, accountPendingConfirmation, unpaidBalance, accountNotConfirmedButReceivedTips } = this.state; const {
stripeConnectionUrl,
accountConfirmed,
accountPendingConfirmation,
unpaidBalance,
accountNotConfirmedButReceivedTips,
} = this.state;
const { user } = this.props; const { user } = this.props;
@ -146,7 +168,7 @@ class StripeAccountConnection extends React.Component<Props, State> {
body={ body={
<div> <div>
{/* show while waiting for account status */} {/* show while waiting for account status */}
{!accountConfirmed && !accountPendingConfirmation && !accountNotConfirmedButReceivedTips && {!accountConfirmed && !accountPendingConfirmation && !accountNotConfirmedButReceivedTips && (
<div className="card__body-actions"> <div className="card__body-actions">
<div> <div>
<div> <div>
@ -154,9 +176,9 @@ class StripeAccountConnection extends React.Component<Props, State> {
</div> </div>
</div> </div>
</div> </div>
} )}
{/* user has yet to complete their integration */} {/* user has yet to complete their integration */}
{!accountConfirmed && accountPendingConfirmation && {!accountConfirmed && accountPendingConfirmation && (
<div className="card__body-actions"> <div className="card__body-actions">
<div> <div>
<div> <div>
@ -164,61 +186,67 @@ class StripeAccountConnection extends React.Component<Props, State> {
</div> </div>
<div className="section__actions"> <div className="section__actions">
<a href={stripeConnectionUrl}> <a href={stripeConnectionUrl}>
<Button <Button button="secondary" label={__('Connect Your Bank Account')} icon={ICONS.FINANCE} />
button="secondary"
label={__('Connect Your Bank Account')}
icon={ICONS.FINANCE}
/>
</a> </a>
</div> </div>
</div> </div>
</div> </div>
} )}
{/* user has completed their integration */} {/* user has completed their integration */}
{accountConfirmed && {accountConfirmed && (
<div className="card__body-actions"> <div className="card__body-actions">
<div> <div>
<div> <div>
<h3>Congratulations! Your account has been connected with Odysee.</h3> <h3>Congratulations! Your account has been connected with Odysee.</h3>
{unpaidBalance > 0 ? <div><br /> {unpaidBalance > 0 ? (
<h3>Your account balance is ${unpaidBalance / 100} USD. Functionality to view your transactions and withdraw your balance will be landing shortly.</h3> <div>
</div> : <div><br /> <br />
<h3>
Your account balance is ${unpaidBalance / 100} USD. Functionality to view your transactions
and withdraw your balance will be landing shortly.
</h3>
</div>
) : (
<div>
<br />
<h3>Your account balance is $0 USD. When you receive a tip you will see it here.</h3> <h3>Your account balance is $0 USD. When you receive a tip you will see it here.</h3>
</div>} </div>
)}
</div> </div>
</div> </div>
</div> </div>
} )}
{ accountNotConfirmedButReceivedTips && {accountNotConfirmedButReceivedTips && (
<div className="card__body-actions"> <div className="card__body-actions">
<div> <div>
<div> <div>
<h3>Congratulations, you have already begun receiving tips on Odysee!</h3> <h3>Congratulations, you have already begun receiving tips on Odysee!</h3>
<div><br /> <div>
<h3>Your pending account balance is ${unpaidBalance / 100} USD. Functionality to view and receive your transactions will land soon.</h3> <br />
</div><br /> <h3>
Your pending account balance is ${unpaidBalance / 100} USD. Functionality to view and receive
your transactions will land soon.
</h3>
</div>
<br />
<div> <div>
<h3>Connect your Bank Account to be able to cash your pending balance out to your account.</h3> <h3>Connect your Bank Account to be able to cash your pending balance out to your account.</h3>
</div> </div>
<div className="section__actions"> <div className="section__actions">
<a href={stripeConnectionUrl}> <a href={stripeConnectionUrl}>
<Button <Button button="secondary" label={__('Connect Your Bank Account')} icon={ICONS.FINANCE} />
button="secondary"
label={__('Connect Your Bank Account')}
icon={ICONS.FINANCE}
/>
</a> </a>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
} )}
</div> </div>
} }
/> />
); );
} else { } else {
return (<></>); // probably null; return <></>; // probably null;
} }
} }
} }

View file

@ -1,4 +1,4 @@
// @flow // restore flow
/* eslint-disable no-undef */ /* eslint-disable no-undef */
/* eslint-disable react/prop-types */ /* eslint-disable react/prop-types */
import React from 'react'; import React from 'react';
@ -19,14 +19,25 @@ if (STRIPE_PUBLIC_KEY.indexOf('pk_live') > -1) {
stripeEnvironment = 'live'; stripeEnvironment = 'live';
} }
type Props = { // type Props = {
disabled: boolean, // disabled: boolean,
label: ?string, // label: ?string,
email: ?string, // email: ?string,
} // scriptFailedToLoad: boolean,
// };
//
// type State = {
// open: boolean,
// currentFlowStage: string,
// customerTransactions: Array<any>,
// pageTitle: string,
// userCardDetails: any, // fill this out
// scriptFailedToLoad: boolean,
// };
class CardVerify extends React.Component<Props, State> { class CardVerify extends React.Component<Props, State> {
constructor(props: Props) { constructor(props) {
// :Props
super(props); super(props);
this.state = { this.state = {
open: false, open: false,
@ -58,9 +69,15 @@ class CardVerify extends React.Component<Props, State> {
// TODO: fix this, should be a cleaner way // TODO: fix this, should be a cleaner way
setTimeout(function () { setTimeout(function () {
// check if customer has card setup already // check if customer has card setup already
Lbryio.call('customer', 'status', { Lbryio.call(
'customer',
'status',
{
environment: stripeEnvironment, environment: stripeEnvironment,
}, 'post').then(customerStatusResponse => { },
'post'
)
.then((customerStatusResponse) => {
// user has a card saved if their defaultPaymentMethod has an id // user has a card saved if their defaultPaymentMethod has an id
const defaultPaymentMethod = customerStatusResponse.Customer.invoice_settings.default_payment_method; const defaultPaymentMethod = customerStatusResponse.Customer.invoice_settings.default_payment_method;
var userHasAlreadySetupPayment = Boolean(defaultPaymentMethod && defaultPaymentMethod.id); var userHasAlreadySetupPayment = Boolean(defaultPaymentMethod && defaultPaymentMethod.id);
@ -83,9 +100,14 @@ class CardVerify extends React.Component<Props, State> {
}); });
// get customer transactions // get customer transactions
Lbryio.call('customer', 'list', { Lbryio.call(
'customer',
'list',
{
environment: stripeEnvironment, environment: stripeEnvironment,
}, 'post').then(customerTransactionsResponse => { },
'post'
).then((customerTransactionsResponse) => {
that.setState({ that.setState({
customerTransactions: customerTransactionsResponse, customerTransactions: customerTransactionsResponse,
}); });
@ -100,9 +122,14 @@ class CardVerify extends React.Component<Props, State> {
}); });
// get a payment method secret for frontend // get a payment method secret for frontend
Lbryio.call('customer', 'setup', { Lbryio.call(
'customer',
'setup',
{
environment: stripeEnvironment, environment: stripeEnvironment,
}, 'post').then(customerSetupResponse => { },
'post'
).then((customerSetupResponse) => {
console.log(customerSetupResponse); console.log(customerSetupResponse);
clientSecret = customerSetupResponse.client_secret; clientSecret = customerSetupResponse.client_secret;
@ -112,7 +139,8 @@ class CardVerify extends React.Component<Props, State> {
}); });
} }
// if the status call fails, either an actual error or need to run setup first // if the status call fails, either an actual error or need to run setup first
}).catch(function(error) { })
.catch(function (error) {
console.log(error); console.log(error);
// errorString passed from the API (with a 403 error) // errorString passed from the API (with a 403 error)
@ -126,9 +154,14 @@ class CardVerify extends React.Component<Props, State> {
}); });
// get a payment method secret for frontend // get a payment method secret for frontend
Lbryio.call('customer', 'setup', { Lbryio.call(
'customer',
'setup',
{
environment: stripeEnvironment, environment: stripeEnvironment,
}, 'post').then(customerSetupResponse => { },
'post'
).then((customerSetupResponse) => {
console.log(customerSetupResponse); console.log(customerSetupResponse);
clientSecret = customerSetupResponse.client_secret; clientSecret = customerSetupResponse.client_secret;
@ -154,8 +187,7 @@ class CardVerify extends React.Component<Props, State> {
base: { base: {
fontSize: '16px', fontSize: '16px',
color: '#32325d', color: '#32325d',
fontFamily: fontFamily: '-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, sans-serif',
'-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, sans-serif',
fontSmoothing: 'antialiased', fontSmoothing: 'antialiased',
'::placeholder': { '::placeholder': {
color: 'rgba(0,0,0,0.4)', color: 'rgba(0,0,0,0.4)',
@ -198,12 +230,14 @@ class CardVerify extends React.Component<Props, State> {
changeLoadingState(true); changeLoadingState(true);
stripe.confirmCardSetup(clientSecret, { stripe
.confirmCardSetup(clientSecret, {
payment_method: { payment_method: {
card: card, card: card,
billing_details: { email: email }, billing_details: { email: email },
}, },
}).then(function(result) { })
.then(function (result) {
if (result.error) { if (result.error) {
console.log(result); console.log(result);
@ -239,12 +273,18 @@ class CardVerify extends React.Component<Props, State> {
// Show a spinner on payment submission // Show a spinner on payment submission
var changeLoadingState = function (isLoading) { var changeLoadingState = function (isLoading) {
if (isLoading) { if (isLoading) {
// $FlowFixMe
document.querySelector('button').disabled = true; document.querySelector('button').disabled = true;
// $FlowFixMe
document.querySelector('#spinner').classList.remove('hidden'); document.querySelector('#spinner').classList.remove('hidden');
// $FlowFixMe
document.querySelector('#button-text').classList.add('hidden'); document.querySelector('#button-text').classList.add('hidden');
} else { } else {
// $FlowFixMe
document.querySelector('button').disabled = false; document.querySelector('button').disabled = false;
// $FlowFixMe
document.querySelector('#spinner').classList.add('hidden'); document.querySelector('#spinner').classList.add('hidden');
// $FlowFixMe
document.querySelector('#button-text').classList.remove('hidden'); document.querySelector('#button-text').classList.remove('hidden');
} }
}; };
@ -252,9 +292,14 @@ class CardVerify extends React.Component<Props, State> {
// shows a success / error message when the payment is complete // shows a success / error message when the payment is complete
var orderComplete = function (stripe, clientSecret) { var orderComplete = function (stripe, clientSecret) {
stripe.retrieveSetupIntent(clientSecret).then(function (result) { stripe.retrieveSetupIntent(clientSecret).then(function (result) {
Lbryio.call('customer', 'status', { Lbryio.call(
'customer',
'status',
{
environment: stripeEnvironment, environment: stripeEnvironment,
}, 'post').then(customerStatusResponse => { },
'post'
).then((customerStatusResponse) => {
var card = customerStatusResponse.PaymentMethods[0].card; var card = customerStatusResponse.PaymentMethods[0].card;
var cardDetails = { var cardDetails = {
@ -287,10 +332,16 @@ class CardVerify extends React.Component<Props, State> {
} }
componentWillUnmount() { componentWillUnmount() {
// pretty sure this doesn't exist
// $FlowFixMe
if (this.loadPromise) { if (this.loadPromise) {
// $FlowFixMe
this.loadPromise.reject(); this.loadPromise.reject();
} }
// pretty sure this doesn't exist
// $FlowFixMe
if (CardVerify.stripeHandler && this.state.open) { if (CardVerify.stripeHandler && this.state.open) {
// $FlowFixMe
CardVerify.stripeHandler.close(); CardVerify.stripeHandler.close();
} }
} }
@ -329,7 +380,6 @@ class CardVerify extends React.Component<Props, State> {
const { currentFlowStage, customerTransactions, pageTitle, userCardDetails } = this.state; const { currentFlowStage, customerTransactions, pageTitle, userCardDetails } = this.state;
return ( return (
<Page backout={{ title: pageTitle, backLabel: __('Done') }} noFooter noSideNavigation> <Page backout={{ title: pageTitle, backLabel: __('Done') }} noFooter noSideNavigation>
<div> <div>
{scriptFailedToLoad && ( {scriptFailedToLoad && (
@ -337,20 +387,18 @@ class CardVerify extends React.Component<Props, State> {
)} )}
</div> </div>
{currentFlowStage === 'loading' && <div className="headerCard toConfirmCard"> {currentFlowStage === 'loading' && (
<Card <div className="headerCard toConfirmCard">
title={__('Connect your card with Odysee')} <Card title={__('Connect your card with Odysee')} subtitle={__('Getting your card connection status...')} />
subtitle={__('Getting your card connection status...')} </div>
/> )}
</div>}
{currentFlowStage === 'confirmingCard' && <div className="sr-root"> {currentFlowStage === 'confirmingCard' && (
<div className="sr-root">
<div className="sr-main"> <div className="sr-main">
<div className="sr-payment-form card cardInput"> <div className="sr-payment-form card cardInput">
<div className="sr-form-row"> <div className="sr-form-row">
<label className="payment-details"> <label className="payment-details">Card Details</label>
Card Details
</label>
<div className="sr-input sr-element sr-card-element" id="card-element" /> <div className="sr-input sr-element sr-card-element" id="card-element" />
</div> </div>
<div className="sr-field-error" id="card-errors" role="alert" /> <div className="sr-field-error" id="card-errors" role="alert" />
@ -360,28 +408,37 @@ class CardVerify extends React.Component<Props, State> {
</button> </button>
</div> </div>
</div> </div>
</div>} </div>
)}
{currentFlowStage === 'cardConfirmed' && <div className="successCard"> {currentFlowStage === 'cardConfirmed' && (
<div className="successCard">
<Card <Card
title={__('Card Details')} title={__('Card Details')}
body={<> body={
<h4 className="grey-text">Brand: {userCardDetails.brand.toUpperCase()} &nbsp; <>
Last 4: {userCardDetails.lastFour} &nbsp; <h4 className="grey-text">
Brand: {userCardDetails.brand.toUpperCase()} &nbsp; Last 4: {userCardDetails.lastFour} &nbsp;
Expires: {userCardDetails.expiryMonth}/{userCardDetails.expiryYear} &nbsp; Expires: {userCardDetails.expiryMonth}/{userCardDetails.expiryYear} &nbsp;
</h4> </h4>
</>} </>
}
/> />
<br /> <br />
{(!customerTransactions || customerTransactions.length === 0) && <Card {(!customerTransactions || customerTransactions.length === 0) && (
<Card
title={__('Tip History')} title={__('Tip History')}
subtitle={__('You have not sent any tips yet. When you do they will appear here. ')} subtitle={__('You have not sent any tips yet. When you do they will appear here. ')}
/>} />
)}
{customerTransactions && customerTransactions.length > 0 && <Card {customerTransactions && customerTransactions.length > 0 && (
<Card
title={__('Tip History')} title={__('Tip History')}
body={<><div className="table__wrapper"> body={
<>
<div className="table__wrapper">
<table className="table table--transactions"> <table className="table table--transactions">
<thead> <thead>
<tr> <tr>
@ -403,10 +460,13 @@ class CardVerify extends React.Component<Props, State> {
))} ))}
</tbody> </tbody>
</table> </table>
</div></>} </div>
/>} </>
</div>} }
/>
)}
</div>
)}
</Page> </Page>
); );
} }