Skip to content

Commit fd31250

Browse files
Merge pull request #198 from Adamant-im/FixDeliveredMark
Fix cosmetic bugs for fast ETH-sending
2 parents c70a3d9 + ed1b344 commit fd31250

File tree

6 files changed

+45
-14
lines changed

6 files changed

+45
-14
lines changed

src/components/chat/ChatEntryTemplate.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default {
4848
},
4949
mounted () {
5050
let innerText = this.$refs.chatEntry.innerText
51-
const currencies = ['ADM', 'ETH', 'BNB']
51+
const currencies = ['ADM', 'ETH', 'BNB', 'BZ', 'DOGE']
5252
let checkCurrency = false
5353
currencies.forEach(currency => {
5454
checkCurrency = checkForCurrency(innerText, currency)

src/components/chat/EthTransfer.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
:direction="message.direction"
55
:timestamp="message.timestamp"
66
:brief="brief"
7+
:amount="message.message.amount"
78
>
89
<p>{{ $t("chats." + (message.direction === "from" ? "sent_label" : "received_label")) }}</p>
910
<p class='transaction-amount' v-on:click="goToTransaction()">
@@ -12,7 +13,7 @@
1213
<p><em v-text="message.message.comments"></em></p>
1314

1415
<template slot="brief-view">
15-
<span>{{ $t("chats." + (message.direction === "from" ? "sent_label" : "received_label")) }}</span>&nbsp;
16+
<span>{{ $t("chats." + (message.direction === "from" ? "sent_label" : "received_label")) }} </span>
1617
<span v-text="message.message.amount"></span> {{ crypto }}
1718
</template>
1819
</chat-entry-template>
@@ -68,8 +69,7 @@ export default {
6869
const type = this.message.message && this.message.message.type
6970
if (!type) return Cryptos.ETH
7071
71-
const crypto = type.substr(0, type.indexOf('_')).toUpperCase()
72-
return crypto
72+
return type.substr(0, type.indexOf('_')).toUpperCase()
7373
}
7474
}
7575
}

src/store/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ const store = {
647647
updateLastChatMessage(currentDialogs, payload, confirmClass, direction, payload.id)
648648
}
649649

650-
if (currentDialogs.last_message.id === payload.message.hash) {
650+
if (currentDialogs.last_message.id === payload.message.hash && payload.direction === 'to') {
651651
updateLastChatMessage(currentDialogs, payload, confirmClass, direction, payload.message.hash)
652652
}
653653

src/store/modules/eth-base/eth-base-actions.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ const MAX_ATTEMPTS = 150
1212

1313
const 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+
1523
export 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) }

src/views/Chats.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<div v-if="(chat.last_message.amount > 0 && chat.last_message.direction === 'from') || chat.last_message.direction === 'from'" class="message-status-block" :message-status="chat.last_message.confirm_class"></div>
3333
<chat-entry v-if="chat.last_message.amount > 0 && chat.last_message.direction === 'from'" :message="chat.last_message" :brief="true"></chat-entry>
3434
<chat-entry v-else :message="chat.last_message" :brief="true" class="for-received"></chat-entry>
35-
<div v-if="chat.last_message.amount > 0 && chat.last_message.direction === 'to'" class="message-status-block-for-received" :message-status="chat.last_message.confirm_class"></div>
35+
<div v-if="(chat.last_message.amount || chat.last_message.message.amount > 0) && chat.last_message.direction === 'to'" class="message-status-block-for-received" :message-status="chat.last_message.confirm_class"></div>
3636
</div>
3737
<span class="dt" v-if="chat.last_message.timestamp">{{ $formatDate(chat.last_message.timestamp) }}</span>
3838
</div>

src/views/Transfer.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
@close="onClose"
6262
ref="confirm_transfer_dialog">
6363
</md-dialog-confirm>
64+
<Spinner v-if="showLoader"></Spinner>
6465
</div>
6566
</template>
6667

@@ -96,27 +97,32 @@ export default {
9697
}
9798
if (type !== 'ok') return
9899
this.isWaiting = true
100+
this.showLoader = true
99101
this.sendTokens().then(
100102
hash => {
101103
this.isWaiting = false
102104
103105
if (!hash) {
104106
// No hash: transaction has been rejected
105107
this.errorMessage('error_transaction_send')
108+
this.showLoader = false
106109
return
107110
}
108111
109112
if (this.fixedAddress) {
110113
// Go back to chat if we came from there
114+
this.showLoader = false
111115
this.$router.push({ name: 'Chat', params: { partner: this.fixedAddress } })
112116
} else {
113117
// View the newly created transaction
114118
const params = { crypto: this.crypto, tx_id: hash }
119+
this.showLoader = false
115120
this.$router.push({ name: 'Transaction', params })
116121
}
117122
},
118123
err => {
119124
console.error(err)
125+
this.showLoader = false
120126
this.isWaiting = false
121127
this.errorMessage('error_transaction_send')
122128
}
@@ -303,7 +309,8 @@ export default {
303309
targetAmount: '',
304310
crypto: this.fixedCrypto || Cryptos.ADM,
305311
comments: '',
306-
isWaiting: false
312+
isWaiting: false,
313+
showLoader: false
307314
}
308315
},
309316
props: ['fixedCrypto', 'fixedAddress']

0 commit comments

Comments
 (0)