@ -1,20 +1,17 @@
/* @flow */
'use strict' ;
import * as SEND from './constants/send' ;
import * as NOTIFICATION from './constants/notification' ;
import * as SessionStorageActions from './SessionStorageActions' ;
import { estimateGas , getGasPrice , pushTx } from './Web3Actions' ;
import EthereumjsUtil from 'ethereumjs-util' ;
import EthereumjsUnits from 'ethereumjs-units' ;
import EthereumjsTx from 'ethereumjs-tx' ;
import TrezorConnect from 'trezor-connect' ;
import { strip } from '../utils/ethUtils' ;
import { push } from 'react-router-redux' ;
import BigNumber from 'bignumber.js' ;
import { strip } from '../utils/ethUtils' ;
import { estimateGas , getGasPrice , pushTx } from './Web3Actions' ;
import * as SessionStorageActions from './SessionStorageActions' ;
import * as NOTIFICATION from './constants/notification' ;
import * as SEND from './constants/send' ;
import { initialState } from '../reducers/SendFormReducer' ;
import { findAccount } from '../reducers/AccountsReducer' ;
@ -30,7 +27,7 @@ import type {
ThunkAction ,
AsyncAction ,
RouterLocationState ,
TrezorDevice
TrezorDevice ,
} from '~/flowtype' ;
import type { State as AccountState } from '../reducers/SelectedAccountReducer' ;
import type { Web3Instance } from '../reducers/Web3Reducer' ;
@ -124,19 +121,19 @@ const numberRegExp: RegExp = new RegExp('^(0|0\\.([0-9]+)?|[1-9][0-9]*\\.?([0-9]
export const calculateFee = ( gasPrice : string , gasLimit : string ) : string => {
try {
return EthereumjsUnits . convert ( new BigNumber ( gasPrice ) . times ( gasLimit ) , 'gwei' , 'ether' ) ;
return EthereumjsUnits . convert ( new BigNumber ( gasPrice ) . times ( gasLimit ) , 'gwei' , 'ether' ) ;
} catch ( error ) {
return '0' ;
}
}
} ;
export const calculateTotal = ( amount : string , gasPrice : string , gasLimit : string ) : string => {
try {
return new BigNumber ( amount ) . plus ( calculateFee ( gasPrice , gasLimit ) ) . toString ( 10 ) ;
return new BigNumber ( amount ) . plus ( calculateFee ( gasPrice , gasLimit ) ) . toString ( 10 ) ;
} catch ( error ) {
return '0' ;
}
}
} ;
export const calculateMaxAmount = ( balance : BigNumber , gasPrice : string , gasLimit : string ) : string => {
try {
@ -148,8 +145,7 @@ export const calculateMaxAmount = (balance: BigNumber, gasPrice: string, gasLimi
} catch ( error ) {
return '0' ;
}
}
} ;
export const calculate = ( prevProps : Props , props : Props ) => {
const {
@ -173,7 +169,6 @@ export const calculate = (prevProps: Props, props: Props) => {
if ( state . setMax ) {
const pendingAmount : BigNumber = stateUtils . getPendingAmount ( pending , state . currency , isToken ) ;
if ( isToken ) {
@ -192,14 +187,14 @@ export const calculate = (prevProps: Props, props: Props) => {
state . total = calculateTotal ( isToken ? '0' : state . amount , state . gasPrice , state . gasLimit ) ;
if ( state . selectedFeeLevel . value === 'Custom' ) {
state . selectedFeeLevel . label = ` ${ calculateFee ( state . gasPrice , state . gasLimit ) } ${ state . networkSymbol } ` ;
state . selectedFeeLevel . label = ` ${ calculateFee ( state . gasPrice , state . gasLimit ) } ${ state . networkSymbol } ` ;
state . selectedFeeLevel . gasPrice = state . gasPrice ;
}
}
} ;
export const getFeeLevels = ( symbol : string , gasPrice : BigNumber | string , gasLimit : string , selected ? : FeeLevel ) : Array < FeeLevel > => {
const price : BigNumber = typeof gasPrice === 'string' ? new BigNumber ( gasPrice ) : gasPrice
const price : BigNumber = typeof gasPrice === 'string' ? new BigNumber ( gasPrice ) : gasPrice ;
const quarter : BigNumber = price . dividedBy ( 4 ) ;
const high : string = price . plus ( quarter . times ( 2 ) ) . toString ( 10 ) ;
const low : string = price . minus ( quarter . times ( 2 ) ) . toString ( 10 ) ;
@ -208,58 +203,56 @@ export const getFeeLevels = (symbol: string, gasPrice: BigNumber | string, gasLi
value : 'Custom' ,
gasPrice : selected . gasPrice ,
// label: `${ calculateFee(gasPrice, gasLimit) } ${ symbol }`
label : ` ${ calculateFee ( selected . gasPrice , gasLimit ) } ${ symbol } `
label : ` ${ calculateFee ( selected . gasPrice , gasLimit ) } ${ symbol } ` ,
} : {
value : 'Custom' ,
gasPrice : low ,
label : ''
}
label : '' ,
} ;
return [
{
value : 'High' ,
gasPrice : high ,
label : ` ${ calculateFee ( high , gasLimit ) } ${ symbol } `
label : ` ${ calculateFee ( high , gasLimit ) } ${ symbol } ` ,
} ,
{
value : 'Normal' ,
gasPrice : gasPrice . toString ( ) ,
label : ` ${ calculateFee ( price . toString ( 10 ) , gasLimit ) } ${ symbol } `
label : ` ${ calculateFee ( price . toString ( 10 ) , gasLimit ) } ${ symbol } ` ,
} ,
{
value : 'Low' ,
gasPrice : low ,
label : ` ${ calculateFee ( low , gasLimit ) } ${ symbol } `
label : ` ${ calculateFee ( low , gasLimit ) } ${ symbol } ` ,
} ,
customLevel
]
}
customLevel ,
] ;
} ;
// initialize component
export const init = ( ) : ThunkAction => {
return ( dispatch : Dispatch , getState : GetState ) : void => {
export const init = ( ) : ThunkAction => ( dispatch : Dispatch , getState : GetState ) : void => {
const {
account ,
network ,
web3
web3 ,
} = getState ( ) . selectedAccount ;
if ( ! account || ! network || ! web3 ) return ;
const stateFromStorage = SessionStorageActions . load ( getState ( ) . router . location . pathname ) ;
const stateFromStorage = SessionStorageActions . load ( getState ( ) . router . location . pathname ) ;
if ( stateFromStorage ) {
dispatch ( {
type : SEND . INIT ,
state : stateFromStorage
state : stateFromStorage ,
} ) ;
return ;
}
// TODO: check if there are some unfinished tx in localStorage
const gasPrice : BigNumber = new BigNumber ( EthereumjsUnits . convert ( web3 . gasPrice , 'wei' , 'gwei' ) ) || new BigNumber ( network . defaultGasPrice ) ;
const gasPrice : BigNumber = new BigNumber ( EthereumjsUnits . convert ( web3 . gasPrice , 'wei' , 'gwei' ) ) || new BigNumber ( network . defaultGasPrice ) ;
const gasLimit : string = network . defaultGasLimit . toString ( ) ;
const feeLevels : Array < FeeLevel > = getFeeLevels ( network . symbol , gasPrice , gasLimit ) ;
@ -280,20 +273,16 @@ export const init = (): ThunkAction => {
dispatch ( {
type : SEND . INIT ,
state
state ,
} ) ;
}
}
} ;
export const toggleAdvanced = ( address : string ) : Action => {
return {
type : SEND . TOGGLE _ADVANCED
}
}
export const toggleAdvanced = ( address : string ) : Action => ( {
type : SEND . TOGGLE _ADVANCED ,
} ) ;
const addressValidation = ( ) : ThunkAction => {
return ( dispatch : Dispatch , getState : GetState ) : void => {
const addressValidation = ( ) : ThunkAction => ( dispatch : Dispatch , getState : GetState ) : void => {
const {
account ,
network ,
@ -316,15 +305,15 @@ const addressValidation = (): ThunkAction => {
if ( currentNetworkAccount ) {
const device : ? TrezorDevice = findDevice ( getState ( ) . devices , currentNetworkAccount . deviceID , currentNetworkAccount . deviceState ) ;
if ( device ) {
infos . address = ` ${ device . instanceLabel } Account # ${ ( currentNetworkAccount . index + 1 ) } ` ;
infos . address = ` ${ device . instanceLabel } Account # ${ ( currentNetworkAccount . index + 1 ) } ` ;
}
} else {
const otherNetworkAccount = savedAccounts [ 0 ] ;
const device : ? TrezorDevice = findDevice ( getState ( ) . devices , otherNetworkAccount . deviceID , otherNetworkAccount . deviceState ) ;
const coins = getState ( ) . localStorage . config . coins ;
const otherNetwork : ? Coin = coins . find ( c => c . network === otherNetworkAccount . network )
const otherNetwork : ? Coin = coins . find ( c => c . network === otherNetworkAccount . network ) ;
if ( device && otherNetwork ) {
warnings . address = ` Looks like it's ${ device . instanceLabel } Account # ${ ( otherNetworkAccount . index + 1 ) } address of ${ otherNetwork . name } network ` ;
warnings . address = ` Looks like it's ${ device . instanceLabel } Account # ${ ( otherNetworkAccount . index + 1 ) } address of ${ otherNetwork . name } network ` ;
}
}
} else {
@ -337,15 +326,13 @@ const addressValidation = (): ThunkAction => {
state : {
... state ,
infos ,
warnings
}
} )
}
}
warnings ,
} ,
} ) ;
} ;
export const validation = ( props : Props ) : void => {
const {
account ,
network ,
@ -388,7 +375,6 @@ export const validation = (props: Props): void => {
} else if ( state . amount . length > 0 && ! state . amount . match ( numberRegExp ) ) {
errors . amount = 'Amount is not a number' ;
} else {
let decimalRegExp : RegExp ;
const pendingAmount : BigNumber = stateUtils . getPendingAmount ( pending , state . currency , state . currency !== state . networkSymbol ) ;
@ -397,28 +383,27 @@ export const validation = (props: Props): void => {
if ( token ) {
if ( parseInt ( token . decimals ) > 0 ) {
//decimalRegExp = new RegExp('^(0|0\\.([0-9]{0,' + token.decimals + '})?|[1-9]+\\.?([0-9]{0,' + token.decimals + '})?|\\.[0-9]{1,' + token.decimals + '})$');
decimalRegExp = new RegExp ( '^(0|0\\.([0-9]{0,' + token . decimals + '})?|[1-9][0-9]*\\.?([0-9]{0,' + token . decimals + '})?|\\.[0-9]{1,' + token . decimals + '})$' ) ;
decimalRegExp = new RegExp ( ` ^(0|0 \\ .([0-9]{0, ${ token . decimals } })?|[1-9][0-9]* \\ .?([0-9]{0, ${ token . decimals } })?| \\ .[0-9]{1, ${ token . decimals } }) $ ` ) ;
} else {
// decimalRegExp = new RegExp('^(0|0\\.?|[1-9]+\\.?)$');
decimalRegExp = new RegExp ( '^[0-9]+$' ) ;
}
if ( ! state . amount . match ( decimalRegExp ) ) {
errors . amount = ` Maximum ${ token . decimals } decimals allowed ` ;
errors . amount = ` Maximum ${ token . decimals } decimals allowed ` ;
} else if ( new BigNumber ( state . total ) . greaterThan ( account . balance ) ) {
errors . amount = ` Not enough ${ state . networkSymbol } to cover transaction fee ` ;
} else if ( new BigNumber ( state . amount ) . greaterThan ( new BigNumber ( token . balance ) . minus ( pendingAmount ) ) ) {
errors . amount = ` Not enough ${ state . networkSymbol } to cover transaction fee ` ;
} else if ( new BigNumber ( state . amount ) . greaterThan ( new BigNumber ( token . balance ) . minus ( pendingAmount ) ) ) {
errors . amount = 'Not enough funds' ;
} else if ( new BigNumber ( state . amount ) . lessThanOrEqualTo ( '0' ) ) {
errors . amount = 'Amount is too low' ;
}
}
} else {
decimalRegExp = new RegExp ( '^(0|0\\.([0-9]{0,18})?|[1-9][0-9]*\\.?([0-9]{0,18})?|\\.[0-9]{0,18})$' ) ;
if ( ! state . amount . match ( decimalRegExp ) ) {
errors . amount = ` Maximum 18 decimals allowed ` ;
} else if ( new BigNumber ( state . total ) . greaterThan ( new BigNumber ( account . balance ) . minus ( pendingAmount ) ) ) {
errors . amount = 'Maximum 18 decimals allowed' ;
} else if ( new BigNumber ( state . total ) . greaterThan ( new BigNumber ( account . balance ) . minus ( pendingAmount ) ) ) {
errors . amount = 'Not enough funds' ;
}
}
@ -435,7 +420,7 @@ export const validation = (props: Props): void => {
const gl : BigNumber = new BigNumber ( state . gasLimit ) ;
if ( gl . lessThan ( 1 ) ) {
errors . gasLimit = 'Gas limit is too low' ;
} else if ( gl . lessThan ( state . currency !== state . networkSymbol ? network . defaultGasLimitTokens : network . defaultGasLimit ) ) {
} else if ( gl . lessThan ( state . currency !== state . networkSymbol ? network . defaultGasLimitTokens : network . defaultGasLimit ) ) {
warnings . gasLimit = 'Gas limit is below recommended' ;
}
}
@ -487,14 +472,10 @@ export const validation = (props: Props): void => {
state . errors = errors ;
state . warnings = warnings ;
state . infos = infos ;
}
} ;
export const onAddressChange = ( address : string ) : ThunkAction => {
return ( dispatch : Dispatch , getState : GetState ) : void => {
export const onAddressChange = ( address : string ) : ThunkAction => ( dispatch : Dispatch , getState : GetState ) : void => {
const state : State = getState ( ) . sendForm ;
const touched = { ... state . touched } ;
touched . address = true ;
@ -505,16 +486,14 @@ export const onAddressChange = (address: string): ThunkAction => {
... state ,
untouched : false ,
touched ,
address
}
address ,
} ,
} ) ;
dispatch ( addressValidation ( ) ) ;
}
}
dispatch ( addressValidation ( ) ) ;
} ;
export const onAmountChange = ( amount : string ) : ThunkAction => {
return ( dispatch : Dispatch , getState : GetState ) : void => {
export const onAmountChange = ( amount : string ) : ThunkAction => ( dispatch : Dispatch , getState : GetState ) : void => {
const state = getState ( ) . sendForm ;
const touched = { ... state . touched } ;
touched . amount = true ;
@ -527,16 +506,14 @@ export const onAmountChange = (amount: string): ThunkAction => {
touched ,
setMax : false ,
amount ,
}
} ,
} ) ;
}
}
} ;
export const onCurrencyChange = ( currency : { value : string , label : string } ) : ThunkAction => {
return ( dispatch : Dispatch , getState : GetState ) : void => {
export const onCurrencyChange = ( currency : { value : string , label : string } ) : ThunkAction => ( dispatch : Dispatch , getState : GetState ) : void => {
const {
account ,
network
network ,
} = getState ( ) . selectedAccount ;
if ( ! account || ! network ) return ;
@ -560,13 +537,11 @@ export const onCurrencyChange = (currency: { value: string, label: string }): Th
dispatch ( {
type : SEND . CURRENCY _CHANGE ,
state
state ,
} ) ;
}
}
} ;
export const onSetMax = ( ) : ThunkAction => {
return ( dispatch : Dispatch , getState : GetState ) : void => {
export const onSetMax = ( ) : ThunkAction => ( dispatch : Dispatch , getState : GetState ) : void => {
const state = getState ( ) . sendForm ;
const touched = { ... state . touched } ;
touched . amount = true ;
@ -578,15 +553,13 @@ export const onSetMax = (): ThunkAction => {
untouched : false ,
touched ,
setMax : ! state . setMax ,
}
} ,
} ) ;
}
}
} ;
export const onFeeLevelChange = ( feeLevel : FeeLevel ) : ThunkAction => {
return ( dispatch : Dispatch , getState : GetState ) : void => {
export const onFeeLevelChange = ( feeLevel : FeeLevel ) : ThunkAction => ( dispatch : Dispatch , getState : GetState ) : void => {
const {
network
network ,
} = getState ( ) . selectedAccount ;
if ( ! network ) return ;
@ -602,14 +575,13 @@ export const onFeeLevelChange = (feeLevel: FeeLevel): ThunkAction => {
if ( feeLevel . value === 'Custom' ) {
state . advanced = true ;
feeLevel . gasPrice = state . gasPrice ;
feeLevel . label = ` ${ calculateFee ( state . gasPrice , state . gasLimit ) } ${ state . networkSymbol } ` ;
feeLevel . label = ` ${ calculateFee ( state . gasPrice , state . gasLimit ) } ${ state . networkSymbol } ` ;
} else {
const customLevel : ? FeeLevel = state . feeLevels . find ( f => f . value === 'Custom' ) ;
if ( customLevel )
customLevel . label = '' ;
if ( customLevel ) customLevel . label = '' ;
state . gasPrice = feeLevel . gasPrice ;
if ( isToken ) {
state . gasLimit = network . defaultGasLimitTokens . toString ( )
state . gasLimit = network . defaultGasLimitTokens . toString ( ) ;
} else {
state . gasLimit = state . data . length > 0 ? state . gasLimit : network . defaultGasLimit . toString ( ) ;
}
@ -617,19 +589,17 @@ export const onFeeLevelChange = (feeLevel: FeeLevel): ThunkAction => {
dispatch ( {
type : SEND . FEE _LEVEL _CHANGE ,
state
state ,
} ) ;
}
}
} ;
// Manually triggered from user
// Update gasPrice to recommended value
export const updateFeeLevels = ( ) : ThunkAction => {
return ( dispatch : Dispatch , getState : GetState ) : void => {
export const updateFeeLevels = ( ) : ThunkAction => ( dispatch : Dispatch , getState : GetState ) : void => {
const {
account ,
network
network ,
} = getState ( ) . selectedAccount ;
if ( ! account || ! network ) return ;
@ -659,14 +629,11 @@ export const updateFeeLevels = (): ThunkAction => {
dispatch ( {
type : SEND . UPDATE _FEE _LEVELS ,
state
state ,
} ) ;
}
}
export const onGasPriceChange = ( gasPrice : string ) : ThunkAction => {
return ( dispatch : Dispatch , getState : GetState ) : void => {
} ;
export const onGasPriceChange = ( gasPrice : string ) : ThunkAction => ( dispatch : Dispatch , getState : GetState ) : void => {
const currentState : State = getState ( ) . sendForm ;
const isToken : boolean = currentState . currency !== currentState . networkSymbol ;
@ -677,7 +644,7 @@ export const onGasPriceChange = (gasPrice: string): ThunkAction => {
... currentState ,
untouched : false ,
touched ,
gasPrice : gasPrice ,
gasPrice ,
} ;
if ( currentState . selectedFeeLevel . value !== 'Custom' ) {
@ -688,14 +655,11 @@ export const onGasPriceChange = (gasPrice: string): ThunkAction => {
dispatch ( {
type : SEND . GAS _PRICE _CHANGE ,
state
state ,
} ) ;
}
}
export const onGasLimitChange = ( gasLimit : string , updateFeeLevels : boolean = false ) : ThunkAction => {
return ( dispatch : Dispatch , getState : GetState ) : void => {
} ;
export const onGasLimitChange = ( gasLimit : string , updateFeeLevels : boolean = false ) : ThunkAction => ( dispatch : Dispatch , getState : GetState ) : void => {
const currentState : State = getState ( ) . sendForm ;
const isToken : boolean = currentState . currency !== currentState . networkSymbol ;
@ -718,13 +682,11 @@ export const onGasLimitChange = (gasLimit: string, updateFeeLevels: boolean = fa
dispatch ( {
type : SEND . GAS _LIMIT _CHANGE ,
state
state ,
} ) ;
}
}
} ;
export const onNonceChange = ( nonce : string ) : AsyncAction => {
return async ( dispatch : Dispatch , getState : GetState ) : Promise < void > => {
export const onNonceChange = ( nonce : string ) : AsyncAction => async ( dispatch : Dispatch , getState : GetState ) : Promise < void > => {
const currentState : State = getState ( ) . sendForm ;
const touched = { ... currentState . touched } ;
touched . nonce = true ;
@ -738,13 +700,11 @@ export const onNonceChange = (nonce: string): AsyncAction => {
dispatch ( {
type : SEND . NONCE _CHANGE ,
state
state ,
} ) ;
}
}
} ;
export const onDataChange = ( data : string ) : AsyncAction => {
return async ( dispatch : Dispatch , getState : GetState ) : Promise < void > => {
export const onDataChange = ( data : string ) : AsyncAction => async ( dispatch : Dispatch , getState : GetState ) : Promise < void > => {
const currentState : State = getState ( ) . sendForm ;
const touched = { ... currentState . touched } ;
touched . data = true ;
@ -765,20 +725,17 @@ export const onDataChange = (data: string): AsyncAction => {
dispatch ( {
type : SEND . DATA _CHANGE ,
state
state ,
} ) ;
dispatch ( estimateGasPrice ( ) ) ;
}
}
dispatch ( estimateGasPrice ( ) ) ;
} ;
const estimateGasPrice = ( ) : AsyncAction => {
return async ( dispatch : Dispatch , getState : GetState ) : Promise < void > => {
const estimateGasPrice = ( ) : AsyncAction => async ( dispatch : Dispatch , getState : GetState ) : Promise < void > => {
const {
web3 ,
network
network ,
} = getState ( ) . selectedAccount ;
if ( ! web3 || ! network ) return ;
@ -790,40 +747,36 @@ const estimateGasPrice = (): AsyncAction => {
const re = /^[0-9A-Fa-f]+$/g ;
if ( ! re . test ( requestedData ) ) {
// to stop calculating
dispatch ( onGasLimitChange ( requestedData . length > 0 ? state . gasLimit : network . defaultGasLimit . toString ( ) ) ) ;
dispatch ( onGasLimitChange ( requestedData . length > 0 ? state . gasLimit : network . defaultGasLimit . toString ( ) ) ) ;
return ;
}
if ( state . data . length < 1 ) {
// set default
dispatch ( onGasLimitChange ( network . defaultGasLimit . toString ( ) ) ) ;
dispatch ( onGasLimitChange ( network . defaultGasLimit . toString ( ) ) ) ;
return ;
}
// TODO: allow data starting with 0x ...
const data : string = '0x' + ( state . data . length % 2 === 0 ? state . data : '0' + state . data ) ;
const data : string = ` 0x ${ state . data . length % 2 === 0 ? state . data : ` 0 ${ state . data } ` } ` ;
const gasLimit = await estimateGas ( w3 , {
to : '0x0000000000000000000000000000000000000000' ,
data ,
value : w3 . toHex ( w3 . toWei ( state . amount , 'ether' ) ) ,
gasPrice : w3 . toHex ( EthereumjsUnits . convert ( state . gasPrice , 'gwei' , 'wei' ) ) ,
gasPrice : w3 . toHex ( EthereumjsUnits . convert ( state . gasPrice , 'gwei' , 'wei' ) ) ,
} ) ;
if ( getState ( ) . sendForm . data === requestedData ) {
dispatch ( onGasLimitChange ( gasLimit . toString ( ) ) ) ;
}
dispatch ( onGasLimitChange ( gasLimit . toString ( ) ) ) ;
}
} ;
}
export const onSend = ( ) : AsyncAction => {
return async ( dispatch : Dispatch , getState : GetState ) : Promise < void > => {
export const onSend = ( ) : AsyncAction => async ( dispatch : Dispatch , getState : GetState ) : Promise < void > => {
const {
account ,
network ,
web3 ,
pending
pending ,
} = getState ( ) . selectedAccount ;
if ( ! account || ! web3 || ! network ) return ;
@ -834,7 +787,7 @@ export const onSend = (): AsyncAction => {
const address _n = account . addressPath ;
let data : string = '0x' + currentState . data ;
let data : string = ` 0x ${ currentState . data } ` ;
let txAmount : string = w3 . toHex ( w3 . toWei ( currentState . amount , 'ether' ) ) ;
let txAddress : string = currentState . address ;
if ( isToken ) {
@ -842,12 +795,12 @@ export const onSend = (): AsyncAction => {
if ( ! token ) return ;
const contract = web3 . erc20 . at ( token . address ) ;
const amountValue : string = new BigNumber ( currentState . amount ) . times ( Math . pow ( 10 , token . decimals ) ) . toString ( 10 ) ;
const amountValue : string = new BigNumber ( currentState . amount ) . times ( Math . pow ( 10 , token . decimals ) ) . toString ( 10 ) ;
data = contract . transfer . getData ( currentState . address , amountValue , {
from : account . address ,
gasLimit : currentState . gasLimit ,
gasPrice : currentState . gasPrice
gasPrice : currentState . gasPrice ,
} ) ;
txAmount = '0x00' ;
txAddress = token . address ;
@ -856,7 +809,7 @@ export const onSend = (): AsyncAction => {
const pendingNonce : number = stateUtils . getPendingNonce ( pending ) ;
const nonce = pendingNonce > 0 && pendingNonce >= account . nonce ? pendingNonce : account . nonce ;
console . warn ( "NONCE" , nonce , account . nonce , pendingNonce )
console . warn ( 'NONCE' , nonce , account . nonce , pendingNonce ) ;
const txData = {
address _n ,
@ -867,20 +820,20 @@ export const onSend = (): AsyncAction => {
chainId : web3 . chainId ,
nonce : w3 . toHex ( nonce ) ,
gasLimit : w3 . toHex ( currentState . gasLimit ) ,
gasPrice : w3 . toHex ( EthereumjsUnits . convert ( currentState . gasPrice , 'gwei' , 'wei' ) ) ,
gasPrice : w3 . toHex ( EthereumjsUnits . convert ( currentState . gasPrice , 'gwei' , 'wei' ) ) ,
r : '' ,
s : '' ,
v : ''
}
v : '' ,
} ;
const selected : ? TrezorDevice = getState ( ) . wallet . selectedDevice ;
if ( ! selected ) return ;
le t signedTransaction = await TrezorConnect . ethereumSignTransaction ( {
cons t signedTransaction = await TrezorConnect . ethereumSignTransaction ( {
device : {
path : selected . path ,
instance : selected . instance ,
state : selected . state
state : selected . state ,
} ,
useEmptyPassphrase : ! selected . instance ,
path : txData . address _n ,
@ -890,11 +843,10 @@ export const onSend = (): AsyncAction => {
to : strip ( txData . to ) ,
value : strip ( txData . value ) ,
data : strip ( txData . data ) ,
chainId : txData . chainId
chainId : txData . chainId ,
} ) ;
if ( ! signedTransaction || ! signedTransaction . success ) {
dispatch ( {
type : NOTIFICATION . ADD ,
payload : {
@ -902,26 +854,25 @@ export const onSend = (): AsyncAction => {
title : 'Transaction error' ,
message : signedTransaction . payload . error ,
cancelable : true ,
actions : [ ]
}
} )
actions : [ ] ,
} ,
} ) ;
return ;
}
txData . r = '0x' + signedTransaction . payload . r ;
txData . s = '0x' + signedTransaction . payload . s ;
txData . r = ` 0x ${ signedTransaction . payload . r } ` ;
txData . s = ` 0x ${ signedTransaction . payload . s } ` ;
txData . v = w3 . toHex ( signedTransaction . payload . v ) ;
try {
const tx = new EthereumjsTx ( txData ) ;
const serializedTx = '0x' + tx . serialize ( ) . toString ( 'hex' ) ;
const serializedTx = ` 0x ${ tx . serialize ( ) . toString ( 'hex' ) } ` ;
const txid : string = await pushTx ( w3 , serializedTx ) ;
dispatch ( {
type : SEND . TX _COMPLETE ,
account : account ,
account ,
selectedCurrency : currentState . currency ,
amount : currentState . amount ,
total : currentState . total ,
@ -932,10 +883,10 @@ export const onSend = (): AsyncAction => {
} ) ;
// clear session storage
dispatch ( SessionStorageActions . clear ( ) ) ;
dispatch ( SessionStorageActions . clear ( ) ) ;
// reset form
dispatch ( init ( ) ) ;
dispatch ( init ( ) ) ;
dispatch ( {
@ -945,12 +896,10 @@ export const onSend = (): AsyncAction => {
title : 'Transaction success' ,
message : ` <a href=" ${ network . explorer . tx } ${ txid } " class="green" target="_blank" rel="noreferrer noopener">See transaction detail</a> ` ,
cancelable : true ,
actions : [ ]
}
actions : [ ] ,
} ,
} ) ;
} catch ( error ) {
dispatch ( {
type : NOTIFICATION . ADD ,
payload : {
@ -958,12 +907,11 @@ export const onSend = (): AsyncAction => {
title : 'Transaction error' ,
message : error . message || error ,
cancelable : true ,
actions : [ ]
}
actions : [ ] ,
} ,
} ) ;
}
}
}
} ;
export default {
toggleAdvanced ,
@ -978,4 +926,4 @@ export default {
onNonceChange ,
onDataChange ,
onSend ,
}
} ;