SignedTx.tsx 3.35 KB
Newer Older
Thibaut Sardan's avatar
Thibaut Sardan committed
1
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
Alexey's avatar
Alexey committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity.  If not, see <http://www.gnu.org/licenses/>.

Hanwen Cheng's avatar
Hanwen Cheng committed
17
import React, { useEffect } from 'react';
18
import { ScrollView, StyleSheet, Text, View } from 'react-native';
YJ's avatar
YJ committed
19

20
21
22
23
24
25
26
27
28
29
30
31
import { NETWORK_LIST } from 'constants/networkSpecs';
import testIDs from 'e2e/testIDs';
import { isEthereumNetworkParams } from 'types/networkSpecsTypes';
import { NavigationAccountScannerProps } from 'types/props';
import colors from 'styles/colors';
import PayloadDetailsCard from 'components/PayloadDetailsCard';
import TxDetailsCard from 'components/TxDetailsCard';
import QrView from 'components/QrView';
import { withAccountAndScannerStore } from 'utils/HOC';
import fontStyles from 'styles/fontStyles';
import CompatibleCard from 'components/CompatibleCard';
import { Transaction } from 'utils/transaction';
Alexey's avatar
Alexey committed
32

33
34
35
36
37
38
39
function SignedTx({
	scannerStore,
	accounts
}: NavigationAccountScannerProps<{}>): React.ReactElement {
	const data = scannerStore.getSignedTxData();
	const recipient = scannerStore.getRecipient()!;
	const sender = scannerStore.getSender();
Alexey's avatar
Alexey committed
40

Hanwen Cheng's avatar
Hanwen Cheng committed
41
42
	useEffect(
		() =>
43
44
			function(): void {
				scannerStore.cleanup();
Hanwen Cheng's avatar
Hanwen Cheng committed
45
			},
46
		[scannerStore]
Hanwen Cheng's avatar
Hanwen Cheng committed
47
	);
Alexey's avatar
Alexey committed
48

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
	const renderTxPayload = (): React.ReactElement => {
		const networkParams = NETWORK_LIST[sender!.networkKey];
		if (isEthereumNetworkParams(networkParams)) {
			const { gas, gasPrice, value } = scannerStore.getTx() as Transaction;
			return (
				<React.Fragment>
					<TxDetailsCard
						style={{ marginBottom: 20 }}
						description={TX_DETAILS_MSG}
						value={value}
						gas={gas}
						gasPrice={gasPrice}
					/>
					<Text style={styles.title}>Recipient</Text>
					<CompatibleCard account={recipient} accountsStore={accounts} />
				</React.Fragment>
			);
		} else {
			return (
				<PayloadDetailsCard
					style={{ marginBottom: 20 }}
					description={TX_DETAILS_MSG}
					signature={data}
72
					networkKey={sender!.networkKey}
73
74
75
76
77
				/>
			);
		}
	};

Hanwen Cheng's avatar
Hanwen Cheng committed
78
79
80
81
82
83
84
85
86
	return (
		<ScrollView
			contentContainerStyle={{ paddingBottom: 40 }}
			style={styles.body}
		>
			<Text style={styles.topTitle}>Scan Signature</Text>
			<View style={styles.qr} testID={testIDs.SignedTx.qrView}>
				<QrView data={data} />
			</View>
87

Hanwen Cheng's avatar
Hanwen Cheng committed
88
89
			<Text style={styles.title}>Transaction Details</Text>
			<View style={{ marginBottom: 20, marginHorizontal: 20 }}>
90
				{renderTxPayload()}
Hanwen Cheng's avatar
Hanwen Cheng committed
91
92
93
			</View>
		</ScrollView>
	);
Alexey's avatar
Alexey committed
94
95
}

Hanwen Cheng's avatar
Hanwen Cheng committed
96
97
98
99
export default withAccountAndScannerStore(SignedTx);

const TX_DETAILS_MSG = 'After signing and publishing you will have sent';

Alexey's avatar
Alexey committed
100
const styles = StyleSheet.create({
101
	body: {
Hanwen Cheng's avatar
Hanwen Cheng committed
102
		alignContent: 'flex-start',
103
104
		backgroundColor: colors.bg,
		flex: 1,
Hanwen Cheng's avatar
Hanwen Cheng committed
105
		paddingTop: 24
106
107
108
109
110
	},
	qr: {
		marginBottom: 20
	},
	title: {
Hanwen Cheng's avatar
Hanwen Cheng committed
111
112
		...fontStyles.h2,
		marginHorizontal: 20,
113
114
115
		paddingBottom: 20
	},
	topTitle: {
Hanwen Cheng's avatar
Hanwen Cheng committed
116
		...fontStyles.h1,
117
118
119
		paddingBottom: 20,
		textAlign: 'center'
	}
Alexey's avatar
Alexey committed
120
});