Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: fast first message #657

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/components/Chat/Chat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines 50 to +51
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const UPDATE_BALANCE_INTERVAL = 10000
const UPDATE_BALANCE_INTERVAL_FOR_NEW_ACCOUNT = 2500
const UPDATE_BALANCE_INTERVAL = 5000
const UPDATE_BALANCE_INTERVAL_FOR_NEW_ACCOUNT = 1500


/**
* @type { import("vuex").StoreOptions } store
Expand All @@ -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: '',
Expand All @@ -79,6 +81,7 @@ const store = {
*/
return (
state.balance === 0 &&
state.unconfirmedBalance === 0 &&
state.chat.lastMessageHeight === 0 &&
Object.keys(state.adm.transactions).length === 0
)
Expand All @@ -91,6 +94,9 @@ const store = {
setBalance(state, balance) {
state.balance = balance
},
setUnconfirmedBalance(state, balance) {
state.unconfirmedBalance = balance
},
setBalanceStatus(state, status) {
state.balanceStatus = status
},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
}
Expand Down