diff --git a/src/components/Chat/Chat.vue b/src/components/Chat/Chat.vue index 9c5da0f46..be3e708b6 100644 --- a/src/components/Chat/Chat.vue +++ b/src/components/Chat/Chat.vue @@ -327,8 +327,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 566a74681..aa0f78e92 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -48,6 +48,7 @@ import servicesPlugin from './modules/services/services-plugin' export let interval const UPDATE_BALANCE_INTERVAL = 10000 +const UPDATE_BALANCE_INTERVAL_FOR_NEW_ACCOUNT = 2500 /** * @type { import("vuex").StoreOptions } store @@ -57,6 +58,7 @@ const store = { IDBReady: false, // set `true` when state has been saved in IDB address: '', balance: 0, + unconfirmedBalance: 0, balanceStatus: FetchStatus.Loading, passphrase: '', password: '', @@ -79,6 +81,7 @@ const store = { */ return ( state.balance === 0 && + state.unconfirmedBalance === 0 && state.chat.lastMessageHeight === 0 && Object.keys(state.adm.transactions).length === 0 ) @@ -91,6 +94,9 @@ const store = { setBalance(state, balance) { state.balance = balance }, + setUnconfirmedBalance(state, balance) { + state.unconfirmedBalance = balance + }, setBalanceStatus(state, status) { state.balanceStatus = status }, @@ -130,6 +136,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 @@ -203,6 +210,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() @@ -216,12 +224,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() }