From 6dde980c4d539277b66974e8b2dfb151a86c6ef5 Mon Sep 17 00:00:00 2001 From: PaulDremanovich Date: Mon, 5 Aug 2024 17:33:14 +0300 Subject: [PATCH] fix: allow sending the first message faster --- src/components/Chat/Chat.vue | 7 +++++-- src/store/index.js | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/components/Chat/Chat.vue b/src/components/Chat/Chat.vue index da6d0324c..9cc73a7c7 100644 --- a/src/components/Chat/Chat.vue +++ b/src/components/Chat/Chat.vue @@ -336,8 +336,11 @@ function validateMessage(message) { return validationErrors.emptyMessage } - if (this.$store.state.balance < Fees.NOT_ADM_TRANSFER) { - if (this.$store.getters.isAccountNew()) { + const isNewAccount = this.$store.getters.isAccountNew() + const balance = isNewAccount ? this.$store.state.unconfirmedBalance : this.$store.state.balance + + if (balance < Fees.NOT_ADM_TRANSFER) { + if (isNewAccount) { return validationErrors.notEnoughFundsNewAccount } else { return validationErrors.notEnoughFunds diff --git a/src/store/index.js b/src/store/index.js index 0f7393460..51bebfab8 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -46,6 +46,7 @@ import { PendingTxStore } from '@/lib/pending-transactions' export let interval const UPDATE_BALANCE_INTERVAL = 10000 +const UPDATE_BALANCE_INTERVAL_FOR_NEW_ACCOUNT = 2500 /** * @type { import("vuex").StoreOptions } store @@ -55,6 +56,7 @@ const store = { IDBReady: false, // set `true` when state has been saved in IDB address: '', balance: 0, + unconfirmedBalance: 0, balanceStatus: FetchStatus.Loading, passphrase: '', password: '', @@ -77,6 +79,7 @@ const store = { */ return ( state.balance === 0 && + state.unconfirmedBalance === 0 && state.chat.lastMessageHeight === 0 && Object.keys(state.adm.transactions).length === 0 ) @@ -89,6 +92,9 @@ const store = { setBalance(state, balance) { state.balance = balance }, + setUnconfirmedBalance(state, balance) { + state.unconfirmedBalance = balance + }, setBalanceStatus(state, status) { state.balanceStatus = status }, @@ -128,6 +134,7 @@ const store = { return loginOrRegister(passphrase).then((account) => { commit('setAddress', account.address) commit('setBalance', account.balance) + commit('setUnconfirmedBalance', account.unconfirmedBalance) commit('setPassphrase', passphrase) // retrieve wallet data @@ -201,6 +208,7 @@ const store = { return getCurrentAccount() .then((account) => { commit('setBalance', account.balance) + commit('setUnconfirmedBalance', account.unconfirmedBalance) commit('setBalanceStatus', FetchStatus.Success) if (account.balance > Fees.KVS) { flushCryptoAddresses() @@ -214,12 +222,20 @@ const store = { startInterval: { root: true, - handler({ dispatch }) { + handler({ dispatch, getters }) { function repeat() { validateStoredCryptoAddresses() dispatch('updateBalance') .catch((err) => console.error(err)) - .then(() => (interval = setTimeout(repeat, UPDATE_BALANCE_INTERVAL))) + .then( + () => + (interval = setTimeout( + repeat, + getters.isAccountNew() + ? UPDATE_BALANCE_INTERVAL_FOR_NEW_ACCOUNT + : UPDATE_BALANCE_INTERVAL + )) + ) } repeat() }