-
Notifications
You must be signed in to change notification settings - Fork 47
/
ConfirmTxScreen.tsx
156 lines (128 loc) · 4.54 KB
/
ConfirmTxScreen.tsx
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
/* eslint-disable @typescript-eslint/no-explicit-any */
import React, {useEffect, useRef} from 'react'
import {useIntl} from 'react-intl'
import {Keyboard, ScrollView, StyleSheet, View, ViewProps} from 'react-native'
import {KeyboardSpacer, Spacer, ValidatedTextInput} from '../../../../components'
import {ConfirmTx} from '../../../../components/ConfirmTx'
import globalMessages, {confirmationMessages, errorMessages, txLabels} from '../../../../i18n/global-messages'
import {useWalletNavigation} from '../../../../navigation'
import {useSelectedWallet} from '../../../../SelectedWallet'
import {COLORS} from '../../../../theme'
import {useSaveMemo} from '../../../../yoroi-wallets/hooks'
import {debugWalletInfo, features} from '../../..'
import {useSend} from '../../common/SendContext'
import {BalanceAfter} from './Summary/BalanceAfter'
import {CurrentBalance} from './Summary/CurrentBalance'
import {Fees} from './Summary/Fees'
import {PrimaryTotal} from './Summary/PrimaryTotal'
import {ReceiverInfo} from './Summary/ReceiverInfo'
import {SecondaryTotals} from './Summary/SecondaryTotals'
export const ConfirmTxScreen = () => {
const strings = useStrings()
const {resetToTxHistory} = useWalletNavigation()
const wallet = useSelectedWallet()
const [password, setPassword] = React.useState('')
const [useUSB, setUseUSB] = React.useState(false)
const {memo, resetForm, yoroiUnsignedTx, targets} = useSend()
if (!yoroiUnsignedTx) throw new Error('No unsigned tx')
const {saveMemo} = useSaveMemo({wallet})
useEffect(() => {
if (features.prefillWalletInfo && __DEV__) {
setPassword(debugWalletInfo.PASSWORD)
}
}, [])
const onSuccess = (signedTx) => {
resetToTxHistory()
if (memo.length > 0) {
saveMemo({txId: signedTx.signedTx.id, memo})
}
resetForm()
}
const scrollViewRef = useFlashAndScroll()
return (
<View style={styles.root}>
<CurrentBalance />
<View style={{paddingTop: 16, paddingHorizontal: 16}}>
<Fees yoroiUnsignedTx={yoroiUnsignedTx} />
<Spacer height={4} />
<BalanceAfter yoroiUnsignedTx={yoroiUnsignedTx} />
<Spacer height={16} />
{targets.map((target, index) => (
<ReceiverInfo key={index} address={target.entry.address} receiver={target.receiver} />
))}
</View>
<ScrollView
style={styles.container}
contentContainerStyle={{padding: 16}}
persistentScrollbar
ref={scrollViewRef}
>
<PrimaryTotal yoroiUnsignedTx={yoroiUnsignedTx} />
<Spacer height={8} />
<SecondaryTotals yoroiUnsignedTx={yoroiUnsignedTx} />
{!wallet.isEasyConfirmationEnabled && !wallet.isHW && (
<>
<ValidatedTextInput
secureTextEntry
value={password}
label={strings.password}
onChangeText={setPassword}
testID="spendingPasswordInput"
/>
</>
)}
<KeyboardSpacer />
</ScrollView>
<Actions>
<ConfirmTx
onSuccess={onSuccess}
yoroiUnsignedTx={yoroiUnsignedTx}
useUSB={useUSB}
setUseUSB={setUseUSB}
isProvidingPassword
providedPassword={password}
chooseTransportOnConfirmation
/>
</Actions>
</View>
)
}
const Actions = (props: ViewProps) => <View {...props} style={{padding: 16}} />
const styles = StyleSheet.create({
root: {
backgroundColor: COLORS.WHITE,
flex: 1,
},
container: {
backgroundColor: COLORS.WHITE,
flex: 1,
},
})
const useStrings = () => {
const intl = useIntl()
return {
availableFunds: intl.formatMessage(globalMessages.availableFunds),
balanceAfterTx: intl.formatMessage(txLabels.balanceAfterTx),
total: intl.formatMessage(globalMessages.total),
password: intl.formatMessage(txLabels.password),
confirmButton: intl.formatMessage(confirmationMessages.commonButtons.confirmButton),
submittingTx: intl.formatMessage(txLabels.submittingTx),
pleaseWait: intl.formatMessage(globalMessages.pleaseWait),
generalTxError: {
title: intl.formatMessage(errorMessages.generalTxError.title),
message: intl.formatMessage(errorMessages.generalTxError.message),
},
}
}
const useFlashAndScroll = () => {
const scrollViewRef = useRef<ScrollView | null>(null)
useEffect(() => {
setTimeout(() => {
scrollViewRef.current?.flashScrollIndicators()
}, 500)
Keyboard.addListener('keyboardWillShow', () => {
scrollViewRef.current?.scrollToEnd()
})
}, [])
return scrollViewRef
}