diff options
author | Stefan Malzner <stefan@adlk.io> | 2017-10-13 12:29:40 +0200 |
---|---|---|
committer | Stefan Malzner <stefan@adlk.io> | 2017-10-13 12:29:40 +0200 |
commit | 58cda9cc7fb79ca9df6746de7f9662bc08dc156a (patch) | |
tree | 1211600c2a5d3b5f81c435c6896618111a611720 /src/containers/settings/AccountScreen.js | |
download | ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.gz ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.zst ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.zip |
initial commit
Diffstat (limited to 'src/containers/settings/AccountScreen.js')
-rw-r--r-- | src/containers/settings/AccountScreen.js | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/src/containers/settings/AccountScreen.js b/src/containers/settings/AccountScreen.js new file mode 100644 index 000000000..a1ac8bda3 --- /dev/null +++ b/src/containers/settings/AccountScreen.js | |||
@@ -0,0 +1,114 @@ | |||
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 | import UserStore from '../../stores/UserStore'; | ||
8 | import AppStore from '../../stores/AppStore'; | ||
9 | import { gaPage } from '../../lib/analytics'; | ||
10 | |||
11 | import AccountDashboard from '../../components/settings/account/AccountDashboard'; | ||
12 | |||
13 | const { BrowserWindow } = remote; | ||
14 | |||
15 | @inject('stores', 'actions') @observer | ||
16 | export default class AccountScreen extends Component { | ||
17 | componentDidMount() { | ||
18 | gaPage('Settings/Account Dashboard'); | ||
19 | } | ||
20 | |||
21 | onCloseWindow() { | ||
22 | const { user, payment } = this.props.stores; | ||
23 | user.getUserInfoRequest.invalidate({ immediately: true }); | ||
24 | payment.ordersDataRequest.invalidate({ immediately: true }); | ||
25 | } | ||
26 | |||
27 | reloadData() { | ||
28 | const { user, payment } = this.props.stores; | ||
29 | |||
30 | user.getUserInfoRequest.reload(); | ||
31 | payment.ordersDataRequest.reload(); | ||
32 | payment.plansRequest.reload(); | ||
33 | } | ||
34 | |||
35 | stopMiner() { | ||
36 | const { update } = this.props.actions.user; | ||
37 | |||
38 | update({ userData: { | ||
39 | isMiner: false, | ||
40 | } }); | ||
41 | } | ||
42 | |||
43 | async handlePaymentDashboard() { | ||
44 | const { actions, stores } = this.props; | ||
45 | |||
46 | actions.payment.createDashboardUrl(); | ||
47 | |||
48 | const dashboard = await stores.payment.createDashboardUrlRequest; | ||
49 | |||
50 | if (dashboard.url) { | ||
51 | const paymentWindow = new BrowserWindow({ | ||
52 | title: '🔒 Franz Subscription Dashboard', | ||
53 | parent: remote.getCurrentWindow(), | ||
54 | modal: false, | ||
55 | width: 900, | ||
56 | minWidth: 600, | ||
57 | webPreferences: { | ||
58 | nodeIntegration: false, | ||
59 | }, | ||
60 | }); | ||
61 | paymentWindow.loadURL(dashboard.url); | ||
62 | |||
63 | paymentWindow.on('closed', () => { | ||
64 | this.onCloseWindow(); | ||
65 | }); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | render() { | ||
70 | const { user, payment, app } = this.props.stores; | ||
71 | const { openExternalUrl } = this.props.actions.app; | ||
72 | |||
73 | const isLoadingUserInfo = user.getUserInfoRequest.isExecuting; | ||
74 | const isLoadingOrdersInfo = payment.ordersDataRequest.isExecuting; | ||
75 | const isLoadingPlans = payment.plansRequest.isExecuting; | ||
76 | |||
77 | return ( | ||
78 | <AccountDashboard | ||
79 | user={user.data} | ||
80 | orders={payment.orders} | ||
81 | hashrate={app.minerHashrate} | ||
82 | isLoading={isLoadingUserInfo} | ||
83 | isLoadingOrdersInfo={isLoadingOrdersInfo} | ||
84 | isLoadingPlans={isLoadingPlans} | ||
85 | userInfoRequestFailed={user.getUserInfoRequest.wasExecuted && user.getUserInfoRequest.isError} | ||
86 | retryUserInfoRequest={() => this.reloadData()} | ||
87 | isCreatingPaymentDashboardUrl={payment.createDashboardUrlRequest.isExecuting} | ||
88 | openDashboard={price => this.handlePaymentDashboard(price)} | ||
89 | openExternalUrl={url => openExternalUrl({ url })} | ||
90 | onCloseSubscriptionWindow={() => this.onCloseWindow()} | ||
91 | stopMiner={() => this.stopMiner()} | ||
92 | /> | ||
93 | ); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | AccountScreen.wrappedComponent.propTypes = { | ||
98 | stores: PropTypes.shape({ | ||
99 | user: PropTypes.instanceOf(UserStore).isRequired, | ||
100 | payment: PropTypes.instanceOf(PaymentStore).isRequired, | ||
101 | app: PropTypes.instanceOf(AppStore).isRequired, | ||
102 | }).isRequired, | ||
103 | actions: PropTypes.shape({ | ||
104 | payment: PropTypes.shape({ | ||
105 | createDashboardUrl: PropTypes.func.isRequired, | ||
106 | }).isRequired, | ||
107 | app: PropTypes.shape({ | ||
108 | openExternalUrl: PropTypes.func.isRequired, | ||
109 | }).isRequired, | ||
110 | user: PropTypes.shape({ | ||
111 | update: PropTypes.func.isRequired, | ||
112 | }).isRequired, | ||
113 | }).isRequired, | ||
114 | }; | ||