@@ -12,6 +12,14 @@ const MAX_ATTEMPTS = 150
1212
1313const CHUNK_SIZE = 25
1414
15+ function checkBlockCount ( transaction , rootState ) {
16+ if ( transaction . blockNumber ) {
17+ return Number ( transaction . blockNumber ) !== 0 && ( Number ( transaction . blockNumber ) < Number ( rootState . eth . blockNumber ) )
18+ } else {
19+ return false
20+ }
21+ }
22+
1523export default function createActions ( config ) {
1624 const endpoint = getEndpointUrl ( 'ETH' )
1725 const api = new Web3 ( new Web3 . providers . HttpProvider ( endpoint , 2000 ) )
@@ -103,7 +111,6 @@ export default function createActions (config) {
103111
104112 return admApi . sendSpecialMessage ( admAddress , msg ) . then ( result => {
105113 if ( result . success ) {
106- console . log ( 'ADM message has been sent' , msg , result . transactionId )
107114 return serialized
108115 } else {
109116 console . log ( `Failed to send "${ type } "` , result )
@@ -163,20 +170,22 @@ export default function createActions (config) {
163170 const key = 'transaction:' + payload . hash
164171 const supplier = ( ) => api . eth . getTransaction . request ( payload . hash , ( err , tx ) => {
165172 if ( ! err && tx && tx . input ) {
166- const transaction = parseTransaction ( context , tx )
167-
173+ let transaction = parseTransaction ( context , tx )
168174 if ( transaction ) {
175+ // Override transaction status until getting at least one confirmation from backend
176+ if ( transaction . status === 'SUCCESS' && ! checkBlockCount ( transaction , context . rootState ) ) {
177+ transaction . status = 'PENDING'
178+ }
169179 context . commit ( 'transactions' , [ transaction ] )
170180
171181 // Fetch receipt details: status and actual gas consumption
172182 const { attempt, ...receiptPayload } = payload
173183 context . dispatch ( 'getTransactionReceipt' , receiptPayload )
174184 }
175185 }
176-
177186 if ( ! tx && payload . attempt === MAX_ATTEMPTS ) {
178187 // Give up, if transaction could not be found after so many attempts
179- context . commit ( 'transactions' , [ { hash : tx . hash , status : 'ERROR' } ] )
188+ context . commit ( 'transactions' , [ { hash : payload . hash , status : 'ERROR' } ] )
180189 } else if ( err || ( tx && ! tx . blockNumber ) || ( ! tx && payload . isNew ) ) {
181190 // In case of an error or a pending transaction fetch its details once again later
182191 // Increment attempt counter, if no transaction was found so far
@@ -200,7 +209,22 @@ export default function createActions (config) {
200209 const gasPrice = transaction . gasPrice
201210
202211 const supplier = ( ) => api . eth . getTransactionReceipt . request ( payload . hash , ( err , tx ) => {
203- if ( ! err && tx ) {
212+ if ( ! err && tx && checkBlockCount ( tx , context . rootState ) ) {
213+ // For sync last chat message with transaction state
214+ if ( tx . from === context . rootState . eth . address ) {
215+ let contacts = Object . entries ( context . rootGetters . getContacts . list )
216+ let ADMAddress
217+ contacts . forEach ( ( contact ) => {
218+ const ethAddress = contact [ 1 ] . ETH
219+ if ( ethAddress && ethAddress . toString ( ) . toUpperCase ( ) === tx . to . toUpperCase ( ) ) {
220+ ADMAddress = contact [ 0 ]
221+ let currentDialogs = context . rootState . chats [ ADMAddress ]
222+ if ( currentDialogs . last_message . id === tx . transactionHash ) {
223+ currentDialogs . last_message . confirm_class = 'confirmed'
224+ }
225+ }
226+ } )
227+ }
204228 context . commit ( 'transactions' , [ {
205229 hash : payload . hash ,
206230 fee : utils . calculateFee ( tx . gasUsed , gasPrice ) ,
@@ -210,7 +234,7 @@ export default function createActions (config) {
210234 if ( ! tx && payload . attempt === MAX_ATTEMPTS ) {
211235 // Give up, if transaction could not be found after so many attempts
212236 context . commit ( 'transactions' , [ { hash : tx . hash , status : 'ERROR' } ] )
213- } else if ( err || ( tx && ! tx . blockNumber ) || ( ! tx && payload . isNew ) ) {
237+ } else if ( err || ( tx && ! tx . blockNumber ) || ( ! tx && payload . isNew ) || ! checkBlockCount ( tx , context . rootState ) ) {
214238 // In case of an error or a pending transaction fetch its receipt once again later
215239 // Increment attempt counter, if no transaction was found so far
216240 const newPayload = tx ? payload : { ...payload , attempt : 1 + ( payload . attempt || 0 ) }
0 commit comments