aboutsummaryrefslogtreecommitdiffstats
path: root/src/containers/ui/SubscriptionFormScreen.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/containers/ui/SubscriptionFormScreen.js')
-rw-r--r--src/containers/ui/SubscriptionFormScreen.js126
1 files changed, 126 insertions, 0 deletions
diff --git a/src/containers/ui/SubscriptionFormScreen.js b/src/containers/ui/SubscriptionFormScreen.js
new file mode 100644
index 000000000..d08507809
--- /dev/null
+++ b/src/containers/ui/SubscriptionFormScreen.js
@@ -0,0 +1,126 @@
1import { remote } from 'electron';
2import React, { Component } from 'react';
3import PropTypes from 'prop-types';
4import { inject, observer } from 'mobx-react';
5
6import PaymentStore from '../../stores/PaymentStore';
7
8import SubscriptionForm from '../../components/ui/Subscription';
9
10const { BrowserWindow } = remote;
11
12@inject('stores', 'actions') @observer
13export default class SubscriptionFormScreen extends Component {
14 static propTypes = {
15 onCloseWindow: PropTypes.func,
16 content: PropTypes.oneOrManyChildElements,
17 showSkipOption: PropTypes.bool,
18 skipAction: PropTypes.func,
19 skipButtonLabel: PropTypes.string,
20 hideInfo: PropTypes.bool,
21 }
22
23 static defaultProps = {
24 onCloseWindow: () => null,
25 content: '',
26 showSkipOption: false,
27 skipAction: () => null,
28 skipButtonLabel: '',
29 hideInfo: false,
30 }
31
32 async handlePayment(plan) {
33 const {
34 actions,
35 stores,
36 onCloseWindow,
37 skipAction,
38 } = this.props;
39
40 if (plan !== 'mining') {
41 const interval = plan;
42
43 const { id } = stores.payment.plan[interval];
44 actions.payment.createHostedPage({
45 planId: id,
46 });
47
48 const hostedPage = await stores.payment.createHostedPageRequest;
49 const url = `file://${__dirname}/../../index.html#/payment/${encodeURIComponent(hostedPage.url)}`;
50
51 if (hostedPage.url) {
52 const paymentWindow = new BrowserWindow({
53 parent: remote.getCurrentWindow(),
54 modal: true,
55 title: '🔒 Franz Supporter License',
56 width: 600,
57 height: window.innerHeight - 100,
58 maxWidth: 600,
59 minWidth: 600,
60 webPreferences: {
61 nodeIntegration: true,
62 },
63 });
64 paymentWindow.loadURL(url);
65
66 paymentWindow.on('closed', () => {
67 onCloseWindow();
68 });
69 }
70 } else {
71 actions.user.update({
72 userData: {
73 isMiner: true,
74 },
75 });
76
77 skipAction();
78 }
79 }
80
81 render() {
82 const {
83 content,
84 actions,
85 stores,
86 showSkipOption,
87 skipAction,
88 skipButtonLabel,
89 hideInfo,
90 } = this.props;
91 return (
92 <SubscriptionForm
93 plan={stores.payment.plan}
94 // form={this.prepareForm(stores.payment.plan)}
95 isLoading={stores.payment.plansRequest.isExecuting}
96 retryPlanRequest={() => stores.payment.plansRequest.reload()}
97 isCreatingHostedPage={stores.payment.createHostedPageRequest.isExecuting}
98 handlePayment={price => this.handlePayment(price)}
99 content={content}
100 error={stores.payment.plansRequest.isError}
101 showSkipOption={showSkipOption}
102 skipAction={skipAction}
103 skipButtonLabel={skipButtonLabel}
104 hideInfo={hideInfo}
105 openExternalUrl={actions.app.openExternalUrl}
106 />
107 );
108 }
109}
110
111SubscriptionFormScreen.wrappedComponent.propTypes = {
112 actions: PropTypes.shape({
113 app: PropTypes.shape({
114 openExternalUrl: PropTypes.func.isRequired,
115 }).isRequired,
116 payment: PropTypes.shape({
117 createHostedPage: PropTypes.func.isRequired,
118 }).isRequired,
119 user: PropTypes.shape({
120 update: PropTypes.func.isRequired,
121 }).isRequired,
122 }).isRequired,
123 stores: PropTypes.shape({
124 payment: PropTypes.instanceOf(PaymentStore).isRequired,
125 }).isRequired,
126};