diff options
author | 2017-10-13 12:29:40 +0200 | |
---|---|---|
committer | 2017-10-13 12:29:40 +0200 | |
commit | 58cda9cc7fb79ca9df6746de7f9662bc08dc156a (patch) | |
tree | 1211600c2a5d3b5f81c435c6896618111a611720 /src/containers/ui | |
download | ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.gz ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.zst ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.zip |
initial commit
Diffstat (limited to 'src/containers/ui')
-rw-r--r-- | src/containers/ui/SubscriptionFormScreen.js | 126 | ||||
-rw-r--r-- | src/containers/ui/SubscriptionPopupScreen.js | 43 |
2 files changed, 169 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 @@ | |||
1 | import { remote } from 'electron'; | ||
2 | import React, { Component } from 'react'; | ||
3 | import PropTypes from 'prop-types'; | ||
4 | import { inject, observer } from 'mobx-react'; | ||
5 | |||
6 | import PaymentStore from '../../stores/PaymentStore'; | ||
7 | |||
8 | import SubscriptionForm from '../../components/ui/Subscription'; | ||
9 | |||
10 | const { BrowserWindow } = remote; | ||
11 | |||
12 | @inject('stores', 'actions') @observer | ||
13 | export 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 | |||
111 | SubscriptionFormScreen.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 | }; | ||
diff --git a/src/containers/ui/SubscriptionPopupScreen.js b/src/containers/ui/SubscriptionPopupScreen.js new file mode 100644 index 000000000..d17477b1d --- /dev/null +++ b/src/containers/ui/SubscriptionPopupScreen.js | |||
@@ -0,0 +1,43 @@ | |||
1 | import React, { Component } from 'react'; | ||
2 | import PropTypes from 'prop-types'; | ||
3 | import { inject, observer } from 'mobx-react'; | ||
4 | |||
5 | import SubscriptionPopup from '../../components/ui/SubscriptionPopup'; | ||
6 | |||
7 | |||
8 | @inject('stores', 'actions') @observer | ||
9 | export default class SubscriptionPopupScreen extends Component { | ||
10 | state = { | ||
11 | complete: false, | ||
12 | }; | ||
13 | |||
14 | completeCheck(event) { | ||
15 | const { url } = event; | ||
16 | |||
17 | if (url.includes('recurly') && url.includes('confirmation')) { | ||
18 | this.setState({ | ||
19 | complete: true, | ||
20 | }); | ||
21 | } | ||
22 | } | ||
23 | |||
24 | render() { | ||
25 | return ( | ||
26 | <SubscriptionPopup | ||
27 | url={decodeURIComponent(this.props.router.params.url)} | ||
28 | closeWindow={() => window.close()} | ||
29 | completeCheck={e => this.completeCheck(e)} | ||
30 | isCompleted={this.state.complete} | ||
31 | /> | ||
32 | ); | ||
33 | } | ||
34 | } | ||
35 | |||
36 | |||
37 | SubscriptionPopupScreen.wrappedComponent.propTypes = { | ||
38 | router: PropTypes.shape({ | ||
39 | params: PropTypes.shape({ | ||
40 | url: PropTypes.string.isRequired, | ||
41 | }).isRequired, | ||
42 | }).isRequired, | ||
43 | }; | ||