diff --git a/src/components/Chat/Chat.vue b/src/components/Chat/Chat.vue index 2827c18a2..99b4d2625 100644 --- a/src/components/Chat/Chat.vue +++ b/src/components/Chat/Chat.vue @@ -459,8 +459,11 @@ function validateMessage(message: string): string | false { return validationErrors.emptyMessage } - if (store.state.balance < Fees.NOT_ADM_TRANSFER) { - if (store.getters.isAccountNew()) { + const isNewAccount = store.getters.isAccountNew() + const balance = isNewAccount ? store.state.unconfirmedBalance : 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 f9c868d54..28fb2664a 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -48,7 +48,8 @@ import servicesPlugin from './modules/services/services-plugin' export let interval -const UPDATE_BALANCE_INTERVAL = 10000 +const UPDATE_BALANCE_INTERVAL = 5000 +const UPDATE_BALANCE_INTERVAL_FOR_NEW_ACCOUNT = 1500 /** * @type { import("vuex").StoreOptions } store @@ -58,6 +59,7 @@ const store = { IDBReady: false, // set `true` when state has been saved in IDB address: '', balance: 0, + unconfirmedBalance: 0, balanceStatus: FetchStatus.Loading, passphrase: '', password: '', @@ -80,6 +82,7 @@ const store = { */ return ( state.balance === 0 && + state.unconfirmedBalance === 0 && state.chat.lastMessageHeight === 0 && Object.keys(state.adm.transactions).length === 0 ) @@ -92,6 +95,9 @@ const store = { setBalance(state, balance) { state.balance = balance }, + setUnconfirmedBalance(state, balance) { + state.unconfirmedBalance = balance + }, setBalanceStatus(state, status) { state.balanceStatus = status }, @@ -131,6 +137,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 @@ -204,6 +211,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() @@ -217,12 +225,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() }