AbstractAccound refactor

pull/2/merge
Szymon Lesisz 6 years ago
parent c2fe9d4b95
commit bb22ca54f0

@ -3,11 +3,9 @@
import * as ACCOUNT from './constants/account';
import { initialState } from '../reducers/AccountDetailReducer';
import { initialState } from '../reducers/AbstractAccountReducer';
import { findSelectedDevice } from '../reducers/TrezorConnectReducer';
import type { State } from '../reducers/AccountDetailReducer';
import type { Discovery } from '../reducers/DiscoveryReducer';
import type { State } from '../reducers/AbstractAccountReducer';
export const init = (): any => {
return (dispatch, getState): void => {
@ -18,10 +16,11 @@ export const init = (): any => {
const selected = findSelectedDevice( getState().connect );
if (!selected) return;
const state: State = {
index: parseInt(urlParams.address),
deviceState: selected.state,
deviceId: selected.features.device_id,
deviceInstance: selected.instance,
network: urlParams.network,
location: location.pathname
};
@ -33,33 +32,21 @@ export const init = (): any => {
}
}
export const update = (newProps: any): any => {
export const update = (): any => {
return (dispatch, getState): void => {
const {
accountDetail,
connect,
discovery,
accounts,
abstractAccount,
router
} = getState();
const isLocationChanged: boolean = newProps.location.pathname !== accountDetail.location;
const isLocationChanged: boolean = router.location.pathname !== abstractAccount.location;
if (isLocationChanged) {
dispatch({
type: ACCOUNT.INIT,
state: {
...accountDetail,
location: newProps.location.pathname,
}
});
dispatch( init() );
return;
}
}
}
export const dispose = (device: any): any => {
export const dispose = (): any => {
return (dispatch, getState): void => {
dispatch({
type: ACCOUNT.DISPOSE,

@ -12,20 +12,9 @@ import { findSelectedDevice } from '../reducers/TrezorConnectReducer';
export const init = (): any => {
return (dispatch, getState): void => {
const { location } = getState().router;
const urlParams = location.params;
const selected = findSelectedDevice( getState().connect );
if (!selected) return;
const state: State = {
...initialState,
deviceState: selected.state,
deviceId: selected.features.device_id,
deviceInstance: selected.instance,
accountIndex: parseInt(urlParams.address),
network: urlParams.network,
location: location.pathname,
};
dispatch({
@ -39,14 +28,13 @@ export const init = (): any => {
export const update = (newProps: any): any => {
return (dispatch, getState): void => {
const {
receive,
abstractAccount,
router
} = getState();
const isLocationChanged: boolean = router.location.pathname !== receive.location;
const isLocationChanged: boolean = router.location.pathname !== abstractAccount.location;
if (isLocationChanged) {
dispatch( init() );
return;
}
}
}

@ -15,7 +15,9 @@ import { push } from 'react-router-redux';
import BigNumber from 'bignumber.js';
import { initialState } from '../reducers/SendFormReducer';
import { findAccount } from '../reducers/AccountsReducer';
import type { State, FeeLevel } from '../reducers/SendFormReducer';
import type { Account } from '../reducers/AccountsReducer';
import { findSelectedDevice } from '../reducers/TrezorConnectReducer';
//const numberRegExp = new RegExp('^([0-9]{0,10}\\.)?[0-9]{1,18}$');
@ -33,7 +35,7 @@ const calculateTotal = (amount: string, gasPrice: string, gasLimit: string): str
}
}
export const calculateMaxAmount = (balance: string, gasPrice: string, gasLimit: string): string => {
const calculateMaxAmount = (balance: string, gasPrice: string, gasLimit: string): string => {
try {
const fee = EthereumjsUnits.convert( new BigNumber(gasPrice).times(gasLimit), 'gwei', 'ether');
const b = new BigNumber(balance);
@ -46,6 +48,10 @@ export const calculateMaxAmount = (balance: string, gasPrice: string, gasLimit:
}
const getMaxAmount = () => {
}
export const getFeeLevels = (symbol: string, gasPrice: BigNumber | string, gasLimit: string): Array<FeeLevel> => {
if (typeof gasPrice === 'string') gasPrice = new BigNumber(gasPrice);
const quarter: BigNumber = gasPrice.dividedBy(4);
@ -77,11 +83,12 @@ export const getFeeLevels = (symbol: string, gasPrice: BigNumber | string, gasLi
}
export const findBalance = (getState: any): string => {
const state = getState().sendForm;
const account = getState().accounts.find(a => a.deviceState === state.deviceState && a.index === state.accountIndex && a.network === state.network);
const accountState = getState().abstractAccount;
const { token } = getState().sendForm;
const account: ?Account = findAccount(getState().accounts, accountState.index, accountState.deviceState, accountState.network);
if (state.token !== state.network) {
return getState().tokens.find(t => t.ethAddress === account.address && t.symbol === state.token).balance;
if (token !== state.network) {
return getState().tokens.find(t => t.ethAddress === account.address && t.symbol === token).balance;
} else {
return account.balance;
}
@ -116,14 +123,8 @@ export const init = (): any => {
const state: State = {
...initialState,
deviceState: selected.state,
deviceId: selected.features.device_id,
deviceInstance: selected.instance,
accountIndex: parseInt(urlParams.address),
network: urlParams.network,
coinSymbol: coin.symbol,
token: urlParams.network,
location: location.pathname,
token: coin.network,
feeLevels,
selectedFeeLevel: feeLevels.find(f => f.value === 'Normal'),
@ -143,11 +144,11 @@ export const init = (): any => {
export const update = (): any => {
return (dispatch, getState): void => {
const {
sendForm,
abstractAccount,
router
} = getState();
const isLocationChanged: boolean = router.location.pathname !== sendForm.location;
const isLocationChanged: boolean = router.location.pathname !== abstractAccount.location;
if (isLocationChanged) {
dispatch( init() );
return;
@ -170,6 +171,7 @@ export const toggleAdvanced = (address: string): any => {
export const validation = (): any => {
return (dispatch, getState): void => {
const accountState = getState().abstractAccount;
const state: State = getState().sendForm;
const errors: {[k: string]: string} = {};
const warnings: {[k: string]: string} = {};
@ -188,7 +190,7 @@ export const validation = (): any => {
} else if (!EthereumjsUtil.isValidAddress(state.address)) {
errors.address = 'Address is not valid';
} else if (myAccount) {
if (myAccount.network === state.network) {
if (myAccount.network === accountState.network) {
infos.address = `TREZOR Address #${ (myAccount.index + 1) }`;
} else {
// TODO: load coins from config
@ -206,10 +208,10 @@ export const validation = (): any => {
} else if (state.amount.length > 0 && !state.amount.match(numberRegExp)) {
errors.amount = 'Amount is not a number';
} else {
const account = getState().accounts.find(a => a.deviceState === state.deviceState && a.index === state.accountIndex && a.network === state.network);
const account: ?Account = findAccount(getState().accounts, accountState.index, accountState.deviceState, accountState.network);
let decimalRegExp;
if (state.token !== state.network) {
if (state.token !== accountState.network) {
const token: any = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === state.token);
if (parseInt(token.decimals) > 0) {
@ -272,7 +274,7 @@ export const validation = (): any => {
}
// valid data
if (state.touched.data && state.network === state.token && state.data.length > 0) {
if (state.touched.data && accountState.network === state.token && state.data.length > 0) {
const re = /^[0-9A-Fa-f]+$/g;
//const re = /^[0-9A-Fa-f]{6}$/g;
if (!re.test(state.data)) {
@ -319,10 +321,12 @@ export const onAddressChange = (address: string): any => {
export const onAmountChange = (amount: string): any => {
return (dispatch, getState): void => {
const accountState = getState().abstractAccount;
const currentState: State = getState().sendForm;
const isToken: boolean = currentState.token !== accountState.network;
const touched = { ...currentState.touched };
touched.amount = true;
const total: string = calculateTotal(currentState.token !== currentState.network ? '0' : amount, currentState.gasPrice, currentState.gasLimit);
const total: string = calculateTotal(isToken ? '0' : amount, currentState.gasPrice, currentState.gasLimit);
const state: State = {
...currentState,
@ -344,23 +348,24 @@ export const onAmountChange = (amount: string): any => {
export const onCurrencyChange = (currency: any): any => {
return (dispatch, getState): void => {
const accountState = getState().abstractAccount;
const currentState = getState().sendForm;
const isToken: boolean = currency.value !== accountState.network;
const account = getState().accounts.find(a => a.deviceState === currentState.deviceState && a.index === currentState.accountIndex && a.network === currentState.network);
const account: ?Account = findAccount(getState().accounts, accountState.index, accountState.deviceState, accountState.network);
if (!account) {
// account not found
return;
}
const { config } = getState().localStorage;
const coin = config.coins.find(c => c.network === currentState.network);
const coin = config.coins.find(c => c.network === accountState.network);
let gasLimit: string = '';
let amount: string = currentState.amount;
let total: string;
if (currentState.network !== currency.value) {
if (isToken) {
gasLimit = coin.defaultGasLimitTokens.toString();
if (currentState.setMax) {
const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currency.value).balance;
@ -399,11 +404,13 @@ export const onCurrencyChange = (currency: any): any => {
export const onSetMax = (): any => {
return (dispatch, getState): void => {
const accountState = getState().abstractAccount;
const currentState = getState().sendForm;
const isToken: boolean = currentState.token !== accountState.network;
const touched = { ...currentState.touched };
touched.amount = true;
const account = getState().accounts.find(a => a.deviceState === currentState.deviceState && a.index === currentState.accountIndex && a.network === currentState.network);
const account: ?Account = findAccount(getState().accounts, accountState.index, accountState.deviceState, accountState.network);
if (!account) {
// account not found
return;
@ -412,7 +419,7 @@ export const onSetMax = (): any => {
let amount: string = currentState.amount;
let total: string = currentState.total;
if (!currentState.setMax) {
if (currentState.token !== currentState.network) {
if (isToken) {
const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currentState.token).balance;
amount = tokenBalance;
total = calculateTotal('0', currentState.gasPrice, currentState.gasLimit);
@ -441,8 +448,10 @@ export const onSetMax = (): any => {
export const onFeeLevelChange = (feeLevel: any): any => {
return (dispatch, getState): void => {
const accountState = getState().abstractAccount;
const currentState = getState().sendForm;
const isToken: boolean = currentState.token !== accountState.network;
const state: State = {
...currentState,
untouched: false,
@ -461,15 +470,15 @@ export const onFeeLevelChange = (feeLevel: any): any => {
}
if (currentState.setMax) {
const account = getState().accounts.find(a => a.deviceState === currentState.deviceState && a.index === currentState.accountIndex && a.network === currentState.network);
if (state.token !== state.network) {
const account: ?Account = findAccount(getState().accounts, accountState.index, accountState.deviceState, accountState.network);
if (isToken) {
const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currentState.token).balance;
state.amount = tokenBalance;
} else {
state.amount = calculateMaxAmount(account.balance, state.gasPrice, state.gasLimit);
}
}
state.total = calculateTotal(state.token !== state.network ? '0' : state.amount, state.gasPrice, state.gasLimit);
state.total = calculateTotal(isToken ? '0' : state.amount, state.gasPrice, state.gasLimit);
dispatch({
type: SEND.FEE_LEVEL_CHANGE,
@ -481,7 +490,10 @@ export const onFeeLevelChange = (feeLevel: any): any => {
export const updateFeeLevels = (): any => {
return (dispatch, getState): void => {
const accountState = getState().abstractAccount;
const currentState = getState().sendForm;
const isToken: boolean = currentState.token !== accountState.network;
const feeLevels: Array<FeeLevel> = getFeeLevels(currentState.coinSymbol, currentState.recommendedGasPrice, currentState.gasLimit);
const selectedFeeLevel: ?FeeLevel = feeLevels.find(f => f.value === currentState.selectedFeeLevel.value)
const state: State = {
@ -494,15 +506,15 @@ export const updateFeeLevels = (): any => {
};
if (currentState.setMax) {
const account = getState().accounts.find(a => a.deviceState === currentState.deviceState && a.index === currentState.accountIndex && a.network === currentState.network);
if (state.token !== state.network) {
const account: ?Account = findAccount(getState().accounts, accountState.index, accountState.deviceState, accountState.network);
if (isToken) {
const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currentState.token).balance;
state.amount = tokenBalance;
} else {
state.amount = calculateMaxAmount(account.balance, state.gasPrice, state.gasLimit);
}
}
state.total = calculateTotal(state.token !== state.network ? '0' : state.amount, state.gasPrice, state.gasLimit);
state.total = calculateTotal(isToken ? '0' : state.amount, state.gasPrice, state.gasLimit);
dispatch({
type: SEND.UPDATE_FEE_LEVELS,
@ -514,8 +526,10 @@ export const updateFeeLevels = (): any => {
export const onGasPriceChange = (gasPrice: string): any => {
return (dispatch, getState): void => {
const accountState = getState().abstractAccount;
const currentState = getState().sendForm;
const isToken: boolean = currentState.token !== accountState.network;
const touched = { ...currentState.touched };
touched.gasPrice = true;
@ -534,8 +548,8 @@ export const onGasPriceChange = (gasPrice: string): any => {
state.selectedFeeLevel = customLevel;
if (currentState.setMax) {
const account = getState().accounts.find(a => a.deviceState === currentState.deviceState && a.index === currentState.accountIndex && a.network === currentState.network);
if (state.token !== state.network) {
const account: ?Account = findAccount(getState().accounts, accountState.index, accountState.deviceState, accountState.network);
if (isToken) {
const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currentState.token).balance;
state.amount = tokenBalance;
} else {
@ -544,7 +558,7 @@ export const onGasPriceChange = (gasPrice: string): any => {
}
}
state.total = calculateTotal(state.token !== state.network ? '0' : state.amount, state.gasPrice, state.gasLimit);
state.total = calculateTotal(isToken ? '0' : state.amount, state.gasPrice, state.gasLimit);
dispatch({
type: SEND.GAS_PRICE_CHANGE,
@ -556,7 +570,10 @@ export const onGasPriceChange = (gasPrice: string): any => {
export const onGasLimitChange = (gasLimit: string): any => {
return (dispatch, getState): void => {
const accountState = getState().abstractAccount;
const currentState = getState().sendForm;
const isToken: boolean = currentState.token !== accountState.network;
const touched = { ...currentState.touched };
touched.gasLimit = true;
@ -568,15 +585,15 @@ export const onGasLimitChange = (gasLimit: string): any => {
};
if (gasLimit.match(numberRegExp) && state.gasPrice.match(numberRegExp)) {
const customLevel = currentState.feeLevels.find(f => f.value === 'Custom');
customLevel.label = `${ calculateFee(state.gasPrice, gasLimit) } ${ state.coinSymbol }`;
const customLevel = state.feeLevels.find(f => f.value === 'Custom');
customLevel.label = `${ calculateFee(currentState.gasPrice, gasLimit) } ${ state.coinSymbol }`;
state.selectedFeeLevel = customLevel;
if (currentState.setMax) {
const account = getState().accounts.find(a => a.deviceState === currentState.deviceState && a.index === currentState.accountIndex && a.network === currentState.network);
if (state.token !== state.network) {
const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currentState.token).balance;
if (state.setMax) {
const account: ?Account = findAccount(getState().accounts, accountState.index, accountState.deviceState, accountState.network);
if (isToken) {
const tokenBalance: string = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === state.token).balance;
state.amount = tokenBalance;
} else {
state.amount = calculateMaxAmount(account.balance, state.gasPrice, state.gasLimit);
@ -584,7 +601,7 @@ export const onGasLimitChange = (gasLimit: string): any => {
}
}
state.total = calculateTotal(state.token !== state.network ? '0' : state.amount, state.gasPrice, state.gasLimit);
state.total = calculateTotal(isToken ? '0' : state.amount, state.gasPrice, state.gasLimit);
dispatch({
type: SEND.GAS_LIMIT_CHANGE,
@ -620,32 +637,30 @@ export const onSend = (): any => {
return async (dispatch, getState): Promise<any> => {
const state: State = getState().sendForm;
const web3instance = getState().web3.filter(w3 => w3.network === state.network)[0];
const accountState = getState().abstractAccount;
const currentState: State = getState().sendForm;
const web3instance = getState().web3.filter(w3 => w3.network === accountState.network)[0];
const web3 = web3instance.web3;
const account = getState().accounts.find(a => a.deviceState === state.deviceState && a.index === state.accountIndex && a.network === state.network);
const account: ?Account = findAccount(getState().accounts, accountState.index, accountState.deviceState, accountState.network);
const isToken: boolean = currentState.token !== accountState.network;
const address_n = account.addressPath;
let data: string = '';
let txAmount = web3.toHex(web3.toWei(state.amount, 'ether'));
let txAddress = state.address;
if (state.network !== state.token) {
const tokens = getState().tokens
const t = tokens.find(t => t.ethAddress === account.address && t.symbol === state.token);
let txAmount = web3.toHex(web3.toWei(currentState.amount, 'ether'));
let txAddress = currentState.address;
if (isToken) {
const t = getState().tokens.find(t => t.ethAddress === account.address && t.symbol === currentState.token);
const contract = web3instance.erc20.at(t.address);
data = contract.transfer.getData(state.address, state.amount, {
data = contract.transfer.getData(currentState.address, currentState.amount, {
from: account.address,
gasLimit: state.gasLimit,
gasPrice: state.gasPrice
gasLimit: currentState.gasLimit,
gasPrice: currentState.gasPrice
});
txAmount = '0x00';
txAddress = t.address;
}
const txData = {
address_n,
// from: currentAddress.address
@ -655,8 +670,8 @@ export const onSend = (): any => {
//chainId: 3 // ropsten
chainId: web3instance.chainId,
nonce: web3.toHex(account.nonce),
gasLimit: web3.toHex(state.gasLimit),
gasPrice: web3.toHex( EthereumjsUnits.convert(state.gasPrice, 'gwei', 'wei') ),
gasLimit: web3.toHex(currentState.gasLimit),
gasPrice: web3.toHex( EthereumjsUnits.convert(currentState.gasPrice, 'gwei', 'wei') ),
r: '',
s: '',
v: ''
@ -721,7 +736,7 @@ export const onSend = (): any => {
// console.log("---->GASSS", txData, gasLimit2.toString() );
const { config } = getState().localStorage;
const selectedCoin = config.coins.find(c => c.network === state.network);
const selectedCoin = config.coins.find(c => c.network === currentState.network);
try {
const tx = new EthereumjsTx(txData);
@ -731,8 +746,8 @@ export const onSend = (): any => {
dispatch({
type: SEND.TX_COMPLETE,
address: account,
token: state.token,
amount: state.amount,
token: currentState.token,
amount: currentState.amount,
txid,
txData,
});

@ -15,20 +15,9 @@ import { findSelectedDevice } from '../reducers/TrezorConnectReducer';
export const init = (): any => {
return (dispatch, getState): void => {
const { location } = getState().router;
const urlParams = location.params;
const selected = findSelectedDevice( getState().connect );
if (!selected || !selected.state) return;
const state: State = {
...initialState,
deviceState: selected.state,
deviceId: selected.features.device_id,
deviceInstance: selected.instance,
accountIndex: parseInt(urlParams.address),
network: urlParams.network,
location: location.pathname,
};
dispatch({
@ -42,12 +31,12 @@ export const init = (): any => {
export const update = (newProps: any): any => {
return (dispatch, getState): void => {
const {
summary,
abstractAccount,
router
} = getState();
const isLocationChanged: boolean = router.location.pathname !== summary.location;
if (isLocationChanged || !summary.deviceState) {
const isLocationChanged: boolean = router.location.pathname !== abstractAccount.location;
if (isLocationChanged) {
dispatch( init() );
return;
}

@ -11,26 +11,21 @@ import { QRCode } from 'react-qr-svg';
import AbstractAccount from './account/AbstractAccount';
import { Notification } from '../common/Notification';
import * as ReceiveActions from '../../actions/ReceiveActions';
import * as AbstractAccountActions from '../../actions/AbstractAccountActions';
class Receive extends AbstractAccount {
render() {
return super.render(this.props.receive) || _render(this.props, this.device, this.account, this.deviceStatusNotification);
return super.render() || _render(this.props, this.device, this.account, this.deviceStatusNotification);
}
}
const _render = (props: any, device, account, deviceStatusNotification): any => {
const {
network,
deviceState,
accountIndex,
addressVerified,
addressUnverified,
} = props.receive;
// const device = props.devices.find(d => d.state === deviceState);
// const account = props.accounts.find(a => a.deviceState === deviceState && a.index === accountIndex && a.network === network);
let qrCode = null;
let address = `${account.address.substring(0, 20)}...`;
let className = 'address hidden';
@ -91,6 +86,7 @@ const _render = (props: any, device, account, deviceStatusNotification): any =>
const mapStateToProps = (state, own) => {
return {
abstractAccount: state.abstractAccount,
location: state.router.location,
devices: state.connect.devices,
accounts: state.accounts,
@ -101,6 +97,7 @@ const mapStateToProps = (state, own) => {
const mapDispatchToProps = (dispatch) => {
return {
abstractAccountActions: bindActionCreators(AbstractAccountActions, dispatch),
initAccount: bindActionCreators(ReceiveActions.init, dispatch),
updateAccount: bindActionCreators(ReceiveActions.update, dispatch),
disposeAccount: bindActionCreators(ReceiveActions.dispose, dispatch),

@ -32,6 +32,7 @@ export default class AbstractAccount extends Component {
}
componentDidMount() {
this.props.abstractAccountActions.init();
this.props.initAccount();
}
@ -41,10 +42,12 @@ export default class AbstractAccount extends Component {
this.account = null;
this.deviceStatusNotification = null;
this.props.abstractAccountActions.update();
this.props.updateAccount();
}
componentWillUnmount() {
this.props.abstractAccountActions.dispose();
this.props.disposeAccount();
this.device = null;
@ -53,21 +56,22 @@ export default class AbstractAccount extends Component {
this.deviceStatusNotification = null;
}
render(state: any): any {
render(): any {
const props = this.props;
const state = props.abstractAccount;
if (!state.deviceState) {
return (<section><Notification className="info" title="Loading device" /></section>);
}
const device = findDevice(this.props.devices, state.deviceState, state.deviceId, state.deviceInstance);
const device = findDevice(props.devices, state.deviceState, state.deviceId, state.deviceInstance);
if (!device) {
return (<section>Device with state {state.deviceState} not found</section>);
}
const discovery = props.discovery.find(d => d.deviceState === device.state && d.network === state.network);
const account = props.accounts.find(a => a.deviceState === state.deviceState && a.index === state.accountIndex && a.network === state.network);
const account = props.accounts.find(a => a.deviceState === state.deviceState && a.index === state.index && a.network === state.network);
let deviceStatusNotification = null;
if (!account) {

@ -6,8 +6,8 @@ import Tooltip from 'rc-tooltip';
const AdvancedForm = (props: any): any => {
const { network } = props.abstractAccount;
const {
network,
token,
gasPrice,
gasLimit,

@ -11,23 +11,20 @@ import AbstractAccount from '../account/AbstractAccount';
export default class Send extends AbstractAccount {
render() {
return super.render(this.props.sendForm) || _render(this.props, this.device, this.discovery, this.account, this.deviceStatusNotification);
return super.render() || _render(this.props, this.device, this.discovery, this.account, this.deviceStatusNotification);
}
}
const _render = (props: any, device, discovery, account, deviceStatusNotification): any => {
// const device = props.devices.find(device => device.state === props.sendForm.deviceState);
// const discovery = props.discovery.find(d => d.deviceState === device.state && d.network === props.sendForm.network);
// const account = props.accounts.find(a => a.deviceState === props.sendForm.deviceState && a.index === props.sendForm.accountIndex && a.network === props.sendForm.network);
const addressTokens = props.tokens.filter(t => t.ethAddress === account.address);
const { network } = props.abstractAccount;
const {
address,
amount,
setMax,
network,
coinSymbol,
token,
feeLevels,
@ -54,7 +51,7 @@ const _render = (props: any, device, discovery, account, deviceStatusNotificatio
const { config } = props.localStorage;
const selectedCoin = config.coins.find(c => c.network === network);
const fiatRate = props.fiat.find(f => f.network === selectedCoin.network);
const fiatRate = props.fiat.find(f => f.network === network);
const tokens = addressTokens.map(t => {
return { value: t.symbol, label: t.symbol };

@ -6,10 +6,12 @@ import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import * as SendFormActions from '../../../actions/SendFormActions';
import * as AbstractAccountActions from '../../../actions/AbstractAccountActions';
import SendForm from './SendForm';
const mapStateToProps = (state, own) => {
return {
abstractAccount: state.abstractAccount,
location: state.router.location,
devices: state.connect.devices,
accounts: state.accounts,
@ -24,6 +26,7 @@ const mapStateToProps = (state, own) => {
const mapDispatchToProps = (dispatch) => {
return {
abstractAccountActions: bindActionCreators(AbstractAccountActions, dispatch),
sendFormActions: bindActionCreators(SendFormActions, dispatch),
initAccount: bindActionCreators(SendFormActions.init, dispatch),
updateAccount: bindActionCreators(SendFormActions.update, dispatch),

@ -14,17 +14,13 @@ import { findDevice } from '../../../utils/reducerUtils';
export default class Summary extends AbstractAccount {
render() {
console.warn("RENDER SUMMARY!", this.device, this.discovery, this)
return super.render(this.props.summary) || _render(this.props, this.device, this.discovery, this.account, this.deviceStatusNotification);
return super.render() || _render(this.props, this.device, this.discovery, this.account, this.deviceStatusNotification);
}
}
const _render = (props: any, device, discovery, account, deviceStatusNotification): any => {
//const device = props.devices.find(d => d.state === props.summary.deviceState && d.features.device_id === props.summary.deviceId);
// const device = findDevice(props.devices, props.summary.deviceState, props.summary.deviceId);
// const discovery = props.discovery.find(d => d.deviceState === device.state && d.network === props.summary.network);
//const account = props.accounts.find(a => a.deviceState === props.summary.deviceState && a.index === props.summary.accountIndex && a.network === props.summary.network);
const abstractAccount = props.abstractAccount;
const tokens = props.tokens.filter(t => t.ethAddress === account.address);
return (
@ -32,12 +28,12 @@ const _render = (props: any, device, discovery, account, deviceStatusNotificatio
<section className="summary">
{ deviceStatusNotification }
<h2 className={ `summary-header ${props.summary.network}` }>Address #{ parseInt(props.match.params.address) + 1 }</h2>
<h2 className={ `summary-header ${abstractAccount.network}` }>Address #{ parseInt(abstractAccount.index) + 1 }</h2>
<SummaryDetails
summary={ props.summary }
balance={ account.balance }
network={ props.summary.network }
network={ abstractAccount.network }
fiat={ props.fiat }
localStorage={ props.localStorage }
onToggle={ props.summaryActions.onDetailsToggle } />

@ -6,15 +6,19 @@ import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import Summary from './Summary';
import * as AbstractAccountActions from '../../../actions/AbstractAccountActions';
import * as SummaryActions from '../../../actions/SummaryActions';
const mapStateToProps = (state, own) => {
return {
abstractAccount: state.abstractAccount,
location: state.router.location,
devices: state.connect.devices,
accounts: state.accounts,
discovery: state.discovery,
tokens: state.tokens,
summary: state.summary,
fiat: state.fiat,
localStorage: state.localStorage
@ -23,6 +27,7 @@ const mapStateToProps = (state, own) => {
const mapDispatchToProps = (dispatch) => {
return {
abstractAccountActions: bindActionCreators(AbstractAccountActions, dispatch),
summaryActions: bindActionCreators(SummaryActions, dispatch),
initAccount: bindActionCreators(SummaryActions.init, dispatch),
updateAccount: bindActionCreators(SummaryActions.update, dispatch),

@ -6,7 +6,9 @@ import * as CONNECT from '../actions/constants/TrezorConnect';
export type State = {
+index: number;
+ch: ?string;
+deviceState: ?string;
+deviceId: ?string;
+deviceInstance: ?string;
+network: string;
location: string;
}
@ -14,7 +16,10 @@ export type State = {
export const initialState: State = {
index: 0,
deviceState: null,
deviceId: null,
deviceInstance: null,
network: '',
location: '',
};
@ -25,12 +30,6 @@ export default (state: State = initialState, action: any): State => {
case ACCOUNT.INIT :
return action.state;
case CONNECT.DEVICE_STATE_EXCEPTION :
return {
...state,
deviceStateError: true
}
case ACCOUNT.DISPOSE :
return initialState;

@ -18,6 +18,10 @@ export type Account = {
const initialState: Array<Account> = [];
export const findAccount = (state: Array<Account>, index: number, deviceState: string, network: string): ?Account => {
return state.find(a => a.deviceState === deviceState && a.index === index && a.network === network);
}
const createAccount = (state: Array<Account>, action: any): Array<Account> => {
// TODO check with device_id

@ -4,23 +4,11 @@
import * as RECEIVE from '../actions/constants/receive';
export type State = {
+deviceState: ?string;
+deviceId: ?string;
+deviceInstance: ?string;
+accountIndex: ?number;
+network: ?string;
location: string;
addressVerified: boolean;
adressUnverified: boolean;
}
export const initialState: State = {
deviceState: null,
deviceId: null,
deviceInstance: null,
accountIndex: null,
network: null,
location: '',
addressVerified: false,
addressUnverified: false,
};

@ -10,18 +10,10 @@ import BigNumber from 'bignumber.js';
import { getFeeLevels } from '../actions/SendFormActions';
export type State = {
+deviceState: ?string;
+deviceId: ?string;
+deviceInstance: ?string;
+accountIndex: number;
+network: string;
+coinSymbol: string;
token: string;
location: string;
balanceNeedUpdate: boolean;
// form fields
advanced: boolean;
untouched: boolean; // set to true when user made any changes in form
@ -52,14 +44,8 @@ export type FeeLevel = {
export const initialState: State = {
deviceState: null,
deviceId: null,
deviceInstance: null,
accountIndex: 0,
network: '',
coinSymbol: '',
token: '',
location: '',
advanced: false,
untouched: true,

@ -4,25 +4,11 @@
import * as SUMMARY from '../actions/constants/summary';
export type State = {
+deviceState: ?string;
+deviceId: ?string;
+deviceInstance: ?string;
+accountIndex: ?number;
+network: ?string;
location: string;
details: boolean;
selectedToken: any;
}
export const initialState: State = {
deviceState: null,
deviceId: null,
deviceInstance: null,
accountIndex: null,
network: null,
location: '',
details: true,
selectedToken: null
};

Loading…
Cancel
Save