-
Notifications
You must be signed in to change notification settings - Fork 47
/
WalletSettingsScreen.js
260 lines (243 loc) · 7.16 KB
/
WalletSettingsScreen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
// @flow
import React from 'react'
import {compose} from 'redux'
import {withHandlers} from 'recompose'
import {connect} from 'react-redux'
import {ScrollView, StyleSheet, Switch} from 'react-native'
import {injectIntl, defineMessages, intlShape} from 'react-intl'
import {ignoreConcurrentAsyncHandler} from '../../utils/utils'
import {confirmationMessages} from '../../i18n/global-messages'
import {
closeWallet,
logout,
showConfirmationDialog,
DIALOG_BUTTONS,
} from '../../actions'
import {WALLET_INIT_ROUTES, SETTINGS_ROUTES} from '../../RoutesList'
import {withNavigationTitle} from '../../utils/renderUtils'
import {
isSystemAuthEnabledSelector,
easyConfirmationSelector,
walletNameSelector,
languageSelector,
isHWSelector,
walletMetaSelector,
} from '../../selectors'
import {
SettingsItem,
SettingsBuildItem,
NavigatedSettingsItem,
SettingsSection,
PressableSettingsItem,
} from './SettingsItems'
import {StatusBar} from '../UiKit'
import {isByron, isHaskellShelley} from '../../config/config'
import {getNetworkConfigById} from '../../config/networks'
import type {Navigation} from '../../types/navigation'
import type {ComponentType} from 'react'
import type {NetworkId, WalletImplementationId} from '../../config/types'
import type {MessageDescriptor} from 'react-intl'
const messages = defineMessages({
title: {
id: 'components.settings.walletsettingscreen.title',
defaultMessage: 'Settings',
},
tabTitle: {
id: 'components.settings.walletsettingscreen.tabTitle',
defaultMessage: 'Wallet',
},
switchWallet: {
id: 'components.settings.walletsettingscreen.switchWallet',
defaultMessage: 'Switch wallet',
},
logout: {
id: 'components.settings.walletsettingscreen.logout',
defaultMessage: 'Logout',
description: 'some desc',
},
walletName: {
id: 'components.settings.walletsettingscreen.walletName',
defaultMessage: 'Wallet name',
description: 'some desc',
},
security: {
id: 'components.settings.walletsettingscreen.security',
defaultMessage: 'Security',
description: 'some desc',
},
changePassword: {
id: 'components.settings.walletsettingscreen.changePassword',
defaultMessage: 'Change password',
description: 'some desc',
},
easyConfirmation: {
id: 'components.settings.walletsettingscreen.easyConfirmation',
defaultMessage: '!!!Easy transaction confirmation',
description: 'some desc',
},
removeWallet: {
id: 'components.settings.walletsettingscreen.removeWallet',
defaultMessage: '!!!Remove wallet',
},
// note: moved here from application settings
network: {
id: 'components.settings.applicationsettingsscreen.network',
defaultMessage: '!!!Network:',
},
walletType: {
id: 'components.settings.walletsettingscreen.walletType',
defaultMessage: '!!!Wallet type:',
},
byronWallet: {
id: 'components.settings.walletsettingscreen.byronWallet',
defaultMessage: '!!!Byron-era wallet',
},
shelleyWallet: {
id: 'components.settings.walletsettingscreen.shelleyWallet',
defaultMessage: '!!!Shelley-era wallet',
},
})
const styles = StyleSheet.create({
scrollView: {
backgroundColor: '#fff',
},
})
const _getNetworkName = (networkId: NetworkId) => {
// note(v-almonacid): this throws when switching wallet
try {
const config = getNetworkConfigById(networkId)
return config.MARKETING_NAME
} catch (_e) {
return '-'
}
}
const _getWalletType = (implId: WalletImplementationId): ?MessageDescriptor => {
if (isByron(implId)) return messages.byronWallet
else if (isHaskellShelley(implId)) return messages.shelleyWallet
else return null
}
const WalletSettingsScreen = ({
onToggleEasyConfirmation,
isEasyConfirmationEnabled,
isSystemAuthEnabled,
intl,
walletName,
onSwitchWallet,
onLogout,
isHW,
walletMeta,
}) => (
<ScrollView style={styles.scrollView}>
<StatusBar type="dark" />
<SettingsSection>
<PressableSettingsItem
label={intl.formatMessage(messages.switchWallet)}
onPress={onSwitchWallet}
/>
<PressableSettingsItem
label={intl.formatMessage(messages.logout)}
onPress={onLogout}
/>
</SettingsSection>
<SettingsSection title={intl.formatMessage(messages.walletName)}>
<NavigatedSettingsItem
label={walletName}
navigateTo={SETTINGS_ROUTES.CHANGE_WALLET_NAME}
/>
</SettingsSection>
<SettingsSection title={intl.formatMessage(messages.security)}>
<NavigatedSettingsItem
label={intl.formatMessage(messages.changePassword)}
navigateTo={SETTINGS_ROUTES.CHANGE_PASSWORD}
disabled={isHW}
/>
<SettingsItem
label={intl.formatMessage(messages.easyConfirmation)}
disabled={!isSystemAuthEnabled || isHW}
>
<Switch
value={isEasyConfirmationEnabled}
onValueChange={onToggleEasyConfirmation}
disabled={!isSystemAuthEnabled || isHW}
/>
</SettingsItem>
</SettingsSection>
<SettingsSection>
<NavigatedSettingsItem
label={intl.formatMessage(messages.removeWallet)}
navigateTo={SETTINGS_ROUTES.REMOVE_WALLET}
/>
</SettingsSection>
<SettingsSection title="About">
<SettingsBuildItem
label={intl.formatMessage(messages.network)}
value={_getNetworkName(walletMeta.networkId)}
/>
{_getWalletType(walletMeta.walletImplementationId) != null && (
<SettingsBuildItem
label={intl.formatMessage(messages.walletType)}
value={intl.formatMessage(
_getWalletType(walletMeta.walletImplementationId),
)}
/>
)}
</SettingsSection>
</ScrollView>
)
export default injectIntl(
(compose(
connect((state) => ({
isSystemAuthEnabled: isSystemAuthEnabledSelector(state),
isEasyConfirmationEnabled: easyConfirmationSelector(state),
key: languageSelector(state),
})),
withNavigationTitle(({intl}) => intl.formatMessage(messages.title)),
withNavigationTitle(
({intl}) => intl.formatMessage(messages.tabTitle),
'walletTabTitle',
),
connect(
(state) => ({
walletName: walletNameSelector(state),
isHW: isHWSelector(state),
walletMeta: walletMetaSelector(state),
}),
{
closeWallet,
logout,
},
),
withHandlers({
onToggleEasyConfirmation: ({
isEasyConfirmationEnabled,
navigation,
}) => () => {
navigation.navigate(SETTINGS_ROUTES.EASY_COMFIRMATION)
},
}),
withHandlers({
onSwitchWallet: ignoreConcurrentAsyncHandler(
({navigation, closeWallet}) => async () => {
await closeWallet()
navigation.navigate(WALLET_INIT_ROUTES.WALLET_SELECTION)
},
1000,
),
onLogout: ignoreConcurrentAsyncHandler(
({logout, intl}) => async () => {
const selection = await showConfirmationDialog(
confirmationMessages.logout,
intl,
)
if (selection === DIALOG_BUTTONS.YES) {
await logout()
}
},
500,
),
}),
)(WalletSettingsScreen): ComponentType<{|
navigation: Navigation,
intl: intlShape,
|}>),
)