Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Refactor protocol #354

Merged
merged 2 commits into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/screens/AccountNetworkChooser.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AccountNetworkChooserView extends React.PureComponent {
}
]}
onPress={() => {
accounts.updateNew({ networkKey, protocol: networkParams.protocol });
accounts.updateNew({ networkKey });
navigation.goBack();
}}
>
Expand Down
4 changes: 2 additions & 2 deletions src/screens/SignedTx.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import AccountCard from '../components/AccountCard';
import PayloadDetailsCard from '../components/PayloadDetailsCard';
import TxDetailsCard from '../components/TxDetailsCard';
import QrView from '../components/QrView';
import { NetworkProtocols, TX_DETAILS_MSG } from '../constants';
import { NETWORK_LIST, NetworkProtocols, TX_DETAILS_MSG } from '../constants';
import fonts from '../fonts';
import AccountsStore from '../stores/AccountsStore';
import ScannerStore from '../stores/ScannerStore';
Expand Down Expand Up @@ -71,7 +71,7 @@ export class SignedTxView extends React.PureComponent {
</View>
<Text style={styles.title}>TRANSACTION DETAILS</Text>
{
sender.protocol === NetworkProtocols.ETHEREUM
NETWORK_LIST[sender.networkKey].protocol === NetworkProtocols.ETHEREUM
? (
<React.Fragment>
<TxDetailsCard
Expand Down
4 changes: 3 additions & 1 deletion src/screens/TxDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import PropTypes from 'prop-types';
import React from 'react';
import { ScrollView, StyleSheet, Text } from 'react-native';
import { Subscribe } from 'unstated';

import colors from '../colors';
import { NETWORK_LIST } from '../constants';
import fonts from "../fonts";
import AccountCard from '../components/AccountCard';
import Background from '../components/Background';
Expand Down Expand Up @@ -99,7 +101,7 @@ export class TxDetailsView extends React.PureComponent {
<Text style={styles.title}>TRANSACTION DETAILS</Text>

{
this.props.sender.protocol === NetworkProtocols.ETHEREUM
NETWORK_LIST[this.props.sender.networkKey].protocol === NetworkProtocols.ETHEREUM
? (
<React.Fragment>
<TxDetailsCard
Expand Down
6 changes: 2 additions & 4 deletions src/stores/ScannerStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ export default class ScannerStore extends Container<ScannerState> {
const networkKey = isEthereum ? tx.ethereumChainId : txRequest.data.data.genesisHash.toHex();

const sender = accountsStore.getById({
protocol,
networkKey,
address: txRequest.data.account
});
Expand All @@ -211,14 +210,13 @@ export default class ScannerStore extends Container<ScannerState> {
}

const recipient = accountsStore.getById({
protocol,
networkKey: networkKey,
address: isEthereum ? tx.action : txRequest.data.account
});

// For Eth, always sign the keccak hash.
// For Substrate, only sign the blake2 hash if payload bytes length > 256 bytes (handled in decoder.js).
const dataToSign = sender.protocol === NetworkProtocols.ETHEREUM ? await keccak(txRequest.data.rlp) : txRequest.data.data;
const dataToSign = NETWORK_LIST[sender.networkKey].protocol === NetworkProtocols.ETHEREUM ? await keccak(txRequest.data.rlp) : txRequest.data.data;

this.setState({
type: 'transaction',
Expand All @@ -236,7 +234,7 @@ export default class ScannerStore extends Container<ScannerState> {
const { isHash, sender, type } = this.state;

const seed = await decryptData(sender.encryptedSeed, pin);
const isEthereum = sender.protocol === NetworkProtocols.ETHEREUM;
const isEthereum = NETWORK_LIST[sender.networkKey].protocol === NetworkProtocols.ETHEREUM;

let signedData;

Expand Down